From 2095c56c2b48e6c4e87f7a5e2bdb6a4679b85a24 Mon Sep 17 00:00:00 2001 From: heav Date: Tue, 27 Dec 2022 23:16:22 +0000 Subject: sdfjkhkgfhsdgkldfgklsdfhghbvxcmvcn bee. --- objects/heav_object_2.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 objects/heav_object_2.lua (limited to 'objects') 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 -- cgit v1.2.3