#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>

$Width = 300
$Height = 460

$JumpSpeed = 0.12
$JumpHeight = 80 ;Pixel
$MoveSpeed = 0

$GUI1 = GUICreate("Doodle Jump - Gamma", $Width, $Height)
GUISetState(@SW_SHOW)
Opt("GUIOnEventMode",1)
GUISetOnEvent($GUI_EVENT_CLOSE,"ende",$GUI1)

$pDoodle_Rechts = @ScriptDir&"\gfx\Doodle_Rechts e.png"
$pDoodle_Links = @ScriptDir&"\gfx\Doodle_Links e.png"
$pPlatte_gruen = @ScriptDir&"\gfx\Platform_grün.gif"

_GDIPlus_Startup()
$Background = _GDIPlus_ImageLoadFromFile (@ScriptDir&"\gfx\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

$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
$onplatform = 0
While 1
	$x -= $MoveSpeed



	Select
		Case _IsPressed("25")
			$MoveSpeed += 0.7
			$AktuellerDoodle = $Doodle_Links
		Case _IsPressed("27")
			$MoveSpeed -= 0.7
			$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
;
If $die = False Then
	If $onplatform = 1 Then
		 $y = 400  - $Doodle_Height - 10 - Round (Abs(Sin($i))*$JumpHeight)
		 Else
		$y = $Height - $Doodle_Height - 10 - Round (Abs(Sin($i))*$JumpHeight)
	EndIf
$i += $JumpSpeed
	if 60 - $Doodle_Width <= $x and 60 + $Plat_Width >= $x Then
			if ($y+$Doodle_Height<=400 and $y+$Doodle_Height+6>=400) then
				$onplatform = 1
				$i = 0
			EndIf
		Else
			$onplatform = 0
			$die = True
		EndIf
	Else
	$y +=12
EndIf
	if $y+$Doodle_Height>$width Then
		death()
	EndIf



;~ MsgBox(0, "", $i)

;~     _GDIPlus_GraphicsClear($Buffer, 0xFFFFFFFF)
	_WinAPI_RedrawWindow($GUI1, "", "", $RDW_UPDATENOW + $RDW_FRAME)
    _GDIPlus_GraphicsDrawImage ($Buffer, $Background, 0, 0)

    _GDIPlus_GraphicsDrawImage ($Buffer, $AktuellerDoodle, $x, $y)
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, 60, 400)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)
    Sleep(20)

WEnd

Func Jumpup()
	Do
	$i += $JumpSpeed
    $y = $Height  - $Doodle_Height - 40 - Abs(Sin($i))*$JumpHeight
	_GDIPlus_GraphicsDrawImage ($Buffer, $Background, 0, 0)
    _GDIPlus_GraphicsDrawImage ($Buffer, $AktuellerDoodle, $x, $y)
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, 60, 400)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)
    Sleep(20)
Until $y <= 400 +$Doodle_Height
EndFunc

func ende()
	_GDIPlus_GraphicsDispose($Graphic)
    _GDIPlus_ImageDispose($Buffer)
    _WinAPI_DeleteObject($Bitmap)
	_GDIPlus_Shutdown()
	Exit
EndFunc

func death()
	;score name optionen usw
	;save score
	;values resetten
EndFunc