forked from: forked from: forked from: ボール

by 084 forked from forked from: forked from: ボール (diff: 60)
♥0 | Line 79 | Modified 2011-11-06 21:59:39 | MIT License
play

ActionScript3 source code

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

// forked from 084's forked from: forked from: ボール
// forked from 084's forked from: ボール
// forked from 084's ボール
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.ui.Keyboard;
	import flash.events.KeyboardEvent;
		
	public class Test extends Sprite
	{
		private var ball:Ball;
		
		private var vx:Number;
		private var vy:Number;
		
				
		public function Test()
		{
		    vx = 0;
			vy = 0;
			
			ball = new Ball();
			
			ball.x = stage.stageWidth / 2;
			ball.y = stage.stageHeight / 2;
			
			addChild(ball);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			stage.addEventListener(KeyboardEvent.KEY_DOWN , onKeyDown);
			stage.addEventListener(KeyboardEvent.KEY_UP , onKeyUp );
		}
		private function onEnterFrame(e:Event)
		{
			ball.x += vx;
			ball.y += vy;
		}
		private function onKeyDown(e:KeyboardEvent)
		{
			if (e.keyCode == Keyboard.LEFT)
			{
				vx = -5;
			}
			else if (e.keyCode == Keyboard.RIGHT)
			{
				vx = 5;
			}
			if (e.keyCode == Keyboard.UP)
			{
				vy = -5;
			}
			else if (e.keyCode == Keyboard.DOWN)
			{
				vy = 5;
			}
		}
		private function onKeyUp(e:KeyboardEvent)
		{
			if (e.keyCode == Keyboard.RIGHT || e.keyCode == Keyboard.LEFT)
			{
				vx = 0;
			}
			else if (e.keyCode == Keyboard.UP || e.keyCode == Keyboard.DOWN)
			{
				vy = 0;
			}
		}
	}
}




	import flash.display.Sprite;
	class Ball extends Sprite
	{
		private var hankei:Number;
		private var iro:uint;
		
		public function Ball(hanikei:Number = 10, iro:uint = 0x666666)
		{
			this.hankei = hanikei;
			this.iro = iro;
			
			init();
		}
		private function init():void
		{
			graphics.beginFill(iro);
			graphics.drawCircle(0, 0, hankei);
			graphics.endFill();
                        
		}
	}




	
	 

Forked