Collision detection!
This commit is contained in:
parent
f6f7f0250e
commit
355d831f70
4 changed files with 54 additions and 9 deletions
|
@ -48,7 +48,9 @@ Procedure HandleEventRunningGame()
|
||||||
|
|
||||||
; Player movement
|
; Player movement
|
||||||
If KeyboardReleased(#PB_Key_Left) And Player\X > 0
|
If KeyboardReleased(#PB_Key_Left) And Player\X > 0
|
||||||
Player\X-1
|
If TileIsType(#TILESET_TYPE_FLOOR, Player\X-1, Player\Y) Or TileIsType(#TILESET_TYPE_GRASS, Player\X-1, Player\Y)
|
||||||
|
Player\X-1
|
||||||
|
EndIf
|
||||||
|
|
||||||
; Camera positioning
|
; Camera positioning
|
||||||
If Player\X < (Cam\X + Cam\Padding) And Cam\X > 0
|
If Player\X < (Cam\X + Cam\Padding) And Cam\X > 0
|
||||||
|
@ -57,7 +59,9 @@ Procedure HandleEventRunningGame()
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
If KeyboardReleased(#PB_Key_Right) And Player\X < #MAP_WIDTH-1
|
If KeyboardReleased(#PB_Key_Right) And Player\X < #MAP_WIDTH-1
|
||||||
Player\X+1
|
If TileIsType(#TILESET_TYPE_FLOOR, Player\X+1, Player\Y) Or TileIsType(#TILESET_TYPE_GRASS, Player\X+1, Player\Y)
|
||||||
|
Player\X+1
|
||||||
|
EndIf
|
||||||
|
|
||||||
; Camera positioning
|
; Camera positioning
|
||||||
If Player\X > (Cam\X + Cam\Width - Cam\Padding) And (Cam\X + Cam\Width) < #MAP_WIDTH-1
|
If Player\X > (Cam\X + Cam\Width - Cam\Padding) And (Cam\X + Cam\Width) < #MAP_WIDTH-1
|
||||||
|
@ -66,7 +70,9 @@ Procedure HandleEventRunningGame()
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
If KeyboardReleased(#PB_Key_Up) And Player\Y > 0
|
If KeyboardReleased(#PB_Key_Up) And Player\Y > 0
|
||||||
Player\Y-1
|
If TileIsType(#TILESET_TYPE_FLOOR, Player\X, Player\Y-1) Or TileIsType(#TILESET_TYPE_GRASS, Player\X, Player\Y-1)
|
||||||
|
Player\Y-1
|
||||||
|
EndIf
|
||||||
|
|
||||||
; Camera positioning
|
; Camera positioning
|
||||||
If Player\Y< (Cam\Y + Cam\Padding) And Cam\Y > 0
|
If Player\Y< (Cam\Y + Cam\Padding) And Cam\Y > 0
|
||||||
|
@ -75,7 +81,9 @@ Procedure HandleEventRunningGame()
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
If KeyboardReleased(#PB_Key_Down) And Player\Y < #MAP_HEIGHT-1
|
If KeyboardReleased(#PB_Key_Down) And Player\Y < #MAP_HEIGHT-1
|
||||||
Player\Y+1
|
If TileIsType(#TILESET_TYPE_FLOOR, Player\X, Player\Y+1) Or TileIsType(#TILESET_TYPE_GRASS, Player\X, Player\Y+1)
|
||||||
|
Player\Y+1
|
||||||
|
EndIf
|
||||||
|
|
||||||
; Camera positioning
|
; Camera positioning
|
||||||
If Player\Y > (Cam\Y + Cam\Height - Cam\Padding) And (Cam\Y + Cam\Height) < #MAP_HEIGHT-1
|
If Player\Y > (Cam\Y + Cam\Height - Cam\Padding) And (Cam\Y + Cam\Height) < #MAP_HEIGHT-1
|
||||||
|
|
|
@ -15,8 +15,21 @@ Procedure InitTileset()
|
||||||
For i=0 To 5
|
For i=0 To 5
|
||||||
For j=0 To 5
|
For j=0 To 5
|
||||||
|
|
||||||
Tileset(count) = CopySprite(GFXTileset, #PB_Any)
|
Tileset(count)\ID = CopySprite(GFXTileset, #PB_Any)
|
||||||
ClipSprite(Tileset(count), #TILE_SIZE*j, #TILE_SIZE*i, #TILE_SIZE, #TILE_SIZE)
|
ClipSprite(Tileset(count)\ID, #TILE_SIZE*j, #TILE_SIZE*i, #TILE_SIZE, #TILE_SIZE)
|
||||||
|
|
||||||
|
Tileset(count)\Type = #TILESET_TYPE_FLOOR
|
||||||
|
Select count
|
||||||
|
Case 0
|
||||||
|
Tileset(count)\Type = #TILESET_TYPE_PLAYER
|
||||||
|
Case 2
|
||||||
|
Tileset(count)\Type = #TILESET_TYPE_WALL
|
||||||
|
Case 3
|
||||||
|
Tileset(count)\Type = #TILESET_TYPE_SOLID
|
||||||
|
Case 4
|
||||||
|
Tileset(count)\Type = #TILESET_TYPE_GRASS
|
||||||
|
EndSelect
|
||||||
|
|
||||||
count+1
|
count+1
|
||||||
Next
|
Next
|
||||||
Next
|
Next
|
||||||
|
@ -112,7 +125,7 @@ EndProcedure
|
||||||
|
|
||||||
; Map itself
|
; Map itself
|
||||||
Procedure DrawTile(number.i, x.i, y.i)
|
Procedure DrawTile(number.i, x.i, y.i)
|
||||||
DisplaySprite(Tileset(number), #TILE_SIZE*x, #TILE_SIZE*y)
|
DisplaySprite(Tileset(number)\ID, #TILE_SIZE*x, #TILE_SIZE*y)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure DrawMap()
|
Procedure DrawMap()
|
||||||
|
@ -125,6 +138,18 @@ Procedure DrawMap()
|
||||||
Next
|
Next
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure TileIsType(type.i, X.i, Y.i)
|
||||||
|
Define istype.b
|
||||||
|
|
||||||
|
istype = #False
|
||||||
|
|
||||||
|
If Tileset(TileMap(X, Y)\TileNumber)\Type = type
|
||||||
|
istype = #True
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
ProcedureReturn istype
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
; The player
|
; The player
|
||||||
Procedure DrawPlayer()
|
Procedure DrawPlayer()
|
||||||
DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y)
|
DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y)
|
||||||
|
|
|
@ -6,6 +6,13 @@
|
||||||
#MAP_HEIGHT = 120
|
#MAP_HEIGHT = 120
|
||||||
; TODO: Aus der XML lesen
|
; TODO: Aus der XML lesen
|
||||||
|
|
||||||
|
; Tileset entries
|
||||||
|
#TILESET_TYPE_PLAYER = 0
|
||||||
|
#TILESET_TYPE_FLOOR = 1
|
||||||
|
#TILESET_TYPE_WALL = 2
|
||||||
|
#TILESET_TYPE_SOLID = 3
|
||||||
|
#TILESET_TYPE_GRASS = 4
|
||||||
|
|
||||||
; Global variables
|
; Global variables
|
||||||
Global Fullscreen = 0
|
Global Fullscreen = 0
|
||||||
Global Title.s = "ESCape - Build " + Str(#PB_Editor_BuildCount)
|
Global Title.s = "ESCape - Build " + Str(#PB_Editor_BuildCount)
|
||||||
|
@ -37,7 +44,7 @@ Global Font_H3 = LoadFont(3, "Verdana", 10)
|
||||||
; Graphics
|
; Graphics
|
||||||
Global GFXLogo.i
|
Global GFXLogo.i
|
||||||
Global GFXTileset.i
|
Global GFXTileset.i
|
||||||
Global Dim Tileset.i(36)
|
Global Dim Tileset.TilsetEntry(36)
|
||||||
|
|
||||||
; Sounds
|
; Sounds
|
||||||
Global MenuSoundStarted = 0
|
Global MenuSoundStarted = 0
|
||||||
|
|
|
@ -31,6 +31,11 @@ Structure GameMenu
|
||||||
List Entries.GameMenuItem()
|
List Entries.GameMenuItem()
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
|
Structure TilsetEntry
|
||||||
|
ID.i
|
||||||
|
Type.i
|
||||||
|
EndStructure
|
||||||
|
|
||||||
Structure Tile
|
Structure Tile
|
||||||
X.i
|
X.i
|
||||||
Y.i
|
Y.i
|
||||||
|
|
Loading…
Reference in a new issue