Comment detail

長方形の交差判定 (Nested Flatten)

	
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class Rect(_x:int, _y:int, _w:int, _h:int) {
  var x = _x;var y = _y;var w = _w;var h = _h
  def left = x
  def right = x+w
  def top = y
  def bottom = y+h
  def detectCollision(r:Rect) =
    (left < r.right) && (right > r.left) && (top < r.bottom) && (bottom > r.top)
}

val a = new Rect(10,10,100,100)
val b = new Rect(20,20,100,100)
println(a.detectCollision(b))

Index

Feed

Other

Link

Pathtraq

loading...