Beispiel #1
0
    public static void Interpret(IPEndPoint source, byte[] bytes)
    {
        try {
            message = Read(bytes);
        } catch (Exception ex) {
            Debug.Log(ex);
            return;
        }

        if (message.SourceID == GameObject.FindObjectOfType <Network> ().NetworkCommon.ID)
        {
            // TODO message sent by self returned
        }
        else
        {
            if (message.Type == Message.MessageType.GAMEPLAY)
            {
                GameplayTranslator.Interpret(source, message, Read <GameplayMessage>(message.SerializedContent));
            }
            else if (message.Type == Message.MessageType.NETWORK)
            {
                NetworkTranslator.Interpret(source, message, Read <NetworkMessage>(message.SerializedContent));
            }
        }
    }
Beispiel #2
0
    public void Update()
    {
        if (mIsAttacking == false && (Input.GetKeyDown(PlayerATTACK) || _attackNetwork))
        {
            if (_attackNetwork)
            {
                _attackNetwork = false;
            }
            else
            {
                GameplayTranslator.Send(GameplayMessage.MessageValue.ATTACK, ID, Vector2.zero, transform.position);
            }

            mIsAttacking            = true;
            mSprite.mAnimationFrame = 1;
            mSprite.mFrameSkip      = 1;
        }

        Vector2 delta = Vector2.zero;

        if (Input.GetKey(PlayerUP))
        {
            delta += Vector2.up;
        }
        if (Input.GetKey(PlayerDOWN))
        {
            delta -= Vector2.up;
        }
        if (Input.GetKey(PlayerLEFT))
        {
            delta -= Vector2.right;
        }
        if (Input.GetKey(PlayerRIGHT))
        {
            delta += Vector2.right;
        }

        if (_fromServer || (delta.Equals(Vector2.zero) && !_moveDelta.Equals(Vector2.zero)))
        {
            if (!_oldPosition.Equals(transform.position))
            {
                transform.position.Set(_oldPosition.x, _oldPosition.y, _oldPosition.z);
                transform.Translate(_moveDelta);
                delta = Vector2.zero;
            }
            else
            {
                delta = _moveDelta;
            }

            UpdateFacing(_moveDelta);

            _moveDelta  = Vector2.zero;
            _fromServer = false;
        }
        else
        {
            delta *= 3.0f;
            if (!delta.Equals(Vector2.zero))
            {
                GameplayTranslator.Send(GameplayMessage.MessageValue.MOVE, ID, delta, transform.position);
            }

            UpdateFacing(delta);
        }

        lastPosition = transform.position;
        transform.Translate(delta);

        UpdateSprite();
    }