Example #1
0
        public override void Initialize()
        {
            this.RegisterSystems();

            FPSCamera camera = new FPSCamera(new Vector3(0f, 0f, 0f), Vector3.Zero,
                Blackboard.Get<GraphicsDevice>("GraphicsDevice").Viewport.AspectRatio, 0.05f, 100f);

            Entity fpscounter = new Entity();
            fpscounter.AddComponent(new Transform2DComponent() { Position = new Vector2(5, 150) });
            fpscounter.AddComponent(new FPSCounterComponent());
            fpscounter.AddComponent(new GUITextComponent());

            Entity pos = new Entity();
            pos.AddComponent(new PositionalTrackingComponent() { Target = camera.Get<Transform3DComponent>() });
            pos.AddComponent(new GUITextComponent());
            pos.AddComponent(new Transform2DComponent() { Position = new Vector2(5, 180) });

            Entity model = new Entity();
            model.AddComponent(new Transform3DComponent(new Vector3(0f, -1f, 2f)));
            model.Get<Transform3DComponent>().Rotation = new Vector3(0f, MathHelper.PiOver2, 3f*MathHelper.PiOver2);
            Model m = Blackboard.Get<ContentManager>("ContentManager").Load<Model>("dragon");
            model.AddComponent(new ModelComponent() { Model = m });

            this.AddEntity(model);
            this.AddEntity(pos);
            this.AddEntity(fpscounter);
            this.AddEntity(camera);
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            e.Tag = "Chassis";

            #region Body
            Body Chassis = e.AddComponent<Body>(new Body(_World, e));
            {
                Vertices vertices = new Vertices(8);
                vertices.Add(new Vector2(-2.5f, 0.08f));
                vertices.Add(new Vector2(-2.375f, -0.46f));
                vertices.Add(new Vector2(-0.58f, -0.92f));
                vertices.Add(new Vector2(0.46f, -0.92f));
                vertices.Add(new Vector2(2.5f, -0.17f));
                vertices.Add(new Vector2(2.5f, 0.205f));
                vertices.Add(new Vector2(2.3f, 0.33f));
                vertices.Add(new Vector2(-2.25f, 0.35f));
                PolygonShape chassisShape = new PolygonShape(vertices, 2f);

                Chassis.BodyType = BodyType.Dynamic;
                Chassis.Position = new Vector2(0.0f, -1.0f);
                Chassis.CreateFixture(chassisShape);
            }
            #endregion

            #region Sprite
            e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, (Rectangle)args[1],
               Chassis, 1, Color.White, 0f));
            #endregion
            return e;
        }
 public void Before() {
     var pool = Helper.CreatePool();
     _e = pool.CreateEntity();
     _e.AddComponent(CP.ComponentA, new ComponentA());
     _e.AddComponent(CP.ComponentB, new ComponentB());
     _e.AddComponent(CP.ComponentC, new ComponentC());
 }
 public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
 {
     var shipDef = Game.WorldConfiguration.Ships[args[0] as string];
     entity.AddComponent(new ModelComponent(shipDef.Model));
     entity.AddComponent(new SceneGraphNode());
     entity.AddComponent(shipDef);
     return entity;
 }
 public void Before()
 {
     var context = Helper.CreateContext();
     _e = context.CreateEntity();
     _e.AddComponent(CP.ComponentA, new ComponentA());
     _e.AddComponent(CP.ComponentB, new ComponentB());
     _e.AddComponent(CP.ComponentC, new ComponentC());
 }
 public Entity BuildEntity(Entity e)
 {
     e.Group = "EFFECTS";
     e.AddComponent(new Transform());
     e.AddComponent(new SpatialForm());
     e.AddComponent(new Expires());
     e.GetComponent<SpatialForm>().SpatialFormFile = "BulletExplosion";
     e.GetComponent<Expires>().LifeTime = 1000;
     return e;
 }
 public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
 {
     e.Group = "EFFECTS";
     e.AddComponentFromPool<Transform>();
     e.AddComponent(new SpatialForm());
     e.AddComponent(new Expires());
     e.GetComponent<SpatialForm>().SpatialFormFile = "ShipExplosion";
     e.GetComponent<Expires>().LifeTime = 1000;
     return e;
 }
        public Entity BuildEntity(Entity e)
        {
            e.Group = "BULLETS";

            e.AddComponent(new Transform());
            e.AddComponent(new SpatialForm());
            e.AddComponent(new Velocity());
            e.AddComponent(new Expires());
            e.GetComponent<SpatialForm>().SpatialFormFile = "Missile";
            e.GetComponent<Expires>().LifeTime = 2000;
            return e;
        }
