#include <GDIPlus.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$Width = 300
$Height = 460

$JumpSpeed = 0.15
$JumpHeight = 80 ;Pixel
$MoveSpeed = 0
$Zeitschrit = 0.2

$GUI1 = GUICreate("Doodle Jump - Gamma", $Width, $Height)
GUISetState(@SW_SHOW)

$dll=DllOpen("user32.dll")

opt("guioneventmode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "ende")
AutoItSetOption ("MouseCoordMode", 0)


$pDoodle_Rechts = @ScriptDir&"\Doodle_Rechts e.png"
$pDoodle_Links = @ScriptDir&"\Doodle_Links e.png"
$pPlatte_gruen = @ScriptDir&"\Platform grün.gif"
$pPlatte_braun1 = @ScriptDir&"\Platform_braun1.gif"
$pPlatte_braun2 = @ScriptDir&"\Platform_braun2.gif"
$pPunkteleiste = @ScriptDir&"\Punkteleiste.gif"
$pBackground = @ScriptDir&"\background.gif"
$pStart = @ScriptDir&"\Start.gif"
$pScore = @ScriptDir&"\scorebackground.gif"
$pNewhighscore = @ScriptDir&"\Newhighscore.gif"
$pGameover = @ScriptDir&"\Gameover.gif"

_GDIPlus_Startup()
$Background = _GDIPlus_ImageLoadFromFile ($pBackground)
$Start = _GDIPlus_ImageLoadFromFile ($pStart)
$Scorebackground = _GDIPlus_ImageLoadFromFile ($pScore)
$Platte_braun1 = _GDIPlus_ImageLoadFromFile ($pPlatte_braun1)
$Platte_braun2 = _GDIPlus_ImageLoadFromFile ($pPlatte_braun2)
$Punkteleiste = _GDIPlus_ImageLoadFromFile ($pPunkteleiste)
$Platform_gruen =_GDIPlus_ImageLoadFromFile ($pPlatte_gruen)
$Doodle_Rechts =_GDIPlus_ImageLoadFromFile ($pDoodle_Rechts)
$Doodle_Links = _GDIPlus_ImageLoadFromFile ($pDoodle_Links)
$Newhighscore = _GDIPlus_ImageLoadFromFile ($pNewhighscore)
$Gameover = _GDIPlus_ImageLoadFromFile ($pGameover)
$Doodle_Height = _GDIPlus_ImageGetHeight($Doodle_Rechts)
$Doodle_Width = _GDIPlus_ImageGetWidth($Doodle_Rechts)
$Plat_Width = _GDIPlus_ImageGetWidth($Platform_gruen)
$Graphic = _GDIPlus_GraphicsCreateFromHWND($GUI1)
$Bitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $Graphic)
$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)


$AktuellerDoodle = $Doodle_Rechts
Global $gruen_n[9][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], _
[Random(0, $Width - $Plat_Width, 1), -20], [Random(0, $Width - $Plat_Width, 1), -80]]
Global $braun[1][2] = [[Random(0, $Width - $Plat_Width, 1), 370]]
Global $ReadN[5]
Global $ReadS[5]

$datapath = @ScriptDir & "\Scores.ini"
;~ MsgBox(0, "", $datapath)
If FileExists($datapath) Then
	$ReadS[0] = Iniread($datapath, "Scores", "1", "")
	$ReadS[1] = Iniread($datapath, "Scores", "2", "")
	$ReadS[2] = Iniread($datapath, "Scores", "3", "")
	$ReadS[3] = Iniread($datapath, "Scores", "4", "")
	$ReadS[4] = Iniread($datapath, "Scores", "5", "")

	$ReadN[0] = Iniread($datapath, "Names", "1", "")
	$ReadN[1] = Iniread($datapath, "Names", "2", "")
	$ReadN[2] = Iniread($datapath, "Names", "3", "")
	$ReadN[3] = Iniread($datapath, "Names", "4", "")
	$ReadN[4] = Iniread($datapath, "Names", "5", "")
EndIf

