Untitled

 avatar
unknown
scala
2 years ago
527 B
2
Indexable
class Obstacle(val radius: Int, initialPos: Pos):

  private var currentPos = initialPos

  def pos = this.currentPos

  def approach() =
    this.currentPos =
      if this.isActive then
        this.currentPos.addX(-ObstacleSpeed)
      else
        Pos(1250, 200)

  def touches(bug: Bug) =
    (this.radius + bug.radius) > this.currentPos.distance(bug.pos)

  def isActive = this.currentPos.x >= -this.radius

  override def toString = "center at " + this.pos + ", radius " + this.radius

end Obstacle
Editor is loading...