ld21-ESCape/src/Main.pb
Ruben Müller d68b5d32e9 merge
2011-08-20 18:45:05 +02:00

115 lines
2.9 KiB
Text

; ESCape
; LD21 entry
; 2011 - Ruben Mueller, Aaron Mueller
EnableExplicit
; Initialize subsystems
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitSound() = 0
MessageRequester("Error", "Sorry, can't keep up.", 0)
End
EndIf
XIncludeFile "Structs.pbi"
XIncludeFile "Globals.pbi"
XIncludeFile "Draw.pbi"
XIncludeFile "Functions.pbi"
XIncludeFile "Events.pbi"
; 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()
GameStates("RLY_QUIT")\DrawFun = @DrawMenu()
GameStates("RLY_QUIT")\HandleEventFun = @HandleEventMenu()
GameStates("RUNNING_GAME")\DrawFun = @DrawRunningGame()
GameStates("RUNNING_GAME")\HandleEventFun = @HandleEventRunningGame()
; Initialize the menus
Menus("MAIN_MENU")\Title = "ESCape"
Define Item.GameMenuItem
Item.GameMenuItem\Label = "Escape now!"
Item.GameMenuItem\Selected = #True
Item.GameMenuItem\TargetState = "RUNNING_GAME"
AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item
Define Item.GameMenuItem
Item.GameMenuItem\Label = "End game"
Item.GameMenuItem\Selected = #False
Item.GameMenuItem\TargetState = "RLY_QUIT"
AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item
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
*ActiveMenu.GameMenu = @Menus(CurrentState)
; 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)
InitTileset()
Repeat
; Event loop
Repeat
Define Event = WindowEvent()
Until Event = 0
; 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
EndIf
; Debug CurrentState
; Handle the events for the current state
GameStates(CurrentState)\HandleEventFun()
; Draw the stuff on the screen
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
If StartDrawing(ScreenOutput()) And CurrentState <> "QUIT"
GameStates(CurrentState)\DrawFun()
StopDrawing()
EndIf
Delay(1)
Until CurrentState = "QUIT"
EndIf
End