$die = False
$i = 0
$t = 0
$x = $gruen_n[0][0]
$y  = 380 - $Doodle_Height
$onplatform = 0
$plat = 0


$move =0
$score = 0
$scoreplus = 0
$yboden = $gruen_n[0][1]
$Platmovespeed = 0
$platten = 0



_Start()

While 1

If $die = False Then
	Redraw()
	Elseif $scoreplus > $ReadS[4] Then
		Newscore()
	Elseif $scoreplus < $ReadS[4] Then
		Dead()
	EndIf





WEnd





Func Redraw()
Select
		Case _IsPressed("25",$dll)
			$MoveSpeed -= 2
			$AktuellerDoodle = $Doodle_Links
		Case _IsPressed("27",$dll)
			$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
		$i += $JumpSpeed
		$t += $Zeitschrit


$platnotactive = 0
$platactive = 0

$platold = $plat
For $n = 0 to UBound($gruen_n, 1)-1 Step 1

	Select

		Case $y < 220 and $y > 180
			$move = 1
			$Platmovespeed = 0.5
		Case $y < 180
			$Platmovespeed= 3.5
		Case $y > 180
			$Platmovespeed = 0.5
		Case $y >= 220
			$move = 0
			$Platmovespeed = 0
Endselect
Select
	Case  ($gruen_n[$n][0] - $Doodle_Width <= $x and $gruen_n[$n][0] + $Plat_Width >= $x) and($y+$Doodle_Height<=$gruen_n[$n][1] and $y+$Doodle_Height+15>=$gruen_n[$n][1])
		$onplatform = 1
		$plat = $n
		$t = 0
		$t = $Zeitschrit
		$yboden = $gruen_n[$n][1]
		$platten +=1
		If $platold < $plat or ($platold = 8 and $plat = 0) Then
		$scoreplus +=120
		EndIf
		If Not ($platold = 8 and $plat = 0) Then
			If $platold > $plat Then
			$mul = $platold - $plat
		$scoreplus -=$mul *120
	EndIf
	EndIf

EndSelect
Next

;~ For $n = 0 to Ubound(

$x += $MoveSpeed*$t/6

If $yboden= $y +30 Then
	$y = $yboden  - $Doodle_Height - 10 - Round (Abs(40*$t-(9.81/2)*$t^2))
	Else
$y = $yboden  - $Doodle_Height - 10 - Round (40*$t-(9.81/2)*$t^2)
EndIf
If $y + 5 >= $Height Then
	$die = True
EndIf
If  $scoreplus > $score Then
	$score += 2
	Elseif $scoreplus < $score Then
	$score -=2
EndIf

;~ 	Setbraun()



If $move = 1 then
	$yboden += $Platmovespeed
		For $n = 0 to UBound($gruen_n, 1)-1
		$gruen_n[$n][1] += $Platmovespeed
			$braun[0][1] += $Platmovespeed/8.1
		If $gruen_n[$n][1] > $Height Then
			reset($n)
		EndIf
	Next
	Endif


;~ MsgBox(0, "", $MoveSpeed)

;~     _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, $Platte_braun2, $braun[0][0]+28, $braun[0][1])
;~ 		_GDIPlus_GraphicsDrawImage ($Buffer, $Platte_braun1, $braun[0][0], $braun[0][1])

	For $n = 0 to UBound($gruen_n, 1)-1
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, $gruen_n[$n][0], $gruen_n[$n][1])
Next

	_GDIPlus_GraphicsDrawImageRectRectTrans($Buffer, $Punkteleiste, 0, 0, "", "", "", "", "" , "", 2, 50)
	_GDIPlus_GraphicsDrawString($Buffer, $score * 2, 5, 5, "Comic Sans MS", 15)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)
    Sleep(20)

EndFunc

Func reset($n)
	$gruen_n[$n][0] = Random(0, $Width - $Plat_Width, 1)
	$gruen_n[$n][1] = -80
EndFunc

;~ Func Setbraun()
;~ 	$r = Random(1 , 20, 1)
;~ 	For $n = 0 to UBound($braun, 1)
;~ 	IF $r = 2 Then
;~ 	$braun[$n][0] = Random(0, $Width - $Plat_Width, 1)
;~ 	$braun[$n][1] = Random(-45, -65, 1)

