summaryrefslogtreecommitdiff
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
parentdf189a048a64e1982455ac1a1520a20a2412339d (diff)
sdfjkhkgfhsdgkldfgklsdfhghbvxcmvcn bee.
-rw-r--r--debug_arrow.lua18
-rw-r--r--main.lua7
-rw-r--r--obj.lua2
-rw-r--r--objects/heav_object_2.lua46
4 files changed, 71 insertions, 2 deletions
diff --git a/debug_arrow.lua b/debug_arrow.lua
new file mode 100644
index 0000000..ed79a9a
--- /dev/null
+++ b/debug_arrow.lua
@@ -0,0 +1,18 @@
+local M = {}
+M.queue = {}
+
+M.arrow = function(x1, y1, x2, y2, r, g, b)
+ table.insert(M.queue, {x1, y1, x2, y2, r, g, b})
+end
+
+M.draw = function()
+ for i, v in ipairs(M.queue) do
+ local x1, y1, x2, y2, r, g, b = unpack(v)
+ set_color(r,g,b)
+ line(x1, y1, x2, y2)
+ love.graphics.circle("fill", x2, y2, 1)
+ end
+ M.queue = {}
+end
+
+return M \ No newline at end of file
diff --git a/main.lua b/main.lua
index add0d92..1d51e20 100644
--- a/main.lua
+++ b/main.lua
@@ -1,5 +1,6 @@
local obj = require "obj"
local text = require "text"
+local debug_arrow = require "debug_arrow"
obj.load_types()
line = love.graphics.line
@@ -25,8 +26,7 @@ for i = 1, 100 do
end
obj.new("test", {0, 0})
-
-obj.new("heav_object", {100, 0})
+obj.new("heav_object_2", {100, 60})
local function window_scale()
local w, h = love.graphics.getDimensions()
@@ -80,6 +80,9 @@ local function draw_world()
set_color(1, 1, 1)
o:draw()
end
+
+ debug_arrow.draw()
+
set_color(1, 1, 0.5)
if selection then
for o in pairs(selection) do
diff --git a/obj.lua b/obj.lua
index f93eae9..bb000ff 100644
--- a/obj.lua
+++ b/obj.lua
@@ -4,6 +4,8 @@ local pi = math.pi
local obj = {}
+local arrows = {}
+
obj.max_size = 20
local types = {}
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