示例#1
0
    public override void Awake()
    {
        base.Awake();
        characterController = GetComponent<CharacterController>();
        baseStepOffset = characterController.stepOffset;
        baseRadius = characterController.radius;
        baseHeight = characterController.height;
        baseSkinWidth = characterController.skinWidth;

        crouch = GetComponent<Crouch>();
    }
示例#2
0
 public virtual void Process()
 {
     if (Crouch.Process())
     {
     }
     else if (Prone.Process())
     {
     }
     else if (Sprint.Process())
     {
     }
 }
示例#3
0
    // Start is called before the first frame update
    void Start()
    {
        //Makes sure that there's an audio clip on the audio source, and makes sure it's playable.
        audioData      = GetComponent <AudioSource>();
        audioData.clip = Pavement;
        audioData.Play();
        audioData.loop = true;
        audioData.Pause();

        //Gets the crouch & zone component from the parent.
        cro  = GetComponentInParent <Crouch>();
        zone = GetComponentInParent <ZoneStatusUpdater>();
    }
示例#4
0
    public override void OnStateEnter()
    {
        _inputReader = stateMachine.GetComponent <InputReader>();
        _stats       = stateMachine.GetComponent <StatHolder>().held;
        _motor       = stateMachine.GetComponent <Motor>();
        _crouch      = stateMachine.GetComponent <Crouch>();
        _grounded    = stateMachine.GetComponent <Grounded>();
        _falldmg     = stateMachine.GetComponent <FallDamage>();

        #region change motor vals
        _motor.speed     = _stats.runSpeed;
        _motor.accelRate = _stats.runAccelRate;
        _motor.sprintHorizontalInputReductionMult = 1f;
        #endregion
    }
示例#5
0
    private void Awake()
    {
        inven = false;
        invLight.SetActive(false);
        movement = player.GetComponent <move>();

        //예진//
        crouch     = player.GetComponent <Crouch>();
        cubeCamera = player.transform.GetChild(0).gameObject;

        pick  = player.GetComponent <pickup>();
        rb    = player.GetComponent <Rigidbody>();
        point = GvrReticle.GetComponent <GvrReticlePointer>();

        total_weight = 0;
    }
示例#6
0
    public override void OnStateEnter()
    {
        _stats  = stateMachine.GetComponent <StatHolder>().held;
        _input  = stateMachine.GetComponent <InputReader>();
        _crouch = stateMachine.GetComponent <Crouch>();

        _motor = stateMachine.GetComponent <Motor>();
        //_motor.enabled = false;
        _motor.disabledWorkAround = true;

        // actually physics slide the player forward
        _slide          = stateMachine.GetComponent <Slide>();
        _slide.duration = _stats.slideLength;
        _slide.strength = _stats.slideStrength;
        _slide.enabled  = true;
    }
示例#7
0
    public override void OnStateEnter()
    {
        #region get comps
        _motor    = stateMachine.GetComponent <Motor>();
        _stats    = stateMachine.GetComponent <StatHolder>().held;
        _input    = stateMachine.GetComponent <InputReader>();
        _grounded = stateMachine.GetComponent <Grounded>();
        _jump     = stateMachine.GetComponent <Jump>();
        _crouch   = stateMachine.GetComponent <Crouch>();
        _collider = stateMachine.GetComponent <CapsuleCollider>();
        #endregion

        #region change motor vals
        _motor.speed     = _stats.crouchSpeed;
        _motor.accelRate = _stats.crouchAccelRate;
        #endregion
    }
    public override void OnStateEnter()
    {
        _input              = stateMachine.GetComponent <InputReader>();
        _stats              = stateMachine.GetComponent <StatHolder>().held;
        _motor              = stateMachine.GetComponent <Motor>();
        _grounded           = stateMachine.GetComponent <Grounded>();
        _edgeDetect         = stateMachine.GetComponent <EdgeDetect>();
        _edgeDetect.enabled = true;
        _climb              = stateMachine.GetComponent <Climb>();
        toggle              = false;
        _crouch             = stateMachine.GetComponent <Crouch>();
        _falldmg            = stateMachine.GetComponent <FallDamage>();

        #region change motor vals
        _motor.speed     = _stats.airSpeed;
        _motor.accelRate = _stats.airAccelRate;
        _motor.sprintHorizontalInputReductionMult = 1f;
        #endregion
    }
示例#9
0
    public override void OnStateEnter()
    {
        _motor    = stateMachine.GetComponent <Motor>();
        _grounded = stateMachine.GetComponent <Grounded>();
        _stats    = stateMachine.GetComponent <StatHolder>().held;
        _falldmg  = stateMachine.GetComponent <FallDamage>();
        _jump     = stateMachine.GetComponent <Jump>();
        _crouch   = stateMachine.GetComponent <Crouch>();

        _crouch.crouching = true;

        if (_falldmg.landingFirm)
        {
            _motor.accelMult = Vector3.zero;
            timeToExit       = 0.01f;

            _falldmg.landingFirm = false;
        }
        else if (_falldmg.landingHard)
        {
            _motor.accelMult = Vector3.zero;
            _motor.speed     = _stats.runSpeed * 0.6f;
            _motor.accelRate = _stats.runAccelRate * 0.6f;
            timeToExit       = 0.9f;

            _jump.disableOverride = true;

            _falldmg.landingHard = false;
        }
        else if (_falldmg.landingSplat)
        {
            _motor.accelMult = Vector3.zero;
            _motor.speed     = _stats.runSpeed * 0.2f;
            _motor.accelRate = _stats.runAccelRate * 0.2f;
            timeToExit       = 1.5f;

            _jump.disableOverride = true;

            _falldmg.landingSplat = false;
        }

        timer = 0;
    }
