Ejemplo n.º 1
0
        public void MoveToKeyboardOverridesExistingKeyboardComponent()
        {
            // The only way to test this is to change the velocity and see if the new velocity number is used
            // Set velocity to 100, press D, wait one second; we should move 100px to the right.
            var expectedVelocity = 100;

            var entity = new CobaltEntity();

            entity.MoveToKeyboard(1);
            entity.MoveToKeyboard(expectedVelocity);

            KeyboardSystem.GenerateKeysCallback(() =>
            {
                // Press D to move X positively
                return(new Keys[] { Keys.D });
            });

            // Simulate keypress
            var keyboardSystem = new KeyboardSystem();

            keyboardSystem.Add(entity);
            keyboardSystem.Update(1);

            var velocitySystem = new VelocitySystem();

            velocitySystem.Add(entity);
            velocitySystem.Update(1);

            Assert.That(entity.Get <PositionComponent>().X, Is.EqualTo(expectedVelocity));
        }
Ejemplo n.º 2
0
        public void MoveToKeyboardSetsKeyboardComponent()
        {
            var entity = new CobaltEntity();

            entity.MoveToKeyboard(100);

            var actual = entity.Get <KeyboardComponent>();

            Assert.That(actual, Is.Not.Null);
        }
Ejemplo n.º 3
0
        public void MoveToKeyboardAddsVelocityComponentWithWASDCallbacksIfOneDoesntExist()
        {
            var entity = new CobaltEntity();

            entity.MoveToKeyboard(10);

            Assert.That(entity.Has <VelocityComponent>());
            var actual = entity.Get <VelocityComponent>();

            Assert.That(actual.X, Is.EqualTo(0));
            Assert.That(actual.Y, Is.EqualTo(0));
        }
Ejemplo n.º 4
0
        public void MoveToKeyboardAddsPositionComponentIfOneDoesntExist()
        {
            var entity = new CobaltEntity();

            entity.MoveToKeyboard(10);

            Assert.That(entity.Has <PositionComponent>());

            var actual = entity.Get <PositionComponent>();

            Assert.That(actual.X, Is.EqualTo(0));
            Assert.That(actual.Y, Is.EqualTo(0));
        }
Ejemplo n.º 5
0
        public void MoveToKeyboardDoesntOverrideExistingPositionComponent()
        {
            var expectedX = 100;
            var expectedY = 200;

            var entity = new CobaltEntity().Move(expectedX, expectedY);

            entity.MoveToKeyboard(10);

            var actual = entity.Get <PositionComponent>();

            Assert.That(actual.X, Is.EqualTo(expectedX));
            Assert.That(actual.Y, Is.EqualTo(expectedY));
        }