summaryrefslogtreecommitdiff
path: root/objects/x.lua
diff options
context:
space:
mode:
Diffstat (limited to 'objects/x.lua')
-rw-r--r--objects/x.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/objects/x.lua b/objects/x.lua
new file mode 100644
index 0000000..f97d1d4
--- /dev/null
+++ b/objects/x.lua
@@ -0,0 +1,27 @@
+local obj = require "obj"
+local util = require 'util'
+
+local x_obj = {hitbox = 4}
+
+function x_obj:draw()
+ set_color(0.5, 1, 0.8)
+ line(-4, 2, 0, 0, -2, 4, -4, 2)
+ line(0, 0, 2, 4, 4, 2, 0, 0)
+ line(0, 0, 4, -2, 2, -4, 0, 0)
+ line(0, 0, -2, -4, -4, -2, 0, 0)
+end
+
+local range = 40
+function x_obj:tick()
+ local x, y = unpack(self.data.pos)
+ for o in obj.in_circle(x, y, range) do
+ if o ~= self then
+ local px, py = self:observe_pos(o)
+ local mag = util.magnitude{px, py}
+ local dx, dy = px / mag, py / mag
+ self:avel_to_accel(o, dx * mag/range, dy * mag/range)
+ end
+ end
+end
+
+return {x = x_obj}