Exemple #1
0
            public PhysicsComponent Create(Vector Position, Vector Size, float mass, float friction, EShape shape)
            {
                PhysicsComponent result = new PhysicsComponent();

                result.SetPosition(Position);
                result.SetMass(mass);
                if (shape == EShape.Square)
                {
                    result.HitBox = new Rectangle(Position, Size);
                }
                else if (shape == EShape.Circle)
                {
                    result.HitBox = new Circle(Position, Size.Length());
                }


                return(result);
            }
Exemple #2
0
 private void ResolveCollisionWithBorders(PhysicsComponent body, Dictionary <PhysicsComponent, Vector> hitImpulses)
 {
     if (body.HitBox.Intersects(new Rectangle(new Vector(2, 0), new Vector(2, 2))) && body.Impulse.x > 0)
     {
         hitImpulses[body] += new Vector(-body.Impulse.x, body.Impulse.y);
     }
     if (body.HitBox.Intersects(new Rectangle(new Vector(-2, 0), new Vector(2, 2))) && body.Impulse.x < 0)
     {
         hitImpulses[body] += new Vector(-body.Impulse.x, body.Impulse.y);
     }
     if (body.HitBox.Intersects(new Rectangle(new Vector(0, 2), new Vector(2, 2))) && body.Impulse.y > 0)
     {
         hitImpulses[body] += new Vector(body.Impulse.x, -body.Impulse.y);
     }
     if (body.HitBox.Intersects(new Rectangle(new Vector(0, -2), new Vector(2, 2))) && body.Impulse.y < 0)
     {
         hitImpulses[body] += new Vector(body.Impulse.x, -body.Impulse.y);
     }
 }
Exemple #3
0
 public void AddBody(PhysicsComponent body)
 {
     m_physicsBodies.Add(body);
 }