public PlayerMovingHandler(IInputMapProvider inputMapProvider) : base(PlayerStates.Moving) { _inputMapProvider = inputMapProvider; SystemMessageBroker.AddListener <EntityCreated>(this); SystemMessageBroker.AddListener <EntityDestroyed>(this); }
public Poof CreatePoof() { var poof = new Poof(); poof.Transform.Position = Vector2.Zero; poof.AddComponent(new Animator { Animations = new[] { new Animation(_contentManager.Load <Texture2D>("poof"), new Point(32, 32)) { Looped = false, Name = "poof", Speed = 0.25f } }, }); poof.AddComponent(new Sprite { Texture2D = _contentManager.Load <Texture2D>("blank"), ZIndex = 1000 }); SystemMessageBroker.Send(new EntityCreated(poof)); return(poof); }
public SpriteDrawingSystem(ContentManager contentManager, SpriteBatch spriteBatch) { _spriteBatch = spriteBatch; _debugFont = contentManager.Load <SpriteFont>("default"); SystemMessageBroker.AddListener <ComponentAdded <Sprite> >(this); SystemMessageBroker.AddListener <ComponentRemoved <Sprite> >(this); }
public TComponent AddComponent <TComponent>(TComponent component) where TComponent : ComponentBase { _components.Add(component); component.Entity = this; SystemMessageBroker.Send(new ComponentAdded <TComponent>(component, this)); return(component); }
public Board CreateBoard(BoardData data) { var board = new Board(); var tiles = data.Tiles .Select(tileData => { var tile = _tileFactory.CreateTile(tileData); tile.Transform.SetParent(board.Transform); return(tile); }) .ToList(); board.AddComponent(new BoardInfo { Size = new Point { X = tiles.Max(t => t.GetComponent <TileInfo>().Position.X) + 1, Y = tiles.Max(t => t.GetComponent <TileInfo>().Position.Y) + 1 } }); board.Name = "Board"; var end = _endFactory.CreateEnd(); end.PositionOnBoard.Current = data.End; end.Transform.Position = (data.End * _configurationService.GetTileSizeInPixels()).ToVector2(); end.Transform.SetParent(board.Transform); SystemMessageBroker.Send(new EntityCreated(board)); return(board); }
public PlayerInputHandlingSystem( IntentProvider intentProvider, ConfigurationService configurationService) { _intentProvider = intentProvider; _tileSize = configurationService.GetTileSizeInPixels(); SystemMessageBroker.AddListener <EntityCreated>(this); }
public Player CreatePlayer() { var player = new Player(); var texture = _contentManager.Load <Texture2D>(SpriteSheetNames.PlayerSheet); player.Sprite = player.AddComponent(new Sprite { Texture2D = texture, ZIndex = 2000, Rectangle = new Rectangle(0, 0, 32, 32) }); player.PositionOnBoard = player.AddComponent(new PositionOnBoard()); player.CommandQueue = player.AddComponent(new CommandQueue()); player.State = player.AddComponent(new State { CurrentState = PlayerStates.Idle }); player.Animator = player.AddComponent(new Animator { Animations = new List <Animation> { new Animation(_contentManager.Load <Texture2D>(SpriteSheetNames.PlayerSheet), new [] { new Rectangle(0, 0, 32, 32), new Rectangle(32, 0, 32, 32), new Rectangle(64, 0, 32, 32), new Rectangle(96, 0, 32, 32), new Rectangle(128, 0, 32, 32), new Rectangle(160, 0, 32, 32), }) { Looped = false, Name = AnimationDictionary.PlayerMove, Speed = 0.5f }, new Animation(texture, new[] { new Rectangle(0, 32, 32, 32), new Rectangle(32, 32, 32, 32), new Rectangle(64, 32, 32, 32), new Rectangle(96, 32, 32, 32), new Rectangle(128, 32, 32, 32), }) { Name = AnimationDictionary.PlayerFall, Speed = 0.5f } } }); player.Name = "Player"; SystemMessageBroker.Send(new EntityCreated(player)); return(player); }
public Tile CreateTile(TileData data) { var tileSpriteSheet = _contentManager.Load <Texture2D>(SpriteSheetNames.TilesSheet); Tile tile; switch (data.TileType) { case TileType.Single: tile = CreateNormalTile(tileSpriteSheet); break; case TileType.Double: tile = CreateDoubleTile(tileSpriteSheet); break; case TileType.Triple: tile = CreateTripleTile(tileSpriteSheet); break; case TileType.Unknown: tile = CreateUnknownTile(tileSpriteSheet); break; default: tile = CreateIndestructibleTile(tileSpriteSheet); break; } var position = new Point(data.X, data.Y); tile.Transform.Position = (position * _size).ToVector2(); tile.TileInfo = tile.AddComponent(new TileInfo { Value = data.Value, Position = position, TileType = data.TileType }); tile.State = tile.AddComponent(new State { CurrentState = TileStates.Pristine }); tile.Name = $"tile {position.X} : {position.Y}"; SystemMessageBroker.Send(new EntityCreated(tile)); return(tile); }
public End CreateEnd() { var sheet = _contentManager.Load <Texture2D>(SpriteSheetNames.EndSheet); var end = new End(); end.Sprite = end.AddComponent(new Sprite { Rectangle = new Rectangle(0, 0, 32, 32), Texture2D = sheet, ZIndex = 1100 }); end.State = end.AddComponent(new State { CurrentState = EndStates.Closed }); end.PositionOnBoard = end.AddComponent(new PositionOnBoard()); end.Animator = end.AddComponent(new Animator()); end.Animator.Animations = new[] { new Animation(sheet, new [] { new Rectangle(32, 0, 32, 32), new Rectangle(64, 0, 32, 32), new Rectangle(96, 0, 32, 32), new Rectangle(128, 0, 32, 32), }) { Looped = true, Name = AnimationDictionary.EndOpen, Speed = 0.15f } }; SystemMessageBroker.Send(new EntityCreated(end)); return(end); }
public static void Raise <TEvent>(TEvent @event) where TEvent : IGameEvent { SystemMessageBroker.Send(@event); }
public TileEventsSystem() { GameEventManager.RegisterHandler <PlayerAbandonedTile>(this); SystemMessageBroker.AddListener <EntityCreated>(this); GameEventManager.RegisterHandler <PlayerEnteredTile>(this); }
public FsmSystem() { _handlersDictionary = new Dictionary <string, StateHandlerBase>(); SystemMessageBroker.AddListener <ComponentAdded <State> >(this); }
public AnimationSystem(int fps) { _fps = fps; SystemMessageBroker.AddListener <ComponentAdded <Animator> >(this); SystemMessageBroker.AddListener <EntityDestroyed>(this); }
public static void Destroy(Entity entity) { entity.Destroyed = true; SystemMessageBroker.Send(new EntityDestroyed(entity)); }
public void RemoveComponent <TComponent>(TComponent component) where TComponent : ComponentBase { _components.Remove(component); component.Entity = null; SystemMessageBroker.Send(new ComponentRemoved <TComponent>(component, this)); }
public static void RegisterHandler <TEvent>(IGameEventHandler <TEvent> handler) where TEvent : IGameEvent { SystemMessageBroker.AddListener(handler); }
public EntityRepository() { SystemMessageBroker.AddListener <EntityCreated>(this); SystemMessageBroker.AddListener <EntityDestroyed>(this); }
public CommandHandlingSystem() { SystemMessageBroker.AddListener <ComponentAdded <CommandQueue> >(this); SystemMessageBroker.AddListener <ComponentRemoved <CommandQueue> >(this); }
protected SystemBase() { SystemMessageBroker.AddListener(this); }
public MoveToScreenPositionSystem() { SystemMessageBroker.AddListener <ComponentAdded <TargetScreenPosition> >(this); SystemMessageBroker.AddListener <ComponentRemoved <TargetScreenPosition> >(this); }