示例#1
0
    private void Start()
    {
        gameOver    = false;
        _players[0] = playerOne;
        _players[1] = playerTwo;
        //flag that will trigger the walls to move
        _beginClosing = _timeRemaining * _timeToClose;
        //game begins in progress
        currentScenario = gameScenarios.notOver;

        playerOne.facingLeft = false;
        playerTwo.facingLeft = true;

        // Subscribe to the events from CollisionBehavior
        CollisionBehavior.AttackResolution += Attack;
        CollisionBehavior.KickResolution   += Kick;
    }
示例#2
0
    private void Update()
    {
        //Input reading goes here

        // Player One input reading
        // Movement and facing

        if (gameOver)
        {
            return;
        }

        playerOne.inputHorizontal      = Input.GetAxisRaw("P1Horizontal");
        playerOne.inputRightHorizontal = Input.GetAxisRaw("P1RightHorizontal");

        // P1Fire1: button 0 (A/bottom button on Xbone/360), left ctrl
        playerOne.inputAttackDown = Input.GetButtonDown("P1Fire1");
        playerOne.inputAttackHeld = Input.GetButton("P1Fire1");
        playerOne.inputAttackUp   = Input.GetButtonUp("P1Fire1");

        // P1Fire2: button 1 (B/right button on Xbone/360), left alt
        playerOne.inputDefendDown = Input.GetButtonDown("P1Fire2");
        playerOne.inputDefendHeld = Input.GetButton("P1Fire2");
        playerOne.inputDefendUp   = Input.GetButtonUp("P1Fire2");

        // P1Fire3: button 2 (X/left button on Xbone/360), left shift
        playerOne.inputRollDown = Input.GetButtonDown("P1Fire3");

        // P1Fire4: button 3 (Y/top button on Xbone/360), no key yet
        playerOne.inputKickDown = Input.GetButtonDown("P1Fire4");

        // Player Two input reading
        // Movement and facing
        playerTwo.inputHorizontal      = Input.GetAxisRaw("P2Horizontal");
        playerTwo.inputRightHorizontal = Input.GetAxisRaw("P2RightHorizontal");

        // P2Fire1: button 0, right ctrl
        playerTwo.inputAttackDown = Input.GetButtonDown("P2Fire1");
        playerTwo.inputAttackHeld = Input.GetButton("P2Fire1");
        playerTwo.inputAttackUp   = Input.GetButtonUp("P2Fire1");

        // P2Fire2: buton 1, right alt
        playerTwo.inputDefendDown = Input.GetButtonDown("P2Fire2");
        playerTwo.inputDefendHeld = Input.GetButton("P2Fire2");
        playerTwo.inputDefendUp   = Input.GetButtonUp("P2Fire2");

        // P2Fire3: button 2, right shift
        playerTwo.inputRollDown = Input.GetButtonDown("P2Fire3");

        // P2Fire4: button 3 (Y/top button on Xbone/360), no key yet
        playerTwo.inputKickDown = Input.GetButtonDown("P2Fire4");


        foreach (PlayerController player in _players)
        {
            // Rolling disables pretty much all inputs
            if (player.CanAct())
            {
                if (!player.movementDisabled)
                {
                    // Right stick determines the direction you're facing
                    if (player.inputRightHorizontal != 0.0f)
                    {
                        if (player.inputRightHorizontal < 0.0f && !player.facingLeft)
                        {
                            player.TurnAround(false);
                        }
                        else if (player.inputRightHorizontal > 0.0f && player.facingLeft)
                        {
                            player.TurnAround(false);
                        }
                    }

                    // Left stick determines motion
                    if (player.inputHorizontal != 0.0f && player.action != PlayerController.CharacterAction.GUARDING && player.action != PlayerController.CharacterAction.PARRYING)
                    {
                        PlayerController otherPlayer = _otherPlayer(player);

                        // TODO: Remove these magic numbers!
                        float personalDeltaX = player.transform.position.x - otherPlayer.transform.position.x;
                        //float leftWallDeltaX = player.transform.position.x - wallLeft.transform.position.x;

                        // Moving left
                        if (player.inputHorizontal < 0.0f)
                        {
                            // Make sure they're not against the left wall
                            if (player.leftWallDeltaX > _wallWidth)
                            {
                                // Make sure the other player is not left-adjacent to this one
                                // (Numbers must be different to avoid trapping the player on contact)
                                if ((personalDeltaX <= -2.4) || (personalDeltaX >= 2.7))
                                {
                                    player.action              = PlayerController.CharacterAction.MOVING;
                                    player.transform.position += Vector3.right * (_moveSpeed * player.inputHorizontal);
                                    player.anim.SetBool("Walking", true);  // walking is in Leg Layer, layer 1
                                }
                            }
                        }
                        // Moving right
                        else if (player.inputHorizontal > 0.0f)
                        {
                            if (player.rightWallDeltaX < -_wallWidth)
                            {
                                if ((personalDeltaX <= -2.7) || (personalDeltaX >= 2.4))
                                {
                                    //print(player.transform.position);
                                    //print(Vector3.right * (_moveSpeed * player.inputHorizontal));
                                    player.action              = PlayerController.CharacterAction.MOVING;
                                    player.transform.position += Vector3.right * (_moveSpeed * player.inputHorizontal);
                                    player.anim.SetBool("Walking", true);
                                }
                            }
                        }
                    }

                    if (player.inputHorizontal == 0)
                    {
                        player.anim.SetBool("Walking", false);
                    }

                    // Rolling inputs. Disabled when movement disabled
                    if (player.inputRollDown)
                    {
                        if (!player.rollDisabled)
                        {
                            // Roll in the direction you're moving.
                            // If not moving, roll in the direction you're facing

                            if (player.inputHorizontal < 0.0f)
                            {
                                player.rollingLeft = true;
                            }
                            else if (player.inputHorizontal == 0.0f)
                            {
                                player.rollingLeft = player.facingLeft;
                            }
                            else
                            {
                                player.rollingLeft = false;
                            }

                            if ((player.rollingLeft && (player.leftWallDeltaX > _wallWidth)) || (!player.rollingLeft && (player.rightWallDeltaX < -_wallWidth)))
                            {
                                player.Roll();
                            }
                        }
                    }
                }



                // Attack inputs
                if (player.inputAttackDown)
                {
                    if (!player.disarmed)
                    {
                        player.pressStartTime  = Time.time;
                        player.actionThisPress = false;
                    }
                    else
                    {
                        // TODO: Play some sort of "whoops, I'm disarmed" animation
                    }
                }
                if (player.inputAttackHeld)
                {
                    if (Time.time >= (player.pressStartTime + _holdTime) && !player.actionThisPress)
                    {
                        player.action          = PlayerController.CharacterAction.HEAVY_ATTACKING;
                        player.damageThisSwing = false;
                        player.anim.SetBool("Walking", false);
                        player.anim.Play("None", 1);
                        player.anim.Play("Heavy Attack (Windup)");

                        player.actionThisPress = true;
                    }
                }
                if (player.inputAttackUp)
                {
                    if (Time.time < (player.pressStartTime + _holdTime))
                    {
                        player.action          = PlayerController.CharacterAction.LIGHT_ATTACKING;
                        player.damageThisSwing = false;
                        player.anim.SetBool("Walking", false);
                        player.anim.Play("None", 1);
                        player.anim.Play("Light Attack (Swing)");

                        player.actionThisPress = true;
                    }
                }

                // Kick input
                if (player.inputKickDown)
                {
                    player.action = PlayerController.CharacterAction.KICKING;
                    player.anim.SetBool("Walking", false);
                    player.anim.Play("None", 1);
                    player.anim.Play("Kick");
                }


                // Defend inputs
                if (!player.shieldBroken)
                {
                    if (player.inputDefendDown)
                    {
                        player.pressStartTime  = Time.time;
                        player.actionThisPress = false;
                    }
                    if (player.inputDefendHeld)
                    {
                        if (Time.time >= (player.pressStartTime + _holdTime) && !player.actionThisPress)
                        {
                            if (player.action == PlayerController.CharacterAction.MOVING)
                            {
                                player.anim.SetBool("Walking", false);
                                player.anim.Play("None", 1);
                            }

                            player.action = PlayerController.CharacterAction.GUARDING;
                            player.anim.Play("Guard (On)");
                        }
                    }
                    if (player.inputDefendUp)
                    {
                        if (Time.time < (player.pressStartTime + _holdTime))
                        {
                            if (player.action == PlayerController.CharacterAction.MOVING)
                            {
                                player.anim.SetBool("Walking", false);
                                player.anim.Play("None", 1);
                            }

                            player.action = PlayerController.CharacterAction.PARRYING;
                            player.anim.Play("Parry");
                        }
                        else
                        {
                            player.action = PlayerController.CharacterAction.GUARDING;
                            player.anim.Play("Guard (Off)");
                        }
                    }
                }
            }
        }

        if (isStartScreen)
        {
            return;
        }

        // UI and game loop stuff:
        // continually decreasing time for game timer.
        _timeRemaining -= Time.deltaTime;
        if (_timeRemaining < 0)
        {
            currentScenario = gameScenarios.timeUp;
        }


        if ((_timeRemaining <= _beginClosing) && (wallRight.transform.position.x > _wallStopX) && (!gameOver))
        {
            wallLeft.transform.position += Vector3.right * _wallSpeed;
            safeXMin += _wallSpeed;
            wallRight.transform.position += Vector3.left * _wallSpeed;
            safeXMax -= _wallSpeed;
        }

        //endgame logic
        if (currentScenario == gameScenarios.p1Win)
        {
            //TODO: player 1 wins scenario
        }
        if (currentScenario == gameScenarios.p2Win)
        {
            //TODO: player 2 wins scenario
        }
        if (currentScenario == gameScenarios.timeUp)
        {
            //TODO: time runs out scenario
        }
    }