2011-08-20 14:49:54 +02:00
|
|
|
; ESCape
|
|
|
|
; LD21 entry
|
|
|
|
; 2011 - Ruben Mueller, Aaron Mueller
|
|
|
|
|
|
|
|
EnableExplicit
|
|
|
|
|
|
|
|
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("OPTION_MENU")\DrawFun = @DrawMenu()
|
|
|
|
GameStates("OPTION_MENU")\HandleEventFun = @HandleEventMenu()
|
|
|
|
|
|
|
|
GameStates("RUNNING_GAME")\DrawFun = @DrawRunningGame()
|
|
|
|
GameStates("RUNNING_GAME")\HandleEventFun = @HandleEventRunningGame()
|
|
|
|
|
|
|
|
; Read the complete game menus from the data/menu.data file.
|
|
|
|
; TODO: IncludeBinary looks interesting!
|
|
|
|
If ReadFile(0, "../data/menu.data")
|
|
|
|
CreateRegularExpression(0, "^([A-Z_-]+) {(.*)}") ; Menu title
|
|
|
|
CreateRegularExpression(1, "^ BUTTON: {(.+)} -> (.+)") ; A button
|
|
|
|
CreateRegularExpression(2, "^ OPTION: (.*)") ; A option field (TODO: Thats not exactly right)
|
|
|
|
|
|
|
|
While Eof(0) = 0
|
|
|
|
Dim Matches$(0)
|
|
|
|
Define Line.s = ReadString(0)
|
|
|
|
|
|
|
|
; We found a new menu
|
|
|
|
If MatchRegularExpression(0, Line)
|
|
|
|
Define i
|
|
|
|
For i=0 To ExtractRegularExpression(0, Line, Matches$())-1
|
|
|
|
Debug Matches$(i) ; FIXME: Thats not what we want ...
|
|
|
|
Next
|
|
|
|
EndIf
|
|
|
|
Wend
|
|
|
|
|
|
|
|
FreeRegularExpression(0)
|
|
|
|
FreeRegularExpression(1)
|
|
|
|
FreeRegularExpression(2)
|
|
|
|
CloseFile(0)
|
|
|
|
EndIf
|
|
|
|
|
2011-08-20 17:00:06 +02:00
|
|
|
InitTileset()
|
|
|
|
|
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
|
|
|
|
Item.GameMenuItem\TargetState = GameStates("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 = GameStates("RLY_QUIT")
|
|
|
|
AddElement(Menus("MAIN_MENU")\Entries())
|
|
|
|
menus("MAIN_MENU")\Entries() = Item
|
|
|
|
|
2011-08-20 16:49:48 +02:00
|
|
|
*ActiveMenu.GameMenu = @Menus(CurrentState)
|
2011-08-20 14:49:54 +02:00
|
|
|
|
|
|
|
; Initialize subsystems
|
|
|
|
If InitSprite() = 0 Or InitKeyboard() = 0
|
|
|
|
MessageRequester("Error", "Sorry, can't keep up.", 0)
|
|
|
|
End
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
; 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)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
; 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())
|
|
|
|
GameStates(CurrentState)\DrawFun()
|
|
|
|
StopDrawing()
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
Delay(1)
|
|
|
|
Until KeyboardPushed(#PB_Key_Escape)
|
|
|
|
EndIf
|
|
|
|
; IDE Options = PureBasic 4.51 (MacOS X - x86)
|
2011-08-20 17:00:06 +02:00
|
|
|
; CursorPosition = 49
|
2011-08-20 14:49:54 +02:00
|
|
|
; EnableXP
|
|
|
|
; EnableCompileCount = 0
|
|
|
|
; EnableBuildCount = 0
|