public void HandleBombsIntersection(Player p, BuildingHandler bh, ContentManager theContentManager) { if (p.bombs.Count > 0) { foreach (Bomb b in p.bombs) { bombRectangle = new Rectangle((int)b.X, (int)b.Y, 20, 20); //TODO: width, height if needed foreach (Building building in bh.buildings) { buildingRectangle = new Rectangle((int)building.X, (int)building.Y - building.H + 10, building.W, building.H); if (bombRectangle.Intersects(buildingRectangle)) { building.Damaged = true; p.score.AddPoints(50); p.eh.CreateExplosion("huge", new Vector2(b.X - 48, b.Y - 16), theContentManager); p.bombs.Remove(b); bombRemoved = true; } } if (bombRemoved) { bombRemoved = false; break; } } } }
public void Update(GameTimer timer, ContentManager theContentManager, PowerupHandler pu, Player player, bool soundMuted) { enemiesInLevel = (background.Period + 1) * 3; elapsedTime += (float)timer.UpdateInterval.TotalSeconds; if (elapsedTime > 45f / enemiesInLevel && readyEnemies.Count > 0) //45f = time to 4000px to pass (current background width = 2000px) { elapsedTime = 0; readyEnemies[0].Position = new Vector2(player.Position.X + random.Next(760, 810), random.Next(110, 450)); visibleEnemies.Add(readyEnemies[0]); readyEnemies.Remove(readyEnemies[0]); } foreach (Enemy e in visibleEnemies) { if (e.Position.X < player.Position.X - 100) { if (e.IsAlive && player.IsAlive) player.score.AddPoints(-5); e.IsAlive = true; e.Hitpoints = maxHealth; e.ExplosionCreated = false; e.explosionHandler.explosions.Clear(); readyEnemies.Add(e); visibleEnemies.Remove(e); break; } e.Update(timer, pu, theContentManager, player, soundMuted); } }
public void Animate(GameTimer timer, Player player) { if (player.IsAlive) this.Position += direction * velocity * (float)timer.UpdateInterval.TotalSeconds; if (this.assetName != "bomb") { if (currentFrame < animate.Length) { Source = sources[animate[currentFrame]]; currentFrame++; } else currentFrame = 0; } else { if (this.Scale < 0.75f && smallest) this.Scale += 0.6f * (float)timer.UpdateInterval.TotalSeconds; else { smallest = false; biggest = true; } if (this.Scale > 0.4f && biggest) this.Scale -= 0.6f * (float)timer.UpdateInterval.TotalSeconds; else { smallest = true; biggest = false; } } }
public EnemyHandler(Player p, Background b) { readyEnemies = new List<Enemy>(); visibleEnemies = new List<Enemy>(); player = p; background = b; }
public void Animate(GameTimer timer, Player player) { foreach (Powerup pu in powerups) { pu.Animate(timer, player); if (pu.X < -16) { powerups.Remove(pu); break; } } }
public void HandleBuildingIntersection(Player p, BuildingHandler bh) { playerRectangle = new Rectangle((int)p.X + p.W / 2, (int)p.Y + p.H / 4, p.W / 4, p.H / 2); foreach (Building b in bh.buildings) { buildingRectangle = new Rectangle((int)b.X + 5, (int)b.Y - b.H + 10, b.W - 10, b.H); if (playerRectangle.Intersects(buildingRectangle)) { b.Damaged = true; p.Hitpoints = 0; p.Crash = true; } } }
public void Scroll(GameTimer timer, Player p) { if (p.IsAlive) this.X += direction * velocity * (float)timer.UpdateInterval.TotalSeconds; #region END_OF_TEXTURE_CHECK if (this.X % clouds.Width < 0 && this.X % clouds.Width > -5f && !textureChanged) { period += 1; textureChanged = true; } if (this.X % clouds.Width < -5f && textureChanged) textureChanged = false; #endregion }
public void HandleBulletIntersections(EnemyHandler eh, Player p, ContentManager contentManager) { #region PLAYERS_BULETS foreach (Bullet b in p.bullets) { bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 3, 1); foreach (Enemy e in eh.EnemiesIter()) { if (e.IsAlive) { enemyRectangle = new Rectangle((int)e.X, (int)e.Y - 100, e.W, e.H); if (enemyRectangle.Intersects(bulletRectangle)) { e.Hitpoints -= 1; e.explosionHandler.CreateExplosion("small", new Vector2(b.X - 75, b.Y), contentManager); p.bullets.Remove(b); bulletRemoved = true; } } } if (bulletRemoved) { bulletRemoved = false; break; } } #endregion #region ENEMIES_BULLETS playerRectangle = new Rectangle((int)p.X - p.W / 2, (int)p.Y - p.H / 2, p.W, p.H); foreach (Enemy e in eh.EnemiesIter()) { foreach (Bullet b in e.bullets) { bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 3, 1); if (bulletRectangle.Intersects(playerRectangle)) { p.Hitpoints -= 1; if (p.IsAlive) e.explosionHandler.CreateExplosion("small", new Vector2(b.X - random.Next(5, 20), b.Y), contentManager); e.bullets.Remove(b); break; } } } #endregion }
public void HandlePowerupIntersections(PowerupHandler pu, Player player) { playerRectangle = new Rectangle((int)player.X - player.W / 2, (int)player.Y - player.H / 2, player.W, player.H); foreach (Powerup p in pu.powerups) { powerupRectangle = new Rectangle((int)p.X, (int)p.Y, p.W, p.H); if (playerRectangle.Intersects(powerupRectangle)) { if (p.Type == "health") { if (player.Hitpoints + 5 < player.MaxHealth) player.Hitpoints += 5; else { if (player.healthPowerups.Count < 5) { p.Source = new Rectangle(0, 0, p.W, p.H); p.Position = new Vector2(150, 438); p.Scale = 2f; player.healthPowerups.Add(p); } else player.Hitpoints = player.MaxHealth; } } else if (p.Type == "ammo") { if (player.Ammo + 50 < player.MaxAmmo) player.Ammo += 50; else { if (player.ammoPowerups.Count < 5) { p.Source = new Rectangle(0, 16, p.W * 2, p.H * 2); p.Position = new Vector2(618, 438); //TODO: test behavior on higher resolution if the game scales correctly p.Scale = 1f; player.ammoPowerups.Add(p); } else player.Ammo = player.MaxAmmo; } } else if (p.Type == "ten") { player.score.AddPoints(10); } else if (p.Type == "bomb" && player.AvailibleBombs + 1 <= 2) { player.AvailibleBombs += 1; } pu.powerups.Remove(p); break; } } }
public void HandlePlanesInterestion(EnemyHandler eh, Player p) { playerRectangle = new Rectangle((int)p.X, (int)p.Y, p.W, p.H); foreach (Enemy e in eh.EnemiesIter()) if (e.IsAlive) { enemyRectangle = new Rectangle((int)e.X, (int)e.Y - 100, e.W, e.H); if (playerRectangle.Intersects(enemyRectangle)) { e.Hitpoints = 0; p.Hitpoints -= 10; } } }
public void Update(GameTimer timer, Player player) { if (player.IsAlive) this.Position.X -= 100.0f * (float)timer.UpdateInterval.TotalSeconds; //100.0f = background velocity if (this.Damaged) this.Source = new Rectangle(0, 0, this.W, this.H); }
public void UpdateBuildings(GameTimer timer, Player player) { foreach (Building b in buildings) b.Update(timer, player); }
private void Animate(Player player) { Source = sources[animate[currentFrame] + player.Nation]; currentFrame++; if (currentFrame == animate.Length) currentFrame = 0; }
public void Update(GameTimer timer, PowerupHandler pu , ContentManager theContentManager, Player player, bool soundsMuted) { this.Position += direction * velocity * (float)timer.UpdateInterval.TotalSeconds; if (this.Hitpoints < 1 && !ExplosionCreated) { this.GeneratePowerups(pu, theContentManager); this.IsAlive = false; explosionHandler.CreateExplosion("normal", new Vector2(this.X - 47, this.Y - 87), contentManager); this.ExplosionCreated = true; player.score.AddPoints(10); } if (this.IsAlive && reloadTime == 0 && random.Next(this.Hitpoints / 2 + 1) == 1) { Bullet newBullet = new Bullet(new Vector2(this.X - 45, this.Y - 84), direction, this.Rotation); newBullet.LoadContent(contentManager); bullets.Add(newBullet); //if (!soundsMuted) // mg.Play(0.075f, 0, 0); } reloadTime += (float)timer.UpdateInterval.TotalSeconds; if (reloadTime > 0.05f) reloadTime = 0; foreach (Bullet b in bullets) { b.Update(timer); if (b.Position.X - this.Position.X > 700) { bullets.Remove(b); break; } } explosionHandler.Update(timer, player.IsAlive, soundsMuted); //player.IsAlive indicates that all explosions are moving towards the player as long palyer is alive and background is scrolling this.Animate(player); }