コード例 #1
0
        private void CalculateLighting(Camera camera, IGameArea gameArea)
        {
            var startX = (int)camera.Bounds.Left / gameArea.GameWorld.TileSize;
            var startY = (int)camera.Bounds.Top / gameArea.GameWorld.TileSize;
            var endX   = (int)camera.Bounds.Right / gameArea.GameWorld.TileSize;
            var endY   = (int)camera.Bounds.Bottom / gameArea.GameWorld.TileSize;

            for (float lightChange = 0; lightChange <= 1f; lightChange += 0.1f)
            {
                for (var tileX = startX; tileX <= endX; tileX++)
                {
                    for (var tileY = startY; tileY <= endY; tileY++)
                    {
                        if (IsOutOfBounds(tileX, tileY))
                        {
                            continue;
                        }
                        if (Math.Abs(_lightValues[tileX, tileY] - lightChange) > 0.01f)
                        {
                            continue;
                        }

                        CompareWithNeighbours(tileX, tileY, lightChange);
                    }
                }
            }
        }
コード例 #2
0
ファイル: WorldRenderer.cs プロジェクト: Rixium/Mayday
        public void DrawWorldObjects(IGameArea gameArea, Camera camera)
        {
            foreach (var entity in gameArea.WorldObjects)
            {
                var worldObjectComponent = entity.GetComponent <WorldObjectManagerComponent>();

                if (worldObjectComponent.WorldObjectData.BuildNodes != null &&
                    worldObjectComponent.WorldObjectData.BuildNodes.Length > 0)
                {
                    DrawNodes(entity, worldObjectComponent);
                }

                GraphicsUtils.Instance.SpriteBatch.Draw(worldObjectComponent.WorldObjectTexture,
                                                        entity.GetCurrentBounds(), Color.White);
            }

            var clientPlayer = gameArea.GameWorld.RequestClientPlayer?.Invoke();

            var itemPlacerComponent = clientPlayer?.GetComponent <ItemPlacerComponent>();

            if (itemPlacerComponent?.SelectedItem == null)
            {
                return;
            }

            var selectedItem = itemPlacerComponent.SelectedItem;
            var texture      = ContentChest.ItemTextures[selectedItem.ItemId];

            GraphicsUtils.Instance.SpriteBatch.Draw(texture, clientPlayer.Center, Color.White);
        }
コード例 #3
0
        private void PreCalculateLightValues(Camera camera, IGameArea gameArea)
        {
            var startX = (int)camera.Bounds.Left / gameArea.GameWorld.TileSize;
            var startY = (int)camera.Bounds.Top / gameArea.GameWorld.TileSize;
            var endX   = (int)camera.Bounds.Right / gameArea.GameWorld.TileSize;
            var endY   = (int)camera.Bounds.Bottom / gameArea.GameWorld.TileSize;

            for (var tileX = startX; tileX <= endX; tileX++)
            {
                for (var tileY = startY; tileY <= endY; tileY++)
                {
                    if (tileX < 0 || tileX >= _lightValues.GetLength(0))
                    {
                        continue;
                    }
                    if (tileY < 0 || tileY >= _lightValues.GetLength(1))
                    {
                        continue;
                    }

                    var tile = gameArea.TryGetTile(tileX, tileY);

                    if (tile.TileType == TileTypes.None)
                    {
                        _lightValues[tileX, tileY] = 0;
                    }
                    else
                    {
                        _lightValues[tileX, tileY] = 1f;
                    }
                }
            }
        }
コード例 #4
0
ファイル: GenericCell.cs プロジェクト: Mihinator3000/Efilir
        public void ActionCommand(int commandRotate, IGameArea gameArea)
        {
            //TODO: return cell, not only type
            Coordinate targetPosition = AnalyzePosition(commandRotate);
            IBaseCell  cellOnWay      = gameArea.GetCellOnPosition(targetPosition);

            if (cellOnWay == null)
            {
                return;
            }

            PointType cellType = cellOnWay.GetPointType();

            if (cellType == PointType.Food)
            {
                gameArea.TryEat(this, targetPosition);

                return;
            }

            if (cellType == PointType.Cell)
            {
                //Attack?
            }

            if (cellType == PointType.Trap)
            {
                Health = 0;
            }
        }
