private void UpdateJumpState(JumpingState priorJumpingState)
 {
     if (groundedEvent.TryReceive(out var isGrounded))
     {
         if (isGrounded)
         {
             // The player is grounded now, so if the current animation is the end of a jump or already grounded then update
             // the state to be grounded.
             if (priorJumpingState == JumpingState.JumpEnd || priorJumpingState == JumpingState.Grounded)
             {
                 JumpingState = JumpingState.Grounded;
             }
             else
             {
                 // Otherwise the animation is in the middle of jumping so trigger the end of the jump animation.
                 JumpingState = JumpingState.JumpEnd;
             }
         }
         else
         {
             // The character is in the air. If the animation is grounded start jumping. Otherwise continue jumping.
             JumpingState = (priorJumpingState == JumpingState.Grounded) ? JumpingState.JumpStart : JumpingState.JumpLoop;
         }
     }
 }
Example #2
0
    public void Execute(Player player)
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            JumpingState jumpingState = new JumpingState();
            jumpingState.Enter(player);
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            DuckingState duckingState = new DuckingState();
            duckingState.Enter(player);
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            SpinningState spinningState = new SpinningState();
            spinningState.Enter(player);
        }

        if (Input.GetKeyDown(KeyCode.I))
        {
            InvisibleState invisibleState = new InvisibleState();
            invisibleState.Enter(player);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            RudeState rudeState = new RudeState();
            rudeState.Enter(player);
        }
    }
Example #3
0
 void Start()
 {
     rigidBody    = GetComponent <Rigidbody2D>();
     stateMachine = new StateMachine();
     standing     = new StandingState(this, stateMachine);
     jumping      = new JumpingState(this, stateMachine);
     crouching    = new CrouchingState(this, stateMachine);
     stateMachine.Initialize(standing);
 }
Example #4
0
    //RaycastHit2D[] info;
    public override void UpdateState(Character c, UserInput input, RaycastHit2D[] info)
    {
        this.info = info;
        //base.UpdateState(c, input);


        //Debug.Log("Running state updating " + c.currentLinearSpeed);

        if (c.currentLinearSpeed > 0)
        {
            c.playerSprite.transform.localScale = new Vector3(1, 1, 1);
        }
        if (c.currentLinearSpeed < 0)
        {
            c.playerSprite.transform.localScale = new Vector3(-1, 1, 1);
        }

        if (c.StateList.Count == index)
        {
            //animation
            AnimateState(c);
            //sound
            c.SetSoundEffect(c.playerAudio.walk, true, false, 0.15f);

            //Debug.Log("sdfssfsfsfsfsfsfsf");
            //Exit conditions
            //if (c.State.GetType() != typeof(FallingState))
            //{
            //Debug.Log("x input: " + input.xInput);
            if (input.xInput == 0)
            {
                //c.State = null;
                //c.State = new IdleState();
                c.StateList.RemoveAt(c.StateList.Count - 1);
                //Debug.Log("Removed");
            }
            if (input.jumpPressed)
            {
                //c.State = null;
                //c.State = new JumpingState();
                States nextState = new JumpingState();
                nextState.index = c.StateList.Count + 1;
                c.StateList.Add(nextState);
                return;
            }

            if (info.Length == 0 && c.StateList[c.StateList.Count - 1].GetType() != typeof(FallingState))
            {
                States nextState = new FallingState(1);
                nextState.index = c.StateList.Count + 1;
                c.StateList.Add(nextState);
                return;
            }
        }
    }
Example #5
0
    public StateMachine(Player player)
    {
        stationaryState  = new StationaryState(player);
        runningState     = new RunningState(player);
        jumpingState     = new JumpingState(player);
        fallingState     = new FallingState(player);
        wallSlidingState = new WallSlidingState(player);
        wallHuggingState = new WallHuggingState(player);

        _currentState = stationaryState;
    }
