private void PausedUpdate(GameTime gameTime) { int returnVal = menu.Update(gameTime, true); switch (returnVal) { case 1: //continue case -1: moveTime = gameTime.TotalGameTime.TotalSeconds + moveRate; state = gameState.COUNTDOWN; menu = null; break; case 2: //exit this.Exit(); break; } }
private void MainMenuUpdate(GameTime gameTime) { int returnVal = menu.Update(gameTime, false); switch (returnVal) { case 1: //new game field = new Field(); state = gameState.COUNTDOWN; menu = null; break; case 2: this.Exit(); break; } }
protected override void Initialize() { //this is where I'd open any localization files and input data for the menus pausedItems = new List<string>(); pausedItems.Add("PAUSED"); pausedItems.Add("Continue Game"); pausedItems.Add("Exit Game"); mainMenuItems = new List<string>(); mainMenuItems.Add("A Game of Blocks and Lines"); mainMenuItems.Add("New Game"); mainMenuItems.Add("Exit Game"); gameOverItems = new List<string>(); gameOverItems.Add("Game Over!"); gameOverItems.Add("New Game"); gameOverItems.Add("Exit Game"); instructionItems = new List<string>(); instructionItems.Add("Up - Rotate Clockwise"); instructionItems.Add("Left/Right - Move Piece"); instructionItems.Add("Down - Move Down (Soft Drop)"); instructionItems.Add("Space - Hard Drop"); instructionItems.Add("X - Rotate Counter-Clockwise"); instructionItems.Add("C - Hold Piece"); instructionItems.Add("Esc - Pause"); //so I don't calculate this every frame, dtermining the upper //bound counter for DrawInstruction() if(instructionItems.Count % 2 == 1) { instructionCount = instructionItems.Count - 1; } else { instructionCount = instructionItems.Count; } menu = new Menu(mainMenuItems); nextLocation.x = 350; nextLocation.y = 55; heldLocation.x = 350; heldLocation.y = 225; base.Initialize(); }
private void InProgressUpdate(GameTime gameTime) { kbInput.UpdateWithNewState(Keyboard.GetState(), gameTime); if (!newPiece) { if (kbInput.WasKeyPressed(Keys.Left, true)) ValidMove(direction.LEFT); if (kbInput.WasKeyPressed(Keys.Right, true)) ValidMove(direction.RIGHT); if (kbInput.WasKeyPressed(Keys.Up, true)) ValidMove(direction.RotateCW); if (kbInput.WasKeyPressed(Keys.Down, true)) ValidMove(direction.DOWN); if (kbInput.WasKeyPressed(Keys.Space, false)) ValidMove(direction.HARD_DROP); if (kbInput.WasKeyPressed(Keys.X, true)) ValidMove(direction.RotateCCW); if (kbInput.WasKeyPressed(Keys.C, true)) if(!justHeld) { DispatchPiece(true); } if (kbInput.WasKeyPressed(Keys.Escape, false)) { state = gameState.PAUSED; menu = new Menu(pausedItems); } if (gameTime.TotalGameTime.TotalSeconds >= moveTime) { ValidMove(direction.TICK_DOWN); moveTime = gameTime.TotalGameTime.TotalSeconds + moveRate; } } else if (state != gameState.GAME_OVER) { if (currPiece != null) { field.placePiece(currPiece.shape, currPiece.location); } int lines = field.checkLines(); score += 50 * lines + (25 * lines); totalLines += lines; level = (totalLines / 10) + 1; moveRate = 1.50 - ((level - 1) * .1); DispatchPiece(); newPiece = false; moveTime = gameTime.TotalGameTime.TotalSeconds + moveRate; } }
//Maybe separate out Holding stuff to another function? public void DispatchPiece(bool holding = false) { if (state == gameState.COUNTDOWN) nextPiece = random.Next(0, 7); if (holding) { if (heldPiece > -1) { int temp = currPiece.type; currPiece = new Tetronimo(heldPiece); heldPiece = temp; } else { heldPiece = currPiece.type; currPiece = new Tetronimo(nextPiece); nextPiece = random.Next(0, 7); } //don't want them to spam the hold key, let another piece go first. justHeld = true; } else { currPiece = new Tetronimo(nextPiece); nextPiece = random.Next(0, 7); //reset justHeld, we got a new piece justHeld = false; } //if the piece can't be drawn, it's blocked, game ends. if (!ValidMove(direction.NEW_PIECE)) { menu = new Menu(gameOverItems); state = gameState.GAME_OVER; } else { hardDropLocation = field.getHardDrop(currPiece.shape, currPiece.location); } }