ld21-ESCape/src/Main.pb

141 lines
3.6 KiB
Plaintext
Raw Normal View History

2011-08-20 14:49:54 +02:00
; ESCape
; LD21 entry
; 2011 - Ruben Mueller, Aaron Mueller
EnableExplicit
2011-08-20 17:49:22 +02:00
; Initialize subsystems
2011-08-20 18:18:52 +02:00
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitSound() = 0
2011-08-20 17:49:22 +02:00
MessageRequester("Error", "Sorry, can't keep up.", 0)
End
EndIf
2011-08-20 14:49:54 +02:00
XIncludeFile "Structs.pbi"
XIncludeFile "Globals.pbi"
XIncludeFile "Functions.pbi"
2011-08-20 20:15:44 +02:00
XIncludeFile "Draw.pbi"
2011-08-20 14:49:54 +02:00
XIncludeFile "Events.pbi"
2011-08-20 17:49:22 +02:00
LoadMap(#DATA_PATH + "maps/joni.tmx")
2011-08-21 02:16:30 +02:00
2011-08-20 14:49:54 +02:00
; Initialize all the variables and stuff. I think we refactor this
; into a separate file if it gets messy.
GameStates("MAIN_MENU")\DrawFun = @DrawMenu()
GameStates("MAIN_MENU")\HandleEventFun = @HandleEventMenu()
2011-08-20 17:49:22 +02:00
GameStates("RLY_QUIT")\DrawFun = @DrawMenu()
GameStates("RLY_QUIT")\HandleEventFun = @HandleEventMenu()
2011-08-20 14:49:54 +02:00
GameStates("RUNNING_GAME")\DrawFun = @DrawRunningGame()
GameStates("RUNNING_GAME")\HandleEventFun = @HandleEventRunningGame()
2011-08-20 17:49:22 +02:00
; Initialize the menus
2011-08-20 16:49:48 +02:00
Menus("MAIN_MENU")\Title = "ESCape"
2011-08-20 14:49:54 +02:00
Define Item.GameMenuItem
Item.GameMenuItem\Label = "Escape now!"
Item.GameMenuItem\Selected = #True
2011-08-20 17:49:22 +02:00
Item.GameMenuItem\TargetState = "RUNNING_GAME"
2011-08-20 14:49:54 +02:00
AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item
Define Item.GameMenuItem
Item.GameMenuItem\Label = "End game"
Item.GameMenuItem\Selected = #False
2011-08-20 17:49:22 +02:00
Item.GameMenuItem\TargetState = "RLY_QUIT"
2011-08-20 14:49:54 +02:00
AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item
2011-08-20 17:49:22 +02:00
Menus("RLY_QUIT")\Title = "Really quit?"
Define Item.GameMenuItem
Item.GameMenuItem\Label = "Yes, let me go!"
Item.GameMenuItem\Selected = #True
Item.GameMenuItem\TargetState = "QUIT"
AddElement(Menus("RLY_QUIT")\Entries())
menus("RLY_QUIT")\Entries() = Item
Define Item.GameMenuItem
Item.GameMenuItem\Label = "No way!"
Item.GameMenuItem\Selected = #False
Item.GameMenuItem\TargetState = "MAIN_MENU"
AddElement(Menus("RLY_QUIT")\Entries())
menus("RLY_QUIT")\Entries() = Item
2011-08-20 16:49:48 +02:00
*ActiveMenu.GameMenu = @Menus(CurrentState)
2011-08-20 14:49:54 +02:00
; Start the main loop which will create the window, wait for events and draw things
; on the screen. To escape from this loop, press ESC or close the window.
If OpenWindow(0, 0, 0, Screen\Width, Screen\Height, title, #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, Screen\Width, Screen\Height, 0, 0, 0)
2011-08-21 16:51:16 +02:00
SetFrameRate(40)
2011-08-20 14:49:54 +02:00
2011-08-21 17:59:16 +02:00
; For Linux compatibility
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
KeyboardMode(#PB_Keyboard_International)
CompilerEndSelect
2011-08-20 20:14:22 +02:00
InitGraphics()
2011-08-20 17:49:22 +02:00
InitTileset()
2011-08-21 17:59:16 +02:00
GenerateShadowLayer()
2011-08-20 17:49:22 +02:00
2011-08-20 14:49:54 +02:00
Repeat
; Event loop
Repeat
Define Event = WindowEvent()
Until Event = 0
2011-08-20 21:40:04 +02:00
; Handle the background music
If CurrentState = "MAIN_MENU" Or CurrentState = "RLY_QUIT"
If MenuSoundStarted = 0
MenuSoundStarted = PlaySound(2, #PB_Sound_MultiChannel|#PB_Sound_Loop)
2011-08-20 22:37:31 +02:00
SoundVolume(2, 50, MenuSoundStarted)
2011-08-20 21:40:04 +02:00
EndIf
Else
StopSound(2, MenuSoundStarted)
MenuSoundStarted = 0
EndIf
2011-08-20 14:49:54 +02:00
; Handle global events
ExamineKeyboard()
If KeyboardReleased(#PB_Key_F)
CloseScreen()
If Fullscreen = 0
OpenScreen(800, 600, 32, Title)
Fullscreen = 1
Else
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)
Fullscreen = 0
EndIf
2011-08-21 16:51:16 +02:00
SetFrameRate(40)
2011-08-20 20:14:22 +02:00
InitGraphics()
2011-08-21 00:06:02 +02:00
InitTileset()
2011-08-20 14:49:54 +02:00
EndIf
2011-08-20 18:44:21 +02:00
; Debug CurrentState
2011-08-20 17:49:22 +02:00
2011-08-20 14:49:54 +02:00
; Handle the events for the current state
GameStates(CurrentState)\HandleEventFun()
; Draw the stuff on the screen
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
2011-08-20 19:42:09 +02:00
If CurrentState <> "QUIT"
2011-08-20 14:49:54 +02:00
GameStates(CurrentState)\DrawFun()
EndIf
Delay(1)
2011-08-20 17:49:22 +02:00
Until CurrentState = "QUIT"
2011-08-20 14:49:54 +02:00
EndIf
2011-08-20 17:04:33 +02:00
2011-08-21 18:19:11 +02:00
End