Example #9
0
        private static void InitTestEntities()
        {
            var e = new Entity("player");
            //e.Transform.Scale = new Vector2(0.5f, 0.5f);

            e.AddComponent(new SpriteComponent(e, Engine.Textures["crate"]));
            //e.AddComponent(new PlayerInput(e));
            e.AddComponent(new RectCollider(e) {Width = 96, Height = 96});
            e.AddComponent(new RectRenderer(e, Rectangle.Empty, new Texture2D(Engine.Window.GraphicsDevice, 1, 1)));

            Engine.Entities.AddEntity(e);
        }
        public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
        {
            e.Group = "BULLETS";

            e.AddComponentFromPool<Transform>();
            e.AddComponent(new SpatialForm());
            e.AddComponent(new Velocity());
            e.AddComponent(new Expires());
            e.GetComponent<SpatialForm>().SpatialFormFile = "Missile";
            e.GetComponent<Expires>().LifeTime = 2000;
            return e;
        }
 public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
 {
     e.Group = "SHIPS";
     e.AddComponentFromPool<Transform>();
     e.AddComponent(new SpatialForm());
     e.AddComponent(new Health());
     e.AddComponent(new Weapon());
     e.AddComponent(new Enemy());
     e.AddComponent(new Velocity());
     e.GetComponent<SpatialForm>().SpatialFormFile = "EnemyShip";
     e.GetComponent<Health>().HP = 10;
     return e;
 }
 public void Before()
 {
     _context = Helper.CreateContext();
     _context.GetGroup(Matcher.AllOf(new [] { CP.ComponentA }));
     _e = _context.CreateEntity();
     _e.AddComponent(CP.ComponentA, new ComponentA());
 }
 public void Before() {
     _pool = new Pool(CP.NumComponents);
     _pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentA }));
     _pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentB }));
     _pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentC }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentA,
         CP.ComponentB
     }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentA,
         CP.ComponentC
     }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentB,
         CP.ComponentC
     }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentA,
         CP.ComponentB,
         CP.ComponentC
     }));
     _e = new Entity(CP.NumComponents);
     _e.AddComponent(CP.ComponentA, new ComponentA());
 }
 public void Before() {
     _pool = Helper.CreatePool();
     _pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentA }));
     _pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentB }));
     _pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentC }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentA,
         CP.ComponentB
     }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentA,
         CP.ComponentC
     }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentB,
         CP.ComponentC
     }));
     _pool.GetGroup(Matcher.AllOf(new [] {
         CP.ComponentA,
         CP.ComponentB,
         CP.ComponentC
     }));
     _e = _pool.CreateEntity();
     _componentA = new ComponentA();
     _e.AddComponent(CP.ComponentA, _componentA);
 }
 public override void OnAdded(Entity entity)
 {
     if (entity.HasComponent<ShipComponent>())
     {
         entity.AddComponent(new SpatialTokenComponent { Token = Ships.AllocateToken(entity) });
     }
 }
Example #16
0
		void Start () 
		{
			Entity e = new Entity();

			Entity player1 = new Entity();
			Entity player2 = new Entity();
			player1.AddComponent(new PlayerType(new PlayerInfo(0, true)));
			player2.AddComponent(new PlayerType(new PlayerInfo(1, false)));

			game.AddEntity(player1);
			game.AddEntity(player2);
			Entity card = EntityFactory.MakeCard(CardInfo.NewID(), "test");
			card.GetComponent<CardType>().info.state = CardInfo.State.Hand;
			game.AddEntity(card);

			card = EntityFactory.MakeCard(CardInfo.NewID(), "test");
			card.GetComponent<CardType>().info.state = CardInfo.State.Hand;
			game.AddEntity(card);

			card = EntityFactory.MakeCard(CardInfo.NewID(), "test");
			card.GetComponent<CardType>().info.state = CardInfo.State.Hand;
			game.AddEntity(card);

			game.AddEntity(EntityFactory.MakeSystem(0,0));
			game.AddEntity(EntityFactory.MakeSystem(0,1));

			game.InitateSystems();
		}
 public Entity BuildEntity(Entity et1, EntityWorld world , params object[] args)
 {
     et1.AddComponent(new Power());
     et1.GetComponent<Power>().POWER = 100;
     et1.Refresh();
     return et1;
 }
