Ich habs trotzdem nochmals versucht. Es gibt hier aber noch eine Überschneidung. Mit der Abfolge sollte es jetzt so sein, dass Koll und
Richtungswechsel nur noch auf dem vollen Teil geprüft wird. Kann sich dieser Code mal jemand anschauen??
Code: Alles auswählen
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"")
Global mapHeight.l = 29
Global mapWidth.l = 35
Global MapX.l = 24
Global MapY.l = 24
Global posX.l = 48
Global posY.l = 48
Global i
Global k
Global speed = 2
Global points = -5
#TileSize = 24
#playerWidth = 24
#playerHeight = 24
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()
Structure _object
TileID.l
EndStructure
Global Dim map._object(mapWidth, mapHeight)
Restore map
For t = 0 To mapHeight
For n = 0 To mapWidth
Read map(n,t)\TileID
Next
Next
Repeat
ClearScreen(0)
ExamineKeyboard()
For t = 0 To mapHeight
For n = 0 To mapWidth
If init = 0
If map(n, t)\TileID = 0
punkte + 1
map(n, t)\TileID = 3
EndIf
EndIf
DisplayTransparentSprite(map(n, t)\TileID, (mapX + #TileSize*n),(mapY + #TileSize*t) )
Next
Next
init = 1
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
EndIf
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
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
EndIf
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
If right = 1
posx + speed
schritt + speed
If schritt > 22
If map(i+1, k)\TileID < 1 Or map(i+1, k)\TileID > 2
schritt = 0
Else
right = 0
schritt = 0
EndIf
EndIf
EndIf
If left = 1
posx - speed
schritt - speed
If schritt < 1
If map(i-1, k)\TileID < 1 Or map(i-1, k)\TileID > 2
schritt = 23
Else
left = 0
schritt = 23
EndIf
EndIf
EndIf
If up = 1
posy - speed
schritt - speed
If schritt < 1
If map(i, k-1)\TileID < 1 Or map(i, k-1)\TileID > 2
schritt = 23
Else
up = 0
schritt = 23
EndIf
EndIf
EndIf
If down = 1
posy + speed
schritt + speed
If schritt > 22
If map(i, k+1)\TileID < 1 Or map(i, k+1)\TileID > 2
schritt = 0
Else
down = 0
schritt = 0
EndIf
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))
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,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