Jump to content
  • Advertisement
Sign in to follow this  
Stompy9999

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Using the method JasonA mentions, you need to specify the angle in Radians, this is worked out like this

degree * PI/180.0

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!