Restructure the project files and start implementing the main menu

This commit is contained in:
Aaron Mueller 2011-01-24 22:38:39 +01:00
parent f3d824a9c1
commit c8b07c8979
7 changed files with 79 additions and 37 deletions

13
pongr/data/menu.data Normal file
View file

@ -0,0 +1,13 @@
MAIN_MENU "Pongr"
BUTTON: "Run game" -> RUNNING_GAME
BUTTON: "Options" -> OPTION_MENU
BUTTON: "QUIT" -> RLY_QUIT
OPTION_MENU "Options"
OPTION: "Fullscreen", "Window Mode"
BUTTON: "Back" -> MAIN_MENU
RLY_QUIT "You want to go?"
BUTTON: "Yes" -> EXIT
BUTTON: "No" -> MAIN_MENU

View file

@ -10,33 +10,37 @@
<section name="data"> <section name="data">
<explorer view="../../../" pattern="0"/> <explorer view="../../../" pattern="0"/>
<log show="1"/> <log show="1"/>
<lastopen date="2011-01-20 00:52" user="aaron" host="deskFu"/> <lastopen date="2011-01-22 03:17" user="aaron" host="deskFu"/>
</section> </section>
<section name="files"> <section name="files">
<file name="pong.pb"> <file name="src/Main.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/> <config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="35cfac0386dca5b0d79ba8d56fe90bd6"/> <fingerprint md5="29e4b25d47252dd54c24d6985d0e0b94"/>
</file> </file>
<file name="structs.pb"> <file name="src/Structs.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/> <config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="cd8ca8a4160326aa19af1fc08c397322"/> <fingerprint md5="3f6fdbb23e900f0a334f07d26355f27f"/>
</file> </file>
<file name="draw.pb"> <file name="src/Draw.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/> <config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="f15a45c2b59304338e9de66ad469e9dd"/> <fingerprint md5="104d355e87b74fa0e87bef35d6f6d748"/>
</file> </file>
<file name="events.pb"> <file name="src/Events.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/> <config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="f31cd410f195d632aae7d67d3dd4fd4a"/> <fingerprint md5="938263b937dde78242133aac1b4dbb97"/>
</file>
<file name="src/Globals.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="768cb291ebd658155da6c8419e722db8"/>
</file> </file>
</section> </section>
<section name="targets"> <section name="targets">
<target name="Default Target" enabled="1" default="1"> <target name="Default Target" enabled="1" default="1">
<inputfile value="pong.pb"/> <inputfile value="src/Main.pb"/>
<outputfile value="build/pongr"/> <outputfile value="build/pongr"/>
<executable value="build/pongr"/> <executable value="build/pongr"/>
<options thread="1" xpskin="1" debug="1"/> <options thread="1" xpskin="1" debug="1"/>
<compilecount enable="1" value="48"/> <compilecount enable="1" value="50"/>
<buildcount enable="1" value="4"/> <buildcount enable="1" value="4"/>
</target> </target>
</section> </section>

View file

@ -1,15 +1,16 @@
; Here we draw stuff on screen. These are the dispatch ; Here we draw stuff on screen. These are the dispatch
; functions which wil lbe calles from the state dispatch ; functions which wil lbe calles from the state dispatch
; process. ; process.
Procedure DrawMenu() Procedure DrawMenu()
;DrawText(50, 50, Menus(ActiveMenu)\Label, RGB(255, 255, 255), RGB(0, 0, 0)) DrawText(50, 50, *ActiveMenu\Title, RGB(255, 255, 255), RGB(0, 0, 0))
EndProcedure EndProcedure
Procedure DrawRunningGame() Procedure DrawRunningGame()
Box(0, 0, 200, 200, RGB(0, 255, 0)) Box(0, 0, 200, 200, RGB(0, 255, 0))
EndProcedure EndProcedure
; IDE Options = PureBasic 4.51 (Linux - x64) ; IDE Options = PureBasic 4.51 (Linux - x64)
; CursorPosition = 4 ; CursorPosition = 3
; Folding = - ; Folding = -
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread

View file

@ -9,7 +9,7 @@ EndProcedure
Procedure HandleEventRunningGame() Procedure HandleEventRunningGame()
EndProcedure EndProcedure
; IDE Options = PureBasic 4.51 (Linux - x64) ; IDE Options = PureBasic 4.51 (Linux - x64)
; CursorPosition = 9 ; CursorPosition = 2
; Folding = - ; Folding = -
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread

16
pongr/src/Globals.pbi Normal file
View file

@ -0,0 +1,16 @@

; 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()
Global NewMap Menus.GameMenu()
Global CurrentState.s = "MAIN_MENU"
Global *ActiveMenu.GameMenu
; IDE Options = PureBasic 4.51 (Linux - x64)
; CursorPosition = 10
; EnableXP
; EnableCompileCount = 0
; EnableBuildCount = 0

View file

