forked from: 【練習】バルーンファイト的な動き?

by marcsali forked from 【練習】バルーンファイト的な動き? (diff: 1)
♥0 | Line 86 | Modified 2013-01-20 00:13:37 | MIT License
play

ActionScript3 source code

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

// forked from Tamanegi_kenshi's 【練習】バルーンファイト的な動き?
package{
	import flash.accessibility.Accessibility;
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.events.KeyboardEvent;
 import flash.ui.Keyboard;
 import flash.display.Shape;
 
 public class test extends Sprite{
   private var ball:Sprite;
   private var sen:Shape;
   private var maru:Shape;
   private var vx:Number  =0;
   private var vy:Number  =0;
   private var ax:Number =0;
   private var ay:Number =0;
   private var gravity:Number =0.03;
 
   
   public function test(){
   	init();
   	}
   private function init():void{
   	ball =new Sprite();
   	with(ball.graphics){
   		beginFill(0xff0000);
   		drawEllipse(0,0,50,20);
   		ball.x =0;
   		ball.y = stage.stageHeight/2;
   		
   		endFill();
   	}
   	sen =new Shape();
   	with(sen.graphics){
   		lineStyle(1);
   		moveTo(0,400);
   		lineTo(stage.stageHeight,400);
   		}
   		
   	maru =new Shape();
   	with(maru.graphics){
   		beginFill(0xff0000);
   		drawCircle(25,5,10);
   		endFill();
   		}
   	
   	ball.addChild(maru);
   	addChild(sen);
   	addChild(ball);
   	addEventListener(Event.ENTER_FRAME,onEnterFrame);
   	stage.addEventListener(KeyboardEvent.KEY_DOWN,down);
   	stage.addEventListener(KeyboardEvent.KEY_UP,up);
   	
   	}
 	private function onEnterFrame(event:Event):void{
 			if(ball.y >380){
 		
 		
 		ball.y =380;
 	    vy*=-1*0.5;
 	    vx*=0.9;
 		ax=ay=0;
 		}
 	
 		
 		ball.x +=vx;
 		ball.y +=vy;
 		vx +=ax;
 		vy +=ay;
 		vy +=gravity;
 }
 private function down(event:KeyboardEvent):void{
 
 	switch(event.keyCode){
 		case Keyboard.LEFT:
 			ax =-0.1;
 			break;
 			case Keyboard.RIGHT:
 			ax =0.1;
 			break;
 			case Keyboard.DOWN:
 			ay =0.1;
 			break;
 			case Keyboard.UP:
 			ay=-0.1;
 			break;
 		case Keyboard.SPACE:
 			ball.x=stage.stageHeight/2;
 			ball.y=380 ;
 			vx=vy=0;
 			break;
 	}				
 	}
 	 private function up(event:KeyboardEvent):void{
 	 	ax=ay=0;
 	}
 	
 
 
 } 	
}