//Collision between two circles public static bool Collision(CircleHitbox circle1, CircleHitbox circle2) { if (circle1.Position.EuclideanDistance(circle2.Position) < (circle1.Radius + circle2.Radius)) { return true; } else { return false; } }
//Collision between a polygon and a circle public static bool Collision(CircleHitbox circle, PolygonHitbox polygon) { bool value = false; foreach (Vector2 vector in polygon.Vectors) { if (circle.Contains(vector)) { value = true; break; } } return value; }
public Bullet(InGameState Game, Vector2 position, Vector2 direction , double startTime) : base(Game, null, position) { //we dont want bullets to loop around the screen when then go off the screen Loop = false; //we set the initial velocity which never lowers as theres no friction Velocity = direction * BulletSpeed; //set the start time so we cna kill off the bullet after an interval this.startTime = startTime; //Create a collision shape for the bullet hitbox = new CircleHitbox(this, 2); }
public Asteroid(InGameState Game, Vector2 StartPosition, AsteroidSize size) : base(Game, new LineModel(AsteroidLarge1Vectors), StartPosition) { this.size = size; Velocity = Vector2.RandomVector2(new Vector2(-50, -50), new Vector2(50, 50)).Normalise() * 2; switch (size) { case AsteroidSize.Large: this.Model.Scale = 1; break; case AsteroidSize.Medium: this.Model.Scale = 0.5; break; case AsteroidSize.Small: this.Model.Scale = 0.35; break; } hitbox = new CircleHitbox(this, Model.GetRadius()); }
public Asteroid(InGameState Game, Vector2 StartPosition, Vector2 velocity, AsteroidSize size) : base(Game, new LineModel(AsteroidLarge1Vectors), StartPosition) { this.size = size; Velocity = velocity; switch (size) { case AsteroidSize.Large: this.Model.Scale = 1; break; case AsteroidSize.Medium: this.Model.Scale = 0.5; break; case AsteroidSize.Small: this.Model.Scale = 0.35; break; } hitbox = new CircleHitbox(this, Model.GetRadius()); }