Update() public method

public Update ( ) : void
return void
示例#1
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            camera.Update(gameTime);

            particleController.Update(gameTime, map);

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
示例#2
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            camera.Update(gameTime);

            heroPool.Update(gameTime, map);
            rotBoxPool.Update(gameTime);

            // This stuff is all example - camera follows random Hero and zooms in when following
            //if (Helper.Random.Next(200) == 0)
            //{
            //    List<Entity> activeHeroes = heroPool.Entities.Where(hero => hero.Active).ToList();
            //    if (activeHeroes.Count > 0) followingHero = (Hero) activeHeroes[Helper.Random.Next(activeHeroes.Count)];
            //}
            //if (Helper.Random.Next(200) == 1 && followingHero != null) followingHero = null;

            //if (followingHero != null && followingHero.Active)
            //{
            //    camera.Target = followingHero.Position;
            //    if (camera.Zoom < 2.5f) camera.Zoom += 0.05f;
            //}
            //else
            //{
            //    camera.Target = new Vector2(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight)/2f;
            //    if (camera.Zoom > 1f) camera.Zoom -= 0.05f;
            //}
            //////////////////



            particleController.Update(gameTime, map);

            if (Helper.Random.Next(100) == 0)
            {
                heroPool.Spawn(entity =>
                {
                    entity.Position        = new Vector2(Helper.Random.Next(ScreenManager.Game.RenderWidth - 64) + 32, 32);
                    ((Hero)entity).FaceDir = Helper.Random.Next(2) == 0 ? -1 : 1;
                });
            }

            particleController.Add(new Vector2(17, 40),
                                   new Vector2(Helper.RandomFloat(2f), -1.5f),
                                   100, 3000, 1000,
                                   true, true,
                                   new Rectangle(0, 0, 2, 2),
                                   new Color(new Vector3(1f, 0f, 0f) * (0.25f + Helper.RandomFloat(0.5f))),
                                   ParticleFunctions.FadeInOut,
                                   1f, 0f,
                                   1, ParticleBlend.Alpha);

            particleController.Add(new Vector2(150, 176),
                                   new Vector2(-0.05f + Helper.RandomFloat(0.1f), -0.1f),
                                   1000, Helper.Random.NextDouble() * 3000, Helper.Random.NextDouble() * 3000,
                                   false, false,
                                   new Rectangle(0, 0, 16, 16),
                                   new Color(new Vector3(1f) * (0.25f + Helper.RandomFloat(0.5f))),
                                   ParticleFunctions.Smoke,
                                   0.1f, 0f,
                                   1, ParticleBlend.Additive);

            particleController.Add(new Vector2(250, 50),
                                   new Vector2(-1f + Helper.RandomFloat(2f), -1f + Helper.RandomFloat(2f)),
                                   100, 500, 1000,
                                   false, false,
                                   new Rectangle(0, 0, 16, 16),
                                   Color.White,
                                   ParticleFunctions.FadeLight,
                                   Helper.RandomFloat(0.5f), 0f,
                                   1, ParticleBlend.Multiplicative);


            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
示例#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)));
        }
