示例#1
0
        public Entity CreatePlayer(Vector2 position)
        {
            var dudeTexture = _contentManager.Load <Texture2D>("hero");
            var dudeAtlas   = TextureAtlas.Create("dudeAtlas", dudeTexture, 16, 16);

            var entity      = _world.CreateEntity();
            var spriteSheet = new SpriteSheet {
                TextureAtlas = dudeAtlas
            };

            AddAnimationCycle(spriteSheet, "idle", new[] { 0, 1, 2, 1 });
            AddAnimationCycle(spriteSheet, "walk", new[] { 6, 7, 8, 9, 10, 11 });
            AddAnimationCycle(spriteSheet, "jump", new[] { 10, 12 }, false);
            AddAnimationCycle(spriteSheet, "fall", new[] { 13, 14 }, false);
            AddAnimationCycle(spriteSheet, "swim", new[] { 18, 19, 20, 21, 22, 23 });
            AddAnimationCycle(spriteSheet, "kick", new[] { 15 }, false, 0.3f);
            AddAnimationCycle(spriteSheet, "punch", new[] { 26 }, false, 0.3f);
            AddAnimationCycle(spriteSheet, "cool", new[] { 17 }, false, 0.3f);
            entity.Attach(new AnimatedSprite(spriteSheet, "idle"));
            entity.Attach(new Transform2(position, 0, Vector2.One * 4));
            entity.Attach(new Body {
                Position = position, Size = new Vector2(32, 64), BodyType = BodyType.Dynamic
            });
            entity.Attach(new Player());
            return(entity);
        }
示例#2
0
        public Entity CreatePlayer(Vector2 position)
        {
            var dudeTexture = _contentManager.Load <Texture2D>("Graphics/hero");
            var dudeAtlas   = TextureAtlas.Create("dudeAtlas", dudeTexture, 16, 16);
            var entity      = _world.CreateEntity();

            var animationFactory = new SpriteSheetAnimationFactory(dudeAtlas);

            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }));
            animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 6, 7, 8, 9, 10, 11 }, frameDuration: 0.1f));
            animationFactory.Add("combat", new SpriteSheetAnimationData(new[] { 25 }, frameDuration: 0.1f, isLooping: false));
            animationFactory.Add("guard", new SpriteSheetAnimationData(new[] { 24 }, frameDuration: 0.3f, isLooping: false));

            entity.Attach(new AnimatedSprite(animationFactory, "idle"));
            entity.Attach(new Transform2(position, 0, Vector2.One * 4));
            entity.Attach(new Body {
                Position = position, Size = new Vector2(40, 96), BodyType = BodyType.Dynamic
            });
            entity.Attach(new Focusable {
                IsFocused = true
            });
            entity.Attach(new Health()
            {
                LifePoints = 3
            });
            entity.Attach(new Player());

            return(entity);
        }
