Mail Archives: djgpp/1998/03/02/01:30:21
I'm sorry, maybe this is not the solution, but do you intialize vel_x and
vel_y ? Maybe this is the problem! Everything else seems correct. I hope
to be useful. Let me know if this was the problem!
Umberto Michelucci
=======================================================================
// | /\ /| Umberto Michelucci
// | / \/ | umich AT gwis2 DOT circ DOT gwu DOT edu
// | / |
/_______| / | "The nature can write code up to 10 lines
per minute..." (Freely taken from P.Bock)
=======================================================================
Dan (dyoon AT home DOT com) wrote:
: Ok, I'm having some problems trying to make my little asteroids clone
: game do the following...turn the ship in a certain direction, and if i
: press the up arrow key, have the ship move in the direction it's front
: end is pointing.
: I have some code written but it doesn't work properly. If anyone could
: tell me what I'm doing wrong I would really appreciate it.
: [begin loop]
: if(key[KEY_UP])
: {
: float radian_angle = (angle*180)/PI;
: scale_x = cos(radian_angle);
: scale_y = sin(radian_angle);
: acc_x = scale_x*1;
: acc_y = scale_y*1;
: }
: vel_x += acc_x;
: vel_y += acc_y;
: if(vel_x > SHIP_MAX_SPEED)
: vel_x = SHIP_MAX_SPEED;
: if(vel_y > SHIP_MAX_SPEED)
: vel_y = SHIP_MAX_SPEED;
: if(vel_x < -SHIP_MAX_SPEED)
: vel_x = -SHIP_MAX_SPEED;
: if(vel_y < -SHIP_MAX_SPEED)
: vel_y = -SHIP_MAX_SPEED;
: pos_x += vel_x;
: pos_y += vel_y;
: [end loop]
: the ship starts off with the front of the ship pointing north, so the
: ship's "angle" variable starts off at 90. pressing the right arrow
: key will decrement the angle, and the left arrow key will increment it.
: i know that my code is a little bit off because on the monitor, going up
: the screen will actually mean decrementing the Y axis...but my main
: problem is that the angle isn't even right. for example, i start the
: ship off at 90 degrees...so if i just press the up arrow key from the
: start of the game, the ship should go up the screen? instead it goes at
: some weird angle.
: help will be much appreciated. Oh, and i'm sorry if this is the wrong
: place to ask this question...but i was thinking that maybe there are
: some djgpp specific math routines???
: Daniel
- Raw text -