From 7bab9c56f9670b511b19772b93fe79b0d5353773 Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 27 Dec 2021 12:35:44 -0800 Subject: [PATCH] Implement path drawing effect --- ball.lua | 9 +++++++-- main.lua | 16 ++++++++++------ qphys.p8 | 25 +++++++++++++++++-------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/ball.lua b/ball.lua index a83b540..00f4e29 100644 --- a/ball.lua +++ b/ball.lua @@ -2,6 +2,7 @@ ball = { __count = 0, id = nil, pos = vec2:new(0,0), + last_pos = vec2:new(0,0), vel = vec2:new(0,0), rad = 1, col = 7, @@ -10,11 +11,15 @@ ball = { return self.rad end, - draw = function(self) + draw = function(self, shadow) + if (shadow == true) then + circfill(self.last_pos.x, self.last_pos.y, self.rad, self.col + 8) + end circfill(self.pos.x, self.pos.y, self.rad, self.col) end, move = function(self) + self.last_pos = self.pos self.pos += self.vel end, @@ -53,7 +58,7 @@ function ball:new(o) ball.__count += 1 local o = o or {} o.id = ball.__count - o.col = o.col or o.id % 16 + o.col = o.col or o.id % 8 setmetatable(o, self) o.__index = self return o diff --git a/main.lua b/main.lua index aac8677..269e02c 100644 --- a/main.lua +++ b/main.lua @@ -1,14 +1,18 @@ -ball_count = 10 -max_radius = 8 +pal() +cls() + +ball_count = 16 +max_radius = 16 function _init() - balls = {} + pal({9,10,11,12,13,2,15,136,137,138,139,140,141,130,143,8},1) + balls = {} collisions = {} for i=1,ball_count do add(balls, ball:new({ pos=vec2:new(rnd(127),rnd(127)), vel=vec2:new(rnd(2)-1,rnd(2)-1):normal(), - rad=2+flr(rnd(max_radius)), + rad = i < max_radius and i or max_radius, })) end end @@ -26,9 +30,9 @@ function _update60() end function _draw() - cls() + -- cls() for b in all(balls) do - b:draw() + b:draw(true) end end diff --git a/qphys.p8 b/qphys.p8 index 43c30fb..39cc2ee 100644 --- a/qphys.p8 +++ b/qphys.p8 @@ -59,6 +59,7 @@ ball = { __count = 0, id = nil, pos = vec2:new(0,0), + last_pos = vec2:new(0,0), vel = vec2:new(0,0), rad = 1, col = 7, @@ -67,11 +68,15 @@ ball = { return self.rad end, - draw = function(self) + draw = function(self, shadow) + if (shadow == true) then + circfill(self.last_pos.x, self.last_pos.y, self.rad, self.col + 8) + end circfill(self.pos.x, self.pos.y, self.rad, self.col) end, move = function(self) + self.last_pos = self.pos self.pos += self.vel end, @@ -110,24 +115,28 @@ function ball:new(o) ball.__count += 1 local o = o or {} o.id = ball.__count - o.col = o.col or o.id % 16 + o.col = o.col or o.id % 8 setmetatable(o, self) o.__index = self return o end -->8 -ball_count = 10 -max_radius = 8 +pal() +cls() + +ball_count = 16 +max_radius = 16 function _init() - balls = {} + pal({9,10,11,12,13,2,15,136,137,138,139,140,141,130,143,8},1) + balls = {} collisions = {} for i=1,ball_count do add(balls, ball:new({ pos=vec2:new(rnd(127),rnd(127)), vel=vec2:new(rnd(2)-1,rnd(2)-1):normal(), - rad=2+flr(rnd(max_radius)), + rad = i < max_radius and i or max_radius, })) end end @@ -145,9 +154,9 @@ function _update60() end function _draw() - cls() + -- cls() for b in all(balls) do - b:draw() + b:draw(true) end end