Friday, 11 October 2013

The distance between two points or players in as3



package
{

import flash.display.Sprite;

public class testClass extends Sprite
{
var player1:Player1;
var player2:Player2;
var dist:int;
public function testClass()
{
// constructor code
player1_fun();
player2_fun();
playersBetweenDist();
}
public function player1_fun(){
player1 = new Player1();
addChild(player1);
player1.x = 30;
player1.y = 30;

}
public function player2_fun(){
player2 = new Player2();
addChild(player2);
player2.x = 30;
player2.y = 70;
}
public function playersBetweenDist(){
dist = Math.sqrt(Math.pow( player2.x - player1.x,2 ) + Math.pow( player2.y - player1.y,2 ) );

trace("The distance between two players = "+dist);
}

}

}














Note : - You can change player co-ordinates to see the difference between distance

No comments:

Post a Comment