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"> <section name="data">
<explorer view="../../../" pattern="0"/> <explorer view="../../../" pattern="0"/>
<log show="1"/> <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>
<section name="files"> <section name="files">
<file name="src/Draw.pbi"> <file name="src/Draw.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="28d5e79f6b736428c0580d24de3999d6"/> <fingerprint md5="cf228a2c0d45d8e9685f075a4d7e0c99"/>
</file> </file>
<file name="src/Events.pbi"> <file name="src/Events.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="747a1f6142b879e34b60e4c54569359d"/> <fingerprint md5="a0c820e419e497f30bad0b61543b7f25"/>
</file> </file>
<file name="src/Functions.pbi"> <file name="src/Functions.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="5432329922208eb5928dbbb3199025fe"/> <fingerprint md5="ed491d1019ce28aa13abe10d2d379bd9"/>
</file> </file>
<file name="src/Globals.pbi"> <file name="src/Globals.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="4999be0d788b010d35c9c1c51b4cb78d"/> <fingerprint md5="0ac1462aee241a3988087e55d18c4cb6"/>
</file> </file>
<file name="src/Main.pb"> <file name="src/Main.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="67a305c6fba8d36249b37da082e32e72"/> <fingerprint md5="3dbf5809e1f3064215228cb40414399d"/>
</file> </file>
<file name="src/Structs.pbi"> <file name="src/Structs.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
<fingerprint md5="3670b8c0a4f06f32611d8ba08fca9d35"/> <fingerprint md5="251146b13dc31d1bb75e115d1eb6619c"/>
</file> </file>
</section> </section>
<section name="targets"> <section name="targets">

View file

@ -46,22 +46,40 @@ Procedure HandleEventRunningGame()
*ActiveMenu.GameMenu = Menus(CurrentState) *ActiveMenu.GameMenu = Menus(CurrentState)
EndIf EndIf
; Player movement
If KeyboardReleased(#PB_Key_Left) And Player\X > 0 If KeyboardReleased(#PB_Key_Left) And Player\X > 0
Player\X-1 Player\X-1
; Camera positioning
If Player\X < (Cam\X + Cam\Padding) And Cam\X > 0
Cam\X - 1
EndIf
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 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 EndIf
If KeyboardReleased(#PB_Key_Up) And Player\Y > 0 If KeyboardReleased(#PB_Key_Up) And Player\Y > 0
Player\Y-1 Player\Y-1
; Camera positioning
If Player\Y< (Cam\Y + Cam\Padding) And Cam\Y > 0
Cam\Y - 1
EndIf
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 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 EndIf
EndProcedure EndProcedure

View file

@ -30,15 +30,15 @@ EndProcedure
Procedure DrawMap() Procedure DrawMap()
Define X.i ,Y.i Define X.i ,Y.i
For X.i=Cam\X To Cam\X+Cam\Width For X.i=0 To Cam\Width
For Y.i=Cam\Y To Cam\Y+Cam\Height For Y.i=0 To Cam\Height
DrawTile(TileMap(X, Y)\TileNumber, X, Y) DrawTile(TileMap(X+Cam\X, Y+Cam\Y)\TileNumber, X, Y)
Next Next
Next Next
EndProcedure EndProcedure
Procedure DrawPlayer() Procedure DrawPlayer()
DrawTile(Player\TileNumber, Player\X, Player\Y) DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y)
EndProcedure EndProcedure
Procedure DrawHUD() Procedure DrawHUD()

View file

@ -11,15 +11,16 @@ Global Screen.ScreenDimension\width = 800
Screen.ScreenDimension\height = 600 Screen.ScreenDimension\height = 600
; Player ; Player
Global Player.Tile\X = 10 Global Player.Tile\X = 0
Player.Tile\Y = 10 Player.Tile\Y = 0
Player.Tile\TileNumber = 0 Player.Tile\TileNumber = 0
; Camera ; Camera
Global Cam.Camera\X = 0 Global Cam.Camera\X = 0
Cam.Camera\Y = 0 Cam.Camera\Y = 0
Cam.Camera\Width = Screen\Width/#TILE_SIZE Cam.Camera\Width = (Screen\Width/#TILE_SIZE)-1
Cam.Camera\Height = Screen\Height/#TILE_SIZE Cam.Camera\Height = (Screen\Height/#TILE_SIZE)-1
Cam.Camera\Padding = 10
NewMap GameStates.GameState() NewMap GameStates.GameState()
Global NewMap Menus.GameMenu() Global NewMap Menus.GameMenu()
@ -45,8 +46,8 @@ LoadSound(2, #DATA_PATH + "sound/title_song.wav")
; FIXME: JUST FOR DEBUGGING ; FIXME: JUST FOR DEBUGGING
Global Dim TileMap.Tile(#MAP_WIDTH, #MAP_HEIGHT) Global Dim TileMap.Tile(#MAP_WIDTH, #MAP_HEIGHT)
Define x, y Define x, y
For x.i=0 To 120 For x.i=0 To #MAP_WIDTH
For y.i=0 To 120 For y.i=0 To #MAP_HEIGHT
TileMap(x, y)\TileNumber = Random(2)+1 TileMap(x, y)\TileNumber = Random(2)+1
TileMap(x, y)\X = x TileMap(x, y)\X = x
TileMap(x, y)\Y = y TileMap(x, y)\Y = y

View file

@ -14,7 +14,6 @@ Structure GameState
HandleEventFun.HANDLE_EVENTS HandleEventFun.HANDLE_EVENTS
EndStructure EndStructure
Structure GameMenuItem Structure GameMenuItem
Label.s Label.s
TargetState.s TargetState.s
@ -43,4 +42,5 @@ Structure Camera
Y.i Y.i
Width.i Width.i
Height.i Height.i
Padding.i
EndStructure EndStructure