예제 #1
0
    /// <summary>
    /// 碰撞检测
    /// </summary>
    /// <param name="collParas"></param>
    /// <returns></returns>
    private bool DetectCollisionWithEnemyBullet(EnemyBulletBase bullet)
    {
        if (bullet.Type == BulletType.Enemy_Laser)
        {
            return(false);
        }
        CollisionDetectParas collParas;

        switch (bullet.Type)
        {
        case BulletType.Enemy_Simple:
            collParas = bullet.GetCollisionDetectParas(0);
            break;

        case BulletType.Enemy_LinearLaser:
        case BulletType.Enemy_CurveLaser:
            collParas = bullet.GetCollisionDetectParas(-1);
            break;

        default:
            collParas = new CollisionDetectParas();
            break;
        }
        if (DetectCollisionWithCollisionParas(collParas))
        {
            CollidedByObject(bullet);
            return(true);
        }
        return(false);
    }
    /// <summary>
    /// 获取子弹的碰撞参数
    /// <para>bullet</para>
    /// <para>collisionIndex 第n个碰撞体</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int GetBulletCollisionDetectParas(ILuaState luaState)
    {
        EnemyBulletBase bullet = luaState.ToUserData(-2) as EnemyBulletBase;
        int             index  = luaState.ToInteger(-1);

        luaState.Pop(2);
        CollisionDetectParas collParas = bullet.GetCollisionDetectParas(index);

        luaState.PushInteger((int)collParas.type);
        luaState.PushNumber(collParas.centerPos.x);
        luaState.PushNumber(collParas.centerPos.y);
        luaState.PushNumber(collParas.radius);
        luaState.PushNumber(collParas.halfWidth);
        luaState.PushNumber(collParas.halfHeight);
        luaState.PushNumber(collParas.angle);
        return(7);
    }
예제 #3
0
    /// <summary>
    /// 碰撞检测
    /// </summary>
    /// <param name="collParas"></param>
    /// <returns></returns>
    private bool DetectCollisionWithEnemyBullet(EnemyBulletBase bullet)
    {
        int  nextColliderIndex = 0;
        int  curColliderIndex;
        bool isCollided = false;

        do
        {
            CollisionDetectParas collParas = bullet.GetCollisionDetectParas(nextColliderIndex);
            curColliderIndex  = nextColliderIndex;
            nextColliderIndex = collParas.nextIndex;
            if (DetectCollisionWithCollisionParas(collParas))
            {
                bullet.CollidedByObject(curColliderIndex, _eliminateType);
                isCollided = true;
            }
        } while (nextColliderIndex != -1);
        return(isCollided);
    }
예제 #4
0
 public override void Update()
 {
     for (int i = 0; i < _triggerDataCount; i++)
     {
         TriggerData data = _triggerDatas[i];
         if (data.triggerGroup == 0)
         {
             continue;
         }
         int listCount;
         List <ObjectColliderBase> colliderList = ColliderManager.GetInstance().GetColliderList(out listCount);
         ObjectColliderBase        collider;
         for (int j = 0; j < listCount; j++)
         {
             collider = colliderList[j];
             // 非空,且满足触发条件
             if (collider != null && ((int)collider.GetColliderGroup() & data.triggerGroup) != 0)
             {
                 int nextColliderIndex = 0;
                 int curColliderIndex;
                 do
                 {
                     CollisionDetectParas collParas = _bullet.GetCollisionDetectParas(nextColliderIndex);
                     curColliderIndex  = nextColliderIndex;
                     nextColliderIndex = collParas.nextIndex;
                     if (collider.DetectCollisionWithCollisionParas(collParas))
                     {
                         //InterpreterManager.GetInstance().AddPara(_bullet, LuaParaType.LightUserData);
                         InterpreterManager.GetInstance().AddPara(collider, LuaParaType.LightUserData);
                         InterpreterManager.GetInstance().AddPara(curColliderIndex, LuaParaType.Int);
                         InterpreterManager.GetInstance().CallLuaFunction(data.triggerFuncRef, 2, 0);
                     }
                 } while (nextColliderIndex != -1);
             }
         }
     }
 }