summaryrefslogtreecommitdiff
path: root/objects/x.lua
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2023-04-24 15:20:36 -0500
committerthe lemons <citrons@mondecitronne.com>2023-04-24 15:20:36 -0500
commit425c5dae3521479a694528dff33d32989662dda7 (patch)
tree5623e58763c41bd6a3c2e86691295751e21326b3 /objects/x.lua
parent0d2f8775b11b604adc0f9adf73c8f6379e075ad5 (diff)
obj:avel_to_accel (broken)
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}