コード例 #5
0
        private async void CheckLights(Camera camera, IGameArea gameArea)
        {
            _lightValues ??= new float[gameArea.AreaWidth, gameArea.AreaHeight];

            PreCalculateLightValues(camera, gameArea);
            CalculateLighting(camera, gameArea);

            ChangedSinceLastGet = true;
        }
コード例 #6
0
        public void RenderToRenderTarget(Camera camera, IGameArea gameArea, LightMap lightMap)
        {
            if (lightMap == null)
            {
                return;
            }

            var lightMapData = lightMap.GetLights();

            var startX = (int)camera.Bounds.Left / gameArea.GameWorld.TileSize;
            var startY = (int)camera.Bounds.Top / gameArea.GameWorld.TileSize;
            var endX   = (int)camera.Bounds.Right / gameArea.GameWorld.TileSize;
            var endY   = (int)camera.Bounds.Bottom / gameArea.GameWorld.TileSize;

            _renderTarget ??= new RenderTarget2D(Window.GraphicsDeviceManager.GraphicsDevice, lightMapData.GetLength(0),
                                                 lightMapData.GetLength(1),
                                                 false,
                                                 Window.GraphicsDeviceManager.GraphicsDevice.PresentationParameters.BackBufferFormat,
                                                 DepthFormat.Depth24);
            _renderTarget.GraphicsDevice.Clear(Color.Transparent);

            Window.GraphicsDeviceManager.GraphicsDevice.SetRenderTarget(_renderTarget);

            GraphicsUtils.Instance.SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                BlendState.Opaque,
                null,
                DepthStencilState.Default,
                null,
                null,
                null);

            for (var i = startX; i <= endX; i++)
            {
                for (var j = startY; j <= endY; j++)
                {
                    if (i >= lightMapData.GetLength(0) || i < 0)
                    {
                        continue;
                    }
                    if (j >= lightMapData.GetLength(1) || j < 0)
                    {
                        continue;
                    }

                    GraphicsUtils.Instance.SpriteBatch.Draw(
                        GraphicsUtils.Instance.PixelTexture,
                        new Rectangle(i, j, 1, 1),
                        Color.Black * lightMapData[i, j]);
                }
            }

            GraphicsUtils.Instance.End();

            lightMap.ChangedSinceLastGet = false;
        }
コード例 #7
0
ファイル: GenericCell.cs プロジェクト: Mihinator3000/Efilir
        public void MakeTurn(IGameArea gameArea)
        {
            if (!IsAlive())
            {
                return;
            }

            Brain.MakeTurn(this, gameArea);
            IncreaseAge();
        }
コード例 #8
0
ファイル: GenericCell.cs プロジェクト: Mihinator3000/Efilir
        public void MoveCommand(int commandRotate, IGameArea gameArea)
        {
            ActionCommand(commandRotate, gameArea);

            Coordinate targetPosition = AnalyzePosition(commandRotate);
            IBaseCell  targetCell     = gameArea.GetCellOnPosition(targetPosition);

            if (targetCell == null)
            {
                Position = targetPosition;
            }
        }
コード例 #9
0
 private void AddGameArea(IGameArea area)
 {
     area.GameWorld = this;
     GameAreas.Add(area);
 }
コード例 #10
0
 public GameWorld(IGameArea startingArea)
 {
     AddGameArea(startingArea);
 }
コード例 #11
0
 public void Recalculate(Camera camera, IGameArea gameArea) =>
 Task.Run(() => CheckLights(camera, gameArea));
コード例 #12
0
 public void MakeTurn(IGameArea gameArea)
 {
     // Do nothing
 }
コード例 #13
0
 public virtual void Load(IGameArea gameAreaViewModel)
 {
     GameArea = gameAreaViewModel;
 }
コード例 #14
0
 public Dialog(IGameArea forGame, string name, IDialogViewModel viewModel)
 {
     ForGame   = forGame;
     Name      = name;
     ViewModel = viewModel;
 }
