diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index 29b2307..694da47 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -20,6 +20,7 @@ float phys2d_gravity = -50.f; static float dbg_color[3] = {0.836f, 1.f, 0.45f}; static float trigger_color[3] = {0.278f, 0.953f, 1.f}; +static float disabled_color[3] = {0.58f, 0.58f, 0.58f}; static struct color static_color = {56, 69, 255}; void set_dbg_color(struct color color) @@ -472,6 +473,16 @@ cpShape *id2shape(int id) return NULL; } +void shape_enable(struct phys2d_shape *shape) +{ + cpSpaceAddShape(space, shape->shape); +} + +void shape_disable(struct phys2d_shape *shape) +{ + cpSpaceRemoveShape(space, shape->shape); +} + void phys2d_reindex_body(cpBody *body) { cpSpaceReindexShapesForBody(space, body); } diff --git a/source/engine/2dphysics.h b/source/engine/2dphysics.h index f39198d..2460cf7 100644 --- a/source/engine/2dphysics.h +++ b/source/engine/2dphysics.h @@ -97,6 +97,9 @@ void phys2d_add_handler_type(int cmd, int go, struct callee c); void register_collide(void *sym); void phys2d_set_gravity(cpVect v); +void shape_enable(struct phys2d_shape *shape); +void shape_disable(struct phys2d_shape *shape); + cpShape *id2shape(int id); struct color { diff --git a/source/engine/ffi.c b/source/engine/ffi.c index 2f5beae..7ddc927 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -163,6 +163,20 @@ duk_ret_t duk_cmd(duk_context *duk) { duk_push_undefined(duk); return 1; + + case 20: + sprite_enabled(duk_to_int(duk, 1), duk_to_boolean(duk, 2)); + break; + + case 21: + duk_push_boolean(duk, id2sprite(duk_to_int(duk, 1))->enabled); + return 1; + + case 22: + return 0; + + case 23: + return 0; } return 0; @@ -418,6 +432,17 @@ duk_ret_t duk_make_box2d(duk_context *duk) { phys2d_applybox(box); + duk_push_pointer(duk, box); + + return 1; +} + +duk_ret_t duk_box2d_cmd(duk_context *duk) { + int cmd = duk_to_int(duk, 0); + struct phys2d_box *box = duk_to_pointer(duk, 1); + + YughInfo("Issuing command %d with box %p.", cmd, box); + return 0; } @@ -492,6 +517,7 @@ void ffi_load() DUK_FUNC(make_sprite, 3); DUK_FUNC(make_anim2d, 4); DUK_FUNC(make_box2d, 3); + DUK_FUNC(box2d_cmd, DUK_VARARGS); DUK_FUNC(make_circle2d, 3); DUK_FUNC(cmd, DUK_VARARGS); DUK_FUNC(register, 3); diff --git a/source/engine/sprite.c b/source/engine/sprite.c index e2c0820..0cc14c7 100644 --- a/source/engine/sprite.c +++ b/source/engine/sprite.c @@ -26,7 +26,8 @@ int make_sprite(int go) .size = {1.f, 1.f}, .tex = texture_loadfromfile("ph.png"), .go = go, - .next = -1 }; + .next = -1, + .enabled = 1 }; int ret; @@ -51,6 +52,11 @@ void sprite_delete(int id) first = id; } +void sprite_enabled(int id, int e) +{ + sprites[id].enabled = e; +} + struct sprite *id2sprite(int id) { return &sprites[id]; } @@ -78,9 +84,8 @@ void sprite_io(struct sprite *sprite, FILE *f, int read) void sprite_draw_all() { - //shader_use(spriteShader); for (int i = 0; i < arrlen(sprites); i++) { - if (sprites[i].go >= 0) sprite_draw(&sprites[i]); + if (sprites[i].go >= 0 && sprites[i].enabled) sprite_draw(&sprites[i]); } } diff --git a/source/engine/sprite.h b/source/engine/sprite.h index 23b0122..13660af 100644 --- a/source/engine/sprite.h +++ b/source/engine/sprite.h @@ -19,12 +19,14 @@ struct sprite { struct anim2d anim; struct Texture *tex; int next; + int enabled; }; int make_sprite(int go); struct sprite *id2sprite(int id); void sprite_delete(int id); +void sprite_enabled(int id, int e); void sprite_io(struct sprite *sprite, FILE *f, int read); void sprite_loadtex(struct sprite *sprite, const char *path); void sprite_settex(struct sprite *sprite, struct Texture *tex);