# Asteroids question

This topic is 5068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
You simply mentioned "C". What API are you using to draw things onto the screen?

##### Share on other sites
I'll be using Allegro.

The question I'm am really interested in is number 2

##### Share on other sites
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).

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
Using the method JasonA mentions, you need to specify the angle in Radians, this is worked out like this

degree * PI/180.0

1. 1
Rutin
62
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633412
• Total Posts
3011754
• ### Who's Online (See full list)

There are no registered users currently online

×