示例#10
0
    //Update checks player state, and set the flags
    //Update() is called later than FixedUpdate()
    void Update()
    {
        mouseTracker.Track(this.transform, cam.transform);

        //if player input attemps to jump this frame
        //Core point : the if doesnot check isJumping state, in this case you press jump when jumping, character will jump once it's grounded. It's like the pre-calculation.
        if (!callJump)
        {
            callJump = Input.GetButtonDown("Jump");
        }

        //if player just got grounded this frame
        if (!previouslyGrounded && controller.isGrounded)
        {
            //TODO shake
            PlayAudioClip(landSFX);
            nextStepPlace  += footStepLength;   //if not add one step, landing sound and a foot step sound will play at the same time(if character traveled more than one step dist in air)
            frameMovement.y = 0f;               //TODO what is this
            //isJumping = false;

            //TODO complementary code to fix jump crouch problem. This increases coupling.
            Crouch crouchAbility = GetComponent <Crouch>();
            if (crouchAbility != null && Input.GetButton("Crouch"))
            {
                characterState = CharacterState.Crouching;
                SetMoveSpeed(crouchAbility.crouchMoveSpeed, crouchAbility.crouchMoveSpeed);
            }
            else
            {
                characterState = CharacterState.Idle;
            }
        }

        //if player start jumping this frame
        if (previouslyGrounded && /*!isJumping*/ characterState != CharacterState.Jumping && !controller.isGrounded)
        {
            frameMovement.y = 0f;
        }

        previouslyGrounded = controller.isGrounded;
    }
示例#11
0
    protected override void Start()
    {
        base.Start();

        IdleState        = new Idle(this);
        MoveState        = new Move(this);
        JumpState        = new Jump(this);
        FallState        = new Fall(this);
        WallSlideState   = new WallSliding(this);
        CrouchState      = new Crouch(this);
        GroundPoundState = new GroundPound(this);

        growthFsm.AddToStateList((int)PlayerGrowthStates.SMALL, new Small(this, smallAnimations));
        growthFsm.AddToStateList((int)PlayerGrowthStates.BIG, new Big(this, bigAnimations));

        growthFsm.InitializeFSM((int)PlayerGrowthStates.SMALL);
        baseMovementFSM.InitializeFSM(IdleState);


        playerMoveProperties.CalculatePhysicsValues();
    }
示例#12
0
    private void initialize()
    {
        jump           = GetComponent <Jump>();
        walk           = GetComponent <PlayerWalk>();
        firePivot      = transform.FindChild("FirePivot");
        teleportable   = GetComponent <Teleportable>();
        dieAnim        = GetComponent <PlayerDieAnim>();
        crouch         = GetComponent <Crouch>();
        idle           = GetComponent <Idle>();
        lookDirections = GetComponent <LookDirections>();
        body           = GetComponent <ChipmunkBody>();

        rightFireDir.x = 1f;
        rightFireDir.y = -0.5f;
        leftFireDir.x  = -1f;
        leftFireDir.y  = -0.5f;
        fireDir        = rightFireDir;

        collisionGroupSkip = GetComponent <ChipmunkShape>().collisionGroup;
        // not sure if ok: all layers except Player's layer
        collisionLayersSkip = unchecked ((uint)(1 << KLayers.PLAYER));
        //collisionLayers = 0;
    }
示例#13
0
 private void Awake()
 {
     _playerCrouch   = GetComponent <Crouch>();
     _playerPosition = GetComponent <Transform>();
     _hit.SetActive(false);
 }
