Ejemplo n.º 1
0
        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            map = content.Load <Map>("map");
            MapObject spawn = ((MapObjectLayer)map.GetLayer("spawn")).Objects[0];

            camera        = new Camera(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight, map);
            camera.Target = new Vector2(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight) / 2f;

            heroPool = new EntityPool(100,
                                      sheet => new Hero(sheet, new Rectangle(0, 0, 10, 10), new Vector2(0, -5)),
                                      content.Load <Texture2D>("testhero"));
            heroPool.BoxCollidesWith.Add(heroPool);

            rotBoxPool = new EntityPool(100,
                                        sheet => new RotBox(sheet, new Rectangle(0, 0, 32, 32), null, Vector2.Zero),
                                        ScreenManager.blankTexture);
            rotBoxPool.PolyCollidesWith.Add(rotBoxPool);

            rotBoxPool.Spawn(entity =>
            {
                entity.Position = new Vector2(100, 100);
            });
            rotBoxPool.Spawn(entity =>
            {
                entity.Position = new Vector2(140, 100);
            });

            particleController.LoadContent(content);

            // TimerController.Instance.Create("shake", () => camera.Shake(500, 2f), 3000, true);

            TweenController.Instance.Create("spintext", TweenFuncs.SineEaseInOut, (tween) =>
            {
                textScale = 0.8f + (tween.Value * 0.4f);
            }, 3000, true, true);

            //// More crazy tween examples
            //TweenController.Instance.Create("spincam", TweenFuncs.Linear, (tween) =>
            //{
            //    camera.Rotation = MathHelper.TwoPi * tween.Value;
            //}, 10000, false, true, TweenDirection.Reverse);

            //TweenController.Instance.Create("zoomcam", TweenFuncs.Bounce, (tween) =>
            //{
            //    camera.Zoom = 1f + tween.Value;
            //}, 3000, true, true);

            particleController.Add(new Vector2(195, 150),
                                   Vector2.Zero,
                                   0, 1000, 0,
                                   false, false,
                                   new Rectangle(18, 0, 100, 100),
                                   Color.White,
                                   ParticleFunctions.PermaLight,
                                   1f, 0f,
                                   1, ParticleBlend.Multiplicative);

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