Beispiel #1
0
    /// <summary>
    /// 设置直线运动参数
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int STGMovableSetStraightParas(ILuaState luaState)
    {
        ISTGMovable movableObject = luaState.ToUserData(-6) as ISTGMovable;
        float       v             = (float)luaState.ToNumber(-5);
        float       angle         = (float)luaState.ToNumber(-4);
        bool        isAimToPlayer = luaState.ToBoolean(-3);
        float       acce          = (float)luaState.ToNumber(-2);
        float       accAngle;

        if (luaState.Type(-1) == LuaType.LUA_TBOOLEAN && luaState.ToBoolean(-1) == true)
        {
            accAngle = angle;
        }
        else
        {
            accAngle = (float)luaState.ToNumber(-1);
        }
        if (isAimToPlayer)
        {
            Vector2 playerPos = PlayerInterface.GetInstance().GetCharacter().GetPosition();
            float   relAngle  = MathUtil.GetAngleBetweenXAxis(playerPos - movableObject.GetPosition());
            angle    += relAngle;
            accAngle += relAngle;
        }
        movableObject.SetStraightParas(v, angle, acce, accAngle);
        return(0);
    }
Beispiel #2
0
    /// <summary>
    /// 强制删除一个单位
    /// <para>必定不触发事件</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int DelUnit(ILuaState luaState)
    {
        ISTGMovable go = luaState.ToUserData(-1) as ISTGMovable;

        go.Eliminate(eEliminateDef.ForcedDelete);
        return(0);
    }
Beispiel #3
0
    /// <summary>
    /// 物体做极坐标运动
    /// <para>movableObject 运动的物体</para>
    /// <para>float radius 起始半径</para>
    /// <para>float angle 起始角度</para>
    /// <para>float deltaR 半径增量</para>
    /// <para>float omega 角速度</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int STGMovableDoCurvedMove(ILuaState luaState)
    {
        int top = luaState.GetTop();

        if (top == 5)
        {
            ISTGMovable movableObject = luaState.ToUserData(-5) as ISTGMovable;
            float       radius        = (float)luaState.ToNumber(-4);
            float       angle         = (float)luaState.ToNumber(-3);
            float       deltaR        = (float)luaState.ToNumber(-2);
            float       omega         = (float)luaState.ToNumber(-1);
            movableObject.SetPolarParas(radius, angle, deltaR, omega);
        }
        else if (top == 7)
        {
            ISTGMovable movableObject = luaState.ToUserData(-7) as ISTGMovable;
            float       radius        = (float)luaState.ToNumber(-6);
            float       angle         = (float)luaState.ToNumber(-5);
            float       deltaR        = (float)luaState.ToNumber(-4);
            float       omega         = (float)luaState.ToNumber(-3);
            float       centerPosX    = (float)luaState.ToNumber(-2);
            float       centerPosY    = (float)luaState.ToNumber(-1);
            movableObject.SetPolarParas(radius, angle, deltaR, omega, centerPosX, centerPosY);
        }
        return(0);
    }
Beispiel #4
0
    /// <summary>
    /// 物体在duration的时间内移动到目标位置
    /// <para>movableObject 运动的物体</para>
    /// <para>float toX 目标点X坐标</para>
    /// <para>float toY 目标点Y坐标</para>
    /// <para>int duration 时间间隔</para>
    /// <para>mode 插值方式</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int STGMovableMoveTo(ILuaState luaState)
    {
        ISTGMovable       movableObject = luaState.ToUserData(-5) as ISTGMovable;
        float             toX           = (float)luaState.ToNumber(-4);
        float             toY           = (float)luaState.ToNumber(-3);
        int               duration      = luaState.ToInteger(-2);
        InterpolationMode mode          = (InterpolationMode)luaState.ToInteger(-1);

        movableObject.MoveTo(toX, toY, duration, mode);
        return(0);
    }
Beispiel #5
0
    /// <summary>
    /// 杀死单位
    /// <para>unit</para>
    /// <para>bool triggerEvent 是否触发事件</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int KillUnit(ILuaState luaState)
    {
        ISTGMovable go           = luaState.ToUserData(-2) as ISTGMovable;
        bool        triggerEvent = luaState.ToBoolean(-1);

        if (triggerEvent)
        {
            go.Eliminate(eEliminateDef.CodeEliminate);
        }
        else
        {
            go.Eliminate(eEliminateDef.CodeRawEliminate);
        }
        return(0);
    }
Beispiel #6
0
    /// <summary>
    /// 做加速运动
    /// <para>movableObject 运动的物体</para>
    /// <para>float acce 加速度</para>
    /// <para>float angle 速度方向 or bool useVAngle使用速度方向</para>
    /// <para>bool isAimToPlayer 是否朝向玩家</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int STGMovableDoAcceleration(ILuaState luaState)
    {
        ISTGMovable movableObject = luaState.ToUserData(-4) as ISTGMovable;
        float       acce          = (float)luaState.ToNumber(-3);
        float       angle         = luaState.Type(-2) == LuaType.LUA_TBOOLEAN ? movableObject.vAngle : (float)luaState.ToNumber(-2);
        bool        isAimToPlayer = luaState.ToBoolean(-1);

        if (isAimToPlayer)
        {
            Vector2 playerPos = PlayerInterface.GetInstance().GetCharacter().GetPosition();
            angle += MathUtil.GetAngleBetweenXAxis(playerPos - movableObject.GetPosition());
        }
        movableObject.DoAcceleration(acce, angle);
        return(0);
    }
Beispiel #7
0
    /// <summary>
    /// 做直线运动
    /// <para>movableObject 运动的物体</para>
    /// <para>float v 速度</para>
    /// <para>float angle 速度方向</para>
    /// <para>bool isAimToPlayer 是否朝向玩家</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int STGMovableDoStraightMove(ILuaState luaState)
    {
        ISTGMovable movableObject = luaState.ToUserData(-4) as ISTGMovable;
        float       v             = (float)luaState.ToNumber(-3);
        float       angle         = (float)luaState.ToNumber(-2);
        bool        isAimToPlayer = luaState.ToBoolean(-1);

        if (isAimToPlayer)
        {
            Vector2 playerPos = PlayerInterface.GetInstance().GetCharacter().GetPosition();
            angle += MathUtil.GetAngleBetweenXAxis(playerPos - movableObject.GetPosition());
        }
        movableObject.DoStraightMove(v, angle);
        return(0);
    }