Dim Shared As Any Ptr Figur(),textur()

Dim Shared As Integer levelcount,texturdata(),Colordat()
Dim Shared As Integer texturbreiteold,texturhoeheold,Texturbreite,Texturhoehe
Dim Shared As Integer texturmax, leveltextcount,Spalte,Zeile,Loopzeile,Loopspalte,dataposx,dataposy,Tabellmax,tabellchange,tabellsize
Dim Shared As Integer Figurposx,Figurposy,Levelbreite,Levelhoehe,allhoehe
Dim Shared As Integer Spawnpunkt,levelsizecheck

Dim Shared As String  Taste,leveltext(),leveltextcheck,Texturpfad

#Include "fbgfx.bi"
#Include "file.bi"
#Include "pushkay.bi"

Setvalue()
levelinput("Bin\level\level" & levelcount & ".lvl")
Bildcheck()
SetData()
loadlevel()

ScreenRes Levelbreite,allhoehe , 32

Loadpic()
Zeichnen()
figurpaint()

Do




	If Not Taste = "" Then
		If 	 taste = Chr(255, 77) Then 'Rechts
			If Not Figurposx = Levelbreite - Texturbreite 	And Not texturdata(dataposy,dataposx + 1,1) = 1 Then
				Figurposx = Figurposx + Texturbreite
			EndIf

		ElseIf taste = Chr(255, 75) Then 'Links
			If Not Figurposx = 0  									And Not texturdata(dataposy,dataposx - 1,1) = 1 Then
				Figurposx = Figurposx - Texturbreite
			EndIf

		ElseIf taste = Chr(255, 72) Then 'Oben
			If Not Figurposy = 0  									And Not texturdata(dataposy - 1,dataposx,1) = 1 Then
				Figurposy = Figurposy - Texturhoehe
			EndIf

		ElseIf taste = Chr(255, 80) Then 'Unten
			If Not Figurposy = Levelhoehe - Texturhoehe 		And Not texturdata(dataposy + 1,dataposx,1) = 1 Then
				Figurposy = Figurposy + Texturhoehe
			EndIf
		EndIf

		datapos()
		ScreenLock
		Cls

		Zeichnen()
		figurpaint ()
		ScreenUnLock

		If texturdata(dataposy,dataposx,1) = 3 Then
			Figuraction()
			resetdata()
			levelcount = levelcount + 1
			If FileExists ("Bin\level\level" & levelcount & ".lvl") Then

				Draw String (0,allhoehe - 25),"Level Geschafft!", RGB(0,0,0)
				Draw String (0,allhoehe - 15),"Dr"+Chr(129)+"cke Enter um ins n"+Chr(132)+"chste Level zu gelangen!", RGB(0,0,0)

				levelinput("Bin\level\level" & levelcount & ".lvl")
				SetData()
				loadlevel()

				Waitsub()

				Screen 0

				screenres Levelbreite,allhoehe , 32

				Zeichnen()
				figurpaint()
			Else

				Draw String (0,allhoehe - 25),"Super! Alle Level bew"+Chr(132)+"ltigt!", RGB(0,0,0)
				Draw String (0,allhoehe - 15),"Dr"+Chr(129)+"cke Enter um fortzufahren.", RGB(0,0,0)
				Waitsub()
				levelinput("Bin\level\leveldone.lvl")
				SetData()
				loadlevel()

				Screen 0
				screenres Levelbreite,allhoehe , 32
				Zeichnen()
				Draw String (0,allhoehe - 25),"Herzlichen Gl"+Chr(129)+"ckwunsch!", RGB(0,0,0)
				Draw String (0,allhoehe - 15),"Dr"+Chr(129)+"cke Enter um zu beenden.", RGB(0,0,0)
				Waitsub()
				Exit do
			EndIf
		EndIf


		taste = ""

	End If

	taste = InKey

	Sleep 20,1
Loop Until taste = Chr(27)

For i As Integer = 1 To 4
	ImageDestroy (Figur(i))
Next

For i As Integer = 0 To texturmax
	ImageDestroy (textur(i))
Next

End