6 creates a world (love.physics.world) and sets properties and callback functions
8 function physics_createWorld()
9 love
.physics
.setMeter(1) -- number of pixels in one meter, set to 1 because of bugs
10 world
= love
.physics
.newWorld(xGravity
,yGravity
,false) -- num: x gravity, num: y gravity, bool: sleep allowed
11 world
:setCallbacks(beginContact
, endContact
, preSolve
, postSolve
)
15 iterates over all entities and applies forces on them
17 function physics_update(dt
)
19 for i
,e
in ipairs(entities
) do
21 e
.body
:applyForce(e
.speed
,0,e
.body
:getX(),e
.body
:getY())
23 e
.body
:setGravityScale(getWaterDensity(e
.body
:getY()-e
.density
))
28 creates a body,a shape and a fixture (combined)
29 TODO massData und damping besser machen
31 function physics_createBodyWithShape(xPos
,yPos
,shape
)
32 local body
= love
.physics
.newBody(world
,xPos
,yPos
,"dynamic")
33 body
:setMassData( 100, 100, 2, 0 ) -- num: mass center x, mass center y, mass, inertia
34 body
:setLinearDamping(2)
35 local shape
= love
.physics
.newChainShape(true,unpack(shape
))
36 local fixture
= love
.physics
.newFixture(body
,shape
,0) -- body, shape, density
37 return body
, shape
, fixture
41 creates a body without shape and fixture
43 function physics_createBody(xPos
,yPos
)
44 local body
= love
.physics
.newBody(world
,xPos
,yPos
,"dynamic")
49 generates walls from a given map-matrix
51 function physics_createWalls(map
)
52 for i
= 1,#map
.matrix
do
53 for j
= 1,#map
.matrix
[1] do
54 if map
.matrix
[i
][j
] == 2 then
55 physics_createStaticWall(i
*map
.realTileSize
,j
*map
.realTileSize
,map
.realTileSize
)
63 creates static body with rectangle shape (quad -> walls)
66 function physics_createStaticWall(xPos
,yPos
,size
)
67 local body
= love
.physics
.newBody(world
,xPos
,yPos
,"static")
68 local shape
= love
.physics
.newRectangleShape(-(size
/2),-(size
/2),size
,size
)
69 local fixture
= love
.physics
.newFixture(body
,shape
,0)
73 just returns given value, maybe changed sometimes
75 function getWaterDensity(depth
)
79 function beginContact()