Physics in love 0.6.1

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ColdFusion
Prole
Posts: 2
Joined: Tue Feb 23, 2010 3:14 pm

Physics in love 0.6.1

Post 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 
Last edited by bartbes on Tue Feb 23, 2010 3:37 pm, edited 2 times in total.
Reason: it's 0.6.1 and 0.5.0 (edit requested by robin)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Physics in love 6.1

Post by bartbes »

Yes, origin changed from center to top-left.
ColdFusion
Prole
Posts: 2
Joined: Tue Feb 23, 2010 3:14 pm

Re: Physics in love 0.6.1

Post by ColdFusion »

I have a other question to be solved (see first post)
User avatar
Deecodeuh
Citizen
Posts: 70
Joined: Tue Dec 15, 2009 3:18 am
Location: Michigan, USA

Re: Physics in love 0.6.1

Post 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.
Last edited by Deecodeuh on Thu Feb 25, 2010 4:04 pm, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Physics in love 0.6.1

Post 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?
Help us help you: attach a .love.
User avatar
Deecodeuh
Citizen
Posts: 70
Joined: Tue Dec 15, 2009 3:18 am
Location: Michigan, USA

Re: Physics in love 0.6.1

Post by Deecodeuh »

There is a physics tutorial now. http://love2d.org/wiki/Tutorial:Physics Maybe that will help what you need?
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests