diff --git a/scripts/debug.js b/scripts/debug.js index d5e1709..283080e 100644 --- a/scripts/debug.js +++ b/scripts/debug.js @@ -241,6 +241,7 @@ var Time = { }, pause() { + Time.stash = Time.timescale; Time.timescale = 0; }, diff --git a/scripts/entity.js b/scripts/entity.js index 573e1dc..d0efdbe 100644 --- a/scripts/entity.js +++ b/scripts/entity.js @@ -123,6 +123,10 @@ var gameobject = { set phys(x) { set_body(1, this.body, x); }, 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); }, set velocity(x) { set_body(9, this.body, x); }, get angularvelocity() { return Math.rad2deg(q_body(4, this.body)); }, @@ -237,7 +241,7 @@ var gameobject = { world2this(pos) { return cmd(70, this.body, pos); }, this2world(pos) { return cmd(71, this.body,pos); }, set layer(x) { cmd(75,this.body,x); }, - get layer() { return 0; }, + get layer() { cmd(77,this.body); }, alive() { return this.body >= 0; }, in_air() { return q_body(7, this.body);}, on_ground() { return !this.in_air(); }, @@ -336,7 +340,6 @@ var gameobject = { this.objects.forEach(function(x) { x.sync(); }); }, - /* Bounding box of the object in world dimensions */ boundingbox() { var boxes = []; diff --git a/scripts/input.js b/scripts/input.js index 7ad78c0..1cb2aca 100644 --- a/scripts/input.js +++ b/scripts/input.js @@ -135,7 +135,7 @@ var Player = { } if (!pawn.inputs?.[cmd]) { - if (pawn.inputs.block) return; + if (pawn.inputs?.block) return; continue; } diff --git a/scripts/physics.js b/scripts/physics.js index 0bb1163..a43f65a 100644 --- a/scripts/physics.js +++ b/scripts/physics.js @@ -52,32 +52,16 @@ physics.doc.box_point_query = "Returns the subset of points from a given list th var Collision = { types: {}, - num: 10, + num: 32, set_collide(a, b, x) { this.types[a][b] = x; this.types[b][a] = x; + this.sync(); }, sync() { for (var i = 0; i < this.num; 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++) { @@ -86,3 +70,5 @@ for (var i = 0; i < Collision.num; i++) { Collision.types[i][j] = false; }; +Collision.sync(); + diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 6b813c4..affe6f6 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -50,6 +50,11 @@ int shape2gameobject(cpShape *shape) { return s->go; } +struct gameobject *shape2go(cpShape *shape) +{ + return id2go(shape2gameobject(shape)); +} + int pos2gameobject(cpVect pos) { cpShape *hit = phys2d_query_pos(pos); @@ -84,6 +89,16 @@ int go2id(struct 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) { cpShapeSetFriction(shape, go->f); cpShapeSetElasticity(shape, go->e); @@ -91,8 +106,8 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) { cpShapeFilter filter; filter.group = go2id(go); - filter.categories = CP_ALL_CATEGORIES;//1<layer; - filter.mask = CP_ALL_CATEGORIES;//category_masks[go->layer]; + filter.categories = 1<layer; + filter.mask = category_masks[go->layer]; cpShapeSetFilter(shape, filter); struct phys2d_shape *ape = cpShapeGetUserData(shape); diff --git a/source/engine/gameobject.h b/source/engine/gameobject.h index 40c24f6..b2a5982 100644 --- a/source/engine/gameobject.h +++ b/source/engine/gameobject.h @@ -53,6 +53,9 @@ int go2id(struct gameobject *go); int body2id(cpBody *body); cpBody *id2body(int id); 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); diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 74a23d1..259321d 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -50,13 +50,11 @@ static JSClassDef js_ptr_class = { "POINTER" }; void js_setprop_str(JSValue obj, const char *prop, JSValue v) { JS_SetPropertyStr(js, obj, prop, v); -// JS_FreeValue(js,v); } void js_setprop_num(JSValue obj, uint32_t i, JSValue v) { JS_SetPropertyUint32(js, obj, i, v); -// JS_FreeValue(js,v); } JSValue js_getpropstr(JSValue v, const char *str) @@ -826,6 +824,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) break; case 77: + ret = int2js(js2go(argv[1])->layer); break; case 78: