Example 0100: Mini Physics
-
-
- function load()
-
-
- world = love.physics.newWorld(2000, 2000)
- world:setGravity(0, 50)
-
-
- ground = love.physics.newBody(world, 0, 0, 0)
-
-
- ground_shape = love.physics.newRectangleShape(ground, 400, 500, 600, 10)
-
-
- ball = love.graphics.newImage("images/love-ball.png")
-
-
- body = love.physics.newBody(world, 400, 200)
-
-
- circle_shape = love.physics.newCircleShape(body, 28)
-
-
-
- body:setMassFromShapes()
-
- end
-
- function update(dt)
-
- world:update(dt)
- end
-
- function draw()
-
- love.graphics.polygon(love.draw_line, ground_shape:getPoints())
-
-
- love.graphics.draw(ball,body:getX(), body:getY(), body:getAngle())
- end
-
- function keypressed(k)
- if k == love.key_space then
-
- body:applyImpulse(100000-math.random(0, 200000), 0)
- end
- end