From ad91d81b01416fe422a0eec8365bf8507d4e945b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20Mu=CC=88ller?= Date: Sat, 20 Aug 2011 23:51:33 +0200 Subject: [PATCH] player and camera movement done! --- escape.pbp | 14 +++++++------- src/Events.pbi | 34 ++++++++++++++++++++++++++-------- src/Functions.pbi | 8 ++++---- src/Globals.pbi | 13 +++++++------ src/Structs.pbi | 2 +- 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/escape.pbp b/escape.pbp index 6adccfc..8236ef9 100644 --- a/escape.pbp +++ b/escape.pbp @@ -10,32 +10,32 @@
- +
- + - + - + - + - + - +
diff --git a/src/Events.pbi b/src/Events.pbi index bfe8f63..8bcf16e 100644 --- a/src/Events.pbi +++ b/src/Events.pbi @@ -46,22 +46,40 @@ Procedure HandleEventRunningGame() *ActiveMenu.GameMenu = Menus(CurrentState) EndIf + ; Player movement If KeyboardReleased(#PB_Key_Left) And Player\X > 0 Player\X-1 + + ; Camera positioning + If Player\X < (Cam\X + Cam\Padding) And Cam\X > 0 + Cam\X - 1 + EndIf EndIf - If KeyboardReleased(#PB_Key_Right) And Player\X <= #MAP_WIDTH + If KeyboardReleased(#PB_Key_Right) And Player\X < #MAP_WIDTH Player\X+1 + + ; Camera positioning + If Player\X > (Cam\X + Cam\Width - Cam\Padding) And (Cam\X + Cam\Width) < #MAP_WIDTH + Cam\X + 1 + EndIf EndIf If KeyboardReleased(#PB_Key_Up) And Player\Y > 0 Player\Y-1 - EndIf - - If KeyboardReleased(#PB_Key_Down) And Player\Y <= #MAP_HEIGHT - Player\Y+1 - EndIf - - + ; Camera positioning + If Player\Y< (Cam\Y + Cam\Padding) And Cam\Y > 0 + Cam\Y - 1 + EndIf + EndIf + + If KeyboardReleased(#PB_Key_Down) And Player\Y < #MAP_HEIGHT + Player\Y+1 + + ; Camera positioning + If Player\Y > (Cam\Y + Cam\Height - Cam\Padding) And (Cam\Y + Cam\Height) < #MAP_HEIGHT + Cam\Y + 1 + EndIf + EndIf EndProcedure \ No newline at end of file diff --git a/src/Functions.pbi b/src/Functions.pbi index 6adefef..84848d9 100644 --- a/src/Functions.pbi +++ b/src/Functions.pbi @@ -30,15 +30,15 @@ EndProcedure Procedure DrawMap() Define X.i ,Y.i - For X.i=Cam\X To Cam\X+Cam\Width - For Y.i=Cam\Y To Cam\Y+Cam\Height - DrawTile(TileMap(X, Y)\TileNumber, X, Y) + For X.i=0 To Cam\Width + For Y.i=0 To Cam\Height + DrawTile(TileMap(X+Cam\X, Y+Cam\Y)\TileNumber, X, Y) Next Next EndProcedure Procedure DrawPlayer() - DrawTile(Player\TileNumber, Player\X, Player\Y) + DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y) EndProcedure Procedure DrawHUD() diff --git a/src/Globals.pbi b/src/Globals.pbi index 4411e12..a2e07f1 100644 --- a/src/Globals.pbi +++ b/src/Globals.pbi @@ -11,15 +11,16 @@ Global Screen.ScreenDimension\width = 800 Screen.ScreenDimension\height = 600 ; Player -Global Player.Tile\X = 10 -Player.Tile\Y = 10 +Global Player.Tile\X = 0 +Player.Tile\Y = 0 Player.Tile\TileNumber = 0 ; Camera Global Cam.Camera\X = 0 Cam.Camera\Y = 0 -Cam.Camera\Width = Screen\Width/#TILE_SIZE -Cam.Camera\Height = Screen\Height/#TILE_SIZE +Cam.Camera\Width = (Screen\Width/#TILE_SIZE)-1 +Cam.Camera\Height = (Screen\Height/#TILE_SIZE)-1 +Cam.Camera\Padding = 10 NewMap GameStates.GameState() Global NewMap Menus.GameMenu() @@ -45,8 +46,8 @@ LoadSound(2, #DATA_PATH + "sound/title_song.wav") ; FIXME: JUST FOR DEBUGGING Global Dim TileMap.Tile(#MAP_WIDTH, #MAP_HEIGHT) Define x, y -For x.i=0 To 120 - For y.i=0 To 120 +For x.i=0 To #MAP_WIDTH + For y.i=0 To #MAP_HEIGHT TileMap(x, y)\TileNumber = Random(2)+1 TileMap(x, y)\X = x TileMap(x, y)\Y = y diff --git a/src/Structs.pbi b/src/Structs.pbi index 042bb35..307bb02 100644 --- a/src/Structs.pbi +++ b/src/Structs.pbi @@ -14,7 +14,6 @@ Structure GameState HandleEventFun.HANDLE_EVENTS EndStructure - Structure GameMenuItem Label.s TargetState.s @@ -43,4 +42,5 @@ Structure Camera Y.i Width.i Height.i + Padding.i EndStructure