Example #18
0
 public void Attach(Entity newEntity)
 {
     ControlledEntity = newEntity;
     ControlledEntity.AddComponent(ComponentFamily.Input,
                                   IoCManager.Resolve<IEntityManagerContainer>().EntityManager.ComponentFactory.
                                       GetComponent("KeyBindingInputComponent"));
     ControlledEntity.AddComponent(ComponentFamily.Mover,
                                   IoCManager.Resolve<IEntityManagerContainer>().EntityManager.ComponentFactory.
                                       GetComponent("PlayerInputMoverComponent"));
     ControlledEntity.AddComponent(ComponentFamily.Collider,
                                   IoCManager.Resolve<IEntityManagerContainer>().EntityManager.ComponentFactory.
                                       GetComponent("ColliderComponent"));
     ControlledEntity.GetComponent(ComponentFamily.Collider).SetParameter(new ComponentParameter("TweakAABB",
                                                                                                 new Vector4D(
                                                                                                     39, 0, 0, 0)));
     ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += PlayerEntityMoved;
 }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            #region Body

            Body Body = e.AddComponent<Body>(new Body(_World, e));
            {
                FixtureFactory.AttachEllipse(//Add a basic bounding box (rectangle status)
                    ConvertUnits.ToSimUnits(_SpriteSheet.Animations["rotatinglightball"][0].Width * 2),
                    ConvertUnits.ToSimUnits(_SpriteSheet.Animations["rotatinglightball"][0].Height * 2),
                    5,
                    1,
                    Body);
                Body.Position = ConvertUnits.ToSimUnits((Vector2)args[0]);
                Body.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
                Body.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat3 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat16;
                Body.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat4 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat5;
                Body.FixedRotation = false;

                Body.SleepingAllowed = false;
            }

            #endregion Body

            #region Sprite

            Sprite s = new Sprite(_SpriteSheet, "rotatinglightball", 0.4f);
            e.AddComponent<Sprite>(s);

            #endregion Sprite

            #region Animation

            e.AddComponent<Animation>(new Animation(AnimationType.Loop, 10));

            #endregion Animation

            #region Health

            e.AddComponent<Health>(new Health(1)).OnDeath += LambdaComplex.BigEnemyDeath(e, _World as SpaceWorld, 0);

            #endregion Health

            e.Group = "Structures";
            return e;
        }
Example #20
0
 void addDebugComponent(Entity entity)
 {
     var debugBehaviour = new GameObject().AddComponent<EntityDebugBehaviour>();
     debugBehaviour.Init(this, entity, _debugIndex);
     debugBehaviour.transform.SetParent(_entitiesContainer, false);
     var debugComponent = new DebugComponent();
     debugComponent.debugBehaviour = debugBehaviour;
     entity.AddComponent(_debugIndex, debugComponent);
 }
