forked from: How to use CannonML ?
forked from How to use CannonML ? (diff: 147)
ActionScript3 source code
/**
* Copyright ohisama ( http://wonderfl.net/user/ohisama )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/yV6T
*/
// forked from keim_at_Si's How to use CannonML ?
package
{
import flash.events.*;
import flash.display.*;
import org.si.cml.*;
public class CMLObjectSample extends Sprite
{
public var stageCML : String = "py-160[px$??*100n{{[rw]}vy$?*10+2i40v~bm$i?(5)+2,45f5vd-10}w30]";
function CMLObjectSample()
{
addEventListener(Event.ADDED_TO_STAGE, _setup);
}
private function _setup(e : Event) : void
{
removeEventListener(Event.ADDED_TO_STAGE, _setup);
field = new Sprite();
field.x = 120;
field.y = 160;
field.graphics.lineStyle(1, 0);
field.graphics.drawRect(-120, -160, 240, 320);
addChild(field);
CMLObject.initialize(true);
var stageSequence : CMLSequence = new CMLSequence(stageCML);
var stageCannon:Cannon = new Cannon(0);
stageCannon.create(0, -160);
var stageFiber : CMLFiber = stageCannon.execute(stageSequence);
addEventListener(Event.ENTER_FRAME, _draw);
}
private function _draw(e : Event) : void
{
CMLObject.update();
}
}
}
import flash.display.*;
import org.si.cml.*;
var field:Sprite;
class Cannon extends CMLObject
{
function Cannon(radius : Number)
{
createNewCannonShape(radius);
}
override public function onCreate() : void
{
field.addChild(cannonShape);
cannonShape.x = this.x;
cannonShape.y = this.y;
cannonShape.rotation = this.angle;
}
override public function onDestroy() : void
{
if (this.destructionStatus == 1)
{
createExplosion();
}
field.removeChild(cannonShape);
}
override public function onUpdate() : void
{
cannonShape.x = this.x;
cannonShape.y = this.y;
cannonShape.rotation = this.angle;
if (this.x < -140 || this.x > 140 || this.y < -180 || this.y > 180) this.destroy(0);
}
override public function onNewObject(args : Array) : CMLObject
{
return new Cannon(8);
}
override public function onFireObject(args : Array) : CMLObject
{
return new Cannon(4);
}
private var cannonShape : Shape;
private function createNewCannonShape(radius : Number) : void
{
var graphics:Graphics;
cannonShape = new Shape();
graphics = cannonShape.graphics;
if (radius > 0)
{
graphics.lineStyle(2, 0x404080);
if (radius > 6)
{
graphics.moveTo(0, 0);
graphics.lineTo(radius+4, 0);
}
graphics.beginFill(0xc0c0f0);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
}
private function createExplosion() : void
{
}
}