ship

Final Project, asteroids clone

 

stuff2

 

 

Asteroids has always been a game that I’ve enjoyed so I thought recreating the game would be fun.  After the math for spinning the main character was finished writing the code wasn’t very difficult.

 

Here check it out: http://www.openprocessing.org/sketch/200841

p.s. link may not work, still working out the issues between java and java script

 

Basically the game is my attempt at making a game that works similarly to the game asteroids.  You can fly the ship around and shoot the asteroids into tiny pieces.  There is still many things I wish to do cosmetically but this is the main functions of the game.  Your goal is to destroy ever asteroid on the map before crashing into any them.  More asteroids will spawn the longer you play, so in order to win you must work quickly.

 

 

GAME SETUP

:ship

The setup function spawns the world,  player, and the asteroids. Both the player and the asteroids are array lists.  The asteroids size, velocities, color, and positions are all random.  While the player spawns in the same spot every time.   The code will also check to make sure the asteroids do not spawn to close to the player to prevent fast deaths seconds after the game starts.

 

DRAW:

The draw function runs the entire game as well as keeps track of score, winning, and loosing.

 

TRICKY PARTS:

Again the hardest part for me was  getting the player to rotate and then have the bullets shoot out of the front of the ship. Here is some code that makes it possible.

THIS IS THE CODE TO DRAW THE PLAYER EACH FRAME:

triangle( posx + 10*cos(theta), posy + 10*sin(theta)
posx + 5*cos(theta + 2*PI/3), posy + 5*sin(theta+2*PI/3),
posx + 5*cos(theta + 4*PI/3), posy + 5*sin(theta+4*PI/3) );

Theta is passed to the drawPlayer() function to help update the players position.

 

THIS IS THE CODE TO CHANGE THETA TO ROTATE THE PLAYER:

 

 void rotatePlayer(float amt)
}
theta = theta + amt;
}

When I call the rotate function I will give a value to amt, right now it is .1 so the player changes its rotation by .1 degree each frame the right arrow key is pushed down, and -.1 when the left arrow key is pushed down.  This way i can change how fast the player rotates easily.
THIS IS THE CODE TO MAKE THE PLAYER GO FORWARD IN THE DIRECTION IT IS POINTING:

void fireEngines()
{
velx = velx + 2 * cos(theta);
vely = vely + 2 * sin(theta);
}

The trig insures the player flies in the direction it is pointing towards

 

FUTURE PLANS:

I have many ambitions for the project and because of how much fun I’ve had I will continue to work on the game. I plan to properly make the physics right when the asteroids explode as well as add sound, music, animations for the destruction of the player and asteroids, and power ups.

Leave a Reply

Your email address will not be published. Required fields are marked *