Exemplo n.º 1
0
 internal SystemManager(EntityComponentSystem manager)
 {
     _manager          = manager;
     _updateLayers     = new SystemLayer[0];
     _drawLayers       = new SystemLayer[0];
     _dummyLayer       = new SystemLayer();
     Systems           = new List <EntitySystem>();
     ProcessingSystems = new List <EntityProcessingSystem>();
 }
Exemplo n.º 2
0
        public Entity(EntityComponentSystem entityComponentSystem, long id, string name)
        {
            _entityComponentSystem = entityComponentSystem;
            _components            = new List <EntityComponent>();

            Id       = id;
            Name     = name;
            Position = Vector2.Zero;
            Rotation = 0;
            Scale    = Vector2.One;
        }
Exemplo n.º 3
0
        protected override void LoadContent()
        {
            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);

            _camera = new Camera2D(viewportAdapter);

            _entityComponentSystem = new MonoGame.Extended.Entities.EntityComponentSystem();
            _entityComponentSystem.RegisterSystem(new SpriteBatchSystem(GraphicsDevice, _camera));
            _entityComponentSystem.RegisterSystem(new AnimatedSpriteSystem());
            _entityComponentSystem.RegisterSystem(new ParticleEmitterSystem());

            var logoTexture = Content.Load <Texture2D>("logo-square-128");

            _entity = _entityComponentSystem.CreateEntity("logo", new Vector2(400, 240));
            _entity.AttachComponent(new TransformableComponent <Sprite>(new Sprite(logoTexture)));

            var motwTexture          = Content.Load <Texture2D>("motw");
            var motwAtlas            = TextureAtlas.Create("motw-atlas", motwTexture, 52, 72);
            var motwAnimationFactory = new SpriteSheetAnimationFactory(motwAtlas);

            motwAnimationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0 }));
            motwAnimationFactory.Add("walkSouth", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }, isLooping: false));
            motwAnimationFactory.Add("walkWest", new SpriteSheetAnimationData(new[] { 12, 13, 14, 13 }, isLooping: false));
            motwAnimationFactory.Add("walkEast", new SpriteSheetAnimationData(new[] { 24, 25, 26, 25 }, isLooping: false));
            motwAnimationFactory.Add("walkNorth", new SpriteSheetAnimationData(new[] { 36, 37, 38, 37 }, isLooping: false));

            var animatedEntity = _entityComponentSystem.CreateEntity("animated", new Vector2(50, 50));

            animatedEntity.AttachComponent(new TransformableComponent <Sprite>(new AnimatedSprite(motwAnimationFactory, "walkSouth")));

            var particleEntity  = _entityComponentSystem.CreateEntity("particles", new Vector2(500, 50));
            var particleEmitter = new ParticleEmitter(new TextureRegion2D(logoTexture), 500, TimeSpan.FromSeconds(0.5f),
                                                      Profile.Point())
            {
                Parameters = new ParticleReleaseParameters
                {
                    Speed    = new Range <float>(0f, 150f),
                    Quantity = 30,
                    Rotation = new Range <float>(-1f, 1f),
                    Scale    = new Range <float>(3.0f, 4.0f)
                },
                Modifiers = new IModifier[]
                {
                    new AgeModifier
                    {
                        Interpolators = new IInterpolator[]
                        {
                            new ColorInterpolator
                            {
                                InitialColor = new HslColor(0.8f, 0.8f, 0.8f),
                                FinalColor   = new HslColor(0.5f, 0.9f, 1.0f)
                            }
                        }
                    },
                    new RotationModifier {
                        RotationRate = -2.1f
                    },
                    new RectangleContainerModifier {
                        Width = 800, Height = 480
                    },
                    new LinearGravityModifier {
                        Direction = -Vector2.UnitY, Strength = 130f
                    }
                }
            };

            particleEntity.AttachComponent(new TransformableComponent <ParticleEmitter>(particleEmitter));
        }