Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (lijoyi2011), 1,034 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Radar issue #251807
02/15/09 01:29
02/15/09 01:29
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline OP
Member
heinekenbottle  Offline OP
Member

Joined: Oct 2008
Posts: 218
Nashua NH
I have a little radar system going and it seems to be working fine in detecting where the enemy is in relation to the player.

However, it isn't appearing on the screen in the correct place. I have a radar scope up on the left side of the screen but the "blips" are on the right side of the screen.

Here is the code:
Code:
//The radar blips are found in the code of the enemy tanks:
//unrelated code was removed to make it fit better

action eTank()   //the enemy tank
{
	PANEL* rDot;			//declare a panel pointer for the radar dot
	VECTOR rSpot;			//declare a vector to calculate the radar dot position
	var rSpt[2];			//an array for storing the x and y components of the radar dot's position

	//...sets basic parameters here, unrelated code

	rDot = pan_create(NULL,9999);						//create a panel for the radar dot (rDot)
	set(rDot,LIGHT);										//set its light flag
	rDot.size_x = 8;										//set its size
	rDot.size_y = 8;
	vec_set(rDot.blue,vector(200,0,0));				//make it blue
	
        //...more unrelated code, its healthbar is here

	while(my.health > 0)
	{
		//...basic movement, effects, ai, unrelated code

		if(vec_dist(my.x,player.x) < 3000)	//if the enemy is within 3000 units from the player, he's in radar range
		{
			if(!is(rDot,VISIBLE)) set(rDot,VISIBLE);	//if the radar dot is not visible, make it visible
			vec_set(rSpot,my.x);								//set rSpot to the tank's location
			vec_for_screen(rSpot,camera);					//convert rSpot to screen coordinates
			rSpt[0] = pSpot.x - rSpot.x;					//calculate the x componant of the vector to the player
			rSpt[1] = pSpot.y - rSpot.y;					//calculate the y componant of the vector to the player
			rDot.pos_x = radarPan.center_x + ((rSpt[0]/3000) * 64);	//calculate the x position
			rDot.pos_y = radarPan.center_y + ((rSpt[1]/3000) * 64);	//calculate the y position
		}
		else
		{
			//beep();
			if(is(rDot,VISIBLE)) reset(rDot,VISIBLE);
		}
		wait(1);		//avoid endless loops
	}
	reset(rDot,VISIBLE);
	ptr_remove(rDot);
        //...more unrelated code
}

//and this is the code that puts the radar scope on the screen

function initScreen()
{
	while(!player) { wait(1); }					//wait for the player to be loaded
	set(healthBar,VISIBLE | LIGHT);				//turn on the health bar and allow it to be set by RGB values
	set(radarPan,VISIBLE | TRANSLUCENT);		//turn on the radar scope, make it transparent
	radarPan.alpha = 10;								//radar scope is at an alpha of 10
	radarPan.scale_x *= 0.5;						//radar scope is half its original size
	radarPan.scale_y *= 0.5;
	radarPan.center_x = 0.5 * (bmap_width(radarMap));	//move the center of the scope to the middle of the bmap
	radarPan.center_y = 0.5 * (bmap_height(radarMap));
	vec_set(healthBar.blue,vector(0,200,0));	//health bar is green
	while(player)										//while the player exists
	{
		radarPan.angle -= 5 * time_step * (!freeze_mode);					//rotate the scope
		healthBar.size_x = 190 * (player.health / player.maxHealth);	//healthbar is a function of % of health
		wait(1);
	}
}


How it works is it takes the position of the player tank, converted to screen coordinates (VECTOR pSpot) and uses another vector, this time the enemy tank's position converted to screen coordinates (VECTOR rSpot) to find the x and y component distances to place the rDot panel. These values are stored in the rSpt array. Then the position of the rDot panel is calculated by using the percentage of the tank to the maximum radar range (3000 units, hence (rSpt[0]/3000) ) and then the percentage is multiplied by 64 to get it onto the scope.

As I said, the code appears to work, but the dots aren't being place on the scope, they're on the wrong side of the screen.

Last edited by heinekenbottle; 02/15/09 01:36.

I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: Radar issue [Re: heinekenbottle] #251818
02/15/09 05:12
02/15/09 05:12
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline OP
Member
heinekenbottle  Offline OP
Member

Joined: Oct 2008
Posts: 218
Nashua NH
Well, I found it, the "center_x" and "center_y" values were relative to the bitmap, not to the screen, so the blips ended up on the wrong side of the screen.

And the code now isn't working so I'll take a look at it tomorrow, try to see what I can do.


I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: Radar issue [Re: heinekenbottle] #251820
02/15/09 06:57
02/15/09 06:57
Joined: Feb 2008
Posts: 337
V
Vadim647 Offline
Senior Member
Vadim647  Offline
Senior Member
V

Joined: Feb 2008
Posts: 337
[1|2]Radar scripts, using lines.


I switched to other account since marth 2010. Guess which.

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1