【練習】宇宙船?

by Tamanegi_kenshi
♥0 | Line 64 | Modified 2010-02-14 04:28:13 | MIT License
play

ActionScript3 source code

/**
 * Copyright Tamanegi_kenshi ( http://wonderfl.net/user/Tamanegi_kenshi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pzuA
 */

package{
	import flash.accessibility.Accessibility;
	import flash.text.engine.EastAsianJustifier;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

[SWF(width = 500, height=500, backgroundColor = 0x000000)]

public class Ship extends Sprite{
	private var shi:Sprite;
	private var vr:Number =0;
	private var force:Number =0;
	private var vx:Number =0;
	private var vy:Number =0;

	
	public function Ship(){
		draw();
		}
	private function draw():void{
		shi = new Sprite();
		with(shi.graphics){
			lineStyle(1 ,0xffffff);
			moveTo(10,0);
			lineTo(-10,10);
		    lineTo(-5,0);
		    lineTo(-10,-10);
			lineTo(10,0);
		
		
		
		
				}
				
				
				
			shi.x=200;
			shi.y=200;
			addChild(shi);
			addEventListener(Event.ENTER_FRAME,onEnterFrame);
			stage.addEventListener(KeyboardEvent.KEY_DOWN,down);
			stage.addEventListener(KeyboardEvent.KEY_UP,up);
			
		}
		
	private function onEnterFrame(event:Event):void{
		shi.rotation +=vr;
		var angle:Number =shi.rotation *Math.PI/180;
		var ax:Number =Math.cos(angle)*force;
		var ay:Number =Math.sin(angle)*force;
		vx +=ax;
		vy +=ay;
		shi.x +=vx;
		shi.y +=vy;
	
	
		
		}
	private function down(event:KeyboardEvent):void{
		switch(event.keyCode){
			case Keyboard.LEFT:
			vr =-5;
			break;
			case Keyboard.RIGHT:
			vr =5;
			break;
			case Keyboard.UP:
			force =0.1;
			break;
			
			default:	
				}
				
		}
	private function up(event:KeyboardEvent):void{
		vr=0;
		force=0;

		}
	}	
	
	
	}