From 7d1714c88b156a5ab5af7df524b59e77f92f00cf Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Sat, 15 Jan 2011 17:45:37 +0100 Subject: [PATCH] Add game stats and start up form menu structs --- pongr/draw.pb | 14 ++++++++++++++ pongr/events.pb | 16 ++++++++++++++++ pongr/pong.pb | 35 +++++++++++++++++++++-------------- pongr/pongr.pbp | 22 +++++++++++++++++----- pongr/structs.pb | 23 +++++++++++++++++++++-- 5 files changed, 89 insertions(+), 21 deletions(-) create mode 100644 pongr/draw.pb create mode 100644 pongr/events.pb diff --git a/pongr/draw.pb b/pongr/draw.pb new file mode 100644 index 0000000..b18da1c --- /dev/null +++ b/pongr/draw.pb @@ -0,0 +1,14 @@ +; 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/events.pb b/pongr/events.pb new file mode 100644 index 0000000..7a6f361 --- /dev/null +++ b/pongr/events.pb @@ -0,0 +1,16 @@ +; In this file, we handle alle the events + +Procedure handle_event_main_menu() + If KeyboardReleased(#PB_Key_U) + Debug "U pressed" + EndIf +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/pong.pb b/pongr/pong.pb index 657c804..22ca352 100644 --- a/pongr/pong.pb +++ b/pongr/pong.pb @@ -3,20 +3,20 @@ ; 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 -Procedure DrawOnScreen() - CreateSprite(0, 20, 20) - If StartDrawing(SpriteOutput(0)) - Box(0, 0, 20, 20, RGB(255, 0, 155)) - Box(5, 5, 10, 10, RGB(155, 0, 255)) - StopDrawing() - EndIf -EndProcedure +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 @@ -24,6 +24,7 @@ If InitSprite() = 0 Or InitKeyboard() = 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) @@ -36,7 +37,7 @@ If OpenWindow(0, 0, 0, screen\width, screen\height, title, #PB_Window_ScreenCent event = WindowEvent() Until event = 0 - ; Handle input + ; Handle global events ExamineKeyboard() If KeyboardReleased(#PB_Key_F) CloseScreen() @@ -49,17 +50,23 @@ If OpenWindow(0, 0, 0, screen\width, screen\height, title, #PB_Window_ScreenCent 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, 200, 0)) - DrawOnScreen() + 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 = 23 -; FirstLine = 12 -; Folding = - +; 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 4bdc030..8acb58f 100644 --- a/pongr/pongr.pbp +++ b/pongr/pongr.pbp @@ -10,12 +10,24 @@
- +
- + + + + + + + + + + + + +
@@ -23,9 +35,9 @@ - - - + + +
diff --git a/pongr/structs.pb b/pongr/structs.pb index b67e6a8..09062c4 100644 --- a/pongr/structs.pb +++ b/pongr/structs.pb @@ -6,10 +6,29 @@ Structure ScreenDimension height.i EndStructure +Prototype DRAW() +Prototype HANDLE_EVENTS() + +Structure GameState + draw_fun.DRAW + handle_event_fun.HANDLE_EVENTS +EndStructure + + +Structure GameMenuItem + label.s + target_state.GameState +EndStructure + +Structure GameMenu + title.s + List entries.GameMenuItem() +EndStructure + ; IDE Options = PureBasic 4.51 (Linux - x64) -; CursorPosition = 7 +; CursorPosition = 16 ; EnableUnicode ; EnableThread ; EnableXP -; EnableCompileCount = 0 +; EnableCompileCount = 1 ; EnableBuildCount = 0 \ No newline at end of file