Ejemplo n.º 1
0
 /// <summary>
 /// 执行关卡task
 /// </summary>
 private void OnStageTaskUpdate()
 {
     if (_curStageTask.isFinish != true)
     {
         if (!_curStageTask.isStarted)
         {
             // 设置fixedFPS
             if (_curStageInfo.fixedFps)
             {
                 Application.targetFrameRate = 90;
             }
             else
             {
                 Application.targetFrameRate = 60;
             }
             FPSController.GetInstance().Restart(_curStageInfo.fixedFps);
             // bgm开始播放
             //SoundManager.GetInstance().SetSoundPlayTime(_curStageInfo.bgm, 0);
             SoundManager.GetInstance().ResumeAllSTGSound();
             //SoundManager.GetInstance().PrintSoundTime("DarkRoad");
             InterpreterManager.GetInstance().AddPara(ExtraTaskManager.GetInstance(), LuaParaType.LightUserData);
             InterpreterManager.GetInstance().CallTaskCoroutine(_curStageTask, 1);
         }
         else
         {
             InterpreterManager.GetInstance().CallTaskCoroutine(_curStageTask);
         }
     }
 }
Ejemplo n.º 2
0
    public void Init()
    {
        // 游戏本体边界
        Global.GameLBBorderPos = new Vector2(-Consts.GameWidth / 2, -Consts.GameHeight / 2);
        Global.GameRTBorderPos = new Vector2(Consts.GameWidth / 2, Consts.GameHeight / 2);
        // 弹幕边界
        Global.BulletLBBorderPos = new Vector2(Global.GameLBBorderPos.x - 100, Global.GameLBBorderPos.y - 100);
        Global.BulletRTBorderPos = new Vector2(Global.GameRTBorderPos.x + 100, Global.GameRTBorderPos.y + 100);
        // 玩家坐标边界
        Global.PlayerLBBorderPos = new Vector2(Global.GameLBBorderPos.x + 10, Global.GameLBBorderPos.y + 10);
        Global.PlayerRTBorderPos = new Vector2(Global.GameRTBorderPos.x - 10, Global.GameRTBorderPos.y - 10);

        InterpreterManager.GetInstance().Init();
        STGStageManager.GetInstance().Init();
        AnimationManager.GetInstance().Init();
        BulletsManager.GetInstance().Init();
        EnemyManager.GetInstance().Init();
        ItemManager.GetInstance().Init();
        ColliderManager.GetInstance().Init();

        ExtraTaskManager.GetInstance().Init();

        EffectsManager.GetInstance().Init();
        STGEliminateEffectManager.GetInstance().Init();
        BackgroundManager.GetInstance().Init();
#if ShowCollisionViewer
        CollisionViewer.Instance.Init();
#endif
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 初始化STGMain
    /// </summary>
    private void OnStateInitSTGMainUpdate()
    {
        _stgMain = new STGMain();
        _stgMain.Init();
        // 加载各个stage.lua文件
        //List<string> stageLuaList = new List<string> { "stage1", "stage1sc" };
        List <string> stageLuaList = new List <string> {
            "TestEditorStage"
        };

#if DEBUG_GAMESTATE
        string fileListStr = "";
        for (int k = 0; k < stageLuaList.Count; k++)
        {
            fileListStr = k == 0 ? stageLuaList[k] + ".lua" : "\n" + stageLuaList[k] + ".lua";
        }
        Logger.Log(string.Format("Init STGMain,Start to load lua files\n{0}", fileListStr));
        TimeUtil.BeginSample("InitSTGMain");
#endif
        for (int i = 0; i < stageLuaList.Count; i++)
        {
            InterpreterManager.GetInstance().LoadLuaFile(stageLuaList[i]);
        }
#if DEBUG_GAMESTATE
        TimeUtil.EndSample("InitSTGMain");
        TimeUtil.LogSampleTick("InitSTGMain", "Load luafile(s) complete.Cost time {0}");
#endif
        _curState = eSTGMainState.StateInitSTGData;
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 创建自定义的敌机
    /// <para>customizedName 自定义的名称</para>
    /// <para>posX</para>
    /// <para>posY</para>
    /// <para>paras...</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedEnemy(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);
        // 创建敌机
        NormalEnemy enemy = EnemyManager.GetInstance().CreateEnemyByType(eEnemyType.NormalEnemy) as NormalEnemy;

        enemy.SetPosition(posX, posY);
        int onEliminateFuncRef = InterpreterManager.GetInstance().GetEnemyOnEliminateFuncRef(customizedName);

        if (onEliminateFuncRef != 0)
        {
            enemy.SetOnEliminateFuncRef(onEliminateFuncRef);
        }
        // init函数
        int initFuncRef = InterpreterManager.GetInstance().GetEnemyInitFuncRef(customizedName);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, initFuncRef);
        luaState.PushLightUserData(enemy);
        for (int i = 0; i < numArgs; i++)
        {
            luaState.PushValue(-2 - numArgs);
        }
        luaState.Call(numArgs + 1, 0);
        // 将返回值压入栈
        luaState.PushLightUserData(enemy);
        return(1);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// 加载关卡
    /// </summary>
    /// <param name="stageId"></param>
    public void LoadStage(string stageName)
    {
        StageInfo info;

        if (_stageInfos.TryGetValue(stageName, out info))
        {
            _curStageInfo         = info;
            _curStageTask         = InterpreterManager.GetInstance().CreateStageTask(info);
            _state                = StateUpdateStageTask;
            _frameSinceStageStart = 0;
            _isEnableToShoot      = true;
            _isInDialogMode       = false;
            // 预先加载BGM
            if (info.bgm == "")
            {
                info.bgm = "bgm";
            }
            SoundManager.GetInstance().PauseAllSTGSound();
            SoundManager.GetInstance().Play(info.bgm, 0.5f, false, true);
        }
        else
        {
            Logger.LogError("Stage info of " + stageName + " is not exist!");
        }
        CommandManager.GetInstance().RunCommand(CommandConsts.STGLoadStageLuaComplete);
    }
    /// <summary>
    /// 创建自定义的simpleBullet
    /// <para>customizedName 自定义的子弹名称</para>
    /// <para>float posX</para>
    /// <para>float posY</para>
    /// <para>args...</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedBullet(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);
        EnemySimpleBullet bullet         = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Simple) as EnemySimpleBullet;

        bullet.SetPosition(posX, posY);
        // 设置自定义的数据
        BCCustomizedTask bc = bullet.AddOrGetComponent <BCCustomizedTask>();
        int funcRef         = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef);
        if (!luaState.IsFunction(-1))
        {
            Logger.LogError("InitFuncRef of " + customizedName + " is not point to a function");
        }
        luaState.PushLightUserData(bullet);
        for (int i = 0; i < numArgs; i++)
        {
            luaState.PushValue(-2 - numArgs);
        }
        luaState.Call(numArgs + 1, 0);
        luaState.PushLightUserData(bullet);
        return(1);
    }
