Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        //[TestMethod]
        //public void TestProjectileCollision() {
        //    _gameTime = NewGameTime(144);
        //    _bullet = new Projectile(new Vector2(0, 0), new Vector2(100, 0), 50f, "", Color.Red, 100);
        //    _wall = new Sprite();
        //    _wall.Position = new Vector2(5,0);
        //    _wall.Rect = new Rectangle((int)_wall.Position.X, (int)_wall.Position.Y,100,20);
        //    Rectangle overlap = new Rectangle() ;
        //    while (overlap.IsEmpty) {
        //        _bullet.Update(_gameTime);
        //        overlap = Rectangle.Intersect();
        //    }
        //    Assert.AreEqual(_bullet.Position.X, 200);
        //    Assert.AreEqual(_bullet.Position.Y, 203);
        //}
        private float LetCharacterFall(Vector2 StartPosition, int FallingSteps, int FPSCount)
        {
            _jucko = new Character();
            _gameTime = NewGameTime(FPSCount);

            _jucko.Position = StartPosition;
            for (int i = 0; i < FallingSteps; i++) {
                _jucko.Update(_gameTime);
            }

            return _jucko.Position.Y;
        }