flash on 2015-1-2
♥0 |
Line 81 |
Modified 2015-01-02 06:48:34 |
MIT License
archived:2017-03-30 11:50:40
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/9KLj
*/
package {
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKdown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKup);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public function onKdown(e:KeyboardEvent):void { vecKey[e.keyCode] = true; }
public function onKup(e:KeyboardEvent):void { vecKey[e.keyCode] = false; }
public function isKeyDown(k:int):Boolean { return vecKey[k]; }
public var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512, false);
public var myBlob:xBlob = new xBlob();
public var cx:Number = 130;
public var cy:Number = 230;
public var vx:Number = 0;
public var vy:Number = 0;
public var onBlob:int = 0;
public function setWalk(ms:Number, ac:Number=0.3):void
{
if (vx < ms) { vx += ac; if (vx > ms) { vx = ms;} }
if (vx > ms) { vx -= ac; if (vx < ms) { vx =ms; } }
}
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0);
var bStartGround:Boolean;
var rad:Number;
rad = 8;
var gy:Number;
gy = 300;
vy += 0.3;
bStartGround = (cy+rad >= gy) || onBlob > 0;
var ac:Number; var ms:Number;
ms = 6; ac = 1;
if (isKeyDown(Keyboard.RIGHT)) { setWalk(ms, ac); }
if (isKeyDown(Keyboard.LEFT)) { setWalk(-ms, ac);}
if (bStartGround)
if (isKeyDown(Keyboard.UP)) { vy = -7; bStartGround = false; }
if (vy > 0 && cy+rad >= gy) { cy =gy-rad; vy = 0; }
vx *= 0.95; vy *= 0.95;
cx +=vx; cy +=vy;
graphics.drawCircle(cx,cy, rad);
graphics.drawRect(0, gy, 430, 64);
var a:xBlob;
a = myBlob;
a.cy = gy - a.rad;
a.vx *= 0.9;
if (a.vx >0 && a.cx >= 300) { a.cx = 300; a.vx = 0;}
if (a.vx <0 && a.cx <= 100) { a.cx = 100; a.vx = 0;}
a.cx += a.vx;
graphics.drawCircle(a.cx, a.cy, a.rad);
graphics.drawRect(a.cx-a.rad,a.cy-a.rad,a.rad*2,a.rad*2);
onBlob = 0;
if (a.cx + a.rad < cx - rad) { return ; }
if (a.cx - a.rad > cx + rad) { return ; }
if (a.cy + a.rad < cy - rad) { return ; }
if (a.cy - a.rad > cy + rad) { return ; }
graphics.beginFill(0, 0.5);
graphics.drawRect(a.cx-a.rad,a.cy-a.rad,a.rad*2,a.rad*2);
graphics.endFill();
//if (vy >0 && cy < a.cy-a.rad) { vy = -4; }
if (vy >=0 && cy < a.cy-a.rad) { cy = a.cy-a.rad-rad; vy =0; onBlob = 1; }
if (vx > 0 && cx < a.cx-a.rad) { a.vx += vx; vx *= 0.5; /*cx = a.cx -a.rad-rad;*/ }
if (vx < 0 && cx > a.cx+a.rad) { a.vx += vx; vx *= 0.5; /*cx = a.cx +a.rad+rad;*/ }
}//onenter
}//classend
}
internal class xBlob
{
public var cx:Number = 230;
public var cy:Number = 230;
public var vx:Number = 0;
public var vy:Number = 0;
public var rad:Number = 16;
}//xblob