www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/02/04:06:40

From: cbroo AT iafrica DOT com (Chris Brooker)
Newsgroups: comp.os.msdos.djgpp
Subject: Tank Movement
Date: Fri, 02 Oct 1998 07:14:39 GMT
Organization: UUNET Internet Africa
Lines: 46
Message-ID: <36147a32.10039817@ct-news.iafrica.com>
NNTP-Posting-Host: 196-31-19-231.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

Hi,
Sorry if my code sucks, I a mquite new to C.
I am busy writing a Real Time Strategy with DJGPP and allegro and have
hit a problem, here it is:

I have a selected tank and would like to move it somewhere else by
clicking there, i do this and it either: moves there properly, moves
in the opposite direction or just sits and vibrates.
Can someone please tell me what is wrong.

Here are the functions:

double dir_degrees(int x1, int y1, int y2, int x2)
{
	int v1, v2;
	double dir;
	v1 = y1 - y2;
	v2 = x1 - x2;
	if (v2 == 0) 
	 v2++; //Stops division by zero errors
	dir = 57 * atan(v1 / v2);
	return dir;
}

void move_tank()
{
	double dir;
	int angle;
	dir = dir_degrees(tank.x, tank.y, tank.targetx, tank.targety);
	if (dir <= 90)
	{
		tank.x += 5;
		angle = (((dir - 90) / 180) * 5); //On a scale of -5
to 5
		tank.y += angle;
	}
	if (dir > 90)
	{
		tank.x -= 5;
		angle = (((dir - 270) / 180) * 5); 
		tank.y += angle;
	}
}

Thanks in advance.
Marc

- Raw text -


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