Hey,
wie mache ich eine "Range" um eine Variable? Also es soll folgenden Sinn haben:
Spoiler anzeigen
If $coord1X To $coord1X + 20 Or $coord1X To $coord1X - 20 = $coord2X To $coord2X + 20 Or $coord2X To $coord2X - 20
Then...
Also 2 Zahlenmengen kleiner und größer als der Wert in der Variable (das oben genannte Beispiel funktioniert nicht, Fehler bei To).
Edit: Von Ealendil gelöst:
Funktionierendes Script
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)
OnAutoItExitRegister("_Exit")
_GDIPlus_Startup()
; Variablen ============================================================================
[/autoit] [autoit][/autoit] [autoit]Global $iWidth = 500, $iHeight = 600
Global $iX = 0, $iY = 0
Global $hBackground = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\background.png")
Global $balloon_red = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_red.png")
Global $balloon_green = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_green.png")
Global $balloon_blue = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_blue.png")
Global $balloon_yellow = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_yellow.png")
Global $balloon_pink = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_pink.png")
Global $figur = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\figur.png")
Global $balloonX = 50
Global $balloonY = 50
Global $figurX = 200
Global $figurY = 467
Global $figurWidth = 60
Global $figurHeight = 100
Global $Check
; GUI ============================================================================
[/autoit] [autoit][/autoit] [autoit]$hGUI = GUICreate("TrapTheBalloon", $iWidth, $iHeight, Default, Default)
$hWnd = WinGetHandle("TrapTheBalloon")
GUISetState()
GUISetOnEvent(-3, "_Exit")
; GDI+ ============================================================================
[/autoit] [autoit][/autoit] [autoit]$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
;Erstmal das normale Grafik-Objekt erstellen.
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
;Statt uns mit dem normalen Frontbuffer zufrieden zu geben, erstellen wir erstmal eine
;Bitmap, mit Bezug auf unser Grafikobjekt.
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
;Nachdem unser Bitmap erstellt ist, holen wir uns den Graphics Context. Dieser
;wird von uns verwendet, um darin zu zeichnen
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
_GDIPlus_GraphicsClear($hGraphic)
; While-Schleife ============================================================================
GUIRegisterMsg($WM_PAINT, "_WM_PAINT")
While 1
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_GraphicsClear($hBackbuffer)
; Superradierer benutzen um alten Backbuffer zu löschen
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 5)
_GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBackground, 0, 0, $iWidth, $iHeight)
if not $Check Then _GDIPlus_GraphicsDrawImage($hBackbuffer, $balloon_red, 50, $balloonY)
$balloonY += 7
If $balloonY > $iHeight Then $balloonY = -75
_GDIPlus_GraphicsDrawImage($hBackbuffer, $figur, $figurX, $figurY)
If _IsPressed("25") And $figurX >= 5 Then $figurX -= 10
If _IsPressed("27") And $figurX + 79 <= 495 Then $figurX += 3
if _IsBetween($balloonY+49, $figurY + 20, $figurY + 30) And _IsBetween($balloonX, $figurX, $figurX + 20) Then $Check = 1
_WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_INTERNALPAINT)
; WM_PAINT wird nur aufgerufen, wenn alle Berechnungen fertig sind!
; In WM_PAINT wird selbst nichts berechnet, oder gezeichnet. diese Funktion wird nur das
; Bitmap-Objekt in das Grafik-Objekt übertragen.
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $iX, $iY, $iWidth, $iHeight)
; _GDIPlus_GraphicsDrawImageRect() überträgt den Backbuffer in den Frontbuffer.
; Der erste Parameter ist unser Frontbuffer (Grafik Objekt).
; Der zweite ist unsere Bitmap, welche ja als BackBuffer fungiert.
; Darauf folgt der Abschnitt den man übertragen will.
; i.d.R. ist es 0, 0 für X und Y koordinaten, und die GUI Breite und Höhe für
; Width und Height. Kommt natürlich immer drauf an, wie groß euer Grafikobjekt ist,
; und ob ihr den vollen Teil zeichnen wollt.
ToolTip($balloonY & " " & $balloonX & @CRLF & $figurY & " " & $figurX)
WEnd
; Funktionen ============================================================================
[/autoit] [autoit][/autoit] [autoit]Func _WM_PAINT()
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $iX, $iY, $iWidth, $iHeight)
EndFunc ;==>_WM_PAINT
Func _Exit() ; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic) ; Grafikobjekt auflösen
_GDIPlus_BitmapDispose($hBitmap); Bitmap auflösen
_GDIPlus_ImageDispose($balloon_red); Bild auflösen
_GDIPlus_ImageDispose($balloon_green); Bild auflösen
_GDIPlus_ImageDispose($balloon_blue); Bild auflösen
_GDIPlus_ImageDispose($balloon_yellow); Bild auflösen
_GDIPlus_ImageDispose($balloon_pink); Bild auflösen
_GDIPlus_ImageDispose($hBackground); Bild auflösen
_GDIPlus_ImageDispose($figur); Bild auflösen
_GDIPlus_Shutdown() ; GDI+ Engine beenden
Exit
EndFunc ;==>_Exit
Func _IsBetween($A, $Min, $Max)
Return $A >= $Min And $A <= $Max
EndFunc ;==>_IsBetween