- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
public void isCollideWith(gObj obj, ref bool xCollision, ref bool yCollision)
{
xCollision = (obj.bounds.Top <= this.bounds.Center.Y && this.bounds.Center.Y <= obj.bounds.Bottom) &&
(obj.bounds.Top > this.bounds.Top && obj.bounds.Top < this.bounds.Bottom) ||
(obj.bounds.Bottom > this.bounds.Top && obj.bounds.Bottom < this.bounds.Bottom);
yCollision = (obj.bounds.Left <= this.bounds.Center.X && this.bounds.Center.X <= obj.bounds.Right) &&
(obj.bounds.Left > this.bounds.Left && obj.bounds.Left < this.bounds.Right) ||
(obj.bounds.Right > this.bounds.Left && obj.bounds.Right < this.bounds.Right);
}
Вот так я проверяю произошло ли столкновения двух(obj и this) прямоугольных объектов.
malleus 08.07.2010 15:00 # +1
FMB 08.07.2010 15:02 # 0
3.14159265 08.07.2010 15:07 # 0
WebKill_HochetVBan 08.07.2010 17:57 # +1
inkanus-gray 09.07.2010 22:37 # +1
Ivanoff80 08.07.2010 15:16 # +2
В данном примере можно сделать так:
Rectangle.Intersect(new Rectangle(x1, y1, width1, height1), new Rectangle(x2, y2, width2, height2));
WebKill_HochetVBan 08.07.2010 17:56 # +2
Ivanoff80 09.07.2010 08:01 # 0
WebKill_HochetVBan 09.07.2010 19:40 # −2