我目前正在为我的游戏构建伤害机制。两个类处理这个,“伤害”类和“碰撞”类。伤害类将自身的一个实例传递给碰撞类的“hurtCollision”方法,以便碰撞类可以检测玩家与伤害实例(显示对象)之间的碰撞。但是,当我尝试访问该功能时,出现此错误:
1061: Call to a possibly undefined method hurtCollision through a reference with static type Class.
这是两个类:
碰撞类(你可以 ctrl f 来伤害碰撞):
package
{
import flash.display.MovieClip;
public class Collision extends MovieClip
{
private var e:*;
static public var _playerX:*;
static public var _playerY:*;
private var HIT_BOTTOM_1X:Number;
private var HIT_BOTTOM_2X:Number;
private var HIT_BOTTOM_3X:Number;
private var HIT_TOP_1X:Number;
private var HIT_TOP_2X:Number;
private var HIT_TOP_3X:Number;
private var HIT_R_1X:Number;
private var HIT_R_2X:Number;
private var HIT_R_3X:Number;
private var HIT_L_1X:Number;
private var HIT_L_2X:Number;
private var HIT_L_3X:Number;
private var HIT_BOTTOM_1Y:Number;
private var HIT_BOTTOM_2Y:Number;
private var HIT_BOTTOM_3Y:Number;
private var HIT_TOP_1Y:Number;
private var HIT_TOP_2Y:Number;
private var HIT_TOP_3Y:Number;
private var HIT_R_1Y:Number;
private var HIT_R_2Y:Number;
private var HIT_R_3Y:Number;
private var HIT_L_1Y:Number;
private var HIT_L_2Y:Number;
private var HIT_L_3Y:Number;
public function Collision(enginePass:*)
{
e = enginePass;
}
public function detectCollisions(object:*):void
{
_playerX = e._player.x;
_playerY = e._player.y;
HIT_BOTTOM_1X = object.x - object.width/2;
HIT_BOTTOM_2X = object.x;
HIT_BOTTOM_3X = object.x + object.width/2;
HIT_TOP_1X = object.x - object.width/2;
HIT_TOP_2X = object.x;
HIT_TOP_3X = object.x + object.width/2;
HIT_R_1X = object.x + object.width/2;
HIT_R_2X = object.x + object.width/2;
HIT_R_3X = object.x + object.width/2;
HIT_L_1X = object.x - object.width/2;
HIT_L_2X = object.x - object.width/2;
HIT_L_3X = object.x - object.width/2;
HIT_BOTTOM_1Y = object.y + object.height/2;
HIT_BOTTOM_2Y = object.y + object.height/2;
HIT_BOTTOM_3Y = object.y + object.height/2;
HIT_TOP_1Y = object.y - object.height/2;
HIT_TOP_2Y = object.y - object.height/2;
HIT_TOP_3Y = object.y - object.height/2;
HIT_R_1Y = object.y + object.height/2 - object.height/4;
HIT_R_2Y = object.y;
HIT_R_3Y = object.y - object.height/2 + object.height/4;
HIT_L_1Y = object.y + object.height/2 - object.height/4;
HIT_L_2Y = object.y;
HIT_L_3Y = object.y - object.height/2 - object.height/4;
if(e._ground.hitTestPoint(HIT_BOTTOM_1X,HIT_BOTTOM_1Y,true) || e._ground.hitTestPoint(HIT_BOTTOM_2X,HIT_BOTTOM_2Y,true)
|| e._ground.hitTestPoint(HIT_BOTTOM_3X,HIT_BOTTOM_3Y,true))
{
e._touchGround = true;
if(e._vy < 0)
{
e._vy = 0;
}
}
if(e._ground.hitTestPoint(HIT_TOP_1X,HIT_TOP_1Y,true) || e._ground.hitTestPoint(HIT_TOP_2X,HIT_TOP_2Y,true)
|| e._ground.hitTestPoint(HIT_TOP_3X,HIT_TOP_3Y,true))
{
e._jump = false;
e._vy = -(e._vy) - 5;
}
if(e._ground.hitTestPoint(HIT_R_1X,HIT_R_1Y,true) || e._ground.hitTestPoint(HIT_R_2X,HIT_R_2Y,true)
|| e._ground.hitTestPoint(HIT_R_3X,HIT_R_3Y,true))
{
if(e._vx > 0)
{
e._vy += e._vx;
}
if(e._ground.hitTestPoint(HIT_TOP_3X, HIT_TOP_3Y, true))
{
if(e._vx > 0)
{
e._vx = -(e._vx) *2;
}
}
}
if(e._ground.hitTestPoint(HIT_L_1X,HIT_L_1Y,true) || e._ground.hitTestPoint(HIT_L_2X,HIT_L_2Y,true)
|| e._ground.hitTestPoint(HIT_L_3X,HIT_L_3Y,true))
{
if(e._vx < 0)
{
e._vy += Math.abs(e._vx);
}
if(e._ground.hitTestPoint(HIT_TOP_1X, HIT_TOP_1Y, true))
{
if(e._vx < 0)
{
e._vx = -(e._vx) *2;
}
}
}
if(e._ground.hitTestPoint(HIT_TOP_3X, HIT_TOP_3Y, true) && e._ground.hitTestPoint(HIT_BOTTOM_3X, HIT_BOTTOM_3Y, true))
{
e._vy += 20;
}
if(e._ground.hitTestPoint(HIT_TOP_1X, HIT_TOP_1Y, true) && e._ground.hitTestPoint(HIT_BOTTOM_1X, HIT_BOTTOM_1Y, true))
{
e._vy += 20;
}
if(e._ground.hitTestPoint(e._player.x,e._player.y, true))
{
e._vy = -(e._vy);
e._vx = -(e._vx);
}
else
{
if(!(e._ground.hitTestPoint(HIT_BOTTOM_1X,HIT_BOTTOM_1Y,true) || e._ground.hitTestPoint(HIT_BOTTOM_2X,HIT_BOTTOM_2Y,true)
|| e._ground.hitTestPoint(HIT_BOTTOM_3X,HIT_BOTTOM_3Y,true)))
{
e._vy -= 1;
e._touchGround = false;
}
}
}
public function hurtCollision(hurtObject:*)
{
if(hurtObject.hitTestPoint(HIT_BOTTOM_1X,HIT_BOTTOM_1Y,true) || hurtObject.hitTestPoint(HIT_BOTTOM_2X,HIT_BOTTOM_2Y,true)
|| hurtObject.hitTestPoint(HIT_BOTTOM_3X,HIT_BOTTOM_3Y,true))
{
e.hurtPlayer();
}
if(hurtObject.hitTestPoint(HIT_TOP_1X,HIT_TOP_1Y,true) || hurtObject.hitTestPoint(HIT_TOP_2X,HIT_TOP_2Y,true)
|| hurtObject.hitTestPoint(HIT_TOP_3X,HIT_TOP_3Y,true))
{
e.hurtPlayer();
}
if(hurtObject.hitTestPoint(HIT_R_1X,HIT_R_1Y,true) || hurtObject.hitTestPoint(HIT_R_2X,HIT_R_2Y,true)
|| hurtObject.hitTestPoint(HIT_R_3X,HIT_R_3Y,true))
{
e.hurtPlayer();
}
if(hurtObject.hitTestPoint(HIT_L_1X,HIT_L_1Y,true) || hurtObject.hitTestPoint(HIT_L_2X,HIT_L_2Y,true)
|| hurtObject.hitTestPoint(HIT_L_3X,HIT_L_3Y,true))
{
e.hurtPlayer();
}
}
}
}
伤害等级:
package
{ 导入 flash.display.MovieClip; 导入 flash.events.Event;导入碰撞;
public class Hurt extends MovieClip
{
public function Hurt()
{
addEventListener(Event.ENTER_FRAME, enterFrame);
}
private function enterFrame(e:Event)
{
Collision.hurtCollision(this);
}
}
}
编辑:让大家知道,e.hurtPlayer 只是控制玩家健康的文档类方法。