public void CreateGlow(Entity lightSource) { var center = lightSource.Component<Position>().Coords; var source = lightSource.Component<LightSource>(); // Radius, light strength, fog strength; must start in the center var lightPools = new[] { new[] {1, 30, 0}, new[] {2, 25, 5}, new[] {Convert.ToInt32(source.Radius*.6), 20, 10}, new[] {Convert.ToInt32(source.Radius*.75), 12, 25}, new[] {Convert.ToInt32(source.Radius*.9), 5, 40} }; var glow = new Dictionary<GridPoint, Entity>(); foreach (var pool in lightPools) { var points = Utilities.CreateCircle(center, pool[0], true); foreach (var point in points) { if (glow.ContainsKey(point) == false) { var lightStrength = source.Strength * pool[1] / 100.0; var fogStrength = source.Strength * pool[2] / 100.0; var light = new Light(source.Color, lightStrength, fogStrength); glow[point] = new Entity("Light", new Component[] { new Position(point.X, point.Y), light } ); } } } _sourcesAndLights.Add(lightSource, glow.Values.ToList()); }
public override void Register(Entity entity) { if (entity.Component<Mob>() != null) { _mobs.Add(entity); } if (entity.Component<Obstacle>() != null) { _obstacles.Add(entity); } }
public override void Deregister(Entity entity) { if (entity.Component<Tile>() != null) { var positions = entity.Component<IPosition>().Positions; foreach (var pos in positions) { _map[pos.X, pos.Y] = null; } SetTiles(_region.Default, positions); } }
public override void Register(Entity entity) { if (entity.Component<Harvestable>() != null) { _harvestables.Add(entity); } }
public override void Register(Entity entity) { var item = entity.Component<InventoryItem>(); if (item != null && _inventory.ContainsKey(entity.Name) == false) { _inventory.Add(entity.Name, item); } }
public void DrawEntity(Entity entity) { var position = entity.Component<IPosition>(); if (position == null) return; var graphic = entity.Component<BeadGraphic>(); if (graphic != null) { foreach (var pos in position.Positions) { if (GameState.OnScreen(pos.X, pos.Y)) DrawBeadGraphic(pos.X, pos.Y, graphic); } } var overlay = entity.Component<Overlay>(); if (overlay != null) { foreach (var pos in position.Positions) { DrawOverlay(pos.X, pos.Y, overlay); } } }
public void MoveEntity(Entity entity, GridPoint oldPos, GridPoint newPos, bool checkPassable = true) { var canMove = true; if (checkPassable == true) { if (CanPassThroughSquare(entity, newPos) == false) canMove = false; } if (canMove == true) { var pos = entity.Component<IPosition>(); pos.ChangePosition(oldPos, newPos); GameState.DrawMap(); } }
private bool CanPass(Entity traveler, Entity blocker) { var mob = traveler.Component<Mob>(); var obstacle = blocker.Component<Obstacle>(); // If the obstacle blocks everything, return false if (obstacle.MovementTypesBlocked.Contains("all")) return false; // Get all the flags the traveler has that the obstacle doesn't var flags = from flag in mob.MovementTypes where obstacle.MovementTypesBlocked.Contains(flag) == false select flag; // If the traveler has any flags (can pass) that the obstacle doesn't (can block), // then the traveler can pass over the obstacle return flags.Any(); }
public override void Register(Entity entity) { var position = entity.Component<IPosition>(); if (position == null) return; var beadGraphic = entity.Component<BeadGraphic>(); var overlay = entity.Component<Overlay>(); var light = entity.Component<Light>(); var darkness = entity.Component<Darkness>(); if (beadGraphic != null) { _graphics.Add(entity); } if (overlay != null) { _overlays.Add(entity); } if (light != null) { _lights.Add(entity); } if (darkness != null) { _darkness.Add(entity); } if (beadGraphic != null || overlay != null || light != null || darkness != null) { GameState.DrawMap(); } }
public override void Register(Entity entity) { var lightSource = entity.Component<LightSource>(); if (lightSource != null) { CreateGlow(entity); } }
private void BuildEntity() { if (_name == null) { throw new Exception("Error: Call start before calling build!"); } var tile = new Entity(_name, _requiredComponents.Union(_optionalComponents)); if (tile.Component<Buildable>() != null) { Action<bool> callback = isPressed => GameState.SwitchBuildable(_name, isPressed); ButtonBuilder.Start(_name, ButtonType.Build, _graphic, _buttonColor, callback); ButtonBuilder.AddBorder(_buttonBorderColor, _buttonBorderWidth); if (_graphic.Glyph != ' ') ButtonBuilder.AddGlyph(_buttonGlyphColor, _graphic.Glyph); ButtonBuilder.Build(); } Initialize(); }
private void PressButton(Entity clicked) { var button = clicked.Component<MenuButton>(); button.Toggle(); var buttonGraphic = clicked.Component<ButtonGraphic>(); var beadGraphic = clicked.Component<BeadGraphic>(); if (button.IsPressed == true) { buttonGraphic.ChangeToPressedGraphic(beadGraphic); } else { buttonGraphic.ChangeToOriginalGraphic(beadGraphic); } button.Callback(button.IsPressed); OpenMenu(); }
private void DrawButton(Entity buttonEntity) { var pos = buttonEntity.Component<Position>(); GameState.DrawEntity(buttonEntity); var buildable = buttonEntity.Component<Buildable>(); if (buildable != null) { DrawCounter(pos.X + 1, pos.Y, buildable.Cost, 1, _buildCounterColor, _bgColor); GameState.DrawString(pos.X + 3, pos.Y, buttonEntity.Name, _buildCounterColor); } }