GDK> 2D top down 360 degrees Movement by Swift19th Aug 2008 7:23
|
---|
Summary Moves an object in the given direction with the given speed and then updates the objects x&y positions to reflect this movement Description /* Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com #include "DarkGDK.h" // The function prototype void MoveDirSpeed( float direction, float speed, float *x, float *y ); // The function void MoveDirSpeed( float direction, float speed, float *x, float *y ) { float pi=3.14159265358979; // Declare variable pi for calculations /// Check to see which quadrant the direction angle is in if ( direction < 90 && direction >= 0 ) { // Break the vector direction down into its horizontal and vertical components // and adjust the objects x&y co-ords correspondingly *x += speed * dbCos(direction); *y += -speed * dbSin(direction); } if ( direction < 180 && direction >= 90 ) { *x += - speed * dbCos(180-direction); *y += - speed * dbSin(180-direction); } if ( direction < 270 && direction >= 180 ) { *x += - speed * dbCos(direction-180); *y += speed * dbSin(direction-180); } if ( direction < 360 && direction >= 270 ) { *x += speed * dbCos(360-direction); *y += speed * dbSin(360-direction); } } |