Exemplo n.º 1
0
    }//! updateUI

    private void updateSquareInputImage(int i_square, PlayerController.Direction dir)
    {
        if (i_square > __time_units.Length)
        {
            return;
        }
        if (dir == PlayerController.Direction.UP)
        {
            __time_units[i_square].changeSprite(ui_input_up);
        }
        else if (dir == PlayerController.Direction.DOWN)
        {
            __time_units[i_square].changeSprite(ui_input_down);
        }
        else if (dir == PlayerController.Direction.LEFT)
        {
            __time_units[i_square].changeSprite(ui_input_left);
        }
        else if (dir == PlayerController.Direction.RIGHT)
        {
            __time_units[i_square].changeSprite(ui_input_right);
        }
        else   //NONE
        {
            __time_units[i_square].changeSprite(ui_input_none);
        }
    }
Exemplo n.º 2
0
    private void DoPatrol()
    {
        // move towards the current waypoint
        float patrolDirection = _currentDestination.x < transform.position.x ? -1 : 1;
        float newX            = transform.position.x + (_patrolSpeed * patrolDirection * Time.deltaTime);

        transform.position = new Vector2(newX, transform.position.y);

        // if within _distanceThreshold of the waypoint, select the other waypoint as current
        if (Mathf.Abs(transform.position.x - _currentDestination.x) < _distanceThreshold)
        {
            if (_currentDestination == _startWaypoint)
            {
                _currentDestination = _endWaypoint;
                patrolDirection    *= -1; // change direction
            }
            else
            {
                _currentDestination = _startWaypoint;
                patrolDirection    *= -1; // change direction
            }
        }

        // make sure sprite matches direction
        if (patrolDirection == -1)
        {
            gameObject.GetComponent <SpriteRenderer>().sprite = leftFacing;
            direction = PlayerController.Direction.Left;
        }
        else
        {
            gameObject.GetComponent <SpriteRenderer>().sprite = rightFacing;
            direction = PlayerController.Direction.Right;
        }
    }
Exemplo n.º 3
0
    public bool holdingDirection(PlayerController.Direction dir)
    {
        //For keyboard or left joystick
        switch (dir)
        {
        case (PlayerController.Direction.Right):
            return(Input.GetAxis("Horizontal") > axisDeadZone);

        case (PlayerController.Direction.Left):
            return(Input.GetAxis("Horizontal") < -axisDeadZone);

        case (PlayerController.Direction.Up):
            return(Input.GetAxis("Vertical") > axisDeadZone);

        case (PlayerController.Direction.Down):
            return(Input.GetAxis("Vertical") < -axisDeadZone);

        case (PlayerController.Direction.UpRight):
            return(Input.GetAxis("Horizontal") > axisDeadZone && Input.GetAxis("Vertical") > -axisDeadZone);

        case (PlayerController.Direction.DownRight):
            return(Input.GetAxis("Vertical") < -axisDeadZone && Input.GetAxis("Horizontal") > axisDeadZone);

        case (PlayerController.Direction.DownLeft):
            return(Input.GetAxis("Vertical") < -axisDeadZone && Input.GetAxis("Horizontal") < -axisDeadZone);

        case (PlayerController.Direction.UpLeft):
            return(Input.GetAxis("Vertical") > axisDeadZone && Input.GetAxis("Horizontal") < -axisDeadZone);
        }

        return(false); //should never run
    }
Exemplo n.º 4
0
 public void Activate(PlayerController.Direction currDirr)
 {
     if (currDirr == direction)
     {
         playerController.JumpLedge(direction, targetCoordinates);
     }
 }
Exemplo n.º 5
0
 void Start()
 {
     damage = GameObject.Find("Skills").GetComponent<SkillController>().fireballSkillDamage;
     player = GameObject.Find("Player").GetComponent<PlayerController>();
     thisAnimator = GetComponent<Animator>();
     thisPosition = this.GetComponent<Transform>();
     this.currentStartDirect = player.direct;
 }
