Ejemplo n.º 1
0
    private void InitSequence()
    {
        _enemyController.ClearEnemies();
        _playerMovement.Reset();

        var map = _mapGeneration.Generate();

        _mapBuilder.BuildMap(map);
        _playerMovement._collisions        = map._blocks;
        _playerMovement.transform.position = GetPlayerStart(map);

        _enemyController._map = map;
        _enemyController.GenerateEnemies();
    }
Ejemplo n.º 2
0
        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            map = content.Load <Map>("map");
            MapGeneration.Generate(map);

            camera = new Camera(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight, map);

            //camera.Zoom = 0.5f;

            text = content.Load <Texture2D>("titles");

            hud = new HUD(content.Load <Texture2D>("hud"));

            waterLevel           = ScreenManager.Game.RenderHeight;
            waterParallax        = new Parallax(content.Load <Texture2D>("abovewater-parallax"), 12, 0.5f, waterLevel, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, true);
            underwaterBGParallax = new Parallax(content.Load <Texture2D>("underwater-bg"), 4, 1f, waterLevel + 20, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), true, false);
            skyBGParallax        = new Parallax(content.Load <Texture2D>("sky-bg"), 72, 1f, 70, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, false);
            rocksParallax        = new Parallax(content.Load <Texture2D>("seabed-rocks"), 16, 0.35f, (map.TileHeight * map.Height) - 15, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, false);
            cloudsParallax       = new Parallax(content.Load <Texture2D>("clouds"), 16, 0.35f, 25, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, false, true);

            playerShip          = new Ship(content.Load <Texture2D>("playership"), new Rectangle(0, 0, 10, 10), null, Vector2.Zero);
            playerShip.Position = new Vector2(64, 190);

            particleController.LoadContent(content);

            projectileController = new ProjectileController(1000, sheet => new Projectile(sheet, new Rectangle(0, 0, 4, 4), null, new Vector2(0, 0)), content.Load <Texture2D>("projectiles"));
            enemyController      = new EnemyController(content.Load <Texture2D>("enemies"), content.Load <Texture2D>("boss"));
            powerupController    = new PowerupController(1000, sheet => new Powerup(sheet, new Rectangle(0, 0, 6, 6), null, Vector2.Zero), content.Load <Texture2D>("powerup"));

            powerupController.BoxCollidesWith.Add(playerShip);
            projectileController.BoxCollidesWith.Add(playerShip);
            projectileController.BoxCollidesWith.Add(enemyController);
            projectileController.BoxCollidesWith.Add(projectileController);
            enemyController.BoxCollidesWith.Add(playerShip);
            enemyController.BoxCollidesWith.Add(projectileController);

            GameController.Reset();

            //enemyController.SpawnInitial(GameController.Wave, map);

            base.LoadContent();
        }
Ejemplo n.º 3
0
        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)));
        }