Update() private method

private Update ( ) : void
return void
Example #1
0
    /// <summary>
    /// Updates the character
    /// </summary>
    /// <param name="gameTime">the current game time</param>
    public override void Update(GameTime gameTime)
    {
        // if the character is not downed, it gets updated according to normal rules, so this code block is entered
        if (!IsDowned)
        {
            // Timer updates
            reviveTimer.Update(gameTime);
            stepSoundTimer.Update(gameTime);
            // Updates the weapon and healthbar
            this.weapon.Update(gameTime);
            healthbar.Update(gameTime);
            // Update for if the player is AI
            if (!playerControlled)
            {
                Vector2 previousPosition = this.position;
                AI.Update(gameTime);
                if (!(previousPosition == this.position) && stepSoundTimer.IsExpired)
                {
                    PlaySFX("walk");
                    stepSoundTimer.Reset();
                }
                // Play animations for the AI
                PlayAnimationDirection(position - previousPosition);
                weapon.SwordDirectionCheckerManager(position - previousPosition);
            }

            //When a character takes damage, let the character blink as an indication.
            if (!hitTimer.IsExpired)
            {
                Visible = !Visible;
                hitTimer.Update(gameTime);
            }
            else
            {
                Visible = true;
            }

            // Checks if the character is on ice
            IsOnIceChecker();
            base.Update(gameTime);
        }
        else
        {
            // Updates the death timer and if it expires, the character gets reset and loses some gold
            deathTimer.Update(gameTime);
            if (deathTimer.IsExpired)
            {
                this.Reset();
                this.attributes.Gold = this.attributes.Gold - (this.attributes.Gold / 4);
                deathTimer.Reset();
            }
        }
    }
Example #2
0
        public override void Update(float deltaTime)
        {
            if (_player.IsDestroyed)
            {
                _game.SetState(new ScoreState(_game, Score));
            }

            _entityManager.Update(deltaTime);
            _levelManager.Update(deltaTime);
            _systemManager.Update(deltaTime);
            _healthbar.Update(deltaTime);
        }
Example #3
0
        protected override void Update(GameTime gameTime)
        {
#if true
            level.getClientPlayer().EntityPacket = new EntityPacket(level.getClientPlayer()); //DIFFERENCE DETECTION
            float x = 0, y = 0;
            input.Update(this.IsActive, Mouse.GetState(), Keyboard.GetState(), GamePad.GetState(PlayerIndex.One));
            chat.update();
            mouseX = (int)input.MousePos.X;
            mouseY = (int)input.MousePos.Y;

            if (!chat.Open && !menu.Open)
            {
                if (input.KeyDown(Keys.LeftShift))
                {
                    level.getClientPlayer().speed = 2;
                }
                else
                {
                    level.getClientPlayer().speed = 1;
                }
                if (input.KeyDown(Keys.W))
                {
                    y -= level.getClientPlayer().speed;
                }
                if (input.KeyDown(Keys.A))
                {
                    x -= level.getClientPlayer().speed;
                }
                if (input.KeyDown(Keys.S))
                {
                    y += level.getClientPlayer().speed;
                }
                if (input.KeyDown(Keys.D))
                {
                    x += level.getClientPlayer().speed;
                }

                y += (int)Math.Round(input.CurrentGamepadState.ThumbSticks.Left.Y) * -1;
                x += (int)Math.Round(input.CurrentGamepadState.ThumbSticks.Left.X);

                if (input.KeyPressed(Keys.PageUp))
                {
                    time.CurrentTime += 0.1f;
                }
                if (input.KeyPressed(Keys.PageDown))
                {
                    time.CurrentTime -= 0.1f;
                }

                if (input.KeyPressed(Keys.T))
                {
                    chat.Open = true;
                }

                if (input.KeyPressed(Keys.L))
                {
                    if (playerlight)
                    {
                        playerlight = false;
                    }
                    else
                    {
                        playerlight = true;
                    }
                }
            }



            if (input.KeyPressed(Keys.F11))
            {
                if (graphics.IsFullScreen)
                {
                    graphics.IsFullScreen = false;
                    ChangeResolution(noFullscreenResolutionW, noFullscreenResolutionH);
                }
                else
                {
                    graphics.IsFullScreen   = true;
                    noFullscreenResolutionW = screenWidth;
                    noFullscreenResolutionH = screenHeight;
                    ChangeResolution(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
                }
            }

            if (input.KeyPressed(Keys.Escape))
            {
                if (chat.Open)
                {
                    chat.Open = false;
                }
                if (menu.Open)
                {
                    menu.Open = false;
                }
                else
                {
                    menu.Open = true;
                }
            }

            switch (currentGamestate)
            {
            case GameState.Running:

                if (input.CurrentMouseState.ScrollWheelValue > input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl))
                {
                    camera.AdjustZoom(0.2f);
                }
                if (input.CurrentMouseState.ScrollWheelValue < input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl))
                {
                    camera.AdjustZoom(-0.2f);
                }
                level.getClientPlayer().Move(new Vector2(x, y));
                camera.CenterOn(new Vector2(level.getClientPlayer().Position.X + level.getClientPlayer().width / 2, level.getClientPlayer().Position.Y + level.getClientPlayer().height / 2), true);
                inv.Update(input);
                break;

            case GameState.Editor:

                editor.Update();
                if (editor.tilesetScroll)
                {
                    editor.moveTileset(new Vector2(x, y));
                }
                else
                {
                    camera.MoveCamera(new Vector2(x, y));
                }
                if (editor.currentEditorMode == MapEditor.EditorMode.EntityAdd)
                {
                    inv.Update(input);
                }
                break;

            case GameState.Pause:

                break;
            }

            level.update();

            effectmanager.Update(input);
            menu.update();
            hb.Update(gameTime);
            sound.update();
            NetCode.Update(); //After all movement !important
            input.UpdatePrev();
#endif
            base.Update(gameTime);
        }
Example #4
0
        /// <summary>
        /// All this update needs to do is check to see if there is an
        /// enemy withinthe range, and if soo then shoot in that direction
        /// </summary>
        /// <param name="units"></param>
        public void Update(GameTime gt, List <Unit> units, Map map)
        {
            this.Bounds = new BoundingSphere(new Vector3(this.Position.X, this.Position.Y, 0), 5);
            #region If  the unit is alive
            // Check if the unit is still alive
            if (this.Health > 0)
            {
                map.checkCapturing(this);
                // Check if there are any player units inside of the range, if so, shoot them
                foreach (Unit u in units)
                {
                    if (CheckRange(u))
                    {
                        // Change the test color to see if collision is working,
                        // And call the shoot method with them

                        Shoot(u, gt);

                        // Move away from that unit a little bit
                    }
                    else
                    {
                    }
                }

                // Move the unit to the next destination


                this.IsAlive = true;
            }
            #endregion

            #region If the unit is dead
            else
            {
                // Kill the unit
                // Call the resetmethod
                //_IS_FIRST_CALL = true;

                //this.Position = new Vector2(-200, -200);
                this.Position = this.SpawnLoc;
                var delta = (float)gt.ElapsedGameTime.TotalSeconds;
                timer += delta;

                if (timer >= this.SpawnTime)
                {
                    this.Position = this.SpawnLoc;
                    timer         = 0;
                    Reset();
                    return;
                }
            }
            #endregion

            BulletCheck(map);

            foreach (Bullet b in ActiveBullets)
            {
                foreach (Unit u in units)
                {
                    b.DamageCheck(u);
                }
            }
            Healthbar.Update(Health, Position);

            // Pathfinding

            base.Move(gt);
        }