コード例 #15
0
ファイル: WorldRenderer.cs プロジェクト: Rixium/Mayday
        public void Draw(IGameArea gameArea, Camera camera)
        {
            var worldTileSize = gameArea.GameWorld.TileSize;

            var startTileX = (int)(camera.Position.X - Window.ViewportWidth / 2.0f) / worldTileSize - 1;
            var startTileY = (int)(camera.Position.Y - Window.ViewportHeight / 2.0f) / worldTileSize - 1;
            var endTileX   = (int)(camera.Position.X + Window.ViewportWidth / 2.0f) / worldTileSize + 1;
            var endTileY   = (int)(camera.Position.Y + Window.ViewportHeight / 2.0f) / worldTileSize + 1;

            _renderedTiles.Clear();

            for (var i = startTileX; i < endTileX; i++)
            {
                for (var j = startTileY; j < endTileY; j++)
                {
                    if (i < 0 || j < 0 || i > gameArea.AreaWidth - 1 || j > gameArea.AreaHeight - 1)
                    {
                        continue;
                    }
                    var tile = gameArea.Tiles[i, j];

                    if (tile.TileType == TileTypes.None)
                    {
                        continue;
                    }
                    var tileSet = ContentChest.TileTextures[tile.TileType];

                    _renderedTiles.Add(tile);

                    var rect = new Rectangle(2, 2, 8, 8);
                    GraphicsUtils.Instance.SpriteBatch.Draw(tileSet,
                                                            new Rectangle((int)tile.X, (int)tile.Y, 8, 8),
                                                            rect, Color.White);
                }
            }

            // Drawing the edges of tiles
            foreach (var tile in _renderedTiles)
            {
                var tileSet = ContentChest.TileTextures[tile.TileType];

                if (tile.North != null && tile.North.TileType != tile.TileType &&
                    (tile.North.TileProperties?.Name.Length > tile.TileProperties?.Name.Length ||
                     tile.North.TileProperties == null))
                {
                    var rect = new Rectangle(2, 0, 8, 2);
                    GraphicsUtils.Instance.SpriteBatch.Draw(tileSet,
                                                            new Rectangle((int)tile.X, (int)tile.Y - 2, 8, 2),
                                                            rect, Color.White);
                }

                if (tile.East != null && tile.East.TileType != tile.TileType &&
                    (tile.East.TileProperties?.Name.Length > tile.TileProperties?.Name.Length ||
                     tile.East.TileProperties == null))
                {
                    var rect = new Rectangle(10, 2, 2, 8);
                    GraphicsUtils.Instance.SpriteBatch.Draw(tileSet,
                                                            new Rectangle((int)tile.X + 8, (int)tile.Y, 2, 8),
                                                            rect, Color.White);
                }

                if (tile.South != null && tile.South.TileType != tile.TileType &&
                    (tile.South.TileProperties?.Name.Length > tile.TileProperties?.Name.Length ||
                     tile.South.TileProperties == null))
                {
                    var rect = new Rectangle(2, 10, 8, 2);
                    GraphicsUtils.Instance.SpriteBatch.Draw(tileSet,
                                                            new Rectangle((int)tile.X, (int)tile.Y + 8, 8, 2),
                                                            rect, Color.White);
                }

                if (tile.West != null && tile.West.TileType != tile.TileType &&
                    (tile.West.TileProperties?.Name.Length > tile.TileProperties?.Name.Length ||
                     tile.West.TileProperties == null))
                {
                    var rect = new Rectangle(0, 2, 2, 8);
                    GraphicsUtils.Instance.SpriteBatch.Draw(tileSet,
                                                            new Rectangle((int)tile.X - 2, (int)tile.Y, 2, 8),
                                                            rect, Color.White);
                }
            }
        }
コード例 #16
0
ファイル: WallCell.cs プロジェクト: Step1532/GeneticCell
 public void MakeTurn(IGameArea gameArea)
 {
 }
コード例 #17
0
 /// <inheritdoc />
 public override void Load(IGameArea gameAreaViewModel)
 {
     base.Load(gameAreaViewModel);
     Notes = IoC.Resolve <DbEntities>().DbAccess.GetUserEntry(gameAreaViewModel.AppUserId, "SUBSPACE.NOTES.TEXT")?.Value;
 }
コード例 #18
0
 /// <inheritdoc />
 public override void Load(IGameArea gameAreaViewModel)
 {
     base.Load(gameAreaViewModel);
     ChatGroups = _chatService.GetGroupsForUser(gameAreaViewModel.AppUserId);
 }