sprite layers

This commit is contained in:
John Alanbrook 2023-02-10 20:31:59 +00:00
parent 1fcdae17ba
commit 8155bddb5e
4 changed files with 39 additions and 7 deletions

View file

@ -256,7 +256,12 @@ duk_ret_t duk_spline_cmd(duk_context *duk)
int d = duk_to_int(duk, 2);
cpVect points[n*d];
ts_bspline_new(n, d, duk_to_int(duk, 1), duk_to_int(duk, 3), &spline, NULL);
tsStatus status;
ts_bspline_new(n, d, duk_to_int(duk, 1), duk_to_int(duk, 3), &spline, &status);
if (status.code) {
YughCritical("Spline creation error %d: %s", status.code, status.message);
}
for (int i = 0; i < n; i++) {
duk_get_prop_index(duk, 4, i);
@ -626,6 +631,11 @@ duk_ret_t duk_cmd(duk_context *duk) {
case 59:
duk_push_int(duk, point2segindex(duk2vec2(duk, 1), duk2cpvec2arr(duk, 2), duk_to_number(duk, 3)));
return 1;
case 60:
if (!id2sprite(duk_to_int(duk, 1))) return 0;
id2sprite(duk_to_int(duk, 1))->layer = duk_to_int(duk, 2);
break;
}
return 0;
@ -852,7 +862,7 @@ duk_ret_t duk_make_sprite(duk_context *duk) {
sp->pos[0] = pos.x;
sp->pos[1] = pos.y;
duk_push_int(duk, sprite);
duk_push_int(duk, sprite);
return 1;
}

View file

@ -55,7 +55,7 @@ static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos)
mouse_pos.y = ypos;
for (int i = 0; i < arrlen(pawns); i++) {
if (script_eval_setup("input_mouse_pos", pawns[i])) continue;
if (!pawns[i] || script_eval_setup("input_mouse_pos", pawns[i])) continue;
vect2duk(duk, mouse_pos);
script_eval_exec(1);
}
@ -119,7 +119,8 @@ void call_input_signal(char *signal) {
}
for (int i = 0; i < arrlen(pawns); i++) {
script_eval_w_env(signal, pawns[i]);
if (!pawns[i]) continue;
script_eval_w_env(signal, pawns[i]);
}
}
@ -215,6 +216,17 @@ const char *keyname_extd(int key, int scancode) {
case GLFW_KEY_KP_SUBTRACT:
kkey = "minus";
break;
case GLFW_KEY_GRAVE_ACCENT:
kkey = "backtick";
break;
case GLFW_KEY_LEFT_BRACKET:
kkey = "lbracket";
break;
case GLFW_KEY_RIGHT_BRACKET:
kkey = "rbracket";
break;
}
if (kkey) return kkey;
@ -257,6 +269,7 @@ void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods
case GLFW_PRESS:
snprintf(keystr, 50, "input_%s_pressed", kkey);
add_downkey(key);
call_input_signal("input_any_pressed");
break;
case GLFW_RELEASE:

View file

@ -27,6 +27,7 @@ int make_sprite(int go)
.tex = texture_loadfromfile("ph.png"),
.go = go,
.next = -1,
.layer = 0,
.enabled = 1 };
int ret;
@ -81,13 +82,20 @@ void sprite_io(struct sprite *sprite, FILE *f, int read)
}
}
void sprite_draw_all()
{
static struct sprite **layers[5];
for (int i = 0; i < 5; i++)
arrfree(layers[i]);
for (int i = 0; i < arrlen(sprites); i++) {
if (sprites[i].go >= 0 && sprites[i].enabled) sprite_draw(&sprites[i]);
if (sprites[i].go >= 0 && sprites[i].enabled) arrpush(layers[sprites[i].layer], &sprites[i]);
}
for (int i = 4; i >= 0; i--)
for (int j = 0; j < arrlen(layers[i]); j++)
sprite_draw(layers[i][j]);
}
void sprite_loadtex(struct sprite *sprite, const char *path)

View file

@ -20,6 +20,7 @@ struct sprite {
struct glrect *frame;
int next;
int enabled;
int layer;
};
int make_sprite(int go);