宇宙船!!!
左右キーで回転。
上キーでロケット噴射。
♥0 |
Line 89 |
Modified 2009-09-05 11:29:07 |
MIT License
archived:2017-03-10 21:59:12
ActionScript3 source code
/**
* Copyright pykgg476 ( http://wonderfl.net/user/pykgg476 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/76Zj
*/
//左右キーで回転。
//上キーでロケット噴射。
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class ShipSim extends Sprite
{
private var vr:Number = 0;
private var ship:Sprite;
private var thrust:Number=0;
private var vx:Number = 0;
private var vy:Number = 0;
private var flame:Boolean = false;
public function ShipSim()
{
init();
}
private function init():void{
ship = new Sprite();
addChild(ship);
ship.graphics.clear();
ship. graphics.lineStyle(1,0xffffff);
ship. graphics.moveTo(10,0);
ship. graphics.beginFill(0x000000);
ship. graphics.lineTo(-10,10);
ship. graphics.lineTo(-5,0);
ship. graphics.lineTo(-10,-10);
ship. graphics.lineTo(10,0);
ship.x = stage.stageWidth/2;
ship.y = stage.stageHeight/2;
addEventListener(Event.ENTER_FRAME,onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
}
private function onKeyDown(event:KeyboardEvent):void{
switch(event.keyCode){
case Keyboard.LEFT:
vr = -5;
break;
case Keyboard.RIGHT:
vr = 5;
break;
case Keyboard.UP:
thrust = 0.2;
flame = true;
break;
default:
break;
}
}
private function onKeyUp(event:KeyboardEvent):void{
vr = 0;
thrust = 0;
flame = false;
}
private function onEnterFrame(event:Event):void{
if(flame == true){
ship.graphics.clear();
ship. graphics.lineStyle(1,0xffffff);
ship.graphics.moveTo(10,0);
ship.graphics.beginFill(0x000000);
ship.graphics.lineTo(-10,10);
ship.graphics.lineTo(-5,0);
ship.graphics.lineTo(-10,-10);
ship.graphics.lineTo(10,0);
ship.graphics.moveTo(-7.5,-5);
ship.graphics.lineTo(-15,0);
ship.graphics.lineTo(-7.5,5);
}else{
ship.graphics.clear();
ship. graphics.lineStyle(1,0xffffff);
ship.graphics.moveTo(10,0);
ship.graphics.beginFill(0x000000);
ship.graphics.lineTo(-10,10);
ship.graphics.lineTo(-5,0);
ship.graphics.lineTo(-10,-10);
ship.graphics.lineTo(10,0);
}
ship.rotation += vr;
var angle:Number = ship.rotation * Math.PI/180;
var ax:Number = Math.cos(angle)*thrust;
var ay:Number = Math.sin(angle)*thrust;
vx += ax;
vy += ay;
ship.x += vx;
ship.y += vy;
}
}
}