public void apply_pattern_to_block(string pat, Block.COLOR_TYPE fore_color, Block.COLOR_TYPE back_color) { StackBlockControl stack_control = this.scene_control.stack_control; const int pat_h = 5; int y0 = StackBlockControl.GROUND_LINE; Block.COLOR_TYPE color; for (int y = StackBlockControl.GROUND_LINE; y < StackBlockControl.BLOCK_NUM_Y; y++) { for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++) { color = back_color; if (y0 <= y && y < y0 + pat_h) { if (pat[(y - y0) * StackBlockControl.BLOCK_NUM_X + x] == '*') { color = fore_color; } } stack_control.blocks[x, y].beginColorChangeAction(color); } } }
// 设置高度 public void SetHeight(int height) { StackBlock.PlaceIndex place; place.x = this.lx; place.y = StackBlockControl.GROUND_LINE - 1 + height; this.transform.position = StackBlockControl.calcIndexedPosition(place); }
public void start() { StackBlockControl stack_control = this.scene_control.stack_control; stack_control.is_connect_check_enable = false; GUIControl.get().setDispGoal(true); this.step = STEP.NONE; this.next_step = STEP.START; }
// 从from_block 拷贝颜色和位置等信息 public void relayFrom(StackBlock from_block) { this.setColorType(from_block.color_type); this.step = from_block.step; this.next_step = from_block.next_step; this.step_timer = from_block.step_timer; this.swap_action = from_block.swap_action; this.color_change_action = from_block.color_change_action; this.velocity = from_block.velocity; // 为了使其全局的位置不发生变化,计算偏移植 this.position_offset = StackBlockControl.calcIndexedPosition(from_block.place) + from_block.position_offset - StackBlockControl.calcIndexedPosition(this.place); //this.position_offset = from_block.transform.position - StackBlockControl.calcIndexedPosition(this.place); // 如果按上面这样做,旋转的中心就会受到偏移的影响,这样是不对的 }
// from_block から色や位置などをコピーする. public void relayFrom(StackBlock from_block) { this.setColorType(from_block.color_type); this.step = from_block.step; this.next_step = from_block.next_step; this.step_timer = from_block.step_timer; this.swap_action = from_block.swap_action; this.color_change_action = from_block.color_change_action; this.velocity = from_block.velocity; // グローバルの位置がかわらないよう、オフセットを計算する. this.position_offset = StackBlockControl.calcIndexedPosition(from_block.place) + from_block.position_offset - StackBlockControl.calcIndexedPosition(this.place); //this.position_offset = from_block.transform.position - StackBlockControl.calcIndexedPosition(this.place); // 上こちらにすると、回転の中心をずらしたことの影響を受けてしまうのでだめ. }
void Start() { // Block.materials = this.block_materials; this.stack_control = new StackBlockControl(); this.stack_control.StackBlockPrefab = this.StackBlockPrefab; this.stack_control.scene_control = this; this.stack_control.create(); this.vanish_fx_control = GameObject.FindGameObjectWithTag("VanishEffectControl").GetComponent <VanishEffectControl>(); // this.player_control = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>(); this.player_control.scene_control = this; this.bg_control = GameObject.FindGameObjectWithTag("BG").GetComponent <BGControl>(); this.goal_scene = new GoalSceneControl(); this.goal_scene.scene_control = this; this.goal_scene.create(); // this.audios = this.GetComponents <AudioSource>(); // this.slider_value = Mathf.InverseLerp(RotateAction.ROTATE_TIME_SWAP_MIN, RotateAction.ROTATE_TIME_SWAP_MAX, RotateAction.rotate_time_swap); this.height_level = 0; this.bg_control.setHeightRateDirect((float)this.height_level / (float)MAX_HEIGHT_LEVEL); }
public void execute() { StackBlockControl stack_control = this.scene_control.stack_control; PlayerControl player = this.scene_control.player_control; BGControl bg = this.scene_control.bg_control; this.step_timer_prev = this.step_timer; this.step_timer += Time.deltaTime; // -------------------------------------------------------- // // 次の状態に移るかどうかを、チェックする. switch (this.step) { case STEP.START: { this.next_step = STEP.WAIT_SWAP_END; } break; case STEP.WAIT_SWAP_END: { bool is_has_moving_block = false; foreach (StackBlock block in stack_control.blocks) { if (block.step != StackBlock.STEP.IDLE || block.next_step != StackBlock.STEP.NONE) { is_has_moving_block = true; break; } if (block.position_offset.y != 0.0f) { is_has_moving_block = true; break; } } if (!is_has_moving_block) { this.next_step = STEP.WAIT_SWAP_END_AFTER; } } break; case STEP.WAIT_SWAP_END_AFTER: { if (this.step_timer > 1.0f) { this.next_step = STEP.FALL; } } break; case STEP.FALL: { bool is_has_fall_block = false; for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++) { StackBlock block = stack_control.blocks[x, StackBlockControl.GROUND_LINE - 1]; if (block.isNowFallAction()) { is_has_fall_block = true; break; } } if (!is_has_fall_block) { this.next_step = STEP.COLOR_CHANGE; } } break; case STEP.COLOR_CHANGE: { if (this.step_timer > 1.0f && player.lx == PLAYER_EATING_POSITION) { this.begin_wait_step(1.0f, STEP.MESSAGE); } } break; case STEP.WAIT: { if (this.step_timer > this.wait.duration) { this.next_step = this.wait.next_step; } } break; } // -------------------------------------------------------- // // 状態が遷移したときの初期化. if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.START: { player.setControlable(false); } break; case STEP.FALL: { player.dropBlock(); bg.setHeightRateDirect(1.0f); stack_control.is_scroll_enable = false; stack_control.fall_request = 0; stack_control.blockFallRequest(); for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++) { stack_control.blocks[x, StackBlockControl.GROUND_LINE - 1].beginColorChangeAction(Block.COLOR_TYPE.CYAN); } // this.pat_count = 0; } break; case STEP.COLOR_CHANGE: { this.color_change_count = 0; player.SetHeight(-1); } break; case STEP.MESSAGE: { this.message_color = Block.NORMAL_COLOR_FIRST; player.beginGoalAct(); scene_control.playSe(SceneControl.SE.CLEAR); } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer_prev = -1.0f; this.step_timer = 0.0f; } // -------------------------------------------------------- // // 各状態での実行処理. switch (this.step) { case STEP.COLOR_CHANGE: { if (this.color_change_count < StackBlockControl.BLOCK_NUM_Y - StackBlockControl.GROUND_LINE) { float delay = 0.05f; if (Mathf.FloorToInt(this.step_timer_prev / delay) < Mathf.FloorToInt(this.step_timer / delay)) { int y = StackBlockControl.GROUND_LINE + this.color_change_count; for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++) { stack_control.blocks[x, y].beginColorChangeAction(Block.COLOR_TYPE.CYAN); } this.color_change_count++; } } if (player.lx != PLAYER_EATING_POSITION) { float delay = 0.5f; if (this.step_timer > delay * 2.0f) { if (Mathf.FloorToInt(this.step_timer_prev / delay) < Mathf.FloorToInt(this.step_timer / delay)) { if (player.lx > PLAYER_EATING_POSITION) { player.SetLinedPosition(player.lx - 1); } else { player.SetLinedPosition(player.lx + 1); } } } } } break; case STEP.MESSAGE: { float duration = 2.0f; if (this.step_timer >= duration) { if (Mathf.FloorToInt(this.step_timer_prev / duration) < Mathf.FloorToInt(this.step_timer / duration)) { do { this.message_color = Block.getNextNormalColor(this.message_color); } while(this.message_color == Block.COLOR_TYPE.CYAN); this.apply_pattern_to_block(this.message[this.pat_count], this.message_color, Block.COLOR_TYPE.CYAN); this.pat_count = (this.pat_count + 1) % this.message.Length; } } } break; } // ---------------------------------------------------------------- // }
void Update() { this.step_timer += Time.deltaTime; const float vanish_time = 1.0f; // -------------------------------------------- // // 检测是否迁移到下一状态 switch (this.step) { case STEP.VANISHING: { if (this.step_timer > vanish_time) { this.next_step = STEP.VACANT; } } break; case STEP.FALL: { // 落地后结束 if (this.position_offset.y == 0.0f) { this.next_step = STEP.IDLE; } } break; } // -------------------------------------------- // // 状态迁移时的初始化 if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.VACANT: { this.setColorType(COLOR_TYPE.GRAY); } break; case STEP.FALL: { this.velocity = Vector3.zero; } break; case STEP.VANISHING: { this.shake_start(); this.stack_control.scene_control.vanish_fx_control.createEffect(this); } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; } // -------------------------------------------- // // 各个状态的执行处理 switch (this.step) { case STEP.VANISHING: { // 方块的颜色按照 // // 原来的颜色→红→灰色 // // 的顺序变化 float rate; if (this.step_timer < vanish_time * 0.1f) { rate = this.step_timer / (vanish_time * 0.1f); } else if (this.step_timer < vanish_time * 0.3f) { rate = 1.0f; } else if (this.step_timer < vanish_time * 0.6f) { this.setColorType(COLOR_TYPE.RED); rate = (this.step_timer - vanish_time * 0.3f) / (vanish_time * 0.3f); } else { rate = 1.0f; } this.GetComponent <Renderer>().material.SetFloat("_BlendRate", rate); } break; } // -------------------------------------------------------------------------------- // // 网格上的位置(一般是固定的),旋转时初始化 this.transform.position = StackBlockControl.calcIndexedPosition(this.place); this.transform.rotation = Quaternion.identity; // -------------------------------------------- // // 滑动(偏移植的补间) if (this.step == STEP.FALL) { this.velocity.y += -9.8f * Time.deltaTime; this.position_offset.y += this.velocity.y * Time.deltaTime; if (this.position_offset.y < 0.0f) { this.position_offset.y = 0.0f; } // 为了避免超过下方的方块 // (处理的顺序不局限于从下到上,不够严谨) // if (this.place.y < StackBlockControl.BLOCK_NUM_Y - 1) { StackBlock under = this.stack_control.blocks[this.place.x, this.place.y + 1]; if (this.position_offset.y < under.position_offset.y) { this.position_offset.y = under.position_offset.y; this.velocity.y = under.velocity.y; } } } else { float position_offset_prev = this.position_offset.y; if (Mathf.Abs(this.position_offset.y) < 0.1f) { // 当偏移值足够小就结束 this.position_offset.y = 0.0f; } else { if (this.position_offset.y > 0.0f) { this.position_offset.y -= OFFSET_REVERT_SPEED * Time.deltaTime; this.position_offset.y = Mathf.Max(0.0f, this.position_offset.y); } else { this.position_offset.y -= -OFFSET_REVERT_SPEED * Time.deltaTime; this.position_offset.y = Mathf.Min(0.0f, this.position_offset.y); } } // 为了执行上方落下的方块停止时的处理,提前计算出速度 this.velocity.y = (this.position_offset.y - position_offset_prev) / Time.deltaTime; } this.transform.Translate(this.position_offset); // -------------------------------------------- // // 交换动作 this.swap_action.execute(this); // 蛋糕不会旋转 if (this.isCakeBlock()) { this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, 0.0f); this.transform.rotation = Quaternion.identity; } // -------------------------------------------- // // 改变颜色 this.color_change_action.execute(this); if (this.color_change_action.is_active) { // 旋转到一半的时候改变颜色 if (this.color_change_action.rate > 0.5f) { this.setColorType(this.color_change_action.target_color); } } // -------------------------------------------- // // 方块消失时的振动 this.shake_execute(); }
void Update() { this.step_timer += Time.deltaTime; const float vanish_time = 1.0f; // -------------------------------------------- // // 次の状態に移るかどうかを、チェックする. switch (this.step) { case STEP.VANISHING: { if (this.step_timer > vanish_time) { this.next_step = STEP.VACANT; } } break; case STEP.FALL: { // 着地したらおしまい. if (this.position_offset.y == 0.0f) { this.next_step = STEP.IDLE; } } break; } // -------------------------------------------- // // 状態が遷移したときの初期化. if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.VACANT: { this.setColorType(COLOR_TYPE.GRAY); } break; case STEP.FALL: { this.velocity = Vector3.zero; } break; case STEP.VANISHING: { this.shake_start(); this.stack_control.scene_control.vanish_fx_control.createEffect(this); } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; } // -------------------------------------------- // // 各状態での実行処理. switch (this.step) { case STEP.VANISHING: { // ブロックの色を // // 元の色→赤→灰色 // // に変える. float rate; if (this.step_timer < vanish_time * 0.1f) { rate = this.step_timer / (vanish_time * 0.1f); } else if (this.step_timer < vanish_time * 0.3f) { rate = 1.0f; } else if (this.step_timer < vanish_time * 0.6f) { this.setColorType(COLOR_TYPE.RED); rate = (this.step_timer - vanish_time * 0.3f) / (vanish_time * 0.3f); } else { rate = 1.0f; } this.GetComponent <Renderer>().material.SetFloat("_BlendRate", rate); } break; } // -------------------------------------------------------------------------------- // // マス目上の位置(常に固定)、回転は0で初期化. this.transform.position = StackBlockControl.calcIndexedPosition(this.place); this.transform.rotation = Quaternion.identity; // -------------------------------------------- // // スライド(オフセットの補間). if (this.step == STEP.FALL) { this.velocity.y += -9.8f * Time.deltaTime; this.position_offset.y += this.velocity.y * Time.deltaTime; if (this.position_offset.y < 0.0f) { this.position_offset.y = 0.0f; } // 下にあるブロックを追い抜いてしまわないように. // (処理の順番が下→上とも限らないので、厳密ではない). // if (this.place.y < StackBlockControl.BLOCK_NUM_Y - 1) { StackBlock under = this.stack_control.blocks[this.place.x, this.place.y + 1]; if (this.position_offset.y < under.position_offset.y) { this.position_offset.y = under.position_offset.y; this.velocity.y = under.velocity.y; } } } else { float position_offset_prev = this.position_offset.y; if (Mathf.Abs(this.position_offset.y) < 0.1f) { // オフセットが十分小さくなったらおしまい. this.position_offset.y = 0.0f; } else { if (this.position_offset.y > 0.0f) { this.position_offset.y -= OFFSET_REVERT_SPEED * Time.deltaTime; this.position_offset.y = Mathf.Max(0.0f, this.position_offset.y); } else { this.position_offset.y -= -OFFSET_REVERT_SPEED * Time.deltaTime; this.position_offset.y = Mathf.Min(0.0f, this.position_offset.y); } } // 上から落ちてくるブロックがぶつかったときのために、速度を計算しておく. this.velocity.y = (this.position_offset.y - position_offset_prev) / Time.deltaTime; } this.transform.Translate(this.position_offset); // -------------------------------------------- // // スワップ動作. this.swap_action.execute(this); // ケーキは回転しない. if (this.isCakeBlock()) { this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, 0.0f); this.transform.rotation = Quaternion.identity; } // -------------------------------------------- // // カラーチェンジ. this.color_change_action.execute(this); if (this.color_change_action.is_active) { // 半周回ったところで色が変わる. if (this.color_change_action.rate > 0.5f) { this.setColorType(this.color_change_action.target_color); } } // -------------------------------------------- // // ブロックが消えるときの振動. this.shake_execute(); }
void Update() { this.step_timer += Time.deltaTime; // 检测状态迁移 if (this.next_step == STEP.NONE) { switch (this.step) { case STEP.CARRY_UP: { if (this.position_offset.y == 0.0f) { this.next_step = STEP.CARRY; } } break; case STEP.DROP_DOWN: { if (this.position_offset.y == 0.0f) { this.player.scene_control.stack_control.endDropBlockAction(this.place.x); this.next_step = STEP.HIDE; } } break; } } // 状态迁移时的初始化 if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.HIDE: { this.GetComponent <Renderer>().enabled = false; } break; case STEP.CARRY_UP: { // 从隐藏状态开始时,算出现在的位置 if (this.step == STEP.HIDE) { this.transform.position = StackBlockControl.calcIndexedPosition(this.place); } Vector3 base_position = this.player.transform.position; base_position.y += Block.SIZE_Y; this.position_offset = this.transform.position - base_position; this.setVisible(true); } break; case STEP.DROP_DOWN: { Vector3 base_position = StackBlockControl.calcIndexedPosition(this.place); this.position_offset = this.transform.position - base_position; } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; } // 各个状态的执行 Vector3 position = this.transform.position; switch (this.step) { case STEP.CARRY: case STEP.CARRY_UP: { position.x = this.player.transform.position.x; position.y = this.player.transform.position.y + Block.SIZE_Y; position.z = 0.0f; } break; case STEP.DROP_DOWN: { position = StackBlockControl.calcIndexedPosition(this.place); } break; } // 对偏移值进行补间 if (Mathf.Abs(this.position_offset.y) < 0.1f) { this.position_offset.y = 0.0f; } else { const float speed = 0.2f; if (this.position_offset.y > 0.0f) { this.position_offset.y -= speed * (60.0f * Time.deltaTime); this.position_offset.y = Mathf.Max(this.position_offset.y, 0.0f); } else { this.position_offset.y -= -speed * (60.0f * Time.deltaTime); this.position_offset.y = Mathf.Min(this.position_offset.y, 0.0f); } } position.y += this.position_offset.y; this.transform.position = position; }
void Update() { this.step_timer += Time.deltaTime; // 状態遷移のチェック. if (this.next_step == STEP.NONE) { switch (this.step) { case STEP.CARRY_UP: { if (this.position_offset.y == 0.0f) { this.next_step = STEP.CARRY; } } break; case STEP.DROP_DOWN: { if (this.position_offset.y == 0.0f) { this.player.scene_control.stack_control.endDropBlockAction(this.place.x); this.next_step = STEP.HIDE; } } break; } } // 状態遷移時の初期化. if (this.next_step != STEP.NONE) { switch (this.next_step) { case STEP.HIDE: { this.GetComponent <Renderer>().enabled = false; } break; case STEP.CARRY_UP: { // 非表示状態から始まったときは、現在位置を求めておく. if (this.step == STEP.HIDE) { this.transform.position = StackBlockControl.calcIndexedPosition(this.place); } Vector3 base_position = this.player.transform.position; base_position.y += Block.SIZE_Y; this.position_offset = this.transform.position - base_position; this.setVisible(true); } break; case STEP.DROP_DOWN: { Vector3 base_position = StackBlockControl.calcIndexedPosition(this.place); this.position_offset = this.transform.position - base_position; } break; } this.step = this.next_step; this.next_step = STEP.NONE; this.step_timer = 0.0f; } // 各状態の実行. Vector3 position = this.transform.position; switch (this.step) { case STEP.CARRY: case STEP.CARRY_UP: { position.x = this.player.transform.position.x; position.y = this.player.transform.position.y + Block.SIZE_Y; position.z = 0.0f; } break; case STEP.DROP_DOWN: { position = StackBlockControl.calcIndexedPosition(this.place); } break; } // オフセットを補間する. if (Mathf.Abs(this.position_offset.y) < 0.1f) { this.position_offset.y = 0.0f; } else { const float speed = 0.2f; if (this.position_offset.y > 0.0f) { this.position_offset.y -= speed * (60.0f * Time.deltaTime); this.position_offset.y = Mathf.Max(this.position_offset.y, 0.0f); } else { this.position_offset.y -= -speed * (60.0f * Time.deltaTime); this.position_offset.y = Mathf.Min(this.position_offset.y, 0.0f); } } position.y += this.position_offset.y; this.transform.position = position; }
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; } }