Last active
January 21, 2016 02:23
-
-
Save def-/ab9bced6449106cf7cf1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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