/// <summary> /// 做加速运动(限制最大速度) /// <para>bullet 敌机子弹</para> /// <para>float acce 加速度</para> /// <para>float angle 速度方向 or bool useVAngle使用速度方向</para> /// <para>bool isAimToPlayer 是否朝向玩家</para> /// <para>float maxVelocity 最大速度限制</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int EnemyBulletDoAccelerationWithLimitation(ILuaState luaState) { EnemyBulletBase bullet = luaState.ToUserData(-5) as EnemyBulletBase; float acce = (float)luaState.ToNumber(-4); float angle; if (luaState.Type(-3) == LuaType.LUA_TBOOLEAN) { bullet.GetBulletPara(BulletParaType.VAngel, out angle); } else { angle = (float)luaState.ToNumber(-3); } bool isAimToPlayer = luaState.ToBoolean(-2); float maxVelocity = (float)luaState.ToNumber(-1); luaState.Pop(5); if (isAimToPlayer) { Vector2 playerPos = PlayerInterface.GetInstance().GetCharacter().GetPosition(); angle += MathUtil.GetAngleBetweenXAxis(playerPos - bullet.GetPosition()); } bullet.DoAccelerationWithLimitation(acce, angle, maxVelocity); return(0); }