For making an asteroid game,
I found it hard at first but it’s quite easy.
One of Newton’s law : In the absence of a net external force, a body either is at rest or moves with constant velocity.
We are evolving in space so the last phrase part is our algorithm.
But you might have encountered some problems if you are very new to games programming, like how do I make all these things move ?
It’s simple,
- When you change the direction of your ship, you need to keep a reference of the angle your ship is pointing at.
- With this angle, using trigonometry you will get a vector which is what you need.
And math magics will do the rest !
There are a couple of other issues you need to handle like,
- Limiting velocity of your ship or soon it will go very fast,
- Wrap your angle,
- Screen dimensions,
- etc …
You will soon find out that the core of games is quite short, but the polishing is very long.
Here is the source for controlling the ship : Asteroid
In the next article, I will show you how to implement weapons, monsters and rocks … that in turn involves a couple of other things …
