# movement rendering query....pls answer promptly

Printable View

• 11-30-2003
technoXavage
movement rendering query....pls answer promptly
hi all

there are 3 buttons for the movement of the space ship in my game.
Left - rotate anti-clockwise
right - rotate clockwise
up - thrust

i've settled the rotation part pretty easily. the problem is doing the thrust. i dunno how to calculate the destination rectangle coordinates for blitting.
i've got the actual game in my webserserver at click me

please hope u guys can help me fast. thanks.
• 11-30-2003
Brian
Code:

```#ifndef M_PI #define M_PI 3.14159265358979323846 #endif void rotate(struct ship *sh, double amt) {         sh->angle += (M_PI / 64) * amt;                 if (sh->angle < 0) {                 sh->angle += 2 * M_PI;           } else           if (sh->angle > 2 * M_PI) {                   sh->angle -= 2 * M_PI;           } } void moveforward(struct ship *sh, double amt)         sh->x += (-sin(sh->angle)) * amt;         sh->y += (cos(sh->angle)) * amt;         bounds_check();  /* some function to make sure you havent gone off screen */ }```
the power of trigonometry
use negative amts for moving backwards, or turning anticlockwise.
• 11-30-2003
Brian
I don't know crap about accelleration though. I do know you will have to implement two velocities.
Code:

```double velx; double vely;```
and increase them in the same way when you want to speed up.
Code:

```sh->velx += (-sin(sh->angle)) * force; sh->vely += (cos(sh->angle)) * force;```
and then, every frame, call a function called move which acts like this
Code:

```void move(struct ship *sh) {         sh->x += sh->velx;         sh->y += sh->vely;         boundscheck(sh); }```
• 11-30-2003
technoXavage
hoho thanks dude....u replied at the speed of like real time chat...neways gimme a while to churn your solutions. i'll be posting again if i come accross a prob