Ejemplo n.º 1
0
    private void Rotate(float _angle)
    {
        GameBehaviors.RotateToAngle(this.transform, _angle);

        // responder com o id recebido
        ServerSend.PlayerRotation(this);
    }
Ejemplo n.º 2
0
    private void Move(Vector2 _inputDirection)
    {
        // Aplica no rigidbody2d do jogador
        GameBehaviors.MovePlayer(rb2d, _inputDirection, GetMoveSpeed());

        // responder com o id recebido
        ServerSend.PlayerPosition(this);
    }
Ejemplo n.º 3
0
    public override void TakeDamage(float _damage)
    {
        if (health <= 0f)
        {
            return;
        }

        if (isCombined && id == 1)
        {
            otherPlayer.TakeDamage(_damage);
        }

        else
        {
            health -= _damage;

            if (health <= 0f)
            {
                health = 0f;
                currentLifes--;

                if (currentLifes > 0)
                {
                    if (id == 1)
                    {
                        GameBehaviors.UndoCombine(this, otherPlayer);
                    }
                    else
                    {
                        GameBehaviors.UndoCombine(otherPlayer, this);
                    }


                    // respawn
                    Vector3 _position = (id == 1) ? new Vector3(-6.5f, 0, 0) : new Vector3(6.5f, 0, 0);
                    transform.position = _position;
                    ServerSend.PlayerPosition(this);
                    StartCoroutine(Respawn());
                }
                else
                {
                    // GameOver? Assistir o outro jogador?
                    Debug.Log("Game Over");
                }
            }
        }



        ServerSend.PlayerHealth(this);
    }
Ejemplo n.º 4
0
    public void ShootSkill(Vector3 _facing, float _pressedTime = 0f)
    {
        if (health <= 0)
        {
            return;
        }

        if (id == 1)
        {
            GameBehaviors.PlayerShootSkill(shootOrigin, _facing, id);
        }
        else
        {
            float strengthPercent = Mathf.InverseLerp(0, 2, _pressedTime);

            GameBehaviors.PlayerTankSkill(shootOrigin, _facing, id, strengthPercent);

            // projéteis enviam info para os clientes em seus próprios scripts
        }
    }
Ejemplo n.º 5
0
    public void Shoot(Vector3 _facing)
    {
        if (health <= 0)
        {
            return;
        }

        if (id == 1)
        {
            GameBehaviors.PlayerShoot(shootOrigin, _facing, id);
        }
        else
        {
            // saber quais inimigos atacou
            bool[] attackedEnemy = new bool[stuffOnTrigger.Count];
            foreach (Collider2D col in stuffOnTrigger)
            {
                attackedEnemy[stuffOnTrigger.IndexOf(col)] = GameBehaviors.PlayerAreaAttack(_facing, col, areaDamage);
            }

            // feedback visual
            bool atLeastOneEnemy = false;
            foreach (bool _attacked in attackedEnemy)
            {
                if (_attacked)
                {
                    atLeastOneEnemy = true;
                }
                break;
            }
            Debug.Log($"Attacked enemies? {atLeastOneEnemy}");

            Vector3 animPos = tankTrigger.transform.position;

            ServerSend.TankAttacked(animPos, atLeastOneEnemy);
        }
    }
Ejemplo n.º 6
0
    private void OnTriggerStay2D(Collider2D col)
    {
        // se os dois jogadores estão esperando combinar mas ainda não combinaram
        if (col.TryGetComponent <Player>(out Player _otherPlayer) && _otherPlayer.waitingCombine &&
            waitingCombine && !isCombined && !_otherPlayer.isCombined)
        {
            // combinar
            isCombined = true;
            _otherPlayer.isCombined = true;

            if (_otherPlayer.id == 1)
            {
                GameBehaviors.CombinePlayers(_otherPlayer, this);
            }
            else
            {
                GameBehaviors.CombinePlayers(this, _otherPlayer);
            }

            otherPlayer = _otherPlayer;
            _otherPlayer.otherPlayer = this;
            ServerSend.IsCombined(this);
        }
    }
Ejemplo n.º 7
0
 public GameKey(Keys firstKey, Keys secondKey, GameBehaviors behavior)
 {
     this.firstKey  = firstKey;
     this.secondKey = secondKey;
     this.behavior  = behavior;
 }