Game Development Reference
In-Depth Information
addEventListener(Event.ADDED_TO_STAGE, addedToStage,
false, 0, true);
}
private function addedToStage(e:Event):void {
addEventListener(Event.ENTER_FRAME, enterFrame,
false, 0, true);
}
private function enterFrame(e:Event):void {
//CHECK DISTANCE AND PERFORM MOVES
var distance:Number = Math.sqrt(Math.pow(player.x -
mouseX, 2) + Math.pow(player.y - mouseY, 2));
var tempPoint:Point = new Point(mouseX, mouseY);
var dx:Number = 0;
var dy:Number = 0;
if (distance
player.speed * Time.deltaTime) {
var angle:Number = Math.atan2(mouseY -
player.y, mouseX - player.x);
dx = (player.speed * Time.deltaTime) * Math.
cos(angle);
dy = (player.speed * Time.deltaTime) * Math.
sin(angle);
tempPoint.x = player.x + dx;
tempPoint.y = player.y + dy;
>
}
//DO CHECKS
for each (var coordinate:HitTestCoordinate in
player.hitPointList) {
if (barriers.hitTestPoint(coordinate.pointGlobal.
x + dx, coordinate.pointGlobal.y + dy, true)) {
if (barriers.hitTestPoint(coordinate.
pointGlobal.x + dx, coordinate.pointGlobal.y,
true)) {
tempPoint.x = player.x;
}
if (barriers.hitTestPoint(coordinate.point
Global.x, coordinate.pointGlobal.y + dy, true)) {
tempPoint.y = player.y;
}
}
}
//RE-ASSIGN VALUES
player.x = tempPoint.x;
player.y = tempPoint.y;
}
}
Search Nedrilad ::




Custom Search