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 CreateTile(string type, string layer, float x, float y) { Type t = GameActor.GetGameActorType(type); if (t == null) { throw new Exception("Object of type " + type + " not found in assembly."); } int xi = (int)x; int yi = (int)y; GameActor ga; if (t.IsSubclassOf(typeof(DynamicTile))) { ga = (GameActor)Activator.CreateInstance(t, new Vector2I(xi, yi)); } else if (t.IsSubclassOf(typeof(Tile))) { ga = (GameActor)Activator.CreateInstance(t); } else { throw new Exception("Object of type " + t + " is not subclass of Tile."); } m_atlas.Add(new GameActorPosition(ga, new Vector2(xi, yi), Layer(layer))); }
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 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 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 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 override void Resolve(GameActorPosition target, IAtlas atlas) { 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 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(); } }