Page 1 of 1

Physics in love 0.6.1

Posted: Tue Feb 23, 2010 3:23 pm
by ColdFusion
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 ?

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 

Re: Physics in love 6.1

Posted: Tue Feb 23, 2010 3:33 pm
by bartbes
Yes, origin changed from center to top-left.

Re: Physics in love 0.6.1

Posted: Tue Feb 23, 2010 4:46 pm
by ColdFusion
I have a other question to be solved (see first post)

Re: Physics in love 0.6.1

Posted: Thu Feb 25, 2010 3:51 pm
by Deecodeuh
Maybe you have to create another body as the floor?
I don't really know, because I just started teaching myself love physics this morning. But it's a suggestion.

*edit*
Nevermind, I just noticed you did create a body for the floor.

Re: Physics in love 0.6.1

Posted: Thu Feb 25, 2010 3:57 pm
by Robin
ColdFusion wrote:I have a other question to be solved (see first post)
What question do you consider unanswered? And since your first post wasn't very clear, what is that problem exactly?

Re: Physics in love 0.6.1

Posted: Sat Feb 27, 2010 6:15 pm
by Deecodeuh
There is a physics tutorial now. http://love2d.org/wiki/Tutorial:Physics Maybe that will help what you need?