Esempio n. 1
0
        public void SpriteFromSheetTests()
        {
            var fromNullSheet = new SpriteFromSheet();

            Assert.AreEqual(0, fromNullSheet.SpritesCount);
            Assert.IsNull(fromNullSheet.GetSprite(0));

            var emptySheet     = new SpriteSheet();
            var fromEmptySheet = new SpriteFromSheet {
                Sheet = emptySheet
            };

            Assert.AreEqual(0, fromEmptySheet.SpritesCount);
            Assert.IsNull(fromEmptySheet.GetSprite(0));

            var validSheet = new SpriteSheet()
            {
                Sprites = { new Sprite("0"), new Sprite("1") }
            };
            var fromValidSheet = new SpriteFromSheet {
                Sheet = validSheet
            };

            Assert.AreEqual(2, fromValidSheet.SpritesCount);
            for (int i = 0; i < fromValidSheet.SpritesCount; i++)
            {
                Assert.AreEqual(i.ToString(), fromValidSheet.GetSprite(i).Name);
            }
        }
Esempio n. 2
0
        public void SpriteFromSheetTests()
        {
            var fromNullSheet = new SpriteFromSheet();

            Assert.Equal(0, fromNullSheet.SpritesCount);
            Assert.Null(fromNullSheet.GetSprite());

            var emptySheet     = new SpriteSheet();
            var fromEmptySheet = new SpriteFromSheet {
                Sheet = emptySheet
            };

            Assert.Equal(0, fromEmptySheet.SpritesCount);
            Assert.Null(fromEmptySheet.GetSprite());

            var validSheet = new SpriteSheet {
                Sprites = { new Sprite("0"), new Sprite("1") }
            };
            var fromValidSheet = new SpriteFromSheet {
                Sheet = validSheet
            };

            Assert.Equal(2, fromValidSheet.SpritesCount);
            for (var i = 0; i < fromValidSheet.SpritesCount; i++)
            {
                fromValidSheet.CurrentFrame = i;
                Assert.Equal(i.ToString(), fromValidSheet.GetSprite().Name);
            }
        }
Esempio n. 3
0
        private void UpdateTransform2(InputState inputState)
        {
            if (inputState.HasFlag(InputState.Up))
            {
                var position = _characterEntity.Transform.Position.Y + 60f * (float)Game.UpdateTime.Elapsed.Milliseconds / 1000;

                var halfHeight = _characterSpriteSheet.GetSprite().Size.Y / 2;

                if (position > _bufferHeight / 2 - halfHeight)
                {
                    position = _bufferHeight / 2 - halfHeight;
                }

                //_characterEntity.Get<CharacterComponent>().SetVelocity(new Vector3(0, position, 0));

                _characterEntity.Transform.Position.Y = position;
            }

            if (inputState.HasFlag(InputState.Down))
            {
                var halfHeight = _characterSpriteSheet.GetSprite().Size.Y / 2;

                var position = _characterEntity.Transform.Position.Y - 60f * (float)Game.UpdateTime.Elapsed.Milliseconds / 1000;

                if (position < -_bufferHeight / 2 + halfHeight)
                {
                    position = -_bufferHeight / 2 + halfHeight;
                }

                //_characterEntity.Get<CharacterComponent>().SetVelocity(new Vector3(0, position, 0));

                _characterEntity.Transform.Position.Y = position;
            }

            if (inputState.HasFlag(InputState.Left))
            {
                var halfWidth = _characterSpriteSheet.GetSprite().Size.X / 2;

                var position = _characterEntity.Transform.Position.X - 60f * (float)Game.UpdateTime.Elapsed.Milliseconds / 1000;
                if (position < (-_bufferWidth / 2) + halfWidth)
                {
                    position = (-_bufferWidth / 2) + halfWidth;
                }

                //_characterEntity.Get<CharacterComponent>().SetVelocity(new Vector3(position, 0, 0));

                _characterEntity.Transform.Position.X = position;
            }

            if (inputState.HasFlag(InputState.Right))
            {
                var position = _characterEntity.Transform.Position.X + 60f * (float)Game.UpdateTime.Elapsed.Milliseconds / 1000;

                var halfWidth = _characterSpriteSheet.GetSprite().Size.X / 2;

                if (position > _bufferWidth / 2 - halfWidth)
                {
                    position = _bufferWidth / 2 - halfWidth;
                }

                //_characterEntity.Get<CharacterComponent>().SetVelocity(Vector3.UnitX * position * 60f * (float)Game.UpdateTime.Elapsed.Milliseconds / 1000);
                //_characterEntity.Get<CharacterComponent>().SetVelocity(Vector3.Zero);

                _characterEntity.Transform.Position.X = position;
            }

            if (inputState.HasFlag(InputState.None))
            {
                //_characterEntity.Get<CharacterComponent>().Jump(Vector3.Zero);
            }
        }