public override void Update(GameTime gameTime) { Vector2 start = new Vector2(Position.X, Position.Y); Vector2 end = new Vector2(Ship.Instance.Position.X, Ship.Instance.Position.Y); float distance = Vector2.Distance(start, end); Vector2 directionV2 = Vector2.Normalize(end - start); Vector3 direction = new Vector3(directionV2.X, directionV2.Y, 0); //Shooting if (shootCooldown <= (1.6f * (bosshealth / 320.0f) + 0.6f)) { shootCooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { bulletpos = Position + new Vector3(0, 2, 0); diffuseC = Color.Purple.ToVector3(); ambientC = Color.Red.ToVector3(); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 8, 80, direction)); shootCooldown = 0; Game1.EnemyShoot.Play(0.2f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); } Orientation = (float)Math.PI * 90 / 180 - (float)Math.Atan2(direction.X, direction.Y); }
public void Update(GameTime gameTime) { if ((health == 0) && (ending == false)) { ending = true; Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); ExplosionManager.Add(new Explosion(Ship.Instance.Position, 0, 63)); Ship.Instance.IsExpired = true; } if (ending == true) { if (endtime <= 3.0f) { endtime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } }
public override void Update(GameTime gameTime) { if (isEntering == false) { //Random Movement if (moveCooldown <= moveDur) { moveCooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { moveDur = RandomDuration(gameTime); moveDir = RandomDirection(gameTime); moveCooldown = 0; } Position = Move(Position); } else { MoveCentre(gameTime, Position); } //Shooting if (shootCooldown <= 0.7f) { shootCooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { bulletpos = Position + new Vector3(0, 2, 0); diffuseC = Color.Purple.ToVector3(); ambientC = Color.Red.ToVector3(); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 8, 80, new Vector3(0, 1, 0))); shootCooldown = 0; Game1.EnemyShoot.Play(0.2f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); } //turning AngleY = Rotate(AngleY, moveDir.X / 50); }
static void HandleCollisions() { // handle collisions between bullets and enemy1 for (int i = 0; i < enemy1.Count; i++) { for (int j = 0; j < playerbullets.Count; j++) { if (IsColliding(enemy1[i], playerbullets[j])) { enemy1[i].health--; playerbullets[j].IsExpired = true; Game1.PlayerShoot.Play(0.4f, 0.8f, 0); ExplosionManager.Add(new Explosion(enemy1[i].Position, 0, 2)); if (enemy1[i].health <= 0) { Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); ExplosionManager.Add(new Explosion(enemy1[i].Position, 0, 63)); enemy1[i].IsExpired = true; } } } } // handle collisions between bullets and enemy2 for (int i = 0; i < enemy2.Count; i++) { for (int j = 0; j < playerbullets.Count; j++) { if (IsColliding(enemy2[i], playerbullets[j])) { enemy2[i].health--; playerbullets[j].IsExpired = true; Game1.PlayerShoot.Play(0.4f, 0.8f, 0); ExplosionManager.Add(new Explosion(enemy2[i].Position, 0, 2)); if (enemy2[i].health <= 0) { Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); ExplosionManager.Add(new Explosion(enemy2[i].Position, 0, 63)); enemy2[i].IsExpired = true; } } } } // handle collisions between bullets and player for (int i = 0; i < enemybullets.Count; i++) { if (IsColliding(Ship.Instance, enemybullets[i])) { Healthbar.Hit(); enemybullets[i].IsExpired = true; Game1.EnemyShoot.Play(0.4f, -0.8f, 0); } } // handle collisions between bullets and boss shield for (int i = 0; i < shield.Count; i++) { for (int j = 0; j < playerbullets.Count; j++) { if (IsColliding(shield[i], playerbullets[j])) { shield[i].health--; boss[0].health--; playerbullets[j].IsExpired = true; Game1.PlayerShoot.Play(0.4f, 0.8f, 0); ExplosionManager.Add(new Explosion(shield[i].Position, 0, 2)); if (shield[i].health <= 0) { Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); ExplosionManager.Add(new Explosion(shield[i].Position, 0, 63)); shield[i].IsExpired = true; } } } } // handle collisions between bullets and boss core for (int i = 0; i < core.Count; i++) { for (int j = 0; j < playerbullets.Count; j++) { if (IsColliding(core[i], playerbullets[j])) { core[i].health--; boss[0].health--; playerbullets[j].IsExpired = true; Game1.PlayerShoot.Play(0.4f, 0.8f, 0); ExplosionManager.Add(new Explosion(core[i].Position, 0, 2)); if (core[i].health <= 0) { Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); ExplosionManager.Add(new Explosion(core[i].Position, 0, 63)); core[i].IsExpired = true; } } } } //remove boss when cores destroyed if (core.Count > 0) { bossSpawned = true; } else if ((core.Count == 0) && (bossSpawned == true)) { for (int i = 0; i < turret.Count; i++) { turret[i].IsExpired = true; } ExplosionManager.Add(new Explosion(boss[0].Position, 0, 63)); boss[0].IsExpired = true; bossSpawned = false; } }
public override void Update(GameTime gameTime) { KeyboardState state = Keyboard.GetState(); if (state.IsKeyDown(Keys.D)) { xPos = Movement(xPos, -2, 0); angle = Rotate(angle, 0 - (float)gameTime.ElapsedGameTime.TotalSeconds * 2); } else if (state.IsKeyDown(Keys.A)) { xPos = Movement(xPos, 2, 0); angle = Rotate(angle, (float)gameTime.ElapsedGameTime.TotalSeconds * 2); } else { if (angle > 0) { angle = Rotate(angle, 0 - (float)gameTime.ElapsedGameTime.TotalSeconds * 2); } else if (angle < 0) { angle = angle = Rotate(angle, (float)gameTime.ElapsedGameTime.TotalSeconds * 2); } } if ((xPos > 50) && (fade > 0)) { Healthbar.transparent -= 0.07f; fade--; } else if (xPos < 50) { Healthbar.transparent = 1; fade = 10; } if (state.IsKeyDown(Keys.S)) { yPos = Movement(yPos, 2, 1); } else if (state.IsKeyDown(Keys.W)) { yPos = Movement(yPos, -2, 1); } if (state.IsKeyDown(Keys.Space)) { if (cooldown <= 0.1f) { cooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { bulletpos = Position + new Vector3(4, -2, 0); diffuseC = Color.DarkCyan.ToVector3(); ambientC = Color.Blue.ToVector3(); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 4, 150, new Vector3(0, -1, 0))); bulletpos = Position + new Vector3(-4, -2, 0); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 4, 150, new Vector3(0, -1, 0))); cooldown = 0; Game1.PlayerShoot.Play(0.15f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); } } Position = new Vector3(0 + xPos, 55 + yPos, 20); AngleY = angle; }
public override void Update(GameTime gameTime) { if (isEntering == false) { //Random Movement if (moveCooldown <= moveDur) { moveCooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { moveDur = RandomDuration(gameTime); moveDir = RandomDirection(gameTime); moveCooldown = 0; } Position = Move(Position); } else { MoveCentre(gameTime, Position); } Vector2 start = new Vector2(Position.X, Position.Y); Vector2 end = new Vector2(Ship.Instance.Position.X, Ship.Instance.Position.Y); float distance = Vector2.Distance(start, end); Vector2 directionV2 = Vector2.Normalize(end - start); Vector3 direction = new Vector3(directionV2.X, directionV2.Y, 0); //Shooting if (shootCooldown <= 1.5f) { shootCooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { if (shootCooldown2 < 0.1f) { shootCooldown2 += (float)gameTime.ElapsedGameTime.TotalSeconds; } else if (shotcount > 0) { bulletpos = Position + new Vector3(0, 6, 0); diffuseC = Color.Purple.ToVector3(); ambientC = Color.Red.ToVector3(); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 8, 80, direction)); shootCooldown2 = 0; shotcount--; Game1.EnemyShoot.Play(0.2f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); } else { shotcount = 3; shootCooldown = 0; } } //turning AngleY = Rotate(AngleY, moveDir.X / 25); Orientation = (float)Math.PI * 90 / 180 - (float)Math.Atan2(direction.X, direction.Y); }
public override void Update(GameTime gameTime) { turret1.bosshealth = health; turret2.bosshealth = health; if (isEntering == false) { //Random Movement if (moveCooldown <= moveDur) { moveCooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { moveDur = RandomDuration(gameTime); moveDir = RandomDirection(gameTime); moveCooldown = 0; } Position = Move(Position); } else { MoveCentre(gameTime, Position); } Vector2 start = new Vector2(Position.Y, Position.Z); Vector2 end = new Vector2(Ship.Instance.Position.Y, Ship.Instance.Position.Z); float distance = Vector2.Distance(start, end); Vector2 directionV2 = Vector2.Normalize(end - start); Vector3 direction = new Vector3(0, directionV2.X, directionV2.Y); //Shooting if (shootCooldown <= (0.8f * (health / 320.0f) + 0.3f)) { shootCooldown += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { diffuseC = Color.Purple.ToVector3(); ambientC = Color.Red.ToVector3(); bulletpos = Position + new Vector3(-35, 15, 22); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 8, 80, direction)); bulletpos = Position + new Vector3(-45, 15, 22); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 8, 80, direction)); bulletpos = Position + new Vector3(31, 19, 22); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 8, 80, direction)); bulletpos = Position + new Vector3(41, 19, 22); EntityManager.Add(new Bullet(bulletpos, diffuseC, ambientC, 8, 80, direction)); shootCooldown = 0; Game1.EnemyShoot.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0); } core1.Position = Position + new Vector3(-46, 14, 2); core2.Position = Position + new Vector3(-19, 23, 2); core3.Position = Position + new Vector3(14, 23, 2); core4.Position = Position + new Vector3(44, 14, 2); turret1.Position = Position + new Vector3(6, 17, 22); turret2.Position = Position + new Vector3(-9, 17, 22); shield1.Position = Position + new Vector3(-48, 18, 2); shield2.Position = Position + new Vector3(-18, 27, 5); shield3.Position = Position + new Vector3(14, 28, 5); shield4.Position = Position + new Vector3(47, 19, 4); }