From c2926c5ec74d7e37da395c8c32a7ff2b4cae7d06 Mon Sep 17 00:00:00 2001 From: Alexander M Pickering Date: Mon, 29 Jan 2024 16:20:10 -0600 Subject: All the files --- src/util.moon | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/util.moon (limited to 'src/util.moon') 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 -- cgit v1.2.3-70-g09d2