public void HandleInput(GameTime gameTime, InputHelper inputHelper) { input.Update(gameTime); PlaceStates ps = CanPlace(); if (inputHelper.currentKeyboardState.IsKeyDown(Keys.A) && inputHelper.previousKeyboardState.IsKeyUp(Keys.A) && rotateL() && ps != PlaceStates.OFFSCREEN) { /* roteer linksom */ } if (inputHelper.currentKeyboardState.IsKeyDown(Keys.D) && inputHelper.previousKeyboardState.IsKeyUp(Keys.D) && rotateR() && ps != PlaceStates.OFFSCREEN) {/* roteer rechtsom */ } if (inputHelper.currentKeyboardState.IsKeyDown(Keys.Left) && inputHelper.previousKeyboardState.IsKeyUp(Keys.Left) && side() && ps != PlaceStates.OFFSCREEN) { position.X--; } if (inputHelper.currentKeyboardState.IsKeyDown(Keys.Right) && inputHelper.previousKeyboardState.IsKeyUp(Keys.Right) && side() && ps != PlaceStates.OFFSCREEN) { position.X++; } if (inputHelper.currentKeyboardState.IsKeyDown(Keys.Down) && inputHelper.previousKeyboardState.IsKeyUp(Keys.Down) && fall()) { position.Y++; } }
// De tetromino beweegt recht naar beneden public void BlockFall() { TimeReset = false; Vector2 NewLocation = fallingPiece.Location + new Vector2(0, 1); PlaceStates ps = CanPlace(fallingPiece.Shape, (int)NewLocation.X, (int)NewLocation.Y); if (ps != PlaceStates.CAN_PLACE) { Place(fallingPiece.Shape, (int)fallingPiece.Location.X, (int)fallingPiece.Location.Y); SpawnCurrent(); ps = CanPlace(fallingPiece.Shape, (int)fallingPiece.Location.X, (int)fallingPiece.Location.Y); if (ps == PlaceStates.BLOCKED) { // Hier ben je game over grid.GameGrid = grid.ResetGrid(); //GameOver = true; } } else { fallingPiece.Location = NewLocation; } TimeReset = true; }
// Checkt of een tetromino mag draaien, zoja dan word de opdracht uitgevoerd public void RotatePiece() { int[,] newPiece = shape.Rotate(fallingPiece.Shape); PlaceStates ps = CanPlace(newPiece, (int)fallingPiece.Location.X, (int)fallingPiece.Location.Y); if (ps == PlaceStates.CAN_PLACE) { fallingPiece.Shape = newPiece; } }
public void Update(GameTime gameTime) { if (gameState == GameState.Playing) { if (nextblock == null) { next(); } if (currentblock == null) { position.X = r.Next(10); currentblock = nextblock; next(); } fall(); rotateL(); rotateR(); side(); HandleInput(gameTime, input); ElapsedTime += gameTime.ElapsedGameTime.Milliseconds; if (ElapsedTime > Steptime) { position.Y++; ElapsedTime = 0; Vector2 newblockposition = position + new Vector2(0, 1); PlaceStates ps = CanPlace(); if (ps != PlaceStates.PLACABLE) { Place(); next(); if (ps == PlaceStates.NOTPLACABLE) { gameState = GameState.GameOver; } } } if (gameState == GameState.GameOver) { reset(); } } }
// Checkt of een tetromino naar links of rechts mag bewegen aan de hand van input, zoja dan word de opdracht uitgevoerd public void Move(string direction) { if (direction == "left") { Vector2 NewLocation = fallingPiece.Location + new Vector2(-1, 0); PlaceStates ps = CanPlace(fallingPiece.Shape, (int)NewLocation.X, (int)NewLocation.Y); if (ps == PlaceStates.CAN_PLACE) { fallingPiece.Location = NewLocation; } } if (direction == "right") { Vector2 NewLocation = fallingPiece.Location + new Vector2(1, 0); PlaceStates ps = CanPlace(fallingPiece.Shape, (int)NewLocation.X, (int)NewLocation.Y); if (ps == PlaceStates.CAN_PLACE) { fallingPiece.Location = NewLocation; } } }