diff --git a/pongr/Draw.pbi b/pongr/Draw.pbi
new file mode 100644
index 0000000..7c32535
--- /dev/null
+++ b/pongr/Draw.pbi
@@ -0,0 +1,18 @@
+; 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))
+EndProcedure
+
+Procedure DrawRunningGame()
+ Box(0, 0, 200, 200, RGB(0, 255, 0))
+EndProcedure
+; IDE Options = PureBasic 4.51 (Linux - x64)
+; CursorPosition = 4
+; Folding = -
+; EnableUnicode
+; EnableThread
+; EnableXP
+; EnableCompileCount = 0
+; EnableBuildCount = 0
\ No newline at end of file
diff --git a/pongr/events.pb b/pongr/Events.pbi
similarity index 67%
rename from pongr/events.pb
rename to pongr/Events.pbi
index 7a6f361..6b9baa5 100644
--- a/pongr/events.pb
+++ b/pongr/Events.pbi
@@ -1,13 +1,15 @@
; In this file, we handle alle the events
-Procedure handle_event_main_menu()
+Procedure HandleEventMenu()
If KeyboardReleased(#PB_Key_U)
Debug "U pressed"
EndIf
EndProcedure
+Procedure HandleEventRunningGame()
+EndProcedure
; IDE Options = PureBasic 4.51 (Linux - x64)
-; CursorPosition = 4
+; CursorPosition = 9
; Folding = -
; EnableUnicode
; EnableThread
diff --git a/pongr/Main.pb b/pongr/Main.pb
new file mode 100644
index 0000000..392e9d1
--- /dev/null
+++ b/pongr/Main.pb
@@ -0,0 +1,105 @@
+; 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
\ No newline at end of file
diff --git a/pongr/README b/pongr/README
index 23b5ec4..8eb0943 100644
--- a/pongr/README
+++ b/pongr/README
@@ -1,13 +1,13 @@
-Simple Pong game to create a basic structure and get a
-actual running game READY TO SHIP!
+Simple Pong game To create a basic Structure And get a
+actual running game READY To SHIP!
To get started, download the official PureBasic book:
http://www.purebasic.fr/english/viewtopic.php?f=14&t=37059
TODO:
- - Adapt the coding styles from Chapter 8 to the code
- - Implement the game menu with the specified structures
- - Add global events for closing the window
+ - Implement the game menu With the specified structures
+ - Add Global events For closing the window
BUGS:
- -
+ - In fullscreen mode, the screen resolution does not change.
+
diff --git a/pongr/structs.pb b/pongr/Structs.pbi
similarity index 65%
rename from pongr/structs.pb
rename to pongr/Structs.pbi
index 09062c4..b2269b3 100644
--- a/pongr/structs.pb
+++ b/pongr/Structs.pbi
@@ -2,31 +2,31 @@
; file we need it.
Structure ScreenDimension
- width.i
- height.i
+ Width.i
+ Height.i
EndStructure
Prototype DRAW()
Prototype HANDLE_EVENTS()
Structure GameState
- draw_fun.DRAW
- handle_event_fun.HANDLE_EVENTS
+ DrawFun.DRAW
+ HandleEventFun.HANDLE_EVENTS
EndStructure
Structure GameMenuItem
- label.s
- target_state.GameState
+ Label.s
+ TargetState.GameState
+ Selected.b
EndStructure
Structure GameMenu
- title.s
- List entries.GameMenuItem()
+ Title.s
+ List Entries.GameMenuItem()
EndStructure
-
; IDE Options = PureBasic 4.51 (Linux - x64)
-; CursorPosition = 16
+; CursorPosition = 25
; EnableUnicode
; EnableThread
; EnableXP
diff --git a/pongr/draw.pb b/pongr/draw.pb
deleted file mode 100644
index b18da1c..0000000
--- a/pongr/draw.pb
+++ /dev/null
@@ -1,14 +0,0 @@
-; Here we drad stuff on screen
-
-Procedure draw_main_nenu()
- Box(0, 0, 200, 200, RGB(255, 0 ,0))
-EndProcedure
-
-; IDE Options = PureBasic 4.51 (Linux - x64)
-; CursorPosition = 5
-; Folding = -
-; EnableUnicode
-; EnableThread
-; EnableXP
-; EnableCompileCount = 0
-; EnableBuildCount = 0
\ No newline at end of file
diff --git a/pongr/pong.pb b/pongr/pong.pb
deleted file mode 100644
index 22ca352..0000000
--- a/pongr/pong.pb
+++ /dev/null
@@ -1,72 +0,0 @@
-; Pongr
-; Very simple game to get started with PureBasic and the game development.
-; 2011 - Ruben Mueller, Aaron Mueller
-
-XIncludeFile "structs.pb"
-XIncludeFile "draw.pb"
-XIncludeFile "events.pb"
-
-; Global variables
-fullscreen = 0
-title.s = "Pongr - Build " + Str(#PB_Editor_BuildCount)
-screen.ScreenDimension\width = 800
-screen.ScreenDimension\height = 600
-
-NewMap game_states.GameState()
-game_states("MAIN_MENU")\draw_fun = @draw_main_nenu()
-game_states("MAIN_MENU")\handle_event_fun = @handle_event_main_menu()
-current_state.s = "MAIN_MENU"
-
-
-; Initialize subsystems
-If InitSprite() = 0 Or InitKeyboard() = 0
- MessageRequester("Error", "Sorry, can't boot 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)
- If OpenWindowedScreen(WindowID(0), 0, 0, screen\width, screen\height, 0, 0, 0)
- EndIf
-
- 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
- game_states(current_state)\handle_event_fun()
-
- ; Draw the stuff on the screen
- FlipBuffers()
- ClearScreen(RGB(0, 0, 0))
- If StartDrawing(ScreenOutput())
- game_states(current_state)\draw_fun()
- StopDrawing()
- EndIf
-
- Delay(1)
- Until KeyboardPushed(#PB_Key_Escape)
-EndIf
-; IDE Options = PureBasic 4.51 (Linux - x64)
-; CursorPosition = 57
-; FirstLine = 23
-; EnableXP
-; EnableCompileCount = 0
-; EnableBuildCount = 0
\ No newline at end of file
diff --git a/pongr/pongr.pbp b/pongr/pongr.pbp
index 8acb58f..b239061 100644
--- a/pongr/pongr.pbp
+++ b/pongr/pongr.pbp
@@ -10,24 +10,24 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+