Code: Alles auswählen
Structure Feld
begehbar.i
tile.i
EndStructure
Dim MAPinit.Feld(5,1)
MAPinit(0,0)\begehbar = 1
mapinit(0,0)\tile = 1
MAPinit(1,0)\begehbar = 0
mapinit(0,0)\tile = 0
Code: Alles auswählen
Structure Feld
begehbar.i
tile.i
EndStructure
Dim MAPinit.Feld(5,1)
MAPinit(0,0)\begehbar = 1
mapinit(0,0)\tile = 1
MAPinit(1,0)\begehbar = 0
mapinit(0,0)\tile = 0
Auf das nötige Hintergrundwissen bzw. Verständnis musst du dann schon selbst kommen. Es macht ja sonst keinen Sinn, oder?NathanielBlack hat geschrieben:gar nicht, soweit war ich mit der demo nicht gekommen:P
ich brauche auch keine Pixel genaue Kollision, sondern einfach nur, dass man über tiles net laufen kann;)
mfg
Nathaniel
Code: Alles auswählen
Global Dim MAPinit.l(5,5)
Procedure Darf_Laufen(px,py)
px=Round(px/50,#PB_Round_Down)
py=Round(py/50,#PB_Round_Down)
If px>=0 And px<=5 And py>=0 And py<=5
If MAPinit(px,py)=0
ProcedureReturn 1
EndIf
EndIf
EndProcedure
If InitSprite() And InitKeyboard() And UsePNGImageDecoder()
If OpenScreen(800,600,32,"Tilemap")
ScrollX=400
ScrollY=300
For i = 0 To 2
CreateSprite(i,50,50)
StartDrawing(SpriteOutput(i))
Select i
Case 0
Box(0,0,49,49,$00FF00)
Case 1
Box(0,0,49,49,$FF0000)
Case 2
Box(0,0,49,49,$0000FF)
EndSelect
StopDrawing()
Next
Player=CreateSprite(#PB_Any,11,11)
StartDrawing(SpriteOutput(Player))
Circle(5,5,5,$FFFFFF)
Circle(5,5,4,$FF0000)
StopDrawing()
CopyMemory(?TileMap,@MAPinit(),4*6*6)
Repeat
ClearScreen(RGB(0,0,0))
For x = 0 To 5
For y = 0 To 5
PosX = x * 50 + ScrollX
PosY = y * 50 + ScrollY
DisplaySprite(MAPinit(x,y),PosX,PosY)
Next
Next
DisplaySprite(Player,PlayerX+ScrollX-5,PlayerY+ScrollY-5)
StartDrawing(ScreenOutput())
FrontColor($000000)
BackColor($FFFFFF)
DrawText(0,200,"PlayerX= " + Str(PlayerX))
DrawText(0,220,"PlayerY= " + Str(PlayerY))
DrawText(0,240,"ScrollX= " +Str(ScrollX))
DrawText(0,260,"ScrollY= " +Str(ScrollY))
StopDrawing()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_W) And Darf_Laufen(PlayerX,PlayerY-1)
PlayerY = PlayerY - 1
ScrollY = ScrollY + 1
EndIf
If KeyboardPushed(#PB_Key_S) And Darf_Laufen(PlayerX,PlayerY+1)
PlayerY = PlayerY + 1
ScrollY = ScrollY - 1
EndIf
If KeyboardPushed(#PB_Key_D) And Darf_Laufen(PlayerX+1,PlayerY)
PlayerX = PlayerX + 1
ScrollX = ScrollX - 1
EndIf
If KeyboardPushed(#PB_Key_A) And Darf_Laufen(PlayerX-1,PlayerY-1)
PlayerX = PlayerX - 1
ScrollX = ScrollX + 1
EndIf
Until KeyboardPushed(1)
EndIf
EndIf
End
DataSection
TileMap:
Data.l 0,1,1,0,0,0
Data.l 0,0,1,1,0,2
Data.l 0,0,0,0,0,0
Data.l 0,2,1,0,2,0
Data.l 0,1,1,0,0,0
Data.l 1,1,2,2,0,0
EndDataSection