Esempio n. 1
0
        private void SendInitializePackets()
        {
            if (initializedPacketQueue.Count > 0)
            {
                Packet p = initializedPacketQueue.Peek();

                userMediator.BroadCast(p);
                if (p.Head == Packet.HEADER.GAME_INIT_ALL_PACKET_SENDED)
                {
                    state = STATE.WAIT_ALL_PLAYER_INITIALIZED;
                }
                initializedPacketQueue.Dequeue();
            }
        }
Esempio n. 2
0
        public void ProcessMove(UserInput input, float deltaTime)
        {
            Packet movePacket = new Packet(Packet.HEADER.GAME_UPDATE_PLAYER_POSITION, Config.MAX_SESSION_BUFFER_SIZE);
            int    vertical = 0; int horizontal = 0;

            vertical += input.KeyInput.upKey ? 1 : 0;
            vertical += input.KeyInput.downKey ? -1 : 0;

            horizontal += input.KeyInput.leftKey ? -1 : 0;
            horizontal += input.KeyInput.rightKey ? 1 : 0;

            float nextX = position.X + (horizontal * this.condition.MoveSpeed * deltaTime);
            float nextY = position.Y + (vertical * this.condition.MoveSpeed * deltaTime);

            nextX = nextX > width ? width : nextX;
            nextX = nextX < mapCenter.X ? mapCenter.X : nextX;

            nextY = nextY < mapCenter.Y ? mapCenter.Y : nextY;
            nextY = nextY > height ? height : nextY;

            position            = new Vector3(nextX, nextY, position.Z);
            coll.Circle.point.X = position.X;
            coll.Circle.point.Y = position.Y;

            movePacket.Push(this.gameObject.Name);
            movePacket.Push(Encoding.ASCII.GetByteCount(this.gameObject.Name));
            movePacket.Push(this.position.X);
            movePacket.Push(this.position.Y);

            movePacket.Push(input.CharacterRotation);

            mediator.BroadCast(movePacket);
        }