Exemplo n.º 6
0
 // Use this for initialization
 void Start()
 {
     initialTime    = Time.time;
     initialTimeNum = MoveTime;
     controller     = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>();
     direction      = controller.direction;
     gameAttribute  = GameAttribute.instance;
 }
Exemplo n.º 7
0
    void Update()
    {
        switch (_currentStatus)
        {
        case SentryBotStatus.Idling:
            gameObject.GetComponent <SpriteRenderer>().sprite = frontFacing;
            direction = PlayerController.Direction.Stationary;

            if (CanSeePlayer())
            {
                _currentStatus = SentryBotStatus.AttackingPlayer;
            }
            else
            {
                DoIdleBob();
            }
            break;

        case SentryBotStatus.AttackingPlayer:
            if (CanSeePlayer())
            {
                // face player
                if (_player.transform.position.x < transform.position.x)
                {
                    // player is left of bot
                    gameObject.GetComponent <SpriteRenderer>().sprite = leftFacing;
                    direction = PlayerController.Direction.Left;
                }
                else
                {
                    // consider player is right of bot
                    gameObject.GetComponent <SpriteRenderer>().sprite = rightFacing;
                    direction = PlayerController.Direction.Right;
                }
                SetLaunchpointOnDirection();
                FireBullet();
            }
            else
            {
                gameObject.GetComponent <SpriteRenderer>().sprite = frontFacing;
                direction      = initialDirection;
                _currentStatus = initialStatus;
            }
            break;

        case SentryBotStatus.Hunting:
            DoPatrol();
            if (CanSeePlayer())
            {
                _currentStatus = SentryBotStatus.AttackingPlayer;
            }
            break;
        }
    }
Exemplo n.º 8
0
    public bool maxedYAxisThisFrame(PlayerController.Direction dir)
    {
        //returns true when the stick hits the edge, for 1 frame
        switch (dir)
        {
        case (PlayerController.Direction.Up):
            return(Input.GetAxis("Vertical") >= (1 - axisDeadZone) && !yAxisMaxed);

        case (PlayerController.Direction.Down):
            return(Input.GetAxis("Vertical") <= (-1 + axisDeadZone) && !yAxisMaxed);
        }
        print("maxedYAxisThisFrame: Invalid Direction->" + dir);
        return(false);
    }
Exemplo n.º 9
0
    /// <summary>
    /// This will apply physics to the object
    /// It will always be called from WorldManager FixedUpdate
    /// Therefore it should be treated as a FixedUpdate function
    /// </summary>
    public Movable.MoveResult Move(PlayerController.Direction Dir)
    {
        Movable.MoveResult Result = Movable.MoveResult.CannotMove;
        // move
        Movable Mover = GetComponent <Movable>();

        if (Mover)
        {
            Result = Mover.Move(Mdl.CurrentDirection, true, true);
            checkSpriteFlip(Dir);
        }
        Tails.Tick();
        return(Result);
    }
    public void CollectedWhenPressed(PlayerController player, PlayerController.Direction direction)
    {
        if (playerStates == null)
        {
            playerStates = player.GetComponent <PlayerStates>();
        }

        switch (direction)
        {
        case PlayerController.Direction.left:
            cballBool.onCooldown = true;

            GameObject ballPlayerObj = player.gameObject;
            //PlayerStates playerStates = player.GetComponent<PlayerStates>();
            //GameObject newBall = Instantiate(cannonballPrefab);
            GameObject newBall = objectPooler.SpawnFromPool("Cannonballs", transform.position, transform.rotation);
            newBall.GetComponent <CannonballObj>().Pickup(player.gameObject, player, player.playerState);
            playerStates = null;

            //newBall.GetComponent<CannonballObj>().EnableCannonball();
            break;

        case PlayerController.Direction.right:
            barrelBool.onCooldown = true;

            GameObject barrelPlayerObj = player.gameObject;
            //GameObject newBarrel = Instantiate(barrelPrefab);
            GameObject newBarrel = objectPooler.SpawnFromPool("Gunpowder", transform.position, transform.rotation);
            newBarrel.GetComponent <GunpowderObj>().Pickup(player.gameObject, player, player.playerState);
            playerStates = null;

            break;

        case PlayerController.Direction.up:
            woodBool.onCooldown = true;

            GameObject woodPlayerObj = player.gameObject;
            //PlayerStates playerStates = player.GetComponent<PlayerStates>();
            //GameObject newWood = Instantiate(woodPrefab);
            GameObject newWood = objectPooler.SpawnFromPool("Planks", transform.position, transform.rotation);
            newWood.GetComponent <WoodObj>().Pickup(player.gameObject, player, player.playerState);

            //WoodStates woodStates = newWood.GetComponent<WoodStates>();
            //woodStates.currentState = WoodStates.WoodState.Held;
            playerStates = null;

            break;
        }
    }