Ejemplo n.º 7
0
 public void Update()
 {
     if (!isFinish)
     {
         InterpreterManager.GetInstance().CallTaskCoroutine(this);
     }
 }
Ejemplo n.º 8
0
    /// <summary>
    /// 创建自定义的STGObject
    /// <para>string customizedName 自定义名称</para>
    /// <para>posX</para>
    /// <para>posY</para>
    /// <para>args...</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedSTGObject(ILuaState luaState)
    {
        int    top            = luaState.GetTop();
        int    numArgs        = top - 3;
        string customizedName = luaState.ToString(-top);
        float  posX           = (float)luaState.ToNumber(-top + 1);
        float  posY           = (float)luaState.ToNumber(-top + 2);
        int    funcRef        = InterpreterManager.GetInstance().GetCustomizedFuncRef(customizedName, eCustomizedType.STGObject, eCustomizedFuncRefType.Init);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef);
        STGSpriteEffect effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.SpriteEffect) as STGSpriteEffect;

        effect.SetPosition(posX, posY);
        luaState.PushLightUserData(effect);
        // 复制参数
        int copyIndex = -numArgs - 2;

        for (int i = 0; i < numArgs; i++)
        {
            luaState.PushValue(copyIndex);
        }
        luaState.Call(numArgs + 1, 0);
        // 返回结果
        luaState.PushLightUserData(effect);
        return(1);
    }