Example #6
0
 void StateExitConditions(Character c, UserInput input)
 {
     //If the special button pressed again while climbing, set the state to fall
     if (input.climbPressed)
     {
         VirtualJoystick.ResetArrows(c);
         Debug.Log("Falling from climbing");
         c.StateList.RemoveAt(c.StateList.Count - 1);
         //Add the falling state
         States nextState = new FallingState(1);
         //States nextState = new FallingState(1);
         nextState.index = c.StateList.Count + 1;
         c.StateList.Add(nextState);
     }
     else if (input.jumpPressed && input.jumpReleased)
     {
         VirtualJoystick.ResetArrows(c);
         Debug.Log("Transition to jump state");
         c.StateList.RemoveAt(c.StateList.Count - 1);
         //Add the falling state
         States nextState = new JumpingState();
         //States nextState = new FallingState(1);
         nextState.index = c.StateList.Count + 1;
         c.StateList.Add(nextState);
     }
     else if (input.xInput < 0 && (Mathf.Abs(bottomNode.position.y - c.transform.position.y) < minimumDifference ||
                                   c.transform.position.y < bottomNode.position.y))
     {
         Debug.Log("X input down");
         VirtualJoystick.ResetArrows(c);
         //If the character is closer to the bottom node and is trying to go down,
         //transition to idle state
         c.StateList.RemoveAt(c.StateList.Count - 1);
         c.BlockInputs();
         //Add the falling state
         //States nextState = new LandState();
         States nextState = new FallingState(1);
         nextState.index = c.StateList.Count + 1;
         c.StateList.Add(nextState);
     }
     //else if(Mathf.Abs(topNode.position.y - c.transform.position.y) < minimumDifference || c.transform.position.y > topNode.position.y)
     //{
     //    Debug.Log("reached top");
     //    VirtualJoystick.ResetArrows(c);
     //    //Player state is set to falling if he attempts to go beyond the ladder proximity
     //    c.StateList.RemoveAt(c.StateList.Count - 1);
     //    c.currentJumpSpeed = 0;
     //    //Add the falling state
     //    States nextState = new FallingState(1);
     //    //States nextState = new FallingState(1);
     //    nextState.index = c.StateList.Count + 1;
     //    c.StateList.Add(nextState);
     //}
 }
 private void UpdateAnimationIfChanged(MovementState priorMovementState, JumpingState priorJumpingState)
 {
     // If the character is or was jumping, the jump start or stop animation takes priority over changes in
     // running / walking.
     if (JumpingState != priorJumpingState)
     {
         ApplyJumpAnimation();
     }
     else if (IsGroundedAndMovementStateChanged(priorMovementState))
     {
         ApplyMovementAnimation();
     }
 }
 public void StopJump()
 {
     //make sure that we are in the jump animation
     if (X8Animator.GetBool("Jump") == true)
     {
         X8Animator.SetBool("Jump", false);
     }
     //make sure that we are in the jump state
     if (PlayerJumpState == JumpingState.IsJumping)
     {
         PlayerJumpState = JumpingState.NotJumping;
     }
 }
    public void Execute(Player player)
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            JumpingState jumpingState = new JumpingState();
            jumpingState.Enter(player);
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            DuckingState duckingState = new DuckingState();
            duckingState.Enter(player);
        }
    }
Example #10
0
    //RaycastHit2D[] info;
    public override void UpdateState(Character c, UserInput input, RaycastHit2D[] info)
    {
        this.info = info;
        base.UpdateState(c, input, info);
        //Debug.Log("Idle state updating");
        c.currentLinearSpeed = input.xInput * c.maxSpeed * GameManager.Instance.DeltaTime * GameManager.Instance.DeltaTime;

        if (c.StateList.Count == index)
        {
            //Check if character is within the ladder's proximity
            //Ladder can only be climbed when the character is idle
            contactWithLadder = CheckLadderProximity();

            //Audio
            c.SetSoundEffect();
            //animation
            AnimateState(c);
        }

        //State Exit conditions
        if (input.xInput != 0 && c.StateList.Count == index)
        {
            //Debug.Log("Running");
            //c.State = null;
            //c.State = new RunningState();
            //Debug.Log("runnnn");
            States nextState = new RunningState();
            nextState.index = c.StateList.Count + 1;
            c.StateList.Add(nextState);
        }

        if (input.jumpPressed && c.StateList.Count == index)
        {
            //c.State = null;
            //c.State = new JumpingState();
            States nextState = new JumpingState();
            nextState.index = c.StateList.Count + 1;
            c.StateList.Add(nextState);
        }

        //Shifting to climbing state
        if (contactWithLadder && input.climbPressed && c.StateList.Count == index)
        {
            Debug.Log("climbing state initiated");
            States nextState = new ClimbingState(ladder, c);
            nextState.index = c.StateList.Count + 1;
            c.StateList.Add(nextState);
        }
    }
        private void ChangeObjectState(object sender, System.Windows.RoutedEventArgs e)
        {
            IObjectState objectState;

            if (_flag)
            {
                objectState = new FlyingState();
            }
            else
            {
                objectState = new JumpingState();
            }

            _flag = !_flag;
            _myObject.ChangeState(objectState);
            ExampleBlock.Text += "State changed.\n";
        }
Example #12
0
 public void JumpingStateTransition()
 {
     if (!(peach.PowerUpState is DeadState))
     {
         if (peach.PowerUpState is StandardState)
         {
             sound = peach.Content.Load <SoundEffect>("Sound Effects/Peach Jumps");
         }
         else
         {
             sound = peach.Content.Load <SoundEffect>("Sound Effects/Peach Jumps Super");
         }
         sound.Play();
         var state = new JumpingState(this, peach);
         peach.ActionState = state;
         peach.Sprite      = PeachSpriteFactory.Instance.FactoryMethod(peach);
     }
 }
Example #13
0
        public void DoCollision(IEntity entity)
        {
            this.Sprite.RectangleTexture.SetData <Color>(new Color[] { Color.YellowGreen });
            AABB peachBox = BoundingBox();
            AABB otherBox = entity.BoundingBox();

            if (entity is Goomba || entity is Bowser)
            {
                if (entity is Bowser bowser && bowser.EnemyState is DeadBowserState)
                {
                    if (!(this.ActionState is FallingState || this.ActionState is JumpingState))
                    {
                        bowser.Sprite.Velocity = new Vector2(this.Sprite.Velocity.X, bowser.Sprite.Velocity.Y);
                        IdleTransition();
                        Sprite.CurrentLocation -= new Vector2(peachBox.Right - otherBox.Left + 1, Constants.ZERO);
                    }
                    else if (!(this.PowerUpState is StarState))
                    {
                        TakeDamageTransition();
                    }
                }
                else if (peachBox.Bottom - otherBox.Top <= 10 && !(PowerUpState is StarState || PowerUpState is DeadState))
                {
                    PlayerStats.Score += 100;
                    KillGoomba.Play();
                    ActionState             = new JumpingState(ActionState, this);
                    Sprite                  = PeachSpriteFactory.Instance.FactoryMethod(this);
                    Sprite.Velocity         = new Vector2(Sprite.Velocity.X, -400f); // override jump vy
                    Sprite.CurrentLocation -= new Vector2(Constants.ZERO, peachBox.Bottom - otherBox.Top + 1);
                }
                else
                {
                    if (PowerUpState is StarState)
                    {
                        PlayerStats.Score += 100;
                    }
                    TakeDamageTransition();
                }
            }
Example #14
0
    // FixedUpdate is called once per physics calculation
    private void FixedUpdate()
    {
        int inputX = getInputX();
        int inputY = getInputY();

        CheckSpriteDirectionChange(inputX);

        Vector2 moveDirection = body.velocity;

        if (inputX != 0)
        {
            moveDirection.x = Mathf.Lerp(body.velocity.x, SPEED * inputX, MOVE_INERTIA);
            UpdateWalkSprite(movingState == MovingState.STILL);
            if (movingState == MovingState.STILL)
            {
                movingState = MovingState.MOVING_LR;
            }
        }
        else
        {
            if (movingState == MovingState.MOVING_LR)
            {
                movingState           = MovingState.STILL;
                spriteRenderer.sprite = player_still;
            }
        }

        if (inputY != 0 && jumpingState == JumpingState.NO_JUMP && IsGrounded())
        {
            moveDirection.y = (JUMP_SPEED * inputY);
            jumpingState    = JumpingState.JUMP;
        }
        else if (jumpingState == JumpingState.JUMP && IsGrounded())
        {
            jumpingState = JumpingState.NO_JUMP;
        }
//        body.AddForce(moveDirection, ForceMode2D.Impulse);
        body.velocity = moveDirection;
    }
        //stops the phase ability
        //!checks if to see if the player is currenty jumping



        public bool IsJumping()
        {
            if (StateInfo.IsName("JumpUp"))
            {
                PlayerJumpState = JumpingState.IsJumping;
                isGrounded      = false;

                if (StateInfo.normalizedTime > .86f)
                {
                    X8Animator.SetBool("Jump", false);
                }
                else
                {
                    X8Animator.SetBool("Jump", true);
                }

                return(true);
            }


            PlayerJumpState = JumpingState.NotJumping;
            return(false);
        }
        public X8Timer ShootTimer = new X8Timer(.5f);          //this will time how longer the player faces the recticle
        void Start()
        {
            innerShield = gameObject.GetComponentInChildren <RaydraShield>(); //!search for the sheild in the children of the parent object

            _myCamera = this.GetComponentInChildren <Camera>();               //get the camera that is connected to this game object
            bool ScoreMode = false;                                           //initally we are not in score mode

            //!the player info that unity will keep tract of
            p_fCameraAngleTheta        = 43f;                              //!initialize the angle that player if facing
            p_fCameraAnglePhi          = 45f;                              //!The camera is initially yyyyin this state
            p_fPlayerToFocusAngleTheta = 43f;                              //!initialize the angle that player if facing
            p_fPlayerToFocusAnglePhi   = 45f;                              //!//!initialize the angle that player if facing in the upward direction
            p_fJumpVelocity            = .40f;                             //!initialize the upward jump force
            ForceOfGravity             = 1f / 60f;                         //!this will have a unit per second force of gravity, in the downward direction
            p_fOrientationAngle        = 90f;                              //!Angle that the player is facing in degrees
            p_v3OrientationVect        = new Vector3(0, 0, 1f);            //!Direction player is facing represented as an angle
            p_v3PlayerToFocusVect      = new Vector3(0, 0, 0);             //!The vector the represents the direction the camera if facing
            p_v3PlayerToCameraVect     = new Vector3(0, 0, 0);             //!The Vector Data the represent the player to camera direction
            PlayerMovementState        = MovingState.IsStandingStill;      //!Intially the player is not moving
            PlayerJumpState            = JumpingState.NotJumping;          //!initlialize the the player is not jumping
            PlayerTackleHitState       = TackeHitState.NoContact;          //!Initial the tackle state of the player
            PlayerTackleState          = TackleState.IsNotTackling;        //!Initial the tackle state of the player
            PlayerAttackState          = AttackMode.NotFiringAbility;      //!Initial the shoot state of the player
            PlayerRaydraState          = RaydraState.NotInRaydraMode;      //!initailly the player is not in Raydra Mode
            PlayerCameraState          = CameraPerspective.Normal;         //!initially the camera to do nothing
            PlayerPhaseState           = PhaseState.IsNotPhasing;
            PlayerBallThrowState       = BallThrowingState.NotBeingThrown; //!Initial the vertical state of the player
            PlayerBallPossessionState  = BallPossessionState.HasBall;      //!Initial the Possession State of the player                                                         //	PlayerMotionVector = new Vector3 (this.transform.position.x,.transform.position.y,playerData.transform.position.z);
            p_v3PlayerVectorDirection  = Vector3.zero;                     //! This is direction that te player is headed as a vector
            _armWeapon    = this.GetComponentInChildren <RaydraWeapon>();  //!reference to the arm weapon on the player which is null to begin with
            p_bFacePlayer = false;                                         //! variable that determines weather or not to face the player, this variable determine weather or not this medthod is recursive
            p_fMass       = 0f;                                            //!initialize the mass of the player
            p_StateTime   = 0f;                                            // Time elasped in current state
            p_Collider    = null;                                          //initialize the first collider connect to this body
            pRidgidBody   = null;


            Controls = GetComponent <RaydraControls>();
            if (CameraFocusOverHead != null)
            {
                p_v3PlayerToCameraVect = CameraFocusOverHead.transform.position - _myCamera.transform.position;
            }
            p_fCameraAnglePhi          = Vector3.Angle(new Vector3(0, 1, 0), p_v3PlayerToCameraVect);
            p_fCameraAngleTheta        = Vector3.Angle(new Vector3(1, 0, 0), p_v3PlayerToCameraVect);
            p_fPlayerToFocusAnglePhi   = Vector3.Angle(new Vector3(0, 1, 0), p_v3PlayerToFocusVect);
            p_fPlayerToFocusAngleTheta = Vector3.Angle(new Vector3(1, 0, 0), p_v3PlayerToFocusVect);
            X8Animator = GetComponent <Animator>();
            isGrounded = false;
            if (p_v3PlayerToFocusVect.z < 0)
            {
                p_fPlayerToFocusAngleTheta = 360 - p_fPlayerToFocusAngleTheta; //make sure that the angle is at the correct corridinate
            }
            if (p_v3PlayerToCameraVect.z < 0)
            {
                p_fCameraAngleTheta = 360 - p_fCameraAngleTheta; //make sure that the angle is at the correct corridinate
            }
            TheBall    = FindObjectOfType <RaydraCellz>();
            X8Animator = GetComponent <Animator>(); //get the reference to the animator

            PlayerMovementState = MovingState.IsStandingStill;

            EnemyAI = GetComponent <Ai>(); //get the ai script attached to the player (if there is one)

            if (EnemyAI != null)
            {
                Debug.Log("enemy AI" + EnemyAI.ToString());
            }
        }
Example #17
0
    // Start is called before the first frame update
    void Start()
    {
        _stateMachine = new StateMachine();

        mStandCollider    = transform.Find("Stand Collider").gameObject;
        mSlideCollider    = transform.Find("Slide Collider").gameObject;
        mPlatformCollider = transform.Find("Platform Collider").gameObject;

        //ColliderBridge cb = mPlatformCollider.AddComponent<ColliderBridge>();
        //cb.Initialize(this);

        //This supposed to fix the raycast issue
        Physics2D.queriesStartInColliders = false;
        collider = GetComponent <Collider2D>();

        run = new RunningState(this, _stateMachine);
        //charge = new ChargingState(this, _stateMachine);
        jump         = new JumpingState(this, _stateMachine);
        descend      = new DescendingState(this, _stateMachine);
        ultraJump    = new UltraJumpState(this, _stateMachine);
        powerDescend = new PowerDescendState(this, _stateMachine);
        slide        = new SlideState(this, _stateMachine);
        die          = new DyingState(this, _stateMachine);

        mRigidBody2D = GetComponent <Rigidbody2D>();

        //AudioManager.instance.PlayMusicInLoop("footsteps");

        worldIndex = m_Scene.GetIndex();

        mScore = m_Scene.GetScore();

        isShieldActive = false;
        mIsDead        = false;



        //PlayerMovementManager.SetInstance(worldIndex, this);

        mPlayerSprite = gameObject.GetComponentInChildren <PlayerSprite>();


        mAnimator = GetComponentInChildren <Animator>();

        //DontDestroyOnLoad(mAnimator);


        mAnimator.SetInteger("State", (int)PlayerAnimation.PlayerRunning);

        _stateMachine.Initialize(run);

        //--Sign as a listener to swipe down event
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_IO_SWIPE_DOWN, Instance_onSwipeDownEvent);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_IO_TAP, Instance_onSwipeUpEvent);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_PLAYER_COLLECTED_FREEZE, OnCollectedFreeze);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_PLAYER_COLLECTED_SHIELD, OnCollectedShield);

        m_Scene.GetServiceManager().CallActionWhenServiceIsLive(ApplicationConstants.SERVICE_LOCAL_LEVEL_BUILDER, () =>
        {
            mLocalLevelBuilder = m_Scene.GetServiceManager().GetService <LocalLevelBuilder_v2>(ApplicationConstants.SERVICE_LOCAL_LEVEL_BUILDER);
        });
    }
 // Use this for initialization
 private void Awake()
 {
     walkingState  = new WalkingState(this);
     jumpingState  = new JumpingState(this);
     grabblerState = new GrabblerState(this);
 }
    protected override void Update()
    {
        if (currentState.AllowJumping() && Input.GetAxis("Jump") > 0.1)
        {
            float jumpForce = Mathf.Sqrt(2 * -gravity * jumpHeight);
            velocity.y = jumpForce;
            SetState(JumpingState.Instance());
        }

        if (!onGround && velocity.y < 0)
        {
            SetState(FallingState.Instance());
        }

        float horizontal          = Input.GetAxis("Horizontal");
        float vertical            = Input.GetAxis("Vertical");
        float strafe              = 0f;
        bool  applyGroundFriction = true;

        if (Math.Abs(horizontal) > AXIS_DEADZONE)
        {
            if (currentState.AllowRunning())
            {
                strafe = horizontal;
                SetState(RunningState.Instance());

                velocity.x          = horizontalSpeed * strafe;
                applyGroundFriction = false;
            }
            else if (currentState.AllowAirControl())
            {
                strafe      = horizontal;
                velocity.x += strafe * airControlHorizontalAcceleration * Time.deltaTime * 1.0f / 0.999f /*counter-drag*/;
            }
        }

        if (Math.Abs(velocity.x) > horizontalSpeed)
        {
            velocity.x = horizontalSpeed * Math.Sign(velocity.x);
        }

        if (currentState.AllowCrouching() && vertical < -AXIS_DEADZONE)
        {
            SetState(CrouchingState.Instance());
        }
        else if (onGround)
        {
            if (strafe == 0f)
            {
                SetState(IdleState.Instance());
            }
            else
            {
                SetState(RunningState.Instance());
            }
        }

        if (applyGroundFriction)
        {
            if (onGround)
            {
                velocity.x *= 0.85f;
            }
            else
            {
                velocity.x *= 0.999f;
            }
        }

        currentState.Update(gameObject, this);

        base.Update();
    }