aboutsummaryrefslogtreecommitdiff
path: root/src/util.moon
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.moon')
-rw-r--r--src/util.moon37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/util.moon b/src/util.moon
new file mode 100644
index 0000000..3066d86
--- /dev/null
+++ b/src/util.moon
@@ -0,0 +1,37 @@
+--[[Utility classes]]
+
+mod = ...
+
+class Vec3
+ new:(x,y,z) =>
+ @x = x or 0
+ @y = y or 0
+ @z = z or 0
+
+class Vec2
+ new: (x,y) =>
+ @x = x or 0
+ @y = y or 0
+ area: () => math.abs(@x * @y)
+ __sub: (a,b) ->
+ Vec2(a.x-b.x,a.y-b.y)
+ __add: (a,b) ->
+ Vec2(a.x + b.x, a.y + b.y)
+
+--getmetatable(Vec2).__sub = (a,b) ->
+ --Vec2(a.x-b.x,b.x-b.y)
+
+drawable = (c) ->
+ assert(c.sprite or c.anim)
+
+anim_co = (a) ->
+ while true
+ a.keyframe = math.floor(am.current_time()*4) % #(a.anim)
+ assert(a.anim[a.keyframe + 1], "Failed to find an appropriate image to draw.")
+ a.node\replace("sprite",am.sprite(a.anim[a.keyframe + 1])\tag "sprite")
+ coroutine.yield()
+
+
+mod["Vec2"] = Vec2
+mod["Vec3"] = Vec3
+mod