Apply the coding conventions and the style guide definitions.

This commit is contained in:
Aaron Mueller 2011-01-20 22:09:31 +01:00
parent d907e0cc9e
commit f3d824a9c1
8 changed files with 152 additions and 113 deletions

18
pongr/Draw.pbi Normal file
View file

@ -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

View file

@ -1,13 +1,15 @@
; In this file, we handle alle the events ; In this file, we handle alle the events
Procedure handle_event_main_menu() Procedure HandleEventMenu()
If KeyboardReleased(#PB_Key_U) If KeyboardReleased(#PB_Key_U)
Debug "U pressed" Debug "U pressed"
EndIf EndIf
EndProcedure EndProcedure
Procedure HandleEventRunningGame()
EndProcedure
; IDE Options = PureBasic 4.51 (Linux - x64) ; IDE Options = PureBasic 4.51 (Linux - x64)
; CursorPosition = 4 ; CursorPosition = 9
; Folding = - ; Folding = -
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread

105
pongr/Main.pb Normal file
View file

@ -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

View file

@ -1,13 +1,13 @@
Simple Pong game to create a basic structure and get a Simple Pong game To create a basic Structure And get a
actual running game READY TO SHIP! actual running game READY To SHIP!
To get started, download the official PureBasic book: To get started, download the official PureBasic book:
http://www.purebasic.fr/english/viewtopic.php?f=14&t=37059 http://www.purebasic.fr/english/viewtopic.php?f=14&t=37059
TODO: TODO:
- Adapt the coding styles from Chapter 8 to the code - Implement the game menu With the specified structures
- Implement the game menu with the specified structures - Add Global events For closing the window
- Add global events for closing the window
BUGS: BUGS:
- - In fullscreen mode, the screen resolution does not change.

View file

@ -2,31 +2,31 @@
; file we need it. ; file we need it.
Structure ScreenDimension Structure ScreenDimension
width.i Width.i
height.i Height.i
EndStructure EndStructure
Prototype DRAW() Prototype DRAW()
Prototype HANDLE_EVENTS() Prototype HANDLE_EVENTS()
Structure GameState Structure GameState
draw_fun.DRAW DrawFun.DRAW
handle_event_fun.HANDLE_EVENTS HandleEventFun.HANDLE_EVENTS
EndStructure EndStructure
Structure GameMenuItem Structure GameMenuItem
label.s Label.s
target_state.GameState TargetState.GameState
Selected.b
EndStructure 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 = 16 ; CursorPosition = 25
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread
; EnableXP ; EnableXP

View file

@ -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

View file

@ -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

View file

@ -10,24 +10,24 @@
<section name="data"> <section name="data">
<explorer view="../../../" pattern="0"/> <explorer view="../../../" pattern="0"/>
<log show="1"/> <log show="1"/>
<lastopen date="2011-01-15 17:39" user="aaron" host="deskFu"/> <lastopen date="2011-01-20 00:52" user="aaron" host="deskFu"/>
</section> </section>
<section name="files"> <section name="files">
<file name="pong.pb"> <file name="pong.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="2d2a96e4447872844b4c2183e257eebc"/> <fingerprint md5="35cfac0386dca5b0d79ba8d56fe90bd6"/>
</file> </file>
<file name="structs.pb"> <file name="structs.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="85e0553420e8dcaef5cd8c0aa2fd7840"/> <fingerprint md5="cd8ca8a4160326aa19af1fc08c397322"/>
</file> </file>
<file name="draw.pb"> <file name="draw.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="0e64513b04987abbba636b341997cad8"/> <fingerprint md5="f15a45c2b59304338e9de66ad469e9dd"/>
</file> </file>
<file name="events.pb"> <file name="events.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/> <config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
<fingerprint md5="5a5949b45c8ae14dd9585575b5f78e02"/> <fingerprint md5="f31cd410f195d632aae7d67d3dd4fd4a"/>
</file> </file>
</section> </section>
<section name="targets"> <section name="targets">
@ -36,7 +36,7 @@
<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="39"/> <compilecount enable="1" value="48"/>
<buildcount enable="1" value="4"/> <buildcount enable="1" value="4"/>
</target> </target>
</section> </section>