@ -2,17 +2,15 @@
; Very simple game to get started with PureBasic and the game development. ; Very simple game to get started with PureBasic and the game development.
; 2011 - Ruben Mueller, Aaron Mueller ; 2011 - Ruben Mueller, Aaron Mueller
EnableExplicit
XIncludeFile "Structs.pbi" XIncludeFile "Structs.pbi"
XIncludeFile "Globals.pbi"
XIncludeFile "Draw.pbi" XIncludeFile "Draw.pbi"
XIncludeFile "Events.pbi" XIncludeFile "Events.pbi"
; Global variables ; Initialize all the variables and stuff. I think we refactor this
Global Fullscreen = 0 ; into a separate file if it gets messy.
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")\DrawFun = @DrawMenu()
GameStates("MAIN_MENU")\HandleEventFun = @HandleEventMenu() GameStates("MAIN_MENU")\HandleEventFun = @HandleEventMenu()
@ -22,35 +20,39 @@ GameStates("OPTION_MENU")\HandleEventFun = @HandleEventMenu()
GameStates("RUNNING_GAME")\DrawFun = @DrawRunningGame() GameStates("RUNNING_GAME")\DrawFun = @DrawRunningGame()
GameStates("RUNNING_GAME")\HandleEventFun = @HandleEventRunningGame() 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")
While Eof(0) = 0
Debug ReadString(0)
Wend
CloseFile(0)
EndIf
; FIXME: This thing is really awful, we have to find a better Menus("MAIN_MENU")\Title = "Pongr"
; way to define the complete menu. (A simple DSL maybe?)
Global NewMap Menus.GameMenu()
Menus("MAIN_MENU")\title = "Pongr"
Define Item.GameMenuItem
Item.GameMenuItem\Label = "Run game" Item.GameMenuItem\Label = "Run game"
Item.GameMenuItem\Selected = true Item.GameMenuItem\Selected = #True
Item.GameMenuItem\TargetState = GameStates("RUNNING_GAME") Item.GameMenuItem\TargetState = GameStates("RUNNING_GAME")
AddElement(Menus("MAIN_MENU")\Entries()) AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item menus("MAIN_MENU")\Entries() = Item
Define Item.GameMenuItem
Item.GameMenuItem\Label = "Options" Item.GameMenuItem\Label = "Options"
Item.GameMenuItem\Selected = false Item.GameMenuItem\Selected = #False
Item.GameMenuItem\TargetState = GameStates("OPTION_MENU") Item.GameMenuItem\TargetState = GameStates("OPTION_MENU")
AddElement(Menus("MAIN_MENU")\Entries()) AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item menus("MAIN_MENU")\Entries() = Item
Define Item.GameMenuItem
Item.GameMenuItem\Label = "Quit" Item.GameMenuItem\Label = "Quit"
Item.GameMenuItem\Selected = false Item.GameMenuItem\Selected = #False
Item.GameMenuItem\TargetState = GameStates("RLY_QUIT") Item.GameMenuItem\TargetState = GameStates("RLY_QUIT")
AddElement(Menus("MAIN_MENU")\Entries()) AddElement(Menus("MAIN_MENU")\Entries())
menus("MAIN_MENU")\Entries() = Item menus("MAIN_MENU")\Entries() = Item
*ActiveMenu.GameMenu = @Menus(CurrentState)
Global CurrentState.s = "MAIN_MENU"
Global ActiveMenu.s = "MAIN_MENU"
; Initialize subsystems ; Initialize subsystems
If InitSprite() = 0 Or InitKeyboard() = 0 If InitSprite() = 0 Or InitKeyboard() = 0
@ -67,7 +69,7 @@ If OpenWindow(0, 0, 0, Screen\Width, Screen\Height, title, #PB_Window_ScreenCent
Repeat Repeat
; Event loop ; Event loop
Repeat Repeat
Event = WindowEvent() Define Event = WindowEvent()
Until Event = 0 Until Event = 0
; Handle global events ; Handle global events
@ -98,8 +100,8 @@ If OpenWindow(0, 0, 0, Screen\Width, Screen\Height, title, #PB_Window_ScreenCent
Until KeyboardPushed(#PB_Key_Escape) Until KeyboardPushed(#PB_Key_Escape)
EndIf EndIf
; IDE Options = PureBasic 4.51 (Linux - x64) ; IDE Options = PureBasic 4.51 (Linux - x64)
; CursorPosition = 69 ; CursorPosition = 71
; FirstLine = 48 ; FirstLine = 52
; EnableXP ; EnableXP
; EnableCompileCount = 0 ; EnableCompileCount = 0
; EnableBuildCount = 0 ; EnableBuildCount = 0

View file

@ -21,12 +21,18 @@ Structure GameMenuItem
Selected.b Selected.b
EndStructure EndStructure
Structure GameOptionItem
List Options.s()
CurrentPosition.i
Selected.b
EndStructure
Structure GameMenu Structure GameMenu
Title.s Title.s
List Entries.GameMenuItem() List Entries.GameMenuItem()
EndStructure EndStructure
; IDE Options = PureBasic 4.51 (Linux - x64) ; IDE Options = PureBasic 4.51 (Linux - x64)
; CursorPosition = 25 ; CursorPosition = 12
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread
; EnableXP ; EnableXP