Пример #1
0
        public override void Draw(float delta)
        {
            foreach (int entity in ECS.Entities)
            {
                CSpriteRenderer renderer = ECS.GetComponent <CSpriteRenderer>(entity);
                CPhysics        physics  = ECS.GetComponent <CPhysics>(entity);

                if (renderer == null || physics == null)
                {
                    continue;
                }

                renderer.sprite.position = physics.position;

                if (physics.isMoving)
                {
                    Point move = physics.queuedMovement;
                    move.X = (int)(move.X * physics.moveDelta * Pos.TileSize);
                    move.Y = (int)(move.Y * physics.moveDelta * Pos.TileSize);
                    renderer.sprite.position += move;
                }

                renderer.sprite.Draw();
            }
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        void HandleMovement(float delta, CPhysics physics)
        {
            if (physics.moveDelta >= 1)
            {
                physics.moveDelta = 0;
                physics.isMoving  = false;
                physics.position += new Pos(physics.queuedMovement.X, physics.queuedMovement.Y);
                return;
            }

            physics.moveDelta += delta * physics.tilePerSecond;
        }
Пример #4
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);
            }
        }