Beispiel #1
0
    /// <summary>
    /// 设置曲线激光的长度
    /// <para>laser 曲线激光本体</para>
    /// <para>len 设置的长度</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetCurveLaserLength(ILuaState luaState)
    {
        EnemyCurveLaser laser = luaState.ToUserData(-2) as EnemyCurveLaser;
        int             len   = luaState.ToInteger(-1);

        laser.SetLength(len);
        return(0);
    }
Beispiel #2
0
    /// <summary>
    /// 设置曲线激光的宽带已经碰撞检测宽度
    /// <para>laser 曲线激光本体</para>
    /// <para>width 设置的宽度</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetCurveLaserWidth(ILuaState luaState)
    {
        EnemyCurveLaser laser = luaState.ToUserData(-2) as EnemyCurveLaser;
        float           width = (float)luaState.ToNumber(-1);

        laser.SetWidth(width);
        return(0);
    }
Beispiel #3
0
    private BulletBase NewBullet(BulletType bulletID)
    {
        BulletBase         bullet = null;
        Stack <BulletBase> _stack;

        // 判断对象池中是否有该类型的对象,如果有,则取出
        if (_bulletsPool.TryGetValue(bulletID, out _stack))
        {
            if (_stack.Count > 0)
            {
                bullet = _stack.Pop();
            }
        }
        else
        {
            _stack = new Stack <BulletBase>();
            _bulletsPool.Add(bulletID, _stack);
        }
        // 如果对象池内没有该对象,则创建
        if (bullet == null)
        {
            switch (bulletID)
            {
            case BulletType.ReimuA_Sub1:
                bullet = new BulletReimuASub1();
                break;

            case BulletType.Player_Laser:
                bullet = new PlayerLaser();
                break;

            case BulletType.Player_Simple:
                bullet = new PlayerBulletSimple();
                break;

            case BulletType.Enemy_Laser:
                bullet = new EnemyLaser();
                break;

            case BulletType.Enemy_CurveLaser:
                bullet = new EnemyCurveLaser();
                break;

            case BulletType.Enemy_Simple:
                bullet = new EnemySimpleBullet();
                break;

            case BulletType.Enemy_LinearLaser:
                bullet = new EnemyLinearLaser();
                break;

            default:
                Logger.Log("Create Bullet Fail! Invalid BulledId!");
                break;
            }
        }
        return(bullet);
    }
Beispiel #4
0
    /// <summary>
    /// 曲线激光的曲线运动
    /// <para>radius 初始半径</para>
    /// <para>angle 初始角度</para>
    /// <para>deltaR 半径增量</para>
    /// <para>omega 角速度</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetCurveLaserCurveParas(ILuaState luaState)
    {
        EnemyCurveLaser laser  = luaState.ToUserData(-5) as EnemyCurveLaser;
        float           radius = (float)luaState.ToNumber(-4);
        float           angle  = (float)luaState.ToNumber(-3);
        float           deltaR = (float)luaState.ToNumber(-2);
        float           omega  = (float)luaState.ToNumber(-1);

        laser.SetPolarParas(radius, angle, deltaR, omega);
        return(0);
    }
Beispiel #5
0
    /// <summary>
    /// 加速运动
    /// <para>acce 加速度</para>
    /// <para>accAngle 加速度方向 Consts.VelocityAngle时跟速度方向一致</para>
    /// <para>int duration 加速度时间</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int DoCurveLaserAccelerationWithLimitation(ILuaState luaState)
    {
        EnemyCurveLaser laser       = luaState.ToUserData(-4) as EnemyCurveLaser;
        float           acce        = (float)luaState.ToNumber(-3);
        float           accAngle    = (float)luaState.ToNumber(-2);
        float           maxVelocity = (float)luaState.ToNumber(-1);

        luaState.Pop(4);
        laser.DoAccelerationWithLimitation(acce, accAngle, maxVelocity);
        return(0);
    }
Beispiel #6
0
    /// <summary>
    /// 创建曲线激光
    /// <para>id 配置id</para>
    /// <para>laserLen 激光长度</para>
    /// <para>posX</para>
    /// <para>posY</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCurveLaser(ILuaState luaState)
    {
        string id       = luaState.ToString(-4);
        int    laserLen = luaState.ToInteger(-3);
        float  posX     = (float)luaState.ToNumber(-2);
        float  posY     = (float)luaState.ToNumber(-1);

        luaState.Pop(4);
        EnemyCurveLaser laser = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_CurveLaser) as EnemyCurveLaser;

        laser.SetStyleById(id);
        laser.SetLength(laserLen);
        laser.SetPosition(posX, posY);
        luaState.PushLightUserData(laser);
        return(1);
    }
Beispiel #7
0
    /// <summary>
    /// 曲线激光的直线运动
    /// <para>v 速度</para>
    /// <para>vAngle 速度方向</para>
    /// <para>bool isAimToPlayer 是否指向玩家</para>
    /// <para>acce 加速度</para>
    /// <para>accAngle 加速度方向 Consts.VelocityAngle时跟速度方向一致</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetCurveLaserStraightParas(ILuaState luaState)
    {
        EnemyCurveLaser laser         = luaState.ToUserData(-6) as EnemyCurveLaser;
        float           v             = (float)luaState.ToNumber(-5);
        float           vAngle        = (float)luaState.ToNumber(-4);
        bool            isAimToPlayer = luaState.ToBoolean(-3);
        float           acce          = (float)luaState.ToNumber(-2);
        float           accAngle      = (float)luaState.ToNumber(-1);

        luaState.Pop(6);
        if (isAimToPlayer)
        {
            vAngle += MathUtil.GetAngleBetweenXAxis(Global.PlayerPos.x - laser.posX, Global.PlayerPos.y - laser.posY);
        }
        laser.DoMove(v, vAngle, acce, accAngle);
        return(0);
    }
Beispiel #8
0
    /// <summary>
    /// 创建曲线激光
    /// <para>string customizedName</para>
    /// <para>posX</para>
    /// <para>posY</para>
    /// <para>...args</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedCurveLaser(ILuaState luaState)
    {
        int    numArgs        = luaState.GetTop() - 3;
        string customizedName = luaState.ToString(-3 - numArgs);
        float  posX           = (float)luaState.ToNumber(-2 - numArgs);
        float  posY           = (float)luaState.ToNumber(-1 - numArgs);
        int    initFuncRef    = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, initFuncRef);
        // 将本体插入执行栈中
        EnemyCurveLaser laser = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_CurveLaser) as EnemyCurveLaser;

        laser.SetPosition(posX, posY);
        laser.AddOrGetComponent <BCCustomizedTask>();
        luaState.PushLightUserData(laser);
        for (int i = 0; i < numArgs; i++)
        {
            luaState.PushValue(-2 - numArgs);
        }
        luaState.Call(numArgs + 1, 0);
        // 将返回值压入栈中
        luaState.PushLightUserData(laser);
        return(1);
    }
Beispiel #9
0
    public static bool Get(object o, TValue key, out TValue res)
    {
        EnemyCurveLaser bullet = (EnemyCurveLaser)o;

        res = new TValue();
        if (key.TtIsString())
        {
            switch (key.SValue())
            {
                #region 基础变量
            case "x":
            {
                res.SetNValue(bullet.GetPosition().x);
                return(true);
            }

            case "y":
            {
                res.SetNValue(bullet.GetPosition().y);
                return(true);
            }

            case "rot":
            {
                res.SetNValue(bullet.GetRotation());
                return(true);
            }

            case "dx":
            {
                res.SetNValue(bullet.dx);
                return(true);
            }

            case "dy":
            {
                res.SetNValue(bullet.dy);
                return(true);
            }

                #endregion
                #region 运动相关变量
            case "v":
            {
                res.SetNValue(bullet.velocity);
                return(true);
            }

            case "vx":
            {
                res.SetNValue(bullet.vx);
                return(true);
            }

            case "vy":
            {
                res.SetNValue(bullet.vy);
                return(true);
            }

            case "vAngle":
            {
                res.SetNValue(bullet.vAngle);
                return(true);
            }

            case "maxV":
            {
                res.SetNValue(bullet.maxVelocity);
                return(true);
            }

            case "acce":
            {
                res.SetNValue(bullet.acce);
                return(true);
            }

            case "accAngle":
            {
                res.SetNValue(bullet.accAngle);
                return(true);
            }

                #endregion
                #region 子弹类专属变量
            case "timer":
            {
                res.SetNValue(bullet.timeSinceCreated);
                return(true);
            }

            case "SetSelfRotation":
            {
                res.SetClCsValue(_funcSetSelfRotaion);
                return(true);
            }

            case "SetStyleById":
            {
                res.SetClCsValue(_funcSetStyleById);
                return(true);
            }

                #endregion
                #region 运动类专属方法 ISTGMovable
            case "SetV":
            {
                res.SetClCsValue(_funcSetV);
                return(true);
            }

            case "SetAcce":
            {
                res.SetClCsValue(_funcSetAcce);
                return(true);
            }

            case "SetStraightParas":
            {
                res.SetClCsValue(_funcSetStraightParas);
                return(true);
            }

            case "SetPolarParas":
            {
                res.SetClCsValue(_funcSetPolarParas);
                return(true);
            }

            case "MoveTo":
            {
                res.SetClCsValue(_funcMoveTo);
                return(true);
            }

            case "MoveTowards":
            {
                res.SetClCsValue(_funcMoveTowards);
                return(true);
            }

            case "SetPos":
            {
                res.SetClCsValue(_funcSetPos);
                return(true);
            }

            case "GetPos":
            {
                res.SetClCsValue(_funcGetPos);
                return(true);
            }

                #endregion
                #region IAttachable
            case "AttachTo":
            {
                res.SetClCsValue(_funcAttachTo);
                return(true);
            }

            case "SetRelativePos":
            {
                res.SetClCsValue(_funcSetRelativePos);
                return(true);
            }

                #endregion
                #region Component
            case "AddTask":
            {
                res.SetClCsValue(_funcAddTask);
                return(true);
            }

            case "ChangeProperty":
            {
                res.SetClCsValue(_funcChangeProperty);
                return(true);
            }

                #endregion
                #region 激光相关
            case "SetWidth":
            {
                res.SetClCsValue(_funcSetWidth);
                return(true);
            }

            case "SetLength":
            {
                res.SetClCsValue(_funcSetLength);
                return(true);
            }
                #endregion
            }
        }
        res.SetSValue(string.Format("GetField from userData fail!Invalid key {0} for type {1}", key, typeof(EnemyCurveLaser).Name));
        return(false);
    }
Beispiel #10
0
    public static bool Set(object o, TValue key, ref TValue value)
    {
        EnemyCurveLaser bullet = (EnemyCurveLaser)o;

        if (key.TtIsString())
        {
            switch (key.SValue())
            {
                #region 基础变量
            case "x":
            {
                Vector2 pos = bullet.GetPosition();
                pos.x = (float)value.NValue;
                bullet.SetPosition(pos);
                return(true);
            }

            case "y":
            {
                Vector2 pos = bullet.GetPosition();
                pos.y = (float)value.NValue;
                bullet.SetPosition(pos);
                return(true);
            }

            case "rot":
            {
                bullet.SetRotation((float)value.NValue);
                return(true);
            }

                #endregion
                #region 运动相关变量
            case "v":
            {
                bullet.velocity = (float)value.NValue;
                return(true);
            }

            case "vx":
            {
                bullet.vx = (float)value.NValue;
                return(true);
            }

            case "vy":
            {
                bullet.vy = (float)value.NValue;
                return(true);
            }

            case "vAngle":
            {
                bullet.vAngle = (float)value.NValue;
                return(true);
            }

            case "maxV":
            {
                bullet.maxVelocity = (float)value.NValue;
                return(true);
            }

            case "acce":
            {
                bullet.acce = (float)value.NValue;
                return(true);
            }

            case "accAngle":
            {
                bullet.accAngle = (float)value.NValue;
                return(true);
            }

                #endregion
                #region 子弹类专属变量
            case "orderInLayer":
            {
                bullet.SetOrderInLayer((int)value.NValue);
                return(true);
            }

            case "checkCollision":
            {
                bullet.SetDetectCollision(value.BValue());
                return(true);
            }

            case "checkBorder":
            {
                bullet.SetCheckOutOfBorder(value.BValue());
                return(true);
            }
                #endregion
            }
        }
        value.SetSValue(string.Format("SetField of userData fail!Invalid key {0} for type {1}", key, typeof(EnemyCurveLaser).Name));
        return(false);
    }