;~ 	Endif
;~ 	Next
;~ EndFunc



Func _GDIPlus_GraphicsDrawImageRectRectTrans($hGraphics, $hImage, $iSrcX, $iSrcY, $iSrcWidth = "", $iSrcHeight = "", _
    $iDstX = "", $iDstY = "", $iDstWidth = "" , $iDstHeight = "", $iUnit = 2, $nTrans = 1)
    Local $tColorMatrix, $x, $hImgAttrib, $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage)
    If $iSrcWidth = 0 or $iSrcWidth = "" Then $iSrcWidth = $iW
    If $iSrcHeight = 0 or $iSrcHeight = "" Then $iSrcHeight = $iH
    If $iDstX = "" Then $iDstX = $iSrcX
    If $iDstY = "" Then $iDstY = $iSrcY
    If $iDstWidth = "" Then $iDstWidth = $iSrcWidth
    If $iDstHeight = "" Then $iDstHeight = $iSrcHeight
    If $iUnit = "" Then $iUnit = 2
    ;;create color matrix data
    $tColorMatrix = DllStructCreate("float[5];float[5];float[5];float[5];float[5]")
    ;blending values:
    $x = DllStructSetData($tColorMatrix, 1, 1, 1) * DllStructSetData($tColorMatrix, 2, 1, 2) * DllStructSetData($tColorMatrix, 3, 1, 3) * _
            DllStructSetData($tColorMatrix, 4, $nTrans, 4) * DllStructSetData($tColorMatrix, 5, 1, 5)
    ;;create an image attributes object and update its color matrix
    $hImgAttrib =  DllCall($ghGDIPDll, "int", "GdipCreateImageAttributes", "ptr*", 0)
    $hImgAttrib = $hImgAttrib[1]
     DllCall($ghGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr", $hImgAttrib, "int", 1, _
            "int", 1, "ptr", DllStructGetPtr($tColorMatrix), "ptr", 0, "int", 0)
    ;;draw image into graphic object with alpha blend
    DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "hwnd", $hGraphics, "hwnd", $hImage, "int", $iDstX, "int", _
            $iDstY, "int", $iDstWidth, "int", $iDstHeight, "int", $iSrcX, "int", $iSrcY, "int", $iSrcWidth, "int", _
            $iSrcHeight, "int", $iUnit, "ptr", $hImgAttrib, "int", 0, "int", 0)
    ;;clean up
    DllCall($ghGDIPDll, "int", "GdipDisposeImageAttributes", "ptr", $hImgAttrib)
    Return
EndFunc   ;==>_GDIPlus_GraphicsDrawImageRectRectTrans


Func _Start()
;~ 	MsgBox(0,"","")
	While 2
