Example #1
0
 public Wall(Point position, int size)
 {
     Body = new Body(this, position, size, size)
     {
         Type = Body.Geometry.RECTANGLE
     };
     Type = EntityType.WALL;
 }
 public void CollisionLineSquareTest()
 {
     Body body = new Body(null, new Point(0, 0), 40, 40)
     {
         Type = Body.Geometry.RECTANGLE
     };
     // Checking if a normal line, going straight across the rectangle, collides.
     Assert.IsTrue(CollisionHandler.CollisionLineSquare(-5, 50, -5, 50, body));
 }
 public void IsCollidingCircleVsRectangleTest()
 {
     // Checking if it differentiates properly between circle and rectangles (its circle by default)
     Body body1 = new Body(null, new Point(50, 40), 20, 20);
     Body body2 = new Body(null, new Point(50, 59), 40, 40);
     Assert.IsFalse(CollisionHandler.IsColliding(body1, body2));
     body1.Type = Body.Geometry.RECTANGLE;
     body2.Type = Body.Geometry.RECTANGLE;
     Assert.IsTrue(CollisionHandler.IsColliding(body1, body2));
 }
Example #4
0
 public Bullet(Point position, Vector velocity, double diameter, int damage, int bulletType, GameObject owner)
 {
     BulletType = bulletType;
     Owner = owner;
     Damage = damage;
     Body = new Body(this, position, diameter, diameter)
     {
         Type = Body.Geometry.CIRCLE
     };
     Physics = new Physics(this, 200, velocity);
     _lifeTimeEvent = new LightEvent(5000, () => { Destroy(); });
     Type = EntityType.BULLET;
 }
        public void CollisionLineSquareTest3()
        {
            const int BODY_X = 40;
            const int BODY_Y = 50;
            const int BODY_WIDTH = 40;
            const int BODY_HEIGHT = 20;
            Body body = new Body(null, new Point(BODY_X, BODY_Y), BODY_WIDTH, BODY_HEIGHT)
            {
                Type = Body.Geometry.RECTANGLE
            };
            // Checking if it collides with lines just inside the square.
            Assert.IsTrue(CollisionHandler.CollisionLineSquare(81, 80, 50, 70, body));

            Assert.IsTrue(CollisionHandler.CollisionLineSquare(40, 80, 71, 70, body));

            Assert.IsTrue(CollisionHandler.CollisionLineSquare(39, 79, 50, 50, body));

            Assert.IsTrue(CollisionHandler.CollisionLineSquare(39, 40, 30, 70, body));
        }
 public void IsCollidingTest3()
 {
     // The bodies are next to each other.
     Body body1 = new Body(null, new Point(0, 0), 40, 40);
     Body body2 = new Body(null, new Point(41, 0), 40, 40);
     Assert.IsFalse(CollisionHandler.IsColliding(body1, body2));
 }
 public void IsCollidingTest2()
 {
     // The bodies collide in (20, 0).
     Body body1 = new Body(null, new Point(0, 0), 40, 40);
     Body body2 = new Body(null, new Point(40, 0), 40, 40);
     Assert.IsTrue(CollisionHandler.IsColliding(body1, body2));
 }
 public void IsCollidingSelfTest()
 {
     // An object collides with itself.
     Body body1 = new Body(null, new Point(0, 0), 40, 40);
     Assert.IsTrue(CollisionHandler.IsColliding(body1, body1));
 }
 public void IsCollidingTest4()
 {
     Body body1 = new Body(null, new Point(50, 40), 20, 20);
     Body body2 = new Body(null, new Point(50, 61), 40, 40);
     Assert.IsFalse(CollisionHandler.IsColliding(body1, body2));
 }