private void CorrectWallType(WorldCell cell, Wall newWall) { WorldCell c = cell; Wall cw = newWall; if (c.occupiedType == "VPiece" && worldCells[c.index + 1].occupiedType == "HPiece") { worldCells[c.index + 1].occupiedType = "TTop"; for (int i = 0; i < Walls.Count; i++) { Wall wall = Walls[i]; if (wall.index == cw.index + 1) { wall.Type = "TTop"; } //done 1 down } } if (c.occupiedType == "VPiece" && worldCells[c.index - 1].occupiedType == "HPiece") { worldCells[c.index - 1].occupiedType = "TBottom"; for (int i = 0; i < Walls.Count; i++) { Wall wall = Walls[i]; if (wall.index == cw.index - 1) { wall.Type = "TBottom"; } //done 1 up } } }
private void CreateTurretWithClick(WorldCell worldcell) { if (Input.MouseInRect(worldcell.cellRect) && Input.KeyPressed(Keys.F1)) { if (worldcell.occupiedType != "" && worldcell.occupiedType != "turret") { Turret turret = new Turret(turretSpriteSheet); turret.Position = new Vector2(worldcell.cellRect.X + turret.BoundingBox.Width / 2, worldcell.cellRect.Y + turret.BoundingBox.Height / 2); Turrets.Add(turret); worldcell.occupiedType = "turret"; } } }
private void CreateWallWithClick(WorldCell worldCell) { if (Input.MouseInRect(worldCell.cellRect) && Input.LeftMouseButtonClick() && worldCell.occupiedType == "null") { Vector2 cell = new Vector2(worldCell.cellRect.X, worldCell.cellRect.Y); Wall newWall = new Wall(WallSpriteSheet, "VPiece"); newWall.index = worldCell.index; newWall.Position = cell; newWall.Type = prevViewWall.Type; worldCell.occupiedType = newWall.Type; CorrectWallType(worldCell, newWall); Walls.Add(newWall); } }
private void WallPreview(WorldCell worldCell) { if (Input.MouseInRect(worldCell.cellRect)) { prevViewWall.Position = new Vector2(worldCell.cellRect.X, worldCell.cellRect.Y); if (Input.KeyPressed(Keys.F) && pieceSwitch == 0) { prevViewWall.Type = "HPiece"; pieceSwitch = 1; } else if (Input.KeyPressed(Keys.F) && pieceSwitch == 1) { prevViewWall.Type = "VPiece"; pieceSwitch = 2; } else if (Input.KeyPressed(Keys.F) && pieceSwitch == 2) { prevViewWall.Type = "SECorner"; pieceSwitch = 3; } else if (Input.KeyPressed(Keys.F) && pieceSwitch == 3) { prevViewWall.Type = "NECorner"; pieceSwitch = 4; } else if (Input.KeyPressed(Keys.F) && pieceSwitch == 4) { prevViewWall.Type = "SWCorner"; pieceSwitch = 5; } else if (Input.KeyPressed(Keys.F) && pieceSwitch == 5) { prevViewWall.Type = "NWCorner"; pieceSwitch = 0; } } }
protected override void Update(GameTime gameTime) { Input.Update(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } //Fps counter elaspedTime += gameTime.ElapsedGameTime; if (elaspedTime > TimeSpan.FromSeconds(1)) { elaspedTime -= TimeSpan.FromSeconds(1); frameRate = frameCounter; frameCounter = 0; } //Fps counter switch (currentGameState) { case GameState.SplashScreen: if (splashScreenMusicPlaying) { SplashScreenMusic.Play(); splashScreenMusicPlaying = false; } colorlerp += 0.004f; if (Input.LeftMouseButtonClick()) { currentGameState = GameState.StartScreen; SplashScreenMusic.Dispose(); } break; case GameState.StartScreen: foreach (Button button in buttons) { button.Update(gameTime); } if (buttons[0].ButtonSelected && Input.LeftMouseButtonClick()) { currentGameState = GameState.Playing; } break; case GameState.Playing: #region [Input] for (int i = 0; i < worldCells.Count; i++) { WorldCell cell = worldCells[i]; cell.index = i; CreateTurretWithClick(cell); WallPreview(cell); CreateWallWithClick(cell); } foreach (Wall item in Walls) { item.Update(gameTime); } prevViewWall.Update(gameTime); #endregion GamePlayingInitialTime += (float)gameTime.ElapsedGameTime.TotalSeconds; #region level Switch while (GamePlayingInitialTime > LEVELINITIALTIME) { GamePlayingInitialTime = LEVELINITIALTIME; createLevel(level); if (Zombies.Count == 0) { DisplayLevelText = true; levelChangeTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (levelChangeTime >= LEVELCHANGETIMER || Input.KeyPressed(Keys.Space)) { created = false; level++; DisplayLevelText = false; levelChangeTime = 0; } } } #endregion HomeBase.Update(); invetory.Update(gameTime); CreateZombieWithClick(); UpdateZombiesHits(gameTime); RemoveDeadZombies(); Updateturrets(gameTime); PlayGameMusic(gameTime); UpdateBloodPoofs(gameTime); UpdateBrainDrops(gameTime); break; case GameState.Paused: break; case GameState.GameOver: break; default: break; } base.Update(gameTime); }