void Update() { StackBlockControl stack_control = this.scene_control.stack_control; this.step_timer += Time.deltaTime; // ---------------------------------------------------------------- // #if false // 按下“3”后,能量减少 if (Input.GetKey(KeyCode.Keypad3)) { this.addLife(-1); } // 按下“4”后,能量增加 if (Input.GetKey(KeyCode.Keypad4)) { this.addLife(1); } #endif // 饥饿达到一定程度后,游戏结束 if (this.life <= LIFE_MIN) { this.next_step = STEP.HUNGRY; } // // 检测是否移到下一个状态 switch (this.step) { case STEP.NORMAL: case STEP.EATING: { // 举起 if (this.next_step == STEP.NONE) { do { if (!this.is_carry_input()) { break; } // 脚下的方块 StackBlock ground_block = stack_control.blocks[this.lx, StackBlockControl.GROUND_LINE]; // 灰色的方块不能被举起 if (!ground_block.isCarriable()) { break; } // 正在执行交换的方块不能被举起 if (ground_block.isNowSwapAction()) { break; } // // 将举起的方块的颜色设置为和脚下方块相同 this.carry_block.setColorType(ground_block.color_type); this.carry_block.startCarry(this.lx); stack_control.pickBlock(this.lx); // this.GetComponent <AudioSource>().PlayOneShot(this.audio_pick); this.next_step = STEP.CARRY; } while(false); } if (this.next_step == STEP.NONE) { if (this.step == STEP.EATING) { if (this.step_timer > 3.0f) { this.next_step = STEP.NORMAL; } } } } break; case STEP.CARRY: { if (this.is_carry_input()) { // 放下 if (this.carry_block.isCakeBlock()) { // 如果举起的时蛋糕, // 吃掉 & 改变颜色 this.carry_block.startHide(); stack_control.onEatCake(); this.addLife(LIFE_ADD_CAKE); this.GetComponent <AudioSource>().PlayOneShot(scene_control.audio_clips[(int)SceneControl.SE.EATING]); // this.next_step = STEP.EATING; } else { // 如果举起的是普通的方块,则放下 this.drop_block(); this.addLife(LIFE_SUB); this.next_step = STEP.NORMAL; } } } break; } // ---------------------------------------------------------------- // // 状态迁移时的初始化 if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.NORMAL: { } break; case STEP.HUNGRY: { } break; case STEP.GOAL_ACT: { this.SetHeight(-1); } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; } // ---------------------------------------------------------------- // // 各个状态的执行处理 switch (this.step) { case STEP.NORMAL: case STEP.CARRY: case STEP.EATING: { int lx = this.lx; // 左右移动 do { // 举起,放下过程中不能左右移动 // // 如果习惯于这种操作,有时可能会无法移动影响了游戏操作 // 屏蔽 // /*if(this.carry_block.isMoving()) { * * break; * }*/ // if (!this.is_controlable) { break; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { lx--; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { lx++; } else { break; } lx = Mathf.Clamp(lx, 0, StackBlockControl.BLOCK_NUM_X - 1); this.GetComponent <AudioSource>().PlayOneShot(this.audio_walk); this.SetLinedPosition(lx); } while(false); } break; } // ---------------------------------------------------------------- // // 控制纹理模式 switch (this.step) { default: case STEP.NORMAL: { // 左→闭上眼睛→右→闭上眼睛→循环 int texture_index; texture_index = (int)(this.step_timer * 8.0f); texture_index %= 4; if (texture_index % 2 == 0) { // 闭上眼睛 texture_index = 0; } else { // 右,左 texture_index = (texture_index / 2) % 2 + 1; } this.sprite.SetTexture(this.textures_normal[texture_index]); } break; case STEP.CARRY: { int texture_index; texture_index = (int)(this.step_timer * 8.0f); texture_index %= 4; if (texture_index % 2 == 0) { texture_index = 0; } else { texture_index = (texture_index / 2) % 2 + 1; } this.sprite.SetTexture(this.textures_carry[texture_index]); } break; case STEP.EATING: { int texture_index = ((int)(this.step_timer / 0.1f)) % this.textures_eating.Length; this.sprite.SetTexture(this.textures_eating[texture_index]); } break; case STEP.HUNGRY: { this.sprite.SetTexture(this.texture_hungry); } break; case STEP.GOAL_ACT: { const float time0 = 0.5f; const float time1 = 0.5f; float time_all = time0 + time1; float t = Mathf.Repeat(this.step_timer, time_all); if (t < time0) { this.sprite.SetTexture(this.textures_carry[1]); } else { t -= time0; int texture_index = ((int)(t / 0.1f)) % this.textures_eating.Length; this.sprite.SetTexture(this.textures_eating[texture_index]); } } break; } }
void Update() { StackBlockControl stack_control = this.scene_control.stack_control; this.step_timer += Time.deltaTime; // ---------------------------------------------------------------- // #if false // "3" を押すと、エネルギー減少. if (Input.GetKey(KeyCode.Keypad3)) { this.addLife(-1); } // "4" を押すと、エネルギー減少. if (Input.GetKey(KeyCode.Keypad4)) { this.addLife(1); } #endif // 腹ペコになったら、ゲームオーバー. if (this.life <= LIFE_MIN) { this.next_step = STEP.HUNGRY; } // // 次の状態に移るかどうかを、チェックする. switch (this.step) { case STEP.NORMAL: case STEP.EATING: { // 持ち上げ. if (this.next_step == STEP.NONE) { do { if (!this.is_carry_input()) { break; } // 足元のブロック. StackBlock ground_block = stack_control.blocks[this.lx, StackBlockControl.GROUND_LINE]; // 灰色のブロックは持ち上げられない. if (!ground_block.isCarriable()) { break; } // スワップ動作中は持ち上げられない. if (ground_block.isNowSwapAction()) { break; } // // キャリーブロックを、足元のブロックと同じ色にする. this.carry_block.setColorType(ground_block.color_type); this.carry_block.startCarry(this.lx); stack_control.pickBlock(this.lx); // this.GetComponent <AudioSource>().PlayOneShot(this.audio_pick); this.next_step = STEP.CARRY; } while(false); } if (this.next_step == STEP.NONE) { if (this.step == STEP.EATING) { if (this.step_timer > 3.0f) { this.next_step = STEP.NORMAL; } } } } break; case STEP.CARRY: { if (this.is_carry_input()) { // ぽい捨て. if (this.carry_block.isCakeBlock()) { // 持ち上げていたのがケーキだったら、 // もぐもぐ&カラーチェンジ. this.carry_block.startHide(); stack_control.onEatCake(); this.addLife(LIFE_ADD_CAKE); this.GetComponent <AudioSource>().PlayOneShot(scene_control.audio_clips[(int)SceneControl.SE.EATING]); // this.next_step = STEP.EATING; } else { // 持ち上げていたのが普通のブロックだったら、ぽい捨て. this.drop_block(); this.addLife(LIFE_SUB); this.next_step = STEP.NORMAL; } } } break; } // ---------------------------------------------------------------- // // 状態が遷移したときの初期化. if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.NORMAL: { } break; case STEP.HUNGRY: { } break; case STEP.GOAL_ACT: { this.SetHeight(-1); } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; } // ---------------------------------------------------------------- // // 各状態での実行処理. switch (this.step) { case STEP.NORMAL: case STEP.CARRY: case STEP.EATING: { int lx = this.lx; // 左右移動. do { // 持ち上げ、ぽい捨て中は左右に移動できない. // // 慣れてくると、少しでも動けないときがあるのがストレスになるので // 封印 // /*if(this.carry_block.isMoving()) { * * break; * }*/ // if (!this.is_controlable) { break; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { lx--; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { lx++; } else { break; } lx = Mathf.Clamp(lx, 0, StackBlockControl.BLOCK_NUM_X - 1); this.GetComponent <AudioSource>().PlayOneShot(this.audio_walk); this.SetLinedPosition(lx); } while(false); } break; } // ---------------------------------------------------------------- // // テクスチャーパターンのコントロール. switch (this.step) { default: case STEP.NORMAL: { // 左→目閉じる→右→目閉じる→ループ. int texture_index; texture_index = (int)(this.step_timer * 8.0f); texture_index %= 4; if (texture_index % 2 == 0) { // 目を閉じる. texture_index = 0; } else { // 右、左 texture_index = (texture_index / 2) % 2 + 1; } this.sprite.SetTexture(this.textures_normal[texture_index]); } break; case STEP.CARRY: { int texture_index; texture_index = (int)(this.step_timer * 8.0f); texture_index %= 4; if (texture_index % 2 == 0) { texture_index = 0; } else { texture_index = (texture_index / 2) % 2 + 1; } this.sprite.SetTexture(this.textures_carry[texture_index]); } break; case STEP.EATING: { int texture_index = ((int)(this.step_timer / 0.1f)) % this.textures_eating.Length; this.sprite.SetTexture(this.textures_eating[texture_index]); } break; case STEP.HUNGRY: { this.sprite.SetTexture(this.texture_hungry); } break; case STEP.GOAL_ACT: { const float time0 = 0.5f; const float time1 = 0.5f; float time_all = time0 + time1; float t = Mathf.Repeat(this.step_timer, time_all); if (t < time0) { this.sprite.SetTexture(this.textures_carry[1]); } else { t -= time0; int texture_index = ((int)(t / 0.1f)) % this.textures_eating.Length; this.sprite.SetTexture(this.textures_eating[texture_index]); } } break; } }