/// <summary> /// 現在のコマンド取得 / 取得後初期化するので副作用あり /// </summary> /// <returns></returns> public ePlayCommand GetCurrentCommand() { // 一回取得した後は無効 ePlayCommand ret = command; command = ePlayCommand.None; return(ret); }
/// <summary> /// 更新 /// </summary> /// <param name="dt"></param> /// <returns></returns> public override bool Update(float dt) { ePlayCommand com = input.GetCurrentCommand(); if (com == ePlayCommand.PauseAndResume) { return(false); } return(true); }
/// <summary> /// 毎フレーム更新処理 /// </summary> /// <param name="dt"></param> public void UpdateFrameProcess(float dt) { // 現在のキー情報取得 ePlayCommand command = getInputCommand(); if (command == ePlayCommand.None) { // 特に何も押されてない if (current.command != ePlayCommand.None) { // 何か設定されてたらリセットしとく current.Initialize(); } } else if (command == current.command) { // 現在と同じボタンが押された current.duration += dt; switch (current.inputType) { case eInputType.Press: // 押しっぱなしなので常に判定 current.duration = 0f; break; case eInputType.Repeat: { // 判定に遊びを作る float maxDuration = current.isAccelerate ? DURATION_SECOND_GEAR : DURATION_FIRST_GEAR; if (current.duration >= maxDuration) { current.duration = 0f; current.isAccelerate = true; } } break; case eInputType.Down: // 初回だけ反応するので何もしない break; } } else { // 初めて押された current.command = command; current.duration = 0f; current.isAccelerate = false; } }
/// <summary> /// 更新 /// </summary> /// <param name="_dt"></param> /// <returns></returns> public override sealed bool Update(float dt) { if (!isPlaying) { return(false); } ePlayCommand command = input.GetCurrentCommand(); BlockStatus attemptPut = current; switch (command) { case ePlayCommand.Rotate: attemptPut.RotateNum++; break; case ePlayCommand.Right: attemptPut.Pos.x++; break; case ePlayCommand.Left: attemptPut.Pos.x--; break; case ePlayCommand.Down: case ePlayCommand.DownImmediately: duration = speed; break; case ePlayCommand.PauseAndResume: onPause(); return(true); } lock (threadLockObj) { // 通信対戦時にここで書き換えている値を参照するのでlock mutableUpdate(attemptPut, command, dt); } return(true); }
/// <summary> /// キー入力取得 /// </summary> /// <returns></returns> private ePlayCommand getInputCommand() { ePlayCommand command = ePlayCommand.None; if (Input.GetKey(KeyCode.RightArrow)) { command = ePlayCommand.Right; } else if (Input.GetKey(KeyCode.LeftArrow)) { command = ePlayCommand.Left; } else if (Input.GetKey(KeyCode.UpArrow)) { command = ePlayCommand.Rotate; } else if (Input.GetKey(KeyCode.DownArrow)) { command = ePlayCommand.Down; } else if (Input.GetKeyDown(KeyCode.Space)) { command = ePlayCommand.DownImmediately; } else if (Input.GetKeyDown(KeyCode.P)) { command = ePlayCommand.PauseAndResume; } else if (Input.GetKeyDown(KeyCode.Return)) { command = ePlayCommand.Enter; } else if (Input.GetKeyDown(KeyCode.Escape)) { command = ePlayCommand.Cancel; } return(command); }
/// <summary> /// 書き換え前提の更新 / lock必須 /// </summary> /// <param name="_attemptPut"></param> /// <param name="command"></param> /// <param name="_dt"></param> private void mutableUpdate(BlockStatus attemptPut, ePlayCommand command, float dt) { current = operatePanel(current, attemptPut); // 一定時間超えたらブロックを一段下へ bool willLinesDelete = false; duration += dt; if (duration >= speed) { willLinesDelete = downBlock(command == ePlayCommand.DownImmediately); duration = 0; } if (willLinesDelete) { // 消える行がある場合、downStateへ移動 isEndOfDown = true; onDeleteLine(); } else { // 最下層の位置を描画 attempt = drawLowestBlock(current, attempt); } }
/// <summary> /// アップデート /// </summary> public void SetCurrentCommand(ePlayCommand com) { command = com; }
/// <summary> /// 初期化 /// </summary> public void Initialize() { command = ePlayCommand.None; duration = 0f; isAccelerate = false; }