private void LogAvatarStatus(IAtlas atlas, float temperatureAround) { string areaName = atlas.AreasCarrier.AreaName(Position); if (areaName != null) { Log.Instance.Debug("Name of current Avatar's location is " + areaName + "."); } else { Log.Instance.Debug("Avatar is in unknown location."); } string roomName = atlas.AreasCarrier.RoomName(Position); if (roomName != null) { Log.Instance.Debug("Avatar is in room " + roomName + "."); } else { Log.Instance.Debug("Avatar is in no room."); } Log.Instance.Debug("Energy of avatar {" + Id + "} is " + Energy); Log.Instance.Debug("Temperature around avatar " + temperatureAround + "."); Log.Instance.Debug("Temperature of avatar " + Temperature + "."); }
public void PickUp(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable = null) { if (gameAction is PickUp || gameAction is LayDown) { gameAction.Resolve(new GameActorPosition(this, position, LayerType.Object), atlas, tilesetTable); } }
public ISwitchableGameActor SwitchOff(GameActorPosition gameActorPosition, IAtlas atlas) { TilesetId = AlternativeTextures.Id("Open"); atlas.MoveToOtherLayer(new GameActorPosition(this, new Vector2(Position), LayerType.OnGroundInteractable), LayerType.ObstacleInteractable); m_closed = false; return(this); }
private bool PerformPickup(IAtlas atlas, ITilesetTable tilesetTable) { // check tile in front of List <GameActorPosition> targets = GetInteractableTilesInFrontOf(atlas); // if no tile, check objects if (targets.Count == 0) { targets = GetInteractableObjectsInFrontOf(atlas); } if (targets.Count == 0) { return(false); } foreach (GameActorPosition target in targets) { IPickableGameActor interactableTarget = target.Actor as IPickableGameActor; if (interactableTarget == null) { continue; } GameAction pickUpAction = new PickUp(this); interactableTarget.PickUp(atlas, pickUpAction, target.Position, tilesetTable); RemoveSpeed(target); return(true); } return(false); }
public void PickUp(IAtlas atlas, GameAction gameAction, Vector2 position) { if (gameAction is PickUp || gameAction is LayDown) { gameAction.Resolve(new GameActorPosition(this, position, LayerType.Object), atlas); } }
static void Main(string[] args) { // configure our dependency injection var serviceProvider = new ServiceCollection() .AddLogging(config => { config.ClearProviders().AddConsole(); }) .AddScoped <IDefaultValidators, DefaultValidators>() .AddScoped <IAtlasConsoleOutputService, AtlasConsoleOutputService>() .AddTransient <ISolverService, SolverService>() .BuildServiceProvider(); // get our solver service var solverService = serviceProvider.GetService <ISolverService>(); var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger <Program>(); // generate a test atlas to generate IAtlas <TextItem> atlasOutput = null; var result = solverService.Solve(50, 100, new List <TextItem> { new TextItem { Width = 25, Height = 25, Character = 'a' }, new TextItem { Width = 25, Height = 50, Character = 'B' }, new TextItem { Width = 5, Height = 5, Character = 'c' }, new TextItem { Width = 9, Height = 14, Character = 'D' }, new TextItem { Width = 25, Height = 3, Character = 'e' } }, out atlasOutput); if (result) { // generate our output var outputService = serviceProvider.GetService <IAtlasConsoleOutputService>(); var output = outputService.GenerateConsoleOutput <TextItem>(atlasOutput); // print it to screen foreach (var line in output) { Console.WriteLine(line); } } else { Console.WriteLine("Unable to generate atlas."); } serviceProvider.Dispose(); Console.WriteLine(""); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); }
public void Switch(GameActorPosition gameActorPosition, IAtlas atlas, ITilesetTable table) { var leverOn = new LeverSwitchOn(table, Position); atlas.ReplaceWith(new GameActorPosition(this, (Vector2)Position, LayerType.ObstacleInteractable), leverOn); if (Switchable == null) return; leverOn.Switchable = Switchable.Switch(null, atlas, table); }
private void Ignite(IAtlas atlas, ITilesetTable tilesetTable) { var fireplaceBurning = new FireplaceBurning(tilesetTable, Position); atlas.ReplaceWith(ThisGameActorPosition(LayerType.OnGroundInteractable), fireplaceBurning); atlas.RegisterToAutoupdate(fireplaceBurning); }
public void Update(IAtlas atlas) { List <Vector2I> free = atlas.FreePositionsAround(Position, LayerType.Obstacle | LayerType.Object).ToList(); if (free.Count == 0) { return; } // filter out position with PathTiles free = free.Where(x => atlas.ActorsAt((Vector2)x, LayerType.Background).First().Actor.GetType() != typeof(PathTile)).ToList(); if (free.Count == 0) { return; } Vector2I targetPosition = free[m_rng.Next(free.Count)]; object[] args = { targetPosition }; Fruit fruit = (Fruit)Activator.CreateInstance(typeof(T), args); GameActorPosition fruitPosition = new GameActorPosition(fruit, new Vector2(targetPosition), LayerType.ObstacleInteractable); atlas.Add(fruitPosition); NextUpdateAfter = m_updatePeriod; }
public void Update(IAtlas atlas, ITilesetTable table) { List<IGameObject> stayingOnTile = atlas.StayingOnTile(Position); if (stayingOnTile.Count != 0) return; atlas.ReplaceWith(new GameActorPosition(this, new Vector2(Position), LayerType.OnGroundInteractable), new TrapCharged(table, Position)); NextUpdateAfter = 0; }
private bool PerformLayDown(IAtlas atlas, ITilesetTable tilesetTable) { Vector2 positionInFrontOf = atlas.PositionInFrontOf(this, 1); GameAction layDownAction = new LayDown(this); Tool.PickUp(atlas, layDownAction, positionInFrontOf, tilesetTable); return(true); }
public ISwitchableGameActor Switch(GameActorPosition gameActorPosition, IAtlas atlas, ITilesetTable table) { RcDoorClosed closedDoor = new RcDoorClosed(table, Position); bool added = atlas.Add(new GameActorPosition(closedDoor, (Vector2)Position, LayerType.ObstacleInteractable), true); if (!added) return this; atlas.Remove(new GameActorPosition(this, (Vector2)Position, LayerType.OnGroundInteractable)); return closedDoor; }
public LuaExecutor(IAtlas atlas, LuaConsole luaConsole = null) { m_atlas = atlas; DoWorkSync = new AutoResetEvent(false); WorkDoneSync = new AutoResetEvent(false); m_luaConsole = luaConsole; SetInitialState(); }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position) { var interact = gameAction as Interact; if (interact != null) { Ignite(atlas); } }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable) { var doorOpened = new SimpleDoorOpened(tilesetTable); bool added = atlas.Add(new GameActorPosition(doorOpened, position, LayerType.OnGroundInteractable)); if (added) { atlas.Remove(new GameActorPosition(this, position, LayerType.ObstacleInteractable)); } }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable) { var interact = gameAction as Interact; if (interact != null) { Ignite(atlas, tilesetTable); } }
public void ObjectDetected(IGameObject gameObject, IAtlas atlas) { if (SomeoneOnTile) { return; } NextUpdateAfter = 60; atlas.RegisterToAutoupdate(this); }
private List <GameActorPosition> GetInteractableObjectsInFrontOf(IAtlas atlas) { // check circle in front of avatar float radius = ((CircleShape)PhysicalEntity.Shape).Radius; List <GameActorPosition> actorsInFrontOf = atlas.ActorsInFrontOf(this, LayerType.Object, 0.2f + radius, radius).ToList(); return(actorsInFrontOf); }
public void Use(GameActorPosition senderPosition, IAtlas atlas, ITilesetTable tilesetTable) { IEnumerable<GameActorPosition> actorsInFrontOf = atlas.ActorsInFrontOf(senderPosition.Actor as ICharacter).ToList(); if (actorsInFrontOf.Select(x => x.Actor).Contains(Switchable as GameActor)) { GameActorPosition switchable = actorsInFrontOf.First(x => x.Actor == Switchable); Switch(switchable, atlas, tilesetTable); } }
public override void Resolve(GameActorPosition target, IAtlas atlas, ITilesetTable table) { ICanPickGameObject picker = Sender as ICanPickGameObject; IPickableGameActor pickItem = target.Actor as IPickableGameActor; if (picker == null || pickItem == null) return; if (picker.AddToInventory(pickItem)) atlas.Remove(target); }
public AvatarCommander(LuaExecutor ex, IAtlas atlas) { m_atlas = atlas; ex.State.RegisterFunction("Vector", typeof(AtlasManipulator).GetMethod("Vector")); m_currentAvatar = atlas.Avatars.Values.First(); ex.State["avatar"] = m_currentAvatar; m_le = ex; }
public void Use(GameActorPosition senderPosition, IAtlas atlas) { IEnumerable <GameActorPosition> actorsInFrontOf = atlas.ActorsInFrontOf(senderPosition.Actor as ICharacter).ToList(); if (actorsInFrontOf.Select(x => x.Actor).Contains(Switchable as GameActor)) { GameActorPosition switchable = actorsInFrontOf.First(x => x.Actor == Switchable); Switch(switchable, atlas); } }
public void ObjectDetected(IGameObject gameObject, IAtlas atlas) { if (m_wasActive) { m_isActive = true; return; } m_isActive = true; NextUpdateAfter = 1; atlas.RegisterToAutoupdate(this); }
public void Switch(GameActorPosition gameActorPosition, IAtlas atlas, ITilesetTable table) { var leverOff = new LeverSwitchOff(table, Position); atlas.ReplaceWith(new GameActorPosition(this, (Vector2)Position, LayerType.ObstacleInteractable), leverOff); if (Switchable == null) { return; } leverOff.Switchable = Switchable.Switch(null, atlas, table) as ISwitchableGameActor; }
public AtlasTests() { Stream tmxStream = FileStreams.SmallPickupTmx(); StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream()); TmxSerializer serializer = new TmxSerializer(); Map map = serializer.Deserialize(tmxStream); ToyWorld world = new ToyWorld(map, tilesetTableStreamReader); m_atlas = world.Atlas; }
public void Switch(GameActorPosition gameActorPosition, IAtlas atlas) { if (m_On) { SwitchOff(gameActorPosition, atlas); } else { SwitchOn(gameActorPosition, atlas); } }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable = null) { UsePickaxe action = gameAction as UsePickaxe; if (action != null) { UsePickaxe usePickaxe = action; Health -= usePickaxe.Damage; } if (Health <= 0f) atlas.ReplaceWith(new GameActorPosition(this, position, LayerType.ObstacleInteractable), new DestroyedWall(tilesetTable)); }
public void Update(IAtlas atlas, ITilesetTable table) { List <IGameObject> stayingOnTile = atlas.StayingOnTile(Position); if (stayingOnTile.Count != 0) { return; } atlas.ReplaceWith(new GameActorPosition(this, new Vector2(Position), LayerType.OnGroundInteractable), new TrapCharged(table, Position)); NextUpdateAfter = 0; }
public ISwitchableGameActor Switch(GameActorPosition gameActorPosition, IAtlas atlas) { if (m_closed) { SwitchOff(gameActorPosition, atlas); } else { SwitchOn(gameActorPosition, atlas); } return(this); }
public ISwitchableGameActor Switch(GameActorPosition gameActorPosition, IAtlas atlas, ITilesetTable table) { RcDoorClosed closedDoor = new RcDoorClosed(table, Position); bool added = atlas.Add(new GameActorPosition(closedDoor, (Vector2)Position, LayerType.ObstacleInteractable), true); if (!added) { return(this); } atlas.Remove(new GameActorPosition(this, (Vector2)Position, LayerType.OnGroundInteractable)); return(closedDoor); }
public LuaConsole(ToyWorld toyWorld, IAtlas atlas) { InitializeComponent(); toyWorld.ToyWorldDisposed += CloseConsole; outputListBox.DataSource = m_inputOutputList; m_lex = new LuaExecutor(atlas, this); m_inputOutputList.Add(INVITATION_MESSAGE); ResetBox(); }
public void Update(IAtlas atlas, ITilesetTable table) { List<IGameObject> gameActorPositions = atlas.StayingOnTile(Position); SomeoneOnTile = gameActorPositions.Any(); foreach (IGameObject gameActor in gameActorPositions) { IAvatar avatar = gameActor as IAvatar; if (avatar != null) avatar.Rested += TWConfig.Instance.BedRechargeRate; } }
public CollisionChecker(IAtlas atlas) { m_atlas = atlas; m_objectLayer = atlas.GetLayer(LayerType.Object) as SimpleObjectLayer; if (m_objectLayer != null) { m_physicalEntities = m_objectLayer.GetPhysicalEntities(); } else { throw new ArgumentException("ObjectLayer not found."); } }
public void Update(IAtlas atlas) { if (m_isActive) { Switchable?.SwitchOn(null, atlas); m_isActive = false; m_wasActive = true; NextUpdateAfter = DELAY; return; } Switchable?.SwitchOff(null, atlas); NextUpdateAfter = 0; m_wasActive = false; }
private static void FillNamedAreas(IAtlas atlas, Map map) { ObjectGroup foregroundObjects = map.ObjectGroups.First(x => x.Name == "ForegroundObject"); List <TmxObject> tmxMapObjects = foregroundObjects.TmxMapObjects; List <TmxObject> areaLabels = tmxMapObjects.Where(x => x.Type.Trim() == "AreaLabel").ToList(); IEnumerable <Vector2I> positions = areaLabels.Select(x => new Vector2I((int)Math.Floor(x.X), (int)Math.Floor(x.Y))); IEnumerable <string> names = areaLabels.Select(x => x.Name); List <Tuple <Vector2I, string> > namesPositions = positions.Zip(names, (x, y) => new Tuple <Vector2I, string>(x, y)).ToList(); atlas.AreasCarrier = new AreasCarrier((ITileLayer)atlas.GetLayer(LayerType.Background), (ITileLayer)atlas.GetLayer(LayerType.Area), namesPositions); }
public void Update(IAtlas atlas) { List<IGameObject> stayingOnTile = atlas.StayingOnTile(Position); if (stayingOnTile.Count == 0) { Charged = true; } if (Charged) { var avatars = stayingOnTile.OfType<IAvatar>(); avatars.ForEach(x => x.Energy -= ENERGY_FOR_STEP_ON_TRAP); Charged = false; } }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position) { if (m_closed) { TilesetId = AlternativeTextures.Id("Open"); atlas.MoveToOtherLayer(new GameActorPosition(this, position, LayerType.ObstacleInteractable), LayerType.OnGroundInteractable); } else { TilesetId = AlternativeTextures.Id("Closed"); atlas.MoveToOtherLayer(new GameActorPosition(this, position, LayerType.OnGroundInteractable), LayerType.ObstacleInteractable); } m_closed = !m_closed; }
public override void Resolve(GameActorPosition target, IAtlas atlas, ITilesetTable table) { if (target.Actor is Apple || target.Actor is Pear) { atlas.Remove(target); } var switcher = target.Actor as ISwitcherGameActor; if (switcher != null) { switcher.Switch(target, atlas, table); } }
public void Update(IAtlas atlas, ITilesetTable table) { List<IGameObject> gameActorPositions = atlas.StayingOnTile(Position); SomeoneOnTile = gameActorPositions.Any(); foreach (IGameObject gameActor in gameActorPositions) { var avatar = gameActor as IAvatar; if (avatar != null) { avatar.Energy += ENERGY_RECHARGED; } } }
public void Update(IAtlas atlas, ITilesetTable table) { List<IGameObject> gameActorPositions = atlas.StayingOnTile(Position); SomeoneOnTile = gameActorPositions.Any(); foreach (IGameObject gameActor in gameActorPositions) { var avatar = gameActor as IAvatar; if (avatar != null) { avatar.Energy -= ENERGY_FOR_STEP_OR_WAIT_A_SECOND_ON_POISON; } } }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable = null) { UsePickaxe action = gameAction as UsePickaxe; if (action != null) { UsePickaxe usePickaxe = action; Health -= usePickaxe.Damage; } if (Health <= 0f) { atlas.ReplaceWith(new GameActorPosition(this, position, LayerType.ObstacleInteractable), new DestroyedWall(tilesetTable)); } }
public void UpdateItems(IAtlas atlas, TilesetTable table) { if (atlas.NewAutoupdateables != null) { CurrentUpdateRequests.AddRange(atlas.NewAutoupdateables); atlas.NewAutoupdateables.Clear(); } foreach (IAutoupdateableGameActor actor in CurrentUpdateRequests) { actor.Update(atlas, table); if (actor.NextUpdateAfter > 0) Register(actor, actor.NextUpdateAfter); } CurrentUpdateRequests.Clear(); }
public MapLoaderTests() { // initiate streamReaders var tmxMemoryStream = FileStreams.SmallTmx(); var tilesetTableMemoryStream = FileStreams.TilesetTableStream(); var tilesetTableStreamReader = new StreamReader(tilesetTableMemoryStream); var serializer = new TmxSerializer(); Map map = serializer.Deserialize(tmxMemoryStream); var tilesetTable = new TilesetTable(map, tilesetTableStreamReader); // create atlas m_atlas = MapLoader.LoadMap(map, tilesetTable, (GameActor actor) => { }); }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable = null) { if (!(gameAction is UsePickaxe)) return; UsePickaxe usePickaxe = (UsePickaxe)gameAction; if (Math.Abs(usePickaxe.Damage) < 0.00001f) return; if (usePickaxe.Damage >= 1.0f) { atlas.ReplaceWith(new GameActorPosition(this, position, LayerType.ObstacleInteractable), new DestroyedWall(tilesetTable)); return; } atlas.ReplaceWith(new GameActorPosition(this, position, LayerType.ObstacleInteractable), new DamagedWall(usePickaxe.Damage, tilesetTable, Vector2I.Zero)); }
public void ObjectDetected(IGameObject gameObject, IAtlas atlas, ITilesetTable tilesetTable) { var avatar = gameObject as IAvatar; if (avatar != null) { avatar.Energy -= ENERGY_FOR_STEP_ON_TRAP; } var forwardMovable = gameObject as IForwardMovable; if (forwardMovable != null) { forwardMovable.ForwardSpeed = 0; } gameObject.Position = Vector2.Floor(gameObject.Position) + Vector2.One/2; var trapDischarged = new TrapDischarged(tilesetTable, Position); atlas.RegisterToAutoupdate(trapDischarged); atlas.ReplaceWith(new GameActorPosition(this, new Vector2(Position), LayerType.OnGroundInteractable), trapDischarged); }
public void Update(IAtlas atlas, ITilesetTable table) { if (Heat < 0) { // first update - fire starts Heat = 0.2f; atlas.RegisterHeatSource(this); NextUpdateAfter = 60; } if (Heat >= MAX_HEAT && m_counter > 1000) { // fourth update - fire is extinguished. Heat = 0; NextUpdateAfter = 0; var fireplace = new Fireplace(table, Position); atlas.UnregisterHeatSource(this); atlas.ReplaceWith(ThisGameActorPosition(LayerType.OnGroundInteractable), fireplace); return; } if (Heat < MAX_HEAT) { // second update - fire is growing Heat += 0.4f; } if(Heat >= MAX_HEAT) { // third update - fire is stable IEnumerable<GameActorPosition> gameActorPositions = atlas.ActorsAt((Vector2) Position, LayerType.All); foreach (GameActorPosition gameActorPosition in gameActorPositions) { ICombustibleGameActor combustible = gameActorPosition.Actor as ICombustibleGameActor; if (combustible != null) { combustible.Burn(gameActorPosition, atlas, table); } } m_counter++; } }
public UnpredictableAtmosphere(IAtlas atlas) { m_atlas = atlas; m_heatSources = new List<IHeatSource>(); m_oldTemperature = 1f; DateTime time = atlas.RealTime; bool getCold = time.Hour < 6 || time.Hour >= 18; if (getCold) { m_newDiff = -0.1f; } else { m_newDiff = 0.1f; } long cycles = time.Ticks / TICKS_IN_12_HOURS; m_prevCycleStart = new DateTime(cycles * TICKS_IN_12_HOURS - TICKS_IN_12_HOURS / 2); }
public override void Resolve(GameActorPosition target, IAtlas atlas, ITilesetTable table) { ICanPickGameObject picker = Sender as ICanPickGameObject; ICharacter character = Sender as ICharacter; if (picker == null || character == null) return; Vector2 positionInFrontOf = target.Position; // solving case when positions where character should place tile collides with character's position if (target.Actor is Tile) { Tile tile = (target.Actor as Tile); IPhysicalEntity physicalEntity = tile.GetPhysicalEntity(new Vector2I(positionInFrontOf)); bool collidesWithSource = physicalEntity.CollidesWith(character.PhysicalEntity); if (collidesWithSource) { /* <- change to //* to switch // to the center of current tile character.Position = Vector2.Floor(character.Position) + Vector2.One/2; /*/ // back WRT his direction do { character.Position = Physics.Utils.Move(character.Position, character.Direction, -0.01f); } while (physicalEntity.CollidesWith(character.PhysicalEntity)); // */ } } GameActorPosition toLayDown = new GameActorPosition(target.Actor, positionInFrontOf, target.Layer); bool added = atlas.Add(toLayDown, true); if (added) { picker.RemoveFromInventory(); } }
public void Update(IAtlas atlas, ITilesetTable table) { atlas.Remove(new GameActorPosition(this, (Vector2)Position, LayerType.ObstacleInteractable)); }
public void Burn(GameActorPosition gameActorPosition, IAtlas atlas, ITilesetTable table) { atlas.Remove(gameActorPosition); }
public void Switch(GameActorPosition gameActorPosition, IAtlas atlas, ITilesetTable table) { Switchable = Switchable.Switch(null, atlas, table); }
public void PickUp(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable) { gameAction.Resolve(new GameActorPosition(this, position, LayerType.OnGroundInteractable), atlas, tilesetTable); }
public void ObjectDetected(IGameObject gameObject, IAtlas atlas, ITilesetTable tilesetTable) { if(SomeoneOnTile) return; NextUpdateAfter = 60; atlas.RegisterToAutoupdate(this); }
public SimpleAtmosphere(IAtlas atlas) { m_atlas = atlas; m_heatSources = new List<IHeatSource>(); }
public void ApplyGameAction(IAtlas atlas, GameAction gameAction, Vector2 position, ITilesetTable tilesetTable) { gameAction.Resolve(new GameActorPosition(this, position, LayerType.ObstacleInteractable), atlas, tilesetTable); }