aboutsummaryrefslogtreecommitdiff
path: root/src/broadphase.moon
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2024-01-29 16:20:10 -0600
committerAlexander M Pickering <alex@cogarr.net>2024-01-29 16:20:10 -0600
commitc2926c5ec74d7e37da395c8c32a7ff2b4cae7d06 (patch)
treeac2bb208dab1274cdc5e9059ffe014ae19181a4c /src/broadphase.moon
downloadfools_rush_in-c2926c5ec74d7e37da395c8c32a7ff2b4cae7d06.tar.gz
fools_rush_in-c2926c5ec74d7e37da395c8c32a7ff2b4cae7d06.tar.bz2
fools_rush_in-c2926c5ec74d7e37da395c8c32a7ff2b4cae7d06.zip
All the files
Diffstat (limited to 'src/broadphase.moon')
-rw-r--r--src/broadphase.moon69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/broadphase.moon b/src/broadphase.moon
new file mode 100644
index 0000000..540680e
--- /dev/null
+++ b/src/broadphase.moon
@@ -0,0 +1,69 @@
+
+--[[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
+