player and camera movement done!

This commit is contained in:
Ruben Müller 2011-08-20 23:51:33 +02:00
parent 480ddca935
commit ad91d81b01
5 changed files with 45 additions and 26 deletions

View file

@ -10,32 +10,32 @@
<section name="data">
<explorer view="../../../" pattern="0"/>
<log show="1"/>
<lastopen date="2011-08-20 19:33" user="rubenmueller" host="localhost"/>
<lastopen date="2011-08-20 22:58" user="rubenmueller" host="localhost"/>
</section>
<section name="files">
<file name="src/Draw.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="28d5e79f6b736428c0580d24de3999d6"/>
<fingerprint md5="cf228a2c0d45d8e9685f075a4d7e0c99"/>
</file>
<file name="src/Events.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="747a1f6142b879e34b60e4c54569359d"/>
<fingerprint md5="a0c820e419e497f30bad0b61543b7f25"/>
</file>
<file name="src/Functions.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="5432329922208eb5928dbbb3199025fe"/>
<fingerprint md5="ed491d1019ce28aa13abe10d2d379bd9"/>
</file>
<file name="src/Globals.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="4999be0d788b010d35c9c1c51b4cb78d"/>
<fingerprint md5="0ac1462aee241a3988087e55d18c4cb6"/>
</file>
<file name="src/Main.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="67a305c6fba8d36249b37da082e32e72"/>
<fingerprint md5="3dbf5809e1f3064215228cb40414399d"/>
</file>
<file name="src/Structs.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="3670b8c0a4f06f32611d8ba08fca9d35"/>
<fingerprint md5="251146b13dc31d1bb75e115d1eb6619c"/>
</file>
</section>
<section name="targets">

View file

@ -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
; 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
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

View file

@ -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()

View file

@ -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

View file

@ -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