Jump to content
  • Advertisement
Sign in to follow this  
toXic1337

Asteroids Movement

This topic is 4818 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

Hey everybody, I'm currently trying to make an asteroids clone and I'm at the moment trying to create some sort of movement system. I know its movement direction is based on the angle the ship is facing and then when pressing a "thrust" button, the game uses sin(radian) and cos(radian) to get the y and x velocity, respectively. Basically, I'm just looking for the common way of doing this. Here's my dilemma. My ship class's (x,y) values and even its velocity and acceleration variables are set up as integers and I want to keep it that way. BUT, when you take the cos(pi/4) you are going to get a decimal. And if I cast this to my integer velocities, it either converts to 1 or 0. (Because nothing on the unit circle is > 1. SO, I'm thinking... what should I do. I believe I could just multiply whatever I get from my trig calculations by a common value and then apply that value to the velocity but like I've said I'm looking for a common way of doing this. I'm kind of worried that between rotation, particle_systems, and these calculations, I may end up with a considerable performance decrease. I hope this doesn't sound confusing at all. Thanks in Advance for Advice, toXic1337 [EDIT] Not that I think it matters for this is mainly theory, but just in case Using SDL with Dev-C++

Share this post


Link to post
Share on other sites
Advertisement
Yes, that should work. Pick a power-of-two scaling factor to get some performance out of it.
The technique itself is called fixed-point math.

Be sure to precalculate the sine/cosine tables if you're worried about the performance of using fixed-point integers. A single such call, especially on a machine without floating-point support (I assume that's why you want to avoid them), would outweight any integer operations you'll have to perform by an order of magnitude or two.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!