示例#4
0
文件: Game1.cs 项目: DCNick3/FGame
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            this.gameTime = gameTime;

            //FPS
            if (gameTime.TotalGameTime - lastFpsCounterReset > fpsCounterResetFreq)
            {
                fps                 = fpsCounter;
                fpsCounter          = 0;
                lastFpsCounterReset = gameTime.TotalGameTime;
            }

            //Player Run
            if (gameTime.TotalGameTime - lastRunUpdate > runFreq)
            {
                if (isMoving)
                {
                    if (runStepDirection)
                    {
                        if (playerRunStep < 2)
                        {
                            playerRunStep++;
                        }
                        else
                        {
                            runStepDirection = !runStepDirection;
                            playerRunStep--;
                        }
                    }
                    else
                    {
                        if (playerRunStep > 0)
                        {
                            playerRunStep--;
                        }
                        else
                        {
                            runStepDirection = !runStepDirection;
                            playerRunStep++;
                        }
                    }
                }
                else
                {
                    playerRunStep = 1;
                }
                lastRunUpdate = gameTime.TotalGameTime;
            }
            isMoving = false;
            UpdateFireballs(gameTime);
            lightSources = GetLightSources();

            #region keyboard_input
            lastKeyboardState = keyboardState;
            keyboardState     = Keyboard.GetState();
            if (firstRun)
            {
                firstRun = false;
                return;
            }

            if (!player.IsInInventory)
            {
                if (keyboardState.IsKeyDown(Keys.Up))
                {
                    PlayerMove(3, gameTime);
                    isMoving = true;
                }
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    PlayerMove(2, gameTime);
                    isMoving = true;
                }
                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    PlayerMove(1, gameTime);
                    isMoving = true;
                }
                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    PlayerMove(0, gameTime);
                    isMoving = true;
                }

                if (KeyPress(Keys.Q))
                {
                    if (player.Type == 1 && player.UseSkill(0, gameTime))
                    {
                        fireballs.Add(new Fireball()
                        {
                            X = (int)player.Position.X, Y = (int)player.Position.Y, Direction = player.RunDirection, Speed = 3, Step = 0
                        });
                    }
                    if (player.CanUseSwords && player.UseSkill(0, gameTime))
                    {
                        player.CastSword(48, 0.3F, player.RunDirection);
                    }
                }
            }

            if (keyboardState.IsKeyDown(Keys.OemTilde))
            {
                //RegenPole();
            }

            Rectangle playerRect = new Rectangle((int)player.Position.X, (int)player.Position.Y, playerTextureWidth, playerTextureHeight);
            if (KeyPress(Keys.E))
            {
                foreach (var obj in currentLocation.GetObjectsIntersectsRect(playerRect))
                {
                    obj.Interact(player);
                }
            }

            for (int i = 0; i < player.Buffs.Count; i++)
            {
                var buff = player.Buffs[i];
                if (buff.LastedTime <= TimeSpan.Zero)
                {
                    player.Buffs.Remove(buff);
                    i--;
                    continue;
                }
                buff.LastedTime -= gameTime.ElapsedGameTime;
            }

            if (KeyPress(Keys.T))
            {
                if (player.Type == 1 && player.UseSkill(1, gameTime))
                {
                    player.AddBuff(new Buff(BuffType.Torch, 10));
                }
            }

            if (player.HP < 0)
            {
                player.Kill();
            }

            if (player.SkillUsePoint < player.MaxSkillUsePoint)
            {
                player.SkillUsePoint += player.SkillUsePointPerSec * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (player.SkillUsePoint > player.MaxSkillUsePoint)
            {
                player.SkillUsePoint = player.MaxSkillUsePoint;
            }

            if (KeyPress(Keys.OemComma))
            {
                enableSmoothLightning = !enableSmoothLightning;
            }

            if (player.Buffs.Where((Buff f) => f.Type == BuffType.Poison).Count() > 0)
            {
                player.HP -= (float)(Buff.PoisonDmgPS * gameTime.ElapsedGameTime.TotalSeconds);
            }

            if (enableDevCheats && KeyPress(Keys.Z))
            {
                //Healing Potion
                player.HP += 50;
                if (player.HP > player.MaxHP)
                {
                    player.HP = player.MaxHP;
                }
            }

            if (enableDevCheats && KeyPress(Keys.X))
            {
                //Healing Potion
                player.SkillUsePoint += 50;
                if (player.SkillUsePoint > player.MaxSkillUsePoint)
                {
                    player.SkillUsePoint = player.MaxSkillUsePoint;
                }
            }

            if (enableDevCheats && KeyPress(Keys.C))
            {
                cheatFullBright       = !cheatFullBright;
                enableSmoothLightning = !cheatFullBright;
            }

            if (enableDevCheats && KeyPress(Keys.F3))
            {
                debugInfo = !debugInfo;
            }

            if (enableDevCheats && KeyPress(Keys.V))
            {
                player.isSpeedHack = !player.isSpeedHack;
            }

            if (enableDevCheats && KeyPress(Keys.B))
            {
                MouseState s = Mouse.GetState();
                player.Position += new Vector2(s.X, s.Y) - ScreenCenter;
            }

            if (enableDevCheats && KeyPress(Keys.N))
            {
                player.CastSword(10000000, 1F, player.RunDirection);
            }

            if (enableDevCheats && KeyPress(Keys.M))
            {
                player.UnCastSword();
            }

            if (KeyPress(Keys.Escape))
            {
                player.IsInInventory = !player.IsInInventory;
            }

            if (KeyPress(Keys.F4))
            {
                isFullScreen = !isFullScreen;
                //TODO: Fix fullscreen bug
            }

            if (!player.IsInInventory)
            {
                if (holdingItem != null)
                {
                    player.AddItem(holdingItem);
                    holdingItem = null;
                }
                if (KeyPress(Keys.D1))
                {
                    player.SelectedSlot = 0;
                }
                if (KeyPress(Keys.D2))
                {
                    player.SelectedSlot = 1;
                }
                if (KeyPress(Keys.D3))
                {
                    player.SelectedSlot = 2;
                }
                if (KeyPress(Keys.D4))
                {
                    player.SelectedSlot = 3;
                }
                if (KeyPress(Keys.D5))
                {
                    player.SelectedSlot = 4;
                }
                if (KeyPress(Keys.D6))
                {
                    player.SelectedSlot = 5;
                }
                if (KeyPress(Keys.D7))
                {
                    player.SelectedSlot = 6;
                }
                if (KeyPress(Keys.D8))
                {
                    player.SelectedSlot = 7;
                }
                if (KeyPress(Keys.D9))
                {
                    player.SelectedSlot = 8;
                }

                if (KeyPress(Keys.D0))
                {
                    player.SelectedSlot = 9;
                }

                if (KeyPress(Keys.A))
                {
                    player.SelectedSlot--;
                    if (player.SelectedSlot < 0)
                    {
                        player.SelectedSlot += 10;
                    }
                }

                if (KeyPress(Keys.D))
                {
                    player.SelectedSlot++;
                    player.SelectedSlot %= 10;
                }
            }
            else
            {
                if (KeyPress(Keys.Up))
                {
                    player.SelectedSlot -= 10;
                    if (player.SelectedSlot < 0)
                    {
                        player.SelectedSlot += 40;
                    }
                    player.SelectedSlot %= 40;
                }
                if (KeyPress(Keys.Down))
                {
                    player.SelectedSlot += 10;
                    if (player.SelectedSlot < 0)
                    {
                        player.SelectedSlot += 40;
                    }
                    player.SelectedSlot %= 40;
                }
                if (KeyPress(Keys.Left))
                {
                    player.SelectedSlot -= 1;
                    if (player.SelectedSlot < 0)
                    {
                        player.SelectedSlot += 40;
                    }
                    player.SelectedSlot %= 40;
                }
                if (KeyPress(Keys.Right))
                {
                    player.SelectedSlot += 1;
                    if (player.SelectedSlot < 0)
                    {
                        player.SelectedSlot += 40;
                    }
                    player.SelectedSlot %= 40;
                }
                if (KeyPress(Keys.W))
                {
                    ItemStack s = player.Inventory[player.SelectedSlot];
                    if (holdingItem == null || s == null || s.Type != holdingItem.Type)
                    {
                        player.Inventory[player.SelectedSlot] = holdingItem;
                        holdingItem = s;
                    }
                    else
                    {
                        int add = holdingItem.Count;
                        if (add + player.Inventory[player.SelectedSlot].Count > holdingItem.Type.GetMaxStackSize())
                        {
                            add = holdingItem.Type.GetMaxStackSize() - player.Inventory[player.SelectedSlot].Count;
                        }
                        player.Inventory[player.SelectedSlot].Count += add;
                        holdingItem.Count -= add;
                        if (holdingItem.Count <= 0)
                        {
                            holdingItem = null;
                        }
                    }
                }
                if (KeyPress(Keys.Q))
                {
                    ItemStack s = player.Inventory[player.SelectedSlot];
                    if (s != null)
                    {
                        if (holdingItem == null)
                        {
                            holdingItem = new ItemStack(s.Type, 1);
                            s.Count--;
                        }
                        else if (holdingItem.Type == s.Type && holdingItem.Count + 1 <= holdingItem.Type.GetMaxStackSize())
                        {
                            holdingItem.Count++;
                            s.Count--;
                        }
                        if (s.Count <= 0)
                        {
                            player.Inventory[player.SelectedSlot] = null;
                        }
                    }
                }
            }

            if (KeyPress(Keys.S))
            {
                ItemStack cs = player.Inventory[player.SelectedSlot];
                if (cs != null)
                {
                    cs.Type.OnUse(player, cs);
                    player.ValidateInventory();
                }
            }
            #endregion


            particleController.Update(gameTime);
            if (player.Type == 1)
            {
                particleController.PlayerWizardManaSparks(player.Position);
            }
            base.Update(gameTime);
        }
示例#5
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
            {
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            }
            else
            {
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);
            }

            if (IsActive)
            {
                if (playerController.GameOver)
                {
                    HandleGameOver();
                }

                if (enemyController.LevelFinished)
                {
                    HandleLevelComplete();
                }

                var timeWarpFactor = 1.0f;
                foreach (float value in timeFactors.Values)
                {
                    timeWarpFactor *= value;
                }

                var elapsedTime = gameTime.ElapsedGameTime.Milliseconds * timeWarpFactor;
                var timeSpan    = new TimeSpan(0, 0, 0, 0, (int)elapsedTime);
                myGameTime        = new GameTime(myGameTime.TotalGameTime, timeSpan);
                affectedGameTime += elapsedTime;

                #region Update Objects
                #region Update Player
                playerController.Update(elapsedTime);
                #endregion

                #region Update Bullets
                bulletController.Update(elapsedTime);
                #endregion

                #region Update Enemies
                enemyController.Update(elapsedTime);
                #endregion

                #region Update Particles
                particleController.Update(elapsedTime);
                #endregion

                #region Update Background
                backgroundController.Update(elapsedTime);
                #endregion
                #endregion
            }
        }