Ich wollte ein kleines Spiel machen. Ich müsste dafür es hinbekommen, einen Ball, der sich die ganze Zeit bewegt, an den Rändern abprallen zu lassen.
Script:
Spoiler anzeigen
#Region includes
#include <GDIPlus.au3>
#include <Misc.au3>
#EndRegion
#Region Globale Variablen und Einstellungen
OnAutoItExitRegister("dispose")
Opt("GUICloseOnESC", 0)
Global $xl=25, $yl=70, $xt=70, $yt=25, $xr=460, $yr=70, $xb=70, $yb=460, $score=0, $ballpos[2]=[250, 250], $delaybmove=100, $var=5
Const $vWidth=10, $vHeight=50, $hWidth=50, $hHeight=10, $ly=20, $lx=20, $lwidth=455, $lheight=455
#EndRegion
#Region GDI+
_GDIPlus_Startup()
$BlockPen=_GDIPlus_PenCreate(0xFFFFFFFF, 4)
$BlockBrush=_GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$LinePen=_GDIPlus_PenCreate(0xFFFF0000, 2)
$sFormat = _GDIPlus_StringFormatCreate()
$sBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
$sFamily = _GDIPlus_FontFamilyCreate("Courier New")
$sFont = _GDIPlus_FontCreate($sFamily, 10)
$sLayout = _GDIPlus_RectFCreate(5, 5)
$BallPen=_GDIPlus_PenCreate(0xFFFFFFFF)
$BallBrush=_GDIPlus_BrushCreateSolid(0xFFFFFFFF)
#EndRegion
While 1
#Region Hauptmenü
$sGUI = GUICreate("", 342, 143, -1, -1, 0x80000000+0x00800000)
GUISetFont(20, 800, 2, "Courier New")
GUISetBkColor(0x000000)
$start = GUICtrlCreateLabel("Starten", 104, 8, 116, 35)
GUICtrlSetColor(-1, 0xFFFF00)
$credits = GUICtrlCreateLabel("Credits", 104, 52, 116, 35)
GUICtrlSetColor(-1, 0xFFFF00)
$exit = GUICtrlCreateLabel("Beenden", 104, 97, 116, 35)
GUICtrlSetColor(-1, 0xFFFF00)
GUISetState()
While 1
Switch GUIGetMsg()
Case -3, $exit
Exit
Case $start
GUIDelete($sGUI)
ExitLoop
Case $credits
EndSwitch
WEnd
#EndRegion
#Region GameGUI
$hGUI = GUICreate("Minigame", 500, 500, -1, -1, 0x80000000+0x00800000)
GUISetBkColor(0x000000)
$hGraphics=_GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap=_GDIPlus_BitmapCreateFromGraphics(500, 500, $hGraphics)
$hBuffer=_GDIPlus_ImageGetGraphicsContext($hBitmap)
GUISetState()
drawblocks()
drawball()
_GDIPlus_GraphicsDrawRect($hBuffer, $lx, $ly, $lWidth, $lHeight, $LinePen)
_GDIPlus_GraphicsDrawStringEx($hBuffer, "Score: "&$score, $sFont, $sLayout, $sFormat, $sBrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 500, 500)
AdlibRegister("moveball", $delaybmove)
While sleep(1)
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
If _IsPressed("1B") Then ExitLoop
If _IsPressed(25) And $xb>25 Then moveblock(4, "l")
If _IsPressed(27) And $xb<420 Then moveblock(4, "r")
If _IsPressed(26) And $yr>25 Then moveblock(3, "u")
If _IsPressed(28) And $yr<420 Then moveblock(3, "d")
If _IsPressed(41) And $xt>25 Then moveblock(2, "l")
If _IsPressed(44) And $xt<420 Then moveblock(2, "r")
If _IsPressed(57) And $yl>25 Then moveblock(1, "u")
If _IsPressed(53) And $yl<420 Then moveblock(1, "d")
If NOT WinActive("Minigame") Then
AdlibUnRegister("moveball")
Do
sleep(100)
Until WinActive("Minigame")
drawblocks()
drawball()
_GDIPlus_GraphicsDrawRect($hBuffer, $lx, $ly, $lWidth, $lHeight, $LinePen)
_GDIPlus_GraphicsDrawStringEx($hBuffer, "Score: "&$score, $sFont, $sLayout, $sFormat, $sBrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 500, 500)
AdlibRegister("moveball", $delaybmove)
EndIf
WEnd
#EndRegion
GUIDelete($hGUI)
WEnd
#Region Funktionen
#Region Zeichnen
Func drawblocks()
_GDIPlus_GraphicsClear($hBuffer)
_GDIPlus_GraphicsDrawRect($hBuffer, $xl, $yl, $vwidth, $vheight, $BlockPen)
_GDIPlus_GraphicsFillRect($hBuffer, $xl, $yl, $vwidth, $vheight, $BlockBrush)
_GDIPlus_GraphicsDrawRect($hBuffer, $xt, $yt, $hwidth, $hheight, $BlockPen)
_GDIPlus_GraphicsFillRect($hBuffer, $xt, $yt, $hwidth, $hheight, $BlockBrush)
_GDIPlus_GraphicsDrawRect($hBuffer, $xr, $yr, $vwidth, $vheight, $BlockPen)
_GDIPlus_GraphicsFillRect($hBuffer, $xr, $yr, $vwidth, $vheight, $BlockBrush)
_GDIPlus_GraphicsDrawRect($hBuffer, $xb, $yb, $hwidth, $hheight, $BlockPen)
_GDIPlus_GraphicsFillRect($hBuffer, $xb, $yb, $hwidth, $hheight, $BlockBrush)
EndFunc
Func drawball()
_GDIPlus_GraphicsDrawEllipse($hBuffer, $ballpos[0], $ballpos[1], 20, 20, $BallPen)
_GDIPlus_GraphicsFillEllipse($hBuffer, $ballpos[0], $ballpos[1], 20, 20, $BallBrush)
EndFunc
#EndRegion
#Region Bewegungen
Func moveblock($block, $direction)
Switch $block
Case 1
If $direction="u" Then $yl-=5
If $direction="d" Then $yl+=5
Case 2
If $direction="l" Then $xt-=5
If $direction="r" Then $xt+=5
Case 3
If $direction="u" Then $yr-=5
If $direction="d" Then $yr+=5
Case 4
If $direction="l" Then $xb-=5
If $direction="r" Then $xb+=5
EndSwitch
drawblocks()
drawball()
_GDIPlus_GraphicsDrawRect($hBuffer, $lx, $ly, $lWidth, $lHeight, $LinePen)
_GDIPlus_GraphicsDrawStringEx($hBuffer, "Score: "&$score, $sFont, $sLayout, $sFormat, $sBrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 500, 500)
_GDIPlus_GraphicsClear($hBuffer)
EndFunc
Func moveball()
If $ballpos[1]=430 Or $ballpos[1]=25 Then $var=$var*(-1)
$ballpos[0]-=$var
$ballpos[1]-=$var
drawblocks()
drawball()
_GDIPlus_GraphicsDrawRect($hBuffer, $lx, $ly, $lWidth, $lHeight, $LinePen)
_GDIPlus_GraphicsDrawStringEx($hBuffer, "Score: "&$score, $sFont, $sLayout, $sFormat, $sBrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 500, 500)
_GDIPlus_GraphicsClear($hBuffer)
EndFunc
#EndRegion
Func dispose()
_GDIPlus_FontDispose($sFont)
_GDIPlus_FontFamilyDispose($sFamily)
_GDIPlus_StringFormatDispose($sFormat)
_GDIPlus_BrushDispose($sBrush)
_GDIPlus_BrushDispose($BlockBrush)
_GDIPlus_BrushDispose($BallBrush)
_GDIPlus_PenDispose($BallPen)
_GDIPlus_PenDispose($BlockPen)
_GDIPlus_PenDispose($LinePen)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
EndFunc
#EndRegion
Ich krieg es einfach nicht hin