#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>

$Width = 300
$Height = 460

$JumpSpeed = 0.15
$JumpHeight = 80 ;Pixel
$MoveSpeed = 0

$GUI1 = GUICreate("Doodle Jump - Gamma", $Width, $Height)
GUISetState(@SW_SHOW)

$pDoodle_Rechts = @ScriptDir&"\Doodle_Rechts e.png"
$pDoodle_Links = @ScriptDir&"\Doodle_Links e.png"
$pPlatte_gruen = @ScriptDir&"\Platform grün.gif"

_GDIPlus_Startup()
$Background = _GDIPlus_ImageLoadFromFile (@ScriptDir&"\background.gif")
$Platform_gruen =_GDIPlus_ImageLoadFromFile ($pPlatte_gruen)
$Doodle_Rechts =_GDIPlus_ImageLoadFromFile ($pDoodle_Rechts)
$Doodle_Links = _GDIPlus_ImageLoadFromFile ($pDoodle_Links)
$Doodle_Height = _GDIPlus_ImageGetHeight($Doodle_Rechts)
$Doodle_Width = _GDIPlus_ImageGetWidth($Doodle_Rechts)
$Plat_Width = _GDIPlus_ImageGetWidth($Platform_gruen)
$AktuellerDoodle = $Doodle_Rechts
Global $gruen_n[7][2] = [[Random(0, $Width - $Plat_Width, 1), 400], [Random(0, $Width - $Plat_Width, 1), 340], [Random(0, $Width - $Plat_Width, 1), 280], _
[Random(0, $Width - $Plat_Width, 1), 220], [Random(0, $Width - $Plat_Width, 1), 160], [Random(0, $Width - $Plat_Width, 1), 100], [Random(0, $Width - $Plat_Width, 1), 40]]
$Graphic = _GDIPlus_GraphicsCreateFromHWND($GUI1)
$Bitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $Graphic)
$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
$die = False
$i = 0
$x = 50
$Jumped = 0
$yplus = 0
$y  = $Height  - $yplus - $Doodle_Height - 40 - Abs(Sin($i))*$JumpHeight
$ynew = 0
$onplat = -1
While 1




	Select
		Case _IsPressed("25")
			$MoveSpeed += 2
			$AktuellerDoodle = $Doodle_Links
		Case _IsPressed("27")
			$MoveSpeed -= 2
			$AktuellerDoodle = $Doodle_Rechts
		Case $x + $Doodle_Width < 0
			$x = $Width
		Case $x > $Width
			$x = $Doodle_Width * -1
		Case $MoveSpeed > 30
			$MoveSpeed =30
		Case $MoveSpeed < -30
			$MoveSpeed = -30
	EndSelect
;~ 	Select
;~ 		Case 60 - $Doodle_Width < $x and $x < 60 + $Plat_Width and $Jumped = 0
;~ 			$yplus = ($Height - 400 - $Doodle_Height) * -1
;~ 			Jumpup()
;~ 			$Jumped = 1


;~ 		Case $x < 60
;~ 			$yplus =  $Height - 400 - $Doodle_Height
;~ 		Case 60 + $Plat_Width < $x
;~ 			$yplus =  $Height - 400 - $Doodle_Height
;~ 	EndSelect

Redraw()

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($Graphic)
            _GDIPlus_ImageDispose($Buffer)
            _WinAPI_DeleteObject($Bitmap)

            Exit
    EndSwitch
WEnd

Func Redraw()
		$x -= $MoveSpeed
		If $die = False Then
		If $onplat >= 0 Then
		$y = $gruen_n[$onplat][1]  - $Doodle_Height - 10 - Round (Abs(Sin($i))*$JumpHeight)
		 Else
    $y = $Height - $Doodle_Height - 10 - Round (Abs(Sin($i))*$JumpHeight)
EndIf
$i += $JumpSpeed
For $n = 0 to UBound($gruen_n, 1)-1
	if $gruen_n[$n][0] - $Doodle_Width <= $x and $gruen_n[$n][0] + $Plat_Width >= $x Then
			if ($y+$Doodle_Height <= $gruen_n[$n][1] and $y+$Doodle_Height+6 >= $gruen_n[$n][1]) then
				$onplat = $n
				$i = 0
				Else
			$onplat = -1
			EndIf
		Else
			$onplat = -1

		EndIf
	Next
		Else
	$y +=50
EndIf






;~ MsgBox(0, "", $MoveSpeed)

;~     _GDIPlus_GraphicsClear($Buffer, 0xFFFFFFFF)

    _GDIPlus_GraphicsDrawImage ($Buffer, $Background, 0, 0)

    _GDIPlus_GraphicsDrawImage ($Buffer, $AktuellerDoodle, $x, $y)
	For $n = 0 to UBound($gruen_n, 1)-1
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, $gruen_n[$n][0], $gruen_n[$n][1])
	Next
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)
    Sleep(20)

EndFunc
