collision layers

This commit is contained in:
John Alanbrook 2023-11-07 23:24:26 +00:00
parent 8c3e8aa539
commit 83851ef272
7 changed files with 32 additions and 25 deletions

View file

@ -241,6 +241,7 @@ var Time = {
}, },
pause() { pause() {
Time.stash = Time.timescale;
Time.timescale = 0; Time.timescale = 0;
}, },

View file

@ -123,6 +123,10 @@ var gameobject = {
set phys(x) { set_body(1, this.body, x); }, set phys(x) { set_body(1, this.body, x); },
get phys() { return q_body(0,this.body); }, get phys() { return q_body(0,this.body); },
// set mask(x) { cmd(41, this.body, x); },
// get mask() { return cmd(43, this.body); },
// set category(x) { cmd(40, this.body, x); },
// get category() { return cmd(42, this.body); },
get velocity() { return q_body(3, this.body); }, get velocity() { return q_body(3, this.body); },
set velocity(x) { set_body(9, this.body, x); }, set velocity(x) { set_body(9, this.body, x); },
get angularvelocity() { return Math.rad2deg(q_body(4, this.body)); }, get angularvelocity() { return Math.rad2deg(q_body(4, this.body)); },
@ -237,7 +241,7 @@ var gameobject = {
world2this(pos) { return cmd(70, this.body, pos); }, world2this(pos) { return cmd(70, this.body, pos); },
this2world(pos) { return cmd(71, this.body,pos); }, this2world(pos) { return cmd(71, this.body,pos); },
set layer(x) { cmd(75,this.body,x); }, set layer(x) { cmd(75,this.body,x); },
get layer() { return 0; }, get layer() { cmd(77,this.body); },
alive() { return this.body >= 0; }, alive() { return this.body >= 0; },
in_air() { return q_body(7, this.body);}, in_air() { return q_body(7, this.body);},
on_ground() { return !this.in_air(); }, on_ground() { return !this.in_air(); },
@ -336,7 +340,6 @@ var gameobject = {
this.objects.forEach(function(x) { x.sync(); }); this.objects.forEach(function(x) { x.sync(); });
}, },
/* Bounding box of the object in world dimensions */ /* Bounding box of the object in world dimensions */
boundingbox() { boundingbox() {
var boxes = []; var boxes = [];

View file

@ -135,7 +135,7 @@ var Player = {
} }
if (!pawn.inputs?.[cmd]) { if (!pawn.inputs?.[cmd]) {
if (pawn.inputs.block) return; if (pawn.inputs?.block) return;
continue; continue;
} }

View file

@ -52,32 +52,16 @@ physics.doc.box_point_query = "Returns the subset of points from a given list th
var Collision = { var Collision = {
types: {}, types: {},
num: 10, num: 32,
set_collide(a, b, x) { set_collide(a, b, x) {
this.types[a][b] = x; this.types[a][b] = x;
this.types[b][a] = x; this.types[b][a] = x;
this.sync();
}, },
sync() { sync() {
for (var i = 0; i < this.num; i++) for (var i = 0; i < this.num; i++)
cmd(76,i,this.types[i]); cmd(76,i,this.types[i]);
}, },
types_nuke() {
Nuke.newline(this.num+1);
Nuke.label("");
for (var i = 0; i < this.num; i++) Nuke.label(i);
for (var i = 0; i < this.num; i++) {
Nuke.label(i);
for (var j = 0; j < this.num; j++) {
if (j < i)
Nuke.label("");
else {
this.types[i][j] = Nuke.checkbox(this.types[i][j]);
this.types[j][i] = this.types[i][j];
}
}
}
},
}; };
for (var i = 0; i < Collision.num; i++) { for (var i = 0; i < Collision.num; i++) {
@ -86,3 +70,5 @@ for (var i = 0; i < Collision.num; i++) {
Collision.types[i][j] = false; Collision.types[i][j] = false;
}; };
Collision.sync();

View file

@ -50,6 +50,11 @@ int shape2gameobject(cpShape *shape) {
return s->go; return s->go;
} }
struct gameobject *shape2go(cpShape *shape)
{
return id2go(shape2gameobject(shape));
}
int pos2gameobject(cpVect pos) { int pos2gameobject(cpVect pos) {
cpShape *hit = phys2d_query_pos(pos); cpShape *hit = phys2d_query_pos(pos);
@ -84,6 +89,16 @@ int go2id(struct gameobject *go) {
return id_from_gameobject(go); return id_from_gameobject(go);
} }
uint32_t go2category(struct gameobject *go)
{
return 0;
}
uint32_t go2mask(struct gameobject *go)
{
return 0;
}
void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) { void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
cpShapeSetFriction(shape, go->f); cpShapeSetFriction(shape, go->f);
cpShapeSetElasticity(shape, go->e); cpShapeSetElasticity(shape, go->e);
@ -91,8 +106,8 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
cpShapeFilter filter; cpShapeFilter filter;
filter.group = go2id(go); filter.group = go2id(go);
filter.categories = CP_ALL_CATEGORIES;//1<<go->layer; filter.categories = 1<<go->layer;
filter.mask = CP_ALL_CATEGORIES;//category_masks[go->layer]; filter.mask = category_masks[go->layer];
cpShapeSetFilter(shape, filter); cpShapeSetFilter(shape, filter);
struct phys2d_shape *ape = cpShapeGetUserData(shape); struct phys2d_shape *ape = cpShapeGetUserData(shape);

View file

@ -53,6 +53,9 @@ int go2id(struct gameobject *go);
int body2id(cpBody *body); int body2id(cpBody *body);
cpBody *id2body(int id); cpBody *id2body(int id);
int shape2gameobject(cpShape *shape); int shape2gameobject(cpShape *shape);
struct gameobject *shape2go(cpShape *shape);
uint32_t go2category(struct gameobject *go);
uint32_t go2mask(struct gameobject *go);
void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go); void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go);

View file

@ -50,13 +50,11 @@ static JSClassDef js_ptr_class = { "POINTER" };
void js_setprop_str(JSValue obj, const char *prop, JSValue v) void js_setprop_str(JSValue obj, const char *prop, JSValue v)
{ {
JS_SetPropertyStr(js, obj, prop, v); JS_SetPropertyStr(js, obj, prop, v);
// JS_FreeValue(js,v);
} }
void js_setprop_num(JSValue obj, uint32_t i, JSValue v) void js_setprop_num(JSValue obj, uint32_t i, JSValue v)
{ {
JS_SetPropertyUint32(js, obj, i, v); JS_SetPropertyUint32(js, obj, i, v);
// JS_FreeValue(js,v);
} }
JSValue js_getpropstr(JSValue v, const char *str) JSValue js_getpropstr(JSValue v, const char *str)
@ -826,6 +824,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
break; break;
case 77: case 77:
ret = int2js(js2go(argv[1])->layer);
break; break;
case 78: case 78: