示例#1
0
 public PlayerMovingHandler(IInputMapProvider inputMapProvider)
     : base(PlayerStates.Moving)
 {
     _inputMapProvider = inputMapProvider;
     SystemMessageBroker.AddListener <EntityCreated>(this);
     SystemMessageBroker.AddListener <EntityDestroyed>(this);
 }
示例#2
0
        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);
        }
示例#3
0
 public SpriteDrawingSystem(ContentManager contentManager, SpriteBatch spriteBatch)
 {
     _spriteBatch = spriteBatch;
     _debugFont   = contentManager.Load <SpriteFont>("default");
     SystemMessageBroker.AddListener <ComponentAdded <Sprite> >(this);
     SystemMessageBroker.AddListener <ComponentRemoved <Sprite> >(this);
 }
示例#4
0
 public TComponent AddComponent <TComponent>(TComponent component) where TComponent : ComponentBase
 {
     _components.Add(component);
     component.Entity = this;
     SystemMessageBroker.Send(new ComponentAdded <TComponent>(component, this));
     return(component);
 }
示例#5
0
        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);
        }
示例#6
0
 public PlayerInputHandlingSystem(
     IntentProvider intentProvider,
     ConfigurationService configurationService)
 {
     _intentProvider = intentProvider;
     _tileSize       = configurationService.GetTileSizeInPixels();
     SystemMessageBroker.AddListener <EntityCreated>(this);
 }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
 public static void Raise <TEvent>(TEvent @event) where TEvent : IGameEvent
 {
     SystemMessageBroker.Send(@event);
 }
示例#11
0
 public TileEventsSystem()
 {
     GameEventManager.RegisterHandler <PlayerAbandonedTile>(this);
     SystemMessageBroker.AddListener <EntityCreated>(this);
     GameEventManager.RegisterHandler <PlayerEnteredTile>(this);
 }
示例#12
0
 public FsmSystem()
 {
     _handlersDictionary = new Dictionary <string, StateHandlerBase>();
     SystemMessageBroker.AddListener <ComponentAdded <State> >(this);
 }
示例#13
0
 public AnimationSystem(int fps)
 {
     _fps = fps;
     SystemMessageBroker.AddListener <ComponentAdded <Animator> >(this);
     SystemMessageBroker.AddListener <EntityDestroyed>(this);
 }
示例#14
0
 public static void Destroy(Entity entity)
 {
     entity.Destroyed = true;
     SystemMessageBroker.Send(new EntityDestroyed(entity));
 }
示例#15
0
 public void RemoveComponent <TComponent>(TComponent component) where TComponent : ComponentBase
 {
     _components.Remove(component);
     component.Entity = null;
     SystemMessageBroker.Send(new ComponentRemoved <TComponent>(component, this));
 }
示例#16
0
 public static void RegisterHandler <TEvent>(IGameEventHandler <TEvent> handler) where TEvent : IGameEvent
 {
     SystemMessageBroker.AddListener(handler);
 }
示例#17
0
 public EntityRepository()
 {
     SystemMessageBroker.AddListener <EntityCreated>(this);
     SystemMessageBroker.AddListener <EntityDestroyed>(this);
 }
示例#18
0
 public CommandHandlingSystem()
 {
     SystemMessageBroker.AddListener <ComponentAdded <CommandQueue> >(this);
     SystemMessageBroker.AddListener <ComponentRemoved <CommandQueue> >(this);
 }
示例#19
0
 protected SystemBase()
 {
     SystemMessageBroker.AddListener(this);
 }
示例#20
0
 public MoveToScreenPositionSystem()
 {
     SystemMessageBroker.AddListener <ComponentAdded <TargetScreenPosition> >(this);
     SystemMessageBroker.AddListener <ComponentRemoved <TargetScreenPosition> >(this);
 }