#include <GDIPlus.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <timers.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)
TCPStartUp()

$pDoodle_Rechts = @ScriptDir&"\Doodle_Rechts e.png"
$pDoodle_Links = @ScriptDir&"\Doodle_Links e.png"
$pPlatte_gruen = @ScriptDir&"\Platform grün.gif"
$pPlatte_hellblau = @ScriptDir&"\Platform hellblau.gif"
$pPlatte_weis = @ScriptDir&"\Platform weis.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"
$pHut = @ScriptDir&"\Hut.gif"
$pDoodlehutl = @ScriptDir&"\Doodle_Links k.gif"
$pDoodlehutr = @ScriptDir&"\Doodle_Rechts k.gif"
$pDoodlehutl1 = @ScriptDir&"\Doodle_Links l.gif"
$pDoodlehutr1 = @ScriptDir&"\Doodle_Rechts l.gif"



_GDIPlus_Startup()
$Background = _GDIPlus_ImageLoadFromFile ($pBackground)
$Start = _GDIPlus_ImageLoadFromFile ($pStart)
$Hut = _GDIPlus_ImageLoadFromFile ($pHut)
$DoodleHutl = _GDIPlus_ImageLoadFromFile ($pDoodlehutl)
$DoodleHutr = _GDIPlus_ImageLoadFromFile ($pDoodlehutr)
$DoodleHutl1 = _GDIPlus_ImageLoadFromFile ($pDoodlehutl1)
$DoodleHutr1 = _GDIPlus_ImageLoadFromFile ($pDoodlehutr1)
$Scorebackground = _GDIPlus_ImageLoadFromFile ($pScore)
$Punkteleiste = _GDIPlus_ImageLoadFromFile ($pPunkteleiste)
$Platform_gruen =_GDIPlus_ImageLoadFromFile ($pPlatte_gruen)
$Platform_hellblau = _GDIPlus_ImageLoadFromFile ($pPlatte_hellblau)
$Platform_weis = _GDIPlus_ImageLoadFromFile ($pPlatte_weis)
$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][4] = [[Random(0, $Width - $Plat_Width, 1), 400, 0, 0], [Random(0, $Width - $Plat_Width, 1), 340, 0, 0], [Random(0, $Width - $Plat_Width, 1), 280, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), 220, 0, 0], [Random(0, $Width - $Plat_Width, 1), 160, 0, 0], [Random(0, $Width - $Plat_Width, 1), 100, 0, 0], [Random(0, $Width - $Plat_Width, 1), 40, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), -20, 0, 0], [Random(0, $Width - $Plat_Width, 1), -80, 0, 0]]

Global $ReadN[5]
Global $bewegrichtung[9] = [Random(0, 1, 1), Random(0, 1, 1), Random(0, 1, 1), Random(0, 1, 1), Random(0, 1, 1), Random(0, 1 , 1), Random(0, 1, 1), Random(0, 1, 1), Random(0, 1, 1)]

Global $ReadS[5], $trans[9] = [1, 1, 1, 1, 1, 1, 1, 1, 1]

$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

$winter = False
$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
$huton = 0
$timeron = 0
Global $huttimer, $ybodenalt, $hutbild = 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()

		If  _IsPressed("25",$dll) Then
			$MoveSpeed -= 2
			If $huton = 0 Then
			$AktuellerDoodle = $Doodle_Links
			Else
			$AktuellerDoodle = $DoodleHutl
		EndIf
		EndIf
		If  _IsPressed("27",$dll) Then
			$MoveSpeed += 2
			If $huton = 0 Then
				$AktuellerDoodle = $Doodle_Rechts
			Else
				$AktuellerDoodle = $DoodleHutr
			EndIf
			EndIf
	Select
		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



$platnotactive = 0
$platactive = 0

$platold = $plat
If $huton = 0 Then
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
		If $gruen_n[$n][3] = 1 Then
			If $AktuellerDoodle = $Doodle_Links Then
				$AktuellerDoodle = $DoodleHutl
			Else
				$AktuellerDoodle = $DoodleHutr
			EndIf
			$gruen_n[$n][3] = 0
			$huton = 1
		EndIf

EndSelect
Next
EndIf

