问题描述
我正在用as3开发游戏,一方面,我在调试它时遇到了当前的错误。 该错误发生在角色跳跃时,因为角色没有回到正确的位置,这也导致了碰撞不起作用。
其他问题是死亡碰撞后重新启动游戏,这部分速度比以前高。有人可以帮助我吗?
代码:
chico.addEventListener(Event.ENTER_FRAME,moveChar);
hater.addEventListener(Event.ENTER_FRAME,moveHater);
hater3.addEventListener(Event.ENTER_FRAME,moveHater3);
hater4.addEventListener(Event.ENTER_FRAME,moveHater4);
hater5.addEventListener(Event.ENTER_FRAME,moveHater5);
deslikito.addEventListener(Event.ENTER_FRAME,moveDeslikito);
deslikito2.addEventListener(Event.ENTER_FRAME,moveDeslikito2);
deslikito3.addEventListener(Event.ENTER_FRAME,moveDeslikito3);
deslikito4.addEventListener(Event.ENTER_FRAME,moveDeslikito4);
stage.addEventListener(KeyboardEvent.KEY_DOWN,tecla_baixo);
stage.addEventListener(KeyboardEvent.KEY_UP,tecla_cima);
stage.addEventListener(Event.ENTER_FRAME,inimigos);
stage.addEventListener(Event.ENTER_FRAME,buracos);
var left:Boolean = false;
var right:Boolean = false;
var esqDown:Boolean = false;
var cimaDown:Boolean = false;
var dirDown:Boolean = false;
var baixoDown:Boolean = false;
var poder:Boolean = false;
var velocidade:Number = 0;
var mainPulo:Boolean = false;
var jumpSpeedLimit:int = 10;
var jumpSpeed:Number = 0;
var vfogo:Number = 20;
like.visible = false;
moeda1.visible = false;
moeda2.visible = false;
moeda3.visible = false;
moeda4.visible = false;
moeda5.visible = false;
moeda6.visible = false;
moeda7.visible = false;
moeda8.visible = false;
moeda9.visible = false;
moeda10.visible = false;
moeda11.visible = false;
moeda12.visible = false;
moeda13.visible = false;
moeda14.visible = false;
moeda15.visible = false;
buraco.visible = false;
chico.fogo.visible = false;
btf2.visible = false;
btf2.addEventListener(MouseEvent.MOUSE_DOWN,gofase2);
function gofase2 (e:MouseEvent):void{
gotoAndStop(15);
}
function moveHater(event:Event):void
{
hater.x -= 2;
}
function moveHater3(event:Event):void
{
hater3.x -= 2;
}
function moveHater4(event:Event):void
{
hater4.x -= 2;
}
function moveHater5(event:Event):void
{
hater5.x -= 2;
}
function moveDeslikito(event:Event):void
{
deslikito.x -= 2;
}
function moveDeslikito2(event:Event):void
{
deslikito2.x -= 2;
}
function moveDeslikito3(event:Event):void
{
deslikito3.x -= 2;
}
function moveDeslikito4(event:Event):void
{
deslikito4.x -= 2;
}
function moveChar(event:Event):void
{
if (esqDown)
{
velocidade = 0.5;
chico.x -= velocidade * 5;
chico.gotoAndStop("voltando");
}
if (dirDown)
{
velocidade = 0.5;
chico.gotoAndStop("andando");
chico.x += velocidade;
plataforma.x -= 10;
deslikito7.x -= 10;
deslikito6.x -= 10;
deslikito5.x -= 10;
deslikito4.x -= 10;
deslikito3.x -= 10;
deslikito2.x -= 10;
deslikito.x -= 10;
cenario.x -= 10;
luckyq2.x -= 10;
luckyq3.x -= 10;
luckyq4.x -= 10;
luckyq5.x -= 10;
luckyq6.x -= 10;
luckyq7.x -= 10;
luckyq8.x -= 10;
luckyq9.x -= 10;
luckyq10.x -= 10;
luckyq11.x -= 10;
luckyq12.x -= 10;
luckyq13.x -= 10;
luckyq14.x -= 10;
luckyq15.x -= 10;
luckyq16.x -= 10;
luckyq.x -= 10;
buraco.x -= 10;
moeda10.x -= 10;
moeda11.x -= 10;
moeda9.x -= 10;
moeda8.x -= 10;
moeda7.x -= 10;
moeda6.x -= 10;
moeda5.x -= 10;
moeda4.x -= 10;
moeda3.x -= 10;
moeda2.x -= 10;
moeda1.x -= 10;
buraco.x -= 10;
square1.x -= 10;
hater9.x -= 10;
hater8.x -= 10;
hater7.x -= 10;
hater6.x -= 10;
hater5.x -= 10;
hater4.x -= 10;
hater3.x -= 10;
hater2.x -= 10;
hater.x -= 10;
plat1.x -= 10;
plat2.x -= 10;
btf2.x -= 10;
like.x -= 10;
base.x -= 10;
fim.x -= 10;
}
if (cimaDown || mainPulo)
{
mainJump();
}
}
function tecla_baixo(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
esqDown = true;
}
if (event.keyCode == 32)
{
cimaDown = true;
}
if (event.keyCode == 39)
{
dirDown = true;
}
if (event.keyCode == 40)
{
baixoDown = true;
}
if (event.keyCode == 81)
{
poder = true;
chico.gotoAndStop("poder");
}
}
function tecla_cima(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
esqDown = false;
chico.gotoAndStop(1);
}
if (event.keyCode == 32)
{
cimaDown = false;
chico.gotoAndStop(1);
}
if (event.keyCode == 39)
{
dirDown = false;
chico.gotoAndStop(1);
}
if (event.keyCode == 40)
{
baixoDown = false;
chico.gotoAndStop(1);
}
else
{
chico.gotoAndStop(1);
}
}
function mainJump():void
{
if (! mainPulo)
{
mainPulo = true;
chico.gotoAndStop("pulo");
jumpSpeed = jumpSpeedLimit * -2;
chico.y += jumpSpeed;
}
else
{
if (jumpSpeed < 0)
{
chico.gotoAndStop("pulo");
jumpSpeed *= 1 - jumpSpeedLimit / 100;
if (jumpSpeed > -jumpSpeedLimit/5)
{
jumpSpeed *= -2;
}
}
if (jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
{
jumpSpeed *= 1 + jumpSpeedLimit / 100;
}
chico.y += jumpSpeed;
if (chico.y >= stage.stageHeight - 450 - chico.height)
{
mainPulo = false;
chico.y = stage.stageHeight - 450 - chico.height;
chico.gotoAndStop("parado");
}
else if ((chico.y >= stage.stageHeight - 450-chico.height)&& (esqDown = true))
{
mainPulo = false;
chico.y = stage.stageHeight - 450 - chico.height;
chico.gotoAndStop("parado");
}
else if ((chico.y >= stage.stageHeight - 450-chico.height)&& (dirDown = true))
{
mainPulo = false;
chico.y = stage.stageHeight - 450 - chico.height;
chico.gotoAndStop("parado");
}
}
}
function inimigos(e:Event):void{
if(chico.hitTestObject(deslikito)){
chico.visible = false;
trace('bateu');
gotoAndStop("gueimiouver");
}
if(chico.hitTestObject(deslikito2)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(deslikito3)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(deslikito4)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(deslikito5)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(hater)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(hater2)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(hater3)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(hater4)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(hater5)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}
if(chico.hitTestObject(fim)){
//btf2.visible=true;
trace('bateu');
gotoAndStop(15);
}
}
function buracos(e:Event):void{
if(chico.hitTestObject(square1)){
chico.visible = false;
trace('bateu');
gotoAndStop(10);
}}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)