示例#14
0
    void Update()
    {
        Animator anim   = GetComponent <Animator>();
        Crouch   crouch = new Crouch();

        // WASD入力から、XZ平面(水平な地面)を移動する方向(velocity)を得ます
        velocity = Vector3.zero;

        if (Input.GetKey(KeyCode.W))
        {
            velocity.z += 1;
        }
        if (Input.GetKey(KeyCode.A))
        {
            velocity.x -= 1;
        }
        if (Input.GetKey(KeyCode.S))
        {
            velocity.z -= 1;
        }
        if (Input.GetKey(KeyCode.D))
        {
            velocity.x += 1;
        }

        currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
        if (currentBaseState.fullPathHash == stateIdle ||
            currentBaseState.fullPathHash == stateWalk ||
            currentBaseState.fullPathHash == stateJump ||
            currentBaseState.fullPathHash == stateRunningJump ||
            currentBaseState.fullPathHash == stateSlide ||
            currentBaseState.fullPathHash == stateCrouch ||
            currentBaseState.fullPathHash == stateCrouchWalk ||
            currentBaseState.fullPathHash == stateRun)
        {
            moveflg = true;
        }
        else
        {
            moveflg = false;
        }

        if ((Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D)) && moveflg == true) //方向キーを押しているとき(歩き)
        {
            if (crouch.CrouchJudge() == true && !Input.GetKey(KeyCode.LeftShift))                                                          //しゃがんでいてシフト(走りボタンが押されていないとき)
            {
                moveSpeed = crouchSpeed;                                                                                                   //移動速度にしゃがみ速度を代入
            }
            else//しゃがんでいないとき
            {
                moveSpeed = walkSpeed;               //移動速度に歩き速度を代入
                if (Input.GetKey(KeyCode.LeftShift)) //上記に加えさらにシフトキーを押しているとき(走り)
                {
                    moveSpeed = runSpeed;            //移動速度に走り速度を代入
                }
            }
        }
        else //移動しないとき
        {
            moveSpeed = 0.0f;//移動速度を元に戻す()
        }

        // 速度ベクトルの長さを1秒でmoveSpeedだけ進むように調整します
        velocity = velocity.normalized * moveSpeed * Time.deltaTime;

        anim.SetFloat("Speed", moveSpeed);//animatorにmoveSpeedを渡してSpeedに応じてアニメーション遷移

        // いずれかの方向に移動している場合
        if (velocity.magnitude > 0)
        {
            // プレイヤーの回転(transform.rotation)の更新
            // 無回転状態のプレイヤーのZ+方向(後頭部)を、
            // カメラの水平回転(refCamera.hRotation)で回した移動の反対方向(-velocity)に回す回転に段々(applySpeedずつ)近づけます
            transform.rotation = Quaternion.Slerp(transform.rotation,                                      //開始地点(今の地点)
                                                  Quaternion.LookRotation(refCamera.hRotation * velocity), //終了地点(カメラの水平方向の前方向とキャラの向きから算出)
                                                  applySpeed);                                             //振り向き速度

            // プレイヤーの位置(transform.position)の更新
            // カメラの水平回転(refCamera.hRotation)で回した移動方向(velocity)を足し込みます
            transform.position += refCamera.hRotation * velocity;
        }
    }
    //handy way to make sure there's nothing wrong
    public void InitializePlayer()
    {
        try
        {
            rb = GetComponent <Rigidbody>();
        }
        catch
        {
            rb = this.gameObject.AddComponent <Rigidbody>();
        }

        //set up ground component
        try
        {
            //moveComponent = move.GetComponent<PlayerMovementv3>();
            moveComponent = move.GetComponent <PlayerGroundMovement>();
        }
        catch
        {
            GameObject go = new GameObject();
            go.transform.parent   = transform;
            go.transform.position = transform.position;
            move = go;
            //move.AddComponent<PlayerMovementv3>();
            move.AddComponent <PlayerGroundMovement>();
            //moveComponent = move.GetComponent<PlayerMovementv3>();
            moveComponent = move.GetComponent <PlayerGroundMovement>();
            move.name     = "move";
        }

        playerMovementArray[0] = move;

        //set up grapple component
        try
        {
            grappleComponent = grapple.GetComponent <GrappleComponent>();
        }
        catch
        {
            GameObject go = new GameObject();
            go.transform.parent   = transform;
            go.transform.position = transform.position;
            grapple = go;
            grapple.AddComponent <GrappleComponent>();
            grappleComponent = grapple.GetComponent <GrappleComponent>();
            grapple.name     = "grapple";
        }

        grappleComponent.Initialize();
        playerMovementArray[1] = grapple;

        //set up crouch component
        try
        {
            crouchComponent = crouch.GetComponent <Crouch>();
        }
        catch
        {
            GameObject go = new GameObject();
            go.transform.parent   = transform;
            go.transform.position = transform.position;
            crouch = go;
            crouch.AddComponent <Crouch>();
            crouchComponent = crouch.GetComponent <Crouch>();
            crouch.name     = "crouch";
        }

        playerMovementArray[2] = crouch;

        //set up air component
        try
        {
            airComponent = air.GetComponent <PlayerAirMovement>();
        }
        catch
        {
            GameObject go = new GameObject();
            go.transform.parent   = transform;
            go.transform.position = transform.position;
            air = go;
            air.AddComponent <PlayerAirMovement>();
            airComponent = air.GetComponent <PlayerAirMovement>();
            air.name     = "air";
        }

        playerMovementArray[3] = air;



        for (int i = 0; i < playerMovementArray.Length; i++)
        {
            Debug.Log(playerMovementArray[i].name + " is in the player movement array");
        }


        SetMovementType("move");
    }
        public StateController <CharacterState, CharacterContext> BuildCharacterControllerImpl(StateControllerBuilder <CharacterState, CharacterContext> builder)
        {
            Builder = builder;
            InjectState(this);

            // Declare Smash Attacks
            SmashUp.Charge.Data.SmashAttack   = SmashAttack.Charge;
            SmashSide.Charge.Data.SmashAttack = SmashAttack.Charge;
            SmashDown.Charge.Data.SmashAttack = SmashAttack.Charge;

            SmashUp.Attack.Data.SmashAttack   = SmashAttack.Attack;
            SmashSide.Attack.Data.SmashAttack = SmashAttack.Attack;
            SmashDown.Attack.Data.SmashAttack = SmashAttack.Attack;

            // Ground Attacks
            new [] { Idle, Walk, CrouchStart, Crouch, CrouchEnd }
            // Smash Attacks
            .AddTransitions <CharacterState, CharacterContext>(context => {
                var input = context.Input;
                if (!input.Attack.WasPressed)
                {
                    return(null);
                }
                switch (input.Smash.Direction)
                {
                case Direction.Right:
                case Direction.Left:
                    return(SmashSide.Charge);

                case Direction.Up:
                    return(SmashUp.Charge);

                case Direction.Down:
                    return(SmashDown.Charge);
                }
                return(null);
            })
            // Tilt Attacks
            .AddTransitions <CharacterState, CharacterContext>(context => {
                var input = context.Input;
                if (!input.Attack.WasPressed)
                {
                    return(null);
                }
                switch (input.Movement.Direction)
                {
                case Direction.Right:
                case Direction.Left:
                    return(TiltSide);

                case Direction.Up:
                    return(TiltUp);

                case Direction.Down:
                    return(TiltDown);
                }
                return(Neutral);
            });
            SmashUp.Charge.AddTransitionTo(SmashUp.Attack);
            SmashDown.Charge.AddTransitionTo(SmashDown.Attack);
            SmashSide.Charge.AddTransitionTo(SmashSide.Attack);
            TiltDown.AddTransitionTo(Crouch, Input(i => i.Movement.Direction == Direction.Down));
            new[] { Neutral, TiltUp, TiltDown, TiltSide, SmashUp.Attack, SmashDown.Attack, SmashSide.Attack }
            .AddTransitionTo(Idle);

            new [] { Fall, Jump, JumpAerial }
            .AddTransitions(Land, ctx => ctx.IsGrounded)
            // Aerial Attacks
            .AddTransitions <CharacterState, CharacterContext>(context => {
                var input = context.Input;
                if (!input.Attack.WasPressed)
                {
                    return(null);
                }
                switch (input.Movement.Direction)
                {
                case Direction.Right:
                    return(context.Direction >= 0f ? AerialForward : AerialBackward);

                case Direction.Left:
                    return(context.Direction >= 0f ? AerialBackward : AerialForward);

                case Direction.Up:
                    return(AerialUp);

                case Direction.Down:
                    return(AerialDown);
                }
                return(AerialNeutral);
            });
            new[] { AerialForward, AerialBackward, AerialDown, AerialUp, AerialNeutral }
            .AddTransitions(AerialAttackLand, ctx => ctx.IsGrounded)
            .AddTransitionTo(Fall);
            AerialAttackLand.AddTransitionTo(Idle);

            // Aerial Movement
            new [] { Idle, Walk, Dash, Run, RunTurn, RunBrake, CrouchStart, Crouch, CrouchEnd, Shield.Main }
            .AddTransitions(JumpStart, ctx => ctx.Input.Jump.WasPressed && ctx.CanJump);
            new[] { JumpStart, JumpAerial }.AddTransitionTo(Jump);
            new[] { Jump, Fall }.AddTransitions(JumpAerial, ctx => ctx.Input.Jump.WasPressed && ctx.CanJump)
            .AddTransitions(EscapeAir, Input(i => i.Shield.WasPressed));
            Jump.AddTransition(Idle, ctx => ctx.NormalizedStateTime >= 1.0f && ctx.IsGrounded)
            .AddTransition(Fall, ctx => ctx.NormalizedStateTime >= 1.0f && !ctx.IsGrounded);
            EscapeAir.AddTransitionTo(FallHelpless);
            new[] { Fall, FallHelpless, EscapeAir }.AddTransitions(Land, ctx => ctx.IsGrounded);
            Land.AddTransitionTo(Idle);

            Func <Func <PlayerInputContext, DirectionalInput>, Func <CharacterContext, bool> >
            movementContext = func => {
                return(ctx => !DirectionInput(Direction.Down)(ctx) &&
                       Input(i => Mathf.Abs(func(i).Value.x) > DirectionalInput.DeadZone)(ctx));
            };

            // Running States
            Idle.AddTransition(Dash, movementContext(i => i.Smash));
            Dash.AddTransitionTo(Idle, DirectionInput(Direction.Neutral));
            new[] { Dash, RunTurn }.AddTransitionTo(Run);
            Run.AddTransition(RunBrake, DirectionInput(Direction.Neutral));
            Run.AddTransition(RunTurn,
                              ctx => !Mathf.Approximately(Mathf.Sign(ctx.Input.Movement.Value.x), Mathf.Sign(ctx.Direction)));
            RunBrake.AddTransitionTo(Idle);

            // Ground Movement
            new[] { Idle, Walk, Run }
            .AddTransitions(CrouchStart, DirectionInput(Direction.Down))
            .AddTransitions(Fall, ctx => !ctx.IsGrounded);

            Idle.AddTransition(Walk, movementContext(i => i.Movement));
            Walk.AddTransition(Idle, DirectionInput(Direction.Neutral));

            // Crouching States
            CrouchStart.AddTransitionTo(Crouch);
            CrouchEnd.AddTransitionTo(Idle);
            new[] { CrouchStart, Crouch, CrouchEnd }.AddTransitions(Fall, ctx => !ctx.IsGrounded);
            Crouch.AddTransition(CrouchEnd, Input(i => i.Movement.Direction != Direction.Down));

            // Ledge States
            new[] { Idle, Fall, FallHelpless }.AddTransitions(LedgeGrab, ctx => ctx.State.IsGrabbingLedge);
            LedgeGrab.AddTransitionTo(LedgeIdle);
            LedgeIdle.AddTransition(LedgeRelease, ctx => !ctx.State.IsGrabbingLedge)
            .AddTransition(LedgeClimb, DirectionInput(Direction.Up))
            .AddTransition(LedgeJump, ctx => ctx.Input.Jump.WasPressed && ctx.CanJump)
            .AddTransition(LedgeAttack, Attack());
            LedgeJump.AddTransitionTo(Jump);
            new[] { LedgeRelease, LedgeClimb, LedgeEscape, LedgeAttack }
            .AddTransitions(Idle, ctx => ctx.NormalizedStateTime >= 1.0f && ctx.IsGrounded)
            .AddTransitions(Fall, ctx => ctx.NormalizedStateTime >= 1.0f && !ctx.IsGrounded);

            // Shielding
            Idle.AddTransition(Shield.On, Input(i => i.Shield.Current));
            Shield.On.AddTransition(Shield.Perfect, ctx => ctx.State.IsHit)
            .AddTransitionTo(Shield.Main);
            Shield.Main.AddTransition(Shield.Broken, ctx => ctx.State.ShieldDamage <= 0)
            .AddTransition(Shield.Off, Input(i => !i.Shield.Current));
            Shield.Off.AddTransitionTo(Idle);
            new[] { Shield.Broken, Shield.Stunned, Idle }.Chain();

            // Rolls/Sidesteps
            Shield.Main
            .AddTransition(EscapeForward, ctx => {
                if (ctx.Direction > 0f)
                {
                    return(DirectionalSmash(Direction.Right)(ctx));
                }
                else
                {
                    return(DirectionalSmash(Direction.Left)(ctx));
                }
            })
            .AddTransition(EscapeBackward, ctx => {
                if (ctx.Direction > 0f)
                {
                    return(DirectionalSmash(Direction.Left)(ctx));
                }
                else
                {
                    return(DirectionalSmash(Direction.Right)(ctx));
                }
            })
            .AddTransition(Escape, DirectionInput(Direction.Down));
            new[] { Escape, EscapeForward, EscapeBackward }.AddTransitionTo(Shield.Main);

            Builder.WithDefaultState(Idle);
            BuildCharacterController();
            return(Builder.Build());
        }
 void Awake()
 {
     crouch = GetComponent <Crouch>();
 }