;~ For $n = 0 to Ubound(

$x += $MoveSpeed*$t/10

If $huton = 0 Then
	$t += $Zeitschrit
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
;~ 	MsgBox(0, "", $yboden)
	$die = True
EndIf
Endif
If  $scoreplus > $score Then
	$score += 10
	Elseif $scoreplus < $score Then
	$score -=10
EndIf

If $huton = 1 Then
;~
	If $timeron = 0 Then
	$scoreplus += 3000
	$huttimer = _Timer_Init()
	$timeron = 1
	EndIf
	$Platmovespeed = 6
	$time = _Timer_Diff($huttimer)
	If $hutbild = 0 Then
		If $AktuellerDoodle = $DoodleHutl Then
			$AktuellerDoodle = $DoodleHutl1
		ElseIf $AktuellerDoodle = $DoodleHutr Then
			$AktuellerDoodle = $DoodleHutr1

		EndIf
		$hutbild = 1
	Else
		If $AktuellerDoodle = $DoodleHutl1 Then
			$AktuellerDoodle = $DoodleHutl
		ElseIf $AktuellerDoodle = $DoodleHutr1 Then
			$AktuellerDoodle = $DoodleHutr
		EndIf
		$hutbild = 0
	EndIf



	If  $time >= 3000 Then
		$huton = 0
		$timeron = 0
		If $AktuellerDoodle = $DoodleHutr Then
			$AktuellerDoodle = $Doodle_Rechts
			Else
			$AktuellerDoodle = $Doodle_Links
			EndIf

	EndIf
EndIf







If $move = 1 then
	If $huton = 0 Then
	$yboden += $Platmovespeed
	Endif
		For $n = 0 to UBound($gruen_n, 1)-1
		$gruen_n[$n][1] += $Platmovespeed

		If $gruen_n[$n][1] > $Height Then
			reset($n)
		EndIf


	If $gruen_n[$n][2] = 1 Then
		Select
			Case $gruen_n[$n][0] <=30
				$bewegrichtung[$n] = 1
			Case $gruen_n[$n][0] + $Plat_Width >= $Width - 30
				$bewegrichtung[$n] = 0
		EndSelect

		If $bewegrichtung[$n] = 1 Then
			$gruen_n[$n][0] += 3
		Else
			$gruen_n[$n][0] -= 3
		Endif
		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)




	For $n = 0 to UBound($gruen_n, 1)-1
		If $gruen_n[$n][3] = 1 Then
			_GDIPlus_GraphicsDrawImage ($Buffer, $Hut, $gruen_n[$n][0], $gruen_n[$n][1]-23)
			Endif
	Switch $gruen_n[$n][2]
		Case 0
		_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_gruen, $gruen_n[$n][0], $gruen_n[$n][1])
		Case 1
		_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_hellblau, $gruen_n[$n][0], $gruen_n[$n][1])
	Case 2
;~ 		_GDIPlus_GraphicsDrawImage ($Buffer, $Platform_weis, $gruen_n[$n][0], $gruen_n[$n][1])
;~ 		$weisx = $gruen_n[1][0]
;~ 		$weisy = $gruen_n[$n][1]
;~ 		_GDIPlus_GraphicsDrawImageRectRectTrans($Buffer, $Platform_weis, $weisx, $weisx, "", "", "", "", "" , "", 2, 50)

EndSwitch

Next
	$x1 = 0
	$y1 = 0
	_GDIPlus_GraphicsDrawImageRectRectTrans($Buffer, $Punkteleiste, $x1, $y1, "", "", "", "", "" , "", 2, 50)
	_GDIPlus_GraphicsDrawString($Buffer, $score, 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
	If $scoreplus > 2000 Then
		If $scoreplus > 10000 Then
			$r = Random(0, 3, 1)
		Else
			$r = Random(0, 10, 1)
		Endif
	If $r = 1 Then
		$gruen_n[$n][2] = 1
	Else
		$gruen_n[$n][2] = 0
	EndIf
EndIf
$r = Random(0, 50, 1)
If $r = 3 Then $gruen_n[$n][3] = 1


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()
			;MsgBox(0,$pos[0],$pos[1])
		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][4] = [[Random(0, $Width - $Plat_Width, 1), 400, 0, 0], [Random(0, $Width - $Plat_Width, 0), 340, 0, 0], [Random(0, $Width - $Plat_Width, 1), 280, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), 220, 0, 0], [Random(0, $Width - $Plat_Width, 1), 160, 0, 0], [Random(0, $Width - $Plat_Width, 1), 100, 0, 0], [Random(0, $Width - $Plat_Width, 1), 40, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), -20, 0, 0], [Random(0, $Width - $Plat_Width, 1), -80, 0, 0]]


				$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
			
			Case $pos[0] < 303 And $pos[1] < 490 And $pos[0] > 0 And $pos[1] > 455 
				_winter()
			
			
			
					
		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_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $Width, $Height)
	$ReadName = Iniread($datapath, "Names", "Eingetragenername", "")
	$Input = GUICtrlCreateInput($ReadName, 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"
				_iniwrite($Name)
				_sendtoserver($scoreplus, $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", "")

					$ReadName = Iniread($datapath, "Names", "Eingetragenername", "")
				EndIf


				$AktuellerDoodle = $Doodle_Rechts
				Global $gruen_n[9][4] = [[Random(0, $Width - $Plat_Width, 1), 400, 0, 0], [Random(0, $Width - $Plat_Width, 0), 340, 0, 0], [Random(0, $Width - $Plat_Width, 1), 280, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), 220, 0, 0], [Random(0, $Width - $Plat_Width, 1), 160, 0, 0], [Random(0, $Width - $Plat_Width, 1), 100, 0, 0], [Random(0, $Width - $Plat_Width, 1), 40, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), -20, 0, 0], [Random(0, $Width - $Plat_Width, 1), -80, 0, 0]]


				$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
					_sendtoserver($scoreplus, $Name)
				_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
