I noticed someone had arrived at this site by searching for ’Game Maker radar code’. The radar system I am using in this game might not be what everyone wants, but here it is anyway.
The premise goes something like this:
1. The player object in Far Trader creates a background image that is attached to the player object itself which gives an illusion of a rad projection.
2. Each AI ship instance spawns a radar contact object in its Create Event with the x and y value of the player. This will make a radar contact sprite for each and every spaceship object in the room appear at the players location.
The code looks like:
Each AI ship instance has in its Create EventscannerRange=2000; // distance in pixels that objects can be detected
radarContact=instance_create(obj_player.x,obj_player.y,obj_ship_contact);
Then in the AI ship instances’s End Step Event add:
dist = point_distance(x,y,obj_player.x,obj_player.y);
if(dist > scannerRange) {
// hide the sprite
radarContact.image_alpha = 0.0;
} else {
// set sprite alpha as a % of dist from scannerRange
alpha = 100 - ((dist / scannerRange) * 100) ;
radarContact.image_alpha=alpha / 100 ;
}
if(dist < scannerRange) {
if(dist < 390) {
radarBlip=dist;
} else {
radarBlip=390;
}
pDirection=point_direction(x,y,obj_player.x,obj_player.y);
radarContact.x = obj_player.x - lengthdir_x(radarBlip , pDirection);
radarContact.y = obj_player.y - lengthdir_y(radarBlip , pDirection);
}
The above code will pull the radar contact instance away from the player object back to its creator instance, up to a maximum of 390 pixels. The 390 pixel limit is to match the background image attached to the player object, it can be any distance you desire, as long as its visible on the screen! All radar contacts that are greater than scannerRange pixels away have there alpha set to 0.0, which means they are not visible. Once the contact is in scannerRange, the code will set its alpha value to a % of the distance, to give an impression of range, the further away the contact, the more transparent the contact object.
The above is just an example of how I implemented the radar, code. In my game I actually have the code in a script, so that its easy to apply do a number of different object types. I hope someone finds it of use.