Example #21
0
 public void CreateChildEntities(EntityWorld world, Entity parentEntity)
 {
     var modelComponent = new ShipModelComponent { Model = this };
     parentEntity.AddComponent(modelComponent);
     foreach (var part in Parts)
     {
         part.CreateEntity(world, parentEntity);
     }
     modelComponent.BoundingBox = CalculateBoundingBox(0);
 }
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            TextureManager textureManager = EntitySystem.BlackBoard.GetEntry<TextureManager>("TextureManager");
            FarseerPhysics.Dynamics.World world = EntitySystem.BlackBoard.GetEntry<FarseerPhysics.Dynamics.World>("PhysicsWorld");

            int2 pos = new int2(0, 0);
            float rotation = 0.0f;
            int resourceAmount = 500;
            String resourceType = "No type";
            int textureId = 0;

            Random r = new Random();

            if (args.Length >= 1)
                pos = (int2)args[0];

            if (args.Length >= 2)
                rotation = (float)args[1];

            if (args.Length >= 3)
                resourceType = (String)args[2];

            if (args.Length >= 4)
                resourceAmount = (int)args[3];

            if (args.Length >= 5)
                textureId = (int)args[4];

            Texture2D texture = textureManager.getTexture(textureId);

            Rectangle col;
            if (resourceType.Equals("wood"))
                col = new Rectangle(pos.x + 1, pos.y + 1, 2, 2);
            else
                col = new Rectangle(pos.x, pos.y, texture.Width / Global.tileSize, texture.Height / Global.tileSize);

            entity.AddComponent(new component.TileEntity(entity, new Rectangle(pos.x, pos.y, texture.Width / Global.tileSize, texture.Height / Global.tileSize), col, rotation));
            entity.AddComponent(new component.Size(texture.Width, texture.Height));
            entity.AddComponent(new component.Drawable(texture));
            entity.AddComponent(new component.DepletableResource(resourceAmount, resourceType));
            return entity;
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            string text = (string)args[0];
            Vector2 position = (Vector2)args[1];
            float time = 0.9f;

            e.AddComponent<FadingText>(new FadingText(text, time, position));

            e.Refresh();
            return e;
        }
Example #24
0
        public Entity BuildEntity(Entity e, params object[] args)
        {
            e.Tag = "Wheel" + e.Id;

            #region Body
            Body Wheel = e.AddComponent<Body>(new Body(_World, e));
            {
                Wheel.BodyType = BodyType.Dynamic;
                Wheel.Position = (Vector2)args[2];
                Fixture fix = Wheel.CreateFixture(args[3] as CircleShape);
                if (args.Length > 4 && args[4] != null)
                    fix.Friction = (float)args[4];
            }

            #endregion

            #region Sprite
            e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, (Rectangle)args[1]));
            #endregion
            return e;
        }
Example #25
0
 /// <summary>
 /// Add a Modifier script to an Entity, based on a code block (delegate) and a VectorFunction
 /// </summary>
 /// <param name="e">Entity to add modifier script to</param>
 /// <param name="scriptCode">Code block (delegate) that is the script</param>
 /// <param name="func">Function whose value will be passed in ScriptContext.FunctionValue to script</param>
 /// <returns></returns>
 public static VectorModifierScript AddModifier(Entity e, VectorModifierDelegate scriptCode, IVectorFunction func)
 {
     if (!e.HasComponent<ScriptComp>())
     {
         e.AddComponent(new ScriptComp());
         e.Refresh();
     }
     var sc = e.GetComponent<ScriptComp>();
     var script = new VectorModifierScript(scriptCode, func);
     sc.Add(script);
     return script;
 }
Example #26
0
        public IEntity CreateEntity(IEnumerable<Component> componentCollection)
        {
            IEntity entity = new Entity();

            foreach (Component component in componentCollection)
            {
                component.Entity = entity;
                entity.AddComponent(component);
            }

            return entity;
        }
        public override void Process(Entity e)
        {
            Sprite sprite = e.GetComponent<Sprite>();
            Animation anim = e.GetComponent<Animation>();

            if (anim.Type != AnimationType.None)
            {
                anim._Tick++;
                anim._Tick %= anim.FrameRate;
                if (anim._Tick == 0) //If time to animate.
                {
                    switch (anim.Type)
                    {
                        case AnimationType.Loop:
                            sprite.FrameIndex++;
                            break;

                        case AnimationType.ReverseLoop:
                            sprite.FrameIndex--;
                            break;

                        case AnimationType.Increment:
                            sprite.FrameIndex++;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Decrement:
                            sprite.FrameIndex--;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Bounce:
                            sprite.FrameIndex += anim.FrameInc;
                            if (sprite.FrameIndex == sprite.Source.Count() - 1)
                                anim.FrameInc = -1;

                            if (sprite.FrameIndex == 0)
                                anim.FrameInc = 1;
                            break;

                        case AnimationType.Once:
                            if (sprite.FrameIndex < sprite.Source.Count() - 1)
                                sprite.FrameIndex++;
                            else
                                anim.Type = AnimationType.None;
                            break;
                    }
                    e.RemoveComponent<Sprite>(e.GetComponent<Sprite>());
                    e.AddComponent<Sprite>(sprite);
                }
            }
        }
