Exemple #1
0
        public void TestCollisionWithWallBounce()
        {
            //float YPosition1 = LetCharacterFall(StartPosition: new Vector2(200, 200), FallingSteps: 5, FPSCount: 50);

            _gameTime = NewGameTime(144);

            _wall = new Sprite();
            _wall.Position = new Vector2(10, 100 + 80);
            _wall.Rect = new Rectangle((int)_wall.Position.X, (int)_wall.Position.Y, 100, 20);
            _wall.Color = Color.White;
            _wall.Update(_gameTime);

            _jucko = new Character();
            _jucko.Position = new Vector2(20, 0);
            _jucko.Rect = new Rectangle((int)_jucko.Position.X, (int)_jucko.Position.Y, 30, 90);
            _jucko.Color = Color.Red;
            for (int updateGravity = 0; updateGravity < 50; updateGravity++) {
                _jucko.Update(_gameTime);
            }

            Rectangle overlap = Rectangle.Intersect(_jucko.Rect, _wall.Rect);
            if (!overlap.IsEmpty) {
                _jucko.CollisionWith(_wall, overlap);
            }

            for (int updateBounce = 0; updateBounce < 50; updateBounce++) {
                _jucko.Update(_gameTime);
            }

            Assert.AreEqual(18, _jucko.Position.Y);
        }
Exemple #2
0
        public void TestCollisionWithWall()
        {
            _gameTime = NewGameTime(144);

            _wall = new Sprite();
            _wall.Position = new Vector2(10, 100+80);
            _wall.Rect = new Rectangle((int)_wall.Position.X, (int)_wall.Position.Y, 100, 20);

            _jucko = new Character();
            _jucko.Position = new Vector2(20, 100);
            _jucko.Rect = new Rectangle((int)_jucko.Position.X, (int)_jucko.Position.Y, 30, 90);

            _jucko.Update(_gameTime);
            _wall.Update(_gameTime);

            for (int updateGravity = 0; updateGravity < 50; updateGravity++) {
                _jucko.Update(_gameTime);

                Rectangle overlap = Rectangle.Intersect(_jucko.Rect, _wall.Rect);
                if (!overlap.IsEmpty) {
                    _jucko.CollisionWith(_wall, overlap);
                }
            }

            Assert.AreEqual(90, _jucko.Position.Y);
        }