movement rendering query....pls answer promptly

This is a discussion on movement rendering query....pls answer promptly within the Game Programming forums, part of the General Programming Boards category; hi all there are 3 buttons for the movement of the space ship in my game. Left - rotate anti-clockwise ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    12

    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.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    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.
    Last edited by Brian; 11-30-2003 at 05:20 AM.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    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);
    }

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    12
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. One quick question...
    By Kross7 in forum C++ Programming
    Replies: 10
    Last Post: 04-13-2007, 09:50 PM
  2. Tic Tac Toe program...
    By Kross7 in forum C++ Programming
    Replies: 12
    Last Post: 04-12-2007, 03:25 PM
  3. pls help with the correction...
    By leena_teoh in forum C Programming
    Replies: 1
    Last Post: 03-20-2002, 04:18 AM
  4. code help :)
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 02-28-2002, 12:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21