Physics in love 0.6.1
Posted: Tue Feb 23, 2010 3:23 pm
Well afther some years i come back grab the latest love release and try to get some simple code working
- changed love.draw_line to "line"
- lowerd the apply inpulse
- changed love.key_space to " "
- update(dt) to love.update(dt) (same for load draw etc)
It runs but the images all seem to be of target
here is the code (btw this is the example code from love 0.5.0)
EDIT: Sorry Seems to be a problem with the image !
Problem 2 is that the square seems to fall true the floor wtf ?
- changed love.draw_line to "line"
- lowerd the apply inpulse
- changed love.key_space to " "
- update(dt) to love.update(dt) (same for load draw etc)
It runs but the images all seem to be of target
here is the code (btw this is the example code from love 0.5.0)
EDIT: Sorry Seems to be a problem with the image !
Problem 2 is that the square seems to fall true the floor wtf ?
Code: Select all
-- Example: Mini Physics
function love.load()
-- Create a world with size 2000 in every direction.
world = love.physics.newWorld(2000, 2000)
world:setGravity(0, 50)
-- Create the ground body at (0, 0) with mass 0.
ground = love.physics.newBody(world, 0, 0, 0)
-- Create the ground shape at (400,500) with size (600,10).
ground_shape = love.physics.newRectangleShape(ground, 400, 500, 600, 10)
-- Load the image of the ball.
ball = love.graphics.newImage("images/love-ball.png")
square = love.graphics.newImage("images/ball.jpg")
-- Create a Body for the circle.
body = love.physics.newBody(world, 400, 200)
player1 = love.physics.newBody(world, 400, 200)
player1shape = love.physics.newRectangleShape( player1, player1:getX(), player1:getY(), 30, 50 )
player1:setMassFromShapes()
-- Attatch a shape to the body.
circle_shape = love.physics.newCircleShape(body, 28)
-- Calculate the mass of the body based on attatched shapes.
-- This gives realistic simulations.
body:setMassFromShapes()
end
function love.update(dt)
-- Update the world.
world:update(dt)
end
function love.draw()
-- Draws the ground.
love.graphics.polygon("line", ground_shape:getPoints())
-- Draw the circle.
love.graphics.draw(square,player1:getX(), player1:getY(), player1:getAngle())
love.graphics.draw(ball, body:getX(), body:getY(), body:getAngle(), 1, 1, 32, 32)
end
function love.keypressed(k)
if k == " " then
-- Apply a random impulse
body:applyImpulse(10-math.random(0, 20), 0)
end
end