Code: Select all
function love.load()
metro=100
fuerza=600
grv=9.81
ancho=640
alto=480
rebote=0.8
densidad=1
gp=10 -- thickness of the walls and floor.
love.physics.setMeter(metro)
world = love.physics.newWorld(0,grv*metro, true)
objects = {}
--bola:
objects.ball={}
objects.ball.body = love.physics.newBody(world,ancho/2,alto/2,"dynamic")
objects.ball.shape = love.physics.newCircleShape(40) --Radio en pixeles
objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape,densidad)
objects.ball.fixture:setRestitution(rebote)
--paredes:
objects.paredes={}
objects.paredes.cuerpo=love.physics.newBody(world,0,0)
objects.paredes.forma=love.physics.newChainShape(true,0,0, gp,0, gp,alto-gp, ancho-gp,alto-gp, ancho-gp,0, ancho,0, ancho,alto, 0,alto)
objects.paredes.fixture=love.physics.newFixture(objects.paredes.cuerpo,objects.paredes.forma)
love.graphics.setBackgroundColor(0,0,0)
love.graphics.setMode(ancho,alto,false,true,0)
end
function love.update(dt)
world:update(dt)
if love.keyboard.isDown("right") then
objects.ball.body:applyForce(fuerza,0) end
if love.keyboard.isDown("left") then
objects.ball.body:applyForce(-fuerza,0) end
if love.keyboard.isDown("up") then
objects.ball.body:applyForce(0,-fuerza) end
if love.keyboard.isDown("down") then
objects.ball.body:applyForce(0,fuerza) end
end
function love.draw()
love.graphics.setColor(0,80,180)
love.graphics.polygon("fill",objects.paredes.cuerpo:getWorldPoints(objects.paredes.forma:getPoints()))
love.graphics.setColor(0,200,0)
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
end
Thank you very much.