ld21-ESCape/src/Events.pbi

143 lines
3.9 KiB
Plaintext

; In this file, we handle alle the events
Procedure HandleEventMenu()
If KeyboardReleased(#PB_Key_Up)
PlaySound(0, #PB_Sound_MultiChannel)
Menu_GotoCurrent()
*ActiveMenu\Entries()\Selected = #False
If ListIndex(*ActiveMenu\Entries()) = 0
LastElement(*ActiveMenu\Entries())
Else
PreviousElement(*ActiveMenu\Entries())
EndIf
*ActiveMenu\Entries()\Selected = #True
EndIf
If KeyboardReleased(#PB_Key_Down)
PlaySound(0, #PB_Sound_MultiChannel)
Menu_GotoCurrent()
*ActiveMenu\Entries()\Selected = #False
If ListIndex(*ActiveMenu\Entries()) = (ListSize(*ActiveMenu\Entries())-1)
FirstElement(*ActiveMenu\Entries())
Else
NextElement(*ActiveMenu\Entries())
EndIf
*ActiveMenu\Entries()\Selected = #True
EndIf
; We go to the target game state
If KeyboardReleased(#PB_Key_Return)
PlaySound(1, #PB_Sound_MultiChannel)
Menu_GotoCurrent()
CurrentState = *ActiveMenu\Entries()\TargetState
*ActiveMenu.GameMenu = Menus(CurrentState)
EndIf
EndProcedure
Procedure HandleEventRunningGame()
If KeyboardReleased(#PB_Key_Q)
CurrentState = "MAIN_MENU"
*ActiveMenu.GameMenu = Menus(CurrentState)
EndIf
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
GenerateShadowLayer()
CompilerEndSelect
; Player movement
If KeyboardReleased(#PB_Key_Left) And Player\X > 0
Player\Direction = #PLAYER_DIR_LEFT
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
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-1
Player\Direction = #PLAYER_DIR_RIGHT
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
If Player\X > (Cam\X + Cam\Width - Cam\Padding) And (Cam\X + Cam\Width) < #MAP_WIDTH-1
Cam\X + 1
EndIf
EndIf
If KeyboardReleased(#PB_Key_Up) And Player\Y > 0
Player\Direction = #PLAYER_DIR_UP
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
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-1
Player\Direction = #PLAYER_DIR_DOWN
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
If Player\Y > (Cam\Y + Cam\Height - Cam\Padding) And (Cam\Y + Cam\Height) < #MAP_HEIGHT-1
Cam\Y + 1
EndIf
EndIf
; Digging!
If KeyboardReleased(#PB_Key_Escape)
Define TargetX.i, TargetY.i
; Determine the pixel to destroy
If Player\Direction = #PLAYER_DIR_LEFT And Player\X < #MAP_WIDTH
TargetX = Player\X - 1
TargetY = Player\Y
EndIf
If Player\Direction = #PLAYER_DIR_RIGHT And Player\X > 0
TargetX = Player\X + 1
TargetY = Player\Y
EndIf
If Player\Direction = #PLAYER_DIR_UP And Player\Y > 0
TargetX = Player\X
TargetY = Player\Y -1
EndIf
If Player\Direction = #PLAYER_DIR_DOWN And Player\X < #MAP_HEIGHT
TargetX = Player\X
TargetY = Player\Y + 1
EndIf
; Do something with the block
If TileIsType(#TILESET_TYPE_WALL, TargetX, TargetY)
TileMap(TargetX, TargetY)\Health - 1
If TileMap(TargetX, TargetY)\Health = -1
TileMap(TargetX, TargetY)\TileNumber = #TILESET_TYPE_FLOOR
EndIf
*PlayerNoise\X = TargetX
*PlayerNoise\Y = TargetY
*PlayerNoise\Size = 10
CreateThread(@CalculateNoiseWave(), *PlayerNoise)
EndIf
EndIf
EndProcedure