Exemplo n.º 11
0
    void checkSpriteFlip(PlayerController.Direction Dir)
    {
        bool flip_detected = (Dir == Direction.RIGHT) && !Mdl.FacingRight;

        flip_detected |= (Dir == Direction.LEFT) && Mdl.FacingRight;

        if (!flip_detected)
        {
            return;
        }

        SpriteRenderer sprite = gameObject.GetComponentInChildren <SpriteRenderer>();

        sprite.flipX    = !sprite.flipX;
        Mdl.FacingRight = !Mdl.FacingRight;
    }
Exemplo n.º 12
0
    private void Awake()
    {
        startPosition       = transform.position;
        initialStatus       = _currentStatus;
        initialDirection    = direction;
        _currentDestination = _startWaypoint;

        if (_player == null)
        {
            _player = GameObject.Find("Player").GetComponent <PlayerController>();
        }

        SetLaunchpointOnDirection();
        _lastShotFired = 0f;
        _health        = _startingHealth;

        AudioSource[] sounds = transform.GetComponentsInChildren <AudioSource>();
        _gunshot_sound   = sounds[0];
        _explosion_sound = sounds[1];
    }
Exemplo n.º 13
0
    public PlayerController.Direction calculateAimDirection(PlayerController.Direction currentDir)
    {
        //returns Direction up, upright, right,...etc

        //diagonals must be tested before singular directions, because single directions are subsets of diagonals

        if (Mathf.Abs(Input.GetAxis(aimStickVertical)) > axisDeadZone || Mathf.Abs(Input.GetAxis(aimStickHorizontal)) > axisDeadZone)
        {
            float stickAngle = (Mathf.Atan2(Input.GetAxis(aimStickVertical), Input.GetAxis(aimStickHorizontal)) * Mathf.Rad2Deg);
            if (stickAngle < 0)
            {
                stickAngle += 360;
            }
            for (int i = 0; i < 8; ++i)
            {
                if (Mathf.Abs(i * 45 - stickAngle) <= 22.5f)
                {
                    return((PlayerController.Direction)i);
                }
            }
        }
        return(currentDir);         //If no key input, no change
    }
Exemplo n.º 14
0
 public PlayerMoveValue(Movable m, PlayerController.Direction d)
 {
     _go  = m;
     _dir = d;
 }
Exemplo n.º 15
0
    void DuringGame()
    {
        currentDirection = player.currentDirection;

        if (currentDirection == PlayerController.Direction.Down)
        {
            posTxt.text = "Fear";
            negTxt.text = "Pity";
        }
        else if (currentDirection == PlayerController.Direction.Up)
        {
            posTxt.text = "Joy";
            negTxt.text = "Sorrow";
        }
        else if (currentDirection == PlayerController.Direction.Left)
        {
            posTxt.text = "Surprise";
            negTxt.text = "Intimidate";
        }
        else if (currentDirection == PlayerController.Direction.Right)
        {
            posTxt.text = "Admiration";
            negTxt.text = "Anger";
        }


        if (player.currentEnemy == null)
        {
            enemyEmo.enabled = false;
        }
        else
        {
            currentEnemyEmo  = player.currentEnemy.currentEnemyEmotes;
            enemyEmo.enabled = true;

            if (currentEnemyEmo == EnemyController.EnemyEmotes.Admire)
            {
                enemyEmo.text = "Admiration";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Anger)
            {
                enemyEmo.text = "Anger";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Conflicted)
            {
                enemyEmo.text = "Conflicted";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Confusion)
            {
                enemyEmo.text = "Confusion";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Dizzy)
            {
                enemyEmo.text = "Stunned";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Fear)
            {
                enemyEmo.text = "Fear";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Idea)
            {
                enemyEmo.text = "Focused";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Intimidation)
            {
                enemyEmo.text = "Intimidation";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Joy)
            {
                enemyEmo.text = "Joy";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Pity)
            {
                enemyEmo.text = "Pity";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Singing)
            {
                enemyEmo.text = "Humming";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Sorrow)
            {
                enemyEmo.text = "Sorrow";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Surprise)
            {
                enemyEmo.text = "Surprise";
            }
            else if (currentEnemyEmo == EnemyController.EnemyEmotes.Tired)
            {
                enemyEmo.text = "Tired";
            }
        }
    }
