flash on 2012-8-29
♥0 |
Line 63 |
Modified 2012-08-29 23:23:51 |
MIT License
archived:2017-03-30 23:00:09
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/mcQl
*/
package {
import flash.display.Graphics;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var ap:aPlayer;
public function FlashTest() {
// write as3 code here..
graphics.clear();
graphics.lineStyle(2,0);
graphics.drawRect(0,0,300,200);
roomLayer = new Sprite();
addChild(roomLayer);
ap = new aPlayer();
ap.x = 150;
ap.y = 100;
addChild(ap);
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 function onEnter(e:Event):void
{
if (vecKey[Keyboard.UP]) {ap.y-=4;}
if (vecKey[Keyboard.DOWN]) {ap.y+=4;}
if (vecKey[Keyboard.LEFT]) {ap.x-=4;}
if (vecKey[Keyboard.RIGHT]) {ap.x+=4;}
if (ap.y < 0) { ap.y = 200; newRoom(); }
if (ap.y > 200) {ap.y = 0;newRoom(); }
if (ap.x < 0) { ap.x = 300;newRoom(); }
if (ap.x > 300) { ap.x = 0;newRoom(); }
}//onenter
public var roomLayer:Sprite;
public function newRoom():void
{
var g:Graphics;
g = roomLayer.graphics;
g.clear();
g.lineStyle(1,0);
var i:int;
for (i =0; i < 16; i++)
{
g.drawRect(Math.random()*300,Math.random()*200,16,16);
}//nexti
}//newroom
}//classend
}
import flash.display.Sprite;
internal class aPlayer extends Sprite
{
public function aPlayer():void
{
graphics.clear();
graphics.lineStyle(2,0);
graphics.drawCircle(0,0,8);
}//ctor
}//classend