public override void Update(GameTime gameTime, Map gameMap) { if (Helper.Random.Next(10) == 0) { ParticleController.Instance.Add(Position + new Vector2(0, 5), new Vector2(Helper.RandomFloat(-0.1f, 0.1f), 0f), 100, 3000, 1000, true, true, new Rectangle(0, 0, 2, 2), new Color(new Vector3(1f, 0f, 0f) * (0.25f + Helper.RandomFloat(0.5f))), part => { ParticleFunctions.FadeInOut(part); if (part.Position.Y > 260) { part.State = ParticleState.Done; } }, 1f, 0f, 0f, 1, ParticleBlend.Alpha); } if (Helper.Random.Next(200) == 0) { if (Ship.Instance.Position.Y <= 260) { AudioController.PlaySFX("laser", 1f, -0.1f, 0.1f, Camera.Instance, Position); } ProjectileController.Instance.Spawn(entity => { ((Projectile)entity).Type = ProjectileType.ManOWarLaser; ((Projectile)entity).SourceRect = new Rectangle(0, 158, 23, 2); entity.HitBox = new Rectangle(0, 0, 23, 2); ((Projectile)entity).Life = 2000; ((Projectile)entity).EnemyOwner = true; ((Projectile)entity).Damage = 5f; entity.Speed = new Vector2(_faceDir * 5f, 0f); entity.Position = Position + new Vector2(_faceDir * 20, -2); }); } if (Helper.Random.Next(300) == 0 && GameController.Wave >= 7) { ProjectileController.Instance.Spawn(entity => { ((Projectile)entity).Type = ProjectileType.Bomb; ((Projectile)entity).SourceRect = new Rectangle(16, 0, 8, 8); ((Projectile)entity).Life = 5000; ((Projectile)entity).Scale = 0.5f; ((Projectile)entity).EnemyOwner = true; ((Projectile)entity).Damage = 10f; entity.Speed = new Vector2(1f * _faceDir, 0f); entity.Position = Position + new Vector2(0, 5); }); } base.Update(gameTime, gameMap); }
public void Die() { Life = 0f; Active = false; engineLoop.Stop(); gunLoop.Stop(); AudioController.PlaySFX("shipexplosion", 1f, 0f, 0f); for (float a = 0f; a <= MathHelper.TwoPi; a += 0.1f) { Vector2 loc = Helper.PointOnCircle(ref Position, 7, a); Vector2 speed = loc - Position; speed.Normalize(); Color c = new Color(new Vector3(1.0f, (float)Helper.Random.NextDouble(), 0.0f)) * (0.7f + ((float)Helper.Random.NextDouble() * 0.3f)); ParticleController.Instance.Add(loc, speed * Helper.RandomFloat(1f, 3f), 100, 3000, 1000, true, true, new Rectangle(0, 0, 2, 2), c, part => { ParticleFunctions.FadeInOut(part); }, 1f, 0f, 0f, 1, ParticleBlend.Additive); loc = Helper.PointOnCircle(ref Position, 3, a); speed = loc - Position; speed.Normalize(); c = new Color(new Vector3(1.0f, (float)Helper.Random.NextDouble(), 0.0f)) * (0.7f + ((float)Helper.Random.NextDouble() * 0.3f)); ParticleController.Instance.Add(loc, speed * Helper.RandomFloat(1f, 3f), 100, 3000, 1000, true, true, new Rectangle(0, 0, 2, 2), c, part => { ParticleFunctions.FadeInOut(part); }, 1f, 0f, 0f, 1, ParticleBlend.Additive); } }
public override void Update(GameTime gameTime, Map gameMap) { if (_hitAlpha > 0f) { _hitAlpha -= 0.1f; } _idleAnim.Update(gameTime); _hitAnim.Update(gameTime); if (!(this is Gorger) && !(this is Lunger) && !(this is Flyer) && !(this is Boss)) { if (Speed.X <= 0f) { _faceDir = -1; } else { _faceDir = 1; } } if (!(this is Boss)) { CheckMapCollisions(gameMap); } if (Life <= 0f) { Die(); } if (Position.Y > (gameMap.Height * gameMap.TileHeight)) { Die(); } if (_underWater) { if (Position.Y < 260) { AudioController.PlaySFX("water_leave", 1f, -0.1f, 0.1f, Camera.Instance, Position); _underWater = false; for (int i = 0; i < 30; i++) { Vector2 pos = new Vector2(Helper.RandomFloat(-5f, 5f), 0f); Color col = Color.Lerp(new Color(0, 81, 147), new Color(211, 234, 254), Helper.RandomFloat(0f, 1f)); ParticleController.Instance.Add(Position + pos, (pos * 0.1f) + new Vector2(Speed.X, Speed.Y * Helper.RandomFloat(0.25f, 2f)), 0, 2000, 500, true, true, new Rectangle(0, 0, 3, 3), col, particle => { ParticleFunctions.FadeInOut(particle); if (particle.Position.Y > 260) { particle.State = ParticleState.Done; } }, 1f, 0f, Helper.RandomFloat(-0.1f, 0.1f), 1, ParticleBlend.Alpha); } } } else if (Position.Y > 260) { _underWater = true; AudioController.PlaySFX("water_enter", 1f, -0.1f, 0.1f, Camera.Instance, Position); } base.Update(gameTime, gameMap); }
public virtual void Die() { Active = false; AudioController.PlaySFX("explosion", 1f, -0.1f, 0.1f, Camera.Instance, Position); for (float a = 0f; a <= MathHelper.TwoPi; a += 0.1f) { Vector2 loc = Helper.PointOnCircle(ref Position, 7, a); Vector2 speed = loc - Position; speed.Normalize(); ParticleController.Instance.Add(loc, speed * Helper.RandomFloat(1f, 3f), 100, 3000, 1000, true, true, new Rectangle(0, 0, 2, 2), new Color(new Vector3(1f, 0f, 0f) * (0.25f + Helper.RandomFloat(0.5f))), part => { ParticleFunctions.FadeInOut(part); }, 1f, 0f, 0f, 1, ParticleBlend.Alpha); loc = Helper.PointOnCircle(ref Position, 3, a); speed = loc - Position; speed.Normalize(); ParticleController.Instance.Add(loc, speed * Helper.RandomFloat(1f, 3f), 100, 3000, 1000, true, true, new Rectangle(0, 0, 2, 2), new Color(new Vector3(1f, 0f, 0f) * (0.25f + Helper.RandomFloat(0.5f))), part => { ParticleFunctions.FadeInOut(part); }, 1f, 0f, 0f, 1, ParticleBlend.Alpha); } if (Ship.Instance.PowerUpLevel < 4) { int amount = 3 - Ship.Instance.PowerUpLevel; if (amount <= 0) { amount = 1; } for (int i = 0; i < amount; i++) { PowerupController.Instance.Spawn(pup => { pup.Position = Position; pup.Speed = new Vector2(Helper.RandomFloat(-0.5f, 0.5f), Helper.RandomFloat(-0.5f, 0.5f)); }); } } Ship.Instance.AddScore(); }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (otherScreenHasFocus || IsExiting) { return; } //xpos++; //if (xpos == 320*3) xpos = 0; playerShip.Update(gameTime, map); waterLevel = 260; waterParallax.Position.Y = waterLevel; underwaterBGParallax.Position.Y = waterLevel + 20; if (playerShip.Position.X < 0f) { playerShip.Position.X = (map.TileWidth * map.Width) + playerShip.Speed.X; camera.Position.X = (playerShip.Position.X + playerShip.Speed.X * 20f) - (camera.Target.X - camera.Position.X); //particleController.Wrap((map.TileWidth*map.Width)); //projectileController.Wrap((map.TileWidth * map.Width)); } if (playerShip.Position.X >= (map.TileWidth * map.Width)) { playerShip.Position.X = 0f + playerShip.Speed.X; camera.Position.X = (playerShip.Position.X + playerShip.Speed.X * 20f) - (camera.Target.X - camera.Position.X); //particleController.Wrap(-(map.TileWidth * map.Width)); //projectileController.Wrap(-(map.TileWidth * map.Width)); //camera.Target.X += playerShip.Speed.X * 20f; } if (!playerShip.underWater) { if (playerShip.Position.Y > waterLevel + 10) { playerShip.underWater = true; AudioController.PlaySFX("water_enter", 1f, -0.1f, 0.1f); AudioController._songs["overwater-theme"].Volume = 0f; AudioController._songs["underwater-theme"].Volume = AudioController.MusicVolume; } waterParallax.HeightScale = MathHelper.Lerp(waterParallax.HeightScale, 0.65f, 0.1f); } if (playerShip.underWater) { if (playerShip.Position.Y < waterLevel - 10) { AudioController.PlaySFX("water_leave", 0.8f, -0.1f, 0.1f); AudioController._songs["overwater-theme"].Volume = AudioController.MusicVolume; AudioController._songs["underwater-theme"].Volume = 0f; playerShip.underWater = false; for (int i = 0; i < 30; i++) { Vector2 pos = new Vector2(Helper.RandomFloat(-5f, 5f), 0f); Color col = Color.Lerp(new Color(0, 81, 147), new Color(211, 234, 254), Helper.RandomFloat(0f, 1f)); particleController.Add(playerShip.Position + pos, (pos * 0.1f) + new Vector2(playerShip.Speed.X, playerShip.Speed.Y * Helper.RandomFloat(0.25f, 2f)), 0, 2000, 500, true, true, new Rectangle(0, 0, 3, 3), col, particle => { ParticleFunctions.FadeInOut(particle); if (particle.Position.Y > waterLevel) { particle.State = ParticleState.Done; } }, 1f, 0f, Helper.RandomFloat(-0.1f, 0.1f), 1, ParticleBlend.Alpha); } } waterParallax.HeightScale = MathHelper.Lerp(waterParallax.HeightScale, 0.1f, 0.05f); } particleController.Update(gameTime, map); if (!_endOfWave) { enemyController.Update(gameTime, map); } projectileController.Update(gameTime, map); powerupController.Update(gameTime, map); camera.Target = playerShip.Position; camera.Target.X += playerShip.Speed.X * 20f; //Enemy head = EnemyController.Instance.Enemies.FirstOrDefault(en => en is Boss && ((Boss) en).Head); //if (head != null) //{ // playerShip.Position = head.Position + new Vector2(0, -16); // camera.Target = head.Position; //} camera.Update(gameTime, playerShip.underWater, waterLevel); waterParallax.Update(gameTime, (camera.Target.X - camera.Position.X) * camera.Speed, (int)camera.Position.X); underwaterBGParallax.Update(gameTime, ((camera.Target.X - camera.Position.X) * camera.Speed) * 0.5f, (int)camera.Position.X); skyBGParallax.Update(gameTime, ((camera.Target.X - camera.Position.X) * camera.Speed) * 0.1f, (int)camera.Position.X); rocksParallax.Update(gameTime, (camera.Target.X - camera.Position.X) * camera.Speed, (int)camera.Position.X); cloudsParallax.Update(gameTime, (camera.Target.X - camera.Position.X) * camera.Speed, (int)camera.Position.X); hud.Update(gameTime, new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight)); if (enemyController.Enemies.Count == 0 && enemyController.NumToSpawn == 0 && !_endOfWave) { _endOfWave = true; TimerController.Instance.Create("", () => { GameController.Wave++; TweenController.Instance.Create("", TweenFuncs.QuadraticEaseIn, tweenin => { _waveFade = tweenin.Value; if (tweenin.State == TweenState.Finished) { MapGeneration.Generate(map); enemyController.SpawnInitial(GameController.Wave, map); playerShip.Reset(); projectileController.Reset(); _firstWave = false; TweenController.Instance.Create("", TweenFuncs.Linear, eowtween => { //playerShip.Life += 0.2f; _eowTimer = eowtween.Value; if (eowtween.State == TweenState.Finished) { TweenController.Instance.Create("", TweenFuncs.QuadraticEaseIn, tweenout => { _waveFade = 1f - tweenout.Value; if (tweenout.State == TweenState.Finished) { _endOfWave = false; } }, 500, false, false); } }, _tradecost == 0?2000:5000, false, false); } }, 500, false, false); }, GameController.Wave > 0?2000:0, false); } if (playerShip.Life <= 0f && !_gameOver) { _gameOver = true; TimerController.Instance.Create("", () => { TweenController.Instance.Create("", TweenFuncs.QuadraticEaseIn, tweenin => { _goFade = tweenin.Value; if (tweenin.State == TweenState.Finished) { TweenController.Instance.Create("", TweenFuncs.Linear, eowtween => { _goTimer = eowtween.Value; }, 2000, false, false); } }, 1000, false, false); }, 2000, false); } TweenController.Instance.Update(gameTime); TimerController.Instance.Update(gameTime); _tradecost = (int)Math.Ceiling((GameController.Wave * 2f) * (0.01f * (100f - playerShip.Life))); }