示例#3
0
        public void Setup()
        {
            _defaultWorld                      = new DefaultWorld(EntityCount);
            _defaultEntitySet                  = _defaultWorld.GetEntities().With <DefaultComponent>().AsSet();
            _defaultRunner                     = new DefaultParallelRunner(Environment.ProcessorCount);
            _defaultSystem                     = new DefaultEcsSystem(_defaultWorld);
            _defaultMultiSystem                = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
            _defaultEntityComponentSystem      = new DefaultEcsEntityComponentSystem(_defaultWorld);
            _defaultMultiEntityComponentSystem = new DefaultEcsEntityComponentSystem(_defaultWorld, _defaultRunner);
            _defaultComponentSystem            = new DefaultEcsComponentSystem(_defaultWorld);
            _defaultComponentMultiSystem       = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);

            _entitasWorld       = new Context <EntitasEntity>(1, () => new EntitasEntity());
            _entitasSystem      = new EntitasSystem(_entitasWorld);
            _entitasMultiSystem = new EntitasSystem(_entitasWorld, Environment.ProcessorCount);

            _monoWorld = new WorldBuilder().AddSystem(new MonoSystem()).Build();
            _time      = new GameTime();

            for (int i = 0; i < EntityCount; ++i)
            {
                DefaultEntity defaultEntity = _defaultWorld.CreateEntity();
                defaultEntity.Set <DefaultComponent>();

                EntitasEntity entitasEntity = _entitasWorld.CreateEntity();
                entitasEntity.AddComponent(0, new EntitasComponent());

                MonoEntity monoEntity = _monoWorld.CreateEntity();
                monoEntity.Attach(new MonoComponent());
            }
        }
        public void Setup()
        {
            _defaultWorld                      = new DefaultWorld(EntityCount);
            _defaultEntitySet                  = _defaultWorld.GetEntities().With <DefaultComponent>().AsSet();
            _defaultRunner                     = new DefaultParallelRunner(Environment.ProcessorCount);
            _defaultSystem                     = new DefaultEcsSystem(_defaultWorld);
            _defaultMultiSystem                = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
            _defaultEntityComponentSystem      = new DefaultEcsEntityComponentSystem(_defaultWorld);
            _defaultMultiEntityComponentSystem = new DefaultEcsEntityComponentSystem(_defaultWorld, _defaultRunner);
            _defaultComponentSystem            = new DefaultEcsComponentSystem(_defaultWorld);
            _defaultComponentMultiSystem       = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);
            _defaultGeneratorSystem            = new DefaultEcsGeneratorSystem(_defaultWorld);
            _defaultGeneratorMultiSystem       = new DefaultEcsGeneratorSystem(_defaultWorld, _defaultRunner);

            _entitasWorld       = new Context <EntitasEntity>(1, () => new EntitasEntity());
            _entitasSystem      = new EntitasSystem(_entitasWorld);
            _entitasMultiSystem = new EntitasSystem(_entitasWorld, Environment.ProcessorCount);

            _monoWorld = new WorldBuilder().AddSystem(new MonoSystem()).Build();
            _time      = new GameTime();

            _leoWorld   = new LeoWorld();
            _leoSystem  = new LeoSystem();
            _leoSystems = new LeoSystems(_leoWorld).Add(_leoSystem);
            _leoSystems.ProcessInjects().Init();

            SimpleEntitiesSubmissionScheduler sveltoScheduler = new SimpleEntitiesSubmissionScheduler();

            _sveltoWorld  = new EnginesRoot(sveltoScheduler);
            _sveltoSystem = new SveltoSystem();
            _sveltoWorld.AddEngine(_sveltoSystem);
            IEntityFactory sveltoFactory = _sveltoWorld.GenerateEntityFactory();

            for (int i = 0; i < EntityCount; ++i)
            {
                DefaultEntity defaultEntity = _defaultWorld.CreateEntity();
                defaultEntity.Set <DefaultComponent>();

                EntitasEntity entitasEntity = _entitasWorld.CreateEntity();
                entitasEntity.AddComponent(0, new EntitasComponent());

                MonoEntity monoEntity = _monoWorld.CreateEntity();
                monoEntity.Attach(new MonoComponent());

                LeoEntity leoEntity = _leoWorld.NewEntity();
                leoEntity.Get <LeoComponent>();

                sveltoFactory.BuildEntity <SveltoEntity>((uint)i, _sveltoGroup);
            }

            sveltoScheduler.SubmitEntities();
        }
        public Entity CreatePlayer(Vector2 position)
        {
            var dudeTexture = _contentManager.Load <Texture2D>("hero");
            var dudeAtlas   = TextureAtlas.Create("dudeAtlas", dudeTexture, 16, 16);

            var entity           = _world.CreateEntity();
            var animationFactory = new SpriteSheetAnimationFactory(dudeAtlas);

            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }));
            animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 6, 7, 8, 9, 10, 11 }, frameDuration: 0.1f));
            animationFactory.Add("jump", new SpriteSheetAnimationData(new[] { 10, 12 }, frameDuration: 1.0f, isLooping: false));
            animationFactory.Add("fall", new SpriteSheetAnimationData(new[] { 13, 14 }, frameDuration: 1.0f, isLooping: false));
            animationFactory.Add("swim", new SpriteSheetAnimationData(new[] { 18, 19, 20, 21, 22, 23 }));
            animationFactory.Add("kick", new SpriteSheetAnimationData(new[] { 15 }, frameDuration: 0.3f, isLooping: false));
            animationFactory.Add("punch", new SpriteSheetAnimationData(new[] { 26 }, frameDuration: 0.3f, isLooping: false));
            animationFactory.Add("cool", new SpriteSheetAnimationData(new[] { 17 }, frameDuration: 0.3f, isLooping: false));
            entity.Attach(new AnimatedSprite(animationFactory, "idle"));
            entity.Attach(new Transform2(position, 0, Vector2.One * 4));
            entity.Attach(new Body {
                Position = position, Size = new Vector2(32, 64), BodyType = BodyType.Dynamic
            });
            entity.Attach(new Player());
            return(entity);
        }
示例#6
0
文件: Scene.cs 项目: cshlatz/kazaam2D
        public Entity CreateEntity()
        {
            var entity = SceneWorld.CreateEntity();

            return(entity);
        }