flash on 2017-2-18
♥0 |
Line 87 |
Modified 2017-02-18 06:15:46 |
MIT License
archived:2017-03-20 16:20:51
ActionScript3 source code
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aT9X
*/
package {
import flash.text.TextField;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
deb = new TextField();
deb.width=320; deb.height=240;
deb.mouseEnabled=false;
addChild(deb);
vecTeam = new Vector.<xTeam>(0,false);
var a:xTeam;
a = new xTeam(); vecTeam.push(a); a.cx=64;a.cy=64;
a = new xTeam(); vecTeam.push(a); a.cx=320;a.cy=64;
a = new xTeam(); vecTeam.push(a); a.cx=64;a.cy=320;
a = new xTeam(); vecTeam.push(a); a.cx=320;a.cy=320;
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var deb:TextField;
public var vecTeam:Vector.<xTeam>;
public var curTeam:int = 0;
public var timeOut:int = 0;
public var timeLeft:int = 2;
public var timeWait:int = 0;
public var gt:int = 0;
public var turn:int = 0;
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0);
if (timeOut >0)
{
timeOut -=1;
deb.text = turn+"/"+timeOut;
}
else
{
timeWait +=1;
if (timeWait>=30)
{ timeLeft -=1; timeWait=0;
if (timeLeft<=0)
{
timeLeft = 2;
timeOut = 6;
curTeam += 1;
if (curTeam>= vecTeam.length){curTeam=0; turn+=1; timeOut=60; }
}//endif3
}//endif2
deb.text = turn+"/"+timeLeft+":"+timeWait;
}//endif
var i:int; var num:int; var a:xTeam;
num = vecTeam.length;
for(i=0;i<num;i+=1)
{
a = vecTeam[i];
graphics.drawCircle(a.cx,a.cy,16);
if (i==curTeam && timeOut <=0)
{
graphics.beginFill(a.col, 1);
graphics.drawCircle(a.cx, a.cy, 16);
graphics.endFill();
var whit:int;
var ax:Number; var ay:Number;
whit =0;
a.ang += (Math.random()-0.5)*0.2;
ax = Math.cos(a.ang);
ay = Math.sin(a.ang);
if (a.cx-8<0 && ax<0){ax=-ax;whit=1;}
if (a.cx+8>465 && ax>0){ax=-ax;whit=1;}
if (a.cy-8<0 && ay<0){ay=-ay;whit=1;}
if (a.cy+8>465 && ay>0){ay=-ay;whit=1;}
if (whit>0){ a.ang = Math.atan2(ay,ax); }
else { a.cx+=ax; a.cy+=ay; }
}//endif
graphics.moveTo(a.cx,a.cy);
graphics.lineTo(a.cx+Math.cos(a.ang)*16,a.cy+Math.sin(a.ang)*16);
}//nexti
}//onenter
}//classend
}
internal class xTeam
{
public var cx:Number = 0;
public var cy:Number = 0;
public var ang:Number = Math.random()*6.28;
public var col:uint = Math.random()*0xFFffFFff;
}//xteam