;~ 	$Label = GUICtrlCreateLabel("", 53, 149, 110, 41)
;~ 	GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)


	Select
		case _IsPressed("01")
			$pos = MouseGetPos()
		Select
			Case $pos[0] > 53 and $pos[0] < 163 and $pos[1] > 149 and $pos[1] < 190

				If FileExists($datapath) Then
					$ReadS[0] = Iniread($datapath, "Scores", "1", "")
					$ReadS[1] = Iniread($datapath, "Scores", "2", "")
					$ReadS[2] = Iniread($datapath, "Scores", "3", "")
					$ReadS[3] = Iniread($datapath, "Scores", "4", "")
					$ReadS[4] = Iniread($datapath, "Scores", "5", "")

					$ReadN[0] = Iniread($datapath, "Names", "1", "")
					$ReadN[1] = Iniread($datapath, "Names", "2", "")
					$ReadN[2] = Iniread($datapath, "Names", "3", "")
					$ReadN[3] = Iniread($datapath, "Names", "4", "")
					$ReadN[4] = Iniread($datapath, "Names", "5", "")
				EndIf


				$AktuellerDoodle = $Doodle_Rechts
				Global $gruen_n[9][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], _
				[Random(0, $Width - $Plat_Width, 1), -20], [Random(0, $Width - $Plat_Width, 1), -80]]
				Global $braun[1][2] = [[Random(0, $Width - $Plat_Width, 1), 370]]

				$Graphic = _GDIPlus_GraphicsCreateFromHWND($GUI1)
				$Bitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $Graphic)
				$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
				$die = False

				$t = 0
				$x = $gruen_n[0][0]
				$y  = 380 - $Doodle_Height
				$onplatform = 0
				$plat = 0
				$MoveSpeed = 0
				$move =0
				$yboden = $gruen_n[0][1]
				$Platmovespeed = 0
				$platten = 0
				$score = 0
				$scoreplus = 0

				ExitLoop
			Case $pos[0] > 85 and $pos[0] < 197 and $pos[1] > 210 and $pos[1] < 250
				_Showscore()
				ExitLoop
		EndSelect
		EndSelect


		 $y = 400  - $Doodle_Height - 10 - Round (Abs(Sin($i))*$JumpHeight)
		$x = 60
	$i += $JumpSpeed


	_WinAPI_RedrawWindow($GUI1, "", "", $RDW_UPDATENOW + $RDW_FRAME)

	_GDIPlus_GraphicsDrawImage ($Buffer, $Start, 0, 0)
    _GDIPlus_GraphicsDrawImage ($Buffer, $Doodle_Rechts, $x, $y)
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, 50, 400)

    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)
	Sleep(20)
	Wend
EndFunc ;==> Start


Func _Showscore()
;~ 	MsgBox(0, "", "")

	If FileExists($datapath) Then
		$ReadS[0] = Iniread($datapath, "Scores", "1", "")
		$ReadS[1] = Iniread($datapath, "Scores", "2", "")
		$ReadS[2] = Iniread($datapath, "Scores", "3", "")
		$ReadS[3] = Iniread($datapath, "Scores", "4", "")
		$ReadS[4] = Iniread($datapath, "Scores", "5", "")

		$ReadN[0] = Iniread($datapath, "Names", "1", "")
		$ReadN[1] = Iniread($datapath, "Names", "2", "")
		$ReadN[2] = Iniread($datapath, "Names", "3", "")
		$ReadN[3] = Iniread($datapath, "Names", "4", "")
		$ReadN[4] = Iniread($datapath, "Names", "5", "")
	EndIf
;~ 	MsgBox(0, "", $ReadS[0])
	While 3
	 $y = 400  - $Doodle_Height - 10 - Round (Abs(Sin($i))*$JumpHeight)
		$x = 60
	$i += $JumpSpeed

	_WinAPI_RedrawWindow($GUI1, "", "", $RDW_UPDATENOW + $RDW_FRAME)
	_GDIPlus_GraphicsDrawImage($Buffer, $Scorebackground, 0, 0)
	For $n = 0 to 4
		If $ReadS[$n] <> "" Then
			_GDIPlus_GraphicsDrawString($Buffer, $ReadS[$n], $Width - 100, 211 + ($n-1)*23, "Comic Sans MS", 12)
			_GDIPlus_GraphicsDrawString($Buffer, $ReadN[$n], $Width - 240, 211 + ($n-1)*23, "Comic Sans MS", 12)
		EndIf

	Next

    _GDIPlus_GraphicsDrawImage ($Buffer, $Doodle_Rechts, $x, $y)
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, 50, 400)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)
	Sleep(20)

	$pos = MouseGetPos()
    Select
		Case _IsPressed("01", $dll)
			IF $pos[0] > 163 and $pos[0] < 269 and $pos[1] > 403 and $pos[1] < 444 Then
				_Start()
				ExitLoop
			EndIf
    EndSelect
	Wend
EndFunc ;==> Showscore

Func ende()
	_GDIPlus_GraphicsDispose($Graphic)
            _GDIPlus_ImageDispose($Buffer)
            _WinAPI_DeleteObject($Bitmap)
			_GDIPlus_Shutdown()
			Exit
		EndFunc ;==> ende

Func Newscore()
	_WinAPI_RedrawWindow($GUI1, "", "", $RDW_UPDATENOW + $RDW_FRAME)
	_GDIPlus_GraphicsDrawImage($Buffer, $Newhighscore, 0, 0)
	_GDIPlus_GraphicsDrawString($Buffer, "Dein Score: " & $scoreplus, 3, 205, "Comic Sans MS", 12)
	_GDIPlus_GraphicsDrawString($Buffer, "Name: ", 3, 225, "Comic Sans MS", 12)
    _GDIPlus_GraphicsDrawImage ($Buffer, $Doodle_Rechts, $x, $y)
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, 50, 400)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)

	$Input = GUICtrlCreateInput("", 58, 227)
	GUICtrlSetLimit($Input, 9)
	While 4
$pos = MouseGetPos()
    Select
		Case _IsPressed("01", $dll)
			IF $pos[0] > 98 and $pos[0] < 207 and $pos[1] > 284 and $pos[1] < 324 Then
				$Name = GUICtrlRead($Input)
				If $Name = "" Then
					$Name = "Spieler"
					Endif
				_iniwrite($Name)

				If FileExists($datapath) Then
					$ReadS[0] = Iniread($datapath, "Scores", "1", "")
					$ReadS[1] = Iniread($datapath, "Scores", "2", "")
					$ReadS[2] = Iniread($datapath, "Scores", "3", "")
					$ReadS[3] = Iniread($datapath, "Scores", "4", "")
					$ReadS[4] = Iniread($datapath, "Scores", "5", "")

					$ReadN[0] = Iniread($datapath, "Names", "1", "")
					$ReadN[1] = Iniread($datapath, "Names", "2", "")
					$ReadN[2] = Iniread($datapath, "Names", "3", "")
					$ReadN[3] = Iniread($datapath, "Names", "4", "")
					$ReadN[4] = Iniread($datapath, "Names", "5", "")
				EndIf


				$AktuellerDoodle = $Doodle_Rechts
				Global $gruen_n[9][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], _
				[Random(0, $Width - $Plat_Width, 1), -20], [Random(0, $Width - $Plat_Width, 1), -80]]
				Global $braun[1][2] = [[Random(0, $Width - $Plat_Width, 1), 370]]

				$Graphic = _GDIPlus_GraphicsCreateFromHWND($GUI1)
				$Bitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $Graphic)
				$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
				$die = False

				$t = 0
				$x = $gruen_n[0][0]
				$y  = 380 - $Doodle_Height
				$onplatform = 0
				$plat = 0
				$MoveSpeed = 0
				$move =0
				$yboden = $gruen_n[0][1]
				$Platmovespeed = 0
				$platten = 0
				$score = 0
				$scoreplus = 0
				GUICtrlDelete($Input)
				ExitLoop
			EndIf

			IF $pos[0] > 151 and $pos[0] < 261 and $pos[1] > 346 and $pos[1] < 381 Then
				$Name = GUICtrlRead($Input)
				If $Name = "" Then
					$Name = "Spieler"
					Endif
				_iniwrite($Name)
				GUICtrlDelete($Input)
				_Start()
				ExitLoop

			EndIf
		EndSelect
		Wend
			EndFunc

