Я думаю, что Ваша проблема состоит в том, что Вы не используете хороший дизайн OO для своего игрока и врагов. Создайте два класса:
public class Player
{
int X;
int Y;
int Width;
int Height;
// Getters and Setters
}
public class Enemy
{
int X;
int Y;
int Width;
int Height;
// Getters and Setters
}
Ваш Плеер должен иметь X, Y, Ширина и переменные Высоты.
Ваши враги должны также.
В Вашем игровом цикле, сделайте что-то вроде этого (C#):
foreach (Enemy e in EnemyCollection)
{
Rectangle r = new Rectangle(e.X,e.Y,e.Width,e.Height);
Rectangle p = new Rectangle(player.X,player.Y,player.Width,player.Height);
// Assuming there is an intersect method, otherwise just handcompare the values
if (r.Intersects(p))
{
// A Collision!
// we know which enemy (e), so we can call e.DoCollision();
e.DoCollision();
}
}
Для ускорения вещей не потрудитесь проверять, являются ли провода врагов внеэкранными.
Подход, не оптимизированный для производительности, но для полноты.
null
фрагмент кода:
public static class StringHelper
{
public static bool AreNormalizedEquivalents(string source, string target)
{
if (source == null) return target == null;
if (target == null) return false;
var normForm1 = Normalize(source);
var normForm2 = Normalize(target);
return string.Equals(normForm1, normForm2);
}
private static string Normalize(string value)
{
Debug.Assert(value != null);
// normalize unicode, combining characters, diacritics
value = value.Normalize(NormalizationForm.FormC);
// normalize new lines to white space
value = value.Replace("\r\n", "\n").Replace("\r", "\n");
// normalize white space
value = Regex.Replace(value, @"\s", string.Empty);
// normalize casing
return value.ToLowerInvariant();
}
}