Skip to content

Commit

Permalink
make instances interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasvlevi committed May 11, 2024
1 parent 1dad77d commit 6780ce5
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions examples/instances.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

acc = 4;
acc = 1;
bounce = 4.5;
ball_count = 200;
ball_count = 280;

mouse_zone = 128

-- Ball list
balls = {}
Expand Down Expand Up @@ -45,14 +47,32 @@ function Ball:collision(others)
self.vy = self.vy + dy * bounce;
end
end

local dx = nx - mouseX;
local dy = ny - mouseY;
local d = math.sqrt(dx*dx + dy*dy);
if (d < 1.5+8+mouse_zone/2) then

if (mouseIsPressed) then
self.vx = self.vx + -dx * bounce/12;
self.vy = self.vy + -dy * bounce/12;
else
self.vx = self.vx + dx * bounce;
self.vy = self.vy + dy * bounce;
end


end


end

function Ball:move()
self.vx = self.vx + math.random(-acc, acc);
self.vy = self.vy + math.random(-acc, acc);

self.vy = self.vy * 0.97;
self.vx = self.vx * 0.97;
self.vy = self.vy * 0.94;
self.vx = self.vx * 0.94;

self:collision(balls);

Expand Down Expand Up @@ -92,6 +112,8 @@ function draw()
ball:move();
end

circle(mouseX, mouseY, mouse_zone);

textSize(18);
fill(100, 255, 10);
text(round(frameRate()) .. ' fps', 30, 10);
Expand Down

0 comments on commit 6780ce5

Please sign in to comment.