flash on 2012-6-15
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fS15
*/
package {
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var camx:Number = 0;
public var camy:Number = 0;
public var testActor:aActor;
public var myGround:aGround;
public var vecCloud:Array;
public function FlashTest() {
graphics.clear();
graphics.beginFill(0xaAaAFF,1);
graphics.drawRect(0,0,500,500);
graphics.endFill();
// graphics.beginFill(0xaAFFaA,1);
// graphics.drawRect(0,400,500,100);
// graphics.endFill();
testActor = new aActor();
addChild(testActor);
testActor.cx = 250;
testActor.cy = 250;
myGround = new aGround();
myGround.cy = 400;
// myGround.cx = 100;
addChild(myGround);
vecCloud = new Array();
var c:aCloud;
var i:int;
for (i = 0; i < 16; i++)
{
c = new aCloud();
addChild(c);
vecCloud.push(c);
}//nexti
stage.addEventListener(Event.ENTER_FRAME, onEnter);
stage.addEventListener(MouseEvent.CLICK, onClick);
}//ctor
public function setCam(sx:Number, sy:Number):void
{
camx += (sx - camx) * 0.1;
camy += (sy - camy) * 0.1;
if (camx != 0) { camx = 0; }
if (camy > 0) { camy = 0;}
}//setcam
public function onClick(e:MouseEvent):void
{
testActor.spec = 15;
}//onclick
public function onEnter(e:Event):void
{
testActor.update();
if (testActor.spec > 0)
{
testActor.cy -= 30;
testActor.spec -= 1;
}
else
{
testActor.cy += 10;
if (testActor.cy >= 400-16) { testActor.cy = 400-16;}
}
var mx:Number;
var vx:Number;
mx = stage.mouseX;
vx = (mx - testActor.cx) * 0.1;
if (vx > 16) { vx = 16; }
if (vx < -16) { vx = -16;}
testActor.cx += vx;
if (testActor.cx < 16) { testActor.cx = 16; }
if (testActor.cx > 500-16) { testActor.cx = 500 - 16;}
setCam(testActor.cx-250, testActor.cy-250);
myGround.update();
myGround.redraw(camx, camy);
testActor.redraw(camx, camy);
var c:aCloud;
var i:int;
var num:int;
num = vecCloud.length;
for (i = 0; i < num; i++)
{
c = vecCloud[i];
c.update();
c.redraw(camx, camy);
}//nexti
}//onenter
}//classend
}
import flash.display.Sprite;
internal class aActor extends Sprite
{
public var cx:Number = 0;
public var cy:Number = 0;
public var spec:int = 0;
public function aActor()
{
graphics.clear();
graphics.lineStyle(1,0);
graphics.drawCircle(0,0,16);
}//ctor
public function redraw(sx:Number, sy:Number):void
{
x = cx - sx;
y = cy - sy;
}//redraw
public function update():void
{
//this.rotationZ += 10;
}//update
}//actor
internal class aGround extends aActor
{
public function aGround()
{
graphics.clear();
//graphics.lineStyle(1,0);
graphics.beginFill(0xaAFFaA,1);
graphics.drawRect(0,0,500,100);
graphics.endFill();
}//ctor
}//ground
internal class aCloud extends aActor
{
public var vx:Number = 0;
public function aCloud()
{
vx = 0.1 + Math.random() * 10;
var s:Number;
s = 0.1 + Math.random() * 2;
graphics.clear();
graphics.beginFill(0xFFffFF,0.5);
graphics.drawEllipse(0,0,128*s,48*s);
graphics.endFill();
cx = (Math.random() * 900) - 200;
cy = 200 + Math.random() * 1000 *-1;
}//ctor
override public function update():void
{
cx += vx;
if (cx >= 700) {
cx = -200;
cy = 200 + Math.random() * 1000 *-1;
vx = Math.random() * 10 + 0.1;
}
}//update
}//cloud