flash on 2012-9-21
♥0 |
Line 89 |
Modified 2012-09-21 20:19:53 |
MIT License
archived:2017-03-30 22:59:22
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/yQQl
*/
package {
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.display.Graphics;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var bg:Sprite;
public var ps:Sprite;
public function FlashTest() {
// write as3 code here..
bg = new Sprite();
var g:Graphics;
g = bg.graphics;
g.clear();
g.beginFill(0,1);
g.drawRect(0,200,400,200);
g.endFill();
g.beginFill(0,1);
g.drawRect(0,0,60,200);
g.endFill();
g.beginFill(0,1);
g.drawRect(300,0,100,200);
g.endFill();
g.beginFill(0,1);
g.drawEllipse(150,150,400,300);
g.endFill();
addChild(bg);
ps = new Sprite();
g = ps.graphics;
g.clear();
g.beginFill(0xFF0000,1);
g.drawCircle(0,0,16);
g.endFill();
g.lineStyle(2,0);
g.moveTo(0,0);
g.lineTo(16,0);
addChild(ps);
ps.x = 150;
ps.y = 100;
stage.addEventListener(Event.ENTER_FRAME, onEnter);
stage.addEventListener(KeyboardEvent.KEY_DOWN, kdown);
stage.addEventListener(KeyboardEvent.KEY_UP, kup);
}//ctor
public var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512,false);
public function kdown(e:KeyboardEvent):void
{ vecKey[e.keyCode] = true;}
public function kup(e:KeyboardEvent):void
{ vecKey[e.keyCode] = false;}
public var vx:Number = 0;
public var vy:Number = 0;
public var a:Number = 0;
public function onEnter(e:Event):void
{
vy += 0.18;
if (vecKey[ Keyboard.LEFT])
{
vx -= Math.cos(a);
vy -= Math.sin(a);
}
if (vecKey[ Keyboard.RIGHT] )
{
vx += Math.cos(a);
vy += Math.sin(a);
}
if (vecKey[ Keyboard.UP])
{ vy -= 0.3; }
if (vecKey[ Keyboard.DOWN] )
{ vy += 0.3; }
if (vy > 0 && bg.hitTestPoint(ps.x,ps.y+16,true))
{ vy =0; }
if (vx > 0 && bg.hitTestPoint(ps.x+16,ps.y,true))
{ vx =0;}
if (vx < 0 && bg.hitTestPoint(ps.x-16,ps.y,true))
{vx =0;}
a = 0;
if ( bg.hitTestPoint(ps.x+16,ps.y+12,true))
{ a = -0.3;}
if (vecKey[Keyboard.RIGHT] && bg.hitTestPoint(ps.x+17,ps.y,true))
{ a = -1.57;}
else if ( vecKey[Keyboard.LEFT] && bg.hitTestPoint(ps.x-17,ps.y,true))
{ a = 1.57;}
ps.rotation = a * (180/3.1415);
vx *= 0.99;
vy *= 0.99;
ps.x += vx;
ps.y += vy;
}//onenter
}//classend
}