public void Init(PlayerController pl)
    {
        player          = pl;
        blinkController = player.GetComponent <BlinkController>();

        animator = player.GetComponent <Animator>();

        hexagons = new List <HexagonController>();

        specialAttackDetector = player.specialDetector;
        specialAttackDetector.GetComponent <PlayerSpecialAttackDetector>().Blackboard = this;
        specialAttackDetector.GetComponent <SphereCollider>().radius = player.specialAttackAffectationRadius;

        dashPSRotator = player.transform.Find("ParticleSystems/DashPSRotation");

        if (InputManager.Devices.Count >= player.Id)
        {
            controller = InputManager.Devices[player.Id - 1];
        }

        spawningState        = new PlayerSpawningState();
        idleState            = new PlayerIdleState();
        longIdleState        = new PlayerLongIdleState();
        movingState          = new PlayerMovingState();
        dashingState         = new PlayerDashingState();
        speedBumpState       = new PlayerSpeedBumpState();
        specialState         = new PlayerSpecialState();
        receivingDamageState = new PlayerReceivingDamageState();
        pushedState          = new PlayerPushedState();
        fallingState         = new PlayerFallingState();
        dyingState           = new PlayerDyingState();
        blockedState         = new PlayerBlockedState();
        invisibleState       = new PlayerInvisibleState();
        levelClearedState    = new PlayerLevelClearedState();

        spawningState.Init(this);
        idleState.Init(this);
        longIdleState.Init(this);
        movingState.Init(this);
        dashingState.Init(this);
        speedBumpState.Init(this);
        specialState.Init(this);
        receivingDamageState.Init(this);
        pushedState.Init(this);
        fallingState.Init(this);
        dyingState.Init(this);
        blockedState.Init(this);
        invisibleState.Init(this);
        levelClearedState.Init(this);

        string playerStr = "";

        switch (player.Id)
        {
        case 1: playerStr = "P1"; break;

        case 2: playerStr = "P2"; break;
        }

        moveHorizontal = playerStr + "_Horizontal";
        moveVertical   = playerStr + "_Vertical";
        aimHorizontal  = playerStr + "_AimHorizontal";
        aimVertical    = playerStr + "_AimVertical";
        fire           = playerStr + "_Fire";
        dash           = playerStr + "_Dash";
        special        = playerStr + "_Special";
        greenButton    = playerStr + "_Green";
        redButton      = playerStr + "_Red";
        blueButton     = playerStr + "_Blue";
        yellowButton   = playerStr + "_Yellow";

        playerRayCastMask  = LayerMask.GetMask(playerStr + "RayCast");
        playerPhysicsLayer = LayerMask.NameToLayer("Player");
        enemyPhysicsPlayer = LayerMask.NameToLayer("Enemy");

        ResetLifeVariables();
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        //ゲーム中のコードです
        switch (playerState)
        {
        //メイン画面スタート時の処理です
        case PlayerState.Start:
            //歩行していません
            wakingFlag = false;
            //プレイヤー子のオブジェクトを非表示にします
            player_Ko.SetActive(false);
            break;

        //メイン画面プレイ中の処理です
        case PlayerState.PlayStage:
        {
            //歩行しています
            wakingFlag = true;

            //(移動用)のリジットボディのベロシティーを取得します
            var velocity = rigidbody.velocity;
            //ボックスコライダー2Dを取得します
            //var boxCollider2d = gameObject.GetComponent<BoxCollider2D>();
            ////ボックスコライダー2DのSIZEを取得します
            //Vector2 boxColliderSize = boxCollider2d.size;
            //ボックスコライダー2DのSIZEを初期化します
            //boxColliderSize = new Vector2(0.4f, 0.5f);
            ////ボックスコライダー2DのSizeを格納します
            //boxCollider2d.size = boxColliderSize;

            //メイン画面プレイ中のプレイヤーのステータスの処理です
            switch (nowPlayerState)
            {
            //通常状態
            case NowPlayerState.NormalMoad:
            {
                //キャラクターのスプライトを設定します
                GetComponent <SpriteRenderer>().sprite = slimeSprite[0];
                //右移動を設定
                velocity.x = moveSpeed;

                //ジャンプボタンが押された場合
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    if (jampingFrag == false)
                    {
                        wakingFlag  = false;
                        jampingFrag = true;
                        velocity.y  = jumpSpeed;
                    }
                }
                animatorComponent.SetBool("Jamp", jampingFrag);
                playerSte = 0;
            }
            break;

            //パワーモード
            case NowPlayerState.PowerMoad:
            {
                //キャラクターのスプライトを設定します
                GetComponent <SpriteRenderer>().sprite = slimeSprite[1];
                //アニメーションの「PowerMode」を設定します
                animatorComponent.SetBool("JampModeFlag", false);
                animatorComponent.SetBool("PowerModeFlag", true);

                //右移動を設定
                velocity.x = moveSpeed;
                //Aボタンが押された場合
                //スペシャルモード
                if (Input.GetKeyDown(KeyCode.A))
                {
                    aninetionrosTime += aninetionrosTimeMax;
                    //アタックフラグをtrue(可能)状態に設定します
                    attackFlag = true;
                    //アタック状態時間を設定します
                    attackTime = attackTimeValue;
                    //プレイヤーのステータスをアタックモードに設定します
                    playerSpecialState = PlayerSpecialState.AttackMode;
                }
                //ジャンプボタンが押された場合
                if (Input.GetKeyDown(KeyCode.Space) && !attackFlag)
                {
                    if (jampingFrag == false)
                    {
                        wakingFlag  = false;
                        jampingFrag = true;
                        velocity.y  = jumpSpeed;
                    }
                }

                //アタックモード
                switch (playerSpecialState)
                {
                case PlayerSpecialState.AttackMode:
                {
                    if (attackFlag == true)
                    {
                        aninetionrosTime -= Time.deltaTime;
                        animatorComponent.SetBool("AttackFlag", true);
                        jampingFrag = false;
                        if (aninetionrosTime <= 0)
                        {
                            //var boxCollider2d = gameObject.GetComponent<BoxCollider2D>();
                            //Vector2 boxColliderSize = boxCollider2d.size;
                            //boxColliderSize = new Vector2(2.25f, 0.4f);
                            //boxCollider2d.size = boxColliderSize;
                            player_Ko.SetActive(true);
                            attackTime -= Time.deltaTime;
                            //右移動を設定
                            velocity.x = moveSpeed;

                            if (jampingFrag == true)
                            {
                                velocity.y = -5;
                            }

                            if (attackTime < 0)
                            {
                                attackFlag = false;
                            }
                        }
                    }
                    else if (attackFlag == false)
                    {
                        nowPlayerState     = NowPlayerState.PowerMoad;
                        playerSpecialState = PlayerSpecialState.None;
                        animatorComponent.SetBool("AttackFlag", false);
                        player_Ko.SetActive(false);
                    }
                }
                break;
                }
                playerSte = 1;
            }
            break;

            //ジャンプモード
            case NowPlayerState.JampMoad:
            {
                GetComponent <SpriteRenderer>().sprite = slimeSprite[2];
                animatorComponent.SetBool("PowerModeFlag", false);
                animatorComponent.SetBool("JampModeFlag", true);
                //右移動を設定
                velocity.x = moveSpeed;

                //ジャンプボタンが押された場合
                if (Input.GetKey(KeyCode.A))
                {
                    animatorComponent.SetBool("DashFlag", true);
                    //右移動を設定
                    velocity.x = moveSpeed * 1.65f;
                }
                else if (Input.GetKeyUp(KeyCode.A))
                {
                    animatorComponent.SetBool("DashFlag", false);
                }
                //ジャンプボタンが押された場合
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    if (jampingFrag == false)
                    {
                        wakingFlag  = false;
                        jampingFrag = true;
                        velocity.y  = jumpSpeed;
                    }
                }
                playerSte = 2;
            }
            break;
            }
            //速度を更新
            rigidbody.velocity = velocity;
        }
        break;

        case PlayerState.Gameover:
            if (playerSte == 0)
            {
                animatorComponent.SetBool("LifeFlag", false);
            }
            else if (playerSte == 1)
            {
                animatorComponent.SetBool("LifeFlag", false);
            }
            else if (playerSte == 2)
            {
                animatorComponent.SetBool("LifeFlag", false);
            }
            Debug.Log("playerSte= " + playerSte);
            break;

        case PlayerState.Gameclear:
        {
            var velocity = rigidbody.velocity;
            //右移動を設定
            velocity.x = moveSpeed;
            //速度を更新
            rigidbody.velocity = velocity;
        }
        break;
        }
    }
    //Unity methods
    void Awake()
    {
        Debug.Log("Player " + playerId + " created.");
        rend = GetComponentInChildren<Renderer>();
        ctrl = GetComponent<CharacterController>();
        voxelization = GetComponent<VoxelizationClient>();

        spawningState = new PlayerSpawningState();
        idleState = new PlayerIdleState();
        longIdleState = new PlayerLongIdleState();
        movingState = new PlayerMovingState();
        dashingState = new PlayerDashingState();
        specialState = new PlayerSpecialState();
        swingingState = new PlayerSwingingState();
        receivingDamageState = new PlayerReceivingDamageState();
        fallingState = new PlayerFallingState();
        dyingState = new PlayerDyingState();

        spawningState.Init(this);
        idleState.Init(this);
        longIdleState.Init(this);
        movingState.Init(this);
        dashingState.Init(this);
        specialState.Init(this);
        swingingState.Init(this);
        receivingDamageState.Init(this);
        fallingState.Init(this);
        dyingState.Init(this);

        currentState = spawningState;

        string player = "";
        switch (playerId)
        {
            case 1: player = "P1"; break;
            case 2: player = "P2"; break;
        }

        moveHorizontal = player + "_Horizontal";
        moveVertical = player + "_Vertical";
        aimHorizontal = player + "_AimHorizontal";
        aimVertical = player + "_AimVertical";
        fire = player + "_Fire";
        dash = player + "_Dash";
        special = player + "_Special";

        playerRayCastMask = LayerMask.GetMask(player + "RayCast");
        animator = GetComponent<Animator>();
    }