예제 #1
0
        /// <summary>
        /// Execute movement-related logic on every update.
        /// </summary>
        private void Move()
        {
            //No movement if you're dead.
            if (playerState == PlayerState.Dead)
            {
                return;
            }

            Vector2 moveDir = new Vector2(horizontalInput.Value, verticalInput.Value);

            //Adjust for diagonal movement
            float moveMod = (moveDir.X != 0 && moveDir.Y != 0) ? 0.7071f : 1f;

            var movement = moveDir * MoveSpeed * moveMod * Time.DeltaTime;

            //No movement if trying to walk into something.
            if (moveDir.X < 0 && collisionResult.Normal.X > 0 ||
                moveDir.X > 0 && collisionResult.Normal.X < 0)
            {
                return;
            }
            if (moveDir.Y < 0 && collisionResult.Normal.Y > 0 ||
                moveDir.Y > 0 && collisionResult.Normal.Y < 0)
            {
                return;
            }

            mover.CalculateMovement(ref movement, out collisionResult);
            subPixelVector.Update(ref movement);
            mover.ApplyMovement(movement);
        }
예제 #2
0
        public void Update()
        {
            var dt = Time.DeltaTime;

            _arma.Update(dt);

            var moveVec = new Vector2(_xAxisInput.Value, _yAxisInput.Value);

            var movement = _velocidad * moveVec * dt;

            var mousePos = Entity.Scene.Camera.MouseToWorldPoint();


            var center = Transform.Position;
            var angle  = (float)Math.Atan2(mousePos.Y - center.Y, mousePos.X - center.X);

            Transform.Rotation = angle;



            cambiarArmas();
            crearBala();
            animaciones(moveVec);


            _mover.CalculateMovement(ref movement, out var res);

            if (res.Collider != null)
            {
                Console.WriteLine(res.Collider.Entity.Name);
            }

            _subpixelV2.Update(ref movement);
            _mover.ApplyMovement(movement);
        }
        void IUpdatable.Update()
        {
            var move = new Vector2(xAxisInput.Value, yAxisInput.Value);

            if (move != Vector2.Zero)
            {
                var movement = move * moveSpeed * Time.DeltaTime;

                mover.CalculateMovement(ref movement, out var res);
                mover.ApplyMovement(movement);
            }

            // слежение на мышью
            var mousePosition = Entity.Scene.Camera.MouseToWorldPoint();
            var lookVector    = mousePosition - Entity.Position;

            var rotate = Mathf.Atan2(lookVector.Y, lookVector.X) + (Mathf.Deg2Rad * 90);

            Entity.Rotation = rotate;

            // handle firing a projectile
            if (fireInput.IsPressed && !shoot)
            {
                shoot = true;
                // fire a projectile in the direction we are facing
                var tiledScene = Entity.Scene as TiledScene;

                tiledScene.CreateProjectiles(Entity.Position, projectileVelocity);
            }
        }
예제 #4
0
        public void Update()
        {
            var moveDir = new Vector2(_xAxisInput.Value, _yAxisInput.Value);

            moveDir = moveDir * speed * Time.DeltaTime;
            mover.CalculateMovement(ref moveDir, out var res);


            mover.ApplyMovement(moveDir);
        }
예제 #5
0
        void IUpdatable.Update()
        {
            var movementVector = new Vector2(_xAxisInput.Value, _yAxisInput.Value);

            var previousState  = _linkStateFactory.PreviousState;
            var previousAction = previousState.Action;
            var state          = _linkStateFactory.GetNextState(movementVector);

            Action    = state.Action;
            Direction = state.Direction;

            if (Action == LinkAction.Standing)
            {
                if (previousAction == LinkAction.Walking)
                {
                    _bodyAnimator.Pause();
                }

                if (previousAction == LinkAction.Attacking)
                {
                    _bodyAnimator.Stop();
                }

                AnimateStand();
            }

            if (Action == LinkAction.Attacking)
            {
                AnimateAttack();
            }

            if (Action == LinkAction.Walking)
            {
                AnimateWalk();

                // Cut movement speed a little if moving in two directions at once.
                if (movementVector.X != 0 && movementVector.Y != 0)
                {
                    movementVector *= 0.75f;
                }

                if (movementVector != Vector2.Zero)
                {
                    var movement = movementVector * _moveSpeed * Time.DeltaTime;

                    _mover.CalculateMovement(ref movement, out var res);
                    _subpixelV2.Update(ref movement);
                    _mover.ApplyMovement(movement);
                }
            }
        }
        void IUpdatable.Update()
        {
            // handle movement
            var moveDir = new Vector2(_xAxisInput.Value, _yAxisInput.Value);

            if (moveDir != Vector2.Zero)
            {
                var movement = moveDir * _moveSpeed * Time.DeltaTime;

                _mover.CalculateMovement(ref movement, out var res);
                _subpixelV2.Update(ref movement);
                _mover.ApplyMovement(movement);
            }
        }
