Bunnyroids

David Cuddeback
CSC-471, Spring 2009

Contents

Gameplay

Bunnyroids is like Asteroids... with bunnies!

Bunnyroids starts with a few very large, but slow-moving bunnies that are out to get you. When you shoot a bunny, it multiplies (like bunnies tend to do) into a few more smaller bunnies. When you shoot the smaller bunnies, they multiply into even smaller bunnies. There are three sizes of bunnies. When a bunny of the smallest size is shot, it disappears for good without reproducing.

Gameplay ends when all the bunnies are shot or a bunny attacks the player. The player wins by eliminating all the bunnies. If a bunny is allowed to get too close to the player, the player loses.

Controls

The player moves with the WSAD keys and looks and fires with the mouse. Clicking the left mouse button fires a ball in the direction of the camera's boresite.

Key Control
W Move forward
S Move backward
A Strafe left
D Strafe right
Left Mouse Fire
Mouse Move Rotate camera
Q Quit

Collision Detection

Bunnyroids uses very simple collision detection. Everything except the walls are assumed to be spherical, thus most collision detection is testing if two objects are closer than the sum of their radii. Since the bunnies aren't perfectly round, this isn't a perfect model. Sometimes, collisions will be detected when the ball should miss the bunny, and sometimes a collision will be missed when the ball passes through the bunny.

Since the walls are at known locations, testing collisions with the walls is testing whether an object is beyond the wall's distance minus the object's radius. This is used to keep the player and bunnies within the playing field.

"Artificial Intelligence"

It's not advanced AI by any stretch of the imagination, but bunnies will tend to gravitate toward the player. This is implemented as a gravity vector (a constant divided by the square of the distance between the bunny and the player, set in the direction from the bunny toward the player). This gravity vector is added to the bunny's velocity in each frame. This results in some bunnies sneaking up behind the player. This has an amusing side effect that it's possible for a bunny to go into "orbit" around the player, effectively never reaching the player.

Graphics

Lighting

Bunnyroids uses the simple Phong lighting model built into OpenGL. The game uses five light sources. These are a white directional light shining down from the top and four colored point light sources in each corner of the map. The point lights have linear and quadratic attenuation parameters to make them appear to be lamps located in the corners of the map. The point lights cast a glow on the walls, ground, and any objects (bunnies or balls) near the light source.

Display Lists

Since Bunnyroids can potentially involve lots of polygons, display lists are used to optimize rendering. Many bunnies are rendered in each frame, but each uses the same mesh, so a display list is used so that the bunnies' geometry doesn't have to be sent down the graphics pipeline 50 times every frame.

To make the attenuation of the point light sources work correctly, the walls and ground had to be subdivided into many smaller polygons. Each wall is 64 polygons wide by 8 polygons tall, and the ground is 10 by 10 polygons. That's a total of 2,148 polygons that have to be rendered each frame, and since the geometry of the world doesn't change, it is a good candidate for display lists.

Texture Mapping

All the geometry in Bunnyroids is texture mapped with mipmapping. For the walls, a texture of a single cinder block was downloaded, then edited to produce a staggered pattern. The wall and ground textures look best when tiled. However, instead of relying on tiling properties GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T, the geometry was subdivided into polygons, each spanning the texture coordinates (0, 0) to (1, 1). It was done this way because subdividing the geometry was already required to make the lighting look good.

Download

The source code and a Unix Makefile are provided here. Glut and g++ must be installed to compile Bunnyroids. Type make to compile, ./bunnyroids to run, or optionally make run to compile and run.

References

I relied heavily on the man pages hosted at opengl.org and tutorials at gamedev.net. I retrieved my textures from Google Image Search.