Code: Select all
function love.load()
player = {}
player.x = 400
player.y = 400
player.speed = 3
block = {}
block.x = math.random(00, 200)
block.y = math.random(00, 200)
block.speed = math.random(100, 200)
player.radius = 25
end
function love.update(dt)
if love.keyboard.isDown("w") then
player.y = player.y - player.speed
end
if love.keyboard.isDown("s") then
player.y = player.y + player.speed
end
if love.keyboard.isDown("a") then
player.x = player.x - player.speed
end
if love.keyboard.isDown("d") then
player.x = player.x + player.speed
end
block.y = math.random(0, 800) + 1
block.x = math.random(0, 600) + 1
if distanceBetween (block.x, block.y, 5, 5) >= 50 then
block.y = math.random(5, 800)
end
if distanceBetween (block.x, block.y, 600, 5) >= 50 then
block.y = math.random(5, 800)
end
if distanceBetween (block.x, block.y, 5, 800) >= 50 then
block.y = math.random(5, 800)
end
if distanceBetween (block.x, block.y,600, 800) >= 50 then
block.y = math.random(5, 800)
end
if distanceBetween (block.x. block.y, player.x, player.y) >= player.radius then
end
end
function love.draw()
love.graphics.circle("fill", player.x, player.y, player.radius)
love.graphics.rectangle("fill", block.x, block.y, 50,50)
end
function distanceBetween(x1, y1, x2, y2)
return math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
end
Error
main.lua:40: attempt to index field 'x' (a number value)
Traceback
[love "callbacks.lua"]:228: in function 'handler'
main.lua:40: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144> Um.. what??
[C]: in function 'xpcall'