private static void checkExplosionSplashDamage(Vector2 location) { int explosionSplashRadius = 40; foreach (Enemy enemy in EnemyManager.Enemies) { if (!enemy.Destroyed) { if (enemy.EnemyBase.IsCircleColliding(location, explosionSplashRadius)) { enemy.Destroyed = true; GameManager.Score += 10; EffectsManager.AddExplosion(enemy.EnemyBase.WorldCenter, Vector2.Zero); } } } Point a = Game1.ConvertToGrid(new Point((int)location.X, (int)location.Y)); if (TileMap.mapSquares[a.X, a.Y] == TileMap.WeakWallTileEnd) { } }
private static void checkShotEnemyImpacts(Sprite shot) { if (shot.Expired) { return; } foreach (Enemy enemy in EnemyManager.Enemies) { if (!enemy.Destroyed) { if (shot.IsCircleColliding( enemy.EnemyBase.WorldCenter, enemy.EnemyBase.CollisionRadius)) { shot.Expired = true; enemy.Destroyed = true; GameManager.Score += 10; EffectsManager.AddExplosion( enemy.EnemyBase.WorldCenter, enemy.EnemyBase.Velocity / 30); } } } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); spriteSheet = Content.Load <Texture2D>(@"Textures\SpriteSheetNew");//sprite sheet src titleScreen = Content.Load <Texture2D>(@"Textures\TitleScreen"); defaultFont = Content.Load <SpriteFont>(@"Fonts\defaultFont"); //add instances of sounds to SoundInstance list (older at top of list) soundEffectBank.Add("bang", Content.Load <SoundEffect>(@"Audio\bang").CreateInstance()); soundEffectBank.Add("boom", Content.Load <SoundEffect>(@"Audio\boom").CreateInstance()); soundEffectBank.Add("death", Content.Load <SoundEffect>(@"Audio\death").CreateInstance()); //to play sounds, utilize: //Game1.soundEffectBank["SoundID"].Play(); TileMap.Initialize(spriteSheet); Player.Initialize(spriteSheet, new Rectangle(0, 64, 32, 32), 6, new Rectangle(0, 96, 32, 32), 1, new Vector2(32, 32)); Camera.WorldRectangle = new Rectangle(0, 0, 1600, 1600); Camera.ViewPortWidth = 800; Camera.ViewPortHeight = 600; EffectsManager.Initialize( spriteSheet, new Rectangle(0, 288, 2, 2), new Rectangle(0, 256, 32, 32), 3); WeaponManager.Texture = spriteSheet; EnemyManager.Initialize(spriteSheet, new Rectangle(0, 64, 32, 32));//set enemy sprite }
private static void createLargeExplosion(Vector2 location) { Game1.soundEffectBank["boom"].Play(); EffectsManager.AddLargeExplosion(location); EffectsManager.AddLargeExplosion(location + new Vector2(-10, -10)); EffectsManager.AddLargeExplosion(location + new Vector2(-10, 10)); EffectsManager.AddLargeExplosion(location + new Vector2(10, 10)); EffectsManager.AddLargeExplosion(location + new Vector2(10, -10)); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } switch (gameState) { case GameStates.TitleScreen: if ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed) || (Keyboard.GetState().IsKeyDown(Keys.Space))) { GameManager.StartNewGame(); gameState = GameStates.Playing; } break; case GameStates.Playing: Player.Update(gameTime); WeaponManager.Update(gameTime); EnemyManager.Update(gameTime); EffectsManager.Update(gameTime); //!when all enemies killed go to next area (unlock door) //if ( == 0) gameState = GameStates.WaveComplete;//! break; case GameStates.WaveComplete: waveCompleteTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (waveCompleteTimer > waveCompleteDelay) { GameManager.StartNewWave(); gameState = GameStates.Playing; waveCompleteTimer = 0.0f; } break; case GameStates.GameOver: gameOverTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (gameOverTimer > gameOverDelay) { gameState = GameStates.TitleScreen; gameOverTimer = 0.0f; } break; } Window.Title = "Player Square:" + ConvertToGrid(Player.BaseSprite.WorldLocation).ToString();//!player location base.Update(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); if (gameState == GameStates.TitleScreen) { spriteBatch.Draw(titleScreen, new Rectangle(0, 0, 800, 600), Color.White); } if ((gameState == GameStates.Playing) || (gameState == GameStates.WaveComplete) || (gameState == GameStates.GameOver)) { TileMap.Draw(spriteBatch); WeaponManager.Draw(spriteBatch, RandomColor()); Player.Draw(spriteBatch); EnemyManager.Draw(spriteBatch); EffectsManager.Draw(spriteBatch, RandomColor()); checkPlayerDeath(); spriteBatch.DrawString(defaultFont, "Score: " + GameManager.Score.ToString(), new Vector2(30, 5), Color.White); //spriteBatch.DrawString(defaultFont,"Terminals Remaining: " + GoalManager.ActiveTerminals, new Vector2(520, 5), Color.White); } if (gameState == GameStates.WaveComplete) { spriteBatch.DrawString(defaultFont, "Beginning Wave " + (GameManager.CurrentWave + 1).ToString(), new Vector2(300, 300), Color.White); } if (gameState == GameStates.GameOver) { spriteBatch.DrawString(defaultFont, "G A M E O V E R!", new Vector2(300, 300), Color.White); } spriteBatch.End(); base.Draw(gameTime); }
private static void checkShotWallImpacts(Sprite shot) { if (shot.Expired) { return; } if (TileMap.IsWallTile(TileMap.GetSquareAtPixel(shot.WorldCenter)))//! { if (bouncesLeft > 0) { //Ricochet shots if (shot.Velocity.Y < 0 && shot.Velocity.X > 0) { shot.Velocity *= new Vector2(-1, -1); } if (shot.Velocity.Y < 0 && shot.Velocity.X < 0) { shot.Velocity *= new Vector2(-1, 1); } if (shot.Velocity.Y > 0 && shot.Velocity.X > 0) { shot.Velocity *= new Vector2(1, -1); } if (shot.Velocity.Y > 0 && shot.Velocity.X < 0) { shot.Velocity *= new Vector2(-1, 1); } else { shot.Velocity *= new Vector2(-1, -1); } bouncesLeft--; } else if (bouncesLeft <= 0) { shot.Expired = true; //Expire the shot //Add a new Spark effect at the location of the shot EffectsManager.AddSparksEffect(shot.WorldCenter, shot.Velocity); } } }