Example #28
0
        public Entity BuildEntity(Entity e, params object[] args)
        {
            e.Group = "Props";
            e.Tag = "Ground";
            Body ground = e.AddComponent<Body>(new Body(world, e));

            //Verts
            Vertices terrain = new Vertices();
                terrain.Add(new Vector2(-20f, -5f));
                terrain.Add(new Vector2(-20f, 0f));
                terrain.Add(new Vector2(20f, 0f));
                terrain.Add(new Vector2(25f, -0.25f));
                terrain.Add(new Vector2(30f, -1f));
                terrain.Add(new Vector2(35f, -4f));
                terrain.Add(new Vector2(40f, 0f));
                terrain.Add(new Vector2(45f, 0f));
                terrain.Add(new Vector2(50f, 1f));
                terrain.Add(new Vector2(55f, 2f));
                terrain.Add(new Vector2(60f, 2f));
                terrain.Add(new Vector2(65f, 1.25f));
                terrain.Add(new Vector2(70f, 0f));
                terrain.Add(new Vector2(75f, -0.3f));
                terrain.Add(new Vector2(80f, -1.5f));
                terrain.Add(new Vector2(85f, -3.5f));
                terrain.Add(new Vector2(90f, 0f));
                terrain.Add(new Vector2(95f, 0.5f));
                terrain.Add(new Vector2(100f, 1f));
                terrain.Add(new Vector2(105f, 2f));
                terrain.Add(new Vector2(110f, 2.5f));
                terrain.Add(new Vector2(115f, 1.3f));
                terrain.Add(new Vector2(120f, 0f));
                terrain.Add(new Vector2(160f, 0f));
                terrain.Add(new Vector2(159f, 10f));
                terrain.Add(new Vector2(201f, 10f));
                terrain.Add(new Vector2(200f, 0f));
                terrain.Add(new Vector2(240f, 0f));
                terrain.Add(new Vector2(250f, -5f));
                terrain.Add(new Vector2(250f, 10f));
                terrain.Add(new Vector2(270f, 10f));
                terrain.Add(new Vector2(270f, 0));
                terrain.Add(new Vector2(310f, 0));
                terrain.Add(new Vector2(310f, -5));

            for (int i = 0; i < terrain.Count - 1; ++i)
            {
                FixtureFactory.AttachEdge(terrain[i], terrain[i + 1], ground);
            }
            ground.Friction = 0.6f;

            return e;
        }
 public Entity BuildEntity(Entity e)
 {
     e.Group = "SHIPS";
     e.AddComponent(new Transform());
     e.AddComponent(new SpatialForm());
     e.AddComponent(new Health());
     e.AddComponent(new Weapon());
     e.AddComponent(new Enemy());
     e.AddComponent(new Velocity());
     e.GetComponent<SpatialForm>().SpatialFormFile = "EnemyShip";
     e.GetComponent<Health>().HP = 10;
     return e;
 }
Example #30
0
        protected override void Initialize()
        {
            base.Initialize();

            Engine.Initialize((IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService)), TopLevelControl.Handle);

            Entity mainCamera = new Entity("_MainCamera", true);

            mainCamera.AddComponent(new CameraComponent(mainCamera));
            //mainCamera.AddComponent(new CameraInput(mainCamera));
            Engine.Cameras.SetCurrent(mainCamera.GetComponent<CameraComponent>());

            Engine.Textures.Add("crate", "Sprites/crate", true);
            Engine.Textures.Add("grass", "Tiles/grass", true);
            Engine.Textures.Add("background", "Tiles/background", true);

            Engine.SoundFX.Add("ammo_pickup", "Sounds/ammo_pickup", true);

            InitTestEntities();
        }