Created
September 6, 2012 18:15
-
-
Save jbubriski/3659100 to your computer and use it in GitHub Desktop.
Radius-Based Hit Detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Enemy : Sprite | |
{ | |
public int HitRadius { get { return 10; } } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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