Trying to make some asteroids/squares fall to the bottom of the screen, but only 1 does so.
function love.load()
width = 350
height = 700
moulove,mousey = love.mouse.getPosition()
shipx = width/2
shipy = 600
asteroidmax = 35
dtotal = 0
world = love.physics.newWorld(0,0,width,height)
world:setGravity(0,0)
world:setMeter(64)
objects = {}
objects.ship = {}
objects.ship.body = love.physics.newBody(world,0,0,0)
objects.ship.shape = love.physics.newRectangleShape(objects.ship.body,0,0,32,32,0)
objects.asteroid = {}
for x = 1,asteroidmax do
objects.asteroid[x] = {}
objects.asteroid[x].xx = math.random(0,width)
objects.asteroid[x].y = math.random(-400,0)
objects.asteroid[x].body = love.physics.newBody(world,0,0,25)
objects.asteroid[x].shape = love.physics.newRectangleShape(objects.asteroid[x].body,objects.asteroid[x].xx,objects.asteroid[x].y,48,48,0)
objects.asteroid[x].body:applyForce(0,150)
end
love.graphics.setMode(350,700,false,false,2)
end
function love.update(dt)
world:update(dt)
dtotal = dtotal + dt
moulove,mousey = love.mouse.getPosition()
if moulove >= 0 and moulove <= width and mousey >= 0 and mousey <= height then
shipx = moulove
shipy = mousey
objects.ship.body:setX(shipx)
objects.ship.body:setY(shipy)
end
for x = 1,asteroidmax do
velx,vely = objects.asteroid[x].body:getLinearVelocity()
if vely == 0 then
objects.asteroid[x].body:applyForce(0,150)
end
end
end
function love.draw()
love.graphics.setColor(0,255,0)
love.graphics.polygon("fill",objects.ship.shape:getPoints())
love.graphics.setColor(128,96,0)
for x = 1,asteroidmax do
love.graphics.polygon("fill",objects.asteroid[x].shape:getPoints())
end
end
can anyone help? I can't figure it outttt :c
(semi-new to lua as well, kinda getting the hang of it now.)