aboutsummaryrefslogtreecommitdiff
path: root/src/broadphase.moon
blob: 540680ee8eb396c76b3939df2a1669b8fd88c97a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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