public override void Process(GameTime gameTime, int entityId) { var transporter = _transporterMapper.Get(entityId); var tilePosition = _tilePositionMapper.Get(entityId); var transportables = _tileOccupationManager.GetItemsInArea(tilePosition.GetArea()) .Where(entity => _transportableMapper.Has(entity)) .Select(entity => _transportableMapper.Get(entity)); foreach (var transportable in transportables) { var motion = new Vector2(0, (float)(-transporter.TransportSpeed * gameTime.ElapsedGameTime.TotalSeconds)); if (IsTransporterAtNextTile(tilePosition, motion)) { transportable.Velocity = motion; } } }
public override void Update(GameTime gameTime) { foreach (var entityId in ActiveEntities) { var transportable = _transportableMapper.Get(entityId); var tilePosition = _tilePositionMapper.Get(entityId); var newPosition = tilePosition.Position + transportable.Velocity; if (!_tileOccupationManager .GetItemsInArea(new RectangleF(newPosition.X, newPosition.Y, tilePosition.TileSpan.X, tilePosition.TileSpan.Y)) .Where(e => e != entityId) .Any(e => _productMapper.Has(e))) { tilePosition.Move(transportable.Velocity); } } foreach (var entityId in ActiveEntities) { var transportable = _transportableMapper.Get(entityId); transportable.Velocity = Vector2.Zero; } }
private bool OutputPositionIsOccupied(TilePosition outputPosition) { return(_tileOccupationManager.GetItemsInArea(outputPosition.GetArea()).Any(ie => _blockableMapper.Has(ie) || _productMapper.Has(ie))); }
private IEnumerable <MineableResource> GetActiveMineableResources(TilePosition tilePosition) { return(_tileOccupationManager.GetItemsInArea(tilePosition.GetArea()).Select(i => _mineableResourceMapper.Get(i)).Where(r => r != null)); }