public void Update(object sender, UpdateData data)
        {
            if (_follow == null)
                return;

            Pos.X = (float)(_follow.Pos.X - (Core.Width / 2));
            Pos.Y = (float)(_follow.Pos.Y - (Core.Height / 2));
        }
        public override void Update(object sender, UpdateData data)
        {
            base.Update(sender, data);

            Pos += Vel;
            Vel += Acc;

            if (Vel.X > TERMINAL_VEL)
                Vel.X = TERMINAL_VEL;

            if (Vel.Y > TERMINAL_VEL)
                Vel.Y = TERMINAL_VEL;
        }
Example #3
0
        public override void Update(object sender, UpdateData data)
        {
            base.Update(sender, data);

            if (VertState == VertState.Air)
            {
                Vel.Y -= _gravity;

                if (State == State.Jump)
                {
                    if (Util.Sign(Vel.Y) == 1)
                    {
                        SetAnimation(Assets.Animations["eugene-descending"]);
                    }
                    else
                    {
                        SetAnimation(Assets.Animations["eugene-ascending"]);
                    }
                }

                if (Pos.Y > _floor)
                {
                    Vel.Y = 0;
                    Pos.Y = _floor;
                    SetState(State.Idle, VertState.Ground);
                }
            }

            if (Math.Abs(Vel.X) < _minSpeedThreshold)
            {
                Vel.X = 0.0f;
                if (State == State.Walk)
                {
                    SetState(State.Idle, VertState.Ground);
                }
            }

            if (Vel.X != 0.0f)
            {
                float damp;

                if (VertState == VertState.Ground)
                    damp = _damping;
                else
                    damp = _airDamping;

                Vel.X -= damp * Util.Sign(Vel.X);
            }

            if (Math.Abs(Vel.X) > _speedMax)
                Vel.X = _speedMax * Util.Sign(Vel.X);
        }
        protected virtual void UpdateAnimation(UpdateData data)
        {
            _animationTimeout -= data.GameTime.ElapsedGameTime.Milliseconds;
            if (_animationTimeout < 0)
            {
                if (!Looping)
                {
                    if (_frame == _animation.Length() - 1)
                    {
                        _frame = (int)MathHelper.Clamp(_frame, 0, _animation.Length() - 1);

                        if (AnimationCompleteEvent != null)
                            AnimationCompleteEvent(this, new EventArgs());

                        return;
                    }
                }
                _frame = (_frame + 1) % _animation.Length();
                _animationTimeout = _animation.FrameTime;
            }
        }
 public virtual void Update(object sender, UpdateData data)
 {
     if (Animating && !(Looping && _animationComplete))
     {
         UpdateAnimation(data);
     }
 }
        public void Update(object sender, UpdateData data)
        {
            Vector2 startPos = _player.Pos;
            bool
                onSomething = false,
                onRamp      = false;

            for (int i = 0; i < _platforms.Count; ++i)
            {
                Platform plat = _platforms[i];

                Rectangle
                    playerBounds = _player.Bounds(),
                    platBounds   = plat.Bounds();

                playerBounds.Height += 1;

                if (!onSomething)
                {
                    if (!plat.Ramp && platBounds.Intersects(new Rectangle(playerBounds.X, playerBounds.Bottom, playerBounds.Width, 2)))
                    {
                        onSomething = true;
                    }
                }

                if (!playerBounds.Intersects(platBounds))
                {
                    continue;
                }

                if (plat.Ramp)
                {
                    if (_player.Pos.X > plat.Pos.X && _player.Pos.X < plat.Pos.X + plat.Size.X)
                    {
                        float rampAmount = (_player.Pos.X - plat.Pos.X) / plat.Size.X;
                        float newY       = 0.0f;

                        if (rampAmount > 0.9f)
                        {
                            rampAmount = 1.0f;
                        }
                        else if (rampAmount < 0.1f)
                        {
                            rampAmount = 0.0f;
                        }

                        if (plat.RampDir == Direction.West)
                        {
                            newY = plat.Pos.Y + plat.Size.Y - MathHelper.Lerp(plat.Size.Y, 0.0f, rampAmount);
                        }
                        else if (plat.RampDir == Direction.East)
                        {
                            newY = plat.Pos.Y + plat.Size.Y - MathHelper.Lerp(0.0f, plat.Size.Y, rampAmount);
                        }

                        if (_player.VertState == VertState.Air)
                        {
                            if (_player.Pos.Y >= newY)
                            {
                                _player.SetState(State.Idle, VertState.Ground);
                            }
                        }

                        if (_player.VertState == VertState.Ground)
                        {
                            _player.Pos.Y = newY;
                            onSomething   = true;
                            onRamp        = true;
                        }
                    }
                }
            }

            if (!onRamp)
            {
                for (int i = 0; i < _platforms.Count; ++i)
                {
                    Platform plat = _platforms[i];

                    Rectangle
                        playerBounds = _player.Bounds(),
                        platBounds   = plat.Bounds();

                    Side hitSide = Util.Collide(playerBounds, platBounds, _player.Vel);

                    if (plat.JumpThrough && hitSide != Side.Bottom)
                    {
                        continue;
                    }

                    if (plat.Ramp)
                    {
                        continue;
                    }

                    switch (hitSide)
                    {
                    case Side.Top:

                        _player.Pos.Y = platBounds.Bottom + _player.Origin.Y;
                        _player.Vel.Y = 0.0f;

                        break;

                    case Side.Bottom:

                        _player.Pos.Y = platBounds.Top - playerBounds.Height + _player.Origin.Y;
                        _player.Vel.Y = 0.0f;
                        _player.SetState(State.Idle, VertState.Ground);

                        break;

                    case Side.Left:

                        _player.Pos.X = platBounds.Left - playerBounds.Width + _player.Origin.X - 1;
                        _player.Vel.X = 0.0f;

                        break;

                    case Side.Right:

                        _player.Pos.X = platBounds.Right + _player.Origin.X + 1;
                        _player.Vel.X = 0.0f;

                        break;
                    }
                }
            }

            if (_player.VertState == VertState.Ground && !onSomething)
            {
                _player.SetState(State.Jump, VertState.Air);
            }
        }
