/// <summary> /// 开启剧情模式 /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int StartDialog(ILuaState luaState) { int funcRef = luaState.L_Ref(LuaDef.LUA_REGISTRYINDEX); STGStageManager.GetInstance().StartDialog(funcRef); return(luaState.Yield(0)); }
/// <summary> /// 更新STG主线程 /// </summary> private void OnSTGMainUpdate() { // 录像状态中,检测是否进行到了录像的最后一帧 if (Global.IsInReplayMode) { if (_isReplayFinish) { return; } int curFrame = STGStageManager.GetInstance().GetFrameSinceStageStart(); if (curFrame >= ReplayManager.GetInstance().GetReplayLastFrame()) { _isReplayFinish = true; PauseGame(ePauseViewState.PauseAfterReplayFinished); return; } // 检测是否在游戏进行中按下Esc进行暂停 if (!Global.IsPause && Input.GetKeyDown(KeyCode.Escape)) { PauseGame(ePauseViewState.PauseInReplay); } else if (!Global.IsPause && !Global.IsApplicationFocus) { PauseGame(ePauseViewState.PauseInReplay); } } else { if (_isGameOver) { if (!Global.IsPause) { _gameOverTimeCounter++; if (_gameOverTimeCounter >= 30) { PauseGame(ePauseViewState.PauseAfterGameOver); return; } } } // 检测是否在游戏进行中按下Esc进行暂停 if (!Global.IsPause && Input.GetKeyDown(KeyCode.Escape)) { PauseGame(ePauseViewState.PauseInGame); } else if (!Global.IsPause && !Global.IsApplicationFocus) { PauseGame(ePauseViewState.PauseInGame); } } if (_resumeSTGSE) { _resumeSTGSE = false; SoundManager.GetInstance().ResumeAllSTGSound(); } if (!Global.IsPause) { _stgMain.Update(); } }
public void SaveReplay(int index, string name, STGData data) { if (Global.IsInReplayMode) { return; } ReplayInfo info = new ReplayInfo { replayIndex = index, name = name, dateTick = System.DateTime.Now.Ticks, lastFrame = STGStageManager.GetInstance().GetFrameSinceStageStart(), stageName = data.stageName, characterIndex = data.characterIndex, }; ReplayData repData = new ReplayData(); repData.info = info; repData.keyList = OperationController.GetInstance().GetOperationKeyList(); repData.lastFrame = STGStageManager.GetInstance().GetFrameSinceStageStart(); repData.seed = data.seed; // 写入info文件 WriteRepInfoFile(info); WriteRepDataFile(repData); }
/// <summary> /// 角色立绘淡出 /// <para>string name 索引名称</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int FadeOutDialogCG(ILuaState luaState) { string name = luaState.ToString(-1); STGStageManager.GetInstance().DelDialogCG(name); return(0); }
/// <summary> /// 加载Stage.lua /// </summary> private void OnStateLoadStageLuaUpdate() { if (Global.IsInReplayMode) { _isReplayFinish = false; _curStageName = _stgData.stageName; } else { if (Global.DebugStageName != "") { _curStageName = Global.DebugStageName; } else { _curStageName = _nextStageName; } } _stgData.stageName = _curStageName; #if DEBUG_GAMESTATE Logger.Log(string.Format("Create task of stage \"{0}\"", _stgData.stageName)); #endif _curState = eSTGMainState.StateWait; CommandManager.GetInstance().Register(CommandConsts.STGLoadStageLuaComplete, this); STGStageManager.GetInstance().LoadStage(_stgData.stageName); //_stgMain.EnterStage(_curStageName); }
/// <summary> /// 关卡主线程挂起等待符卡结束 /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int WaitForSpellCardFinish(ILuaState luaState) { STGStageManager.GetInstance().SetStageTaskWaitingForSpellCardFinish(true); luaState.PushInteger(1); luaState.Yield(1); return(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 }
public static int LogFrameSinceStageStart(ILuaState luaState) { int frame = STGStageManager.GetInstance().GetFrameSinceStageStart(); Logger.Log("Frame Since Stage Start = " + frame); return(0); }
/// <summary> /// 设置关卡当前是否允许射击 /// <para>isEnable</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int SetStageIsEnableToShoot(ILuaState luaState) { bool isEnable = luaState.ToBoolean(-1); luaState.Pop(1); STGStageManager.GetInstance().SetIsEnableToShoot(isEnable); return(0); }
public static int GetSpellCardTimeLeftRate(ILuaState luaState) { SpellCard sc = STGStageManager.GetInstance().GetSpellCard(); float rate = sc.GetTimeRate(); luaState.PushNumber(rate); return(1); }
/// <summary> /// 高亮角色立绘CG /// <para>string name 索引名称</para> /// <para>bool highlight 高亮/取消高亮</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int HighlightDialogCG(ILuaState luaState) { string name = luaState.ToString(-2); bool highlight = luaState.ToBoolean(-1); STGStageManager.GetInstance().HighlightDialogCG(name, highlight); return(0); }
public void Update() { int curFrame = STGStageManager.GetInstance().GetFrameSinceStageStart(); if (_currentBg != null) { _currentBg.Update(curFrame); } }
//"Current Frame : {0}\n" + //"Current Frame : {0}\n" + //"Current Frame : {0}\n" + //"Current Frame : {0}\n" + //"Current Frame : {0}\n"; private void UpdateDebugInfo() { string info = String.Format(DebugInfo, STGStageManager.GetInstance().GetFrameSinceStageStart(), BulletsManager.GetInstance().GetEnemyBulletsCount() ); _debugInfoText.text = info; }
/// <summary> /// 创建剧情人物CG /// <para>string name 索引名称</para> /// <para>string spName 立绘文件名称</para> /// <para>float posX</para> /// <para>float posY</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int CreateDialogCG(ILuaState luaState) { string name = luaState.ToString(-4); string spName = luaState.ToString(-3); float posX = (float)luaState.ToNumber(-2); float posY = (float)luaState.ToNumber(-1); STGStageManager.GetInstance().CreateDialogCG(name, spName, posX, posY); return(0); }
/// <summary> /// 设置符卡的基本属性 /// <para>name 符卡名称</para> /// <para>duration 单位:秒,符卡持续时间</para> /// <para>conditon 符卡的条件</para> /// <para> finishFunc 可以为nil,符卡结束时候的函数</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int SetSpellCardProperties(ILuaState luaState) { SpellCard sc = STGStageManager.GetInstance().GetSpellCard(); string scName = luaState.ToString(-luaState.GetTop()); float duration = (float)luaState.ToNumber(-3); int condition = luaState.ToInteger(-2); bool isSpellCard = luaState.ToBoolean(-1); sc.SetProperties(scName, duration, (eSpellCardCondition)condition, isSpellCard); return(0); }
public bool CanShoot() { if (!STGStageManager.GetInstance().GetIsEnableToShoot()) { return(false); } if (!_isShootAvailable) { return(false); } return(true); }
/// <summary> /// 创建剧情对话框 /// <para>int style 对话框类型</para> /// <para>string text 对话框文本</para> /// <para>float posX</para> /// <para>float posY</para> /// <para>int duration 对话框持续时间</para> /// <para>float scale 对话框高度缩放</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int CreateDialogBox(ILuaState luaState) { int style = luaState.ToInteger(-6); string text = luaState.ToString(-5); float posX = (float)luaState.ToNumber(-4); float posY = (float)luaState.ToNumber(-3); int duration = luaState.ToInteger(-2); float scale = (float)luaState.ToNumber(-1); STGStageManager.GetInstance().CreateDialogBox(style, text, posX, posY, duration, scale); return(0); }
private void GetInput() { _curInput = eSTGKey.None;; if (Global.IsInReplayMode) { int curFrame = STGStageManager.GetInstance().GetFrameSinceStageStart(); _curInput = _keyList[curFrame]; } else { if (Input.GetKey(_pLeft)) { _curInput |= eSTGKey.KeyLeft; } if (Input.GetKey(_pRight)) { _curInput |= eSTGKey.KeyRight; } if (Input.GetKey(_pUp)) { _curInput |= eSTGKey.KeyUp; } if (Input.GetKey(_pDown)) { _curInput |= eSTGKey.KeyDown; } if (Input.GetKey(_pShift)) { _curInput |= eSTGKey.KeyShift; } if (Input.GetKey(_pZ)) { _curInput |= eSTGKey.KeyZ; } if (Input.GetKey(_pX)) { _curInput |= eSTGKey.KeyX; } if (Input.GetKey(_pC)) { _curInput |= eSTGKey.KeyC; } if (Input.GetKey(_pCtrl)) { _curInput |= eSTGKey.KeyCtrl; } // 添加到keyList中 _keyList.Add(_curInput); } }
private void RefStageTable() { _luaState.GetField(-1, "Stage"); string stageName; if (!_luaState.IsTable(-1)) { Logger.Log("Return value Stage is not a table!"); _luaState.Pop(1); return; } _luaState.PushNil(); while (_luaState.Next(-2)) { stageName = _luaState.ToString(-2); if (!_luaState.IsTable(-1)) { Logger.LogError("Stage " + stageName + " in StageTable is invalid"); continue; } // 读取关卡信息 StageInfo info = new StageInfo(); info.stageName = stageName; _luaState.GetField(-1, "bg"); info.bg = _luaState.ToString(-1); _luaState.GetField(-2, "bgm"); info.bgm = _luaState.ToString(-1); _luaState.GetField(-3, "fixedFPS"); info.fixedFps = _luaState.ToBoolean(-1); _luaState.Pop(3); // 读取关卡task _luaState.GetField(-1, "task"); if (!_luaState.IsFunction(-1)) { Logger.Log("Stage task of " + stageName + " in StageTable is invalid"); } info.taskFuncRef = _luaState.L_Ref(LuaDef.LUA_REGISTRYINDEX); // 添加到stageTask中 STGStageManager.GetInstance().AddStageInfo(info); // 弹出table--Stage[stageName] _luaState.Pop(1); #if LogLuaFuncRef _luaRefDic.Add(initRef, initRef); Logger.Log("Stage " + stageName + " is ref.Task funcRef = " + stageTaskFuncRef); #endif } //弹出StageTable _luaState.Pop(1); }
/// <summary> /// 获取boss当前符卡的hp比例 /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int GetBossSpellCardHpRate(ILuaState luaState) { int index = luaState.ToInteger(-1); luaState.Pop(1); SpellCard sc = STGStageManager.GetInstance().GetSpellCard(); Boss boss = sc.GetBossByIndex(index); float rate = 0f; if (boss != null) { rate = (float)boss.GetCurHp() / boss.GetMaxHp(); } luaState.PushNumber(rate); return(1); }
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(); }
/// <summary> /// 符卡开始 /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int StartSpellCard(ILuaState luaState) { int bossCount = 0; List <Boss> bossList = new List <Boss>(); Boss boss; // 获取符卡对应的table int index = -1; while (!luaState.IsTable(index)) { boss = luaState.ToUserData(-1) as Boss; bossList.Add(boss); bossCount++; index--; } // 获取Init函数 luaState.GetField(index, "Init"); if (!luaState.IsFunction(-1)) { Logger.Log("field \"Init\" of spell card is not a function!"); luaState.Pop(1); return(0); } int initFuncRef = InterpreterManager.GetInstance().RefLuaFunction(luaState); // 获取OnFinish函数 luaState.GetField(index, "OnFinish"); int finishFuncRef = 0; if (!luaState.IsFunction(-1)) { luaState.Pop(1); } else { finishFuncRef = InterpreterManager.GetInstance().RefLuaFunction(luaState); } STGStageManager.GetInstance().StartSpellCard(initFuncRef, finishFuncRef, bossList); return(0); }
private void RenderLaser() { //Logger.Log("Laser len = " + _curLaserLen); if (_preLaserLen != _curLaserLen) { _laserSr.material.SetFloat("_CurLaserLen", _curLaserLen); _preLaserLen = _curLaserLen; } int curFrame = STGStageManager.GetInstance().GetFrameSinceStageStart(); _laserSr.material.SetFloat("_TimeSinceCreated", curFrame); if (_hitObject) { _trans.localScale = new Vector3(1, 0.75f, 1); _laserSr.color = new Color(0.25f, 0.08f, 1f, 1f); } else { _trans.localScale = new Vector3(1, 1, 1); _laserSr.color = new Color(1, 1, 1, 1); } }
private void CollidedByObject(IAffectedMovableObject affectedObject) { int curTime = STGStageManager.GetInstance().GetFrameSinceStageStart(); GravitationParas paras; if (_affectedObjectDic.TryGetValue(affectedObject, out paras)) { if (curTime - paras.lastUpdateTime == 1) { // 每帧重新计算向心力、离心力的角度 if (_fieldType == GravitationType.Centripetal) { paras.vAngle = MathUtil.GetAngleBetweenXAxis(_curPos - affectedObject.GetPosition()); paras.accAngle = paras.vAngle; } else if (_fieldType == GravitationType.Centrifugal) { paras.vAngle = MathUtil.GetAngleBetweenXAxis(affectedObject.GetPosition() - _curPos); paras.accAngle = paras.vAngle; } paras.timeInGravitationField++; } else { paras = CreateGravitationParas(affectedObject); paras.timeInGravitationField = 1; } } else { paras = CreateGravitationParas(affectedObject); paras.timeInGravitationField = 1; } paras.lastUpdateTime = curTime; _affectedObjectDic[affectedObject] = paras; // 设置额外运动参数 affectedObject.AddExtraSpeedParas(paras.velocity, paras.vAngle, paras.acce * paras.timeInGravitationField, paras.accAngle); }
public void Update() { CommandManager.GetInstance().RunCommand(CommandConsts.STGFrameStart); #if CheckSTGFrameTime int index = 0; long[] timeArr = new long[20]; long frameBeginTime = Stopwatch.GetTimestamp(); _opController.Update(); STGStageManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); ColliderManager.GetInstance().UpdateFields(); timeArr[index++] = Stopwatch.GetTimestamp(); ExtraTaskManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); _char.Update(); timeArr[index++] = Stopwatch.GetTimestamp(); EnemyManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); BulletsManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); ItemManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); ColliderManager.GetInstance().UpdateColliders(); timeArr[index++] = Stopwatch.GetTimestamp(); EffectsManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); BulletsManager.GetInstance().Render(); timeArr[index++] = Stopwatch.GetTimestamp(); AnimationManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); BackgroundManager.GetInstance().Update(); timeArr[index++] = Stopwatch.GetTimestamp(); frameNode++; long frameEndTime = Stopwatch.GetTimestamp(); if (frameEndTime - frameBeginTime >= 50000) { string logStr = "Frame " + STGStageManager.GetInstance().GetFrameSinceStageStart() + " cost time " + (frameEndTime - frameBeginTime) * 0.0001d + "ms\n"; index = 0; logStr += "STGStageManager Update Cost Time = " + (timeArr[index] - frameBeginTime) * 0.0001d + "ms\n"; logStr += "GravitationFields Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "ExtraTaskManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "Character Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "EnemyManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "BulletsManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "ItemManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "Colliders Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "EffectsManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "BulletsManager Render Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "AnimationManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; logStr += "BackgroundManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n"; Logger.LogWarn(logStr); CommandManager.GetInstance().RunCommand(CommandConsts.LogFrameStatistics); Logger.Log("------------------------------------------------"); } #else //if (frameNode == 200) //{ // _lastFrameTicks = System.DateTime.Now.Ticks; //} //else if (frameNode > 200 && frameNode <= 300) //{ // long currentTicks = System.DateTime.Now.Ticks; // Logger.Log("Frame Interval = " + (currentTicks - _lastFrameTicks) * 0.0001f); // _lastFrameTicks = currentTicks; //} // 每帧开始 BulletsManager.GetInstance().OnSTGFrameStart(); // 逻辑部分 _opController.Update(); STGStageManager.GetInstance().Update(); ExtraTaskManager.GetInstance().Update(); ColliderManager.GetInstance().UpdateFields(); _char.Update(); EnemyManager.GetInstance().Update(); BulletsManager.GetInstance().Update(); ItemManager.GetInstance().Update(); ColliderManager.GetInstance().UpdateColliders(); EffectsManager.GetInstance().Update(); // 渲染部分 BulletsManager.GetInstance().Render(); EnemyManager.GetInstance().Render(); STGEliminateEffectManager.GetInstance().Render(); ItemManager.GetInstance().Render(); AnimationManager.GetInstance().Update(); BackgroundManager.GetInstance().Update(); #if ShowCollisionViewer CollisionViewer.Instance.Render(); #endif //if (frameNode == 0) // FPSController.GetInstance().Restart(true); frameNode++; //if (frameNode % 60 == 0) //{ // STGBulletEliminateEffect1 effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.BulletEliminate) as STGBulletEliminateEffect1; // effect.SetColor(1, 0, 0, 1); //} #endif //if ( frameNode == 200 ) //{ // List<object> datas = new List<object>(); // float centerX = -130; // float centerY = 180; // float radius = 70; // float distortFactor = 0.1f; // Color effectColor = new Color(0.62f, 0.22f, 0.61f, 1f); // datas.Add(centerX); // datas.Add(centerY); // datas.Add(radius); // datas.Add(distortFactor); // datas.Add(effectColor); // CommandManager.GetInstance().RunCommand(CommandConsts.UpdateBgDistortEffectProps, datas.ToArray()); //} //if ( frameNode == 200 ) //{ // STGBurstEffect effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.BurstEffect) as STGBurstEffect; // effect.SetSize(128); // effect.SetToPos(0, 150); //} //if (frameNode == 200) //{ // TimeUtil.BeginSample(); // STGChargeEffect effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.ChargeEffect) as STGChargeEffect; // effect.SetToPos(0, 100); // TimeUtil.EndSample(); //} //if (frameNode >= 200 && frameNode % 2 == 0 ) //{ // STGBulletEliminateEffect effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.BulletEliminate) as STGBulletEliminateEffect; // effect.SetToPos(Random.Range(-8, 8), Random.Range(-8, 8)); // effect.SetColor(Random.value, Random.value, Random.value, 1); //} }