An FP game engine for Scala.

Time Varying Values

Time varying values describe numeric values that will change over time.

They are intended to live in your game model to help you do simple time based updates.

Tracking a lumberjack's progress

You have a lumberjack, he walks over to a tree and is now going to cut it down. Work is effort over time, and you can track his progress by having an IncreaseTo time varying value in your model.

Here is an oversimplified example. We've made a little lumberjack case class, and all our lumberjack can do is this one job. While the work is being done (which starts immediately), the 'lumberjack' (a circle) will transition from red to green, signaling completion.

final case class LumberJack(chopWood: IncreaseTo):
  def update(gameTime: GameTime): LumberJack =
    this.copy(
      chopWood = chopWood.update(gameTime.delta)
    )

  def present(viewportCenter: Point): SceneNode =
    Shape.Circle(
      Circle(viewportCenter, 50),
      Fill.Color(RGBA.Red.mix(RGBA.Green, chopWood.toDouble / 100.0)),
      Stroke(2, RGBA.White)
    )
object LumberJack:
  val initial: LumberJack =
    LumberJack(
      IncreaseTo(
        value = 0,
        unitsPerSecond = 10,
        limit = 100
      )
    )