IniWrite($datapath, "Names", "Eingetragenername", $Name)
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_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
				$Name = @IPAddress1
				_sendtoserver($scoreplus, $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][4] = [[Random(0, $Width - $Plat_Width, 1), 400, 0, 0], [Random(0, $Width - $Plat_Width, 1), 340, 0, 0], [Random(0, $Width - $Plat_Width, 1), 280, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), 220, 0, 0], [Random(0, $Width - $Plat_Width, 1), 160, 0, 0], [Random(0, $Width - $Plat_Width, 1), 100, 0, 0], [Random(0, $Width - $Plat_Width, 1), 40, 0, 0], _
[Random(0, $Width - $Plat_Width, 1), -20, 0, 0], [Random(0, $Width - $Plat_Width, 1), -80, 0, 0]]


				$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
				$Name = @IPAddress1
				_sendtoserver($scoreplus, $Name)
				_Start()

			EndIf
			EndSelect
		EndFunc




Func _sendtoserver($Score, $Name)


Dim $ConnectedSocket = -1
$ConnectedSocket = TCPConnect("192.168.1.2",33891)
If Not @error Then
        TCPSend($ConnectedSocket,$Name & "|" & $Score)

EndIf
			EndFunc

Func _winter()
	;_GDIPlus_Shutdown()
	;_GDIPlus_Startup()
;$Background = _GDIPlus_ImageLoadFromFile ("")
$Start = _GDIPlus_ImageLoadFromFile (@ScriptDir & "\Winter Start edit .gif")

#cs
$Hut = _GDIPlus_ImageLoadFromFile ($pHut)
$DoodleHutl = _GDIPlus_ImageLoadFromFile ($pDoodlehutl)
$DoodleHutr = _GDIPlus_ImageLoadFromFile ($pDoodlehutr)
$DoodleHutl1 = _GDIPlus_ImageLoadFromFile ($pDoodlehutl1)
$DoodleHutr1 = _GDIPlus_ImageLoadFromFile ($pDoodlehutr1)
$Scorebackground = _GDIPlus_ImageLoadFromFile ($pScore)
$Punkteleiste = _GDIPlus_ImageLoadFromFile ($pPunkteleiste)
$Platform_gruen =_GDIPlus_ImageLoadFromFile ($pPlatte_gruen)
$Platform_hellblau = _GDIPlus_ImageLoadFromFile ($pPlatte_hellblau)
#ce
$Doodle_Rechts =_GDIPlus_ImageLoadFromFile (@ScriptDir & "\Winter Doodle r.gif")
$Doodle_Links = _GDIPlus_ImageLoadFromFile (@ScriptDir & "\Winter Doodle l.gif")


;GUISetBkColor(0x5375A9,$GUI1)
	$winter = True
	_Start()
EndFunc

Func _winteroff()

$Background = _GDIPlus_ImageLoadFromFile ($pBackground)
$Start = _GDIPlus_ImageLoadFromFile ($pStart)
$Hut = _GDIPlus_ImageLoadFromFile ($pHut)
$DoodleHutl = _GDIPlus_ImageLoadFromFile ($pDoodlehutl)
$DoodleHutr = _GDIPlus_ImageLoadFromFile ($pDoodlehutr)
$DoodleHutl1 = _GDIPlus_ImageLoadFromFile ($pDoodlehutl1)
$DoodleHutr1 = _GDIPlus_ImageLoadFromFile ($pDoodlehutr1)
$Scorebackground = _GDIPlus_ImageLoadFromFile ($pScore)
$Punkteleiste = _GDIPlus_ImageLoadFromFile ($pPunkteleiste)
$Platform_gruen =_GDIPlus_ImageLoadFromFile ($pPlatte_gruen)
$Platform_hellblau = _GDIPlus_ImageLoadFromFile ($pPlatte_hellblau)
$Platform_weis = _GDIPlus_ImageLoadFromFile ($pPlatte_weis)
$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)
EndFunc