コード例 #1
0
 public Ingame(Game game)
 {
     Game          = game;
     Ecs           = new EntityComponentSystem(Game);
     EntityFactory = new EntityFactory(Game, Ecs);
     LevelManager  = new LevelManager(Game);
 }
コード例 #2
0
        public override void LoadContent()
        {
            base.LoadContent();

            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);

            _camera = new Camera2D(viewportAdapter);

            _map         = Content.Load <TiledMap>("level-1");
            _mapRenderer = new TiledMapRenderer(GraphicsDevice);

            _entityComponentSystem = new EntityComponentSystem();
            _entityFactory         = new EntityFactory(_entityComponentSystem, Content);

            var service    = new TiledObjectToEntityService(_entityFactory);
            var spawnPoint = _map.GetLayer <TiledMapObjectLayer>("entities").Objects.Single(i => i.Type == "Spawn").Position;

            _entityComponentSystem.RegisterSystem(new PlayerMovementSystem());
            _entityComponentSystem.RegisterSystem(new EnemyMovementSystem());
            _entityComponentSystem.RegisterSystem(new CharacterStateSystem(_entityFactory, spawnPoint));
            _entityComponentSystem.RegisterSystem(new BasicCollisionSystem(gravity: new Vector2(0, 1150)));
            _entityComponentSystem.RegisterSystem(new ParticleEmitterSystem());
            _entityComponentSystem.RegisterSystem(new AnimatedSpriteSystem());
            _entityComponentSystem.RegisterSystem(new SpriteBatchSystem(GraphicsDevice, _camera)
            {
                SamplerState = SamplerState.PointClamp
            });

            service.CreateEntities(_map.GetLayer <TiledMapObjectLayer>("entities").Objects);
        }
コード例 #3
0
        public GameMain()
        {
            Content.RootDirectory    = "Content";
            IsMouseVisible           = true;
            Window.AllowUserResizing = false;
            IsFixedTimeStep          = true;

            _graphicsDeviceManager = new GraphicsDeviceManager(this)
            {
                IsFullScreen                   = false,
                PreferredBackBufferWidth       = 800,
                PreferredBackBufferHeight      = 600,
                PreferredBackBufferFormat      = SurfaceFormat.Color,
                PreferMultiSampling            = false,
                PreferredDepthStencilFormat    = DepthFormat.None,
                SynchronizeWithVerticalRetrace = true,
            };

            _ecs           = new EntityComponentSystem(this);
            _entityManager = _ecs.EntityManager;

            // scan for components and systems in provided assemblies
            _ecs.Scan(Assembly.GetExecutingAssembly());

            Services.AddService(Content);
            Services.AddService(_ecs);
            Services.AddService(_random);
        }
コード例 #4
0
        public EntityFactory(EntityComponentSystem ecs, ContentManager contentManager)
        {
            _ecs           = ecs;
            _entityManager = ecs.EntityManager;

            LoadContent(contentManager);
        }
コード例 #5
0
ファイル: EntityFactory.cs プロジェクト: MichalKubik/GameTest
        public EntityFactory(EntityComponentSystem entityComponentSystem)
        {
            _entityComponentSystem = entityComponentSystem;

            var texture = Game1.Instance.Content.Load <Texture2D>("free-tileset");

            _tilesetAtlas = TextureAtlas.Create("tiny-characters-atlas", texture, 128, 128, 100, 2, 2);
        }
コード例 #6
0
        protected override void Initialize()
        {
            _ecs = new EntityComponentSystem(this);
            Services.AddService(_ecs);

            _ecs.Scan(Assembly.GetExecutingAssembly());

            base.Initialize();
        }
コード例 #7
0
ファイル: Game1.cs プロジェクト: joleeee/ESC-Test
        protected override void Initialize()
        {
            esc           = new EntityComponentSystem(this);
            entityManager = esc.EntityManager;
            esc.Scan(Assembly.GetExecutingAssembly());
            Services.AddService(spriteBatch);

            base.Initialize();
        }
コード例 #8
0
ファイル: Game1.cs プロジェクト: MichalKubik/GameTest
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 1024, 768);
            _mapRenderer     = new TiledMapRenderer(GraphicsDevice);
            _camera          = new Camera2D(_viewportAdapter);

            _entityComponentSystem = new EntityComponentSystem();
            _entityFactory         = new EntityFactory(_entityComponentSystem);
            _objectToEntityService = new TiledObjectToEntityService(_entityFactory);

            position = Vector2.Zero;
            base.Initialize();
        }
コード例 #9
0
        public void ECS_CreateEntityFromTemplate_UsingManager_Test()
        {
            // Seems to work with null.
            var ecs = new EntityComponentSystem(null);

            ecs.Scan(typeof(EntityTemplateUsingManager).Assembly);
            var    manager = ecs.EntityManager;
            Entity entity  = null;

            try
            {
                entity = manager.CreateEntityFromTemplate(EntityTemplateUsingManager.Name);
            }
            catch (Exception e)
            {
                Assert.Fail("Failed to create entity from template.\n" + e.StackTrace);
            }

            Assert.NotNull(entity);
            Assert.NotNull(entity.Get <EntityComponentBasic>());
        }
コード例 #10
0
        public EntityFactory(EntityComponentSystem entityComponentSystem, ContentManager contentManager)
        {
            _entityComponentSystem = entityComponentSystem;

            LoadContent(contentManager);
        }
コード例 #11
0
 public EntityFactory(Game game, EntityComponentSystem ecs) : base(game)
 {
     Content = new ContentManager(Game.Content.ServiceProvider, game.Content.RootDirectory);
     Ecs     = ecs;
 }