private async void SendMap(Connection connection)
        {
            for (var i = 0; i < _gameWorld.Width; i++)
            {
                for (var j = 0; j < _gameWorld.Height; j++)
                {
                    // TODO NETWORK GAME AREAS
                    var tileToSend     = _gameWorld.GameAreas[0].Tiles[i, j];
                    var tileTypePacket = new TileTypePacket()
                    {
                        X        = tileToSend.TileX,
                        Y        = tileToSend.TileY,
                        TileType = tileToSend.TileType
                    };
                    var packet = _messagePackager.Package(tileTypePacket);
                    _networkManager.SendMessage(packet, connection);
                }

                await Task.Delay(1);
            }

            foreach (var player in _entitySet.GetAll())
            {
                var playerPacket = new NewPlayerPacket()
                {
                    SteamId = player.EntityId,
                    X       = (int)player.X,
                    Y       = (int)player.Y,
                    HeadId  = 1
                };

                var package = _messagePackager.Package(playerPacket);

                _networkManager.SendMessage(package, connection);

                await Task.Delay(1);
            }

            var mapSendCompletePacket  = new MapSendCompletePacket();
            var mapSendCompletePackage = _messagePackager.Package(mapSendCompletePacket);

            _networkManager.SendMessage(mapSendCompletePackage, connection);
        }
Example #2
0
        public void Draw(
            Camera camera,
            IGameWorld gameWorld,
            IEntitySet entitySet,
            IEntity myPlayer,
            LightMap lightMap)
        {
            if (_renderTarget.Width != Window.WindowWidth)
            {
                _renderTarget = new RenderTarget2D(
                    Window.GraphicsDeviceManager.GraphicsDevice,
                    Window.WindowWidth, Window.WindowHeight);
            }

            if (lightMap.ChangedSinceLastGet)
            {
                _lightMapRenderer.RenderToRenderTarget(
                    camera,
                    myPlayer.GameArea,
                    lightMap);
            }

            Window.GraphicsDeviceManager.GraphicsDevice.SetRenderTarget(_renderTarget);

            GraphicsUtils.Instance.Begin();
            GraphicsUtils.Instance.SpriteBatch.Draw(ContentChest.Background, new Rectangle(0, 0, Window.WindowWidth, Window.WindowHeight), Color.White);
            GraphicsUtils.Instance.End();

            GraphicsUtils.Instance.Begin(camera.GetMatrix());
            _worldRenderer.DrawWorldObjects(gameWorld.GameAreas[0], camera);
            _playerRenderer.DrawPlayers(entitySet.GetAll());

            foreach (var entity in gameWorld.GameAreas[0].GetItems())
            {
                if (!_updateResolver.ShouldUpdate(entity))
                {
                    continue;
                }
                if (!(entity is ItemDrop item))
                {
                    continue;
                }
                GraphicsUtils.Instance.SpriteBatch.Draw(ContentChest.ItemTextures[item.Item.ItemId],
                                                        new Vector2(item.X, item.Y), Color.White);
            }

            _worldRenderer.Draw(gameWorld.GameAreas[0], camera);
            GraphicsUtils.Instance.End();

            GraphicsUtils.Instance.SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                null,                // No blending
                null,                // Point clamp, so we get sexy pixel perfect resizing
                null,                // We don't care about this. Tbh, I don't even understand it.
                null,                // I don't even know what this it.
                null,                // We can choose to flip textures as an example, but we dont, so null it.
                camera.GetMatrix()); // Window viewport, for nice resizing.
            _lightMapRenderer?.Draw(camera, myPlayer, gameWorld);
            GraphicsUtils.Instance.End();

            Window.GraphicsDeviceManager.GraphicsDevice.SetRenderTarget(null);

            GraphicsUtils.Instance.SpriteBatch.Begin();
            GraphicsUtils.Instance.SpriteBatch.Draw(_renderTarget,
                                                    new Rectangle(0, 0, Window.WindowWidth, Window.WindowHeight), Color.White);
            GraphicsUtils.Instance.End();
        }