Example #1
0
        public override void Update(float delta)
        {
            foreach (int entity in ECS.GetEntitiesWithComponent <CPhysics>())
            {
                CPhysics physics = ECS.GetComponent <CPhysics>(entity);

                if (physics.isMoving)
                {
                    HandleMovement(delta, physics);
                }

                if (physics.isMoving)
                {
                    continue;
                }

                int x = 0, y = 0;
                if (physics.playerControlled)
                {
                    if (Input.IsKeyDown(Keys.Down))
                    {
                        y++;
                    }
                    if (Input.IsKeyDown(Keys.Up))
                    {
                        y--;
                    }
                    if (Input.IsKeyDown(Keys.Left))
                    {
                        x--;
                    }
                    if (Input.IsKeyDown(Keys.Right))
                    {
                        x++;
                    }
                }
                else
                {
                    x = physics.queuedMovement.X;
                    y = physics.queuedMovement.Y;
                }

                if (x != 0 || y != 0)
                {
                    physics.queuedMovement = new Point(x, y);
                    physics.isMoving       = true;
                }

                if (physics.isMoving)
                {
                    HandleMovement(delta, physics);
                }
            }
        }
Example #2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            TextureLoader.GraphicsDevice = GraphicsDevice;
            Global.SpriteBatch           = spriteBatch;

            // load sprites
            SpriteSheet.Load("textures1.xml");

            // initialize systems
            ECS.RegisterComponent <CSpriteRenderer>();
            ECS.RegisterComponent <CPhysics>();
            ECS.RegisterComponent <CSimpleAI>();

            scene = new ShackScene();
            scene.Load();
        }
Example #3
0
        public override void Update(float delta)
        {
            foreach (int entity in ECS.GetEntitiesWithComponent <CSimpleAI>())
            {
                CSimpleAI ai      = ECS.GetComponent <CSimpleAI>(entity);
                CPhysics  physics = ECS.GetComponent <CPhysics>(entity);

                if (physics == null)
                {
                    continue;
                }

                if (physics.isMoving)
                {
                    continue;
                }

                physics.isMoving       = true;
                physics.queuedMovement = new Point(1, 0);
            }
        }