Func _iniwrite($Name)
				If $scoreplus > $ReadS[4] Then
	If $scoreplus > $ReadS[3] Then
		If $scoreplus > $ReadS[2] Then
			If $scoreplus > $ReadS[1] Then
				If $scoreplus > $ReadS[0] Then
					Iniwrite($datapath, "Scores", "1", $scoreplus)
					Iniwrite($datapath, "Scores", "2", $ReadS[0])
					Iniwrite($datapath, "Scores", "3", $ReadS[1])
					Iniwrite($datapath, "Scores", "4", $ReadS[2])
					Iniwrite($datapath, "Scores", "5", $ReadS[3])

					Iniwrite($datapath, "Names", "1", $Name)
					Iniwrite($datapath, "Names", "2", $ReadN[0])
					Iniwrite($datapath, "Names", "3", $ReadN[1])
					Iniwrite($datapath, "Names", "4", $ReadN[2])
					Iniwrite($datapath, "Names", "5", $ReadN[3])
				Else
					Iniwrite($datapath, "Scores", "2", $scoreplus)
					Iniwrite($datapath, "Scores", "3", $ReadS[1])
					Iniwrite($datapath, "Scores", "4", $ReadS[2])
					Iniwrite($datapath, "Scores", "5", $ReadS[3])

					Iniwrite($datapath, "Names", "2", $Name)
					Iniwrite($datapath, "Names", "3", $ReadN[1])
					Iniwrite($datapath, "Names", "4", $ReadN[2])
					Iniwrite($datapath, "Names", "5", $ReadN[3])
				EndIf

			Else
				Iniwrite($datapath, "Scores", "3", $scoreplus)
				Iniwrite($datapath, "Scores", "4", $ReadS[2])
				Iniwrite($datapath, "Scores", "5", $ReadS[3])

				Iniwrite($datapath, "Names", "3", $Name)
				Iniwrite($datapath, "Names", "4", $ReadN[2])
				Iniwrite($datapath, "Names", "5", $ReadN[3])
			EndIf

		Else
			Iniwrite($datapath, "Scores", "4", $scoreplus)
			Iniwrite($datapath, "Scores", "5", $ReadS[3])
			Iniwrite($datapath, "Names", "4", $Name)
			Iniwrite($datapath, "Names", "5", $ReadN[3])
		EndIf

	Else
		Iniwrite($datapath, "Scores", "5", $scoreplus)
		Iniwrite($datapath, "Names", "5", $Name)
	EndIf

EndIf


EndFunc

Func Dead()
		_WinAPI_RedrawWindow($GUI1, "", "", $RDW_UPDATENOW + $RDW_FRAME)
	_GDIPlus_GraphicsDrawImage($Buffer, $Gameover, 0, 0)
	_GDIPlus_GraphicsDrawString($Buffer, "Dein Score: " & $scoreplus, 3, 205, "Comic Sans MS", 12)

    _GDIPlus_GraphicsDrawImage ($Buffer, $Doodle_Rechts, $x, $y)
	_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, 50, 400)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)

$pos = MouseGetPos()
    Select
		Case _IsPressed("01", $dll)
			IF $pos[0] > 98 and $pos[0] < 207 and $pos[1] > 284 and $pos[1] < 324 Then

				If FileExists($datapath) Then
					$ReadS[0] = Iniread($datapath, "Scores", "1", "")
					$ReadS[1] = Iniread($datapath, "Scores", "2", "")
					$ReadS[2] = Iniread($datapath, "Scores", "3", "")
					$ReadS[3] = Iniread($datapath, "Scores", "4", "")
					$ReadS[4] = Iniread($datapath, "Scores", "5", "")

					$ReadN[0] = Iniread($datapath, "Names", "1", "")
					$ReadN[1] = Iniread($datapath, "Names", "2", "")
					$ReadN[2] = Iniread($datapath, "Names", "3", "")
					$ReadN[3] = Iniread($datapath, "Names", "4", "")
					$ReadN[4] = Iniread($datapath, "Names", "5", "")
				EndIf


				$AktuellerDoodle = $Doodle_Rechts
				Global $gruen_n[9][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], _
				[Random(0, $Width - $Plat_Width, 1), -20], [Random(0, $Width - $Plat_Width, 1), -80]]
				Global $braun[1][2] = [[Random(0, $Width - $Plat_Width, 1), 370]]

				$Graphic = _GDIPlus_GraphicsCreateFromHWND($GUI1)
				$Bitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $Graphic)
				$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
				$die = False

				$t = 0
				$x = $gruen_n[0][0]
				$y  = 380 - $Doodle_Height
				$onplatform = 0
				$plat = 0
				$MoveSpeed = 0
				$move =0
				$yboden = $gruen_n[0][1]
				$Platmovespeed = 0
				$platten = 0
				$score = 0
				$scoreplus = 0

			EndIf

			IF $pos[0] > 151 and $pos[0] < 261 and $pos[1] > 346 and $pos[1] < 381 Then
				_Start()

			EndIf
			EndSelect
			EndFunc

