Ejemplo n.º 1
0
        public static void DrawOutlines(StateSpaceComponents spaceComponents, Camera camera, SpriteBatch spriteBatch, Texture2D rectangleTexture, DungeonTile[,] dungeonGrid)
        {
            Matrix cameraMatrix = camera.GetMatrix();
            Entity player       = spaceComponents.Entities.Where(c => (c.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault();
            bool   inWater      = false;

            if (player != null)
            {
                Vector2 playerPos = spaceComponents.PositionComponents[spaceComponents.Entities.Where(c => (c.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).First().Id].Position;
                inWater = dungeonGrid[(int)playerPos.X, (int)playerPos.Y].Type == TileType.TILE_WATER;
            }

            foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.DrawableOutline) == ComponentMasks.DrawableOutline).Select(x => x.Id))
            {
                Entity observer   = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer).FirstOrDefault();
                bool   isObserver = false;
                if (observer != null)
                {
                    isObserver = observer.Id == id;
                }

                OutlineComponent  outline  = spaceComponents.OutlineComponents[id];
                PositionComponent position = spaceComponents.PositionComponents[id];

                bool    outlineInWater = dungeonGrid[(int)position.Position.X, (int)position.Position.Y].Type == TileType.TILE_WATER;
                Vector2 tile           = new Vector2((int)position.Position.X * DevConstants.Grid.CellSize, (int)position.Position.Y * DevConstants.Grid.CellSize);

                Vector2   bottomRight  = Vector2.Transform(new Vector2((tile.X + DevConstants.Grid.CellSize), (tile.Y + DevConstants.Grid.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)position.Position.X, (int)position.Position.Y].InRange && camera.IsInView(cameraMatrix, cameraBounds) && (inWater == outlineInWater || isObserver))
                {
                    if (spaceComponents.SecondaryOutlineComponents.ContainsKey(id))
                    {
                        SecondaryOutlineComponent altColorInfo = spaceComponents.SecondaryOutlineComponents[id];
                        spriteBatch.Draw(rectangleTexture, position: tile, color: Color.Lerp(outline.Color, altColorInfo.AlternateColor, altColorInfo.Seconds / altColorInfo.SwitchAtSeconds) * outline.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: outline.Color * outline.Opacity, origin: new Vector2(DevConstants.Grid.TileBorderSize, DevConstants.Grid.TileBorderSize));
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static void UpdateOutlineColors(StateSpaceComponents spaceComponents, GameTime gameTime)
 {
     foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.GlowingOutline) == ComponentMasks.GlowingOutline).Select(x => x.Id))
     {
         SecondaryOutlineComponent altColorInfo = spaceComponents.SecondaryOutlineComponents[id];
         altColorInfo.Seconds += (float)gameTime.ElapsedGameTime.TotalSeconds;
         if (altColorInfo.Seconds >= altColorInfo.SwitchAtSeconds)
         {
             OutlineComponent outline = spaceComponents.OutlineComponents[id];
             Color            temp    = outline.Color;
             outline.Color = altColorInfo.AlternateColor;
             altColorInfo.AlternateColor           = temp;
             altColorInfo.Seconds                  = 0f;
             spaceComponents.OutlineComponents[id] = outline;
         }
         spaceComponents.SecondaryOutlineComponents[id] = altColorInfo;
     }
 }