Skip to content

Instantly share code, notes, and snippets.

@PhilipWitte
Last active August 29, 2015 13:59
Show Gist options
  • Save PhilipWitte/10698296 to your computer and use it in GitHub Desktop.
Save PhilipWitte/10698296 to your computer and use it in GitHub Desktop.
random syntax thoughts
val everyone: list[Person] = new(size:50, step:25, max:250)

enum Emotion {
  Relaxed, Happy, Angry, Distress
}

type Vector[T:int|num] byRef: tuple {
  var
    x, y, z: T
  init
    cross(a, b:Vector) = a.(x, y, z) * b.(x, y, z)
  func
    cross() = (x, y, z) *= (x, y, z)
    cross(v:Vector) = (x, y, z) *= v.(x, y, z)
    
    +=(n:T)      = (x, y, z) += n
    +=(v:Vector) = (x, y, z) += v.(x, y, z)
    -=(n:T)      = (x, y, z) -= n
    -=(v:Vector) = (x, y, z) -= v.(x, y, z)
}

type Person {
  var
    name = "Unknown"
    age pri: num
    emotion pub: Emotion
    position pub: Vector
  init
    new(.name, .age = 0, .position = 0) pool(everyone)
  fini
    die() pool(everyone)
  func
    greet() =
      echo "Hello, I'm ", name, "."
      echo "I am ", age, " years old."
  proc
    update() required =
      position += World.gravity * Time.delta
    
    collide(hits:list[Collision]) optional {
      for hit in hits:
        if hit.item is Enemy: die()
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment