flash on 2013-1-23
♥0 |
Line 164 |
Modified 2013-01-23 00:31:18 |
MIT License
archived:2017-03-30 22:54:25
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/8ZqB
*/
package {
import flash.text.TextField;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var psys:wPartSys;
public static var deb:TextField;
public function FlashTest() {
deb = new TextField();
addChild(deb);
//deb.text = " debug ";
psys = new wPartSys();
// deb.text =" reach2";
psys.initPart(64);
// deb.text = " reach1 ";
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var delw:int = 0;
public function onEnter(e:Event):void
{
//deb.text = " reach";
delw += 1;
if (delw >= 3)
{
psys.addPart(Math.random()*200+100, Math.random()*200+100, 0 );
delw = 0;
}//endif
psys.update();
psys.render();
graphics.clear();
graphics.lineStyle(1,0);
var vf:Vector.<uint>;
var vv:Vector.<Number>;
var vec:Vector.<wPart>;
var i:int;
var num:int;
var a:wPart;
vec = psys.vecPart;
num = vec.length;
/*
for (i = 0; i < num; i++)
{
a = vec[i];
if (a.hp <= 0) { continue; }
graphics.drawCircle(a.cx,a.cy, 4);
}//nexti
*/
var f:int;
var f2:int;
var f3:int;
vf = psys.vecFace;
vv = psys.vecVert;
num = vf.length;
for (i = 0; i < num; i+=3)
{
f = vf[i] * 3;
f2 = vf[i+1] * 3;
f3 = vf[i+2] * 3;
graphics.moveTo(vv[f],vv[f+1]);
graphics.lineTo(vv[f2],vv[f2+1]);
graphics.lineTo(vv[f3],vv[f3+1]);
graphics.lineTo(vv[f], vv[f+1]);
}//nexti
//deb.text = " " + num;
}//onenter
}//flashtest
}
internal class wPartSys
{
public var vecPart:Vector.<wPart>;
public var vecVert:Vector.<Number>;
public var vecFace:Vector.<uint>;
public var it:int = 0;
public var numPart:int = 0;
public function wPartSys()
{
}//ctor
public function initPart(num:int):void
{
var k:int;
var i:int;
var numFace:int;
if (num < 16) { num = 16;}
if (num > 256) { num=256; }
numPart = num;
// FlashTest.deb.text = " reach2b";
vecPart = new Vector.<wPart>(num,false);
vecVert = new Vector.<Number>(num*3*4,false);
vecFace = new Vector.<uint>(num*3*2,false);
for (i = 0; i < num; i++)
{
vecPart[i] = new wPart();
}//nexti
// FlashTest.deb.text = " reach3";
numFace = num*3*2;
k = 0;
for (i = 0; i < numFace; i +=6 )
{
vecFace[i] = 0+k;
vecFace[i+1] = 1+k;
vecFace[i+2] = 2+k;
vecFace[i+3] = 1+k;
vecFace[i+4] = 3+k;
vecFace[i+5] = 2+k;
k += 4;
}//nexti
}//initpart
public function addPart(x:Number, y:Number, z:Number):void
{
var a:wPart;
a = vecPart[it];
a.hp = 90;
a.cx = x;
a.cy = y;
a.cz = z;
a.vx = Math.random() - Math.random();
a.vy = Math.random() - Math.random();
a.vz = Math.random() - Math.random();
it += 1;
if (it >= numPart) { it = 0; }
}//addpart
public function update():void
{
var a:wPart;
var i:int;
var num:int;
num = vecPart.length;
for (i =0; i < num; i+=1)
{
a = vecPart[i];
if (a.hp <= 0) { continue; }
a.hp -= 1;
a.vy += 0.05;
a.cx += a.vx;
a.cy += a.vy;
a.cz += a.vz;
}//nexti
}//update
public function render():void
{
var a:wPart;
var i:int;
var num:int;
var k:int;
var n:int;
k = 0;
num = vecPart.length;
for (i = 0; i < num; i++)
{
a = vecPart[i];
if (a.hp <= 0) { continue;}
n = k * 12;
vecVert[n] = a.cx - a.size;
vecVert[n+1] = a.cy - a.size;
vecVert[n+2] = a.cz;
vecVert[n+3] = a.cx + a.size;
vecVert[n+4] = a.cy - a.size;
vecVert[n+5] = a.cz;
vecVert[n+6] = a.cx - a.size;
vecVert[n+7] = a.cy + a.size;
vecVert[n+8] = a.cz;
vecVert[n+9] = a.cx + a.size;
vecVert[n+10] = a.cy + a.size;
vecVert[n+11] = a.cz;
k += 1;
}//nexti
}//render
}//wpartsys
internal class wPart
{
public var size:Number = 4;
public var cx:Number = 0;
public var cy:Number = 0;
public var cz:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public var vz:Number = 0;
public var hp:Number = 0;
}//classend