My Function isn't activating, please help
Posted: Sun Apr 18, 2021 4:32 am
I am trying to make a flappy bird replica but my "createrec" function does not seem to work... It is very possible that it is a different problem because as my name suggests, I am very bad.
This is the code:
function love.load()
love.physics.setMeter(64)
world = love.physics.newWorld(0, 9*64, true)
recs = {}
objects = {}
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic")
objects.ball.shape = love.physics.newCircleShape(20)
objects.ball.fixture = love.physics.newFixture(objects.ball.body,
objects.ball.shape, 1)
objects.ball.fixture:setRestitution(0.9)
love.graphics.setBackgroundColor(0.41, 0.53, 0.97)
love.window.setMode(650, 650)
end
function love.update(dt)
world:update(dt)
end
function love.draw()
love.graphics.setColor(0.76, 0.18, 0.05)
love.graphics.circle("fill", objects.ball.body:getX(),
objects.ball.body:getY(), objects.ball.shape:getRadius())
for i,r in ipairs(recs) do
love.graphics.rectangle("line", r.x, r.Y, r.width, r.height)
end
end
function love.keypressed(key)
if key == "up" then
objects.ball.body:applyForce(0, -4000)
end
if key == "down" then
function createRecs()
end
end
function createRecs()
local rec = {}
rec.X = objects.ball.body:getX() + 300
rec.Y = love.math.random(200, 700)
rec.width = 50
rec.height = rec.Y
table.insert(recs, rec)
end
end
Thank you
This is the code:
function love.load()
love.physics.setMeter(64)
world = love.physics.newWorld(0, 9*64, true)
recs = {}
objects = {}
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic")
objects.ball.shape = love.physics.newCircleShape(20)
objects.ball.fixture = love.physics.newFixture(objects.ball.body,
objects.ball.shape, 1)
objects.ball.fixture:setRestitution(0.9)
love.graphics.setBackgroundColor(0.41, 0.53, 0.97)
love.window.setMode(650, 650)
end
function love.update(dt)
world:update(dt)
end
function love.draw()
love.graphics.setColor(0.76, 0.18, 0.05)
love.graphics.circle("fill", objects.ball.body:getX(),
objects.ball.body:getY(), objects.ball.shape:getRadius())
for i,r in ipairs(recs) do
love.graphics.rectangle("line", r.x, r.Y, r.width, r.height)
end
end
function love.keypressed(key)
if key == "up" then
objects.ball.body:applyForce(0, -4000)
end
if key == "down" then
function createRecs()
end
end
function createRecs()
local rec = {}
rec.X = objects.ball.body:getX() + 300
rec.Y = love.math.random(200, 700)
rec.width = 50
rec.height = rec.Y
table.insert(recs, rec)
end
end
Thank you