Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions test/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ for n, v in pairs(_G) do
pre_globals[n] = v
end

local mystr = "Astring"
print(mystr:upper())

bf = require("breezefield")

for n, v in pairs(_G) do
Expand All @@ -13,26 +16,24 @@ end
function love.load()
world = bf.newWorld(0, 90.81, true)

ground = bf.Collider.new(world,
"rect", 325, 600, 650, 100)
ground = world:newCollider("rect", {325, 600, 650, 100})

ground:setType("static")
print(ground.collider_type)

ball = bf.Collider.new(world, "Circle", 325, 325, 20)
ball = world:newCollider("Circle", {325, 325, 20})

ball:setRestitution(0.8)
block1 = bf.Collider.new(world, "Polygon", {150, 375, 250, 375,
250, 425, 150, 425})
block1 = world:newCollider("Polygon", {150, 375, 250, 375, 250, 425, 150, 425})
little_ball.new(
love.math.random(love.graphics.getWidth()), 0)

tri = bf.Collider.new(world, "Polygon", {400, 400, 450, 400, 425, 356.7})
tri = world:newCollider("Polygon", {400, 400, 450, 400, 425, 356.7})

edge = bf.Collider.new(world, 'Edge', 500, 300, 500, 500)
edge = world:newCollider('Edge', {500, 300, 500, 500})
edge:setType('static')

chain = bf.Collider.new(world, 'Chain', false, 100, 100, 110, 110, 115, 110, 120, 115, 120, 125, 130, 130)
chain = world:newCollider('Chain', {false, 100, 100, 110, 110, 115, 110, 120, 115, 120, 125, 130, 130})


function ball:postSolve(other)
Expand Down Expand Up @@ -103,7 +104,7 @@ function spawn_random_ball()
end

function little_ball.new(x, y)
local n = bf.Collider.new(world, 'Circle', x, y, 5)
local n = world:newCollider('Circle', {x, y, 5})
setmetatable(n, little_ball)
return n
end
Expand Down
9 changes: 9 additions & 0 deletions world.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ args:
table_to_use (optional, table): table to generate as the collider
]]--
function World:newCollider(collider_type, shape_arguments, table_to_use)
if type(collider_type) ~= 'string' then
if type(self) == 'string' then
error("World:newCollider not called correctly. "..
"You have probably tried to do world.newCollider(...) instead of world:newCollider(...). "..
"The colon notation is equivalent to world.newCollider(world, ...)"
)
end
error("The first argument of world:newCollider must be a string designating the collider type.")
end
local o = table_to_use or {}
setmetatable(o, Collider)
-- note that you will need to set static vs dynamic later
Expand Down