From c8b07c8979c452e34e989fd5c598a53c13bbda23 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Mon, 24 Jan 2011 22:38:39 +0100 Subject: [PATCH] Restructure the project files and start implementing the main menu --- pongr/data/menu.data | 13 +++++++++++ pongr/pongr.pbp | 26 ++++++++++++--------- pongr/{ => src}/Draw.pbi | 5 ++-- pongr/{ => src}/Events.pbi | 2 +- pongr/src/Globals.pbi | 16 +++++++++++++ pongr/{ => src}/Main.pb | 46 +++++++++++++++++++------------------ pongr/{ => src}/Structs.pbi | 8 ++++++- 7 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 pongr/data/menu.data rename pongr/{ => src}/Draw.pbi (75%) rename pongr/{ => src}/Events.pbi (88%) create mode 100644 pongr/src/Globals.pbi rename pongr/{ => src}/Main.pb (76%) rename pongr/{ => src}/Structs.pbi (79%) diff --git a/pongr/data/menu.data b/pongr/data/menu.data new file mode 100644 index 0000000..1f236f1 --- /dev/null +++ b/pongr/data/menu.data @@ -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 + diff --git a/pongr/pongr.pbp b/pongr/pongr.pbp index b239061..700621c 100644 --- a/pongr/pongr.pbp +++ b/pongr/pongr.pbp @@ -10,33 +10,37 @@
- +
- + - + - + - + - + - + - + - + + + + +
- + - +
diff --git a/pongr/Draw.pbi b/pongr/src/Draw.pbi similarity index 75% rename from pongr/Draw.pbi rename to pongr/src/Draw.pbi index 7c32535..59f27b3 100644 --- a/pongr/Draw.pbi +++ b/pongr/src/Draw.pbi @@ -1,15 +1,16 @@ ; Here we draw stuff on screen. These are the dispatch ; functions which wil lbe calles from the state dispatch ; process. + 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 Procedure DrawRunningGame() Box(0, 0, 200, 200, RGB(0, 255, 0)) EndProcedure ; IDE Options = PureBasic 4.51 (Linux - x64) -; CursorPosition = 4 +; CursorPosition = 3 ; Folding = - ; EnableUnicode ; EnableThread diff --git a/pongr/Events.pbi b/pongr/src/Events.pbi similarity index 88% rename from pongr/Events.pbi rename to pongr/src/Events.pbi index 6b9baa5..c86481d 100644 --- a/pongr/Events.pbi +++ b/pongr/src/Events.pbi @@ -9,7 +9,7 @@ EndProcedure Procedure HandleEventRunningGame() EndProcedure ; IDE Options = PureBasic 4.51 (Linux - x64) -; CursorPosition = 9 +; CursorPosition = 2 ; Folding = - ; EnableUnicode ; EnableThread diff --git a/pongr/src/Globals.pbi b/pongr/src/Globals.pbi new file mode 100644 index 0000000..8e4f37a --- /dev/null +++ b/pongr/src/Globals.pbi @@ -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 \ No newline at end of file diff --git a/pongr/Main.pb b/pongr/src/Main.pb similarity index 76% rename from pongr/Main.pb rename to pongr/src/Main.pb index 392e9d1..f5fb882 100644 --- a/pongr/Main.pb +++ b/pongr/src/Main.pb @@ -2,17 +2,15 @@ ; 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 "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() +; 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() @@ -22,35 +20,39 @@ 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") + While Eof(0) = 0 + Debug ReadString(0) + Wend + CloseFile(0) +EndIf -; 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" +Menus("MAIN_MENU")\Title = "Pongr" +Define Item.GameMenuItem Item.GameMenuItem\Label = "Run game" -Item.GameMenuItem\Selected = true +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\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\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" - - +*ActiveMenu.GameMenu = @Menus(CurrentState) ; Initialize subsystems If InitSprite() = 0 Or InitKeyboard() = 0 @@ -67,7 +69,7 @@ If OpenWindow(0, 0, 0, Screen\Width, Screen\Height, title, #PB_Window_ScreenCent Repeat ; Event loop Repeat - Event = WindowEvent() + Define Event = WindowEvent() Until Event = 0 ; 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) EndIf ; IDE Options = PureBasic 4.51 (Linux - x64) -; CursorPosition = 69 -; FirstLine = 48 +; CursorPosition = 71 +; FirstLine = 52 ; EnableXP ; EnableCompileCount = 0 ; EnableBuildCount = 0 \ No newline at end of file diff --git a/pongr/Structs.pbi b/pongr/src/Structs.pbi similarity index 79% rename from pongr/Structs.pbi rename to pongr/src/Structs.pbi index b2269b3..e4629d3 100644 --- a/pongr/Structs.pbi +++ b/pongr/src/Structs.pbi @@ -21,12 +21,18 @@ Structure GameMenuItem Selected.b EndStructure +Structure GameOptionItem + List Options.s() + CurrentPosition.i + Selected.b +EndStructure + Structure GameMenu Title.s List Entries.GameMenuItem() EndStructure ; IDE Options = PureBasic 4.51 (Linux - x64) -; CursorPosition = 25 +; CursorPosition = 12 ; EnableUnicode ; EnableThread ; EnableXP