package com.basics.stick
{
import flash.display.MovieClip;
import flash.display.Stage;
import com.basics.senocular.utils.KeyObject;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class StickMan extends MovieClip
{
private var stageRef:Stage;
private var key:KeyObject;
private var speed:Number = 2;
private var vx:Number = 0;
private var vy:Number = 0;
private var friction:Number = 0.93;
private var maxspeed:Number = 8;
private var fireTimer:Timer;
private var canFire:Boolean = true;
public function StickMan(stageRef:Stage)
{
this.stageRef = stageRef;
key = new KeyObject(stageRef);
fireTimer = new Timer(300,1);
fireTimer.addEventListener(TimerEvent.TIMER, fireTimerHandler, false, 0, true);
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function fireTimerHandler(e:TimerEvent):void
{
canFire = true;
}
private function fireBullet():void
{
if (canFire)
{
stageRef.addChild(new Bullet(stageRef,x+vx+35, y+10));
canFire = false;
fireTimer.start();
}
}
public function loop(e:Event):void
{
if (key.isDown(Keyboard.LEFT))
{
vx -= speed;
}
else if (key.isDown(Keyboard.RIGHT))
{
vx += speed;
}
else
{
vx *= friction;
}
if (key.isDown(Keyboard.UP))
{
vy -= speed;
}
else if (key.isDown(Keyboard.DOWN))
{
vy += speed;
}
else
{
vy *= friction;
}
if (key.isDown(Keyboard.SPACE))
{
fireBullet();
}
x += vx;
y += vy;
if (vx > maxspeed)
{
vx = maxspeed;
}
else if (vx<-maxspeed)
{
vx = - maxspeed;
}
if (vy > maxspeed)
{
vy = maxspeed;
}
else if (vy<-maxspeed)
{
vy = - maxspeed;
}
if (x > stageRef.stageWidth)
{
x = stageRef.stageWidth;
vx = - vx;
}
else if (x<0)
{
x = 0;
vx = - vx;
}
if (y > stageRef.stageHeight)
{
y = stageRef.stageHeight;
vy = - vy;
}
else if (y<0)
{
y = 0;
vy = - vy;
}
}
}
}
我想要的是当我按下向上按钮时,不仅仅是向上,而是跳跃,然后下降到特定的 y。我在网上搜索,但是大部分教程或其他用户都将代码放在字符中。但是我想要的是修改上面的代码,并使字符跳转。任何指导或任何东西都非常受欢迎。
提前感谢您的时间!:)