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;
}
}
}
}
弹跳的小球
最新推荐文章于 2021-02-13 02:31:42 发布