public override void Update(GameTime gameTime) { Player p = GetNearestPlayer(); gunTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (p != null && Vector2.Distance(p.Position, Position) > 300) { float a = GetAngleBetweenSprite(p); Velocity = new Vector2((float)Math.Cos(a), (float)Math.Sin(a)) * 400f; } if (p != null && gunTimer > 600) { gunTimer = 0; float a = GetAngleBetweenSprite(p); Vector2 vel = new Vector2((float)Math.Cos(a), (float)Math.Sin(a)) * (float)(250f + rand.NextDouble() * 100); Bullet b = new LinearBullet(EntitySide.ENEMY, 3000f, vel) { Texture = BulletTexture, Size = new Point(16, 16), Position = Position, Color = Color.White, }; Bullets.Add(b); } Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity = Vector2.Zero; base.Update(gameTime); }
/// <summary> /// Updates the logic of the enemy. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { base.Update(gameTime); gunTimer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; pathTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; float x = (isGoingRight) ? 1 : -1; Velocity = new Vector2(x * 2, (float)Math.Sin(pathTimer / 500)); Rotation = GetAngleBetweenSprite(GetNearestPlayer()); if (gunTimer < 0) { gunTimer = 500f + rand.Next(0, 1500); // shoot float angle = Rotation + (float)rand.NextDouble() * 0.4f - 0.2f; LinearBullet bullet = new LinearBullet(EntitySide.ENEMY, 10000f, new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * 900f) { Texture = BulletTexture, Position = Position, Size = new Point(16, 9), Color = Color.Red, }; getBullets().Add(bullet); } Position += Velocity * 140f * (float)gameTime.ElapsedGameTime.TotalSeconds; if (isGoingRight) { if (Position.X > ScreenManager.GetInstance().Width + Texture.Width / 2 * SCALE) { IsActive = false; } } else { if (Position.X < -Texture.Width / 2 * SCALE) { IsActive = false; } } }
/// <summary> /// Updates the logic of the vortex enemy. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { base.Update(gameTime); bulletTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; spinTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; ttl -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (ttl < 0) { IsActive = false; } Rotation = spinTimer * MathHelper.TwoPi / spinPeriod; if (bulletTimer > 500f) { bulletTimer = 0; for (int i = 0; i < spin; i++) { float a = Rotation + i * MathHelper.TwoPi / spin; float xD = (float)Math.Cos(a); float yD = (float)Math.Sin(a); Vector2 dir = new Vector2(xD, yD) * 500f; LinearBullet b = new LinearBullet(EntitySide.ENEMY, 6000f, dir) { Position = Position, Size = new Point(10, 6), Texture = BulletTexture, Color = Color.Red, }; getBullets().Add(b); } } Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; }
/// <summary> /// Updates the logic and conditional checking for the test boss. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds; stageTimer += dt; bulletTimer += dt; float theta = stageTimer / 1000f; //Velocity = new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)) * 100f; if (bulletTimer > 500f) { bulletTimer = 0f; for (int i = 0; i < 4; i++) { Player p = GetPlayer(i); if (p != null) { float angle = GetAngleBetweenSprite(p); Vector2 vel = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * 500f; LinearBullet b = new LinearBullet(EntitySide.ENEMY, 7000f, vel) { Texture = BulletTexture, Position = Position, Size = new Point(15, 8), Color = Color.YellowGreen, }; CurrentStage.AddBullet(b); } } } vortexSpawnTimer -= dt; if ((float)(Health) / MAX_HEALTH < 0.5f && vortexSpawnTimer <= 0) { vortexSpawnTimer = 3000f; int Swidth = ScreenManager.GetInstance().Width; int Sheight = ScreenManager.GetInstance().Height; VortexEnemy en = new VortexEnemy(CurrentStage.Players, 4, 4000f, 10000f) { Velocity = new Vector2(0, -200f), Position = new Vector2(200, Sheight), Texture = vortexEnemyTexture, BulletTexture = Blank, Size = new Point(vortexEnemyTexture.Width * SCALE, vortexEnemyTexture.Height * SCALE), }; VortexEnemy en2 = new VortexEnemy(CurrentStage.Players, 4, 4000f, 10000f) { Velocity = new Vector2(0, -200f), Position = new Vector2(Swidth - 200, Sheight), Texture = vortexEnemyTexture, BulletTexture = Blank, Size = new Point(vortexEnemyTexture.Width * SCALE, vortexEnemyTexture.Height * SCALE), }; en.SetBullets(Bullets); en2.SetBullets(Bullets); CurrentStage.AddEnemy(en); CurrentStage.AddEnemy(en2); } //Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; //Velocity = Vector2.Zero; // no velocity, position is fixed int width = ScreenManager.GetInstance().Width; int height = ScreenManager.GetInstance().Height; Position = new Vector2((float)(Math.Cos(theta) + 1) / 2 * width * 0.75f + 0.125f * width, (float)(Math.Sin(theta) + 1) / 2 * height / 4 + 200); base.Update(gameTime); }
/// <summary> /// Updates the logic and conditional checking for the test boss. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds; stageTimer += dt; bulletTimer += dt; sunBeamSafeTimer -= dt; float theta = stageTimer / 1000f; //Velocity = new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)) * 100f; if (sunBeamSafeTimer < 0 && stageTimer > 5000f) { sunBeamChargeTimer -= dt; if (sunBeamChargeTimer <= 0) { // fire sunBeamTimer -= dt; Vector2 v = (isVertical) ? new Vector2(0, -400f) : new Vector2(400, 0); for (int i = 1; i <= 4; i++) { Vector2 pos = (isVertical) ? new Vector2(i * ScreenManager.GetInstance().Width / 5, ScreenManager.GetInstance().Height) : new Vector2(0, i * ScreenManager.GetInstance().Height / 5); LinearBullet b = new LinearBullet(EntitySide.ENEMY, 7000f, v) { Texture = BulletTexture, Position = pos, Size = new Point(30, 50), Color = Color.LightGoldenrodYellow, }; CurrentStage.AddBullet(b); } if (sunBeamTimer <= 0) { sunBeamSafeTimer = SUN_BEAM_SAFE_TIMER; sunBeamTimer = SUN_BEAM_FIRE_TIMER; sunBeamChargeTimer = SUN_BEAM_CHARGE_TIMER; isVertical = rand.Next(0, 2) == 0; } } } if (stageTimer > 12000f) { sunSpawnTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (sunSpawnTimer > 5000) { sunSpawnTimer = 0f; int rad = 100; for (int i = 0; i < CurrentStage.GetPlayerCount(); i++) { Vector2 newPos = new Vector2(Position.X + rand.Next(-rad, rad), Position.Y + rand.Next(-rad, rad)); MiniSun s = new MiniSun(Players) { BulletTexture = sunBullet, Position = newPos, Health = 3, Color = Color.White, Texture = Texture, Size = new Point(Texture.Width * SCALE / 3, Texture.Height * SCALE / 3), }; CurrentStage.AddEnemy(s); } } } if (bulletTimer > 400f) { bulletTimer = 0f; for (int i = 0; i < 4; i++) { Player p = GetPlayer(i); if (p != null) { float angle = GetAngleBetweenSprite(p); Vector2 vel = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * 500f; LinearBullet b = new LinearBullet(EntitySide.ENEMY, 7000f, vel) { Texture = sunBullet, Position = Position, Size = new Point(32, 32), Color = Color.White, }; CurrentStage.AddBullet(b); } } } //Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; //Velocity = Vector2.Zero; // no velocity, position is fixed int width = ScreenManager.GetInstance().Width; int height = ScreenManager.GetInstance().Height; Position = new Vector2((float)(Math.Cos(theta) + 1) / 2 * width * 0.75f + 0.125f * width, (float)(Math.Sin(theta) + 1) / 2 * height / 4 + 200); base.Update(gameTime); }
/// <summary> /// Updates the logic and conditional checking for the test boss. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds; stageTimer += dt; bulletTimer += dt; sinSpawner -= dt; sinSpawner2 -= dt; float theta = stageTimer / 1000f; //Velocity = new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)) * 100f; if (bulletTimer > 300f) { bulletTimer = 0f; for (int i = 0; i < 4; i++) { Player p = GetPlayer(i); if (p == null) { p = CurrentStage.GetRandomPlayer(); } float rot = MathHelper.PiOver2 * i + Rotation; Vector2 offset = new Vector2((float)(Math.Cos(rot)), (float)(Math.Sin(rot))) * 220f; Vector2 pos = Position + offset; float angle = GetAngleBetweenSprite(p, pos); Vector2 vel = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * 800f; LinearBullet b = new LinearBullet(EntitySide.ENEMY, 7000f, vel) { Texture = BulletTexture, Position = pos, Size = new Point(18, 8), Color = Color.OrangeRed, }; CurrentStage.AddBullet(b); } } vortexSpawnTimer -= dt; if ((float)(Health) / MAX_HEALTH < 0.75f && vortexSpawnTimer <= 0) { vortexSpawnTimer = 2500f; int Swidth = ScreenManager.GetInstance().Width; int Sheight = ScreenManager.GetInstance().Height + 200; VortexEnemy en = new VortexEnemy(CurrentStage.Players, 4, 4000f, 10000f) { Velocity = new Vector2(0, -200f), Position = new Vector2(200, Sheight), Texture = vortexEnemyTexture, BulletTexture = Blank, Size = new Point(vortexEnemyTexture.Width * 3, vortexEnemyTexture.Height * 3), }; VortexEnemy en2 = new VortexEnemy(CurrentStage.Players, 4, 4000f, 10000f) { Velocity = new Vector2(0, -200f), Position = new Vector2(Swidth - 200, Sheight), Texture = vortexEnemyTexture, BulletTexture = Blank, Size = new Point(vortexEnemyTexture.Width * 3, vortexEnemyTexture.Height * 3), }; CurrentStage.AddEnemy(en); CurrentStage.AddEnemy(en2); } if ((float)Health / MAX_HEALTH < 0.5f && sinSpawner <= 0) { sinSpawner = 1750f; CurrentStage.SpawnSinEnemy(new Vector2(ScreenManager.GetInstance().Width + 100, 300), false); } if ((float)Health / MAX_HEALTH <= 0.3f && sinSpawner2 <= 0) { sinSpawner2 = 1750f; CurrentStage.SpawnInvisSinEnemy(new Vector2(-100, 300), true); } if (opacity < 1) { opacity += (float)gameTime.ElapsedGameTime.TotalSeconds / 3; } //Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; //Velocity = Vector2.Zero; // no velocity, position is fixed int width = ScreenManager.GetInstance().Width; int height = ScreenManager.GetInstance().Height; Position = new Vector2((float)(Math.Cos(theta) + 1) / 2 * width * 0.75f + 0.125f * width, (float)(Math.Sin(theta) + 1) / 2 * height / 4 + 200); Rotation += dt / 3000 * MathHelper.TwoPi; base.Update(gameTime); }
/// <summary> /// Updates the <c>Player</c>. /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds; invulnTimer -= dt; rocketTimer -= dt; InputManager im = InputManager.Instance; Vector2 velocity = GamePad.GetState(index).ThumbSticks.Left; velocity.Y *= -1; if (ScreenManager.DEV_MODE) { if (im.KeyDown(Keys.W)) { velocity.Y = -1; } else if (im.KeyDown(Keys.S)) { velocity.Y = 1; } if (im.KeyDown(Keys.A)) { velocity.X = -1; } else if (im.KeyDown(Keys.D)) { velocity.X = 1; } } if (ScreenManager.DEV_MODE && velocity.Length() != 0) { velocity.Normalize(); } bulletTimer += dt; shieldTimer -= dt; shieldRechargeTimer -= dt; Velocity = velocity; Velocity *= SPEED; if (invulnTimer <= 0) { CheckBulletCollision(); } else { float vMag = Math.Max(0, (invulnTimer - INVULNERABILITY_TIMESTAMP / 2) / INVULNERABILITY_TIMESTAMP); GamePad.SetVibration(index, vMag, vMag); } if (shieldTimer < 0f && shieldRechargeTimer <= 0 && im.IsButtonDown(Buttons.A, (int)index) || (ScreenManager.DEV_MODE && im.KeyPressed(Keys.Q))) { shieldTimer = 3000f; shieldRechargeTimer = shieldTimer * 2f; } // Shoots bullets if (bulletTimer > 450f && (im.IsButtonDown(Buttons.RightTrigger, (int)index) || (ScreenManager.DEV_MODE && im.KeyDown(Keys.Space)))) { //int shootFx = rand.Next(0, 3); shootSound.Play(1f, 0f, 0f); bulletTimer = 0; SinBullet b = new SinBullet(EntitySide.PLAYER, 7000f, 800, true, true); SinBullet b2 = new SinBullet(EntitySide.PLAYER, 7000f, 800, true, false); LinearBullet b3 = new LinearBullet(EntitySide.PLAYER, 7000f, new Vector2(0, -800)); Vector2 offsetVel = Velocity / 4f; b.Texture = BulletTexture; b.Size = new Point(8, 7); b.Position = Position; b.InitVelocity = offsetVel; b.Color = Color.SkyBlue; b2.Texture = BulletTexture; b2.Size = new Point(8, 7); b2.InitVelocity = offsetVel; b2.Position = Position; b2.Color = Color.SkyBlue; b3.Texture = BulletTexture; b3.InitVelocity = offsetVel; b3.Size = new Point(8, 8); b3.Position = Position; b3.Color = Color.SkyBlue; bullets.Add(b); bullets.Add(b2); bullets.Add(b3); } ; // Fire rocket if (im.IsButtonDown(Buttons.LeftTrigger, (int)index) && rocketTimer < 0) { rocketTimer = 900f; List <Sprite> sprites = new List <Sprite>(); sprites.AddRange(GameScreen.CurrentStage.Enemies); Rocket r = new Rocket(sprites, blank, rocketLaunch, rocketImpact) { Texture = RocketTexture, Explosion = Explosion, Color = Color.White, Position = Position, Size = new Point(RocketTexture.Width, RocketTexture.Height), }; CurrentStage.AddRocket(r); } // inverts the y-axis to be NOT INVERTED if (Velocity.Length() > 0) { Rotation = (float)Math.Atan2(velocity.Y, velocity.X); } UpdatePosition(gameTime); }