ld21-ESCape/src/Main.pb

125 lines
3 KiB
Text
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 "Draw.pbi"
XIncludeFile "Functions.pbi"
XIncludeFile "Events.pbi"
2011-08-20 17:49:22 +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
2011-08-20 17:40:18 +02:00
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-20 17:49:22 +02:00
InitTileset()
2011-08-20 14:49:54 +02:00
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
2011-08-20 17:49:22 +02:00
Debug CurrentState
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 17:57:26 +02:00
If StartDrawing(ScreenOutput()) And CurrentState <> "QUIT"
2011-08-20 14:49:54 +02:00
GameStates(CurrentState)\DrawFun()
StopDrawing()
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-20 17:40:18 +02:00
End
2011-08-20 17:49:22 +02:00
2011-08-20 17:40:18 +02:00
DataSection
Gfx_Tileset:
2011-08-20 17:49:22 +02:00
IncludeBinary "../data/gfx/tileset01.bmp"