www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/08/10:05:11

From: cb AT ia DOT com (Marc Brooker)
Newsgroups: comp.os.msdos.djgpp
Subject: Movement Revisited
Date: Thu, 08 Oct 1998 13:55:10 GMT
Organization: UUNET Internet Africa
Lines: 39
Message-ID: <361cc01b.1648816@ct-news.iafrica.com>
NNTP-Posting-Host: 196-30-240-91.iafrica.com
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello All,

Firstly, thanks for the help of all those who posted replys to my
message about tank movement. 
At about three o' clock yesterday i came up with a much better
solution to that problem and thought some of you might be interested,
here is the entire function, note no trig functions needed. Pity about
wasting speed with doubles but it is the best way to do it.

void move_objects(void)
{
 int i;
 double dx,dy;
 double x, y;
 for (i = 0; i < player.usedobj; i++)
    {
     if ((objects[i].x) && (objects[i].flags & MOVING)) 
       {
        dx = objects[i].targetx - objects[i].x;
        dy = objects[i].targety - objects[i].y;
        if (dx == 0) dx++;
        if (dy == 0) dy++;
        x = dx / (fabs(dx) + fabs(dy)) * 5;
        y = dy / (fabs(dx) + fabs(dy)) * 5;
        objects[i].x += x;
        objects[i].y += y;
        }
     }
}

Note this function wont work on it's own, an array of the proper
object structures is needed. It can easily be converted to just about
any other game type.

Thanks for your time and your modem's.

Marc "Mud Rat" Brooker
quazar[at]freemail.co.za
Quazar Free Software Group

- Raw text -


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