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))
yuin
#954()
[
Scala
]
Rating0/0=0.00
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))Rating0/0=0.00-0+
[ reply ]