Code: Select all
main.lua:73: attempt to call method 'update' (a nil value)
Traceback
main.lua:73 in function 'update'
[C]: in function 'xpcall'
Thanks for any help/explanation.
Code: Select all
main.lua:73: attempt to call method 'update' (a nil value)
Traceback
main.lua:73 in function 'update'
[C]: in function 'xpcall'
Code: Select all
collider = require('hc')
hc = collider.new(150)
function love.load()
ball = hc:circle(400, 300, 10)
paddleLeft = hc:rectangle(10, 250, 20, 100)
paddleRight = hc:rectangle(770, 250, 20, 100)
ball.velocity = {x = -100, y = 0}
end
function love.update(dt)
ball:move(ball.velocity.x*dt, ball.velocity.y*dt)
if love.keyboard.isDown('w') then
paddleLeft:move(0, -100*dt)
elseif love.keyboard.isDown('s') then
paddleLeft:move(0, 100*dt)
end
if love.keyboard.isDown('up') then
paddleRight:move(0, -100*dt)
elseif love.keyboard.isDown('down') then
paddleRight:move(0, 100*dt)
end
if love.keyboard.isDown('escape') then
love.event.push('quit')
end
local collisions = hc:collisions(ball)
for other in pairs(collisions) do
if other == goalLeft then
ball.velocity = {x = 100, y = 0}
ball:moveTo(400,300)
elseif other == goalRight then
ball.velocity = {x = -100, y = 0}
ball:moveTo(400,300)
elseif other == borderTop or other == borderBottom then
ball.velocity.y = -ball.velocity.y
else
local px,py = other:center()
local bx,by = ball:center()
local dy = by - py
ball.velocity.x = -ball.velocity.x
ball.velocity.y = dy
local len = math.sqrt(ball.velocity.x^2 + ball.velocity.y^2)
ball.velocity.x = ball.velocity.x / len * 100
ball.velocity.y = ball.velocity.y / len * 100
end
end
end
function love.draw()
ball:draw('line', 16)
paddleLeft:draw('line')
paddleRight:draw('line')
end
Users browsing this forum: Ahrefs [Bot] and 6 guests