; Pongr ; Very simple game to get started with PureBasic and the game development. ; 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 Menus("MAIN_MENU")\Title = "Pongr" Define Item.GameMenuItem Item.GameMenuItem\Label = "Run game" 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 = "Options" Item.GameMenuItem\Selected = #False Item.GameMenuItem\TargetState = GameStates("OPTION_MENU") AddElement(Menus("MAIN_MENU")\Entries()) menus("MAIN_MENU")\Entries() = Item Define Item.GameMenuItem Item.GameMenuItem\Label = "Quit" Item.GameMenuItem\Selected = #False Item.GameMenuItem\TargetState = GameStates("RLY_QUIT") AddElement(Menus("MAIN_MENU")\Entries()) menus("MAIN_MENU")\Entries() = Item *ActiveMenu.GameMenu = @Menus(CurrentState) ; 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) ; CursorPosition = 5 ; FirstLine = 4 ; EnableXP ; EnableCompileCount = 0 ; EnableBuildCount = 0