www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/02/01:30:21

From: umich AT gwis2 DOT circ DOT gwu DOT edu (Umberto Michelucci)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro and Asteroids
Date: 2 Mar 1998 02:45:04 GMT
Organization: The George Washington University, Washington DC
Lines: 72
Message-ID: <6dd6fg$9uu6@beaker.nit.gwu.edu>
References: <34F9F4B1 DOT 6CE0 AT home DOT com>
NNTP-Posting-Host: gwis2.circ.gwu.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019