Exemplo n.º 16
0
    public MoveResult Move(PlayerController.Direction D, bool ApplyPhysicsBetweenPlayers = true, bool RecordEvent = true, FixedTickValue MoveValue = null)
    {
        if (Freeze)
        {
            return(MoveResult.CannotMove);
        }
        //if (!CanMove()) return MoveResult.IsAnimating;

        MoveResult NeedToBeMoved = MoveResult.CannotMove;

        if (D != PlayerController.Direction.NONE)
        {
            var     Direction = PlayerController.Directionf[(int)D];
            Vector3 Dir3      = new Vector3(Direction.x, Direction.y, 0);
            // WALL HITS
            RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position + (0.6f * Dir3), Dir3, 0.5f, wallmask);
            if (hits.Length != 0)
            {
                UpdatePositionBump(Direction);
                return(MoveResult.CannotMove);
            }
            // MOVABLE HITS
            RaycastHit2D[] hitsm = Physics2D.RaycastAll(transform.position + (0.6f * Dir3), Dir3, 0.5f, movablemask);
            hitsm = hitsm.Where(val => (val.collider.gameObject != this.gameObject)).ToArray(); // filter our own gameobject

            if (!ApplyPhysicsBetweenPlayers)
            {
                hitsm = hitsm.Where(val => (val.collider.gameObject.GetComponent <PlayerController>() == null)).ToArray(); // filter our own gameobject
            }
            if (hitsm.Length == 0)
            {
                NeedToBeMoved = MoveResult.CanMove;
            }
            else
            {
                foreach (RaycastHit2D hit in hitsm)
                {
                    if (hit.collider.gameObject != this.gameObject) // not necessary should already be filtered
                    {
                        if (hit.collider != null)
                        {
                            // Detect if we are colliding with a player
                            // If the player asked for the same direction than us last event
                            // We dont execute the move and simply move this object because physic
                            // is executed in a certain order
                            var PC   = hit.collider.GetComponent <PlayerController>();
                            var Mov  = hit.collider.GetComponent <Movable>();
                            var mePC = GetComponent <PlayerController>();
                            if (Mov)
                            {
                                if (PC && mePC)
                                {
                                    if (Physics2D.GetIgnoreCollision(mePC.GetComponent <BoxCollider2D>(), PC.GetComponent <BoxCollider2D>()))
                                    {
                                        NeedToBeMoved = MoveResult.CanMove;
                                    }
                                    else
                                    {
                                        NeedToBeMoved = Mov.Move(D, true, true, MoveValue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (NeedToBeMoved == MoveResult.CanMove)
            {
                UpdatePosition(Direction);
                if (RecordEvent && MoveValue != null)
                {
                    MoveValue.AddObserver(new MoveValue(this, D));
                }
            }

            if (D != PlayerController.Direction.NONE && NeedToBeMoved == MoveResult.CannotMove)
            {
                // Do a bump into wall animation
                UpdatePositionBump(Direction);
            }
        }
        return(NeedToBeMoved);
    }
Exemplo n.º 17
0
 /// <summary>
 /// Causes the character to face the given direction.
 /// </summary>
 public void Face(PlayerController.Direction d)
 {
     rend.sprite = sprites[(int)d];
 }