fix/workaround: removed glitches with scaling and quads
[uboot.git] / physics.lua
blob6614ce6d749bf7ac438100955c644e2c2c126e37
1 local world
2 local xGravity = 0
3 local yGravity = -1
5 --[[
6 creates a world (love.physics.world) and sets properties and callback functions
7 ]]--
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)
12 end
14 --[[
15 iterates over all entities and applies forces on them
16 ]]--
17 function physics_update(dt)
18 world:update(dt)
19 for i,e in ipairs(entities) do
20 if (e.speed~=0) then
21 e.body:applyForce(e.speed,0,e.body:getX(),e.body:getY())
22 end
23 e.body:setGravityScale(getWaterDensity(e.body:getY()-e.density))
24 end
25 end
27 --[[
28 creates a body,a shape and a fixture (combined)
29 TODO massData und damping besser machen
30 ]]--
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
38 end
40 --[[
41 creates a body without shape and fixture
42 ]]--
43 function physics_createBody(xPos,yPos)
44 local body = love.physics.newBody(world,xPos,yPos,"dynamic")
45 return body
46 end
48 --[[
49 generates walls from a given map-matrix
50 ]]--
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)
56 end
57 end
58 end
60 end
62 --[[
63 creates static body with rectangle shape (quad -> walls)
64 returns nothing
65 ]]--
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)
70 end
72 --[[
73 just returns given value, maybe changed sometimes
74 ]]--
75 function getWaterDensity(depth)
76 return depth
77 end
79 function beginContact()
80 end
82 function endContact()
83 end
85 function preSolve()
86 end
88 function postSolve()
89 end