예제 #7
0
        public void Update()
        {
            if (CanAccelearte)
            {
                CurrentSpeed += Acceleration * Time.DeltaTime;

                if (CurrentSpeed > MaxSpeed)
                {
                    CurrentSpeed  = MaxSpeed;
                    CanAccelearte = false;
                }
            }

            var motion = Vector2Ext.Normalize(player.Position - Entity.Position) * CurrentSpeed * Time.DeltaTime;

            mover.ApplyMovement(motion);
        }
예제 #8
0
        void IUpdatable.Update()
        {
            // handle movement and animations
            var moveDir   = new Vector2(_xAxisInput.Value, _yAxisInput.Value);
            var animation = "WalkDown";

            if (moveDir.X < 0)
            {
                animation = "WalkLeft";
            }
            else if (moveDir.X > 0)
            {
                animation = "WalkRight";
            }

            if (moveDir.Y < 0)
            {
                animation = "WalkUp";
            }
            else if (moveDir.Y > 0)
            {
                animation = "WalkDown";
            }


            if (moveDir != Vector2.Zero)
            {
                if (!_animator.IsAnimationActive(animation))
                {
                    _animator.Play(animation);
                }
                else
                {
                    _animator.UnPause();
                }

                var movement = moveDir * _moveSpeed * Time.DeltaTime;

                _mover.CalculateMovement(ref movement, out var res);
                _subpixelV2.Update(ref movement);
                _mover.ApplyMovement(movement);
            }
            else
            {
                _animator.Pause();
            }

            // handle firing a projectile
            if (_fireInput.IsPressed)
            {
                // fire a projectile in the direction we are facing
                var dir = Vector2.Zero;
                switch (_animator.CurrentAnimationName)
                {
                case "WalkUp":
                    dir.Y = -1;
                    break;

                case "WalkDown":
                    dir.Y = 1;
                    break;

                case "WalkRight":
                    dir.X = 1;
                    break;

                case "WalkLeft":
                    dir.X = -1;
                    break;

                default:
                    dir = new Vector2(1, 0);
                    break;
                }

                var ninjaScene = Entity.Scene as NinjaAdventureScene;
                ninjaScene.CreateProjectiles(Entity.Transform.Position, _projectileVelocity * dir);
            }
        }
예제 #9
0
        void IUpdatable.Update()
        {
            if (Entity.GetComponent <CircleCollider>() != null)
            {
                var collider = Entity.GetComponent <CircleCollider>();
                //if (collider.CollidesWithAny()
            }
            // handle movement and animations
            var moveDir   = new Vector2(_xAxisInput.Value, _yAxisInput.Value);
            var animation = "Idle";

            if (moveDir.X < 0)
            {
                if (_crouchInput)
                {
                    if (!_animator.CurrentAnimationName.Equals("Transition") && !_animator.CurrentAnimationName.Equals("Crouch"))
                    {
                        animation = "Transition";
                    }
                    else
                    {
                        animation = "Crouch";
                    }
                }
                else
                {
                    animation = "Walk";
                }
                _animator.FlipX = true;
            }
            else if (moveDir.X > 0)
            {
                if (_crouchInput)
                {
                    if (!_animator.CurrentAnimationName.Equals("Transition") && !_animator.CurrentAnimationName.Equals("Crouch"))
                    {
                        animation = "Transition";
                    }
                    else
                    {
                        animation = "Crouch";
                    }
                }
                else
                {
                    animation = "Walk";
                }
                _animator.FlipX = false;
            }

            if (_kickInput)
            {
                moveDir   = Vector2.Zero;
                animation = "Kick";
                if (!_animator.IsAnimationActive(animation))
                {
                    _animator.Play(animation);
                }
                else
                {
                    _animator.UnPause();
                }
            }

            else if (moveDir != Vector2.Zero)
            {
                if (!_animator.IsAnimationActive(animation))
                {
                    _animator.Play(animation);
                }
                else
                {
                    _animator.UnPause();
                }

                if (_crouchInput)
                {
                    moveDir *= 3;
                }
                var movement = moveDir * _moveSpeed * Time.DeltaTime;

                _mover.CalculateMovement(ref movement, out var res);
                _subpixelV2.Update(ref movement);
                _mover.ApplyMovement(movement);
            }
            else
            {
                if (!_animator.IsAnimationActive(animation))
                {
                    _animator.Play(animation);
                }
                else
                {
                    _animator.UnPause();
                }
            }
        }