Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Created September 6, 2012 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbubriski/3659100 to your computer and use it in GitHub Desktop.
Save jbubriski/3659100 to your computer and use it in GitHub Desktop.
Radius-Based Hit Detection
public class Enemy : Sprite
{
public int HitRadius { get { return 10; } }
}
public class Projectile : Sprite
{
public override void Update(GameTime gameTime)
{
foreach (var enemy in EnemyManager.Enemies)
{
var distanceToEnemy = Position.DistanceTo(enemy.Position);
if (distanceToEnemy <= enemy.HitRadius)
{
// Hit!
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment