<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ashley Etchell &#187; game maker radar system</title>
	<atom:link href="http://ash.etchell.co.uk/tag/game-maker-radar-system/feed/" rel="self" type="application/rss+xml" />
	<link>http://ash.etchell.co.uk</link>
	<description>Its all a bit random</description>
	<lastBuildDate>Mon, 05 Jul 2010 16:02:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Game Maker Radar system</title>
		<link>http://ash.etchell.co.uk/2009/09/26/game-maker-radar-system/</link>
		<comments>http://ash.etchell.co.uk/2009/09/26/game-maker-radar-system/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 00:27:55 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[Game Maker tutorials]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[game maker radar system]]></category>
		<category><![CDATA[GML]]></category>
		<category><![CDATA[space trading game]]></category>
		<category><![CDATA[top down 2d game]]></category>

		<guid isPermaLink="false">http://ash.etchell.co.uk/?p=54</guid>
		<description><![CDATA[I noticed someone had arrived at this site by searching for  &#8217;Game Maker radar code&#8217;.  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 &#8230; <a href="http://ash.etchell.co.uk/2009/09/26/game-maker-radar-system/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I noticed someone had arrived at this site by searching for  &#8217;Game Maker radar code&#8217;.  The radar system I am using in this game might not be what everyone wants, but here it is anyway.</p>
<p><strong> The premise goes something like this:</strong></p>
<p>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.<br />
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.</p>
<div id="attachment_55" class="wp-caption aligncenter" style="width: 459px"><img class="size-full wp-image-55" title="Example of radar system" src="http://ash.etchell.co.uk/wp-content/uploads/2009/09/radar-example.gif" alt="Example of radar system" width="449" height="300" /><p class="wp-caption-text">Example of radar system</p></div>
<p><strong>The code looks like:</strong></p>
<p>Each AI ship instance has in its <strong>Create Event</strong><br />
<code><br />
scannerRange=2000; // distance in pixels that objects can be detected<br />
radarContact=instance_create(obj_player.x,obj_player.y,obj_ship_contact);<br />
</code></p>
<p>Then in the AI ship instances&#8217;s <strong>End Step</strong> <strong>Event</strong> add:</p>
<p><code>dist = point_distance(x,y,obj_player.x,obj_player.y);<br />
if(dist &gt; scannerRange) {<br />
// hide the sprite<br />
radarContact.image_alpha = 0.0;<br />
} else {<br />
// set sprite alpha as a % of dist from scannerRange<br />
alpha = 100 - ((dist / scannerRange) * 100) ;<br />
radarContact.image_alpha=alpha / 100 ;<br />
}<br />
if(dist &lt; scannerRange) {<br />
if(dist &lt; 390) {<br />
radarBlip=dist;<br />
} else {<br />
radarBlip=390;<br />
}<br />
pDirection=point_direction(x,y,obj_player.x,obj_player.y);<br />
radarContact.x = obj_player.x - lengthdir_x(radarBlip , pDirection);<br />
radarContact.y = obj_player.y - lengthdir_y(radarBlip , pDirection);<br />
}</code></p>
<p>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.</p>
<p>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.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://ash.etchell.co.uk/2009/09/26/game-maker-radar-system/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://ash.etchell.co.uk/2009/09/26/game-maker-radar-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
