|
Radar issue
#251807
02/15/09 01:29
02/15/09 01:29
|
Joined: Oct 2008
Posts: 218 Nashua NH
heinekenbottle
OP
Member
|
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:
//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.
|
|
|
Re: Radar issue
[Re: heinekenbottle]
#251820
02/15/09 06:57
02/15/09 06:57
|
Joined: Feb 2008
Posts: 337
Vadim647
Senior Member
|
Senior Member
Joined: Feb 2008
Posts: 337
|
[ 1| 2]Radar scripts, using lines.
I switched to other account since marth 2010. Guess which.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|