Esempio n. 1
0
        public Platform(PointF position, int length)
        {
            if (length < 1)
            {
                throw new ArgumentException("length must be greater than 1");
            }
            switch (length)
            {
            case 1:
                squares.Add(SquareBuilder("sprites/Tiles/Tile (15).png", position));
                break;

            case 2:
                squares.Add(SquareBuilder("sprites/Tiles/Tile (12).png", position));
                squares.Add(SquareBuilder("sprites/Tiles/Tile (14).png", new PointF(position.X + 128, position.Y)));
                break;

            default:
                squares.Add(SquareBuilder("sprites/Tiles/Tile (12).png", position));
                for (var i = 1; i < length - 1; i++)
                {
                    squares.Add(SquareBuilder("sprites/Tiles/Tile (13).png",
                                              new PointF(position.X + 128 * i, position.Y)));
                }
                squares.Add(SquareBuilder("sprites/Tiles/Tile (14).png",
                                          new PointF(position.X + 128 * (length - 1), position.Y)));
                break;
            }
        }
Esempio n. 2
0
        private Square AddPlayerOnMovingPlatform(Level lvl, PointF startPosition, PointF endPosition)
        {
            var movingPlatform =
                new MovingPlatform(new PointF(startPosition.X, startPosition.Y), endPosition, 3,
                                   1).CreatePlatform()[0];

            lvl.Player.Position =
                startPosition - new PointF(0, lvl.Player.CollideRectangle.Height + player.ColliderArea.Y);
            lvl.AddObject(movingPlatform);
            return(movingPlatform);
        }
Esempio n. 3
0
        public MovingPlatform(PointF startPosition, PointF endPosition, float velocity, int length) : base(
                startPosition, length)
        {
            var headSquare = squares.First();
            var delta      = endPosition - startPosition;
            var moveVector = delta.Normalize() * velocity;

            if (startPosition.Y > endPosition.Y)
            {
                startPosition.Y += headSquare.CollideRectangle.Height;
            }
            else if (startPosition.Y < endPosition.Y)
            {
                endPosition.Y += headSquare.CollideRectangle.Height;
            }
            if (startPosition.X > endPosition.X)
            {
                startPosition.X += headSquare.CollideRectangle.Width;
                endPosition.X   -= headSquare.CollideRectangle.Width;
            }
            if (startPosition.X < endPosition.X)
            {
                startPosition.X -= headSquare.CollideRectangle.Width;
                endPosition.X   += headSquare.CollideRectangle.Width;
            }
            var startCollider =
                new Square(new Rectangle(startPosition, new Size((int)headSquare.CollideRectangle.Width, 1)));
            var endCollider =
                new Square(new Rectangle(endPosition, new Size((int)headSquare.CollideRectangle.Width, 1)));

            foreach (var square in squares)
            {
                square.OnStateUpdate += () =>
                {
                    square.Velocity = moveVector;
                    if (headSquare.IsIntersectsWith(startCollider) && !movingForward)
                    {
                        movingForward = true;
                        moveVector   *= -1;
                    }
                    else if (headSquare.IsIntersectsWith(endCollider) && movingForward)
                    {
                        movingForward = false;
                        moveVector   *= -1;
                    }
                }
            }
            ;
        }
    }
Esempio n. 4
0
        public void Platform_MovePlayer(float startX, float startY, float endX, float endY)
        {
            var lvl            = new Level(clientSize.Size);
            var startPosition  = new PointF(startX, startY);
            var endPosition    = new PointF(endX, endY);
            var movingPlatform = AddPlayerOnMovingPlatform(lvl, startPosition, endPosition);

            game.LoadLevel(() => lvl);
            for (var i = 0; i < 500; i++)
            {
                game.CurrentLevel.Update();
                Assert.AreEqual(movingPlatform.Position.X, lvl.Player.Position.X, delta);
                Assert.AreEqual(lvl.Player.CollideRectangle.Bottom, movingPlatform.CollideRectangle.Top, delta);
            }
        }
Esempio n. 5
0
        public void SetUp()
        {
            game = new Game(clientSize, null);

            const float playerSizeScale = 0.25f;
            var         playerPrefab    =
                new Player(new Rectangle(30, 735, (int)(230 * playerSizeScale), (int)(500 * playerSizeScale)),
                           new Animator())
            {
                ColliderArea = new RectangleF(52 * playerSizeScale, 105 * playerSizeScale, 128 * playerSizeScale,
                                              394 * playerSizeScale)
            };
            var floorPrefab = new List <Transform>();

            floorLevel = (int)playerPrefab.CollideRectangle.Bottom;
            for (var i = 0; i < clientSize.Width; i += 128)
            {
                floorPrefab.Add(new Square(new Rectangle(i, floorLevel, 128, 128),
                                           new Bitmap(1, 1)));
            }
            var square = new Square(new Rectangle(100, floorLevel - 1, 100, 100))
            {
                Static = false
            };

            testSquare = square;
            game.LoadLevel(() =>
            {
                var lvl = new Level(floorPrefab, playerPrefab, new Animator());
                lvl.AddObject(square);
                return(lvl);
            });
            UpdateLevel(game.CurrentLevel, 20);
            playerInitialPosition = game.CurrentLevel.Player.Position;
            player           = game.CurrentLevel.Player;
            player.Collision = false;
            player.Static    = true;
        }
Esempio n. 6
0
 protected Transform(PointF position)
 {
     Position = position;
 }