Ejemplo n.º 9
0
 public void Update()
 {
     // 符卡尚未开始
     if (!_isSCTaskStarted)
     {
         for (int i = 0; i < _bossCount; i++)
         {
             InterpreterManager.GetInstance().AddPara(_bossList[i], LuaParaType.LightUserData);
         }
         InterpreterManager.GetInstance().CallTaskCoroutine(_scTask, _bossCount);
         _isSCTaskStarted = true;
         Logger.Log("Call SpellCard Task");
     }
     // update
     else
     {
         _frameLeft--;
         object[] data = { _frameLeft };
         CommandManager.GetInstance().RunCommand(CommandConsts.UpdateSpellCardTime, data);
         if (_scTask != null && !_scTask.isFinish)
         {
             InterpreterManager.GetInstance().CallTaskCoroutine(_scTask);
             if (_scTask.isFinish)
             {
                 Logger.Log("SpellCard " + _scName + " task finish!");
                 ObjectsPool.GetInstance().RestorePoolClassToPool <Task>(_scTask);
                 _scTask = null;
             }
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 被消除的时候调用
 /// </summary>
 protected void OnEliminate(eEliminateDef eliminateType)
 {
     if (eliminateType != eEliminateDef.ForcedDelete && (eliminateType & RawEliminateTypes) != 0)
     {
         if (_onEliminateFuncRef != 0)
         {
             InterpreterManager.GetInstance().AddPara(this, LuaParaType.LightUserData);
             InterpreterManager.GetInstance().CallLuaFunction(_onEliminateFuncRef, 1);
         }
     }
     if (_attachableMaster != null)
     {
         IAttachable master = _attachableMaster;
         _attachableMaster = null;
         master.OnAttachmentEliminated(this);
     }
     if (_attachmentsCount != 0)
     {
         int count = _attachmentsCount;
         _attachmentsCount = 0;
         IAttachment attachment;
         for (int i = 0; i < count; i++)
         {
             attachment = _attachmentsList[i];
             if (attachment != null)
             {
                 attachment.OnMasterEliminated(eliminateType);
             }
         }
         _attachmentsList.Clear();
     }
 }
Ejemplo n.º 11
0
    public static int RemoveGlobalUserData(ILuaState luaState)
    {
        string key = luaState.ToString(-1);

        luaState.Pop(1);
        InterpreterManager.GetInstance().RemoveGlobalUserData(key);
        return(0);
    }
Ejemplo n.º 12
0
    public static int SetGlobalUserData(ILuaState luaState)
    {
        string key      = luaState.ToString(-2);
        object userData = luaState.ToUserData(-1);

        luaState.Pop(2);
        InterpreterManager.GetInstance().SetGlobalUserData(key, userData);
        return(0);
    }
Ejemplo n.º 13
0
    public static int SetGlobalFloat(ILuaState luaState)
    {
        string key    = luaState.ToString(-2);
        float  number = (float)luaState.ToNumber(-1);

        luaState.Pop(2);
        InterpreterManager.GetInstance().SetGlobalNumber(key, number);
        return(0);
    }
Ejemplo n.º 14
0
 /// <summary>
 /// 创建对话
 /// </summary>
 public void StartDialog(int funcRef)
 {
     _isInDialogMode     = true;
     _timeSinceLastSkip  = SkipDialogTimeInterval;
     _dialogTask         = ObjectsPool.GetInstance().GetPoolClassAtPool <Task>();
     _dialogTask.funcRef = funcRef;
     InterpreterManager.GetInstance().CallTaskCoroutine(_dialogTask);
     CommandManager.GetInstance().RunCommand(CommandConsts.StartDialog);
 }
Ejemplo n.º 15
0
    public static int GetGlobalFloat(ILuaState luaState)
    {
        string key = luaState.ToString(-1);

        luaState.Pop(1);
        float num = InterpreterManager.GetInstance().GetGlobalNumber(key);

        luaState.PushNumber(num);
        return(1);
    }
Ejemplo n.º 16
0
    public static int SetGlobalVector2(ILuaState luaState)
    {
        string key = luaState.ToString(-3);
        float  x   = (float)luaState.ToNumber(-2);
        float  y   = (float)luaState.ToNumber(-1);

        luaState.Pop(3);
        InterpreterManager.GetInstance().SetGlobalVector2(key, new Vector2(x, y));
        return(0);
    }
Ejemplo n.º 17
0
    public static int GetGlobalUserData(ILuaState luaState)
    {
        string key = luaState.ToString(-1);

        luaState.Pop(1);
        object userData = InterpreterManager.GetInstance().GetGlobalUserData(key);

        luaState.PushLightUserData(userData);
        return(1);
    }
Ejemplo n.º 18
0
    public static int GetGlobalVector2(ILuaState luaState)
    {
        string key = luaState.ToString(-1);

        luaState.Pop(1);
        Vector2 vec = InterpreterManager.GetInstance().GetGlobalVector2(key);

        luaState.PushNumber(vec.x);
        luaState.PushNumber(vec.y);
        return(2);
    }
Ejemplo n.º 19
0
    public static int AddEnemyTask(ILuaState luaState)
    {
        EnemyBase enemy   = luaState.ToUserData(-2) as EnemyBase;
        int       funcRef = InterpreterManager.GetInstance().RefLuaFunction(luaState);

        luaState.Pop(1);
        Task task = ObjectsPool.GetInstance().GetPoolClassAtPool <Task>();

        task.funcRef = funcRef;
        enemy.AddTask(task);
        return(0);
    }
Ejemplo n.º 20
0
 public void Clear()
 {
     CommandManager.GetInstance().Remove(CommandConsts.PlayerDying, this);
     CommandManager.GetInstance().Remove(CommandConsts.PlayerMiss, this);
     CommandManager.GetInstance().Remove(CommandConsts.PlayerCastSC, this);
     _bossList = null;
     if (_scTask != null && !_scTask.isFinish)
     {
         InterpreterManager.GetInstance().StopTaskThread(_scTask);
     }
     _scTask = null;
 }
Ejemplo n.º 21
0
    public void Init(string bossName)
    {
        _bossName = bossName;
        int initFuncRef = InterpreterManager.GetInstance().GetEnemyInitFuncRef(_bossName);

        InterpreterManager.GetInstance().AddPara(this, LuaParaType.LightUserData);
        InterpreterManager.GetInstance().CallLuaFunction(initFuncRef, 1);
        _checkOutOfBorder = false;
        _isShowPosHint    = false;
        // 重置抵抗消除标识
        _resistEliminateFlag = (int)eEliminateDef.SpellCardFinish;
        Logger.Log("Call InitFunc of Boss " + _bossName + " Complete!");
    }
Ejemplo n.º 22
0
 public override void Clear()
 {
     _bullet = null;
     for (int i = 0; i < _triggerDataCount; i++)
     {
         int funcRef = _triggerDatas[i].triggerFuncRef;
         if (funcRef != 0)
         {
             InterpreterManager.GetInstance().UnrefLuaFunction(funcRef);
         }
     }
     _triggerDatas.Clear();
     _triggerDataCount = 0;
 }
Ejemplo n.º 23
0
    /// <summary>
    /// 初始化STG的数据、玩家对象、控制器等
    /// </summary>
    public void InitSTG(int characterIndex)
    {
        _char         = PlayerInterface.GetInstance().CreateCharacter(characterIndex);
        _opController = OperationController.GetInstance();
        _opController.InitCharacter();
        InterpreterManager.GetInstance().SetGlobalField("player", _char, LuaParaType.LightUserData);

        // 设置初始残机数和符卡数目
        PlayerInterface.GetInstance().SetLifeCounter(Consts.STGInitLifeCount, 0);
        PlayerInterface.GetInstance().SetSpellCardCounter(Consts.STGInitSpellCardCount, 0);

        CommandManager.GetInstance().RunCommand(CommandConsts.STGInitComplete);
        frameNode = 0;
    }
Ejemplo n.º 24
0
 public void Clear()
 {
     _curSpellCard.Clear();
     _isCastingSpellCard    = false;
     _isWaitingForSpellCard = false;
     if (_isInDialogMode)
     {
         InterpreterManager.GetInstance().StopTaskThread(_dialogTask);
         ObjectsPool.GetInstance().RestorePoolClassToPool <Task>(_dialogTask);
         _dialogTask     = null;
         _isInDialogMode = false;
     }
     InterpreterManager.GetInstance().StopTaskThread(_curStageTask);
     Application.targetFrameRate = 60;
 }
Ejemplo n.º 25
0
    public static int AddBulletTask(ILuaState luaState)
    {
        EnemyBulletBase bullet  = luaState.ToUserData(-2) as EnemyBulletBase;
        int             funcRef = InterpreterManager.GetInstance().RefLuaFunction(luaState);

        luaState.Pop(1);
        Task task = ObjectsPool.GetInstance().GetPoolClassAtPool <Task>();

        task.funcRef  = funcRef;
        task.isFinish = false;
        task.luaState = null;
        BCCustomizedTask bc = bullet.GetComponent <BCCustomizedTask>();

        bc.AddTask(task);
        return(0);
    }
Ejemplo n.º 26
0
    public void OnFinish()
    {
        // 移除符卡事件监听
        CommandManager.GetInstance().Remove(CommandConsts.PlayerDying, this);
        CommandManager.GetInstance().Remove(CommandConsts.PlayerMiss, this);
        CommandManager.GetInstance().Remove(CommandConsts.PlayerCastSC, this);

        // 通过符卡经过的时间
        int framePassed = _frameTotal - _frameLeft;
        int timePassed  = framePassed * 1000 / Consts.TargetFrameRate;
        // 是否获得符卡奖励
        bool getBonus = true;

        if (!_isFinishSpellCard)
        {
            getBonus = false;
        }
        else if (_dyingCount != 0 || _castSCCount != 0)
        {
            getBonus = false;
        }
        // 计算通过符卡实际经过的时间
        long scFinishTimeTick = TimeUtil.GetTimestamp();
        int  realTimePassed   = (int)((scFinishTimeTick - _scStartTimeTick) / 10000);

        object[] datas = { _isSpellCard, _isFinishSpellCard, getBonus, timePassed, realTimePassed };
        CommandManager.GetInstance().RunCommand(CommandConsts.SpellCardFinish, datas);

        if (_finishFuncRef != 0)
        {
            InterpreterManager.GetInstance().AddPara(_bossList[0], LuaParaType.LightUserData);
            InterpreterManager.GetInstance().AddPara(_isFinishSpellCard, LuaParaType.Bool);
            InterpreterManager.GetInstance().AddPara(getBonus, LuaParaType.Bool);
            InterpreterManager.GetInstance().CallLuaFunction(_finishFuncRef, 3);
        }
        // 清除BossTask
        for (int i = 0; i < _bossCount; i++)
        {
            _bossList[i].OnSpellCardFinish();
        }
        ColliderManager.GetInstance().ClearAllObjectCollider(new List <eEliminateDef> {
            eEliminateDef.PlayerSpellCard
        });
        CreateEliminateEnemyCollider(_bossList[0].GetPosition());
    }
Ejemplo n.º 27
0
    /// <summary>
    /// 创建自定义的敌机
    /// <para>customizedName 自定义的名称</para>
    /// <para>enemyId 配置的id</para>
    /// <para>posX</para>
    /// <para>posY</para>
    /// <para>paras...</para>
    /// <para>numArgs 参数个数</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedEnemy2(ILuaState luaState)
    {
        int numArgs = luaState.ToInteger(-1);

        luaState.Pop(1);
        string customizedName = luaState.ToString(-4 - numArgs);
        string enemyId;

        if (luaState.Type(-3 - numArgs) == LuaType.LUA_TNUMBER)
        {
            enemyId = luaState.ToNumber(-3 - numArgs).ToString();
        }
        else
        {
            enemyId = luaState.ToString(-3 - numArgs);
        }
        float posX = (float)luaState.ToNumber(-2 - numArgs);
        float posY = (float)luaState.ToNumber(-1 - numArgs);
        // 创建敌机
        EnemyCfg    cfg   = EnemyManager.GetInstance().GetEnemyCfgById(enemyId);
        NormalEnemy enemy = EnemyManager.GetInstance().CreateEnemyByType(eEnemyType.NormalEnemy) as NormalEnemy;

        enemy.Init(cfg);
        enemy.SetPosition(posX, posY);
        int onEliminateFuncRef = InterpreterManager.GetInstance().GetEnemyOnEliminateFuncRef(customizedName);

        if (onEliminateFuncRef != 0)
        {
            enemy.SetOnEliminateFuncRef(onEliminateFuncRef);
        }
        // init函数
        int initFuncRef = InterpreterManager.GetInstance().GetEnemyInitFuncRef(customizedName);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, initFuncRef);
        luaState.PushLightUserData(enemy);
        luaState.Replace(-3 - numArgs);
        luaState.Replace(-3 - numArgs);
        luaState.Call(numArgs + 1, 0);
        // 弹出剩余两个参数
        luaState.Pop(2);
        // 将返回值压入栈
        luaState.PushLightUserData(enemy);
        return(1);
    }
Ejemplo n.º 28
0
    public override void Clear()
    {
        Task task;

        for (int i = 0; i < _taskCount; i++)
        {
            task = _taskList[i];
            if (task != null)
            {
                if (task.luaState != null)
                {
                    InterpreterManager.GetInstance().StopTaskThread(task.luaState, task.funcRef);
                }
                ObjectsPool.GetInstance().RestorePoolClassToPool <Task>(task);
            }
        }
        _taskList.Clear();
        _taskCount = 0;
    }
Ejemplo n.º 29
0
    protected virtual void ClearTasks()
    {
        Task task;

        for (int i = 0; i < _taskCount; i++)
        {
            task = _tasks[i];
            if (task != null)
            {
                if (!task.isFinish)
                {
                    InterpreterManager.GetInstance().StopTaskThread(task);
                }
                ObjectsPool.GetInstance().RestorePoolClassToPool <Task>(task);
            }
        }
        _tasks.Clear();
        _taskCount = 0;
    }
Ejemplo n.º 30
0
    public void Clear()
    {
        PlayerInterface.GetInstance().Clear();
        _char = null;
        OperationController.GetInstance().Clear();
        ColliderManager.GetInstance().Clear();
        BulletsManager.GetInstance().Clear();
        EnemyManager.GetInstance().Clear();
        ItemManager.GetInstance().Clear();
        EffectsManager.GetInstance().Clear();
        ExtraTaskManager.GetInstance().Clear();
        BackgroundManager.GetInstance().Clear();
        STGStageManager.GetInstance().Clear();
        InterpreterManager.GetInstance().Clear();
        SoundManager.GetInstance().Clear(true);
#if ShowCollisionViewer
        CollisionViewer.Instance.Clear();
#endif
        STGEliminateEffectManager.GetInstance().Clear();
    }