Example #7
0
        public void Update(object sender, UpdateData data)
        {
            MultiState
                newState = new MultiState(),
                oldState = _inputState;

            List<GameInputs> gameInputs = Util.GetValues<GameInputs>();

            for (int i = 0; i < gameInputs.Count; ++i)
            {
                GameInputs
                    gameInput = gameInputs[i];

                if (!_inputMap.Keys.Contains(gameInput))
                    continue;

                MultiInput input = _inputMap[gameInput];

                bool
                    isDown = newState.IsDown(input),
                    wasDown = oldState.IsDown(input);

                if (isDown && !wasDown)
                {
                    if (PressedEvent != null)
                        PressedEvent(this, new InputData(gameInput));
                }
                else if (!isDown && wasDown)
                {
                    if (ReleasedEvent != null)
                        ReleasedEvent(this, new InputData(gameInput));
                }

                if (isDown)
                {
                    if (HeldEvent != null)
                        HeldEvent(this, new InputData(gameInput));
                }
            }

            _inputState = newState;
        }
Example #8
0
 public void Update(object sender, UpdateData data)
 {
     Console.WriteLine(data.FrameDelta);
 }
Example #9
0
 public void Update(object sender, UpdateData data)
 {
     Console.WriteLine(data.FrameDelta);
 }
Example #10
0
        public void Update(object sender, UpdateData data)
        {
            _effects["fade"].Parameters["fadeAmount"].SetValue(FadeAmount);

            float amount = (float)Math.Sin(data.GameTime.TotalGameTime.TotalMilliseconds / 400);
            _glowDistance = MathHelper.Lerp(_minGlowDistance, _maxGlowDistance, Math.Abs(amount));
        }
Example #11
0
        public void Update(object sender, UpdateData data)
        {
            Vector2 startPos = _player.Pos;
            bool
                onSomething = false,
                onRamp = false;

            for (int i = 0; i < _platforms.Count; ++i)
            {
                Platform plat = _platforms[i];

                Rectangle
                    playerBounds = _player.Bounds(),
                    platBounds = plat.Bounds();

                playerBounds.Height += 1;

                if (!onSomething)
                {
                    if (!plat.Ramp && platBounds.Intersects(new Rectangle(playerBounds.X, playerBounds.Bottom, playerBounds.Width, 2)))
                        onSomething = true;
                }

                if (!playerBounds.Intersects(platBounds))
                    continue;

                if (plat.Ramp)
                {
                    if (_player.Pos.X > plat.Pos.X && _player.Pos.X < plat.Pos.X + plat.Size.X)
                    {
                        float rampAmount = (_player.Pos.X - plat.Pos.X) / plat.Size.X;
                        float newY = 0.0f;

                        if (rampAmount > 0.9f)
                            rampAmount = 1.0f;
                        else if (rampAmount < 0.1f)
                            rampAmount = 0.0f;

                        if (plat.RampDir == Direction.West)
                        {
                            newY = plat.Pos.Y + plat.Size.Y - MathHelper.Lerp(plat.Size.Y, 0.0f, rampAmount);
                        }
                        else if (plat.RampDir == Direction.East)
                        {
                            newY = plat.Pos.Y + plat.Size.Y - MathHelper.Lerp(0.0f, plat.Size.Y, rampAmount);
                        }

                        if (_player.VertState == VertState.Air)
                        {
                            if (_player.Pos.Y >= newY)
                            {
                                _player.SetState(State.Idle, VertState.Ground);
                            }
                        }

                        if (_player.VertState == VertState.Ground)
                        {
                            _player.Pos.Y = newY;
                            onSomething = true;
                            onRamp = true;
                        }
                    }
                }
            }

            if (!onRamp)
            {

                for (int i = 0; i < _platforms.Count; ++i)
                {
                    Platform plat = _platforms[i];

                    Rectangle
                        playerBounds = _player.Bounds(),
                        platBounds = plat.Bounds();

                    Side hitSide = Util.Collide(playerBounds, platBounds, _player.Vel);

                    if (plat.JumpThrough && hitSide != Side.Bottom)
                    {
                        continue;
                    }

                    if (plat.Ramp)
                    {
                        continue;
                    }

                    switch (hitSide)
                    {
                        case Side.Top:

                            _player.Pos.Y = platBounds.Bottom + _player.Origin.Y;
                            _player.Vel.Y = 0.0f;

                            break;
                        case Side.Bottom:

                            _player.Pos.Y = platBounds.Top - playerBounds.Height + _player.Origin.Y;
                            _player.Vel.Y = 0.0f;
                            _player.SetState(State.Idle, VertState.Ground);

                            break;
                        case Side.Left:

                            _player.Pos.X = platBounds.Left - playerBounds.Width + _player.Origin.X - 1;
                            _player.Vel.X = 0.0f;

                            break;
                        case Side.Right:

                            _player.Pos.X = platBounds.Right + _player.Origin.X + 1;
                            _player.Vel.X = 0.0f;

                            break;
                    }
                }

            }

            if (_player.VertState == VertState.Ground && !onSomething)
            {
                _player.SetState(State.Jump, VertState.Air);
            }
        }