This repository has been archived on 2021-11-09. You can view files and clone it, but cannot push or open issues or pull requests.
pongr/pongr/Main.pb

105 lines
2.9 KiB
Plaintext

; Pongr
; Very simple game to get started with PureBasic and the game development.
; 2011 - Ruben Mueller, Aaron Mueller
XIncludeFile "Structs.pbi"
XIncludeFile "Draw.pbi"
XIncludeFile "Events.pbi"
; Global variables
Global Fullscreen = 0
Global Title.s = "Pongr - Build " + Str(#PB_Editor_BuildCount)
Global Screen.ScreenDimension\width = 800
Screen.ScreenDimension\height = 600
NewMap GameStates.GameState()
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()
; FIXME: This thing is really awful, we have to find a better
; way to define the complete menu. (A simple DSL maybe?)
Global NewMap Menus.GameMenu()
Menus("MAIN_MENU")\title = "Pongr"
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
Item.GameMenuItem\Label = "Options"
Item.GameMenuItem\Selected = false
Item.GameMenuItem\TargetState = GameStates("OPTION_MENU")
AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item
Item.GameMenuItem\Label = "Quit"
Item.GameMenuItem\Selected = false
Item.GameMenuItem\TargetState = GameStates("RLY_QUIT")
AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item
Global CurrentState.s = "MAIN_MENU"
Global ActiveMenu.s = "MAIN_MENU"
; 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
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 (Linux - x64)
; CursorPosition = 69
; FirstLine = 48
; EnableXP
; EnableCompileCount = 0
; EnableBuildCount = 0