void Update() { if (Input.GetKeyDown(KeyCode.P)) { Debug.Break(); } this.state_timer_prev = this.state_timer; this.state_timer += Time.deltaTime; // 根据当前状态和条件,判断是否迁移到下一个状态 switch (this.state) { case STATE.START: { // 片头阶段,过了 START_TIME 之后进入游戏阶段 if (this.state_timer > SceneControl.START_TIME) { this.gui_control.setVisibleStart(false); this.next_state = STATE.GAME; } } break; case STATE.GAME: { // 游戏进行到生成的怪物超过数量之后,停止生成,准备结束游戏 if (this.oni_group_complite >= this.oni_group_appear_max) { next_state = STATE.ONI_VANISH_WAIT; } // 在结束之前的最后一段,隐藏分数,在人物停止的时候再显示出来递增到最后 if (this.oni_group_complite >= this.oni_group_appear_max - 10 && this.backup_oni_defeat_num == -1) { this.backup_oni_defeat_num = this.result.oni_defeat_num; } } break; case STATE.ONI_VANISH_WAIT: { // 等所有怪物都消失,且速度超过一半时(才)进入 LAST_RUN do { if (GameObject.FindGameObjectsWithTag("OniGroup").Length > 0) { break; } if (this.player.GetSpeedRate() < 0.5f) { break; } next_state = STATE.LAST_RUN; } while (false); } break; case STATE.LAST_RUN: { // LAST_RUN 阶段持续 2.0 秒后进入刹车阶段 if (this.state_timer > 2.0f) { next_state = STATE.PLAYER_STOP_WAIT; } } break; case STATE.PLAYER_STOP_WAIT: { // 刹车持续到角色停止后,进入 GOAL 阶段 if (this.player.IsStopped()) { next_state = STATE.GOAL; } } break; case STATE.GOAL: { // 掉落的怪物全部生成后,进入 RANK 展示前的过渡态 ONI_FALL_WAIT if (this.oni_emitter.oni_num == 0) { this.next_state = STATE.ONI_FALL_WAIT; } } break; case STATE.ONI_FALL_WAIT: { // 分数不再变化,且超过 1.5 秒后,进入 RANK 展示阶段 if (!this.score_control.isActive() && this.state_timer > 1.5f) { this.next_state = STATE.RESULT_DEFEAT; } } break; case STATE.RESULT_DEFEAT: { // 播放"咚咚"音效 (感觉与下面其他播放音效的代码一起,都可以放最后的 switch 处理,这个 switch 里面只关心和判断是否变化状态,放这里可以少写case的判断) // 这个判断方法使得只会在本状态时间超过 0.4 秒的【那一帧】播放一次,防止了多次播放 if (this.state_timer >= 0.4f && this.state_timer_prev < 0.4f) { // TODO 播放音效 } // 超过 0.5 秒后展示下一个 if (this.state_timer > 0.5f) { this.next_state = STATE.RESULT_EVALUATION; } } break; case STATE.RESULT_EVALUATION: { if (this.state_timer >= 0.4f && this.state_timer_prev < 0.4f) { // TODO 播放音效 } // 超过 2.0 秒后展示总得分 if (this.state_timer > 2.0f) { this.next_state = STATE.RESULT_TOTAL; } } break; case STATE.RESULT_TOTAL: { if (this.state_timer >= 0.4f && this.state_timer_prev < 0.4f) { // TODO 播放音效 } // 超过 2.0 秒后进入结束画面 if (this.state_timer > 2.0f) { this.next_state = STATE.GAME_OVER; } } break; case STATE.GAME_OVER: { if (Input.GetMouseButtonDown(0)) { this.fader.fade(1.0f, new Color(0.0f, 0.0f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 1.0f)); this.next_state = STATE.GOTO_TITLE; } } break; case STATE.GOTO_TITLE: { if (!this.fader.isActive()) { UnityEngine.SceneManagement.SceneManager.LoadScene("TitleScene"); } } break; } // 状态变化时,下一个状态开始前的初始化处理,然后改变状态 // 只会触发一次的逻辑放在这里,不能放在下面的 switch 里 if (this.next_state != STATE.NONE) { switch (this.next_state) { case STATE.START: { // 显示 "开始" 文字 this.gui_control.setVisibleStart(true); } break; case STATE.PLAYER_STOP_WAIT: { // 使 player 开始减速 this.player.StopRequest(); // 根据结果的 rank 生成怪物山,放在前方,自然进入画面 //if(this.result_control.getTotalRank() > 0) //{ GameObject oni_yama = Instantiate(this.OniYamaPrefab[2]) as GameObject; Vector3 oni_yama_position = this.player.transform.position; oni_yama_position.x += this.player.CalcDistanceToStop(); oni_yama_position.x += SceneControl.GOAL_STOP_DISTANCE; oni_yama_position.y = 0.5f; oni_yama.transform.position = oni_yama_position; //} } break; case STATE.GOAL: { // 隐藏掉的分数重新显示并且开始递增 this.gui_control.score_control.setNumForce(this.backup_oni_defeat_num); this.gui_control.score_control.setNum(this.result.oni_defeat_num); // 生成使“怪物从上方掉下来”的发射器 GameObject go = Instantiate(this.OniEmitterPrefab) as GameObject; this.oni_emitter = go.GetComponent <OniEmitterControl>(); Vector3 emitter_position = oni_emitter.transform.position; emitter_position.x = this.player.transform.position.x; emitter_position.x += this.player.CalcDistanceToStop(); emitter_position.x += SceneControl.GOAL_STOP_DISTANCE; emitter_position.y = 10; this.oni_emitter.transform.position = emitter_position; // 根据 rank 确定掉落数量 int oni_num = 0; switch (this.result_control.getTotalRank()) { case 0: oni_num = Mathf.Min(this.result.oni_defeat_num, 10); break; case 1: oni_num = 6; break; case 2: oni_num = 10; break; case 3: oni_num = 20; break; } oni_num = 10; // 测试用 this.oni_emitter.oni_num = oni_num; } break; // 显示最终 Rank 的三个状态,因为只要触发一次,所以放在这里 case STATE.RESULT_DEFEAT: { this.gui_control.startDispDefeatRank(); } break; case STATE.RESULT_EVALUATION: { this.gui_control.startDispEvaluationRank(); } break; case STATE.RESULT_TOTAL: { this.gui_control.hideDefeatRank(); this.gui_control.hideEvaluationRank(); this.gui_control.startDispTotalRank(); } break; case STATE.GAME_OVER: { this.gui_control.setVisibleReturn(true); } break; } this.state = this.next_state; this.next_state = STATE.NONE; this.state_timer = 0.0f; this.state_timer_prev = -1.0f; } // 各个状态的逻辑 switch (this.state) { case STATE.GAME: { this.level_control.oniAppearControl(); } break; } }
void Update() { if (Input.GetKeyDown(KeyCode.P)) { Debug.Break(); } // 管理游戏的当前状态 this.step_timer_prev = this.step_timer; this.step_timer += Time.deltaTime; // 检测是否迁移到下一个状态 switch (this.step) { case STEP.START: { if (this.step_timer > SceneControl.START_TIME) { GUIControl.get().setVisibleStart(false); this.next_step = STEP.GAME; } } break; case STEP.GAME: { // 超过允许出现的最大数量,停止生成怪物 if (this.oni_group_complite >= this.oni_group_appear_max) { next_step = STEP.ONI_VANISH_WAIT; } if (this.oni_group_complite >= SCORE_HIDE_NUM && this.backup_oni_defeat_num == -1) { this.backup_oni_defeat_num = this.result.oni_defeat_num; } } break; case STEP.ONI_VANISH_WAIT: { do { // 等待怪物全部倒下 if (GameObject.FindGameObjectsWithTag("OniGroup").Length > 0) { break; } // 等待玩家加速 // 在画面外生成怪物小山,当最后的怪物倒下后使其移动一定距离 if (this.player.GetSpeedRate() < 0.5f) { break; } // next_step = STEP.LAST_RUN; } while(false); } break; case STEP.LAST_RUN: { if (this.step_timer > 2.0f) { // 使玩家停下来 next_step = STEP.PLAYER_STOP_WAIT; } } break; case STEP.PLAYER_STOP_WAIT: { // 玩家停下后,开始显示得分成绩 if (this.player.IsStopped()) { this.gui_control.score_control.setNumForce(this.backup_oni_defeat_num); this.gui_control.score_control.setNum(this.result.oni_defeat_num); next_step = STEP.GOAL; } } break; case STEP.GOAL: { // 等待怪物全部出现在画面上 if (this.oni_emitter.oni_num == 0) { this.next_step = STEP.ONI_FALL_WAIT; } } break; case STEP.ONI_FALL_WAIT: { if (!this.score_control.isActive() && this.step_timer > 1.5f) { this.next_step = STEP.RESULT_DEFEAT; } } break; case STEP.RESULT_DEFEAT: { if (this.step_timer >= 0.4f && this.step_timer_prev < 0.4f) { // SE(“咚咚”) this.GetComponent <AudioSource>().PlayOneShot(this.EvalSound); } // 等待评价显示结束 // if (this.step_timer > 0.5f) { this.next_step = STEP.RESULT_EVALUATION; } } break; case STEP.RESULT_EVALUATION: { if (this.step_timer >= 0.4f && this.step_timer_prev < 0.4f) { // SE(“咚咚”) this.GetComponent <AudioSource>().PlayOneShot(this.EvalSound); } // 等待评价显示结束 // if (this.step_timer > 2.0f) { this.next_step = STEP.RESULT_TOTAL; } } break; case STEP.RESULT_TOTAL: { if (this.step_timer >= 0.4f && this.step_timer_prev < 0.4f) { // SE(“咚咚”) this.GetComponent <AudioSource>().PlayOneShot(this.EvalSound); } // 等待评价显示结束 // if (this.step_timer > 2.0f) { this.next_step = STEP.GAME_OVER; } } break; case STEP.GAME_OVER: { // 鼠标被按下后淡出回到标题画面 // if (Input.GetMouseButtonDown(0)) { // 淡出 this.fader.fade(1.0f, new Color(0.0f, 0.0f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 1.0f)); this.GetComponent <AudioSource>().PlayOneShot(this.ReturnSound); this.next_step = STEP.GOTO_TITLE; } } break; case STEP.GOTO_TITLE: { // 淡入淡出结束后返回标题画面 // if (!this.fader.isActive()) { UnityEngine.SceneManagement.SceneManager.LoadScene("TitleScene"); } } break; } // 状态变化时的初始化处理 if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.START: { // 显示“开始!”文字 GUIControl.get().setVisibleStart(true); } break; case STEP.PLAYER_STOP_WAIT: { // 使玩家停下来 this.player.StopRequest(); // -------------------------------------------------------- // // 生成“怪物堆积而成的小山” if (this.result_control.getTotalRank() > 0) { GameObject oni_yama = Instantiate(this.OniYamaPrefab[this.result_control.getTotalRank() - 1]) as GameObject; Vector3 oni_yama_position = this.player.transform.position; oni_yama_position.x += this.player.CalcDistanceToStop(); oni_yama_position.x += SceneControl.GOAL_STOP_DISTANCE; oni_yama_position.y = 0.0f; oni_yama.transform.position = oni_yama_position; } else { } // -------------------------------------------------------- // } break; case STEP.GOAL: { // 开始显示得分成绩 // 生成使“怪物从上方掉下来”的发射器 GameObject go = Instantiate(this.OniEmitterPrefab) as GameObject; this.oni_emitter = go.GetComponent <OniEmitterControl>(); Vector3 emitter_position = oni_emitter.transform.position; // 放在怪物小山的上方 emitter_position.x = this.player.transform.position.x; emitter_position.x += this.player.CalcDistanceToStop(); emitter_position.x += SceneControl.GOAL_STOP_DISTANCE; this.oni_emitter.transform.position = emitter_position; // 根据最终的评价改变掉落怪物的数量 int oni_num = 0; switch (this.result_control.getTotalRank()) { case 0: oni_num = Mathf.Min(this.result.oni_defeat_num, 10); break; case 1: oni_num = 6; break; case 2: oni_num = 10; break; case 3: oni_num = 20; break; } this.oni_emitter.oni_num = oni_num; if (oni_num == 0) { this.oni_emitter.is_enable_hit_sound = false; } } break; case STEP.RESULT_DEFEAT: { // 得分评价出现后,停止发出怪物落下的声音 this.oni_emitter.is_enable_hit_sound = false; // 开始显示“击杀数量”的评价 this.gui_control.startDispDefeatRank(); } break; case STEP.RESULT_EVALUATION: { // 开始显示“击杀敏捷度”的评价 this.gui_control.startDispEvaluationRank(); } break; case STEP.RESULT_TOTAL: { // 隐藏“击杀数量”和“击杀敏捷度”的评价 this.gui_control.hideDefeatRank(); this.gui_control.hideEvaluationRank(); // 开始显示总体评价 this.gui_control.startDispTotalRank(); } break; case STEP.GAME_OVER: { // 显示“返回!”文本 this.gui_control.setVisibleReturn(true); } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; this.step_timer_prev = -1.0f; } // 各个状态的执行处理 switch (this.step) { case STEP.GAME: { // 控制怪物的出现 this.level_control.oniAppearControl(); } break; } }
void Update() { if (Input.GetKeyDown(KeyCode.P)) { Debug.Break(); } // ゲームの現在の状態を管理する this.step_timer_prev = this.step_timer; this.step_timer += Time.deltaTime; // 次の状態に移るかどうかを、チェックする. switch (this.step) { case STEP.START: { if (this.step_timer > SceneControl.START_TIME) { GUIControl.get().SetVisibleStart(false); this.next_step = STEP.GAME; } } break; case STEP.GAME: { // 出現最大数を過ぎたら、オニの発生を止める. if (this.oni_group_complite >= this.oni_group_appear_max) { next_step = STEP.ONI_VANISH_WAIT; } if (this.oni_group_complite >= SCORE_HIDE_NUM && this.backup_oni_defeat_num == -1) { this.backup_oni_defeat_num = this.result.oni_defeat_num; } } break; case STEP.ONI_VANISH_WAIT: { do { // おに(やられる前)をすべて倒すまで待つ. if (GameObject.FindGameObjectsWithTag("OniGroup").Length > 0) { break; } // プレイヤーが加速するまで待つ. // おに山を画面外で出現させるため、最後のおにを倒してから一定距離 // 走るようにしたい. if (this.player.GetSpeedRate() < 0.5f) { break; } // next_step = STEP.LAST_RUN; } while(false); } break; case STEP.LAST_RUN: { if (this.step_timer > 2.0f) { // プレイヤーを止める. next_step = STEP.PLAYER_STOP_WAIT; } } break; case STEP.PLAYER_STOP_WAIT: { // プレイヤーが止まったら、ゴール演出開始. if (this.player.IsStopped()) { this.gui_control.scoreControl.SetNumForce(this.backup_oni_defeat_num); this.gui_control.scoreControl.SetNum(this.result.oni_defeat_num); next_step = STEP.GOAL; } } break; case STEP.GOAL: { // おにが全部画面に出きるまでまつ. if (this.oni_emitter.oni_num == 0) { this.next_step = STEP.ONI_FALL_WAIT; } } break; case STEP.ONI_FALL_WAIT: { if (!this.score_control.IsActive() && this.step_timer > 1.5f) { this.next_step = STEP.RESULT_DEFEAT; } } break; case STEP.RESULT_DEFEAT: { if (this.step_timer >= 0.4f && this.step_timer_prev < 0.4f) { // SE(『どどんっ』). this.GetComponent <AudioSource>().PlayOneShot(this.EvalSound); } // 評価の表示が終わるまで待つ. // if (this.step_timer > 0.5f) { this.next_step = STEP.RESULT_EVALUATION; } } break; case STEP.RESULT_EVALUATION: { if (this.step_timer >= 0.4f && this.step_timer_prev < 0.4f) { // SE(『どどんっ』). this.GetComponent <AudioSource>().PlayOneShot(this.EvalSound); } // 評価の表示が終わるまで待つ. // if (this.step_timer > 2.0f) { this.next_step = STEP.RESULT_TOTAL; } } break; case STEP.RESULT_TOTAL: { if (this.step_timer >= 0.4f && this.step_timer_prev < 0.4f) { // SE(『どどんっ』). this.GetComponent <AudioSource>().PlayOneShot(this.EvalSound); } // 評価の表示が終わるまで待つ. // if (this.step_timer > 2.0f) { this.next_step = STEP.GAME_OVER; } } break; case STEP.GAME_OVER: { // マウスがクリックされたらフェードアウトしてタイトル画面に戻る. // if (Input.GetMouseButtonDown(0)) { // フェードアウトさせる this.fader.Fade(1.0f, new Color(0.0f, 0.0f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 1.0f)); this.GetComponent <AudioSource>().PlayOneShot(this.ReturnSound); this.next_step = STEP.GOTO_TITLE; } } break; case STEP.GOTO_TITLE: { // フェードが終わったらタイトル画面に戻る. // if (!this.fader.IsActive()) { UnityEngine.SceneManagement.SceneManager.LoadScene("TitleScene"); } } break; } // 状態がかわったときの初期化処理. if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.START: { // 『はじめっ!』の文字を表示する. GUIControl.get().SetVisibleStart(true); } break; case STEP.PLAYER_STOP_WAIT: { // プレイヤーを止める. this.player.StopRequest(); // -------------------------------------------------------- // // 『オニが積まれている山』を生成する. if (this.result_control.getTotalRank() > 0) { GameObject oni_yama = Instantiate(this.OniYamaPrefab[this.result_control.getTotalRank() - 1]) as GameObject; Vector3 oni_yama_position = this.player.transform.position; oni_yama_position.x += this.player.CalcDistanceToStop(); oni_yama_position.x += SceneControl.GOAL_STOP_DISTANCE; oni_yama_position.y = 0.0f; oni_yama.transform.position = oni_yama_position; } else { } // -------------------------------------------------------- // } break; case STEP.GOAL: { // ゴール演出開始. // 『おにが画面の上から飛んでくる』用のエミッターを生成する. GameObject go = Instantiate(this.OniEmitterPrefab) as GameObject; this.oni_emitter = go.GetComponent <OniEmitterControl>(); Vector3 emitter_position = oni_emitter.transform.position; // おに山の真上に置く. emitter_position.x = this.player.transform.position.x; emitter_position.x += this.player.CalcDistanceToStop(); emitter_position.x += SceneControl.GOAL_STOP_DISTANCE; this.oni_emitter.transform.position = emitter_position; // 最終評価で、ふってくるおにの数を変える. int oni_num = 0; switch (this.result_control.getTotalRank()) { case 0: oni_num = Mathf.Min(this.result.oni_defeat_num, 10); break; case 1: oni_num = 6; break; case 2: oni_num = 10; break; case 3: oni_num = 20; break; } this.oni_emitter.oni_num = oni_num; if (oni_num == 0) { this.oni_emitter.is_enable_hit_sound = false; } } break; case STEP.RESULT_DEFEAT: { // 評価が出た後は、おにの落下音を鳴らなくする. this.oni_emitter.is_enable_hit_sound = false; // 『鬼切り』の評価の表示をスタートする. this.gui_control.StartDispDefeatRank(); } break; case STEP.RESULT_EVALUATION: { // 『見切り』の評価の表示をスタートする. this.gui_control.StartDispEvaluationRank(); } break; case STEP.RESULT_TOTAL: { // 『鬼切り』『見切り』の評価の表示を消す. this.gui_control.HideDefeatRank(); this.gui_control.HideEvaluationRank(); // トータル評価の表示をスタートする. this.gui_control.StartDispTotalRank(); } break; case STEP.GAME_OVER: { // 『もどる!』の文字を表示する. this.gui_control.SetVisibleReturn(true); } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; this.step_timer_prev = -1.0f; } // 各状態での実行処理. switch (this.step) { case STEP.GAME: { // おにの出現の制御. this.level_control.OniAppearControl(); } break; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.P)) { Debug.Break(); } preStateTimer = timer; timer += Time.deltaTime; switch (state) { case State.Start: { if (timer > StartTime) { gameUIControl.SetStartVisible(false); nextState = State.Game; } break; } case State.Game: { levelControl.OniAppearControl(); if (oniGroupComplite >= oniGroupAppearMax) { nextState = State.WaitOniVanish; } if (oniGroupComplite >= ScoreHideNum && backupOniDefeatNum == -1) { backupOniDefeatNum = result.oniDefeatNum; } break; } case State.WaitOniVanish: { if (GameObject.FindGameObjectsWithTag("OniGroup").Length == 0 && player.GetSpeedRate() > 0.5f) { nextState = State.LastRun; } break; } case State.LastRun: { if (timer > 2.0f) { nextState = State.WaitPlayerStop; } break; } case State.WaitPlayerStop: { if (player.IsStopped) { scoreControl.SetScoreForce(backupOniDefeatNum); scoreControl.SetScore(result.oniDefeatNum); nextState = State.Goal; } break; } case State.Goal: { if (oniEmitter.oniNum == 0) { nextState = State.WaitOniFall; } break; } case State.WaitOniFall: { if (!scoreControl.IsActive && timer > 1.5f) { nextState = State.ResultDefeat; } break; } case State.ResultDefeat: { if (timer >= 0.4f && preStateTimer < 0.4f) { GetComponent <AudioSource>().PlayOneShot(evaluationSound); } if (timer > 0.5f) { nextState = State.ResultEvaluation; } break; } case State.ResultEvaluation: { if (timer >= 0.4f && preStateTimer < 0.4f) { GetComponent <AudioSource>().PlayOneShot(evaluationSound); } if (timer > 2.0f) { nextState = State.ResultTotal; } break; } case State.ResultTotal: { if (timer >= 0.4f && preStateTimer < 0.4f) { GetComponent <AudioSource>().PlayOneShot(evaluationSound); } if (timer > 2.0f) { nextState = State.GameOver; } break; } case State.GameOver: { if (Input.GetMouseButton(0)) { fadeControl.Fade(1.0f, new Color(0, 0, 0, 0), new Color(0, 0, 0, 1.0f)); GetComponent <AudioSource>().PlayOneShot(returnSound); nextState = State.GotoTitle; } break; } case State.GotoTitle: { if (fadeControl.IsActive) { UnityEngine.SceneManagement.SceneManager.LoadScene("TitleScene"); } break; } } if (nextState != State.None) { switch (nextState) { case State.Start: { gameUIControl.SetStartVisible(true); break; } case State.WaitPlayerStop: { player.Stop(); int totalRank = resultControl.GetTotalRank(); if (totalRank > 0) { var oniHill = Instantiate <GameObject>(OniHillPrefab[totalRank]); var oniHillPosition = player.transform.position; oniHillPosition.x += player.DistanceToStop(); oniHillPosition.x += GoalStopDistance; oniHillPosition.y = 0.0f; oniHill.transform.position = oniHillPosition; } break; } case State.Goal: { var go = Instantiate <GameObject>(oniEmitterPrefab); oniEmitter = go.GetComponent <OniEmitterControl>(); var emitterPosition = oniEmitter.transform.position; emitterPosition.x = player.transform.position.x; emitterPosition.x += player.DistanceToStop(); emitterPosition.x += GameSceneControl.GoalStopDistance; oniEmitter.transform.position = emitterPosition; int oniNum = 0; switch (resultControl.GetTotalRank()) { // bad rank case 0: oniNum = Mathf.Min(result.oniDefeatNum, 10); break; // normal rank case 1: oniNum = 6; break; // good rank case 2: oniNum = 10; break; // excellent rank case 3: oniNum = 20; break; } oniEmitter.oniNum = oniNum; if (oniNum == 0) { oniEmitter.isEnableHitSound = false; } break; } case State.ResultDefeat: { oniEmitter.isEnableHitSound = false; gameUIControl.DisplayDefeatRank(true); break; } case State.ResultEvaluation: { gameUIControl.DisplayEvaluationRank(true); break; } case State.ResultTotal: { gameUIControl.DisplayDefeatRank(false); gameUIControl.DisplayEvaluationRank(false); gameUIControl.DisplayTotalRank(true); break; } case State.GameOver: { gameUIControl.SetReturnVisible(true); break; } } state = nextState; nextState = State.None; timer = 0.0f; preStateTimer = -1.0f; } }
void Update() { // ゲームの現在の状態を管理する this.step_timer_prev = this.step_timer; this.step_timer += Time.deltaTime; // 次の状態に移るかどうかを、チェックする. switch(this.step) { case STEP.START: { if(this.step_timer > SceneControl.START_TIME) { next_step = STEP.GAME; } } break; case STEP.GAME: { // 出現最大数を過ぎたら、オニの発生を止める. if(this.oni_group_complite >= this.oni_group_appear_max ) { next_step = STEP.ONI_VANISH_WAIT; } if(this.oni_group_complite >= SCORE_HIDE_NUM && this.backup_oni_defeat_num == -1) { this.backup_oni_defeat_num = this.result.oni_defeat_num; } } break; case STEP.ONI_VANISH_WAIT: { do { // おに(やられる前)をすべて倒すまで待つ. if(GameObject.FindGameObjectsWithTag("OniGroup").Length > 0) { break; } // プレイヤーが加速するまで待つ. // おに山を画面外で出現させるため、最後のおにを倒してから一定距離 // 走るようにしたい. if(this.player.GetSpeedRate() < 0.5f) { break; } // next_step = STEP.LAST_RUN; } while(false); } break; case STEP.LAST_RUN: { if(this.step_timer > 2.0f) { // プレイヤーを止める. next_step = STEP.PLAYER_STOP_WAIT; } } break; case STEP.PLAYER_STOP_WAIT: { // プレイヤーが止まったら、ゴール演出開始. if(this.player.IsStopped()) { this.gui_control.score_control.setNumForce(this.backup_oni_defeat_num); this.gui_control.score_control.setNum(this.result.oni_defeat_num); next_step = STEP.GOAL; } } break; case STEP.GOAL: { // おにが全部画面に出きるまでまつ. if(this.oni_emitter.oni_num == 0) { this.next_step = STEP.ONI_FALL_WAIT; } } break; case STEP.ONI_FALL_WAIT: { if(!this.score_control.isActive() && this.step_timer > 1.5f) { this.next_step = STEP.RESULT_DEFEAT; } } break; case STEP.RESULT_DEFEAT: { if(this.step_timer >= 0.4f && this.step_timer_prev < 0.4f ) { // SE(『どどんっ』). this.GetComponent<AudioSource>().PlayOneShot(this.EvalSound); } // 評価の表示が終わるまで待つ. // if(this.step_timer > 0.5f) { this.next_step = STEP.RESULT_EVALUATION; } } break; case STEP.RESULT_EVALUATION: { if(this.step_timer >= 0.4f && this.step_timer_prev < 0.4f ) { // SE(『どどんっ』). this.GetComponent<AudioSource>().PlayOneShot(this.EvalSound); } // 評価の表示が終わるまで待つ. // if(this.step_timer > 2.0f) { this.next_step = STEP.RESULT_TOTAL; } } break; case STEP.RESULT_TOTAL: { if(this.step_timer >= 0.4f && this.step_timer_prev < 0.4f ) { // SE(『どどんっ』). this.GetComponent<AudioSource>().PlayOneShot(this.EvalSound); } // 評価の表示が終わるまで待つ. // if(this.step_timer > 2.0f) { this.next_step = STEP.GAME_OVER; } } break; case STEP.GAME_OVER: { // マウスがクリックされたらフェードアウトしてタイトル画面に戻る. // if(Input.GetMouseButtonDown(0)) { // フェードアウトさせる this.fader.fade( 1.0f, new Color( 0.0f, 0.0f, 0.0f, 0.0f ), new Color( 0.0f, 0.0f, 0.0f, 1.0f ) ); this.GetComponent<AudioSource>().PlayOneShot(this.ReturnSound); this.next_step = STEP.GOTO_TITLE; } } break; case STEP.GOTO_TITLE: { // フェードが終わったらタイトル画面に戻る. // if(!this.fader.isActive()) { Application.LoadLevel("TitleScene"); } } break; } // 状態がかわったときの初期化処理. if(this.next_step != STEP.NONE) { switch(this.next_step) { case STEP.PLAYER_STOP_WAIT: { // プレイヤーを止める. this.player.StopRequest(); // -------------------------------------------------------- // // 『オニが積まれている山』を生成する. if( this.result_control.getTotalRank() > 0 ) { GameObject oni_yama = Instantiate(this.OniYamaPrefab[this.result_control.getTotalRank() - 1]) as GameObject; Vector3 oni_yama_position = this.player.transform.position; oni_yama_position.x += this.player.CalcDistanceToStop(); oni_yama_position.x += SceneControl.GOAL_STOP_DISTANCE; oni_yama_position.y = 0.0f; oni_yama.transform.position = oni_yama_position; } else{ } // -------------------------------------------------------- // } break; case STEP.GOAL: { // ゴール演出開始. // 『おにが画面の上から飛んでくる』用のエミッターを生成する. GameObject go = Instantiate(this.OniEmitterPrefab) as GameObject; this.oni_emitter = go.GetComponent<OniEmitterControl>(); Vector3 emitter_position = oni_emitter.transform.position; // おに山の真上に置く. emitter_position.x = this.player.transform.position.x; emitter_position.x += this.player.CalcDistanceToStop(); emitter_position.x += SceneControl.GOAL_STOP_DISTANCE; this.oni_emitter.transform.position = emitter_position; // 最終評価で、ふってくるおにの数を変える. int oni_num = 0; switch(this.result_control.getTotalRank()) { case 0: oni_num = Mathf.Min( this.result.oni_defeat_num, 10 ); break; case 1: oni_num = 6; break; case 2: oni_num = 10; break; case 3: oni_num = 20; break; } this.oni_emitter.oni_num = oni_num; if( oni_num == 0 ) { this.oni_emitter.is_enable_hit_sound = false; } } break; case STEP.RESULT_DEFEAT: { // 評価が出た後は、おにの落下音を鳴らなくする. this.oni_emitter.is_enable_hit_sound = false; } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; this.step_timer_prev = -1.0f; } // 各状態での実行処理. switch(this.step) { case STEP.GAME: { // おにの出現の制御. this.level_control.oniAppearControl(); } break; case STEP.RESULT_DEFEAT: { // 評価の文字. this.gui_control.updateEval(this.step_timer); } break; case STEP.RESULT_EVALUATION: { // 評価の文字. this.gui_control.updateEval(this.step_timer); } break; case STEP.RESULT_TOTAL: { // 評価の文字. this.gui_control.updateEval(this.step_timer); } break; } }