# Asteroids Movement

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

## 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 on other sites
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 on other sites
Thanks doynax,

[lol] It's good to know that without researching the topic I'm heading in a common direction :D.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011722
• ### Who's Online (See full list)

There are no registered users currently online

×