Game Development Reference
In-Depth Information
Prototyping The Game
Warming up was really important, but let's combine everything we learned, add some new
challenges, and build a small prototype with following features:
1.
Camera loosely follows tank.
2.
Camera zooms automatically depending on tank speed.
3.
You can temporarily override automatic camera zoom using keyboard.
4.
Music and sound effects.
5.
Randomly generated map.
6.
Two modes: menu and gameplay.
7.
Tank movement with WADS keys.
8.
Tank aiming and shooting with mouse.
9.
Collision detection (tanks don't swim).
10.
Explosions, visible bullet trajectories.
11.
Bullet range limiting.
Sounds fun? Hell yes! However, before we start, we should plan ahead a little and think
how our game architecture will look like. We will also structure our code a little, so it will
not be smashed into one ruby class, as we did in earlier examples. Topics should show good
manners!
Switching Between Game States
State pattern
naturally comes to mind.
So, our
GameWindow
class could look like this:
03-prototype/game_window.rb
1
class
GameWindow
<
Gosu
::
Window
2
3
attr_accessor
:state
4
5
def
initialize
6
super
(
800
,
600
,
false
)
7
end