コード例 #1
0
ファイル: Player.cs プロジェクト: mephistia/UnityGameServer
    private void Rotate(float _angle)
    {
        GameBehaviors.RotateToAngle(this.transform, _angle);

        // responder com o id recebido
        ServerSend.PlayerRotation(this);
    }
コード例 #2
0
ファイル: Player.cs プロジェクト: mephistia/UnityGameServer
    private void Move(Vector2 _inputDirection)
    {
        // Aplica no rigidbody2d do jogador
        GameBehaviors.MovePlayer(rb2d, _inputDirection, GetMoveSpeed());

        // responder com o id recebido
        ServerSend.PlayerPosition(this);
    }
コード例 #3
0
ファイル: Player.cs プロジェクト: mephistia/UnityGameServer
    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);
    }
コード例 #4
0
ファイル: Player.cs プロジェクト: mephistia/UnityGameServer
    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
        }
    }
コード例 #5
0
ファイル: Player.cs プロジェクト: mephistia/UnityGameServer
    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);
        }
    }
コード例 #6
0
ファイル: Player.cs プロジェクト: mephistia/UnityGameServer
    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);
        }
    }
コード例 #7
0
ファイル: Options.cs プロジェクト: LordElf/Invaders
 public GameKey(Keys firstKey, Keys secondKey, GameBehaviors behavior)
 {
     this.firstKey  = firstKey;
     this.secondKey = secondKey;
     this.behavior  = behavior;
 }