summaryrefslogtreecommitdiff
path: root/objects/heav_object_2.lua
diff options
context:
space:
mode:
authorheav <hheav3@gmail.com>2022-12-27 23:16:22 +0000
committerheav <hheav3@gmail.com>2022-12-27 23:16:22 +0000
commit2095c56c2b48e6c4e87f7a5e2bdb6a4679b85a24 (patch)
treed6a41ee4b4b2a22f151176366e5be972470146d4 /objects/heav_object_2.lua
parentdf189a048a64e1982455ac1a1520a20a2412339d (diff)
sdfjkhkgfhsdgkldfgklsdfhghbvxcmvcn bee.
Diffstat (limited to 'objects/heav_object_2.lua')
-rw-r--r--objects/heav_object_2.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/objects/heav_object_2.lua b/objects/heav_object_2.lua
new file mode 100644
index 0000000..63eba78
--- /dev/null
+++ b/objects/heav_object_2.lua
@@ -0,0 +1,46 @@
+local heav_object_2 = {hitbox = 4}
+local obj = require "obj"
+local debug_arrow = require "debug_arrow"
+
+function heav_object_2:draw()
+ set_color(0.8,0.7,0.95)
+ line(-4, -4, -4, 4, 4, 4, -4, -4)
+ line(3, -3, -3, -3)
+ line(3, -3, 3, 3)
+ line(4, 4, 4, -4, -4, -4)
+end
+
+function heav_object_2:init()
+end
+
+function heav_object_2:tick()
+ local x, y = self.data.pos[1], self.data.pos[2]
+ local vx, vy = self.data.vel[1], self.data.vel[2]
+ for obj in obj.in_circle(x, y, 40) do
+ if obj ~= self then
+ local ox, oy = obj.data.pos[1], obj.data.pos[2]
+ local ovx, ovy = obj.data.vel[1], obj.data.vel[2]
+ -- shift frame of reference
+ ox = ox - x
+ oy = oy - y
+ ovx = ovx - vx
+ ovy = ovy - vy
+
+ local mag = math.sqrt(ovx^2 + ovy^2)
+
+ ovx = ovx * 0.99
+ ovy = ovy * 0.99
+
+ local diff = math.sqrt(ovx^2 + ovy^2) - mag
+
+ self.data.avel = self.data.avel + diff * (self.data.avel > 0 and 1 or -1)
+
+ ovx = ovx + vx
+ ovy = ovy + vy
+ obj.data.vel[1] = ovx
+ obj.data.vel[2] = ovy
+ end
+ end
+end
+
+return {heav_object_2 = heav_object_2} \ No newline at end of file