My first game!

Posted by Protostome | Posted in , , | Posted on 12:09 PM

1


I wasn't planning on publishing my journey towards a *Really* famous game developer, but it keeps me motivated , and thinking that people will actually play those games, make me invest much more thought and effort on creating some well designed bug free games.
If you're on a similar journey and also documenting it on a blog, send me a message ... ^_^

Anyway, as my first game , I chose to program a *very* simple version of Arkanoid.

You can see that the graphics are very simple -
colored rectangles as bricks, a long white rectangle as a "paddle" (I called it deflector... :-))
and a ball.

Additional features include:
  1. "power capsules" (the little triangles) that appear when the ball collides with some of the bricks. those capsules add additional abilities if encountered by the paddle: cannon, additional ball, increase \ decrease the paddle's width... and that's it :-)
  2. A relatively realistic movement of the paddle - i.e collision with either side of the window revert the paddle to the opposite direction - simulating a real collision etc..
I used opengl for the graphical part of the game, for example this code snippet create each one of the bricks:


glColor3ubv(colors[_colorCode]);
glBegin( GL_QUADS );
glVertex2f(_x,_y);
glVertex2f(_x+BRICKW,_y);
glVertex2f(_x+BRICKW,_y+BRICKH);
glVertex2f(_x,_y+BRICKH);
glEnd();



Basic design issues:
Each object involved in the actual game
(bricks, ball, paddle... etc - every item that requires drawing)
inherits from a "Shape" object, that contain x,y coordinates and other basic parameters.

Also ,to represent the power capsules I created an "Artifact" class which all power capsules inherit from.
It has an abstract methos "Act" that each power capsule implement.

class Artifact: public Shape {
private:
float _speedY;
Artifact();
protected:
GLubyte _color[3];
public:
Artifact(float x, float y);
virtual void draw();
virtual void act(Game* g) = 0;
bool detectDeflectorCol(Deflector& d);
void move();
virtual ~Artifact();
};


This function receives a pointer to the Game class (the place where all the really fun stuff happen) and each power capsule implements it according to their specific feature.
For example:


void LargeDeflectorArtifact::act(Game* g){
Deflector* d = g->getDeflector();
d->setWidth(std::min(d->getWidth()+Deflector::WIDTHDIFF,(float)MAXWIDTH));
}


for more technical (and maybe boring...) information you can download my (partly documented) code. it should compile both in Windows (didn't try!) and Linux (I usually use Ubuntu Linux BTW)

(some) Known issues:
Collision detection could be improved, the ball sometime gets stuck on the paddle's side (need to handle collisions on the sides of the paddle...)
Collision detection was implemented several times , sometimes unnecessarily. If I had time to redesign the class I would have created a template class\method that deals with collisions; template params are two objects, and the output should be a boolean ..

The next stop on my journey: A Tetris game using SDL.
I think tetris is a little bit simpler to implement, I'm doing this in order to actually learn how to program using the SDL API.
glut is a very basic library ; it doesn't handle any sound effects or anything like that - just a simple window for graphics drawing - and it is simply not enough for more serious games.

For your amusement - a video of some of the gameplay:



Until my next post - see ya! :)