--[[I was going to write my own physics engine, but decided to just use a library]] --[[Keeps track of the collisions in the world]] mod = ... util = require "util" bump = require "bump" main = require "main" --for debugging import Vec3 from util mod.world = bump.newWorld(8) --passes the bottom left x,y and the width,height of the object mod.add = (ref,x,y,width,height) -> print("Making phys for ref:",ref) --print("At the time of adding, main.screenpos is",main.screenpos, "x:", x, "y:",y) --print("Width:",width, "height", height) --print("ref.node is", ref.node) graphic_x = 0--x/4 graphic_y = 0--y --+ (height / 2) --print("graphic_y:",graphic_y) physx = x physy = y --lx = x - main.screenpos.x - (width / 2) --ly = y - main.screenpos.y - (height / 2) lx = x --+ (width / 2) ly = y --+ (height / 2) --tn = am.translate(lx,ly)\tag("position") --node = tn ^ am.rect(0,0,width,height,vec4(0.5,0.5,0.5,0.5))\tag("sprite") --(main.world("world_platforms"))\append(node) --for debugging --print("ref node:",ref.node) --print("positionnode:",(ref.node)("position")) --print("ref's children:") --for k,v in ref.node\child_pairs() --print(k,v) --[[The debug display for the physics box]] positionnode = ref.node --positionnode\append(am.rect(-width/2,-height/2, width/2,height/2,vec4(1.0,0.0,0.0,1.0))\tag("dsprite")) --positionnode\append(am.rect(x , y , x + width, y - height,vec4(1.0,0.0,0.0,0.5))\tag("dsprite")) --positionnode\append(am.rect(lx,ly,lx + width,ly + height,vec4(0.5,0.5,0.5,0.5))\tag("dsprite")) --[[The actual physics object for bump.lua]] mod.world\add(ref,physx,physy,width,height) --mod.world\add(ref,x - (width/2),y,width,height) print("physics node:",node) node mod.update = (ref,x,y,newwidth,newheight) -> mod.world\update(ref,x,y,newwidth,newheight) mod.move = (ref,x,y,filter) -> mod.world\move(ref,x,y,filter) mod.remove = (ref) -> mod.world\remove(ref) mod.check = (x,y) -> mod.world\queryPoint(x,y) class PhysGroup new: (offset, size, extra = {}) => @offset = offset @size = size @extra = extra mod.gravity = 0.5 mod.term_fall_vel = 10 mod.PhysGroup = PhysGroup mod