Study Guides (390,000)
CA (150,000)
SFU (5,000)
IAT (80)
IAT 167 (20)
Final

IAT167-HitDetectionExample.docx


Department
Interactive Arts & Tech
Course Code
IAT 167
Professor
Jack Stockholm
Study Guide
Final

This preview shows half of the first page. to view the full 3 pages of the document.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
public var lightModel:Array = [];
public var closestLight:int = -1;
public static const THRESHOLD:int = 80;
public function Main():void
{
createLights();
addEventListener(Event.ENTER_FRAME, gameLoop);
}
public function createLights():void
{
var xTemp:int = 50;
var yTemp:int = 50;
var placeHolder:CircleLight;
for (var i:int = 0; i < 5; i++)
{
placeHolder = new CircleLight();
placeHolder.x = xTemp;
placeHolder.y = yTemp;
addChild(placeHolder);
lightModel.push(placeHolder);
xTemp += 50;
yTemp += 50;
}
}
public function gameLoop(event:Event):void
{
var distance:Number = 0;
var closestDistance:int = THRESHOLD + 1;
var closestTemp:int = -1;
for (var i:int = 0; i < lightModel.length; i++)
{
distance = Math.sqrt(Math.pow(lightModel[i].x - mouseX, 2) +
Math.pow(lightModel[i].y -mouseY, 2));
if (distance <= THRESHOLD)
You're Reading a Preview

Unlock to view full version