Deteksi Tabrakan Kotak

function colidedWithRect(rect: Rectangle) {

  if (this.position.x + this.width > rect.position.x &&
      this.position.x < rect.position.x + rect.width &&
      this.position.y + this.width > rect.position.y &&
      this.position.y < rect.position.y + rect.height) {
    return true
  }

  return false
}
Himanshu Jangid