예제 #1
0
        public static void DrawAIFieldOfViews(StateSpaceComponents spaceComponents, Camera camera, SpriteBatch spriteBatch, Texture2D rectangleTexture, int cellSize, DungeonTile[,] dungeonGrid)
        {
            Matrix cameraMatrix = camera.GetMatrix();

            foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.AIView) == ComponentMasks.AIView).Select(x => x.Id))
            {
                AIFieldOfView fovInfo = spaceComponents.AIFieldOfViewComponents[id];
                if (fovInfo.DrawField)
                {
                    foreach (Vector2 tilePosition in fovInfo.SeenTiles)
                    {
                        Vector2 tile = new Vector2((int)tilePosition.X * cellSize, (int)tilePosition.Y * cellSize);

                        Vector2   bottomRight  = Vector2.Transform(new Vector2((tile.X + cellSize), (tile.Y + cellSize)), cameraMatrix);
                        Vector2   topLeft      = Vector2.Transform(tile, cameraMatrix);
                        Rectangle cameraBounds = new Rectangle((int)topLeft.X, (int)topLeft.Y, (int)bottomRight.X - (int)topLeft.X, (int)bottomRight.Y - (int)topLeft.Y);

                        if (dungeonGrid[(int)tilePosition.X, (int)tilePosition.Y].InRange && camera.IsInView(cameraMatrix, cameraBounds))
                        {
                            if (spaceComponents.AlternateFOVColorChangeComponents.ContainsKey(id))
                            {
                                AlternateFOVColorChangeComponent altColorInfo = spaceComponents.AlternateFOVColorChangeComponents[id];
                                spriteBatch.Draw(rectangleTexture, position: tile, color: Color.Lerp(fovInfo.Color, altColorInfo.AlternateColor, altColorInfo.Seconds / altColorInfo.SwitchAtSeconds) * fovInfo.Opacity, origin: new Vector2(DevConstants.Grid.TileBorderSize, DevConstants.Grid.TileBorderSize));
                            }
                            else
                            {
                                //origin is 4,4 because the tile texture is 40x40 and the grid is 32x32.  If size of grid changes, change this -- and then don't hardcode it anymore!!!
                                spriteBatch.Draw(rectangleTexture, position: tile, color: fovInfo.Color * fovInfo.Opacity, origin: new Vector2(DevConstants.Grid.TileBorderSize, DevConstants.Grid.TileBorderSize));
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
 public static void UpdateFovColors(StateSpaceComponents spaceComponents, GameTime gameTime)
 {
     foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.FOVColorChange) == ComponentMasks.FOVColorChange).Select(x => x.Id))
     {
         AlternateFOVColorChangeComponent altColorInfo = spaceComponents.AlternateFOVColorChangeComponents[id];
         altColorInfo.Seconds += (float)gameTime.ElapsedGameTime.TotalSeconds;
         if (altColorInfo.Seconds >= altColorInfo.SwitchAtSeconds)
         {
             AIFieldOfView fovInfo = spaceComponents.AIFieldOfViewComponents[id];
             Color         temp    = fovInfo.Color;
             fovInfo.Color = altColorInfo.AlternateColor;
             altColorInfo.AlternateColor = temp;
             altColorInfo.Seconds        = 0f;
             spaceComponents.AIFieldOfViewComponents[id] = fovInfo;
         }
         spaceComponents.AlternateFOVColorChangeComponents[id] = altColorInfo;
     }
 }