Line[] pBase = person.GetBounds();int w = (int)(pBase[0].End.X - pBase[0].Start.X);float dx = person.Position.X - compare.Position.X;float dy = person.Position.Y - compare.Position.Y; if ((int)Math.Sqrt(dx * dx + dy * dy) <= _talk_dist + w/2) return person.Name;
Wait, so Sphere calculates talk distance based on the center of the base...? I guess it makes a certain amount of sense, but at the same time it's counterintuitive--if it were me implementing this from scratch, I'd probably set it up to use distance between the edges of the bases instead. This way the same talk distance would still work even if you changed the size of your sprites later. Oh well, not much you can do since you're aiming for parity with Sphere.
What's wrong with just inflating the baserects and checking for an intersection? That would save you from having to do all that trig, which might help performance...
Quote from: Lord English on August 10, 2013, 10:33:05 pmWhat's wrong with just inflating the baserects and checking for an intersection? That would save you from having to do all that trig, which might help performance...Actually I don't follow. It might work for square bases as I did above, but what about rectangular bases?
public static string GetClosest(string name) { int talk_x = GetPersonX(name), talk_y = GetPersonY(name); string direction = GetPersonDirection(name); if (direction.Contains("north")) talk_y -= _talk_dist; if (direction.Contains("south")) talk_y += _talk_dist; if (direction.Contains("east")) talk_x += _talk_dist; if (direction.Contains("west")) talk_x -= _talk_dist; foreach (Person p in People) { if (name == p.Name) continue; float dx = p.Position.X - talk_x; float dy = p.Position.Y - talk_y; if ((int)Math.Sqrt(dx * dx + dy * dy) <= _talk_dist) return p.Name; } return null; }
Boxing only applies when you convert a value type to a reference type (storing an int in a variable of type object, e.g.). Just passing values around won't cause anything to be boxed or unboxed.
array[0] = 0;array[1] = "hello";array[2] = true;
If you have an array of ints, for example