示例#18
0
 // Use this for initialization
 void Start()
 {
     text.SetActive(false);
     player = GameObject.FindGameObjectWithTag("Player");
     script = player.GetComponent <Crouch>();
 }
示例#19
0
 // Use this for initialization
 void Start()
 {
     _animator = GetComponent <Animator>();
     _crouch   = transform.parent.GetComponent <Crouch>();
 }
示例#20
0
文件: FPSJump.cs 项目: Thaon/IRNBRU
	// Use this for initialization
	void Start ()
    {
        m_crouchScript = GetComponent<Crouch>();
        m_CC = GetComponent<CharacterController>();
	}
示例#21
0
 void Awake()
 {
     move   = GetComponent <WalkAbs>();
     jump   = GetComponent <Jump>();
     crouch = GetComponent <Crouch>();
 }
示例#22
0
    //prob matrix nxn

    //v = colum vector (states) num at index is the value assosiated with state
    //I is identity matrix mxm
    //Gamma set to 1 (0-1) I set it 0 cancels prob matrix (means greedy)
    // P prob matrix all states in rows and colums
    //r is colum vector (size num of states) keeps track of current reward for all states


    // Start is called before the first frame update
    void Start()
    {
        jumping = gameObject.GetComponent <Jumping>();                   //adds a reference to the jumping script
        crouch  = gameObject.GetComponent <Crouch>();                    //adds a reference to the crouching script

        pMatrix = Matrix <float> .Build.Dense(numOfStates, numOfStates); //creates a probability matrix the size of the number of unique states

        identity = Matrix <float> .Build.DenseIdentity(numOfStates);     //creates a matrix the same size but as an identity matrix

        Debug.Log(identity);

        stateList = new List <State>();

        samples = new List <Samples>();

        states = Vector <float> .Build.Dense(numOfStates);            //creates an array/vector for storing the number of single states

        rewards = Vector <float> .Build.Dense(numOfStates);           //creates a vector that holds the reward for each state

        cumulativeRewards = Vector <float> .Build.Dense(numOfStates); //holds the sum of all rewards each state received


        //for (int i = 0; i < numOfStates; i++)
        //{
        //    states[i] = i;
        //}

        //sets all states to false for the start
        initialState.highJumping   = false;
        initialState.jumping       = false;
        initialState.ducking       = false;
        initialState.dead          = false;
        initialState.objectInfront = false;
        initialState.wideObject    = false;

        currentState = initialState;   //sets current state to blank

        State tempState = new State(); //holds all the unique states temporarily

        for (int a = 0; a < 2; a++)    //these for loops combine each state to get all unique possible states
        {
            tempState.highJumping = (a == 1);
            for (int b = 0; b < 2; b++)
            {
                tempState.jumping = (b == 1);
                for (int c = 0; c < 2; c++)
                {
                    tempState.ducking = (c == 1);
                    for (int d = 0; d < 2; d++)
                    {
                        tempState.dead = (d == 1);
                        for (int e = 0; e < 2; e++)
                        {
                            tempState.objectInfront = (e == 1);
                            for (int f = 0; f < 2; f++)
                            {
                                tempState.wideObject = (f == 1);
                                stateList.Add(tempState);
                            }
                        }
                    }
                }
            }
        }

        for (int i = 0; i < numOfStates; i++)// This for loop sets the reward/punish amount for each of the single states
        {
            //if (!stateList[i].dead && !stateList[i].objectInfront && !stateList[i].wideObject)
            //    rewards[i] += 3;
            //else if (stateList[i].objectInfront && !stateList[i].jumping)
            //    rewards[i] += -2;
            //else if (stateList[i].objectInfront && !stateList[i].ducking)
            //    rewards[i] += 1;
            //else if (stateList[i].dead)
            //    rewards[i] += -10;

            if (stateList[i].dead)//sets punish for death
            {
                rewards[i] += -30;
            }
            else
            {
                rewards[i] += 1;
            }
            if (stateList[i].ducking)//sets reward for ducking
            {
                rewards[i] += 1;
            }
            if (stateList[i].highJumping)//sets reward for highjump
            {
                rewards[i] += 5;
            }
            if (stateList[i].jumping)//sets reward for regular jump
            {
                rewards[i] += 10;
            }
            if (stateList[i].objectInfront)//sets punish for when a cactus is in front of AI
            {
                rewards[i] += -2;
            }
            else
            {
                rewards[i] += 1;
            }
            if (stateList[i].wideObject)//sets punish for when a double cactus is in from of AI
            {
                rewards[i] += -2;
            }
            else
            {
                rewards[i] += 1;
            }

            if (stateList[i].jumping && stateList[i].objectInfront)// sets reward for jumping when in front of cactus
            {
                rewards[i] += 10;
            }
            if (stateList[i].jumping && stateList[i].highJumping && stateList[i].wideObject)// sets reward for jumping when in front of double cactus
            {
                rewards[i] += 10;
            }

            if (!stateList[i].jumping && stateList[i].objectInfront)// sets punish for not jumping when in front of cactus
            {
                rewards[i] += -20;
            }
            if (!stateList[i].jumping && !stateList[i].highJumping && stateList[i].wideObject)// sets punish for not high jumping when in front of double cactus
            {
                rewards[i] += -20;
            }

            if (!stateList[i].ducking && !stateList[i].dead && !stateList[i].highJumping &&
                !stateList[i].jumping && !stateList[i].objectInfront && !stateList[i].wideObject)
            {
                rewards[i] += 25;// if surviving it will get rewarded
            }
        }
    }
 protected override void Init()
 {
     _rb = GetComponent <Rigidbody>();
     _footstepController = GetComponentInChildren <FootstepController>();
     _crouch             = GetComponentInChildren <Crouch>();
 }
 /// <summary>
 ///     Handles a change in PlayerKeyState.
 /// </summary>
 /// <param name="sender">Sender of the event.</param>
 /// <param name="e">Object containing information about the event.</param>
 public void Handle(object sender, KeyStateChangedEventArgs e)
 {
     if (Action != null && _check(e, Keys.Action))
     {
         Action.Handle(sender, e);
     }
     if (Crouch != null && _check(e, Keys.Crouch))
     {
         Crouch.Handle(sender, e);
     }
     if (Fire != null && _check(e, Keys.Fire))
     {
         Fire.Handle(sender, e);
     }
     if (Sprint != null && _check(e, Keys.Sprint))
     {
         Sprint.Handle(sender, e);
     }
     if (SecondaryAttack != null && _check(e, Keys.SecondaryAttack))
     {
         SecondaryAttack.Handle(sender, e);
     }
     if (Jump != null && _check(e, Keys.Jump))
     {
         Jump.Handle(sender, e);
     }
     if (LookRight != null && _check(e, Keys.LookRight))
     {
         LookRight.Handle(sender, e);
     }
     if (Handbrake != null && _check(e, Keys.Handbrake))
     {
         Handbrake.Handle(sender, e);
     }
     if (Aim != null && _check(e, Keys.Aim))
     {
         Aim.Handle(sender, e);
     }
     if (LookLeft != null && _check(e, Keys.LookLeft))
     {
         LookLeft.Handle(sender, e);
     }
     if (Submission != null && _check(e, Keys.Submission))
     {
         Submission.Handle(sender, e);
     }
     if (Walk != null && _check(e, Keys.Walk))
     {
         Walk.Handle(sender, e);
     }
     if (AnalogUp != null && _check(e, Keys.AnalogUp))
     {
         AnalogUp.Handle(sender, e);
     }
     if (AnalogDown != null && _check(e, Keys.AnalogDown))
     {
         AnalogDown.Handle(sender, e);
     }
     if (AnalogLeft != null && _check(e, Keys.AnalogLeft))
     {
         AnalogLeft.Handle(sender, e);
     }
     if (AnalogRight != null && _check(e, Keys.AnalogRight))
     {
         AnalogRight.Handle(sender, e);
     }
     if (Yes != null && _check(e, Keys.Yes))
     {
         Yes.Handle(sender, e);
     }
     if (No != null && _check(e, Keys.No))
     {
         No.Handle(sender, e);
     }
     if (CtrlBack != null && _check(e, Keys.CtrlBack))
     {
         CtrlBack.Handle(sender, e);
     }
 }
    public static Chart Convert(string path, int distancex = 50, int distancey = 35, int offsety = 10, int dynamic = 20, int repeat = 200)
    {
        path = path.Substring(0, path.LastIndexOf(@"\"));

        Chart synthSong = new Chart();

        if (File.Exists(path + @"\info.dat"))
        {
            //load song info
            string infoStr = "";
            using (StreamReader streamReader = new StreamReader(path + @"\info.dat"))
            {
                infoStr = streamReader.ReadToEnd();
            }
            //deserialize song info
            Info info = JsonConvert.DeserializeObject <Info>(infoStr);

            synthSong.Name          = (info._songName != "") ? info._songName : "N/A";
            synthSong.Author        = (info._songAuthorName != "") ? info._songAuthorName : "N/A";
            synthSong.BPM           = info._beatsPerMinute;
            synthSong.Offset        = (info._songTimeOffset < 0) ? info._songTimeOffset : synthSong.Offset = 0;
            synthSong.Beatmapper    = (info._levelAuthorName != "") ? info._levelAuthorName : "N/A";
            synthSong.BeatConverted = true;

            synthSong.Artwork        = "Default Artwork";
            synthSong.ArtworkBytes   = null;
            synthSong.AudioName      = "";
            synthSong.AudioData      = null;
            synthSong.AudioFrecuency = 0;
            synthSong.AudioChannels  = 2;
            synthSong.EditorVersion  = "1.8";
            synthSong.IsAdminOnly    = false;

            for (int i = 0; i < info._difficultyBeatmapSets[0]._difficultyBeatmaps.Count && i < 5; i++)
            {
                if (File.Exists(path + @"\" + info._difficultyBeatmapSets[0]._difficultyBeatmaps[i]._beatmapFilename))
                {
                    //load song difficulty
                    string beatSongStr = "";
                    using (StreamReader streamReader = new StreamReader(path + @"\" + info._difficultyBeatmapSets[0]._difficultyBeatmaps[i]._beatmapFilename))
                    {
                        beatSongStr = streamReader.ReadToEnd();
                    }

                    //deserialize song difficulty
                    BeatSong beatSong = JsonConvert.DeserializeObject <BeatSong>(beatSongStr);

                    //convert notes
                    Dictionary <float, List <Note> > track = new Dictionary <float, List <Note> >();
                    for (int j = 0; j < beatSong._notes.Count; j++)
                    {
                        int time = (int)Math.Round(beatSong._notes[j]._time * 60000f / info._beatsPerMinute);

                        float y_offset = 0;
                        float _offset  = 0;
                        switch (beatSong._notes[j]._cutDirection)
                        {
                        case 0: y_offset += dynamic * 0.01f; break;                                                     //up

                        case 1: y_offset -= dynamic * 0.01f; break;                                                     //down

                        case 2: _offset += dynamic * 0.01f; break;                                                      //left

                        case 3: _offset -= dynamic * 0.01f; break;                                                      //right

                        case 4: y_offset += (dynamic / sqrttwo) * 0.01f; _offset += (dynamic / sqrttwo) * 0.01f; break; //up_left

                        case 5: y_offset += (dynamic / sqrttwo) * 0.01f; _offset -= (dynamic / sqrttwo) * 0.01f; break; //up_right

                        case 6: y_offset -= (dynamic / sqrttwo) * 0.01f; _offset += (dynamic / sqrttwo) * 0.01f; break; //down_left

                        case 7: y_offset -= (dynamic / sqrttwo) * 0.01f; _offset -= (dynamic / sqrttwo) * 0.01f; break; //down_right
                        }

                        Vector3 pos = new Vector3(_offset + (distancex / 150f) * (beatSong._notes[j]._lineIndex - 1.5f), y_offset + (distancey / 100f) * (beatSong._notes[j]._lineLayer - 1f) + offsety * 0.01f, (time) * 0.02f);

                        Note.NoteType type;
                        if (beatSong._notes[j]._type == 0)
                        {
                            type = Note.NoteType.LeftHanded;
                        }
                        else if (beatSong._notes[j]._type == 1)
                        {
                            type = Note.NoteType.RightHanded;
                        }
                        else//bombs
                        {
                            continue;
                        }

                        string id = i.ToString() + "," + j.ToString();

                        Note note = new Note(pos, id, -1, type);

                        if (!track.ContainsKey(time))
                        {
                            List <Note> notes = new List <Note>();
                            notes.Add(note);

                            track.Add(time, notes);
                        }
                        else
                        {
                            track[time].Add(note);
                        }
                    }

                    //convert obstacles
                    List <Crouch> crouches = new List <Crouch>();
                    List <Slide>  slides   = new List <Slide>();
                    for (int j = 0; j < beatSong._obstacles.Count; j++)
                    {
                        int time     = (int)Math.Round(beatSong._obstacles[j]._time * 60000f / info._beatsPerMinute);
                        int duration = (int)Math.Round(beatSong._obstacles[j]._duration * 60000f / info._beatsPerMinute);

                        for (int n = time; n < time + duration; n += repeat)
                        {
                            if (beatSong._obstacles[j]._type == 1)
                            {
                                Crouch crouch = new Crouch();
                                crouch.time     = n;
                                crouch.position = new float[] { 0, 0, n * 18.75f };
                                crouches.Add(crouch);
                            }
                            else
                            {
                                Slide slide = new Slide();
                                slide.time     = n;
                                slide.position = new float[] { 0, 0, n * 18.75f };
                                if (beatSong._obstacles[j]._width == 1)
                                {
                                    if (beatSong._obstacles[j]._lineIndex == 0)//one on the left
                                    {
                                        slide.slideType = (Note.NoteType) 4;
                                    }
                                    else if (beatSong._obstacles[j]._lineIndex == 3)//one on the right
                                    {
                                        slide.slideType = (Note.NoteType) 2;
                                    }
                                    else//one middle right or middle left
                                    {
                                        slide.slideType = (Note.NoteType) 3;
                                    }
                                    slides.Add(slide);
                                }
                                else if (beatSong._obstacles[j]._width == 2)
                                {
                                    if (beatSong._obstacles[j]._lineIndex == 0)//two on the left
                                    {
                                        slide.slideType = (Note.NoteType) 1;
                                    }
                                    else if (beatSong._obstacles[j]._lineIndex == 1)//two in the middle
                                    {
                                        slide.slideType = (Note.NoteType) 3;
                                    }
                                    else if (beatSong._obstacles[j]._lineIndex == 2)//two on the right
                                    {
                                        slide.slideType = (Note.NoteType) 0;
                                    }
                                    slides.Add(slide);
                                }
                                else
                                {
                                    Crouch crouch = new Crouch();
                                    crouch.time     = n;
                                    crouch.position = new float[] { 0, 0, n * 18.75f };
                                    crouches.Add(crouch);
                                }
                            }
                        }
                    }

                    Beats defaultBeats = new Beats();
                    defaultBeats.Easy   = new Dictionary <float, List <Note> >();
                    defaultBeats.Normal = new Dictionary <float, List <Note> >();
                    defaultBeats.Hard   = new Dictionary <float, List <Note> >();
                    defaultBeats.Expert = new Dictionary <float, List <Note> >();
                    defaultBeats.Master = new Dictionary <float, List <Note> >();
                    defaultBeats.Custom = new Dictionary <float, List <Note> >();

                    synthSong.Track = defaultBeats;

                    Crouchs defaultCrouchs = new Crouchs();
                    defaultCrouchs.Easy   = new List <Crouch>();
                    defaultCrouchs.Normal = new List <Crouch>();
                    defaultCrouchs.Hard   = new List <Crouch>();
                    defaultCrouchs.Expert = new List <Crouch>();
                    defaultCrouchs.Master = new List <Crouch>();
                    defaultCrouchs.Custom = new List <Crouch>();

                    synthSong.Crouchs = defaultCrouchs;

                    Slides defaultSlides = new Slides();
                    defaultSlides.Easy   = new List <Slide>();
                    defaultSlides.Normal = new List <Slide>();
                    defaultSlides.Hard   = new List <Slide>();
                    defaultSlides.Expert = new List <Slide>();
                    defaultSlides.Master = new List <Slide>();
                    defaultSlides.Custom = new List <Slide>();

                    synthSong.Slides = defaultSlides;

                    if (info._difficultyBeatmapSets[0]._difficultyBeatmaps[i]._difficulty.Equals("Expert"))
                    {
                        synthSong.Track.Expert   = track;
                        synthSong.Crouchs.Expert = crouches;
                        synthSong.Slides.Expert  = slides;
                    }
                    else if (info._difficultyBeatmapSets[0]._difficultyBeatmaps[i]._difficulty.Equals("Hard"))
                    {
                        synthSong.Track.Hard   = track;
                        synthSong.Crouchs.Hard = crouches;
                        synthSong.Slides.Hard  = slides;
                    }
                    else if (info._difficultyBeatmapSets[0]._difficultyBeatmaps[i]._difficulty.Equals("Normal"))
                    {
                        synthSong.Track.Normal   = track;
                        synthSong.Crouchs.Normal = crouches;
                        synthSong.Slides.Normal  = slides;
                    }
                    else if (info._difficultyBeatmapSets[0]._difficultyBeatmaps[i]._difficulty.Equals("Easy"))
                    {
                        synthSong.Track.Easy   = track;
                        synthSong.Crouchs.Easy = crouches;
                        synthSong.Slides.Easy  = slides;
                    }
                    else
                    {
                        synthSong.Track.Master   = track;
                        synthSong.Crouchs.Master = crouches;
                        synthSong.Slides.Master  = slides;
                    }
                }
            }

            string[] filePaths = Directory.GetFiles(path);

            foreach (string filePath in filePaths)
            {
                if (filePath.Contains(".egg"))//replace the .egg file ending with .ogg
                {
                    string tmp = filePath.Substring(0, filePath.IndexOf(".egg")) + ".ogg";
                    if (!File.Exists(tmp))
                    {
                        File.Copy(filePath, tmp);
                    }
                }
            }
        }
        return(synthSong);
    }