Skip to main content
GameDev.net gamedev.net
🔒 Locked

Asteroids question

Started by Stompy9999 Jan 4, 2005 at 9:32 AM 5 replies 650+ views
Original Post
Stompy9999
Stompy9999
I am interested in making an asteroids clone with C. I have a few questions though: 1. How do you rotate the ship then draw the ship rotated? 2. How do you calculate what direction the bullet will go? 3. How do you break the asteroids into smaller pieces? any help would be great. Thanks.
Ilici
Ilici
You simply mentioned "C". What API are you using to draw things onto the screen?
Ilici
Ilici
The direction is a vector, set the velocity equal to this vector times a constant.

To rotate the direction around your ship use an angle which you increment or decrmenet. Then your direction will have x = cos(angle) and y = sin(angle).
JasonA
JasonA
Just to elaborate on Ilici's post:

1. How do you rotate the ship then draw the ship rotated?
Have a direction variable which stores the ship's current angle. Increment or decrement the direction depending on if the player is pressing left or right. I'm not very familiar with Allegro, but you'll have to use a rotation function to draw the ship. Just check the docs.

2. How do you calculate what direction the bullet will go?
Using the direction variable,
bulletVelocityX = maxSpeed * cos(direction)
bulletVelocityY = maxSpeed * sin(direction)

3. How do you break the asteroids into smaller pieces?
This is entirely up to your design. You could have smaller asteroid graphics and just add them to your linked list/array of asteroids or whatever. Or you could be using vectors for the graphics.
Jason Arorajason@pubism.comhttp://www.pubism.com
Stompy9999
Stompy9999
Would I use a 360 degree number for the direction variable or would I just use the number of actual directions the ship can turn in?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.