ich hab deinen code mal angekuckt und etwas überarbeitet:
Code: Alles auswählen
EnableExplicit
Structure OBJECT
TileID.l
EndStructure
Define mapHeight.l = 29
Define mapWidth.l = 35
Define MapX.l = 24
Define MapY.l = 24
Define posX.l = 48
Define posY.l = 48
Define speed = 2
Define points = 0
Define i, k, t, n
Define punkte, right, left, Up, Down, schritt
Dim map.OBJECT(mapWidth, mapHeight)
#TileSize = 24
#playerWidth = 24
#playerHeight = 24
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"")
CreateSprite(0,24,24)
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,24,24,RGB(0,0,0))
StopDrawing()
CreateSprite(1,24,24)
StartDrawing(SpriteOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,24,24,RGB(255,255,255))
StopDrawing()
CreateSprite(2,24,24)
StartDrawing(SpriteOutput(2))
DrawingMode(#PB_2DDrawing_Default)
Circle(12,12,12,RGB(255,100,255))
StopDrawing()
CreateSprite(3,24,24)
StartDrawing(SpriteOutput(3))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,24,24,RGB(0, 0, 0))
Circle(12,12,3,RGB(254, 255, 61))
StopDrawing()
Restore map
For t = 0 To mapHeight
For n = 0 To mapWidth
Read map(n,t)\TileID
If map(n, t)\TileID = 0
punkte + 1
map(n, t)\TileID = 3
EndIf
Next
Next
Repeat
ClearScreen(0)
ExamineKeyboard()
For t = 0 To mapHeight
For n = 0 To mapWidth
DisplayTransparentSprite(map(n, t)\TileID, (MapX + #TileSize*n),(MapY + #TileSize*t) )
Next
Next
i = ((posX-MapX)/#TileSize)
k = ((posY-MapY)/#TileSize)
If schritt < 1
If KeyboardPushed(#PB_Key_Right)
If map(i+1, k)\TileID < 1 Or map(i+1, k)\TileID > 2
right = 1:left = 0:Up = 0:Down = 0
EndIf
Else
If KeyboardPushed(#PB_Key_Left)
If map(i-1, k)\TileID < 1 Or map(i-1, k)\TileID > 2
right = 0:left = 1:Up = 0:Down = 0
EndIf
EndIf
EndIf
If KeyboardPushed(#PB_Key_Up)
If map(i, k-1)\TileID < 1 Or map(i, k-1)\TileID > 2
right = 0:left = 0:Up = 1:Down = 0
EndIf
Else
If KeyboardPushed(#PB_Key_Down)
If map(i, k+1)\TileID < 1 Or map(i, k+1)\TileID > 2
right = 0:left = 0:Up = 0:Down = 1
EndIf
EndIf
EndIf
EndIf
If right = 1
posX + speed
schritt + speed
If schritt > 23
schritt = 0
right = 0
EndIf
EndIf
If left = 1
posX - speed
schritt + speed
If schritt > 23
left = 0
schritt = 0
EndIf
EndIf
If Up = 1
posY - speed
schritt + speed
If schritt > 23
Up = 0
schritt = 0
EndIf
EndIf
If Down = 1
posY + speed
schritt + speed
If schritt > 23
Down = 0
schritt = 0
EndIf
EndIf
If map(i, k)\TileID = 3
map(i, k)\TileID = 0
punkte - 1
points + 5
EndIf
DisplayTransparentSprite(2,posX,posY)
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(925,50,"PUNKTE",RGB(255,255,255))
DrawText(930, 80, RSet(Str(points), 6, "0"),RGB(255,255,255))
DrawText(10,30,"schritte: "+Str(schritt),RGB(255,0,255))
DrawText(10,50,"richtung: "+Str(right),RGB(255,0,255))
DrawText(10,70,"posx: "+Str((posX)),RGB(255,0,0))
DrawText(10,90,"posy: "+Str((posY)),RGB(255,0,0))
StopDrawing()
Delay(1)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
DataSection
map:
Data.l 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data.l 1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1
Data.l 1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1
Data.l 1,0,1,1,0,0,0,0,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