弹跳的小球

跳动小球

package 
{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.ui.Keyboard;
	import flash.events.KeyboardEvent;
	
	
	public class  main extends Sprite
	{
		
		public var ball:Sprite;
		public var border:Sprite;
		public var vy:Number = 0;
		public var g:Number = 0.9;
		
		public function main()
		{
			//stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
			//stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
			addEventListener(Event.ENTER_FRAME,frameHandler);
		}
		
		/*public function keyDownHandler(e:KeyboardEvent):void
		{
			//trace("键盘按下");
			switch(e.keyCode)
			{
				case Keyboard.LEFT:
					vx = -5;
					break;
				case Keyboard.RIGHT:
					vx = 5;
					break;
			}
		}
		
		public function keyUpHandler(e:KeyboardEvent):void
		{
			//trace("键盘抬起");
			switch(e.keyCode)
			{
				case Keyboard.LEFT:
					vx = 0;
					break;
				case Keyboard.RIGHT:
					vx = 0;
					break;
			}
		}*/
		public function frameHandler(e:Event):void
		{
			vy += g;
			ball.y += vy;
			//if (ball.y >= border.y-ball.height)
			if(ball.hitTestObject(border))
			{
				ball.y = border.y - ball.height;
				vy = -20;
			}
		}	
	}
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值