Skip to content

Instantly share code, notes, and snippets.

@def-
Last active January 21, 2016 02:23
Show Gist options
  • Save def-/ab9bced6449106cf7cf1 to your computer and use it in GitHub Desktop.
Save def-/ab9bced6449106cf7cf1 to your computer and use it in GitHub Desktop.
import strutils, unicode
type
Component = ref object of RootObj
CPosition = ref object of Component
x, y: int
CVelocity = ref object of Component
dx, dy: int
CRune = ref object of Component
rune: Rune
Entity = object
position: CPosition
velocity: CVelocity
rune: CRune
proc `$`[T](v: ref T): string = $(v[])
var e = Entity(
position: CPosition(x:100, y:50),
velocity: CVelocity(dx:1, dy:2),
rune: CRune(rune: toRunes("@")[0]))
if e.position != nil:
echo "e has a position!"
# gameplay code - has reference to a relevant entity...
var
pos = e.position
rune = e.rune
echo "Rendering $1 at $2, $3".format(rune.rune, pos.x, pos.y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment