Game Development Reference
In-Depth Information
And that is all you need to know to produce a nice 2D game with OpenGL ES. Note how we
still separate the game logic and the presentation from each other. A caveman does not need
to know that he is being rendered. He therefore doesn't keep any rendering-related members,
such as an Animation instance or a Texture . All we need to do is keep track of the state of the
caveman, and how long he's been in that state. Together with his position and size, we can then
easily render him by using our little helper classes.
Summary
You should now be well equipped to create almost any 2D game you want. We've learned about
vectors and how to work with them, resulting in a nice, reusable Vector2 class. We also looked
into basic physics for creating things like ballistic cannonballs. Collision detection is also a
vital part of most games, and you should now know how to do it correctly and efficiently via a
SpatialHashGrid . We explored a way to keep our game logic and objects separated from the
rendering by creating GameObject and DynamicGameObject classes that keep track of the state
and shape of objects. We covered how easy it is to implement the concept of a 2D camera via
OpenGL ES, all based on a single method called glOrthof() . We learned about texture atlases,
why we need them, and how we can use them. This was expanded by introducing texture
regions, sprites, and how we can render them efficiently via a SpriteBatcher . Finally, we looked
into sprite animations, which turn out to be extremely simple to implement.
It should be worth noting that all of the topics covered in this chapter, including broad- and
narrow-phase collision detection, physics simulation, movement integration, and differently
shaped bounds are implemented robustly in many open source libraries, such as Box2D,
Chipmunk Physics, Bullet Physics, and more. All of these libraries were originally developed in
C or C++, but there are Android wrappers or Java implementations for a few that make them
options worth checking out as you plan your game.
In the next chapter, we'll create a new game with our new tools . You'll be surprised how
easy it is.
 
Search WWH ::




Custom Search