From 56942461e7fdb8cac5700537e0378f824b45a2d1 Mon Sep 17 00:00:00 2001 From: Quinn Date: Sun, 26 Dec 2021 22:10:14 -0800 Subject: [PATCH] Fix mass function use --- ball.lua | 4 ++-- main.lua | 4 ++-- qphys.p8 | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ball.lua b/ball.lua index 8638a49..a83b540 100644 --- a/ball.lua +++ b/ball.lua @@ -6,8 +6,8 @@ ball = { rad = 1, col = 7, - mass = function() - return rad + mass = function(self) + return self.rad end, draw = function(self) diff --git a/main.lua b/main.lua index 7211b75..aac8677 100644 --- a/main.lua +++ b/main.lua @@ -46,8 +46,8 @@ function handle_collisions() s_xpoint = source.pos - source.vel * rewind t_xpoint = target.pos - target.vel * rewind until rewind > 1 or (s_xpoint - t_xpoint):mag() >= source.rad + target.rad - local s_newvel = collision_vel(s_xpoint, source.vel, t_xpoint, target.vel, source.mass(), target.mass()) - local t_newvel = collision_vel(t_xpoint, target.vel, s_xpoint, source.vel, target.mass(), source.mass()) + local s_newvel = collision_vel(s_xpoint, source.vel, t_xpoint, target.vel, source:mass(), target:mass()) + local t_newvel = collision_vel(t_xpoint, target.vel, s_xpoint, source.vel, target:mass(), source:mass()) source.pos = s_xpoint + source.vel * rewind target.pos = t_xpoint + target.vel * rewind source.vel = s_newvel diff --git a/qphys.p8 b/qphys.p8 index 554f96b..43c30fb 100644 --- a/qphys.p8 +++ b/qphys.p8 @@ -63,8 +63,8 @@ ball = { rad = 1, col = 7, - mass = function() - return rad + mass = function(self) + return self.rad end, draw = function(self) @@ -165,8 +165,8 @@ function handle_collisions() s_xpoint = source.pos - source.vel * rewind t_xpoint = target.pos - target.vel * rewind until rewind > 1 or (s_xpoint - t_xpoint):mag() >= source.rad + target.rad - local s_newvel = collision_vel(s_xpoint, source.vel, t_xpoint, target.vel, source.mass(), target.mass()) - local t_newvel = collision_vel(t_xpoint, target.vel, s_xpoint, source.vel, target.mass(), source.mass()) + local s_newvel = collision_vel(s_xpoint, source.vel, t_xpoint, target.vel, source:mass(), target:mass()) + local t_newvel = collision_vel(t_xpoint, target.vel, s_xpoint, source.vel, target:mass(), source:mass()) source.pos = s_xpoint + source.vel * rewind target.pos = t_xpoint + target.vel * rewind source.vel = s_newvel