Apply the coding conventions and the style guide definitions.
This commit is contained in:
parent
d907e0cc9e
commit
f3d824a9c1
8 changed files with 152 additions and 113 deletions
18
pongr/Draw.pbi
Normal file
18
pongr/Draw.pbi
Normal 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
|
|
@ -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
|
105
pongr/Main.pb
Normal file
105
pongr/Main.pb
Normal 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
|
12
pongr/README
12
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.
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -10,24 +10,24 @@
|
|||
<section name="data">
|
||||
<explorer view="../../../" pattern="0"/>
|
||||
<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 name="files">
|
||||
<file name="pong.pb">
|
||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
|
||||
<fingerprint md5="2d2a96e4447872844b4c2183e257eebc"/>
|
||||
<fingerprint md5="35cfac0386dca5b0d79ba8d56fe90bd6"/>
|
||||
</file>
|
||||
<file name="structs.pb">
|
||||
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
|
||||
<fingerprint md5="85e0553420e8dcaef5cd8c0aa2fd7840"/>
|
||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
|
||||
<fingerprint md5="cd8ca8a4160326aa19af1fc08c397322"/>
|
||||
</file>
|
||||
<file name="draw.pb">
|
||||
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
|
||||
<fingerprint md5="0e64513b04987abbba636b341997cad8"/>
|
||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
|
||||
<fingerprint md5="f15a45c2b59304338e9de66ad469e9dd"/>
|
||||
</file>
|
||||
<file name="events.pb">
|
||||
<config load="0" scan="1" panel="1" warn="1" lastopen="0"/>
|
||||
<fingerprint md5="5a5949b45c8ae14dd9585575b5f78e02"/>
|
||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1"/>
|
||||
<fingerprint md5="f31cd410f195d632aae7d67d3dd4fd4a"/>
|
||||
</file>
|
||||
</section>
|
||||
<section name="targets">
|
||||
|
@ -36,7 +36,7 @@
|
|||
<outputfile value="build/pongr"/>
|
||||
<executable value="build/pongr"/>
|
||||
<options thread="1" xpskin="1" debug="1"/>
|
||||
<compilecount enable="1" value="39"/>
|
||||
<compilecount enable="1" value="48"/>
|
||||
<buildcount enable="1" value="4"/>
|
||||
</target>
|
||||
</section>
|
||||
|
|
Reference in a new issue