Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Champion Island: rooms inside buildings; work in progress on sports and NumDash levels
Mason Chenb5860b5badd6
diff --git a/games/championisland/src/gfx.c b/games/championisland/src/gfx.cindex 6815ab07..aad41124 100644--- a/games/championisland/src/gfx.c+++ b/games/championisland/src/gfx.c@@ -468,21 +468,21 @@ static void draw_rle_row(const uint8_t *p, int x, int w, bool flipx, uint16_t *dint start = cx;cx += len;int i0 = 0, i1 = len;- uint16_t *dd;- int step;+ uint16_t *dd = d;+ int step, o; /* dd[o + i * step]: no negative index (UBSan's object-size check) */if (!flipx) {int sx = x + start; /* screen x of the run's first pixel */if (sx >= VIEW_W) break;if (sx < 0) i0 = -sx;if (sx + len > VIEW_W) i1 = VIEW_W - sx;- dd = d + sx;+ o = sx;step = 1;} else {int base = x + w - 1 - start; /* screen x of the run's first pixel; the run goes left */if (base < 0) break;if (base >= VIEW_W) i0 = base - VIEW_W + 1;if (base - (len - 1) < 0) i1 = base + 1;- dd = d + base;+ o = base;step = -1;}if (i0 >= i1) continue;@@ -491,20 +491,20 @@ static void draw_rle_row(const uint8_t *p, int x, int w, bool flipx, uint16_t *dif (!a) continue;uint16_t col = pal[c];if (a == 255 && galpha == 32) {- for (int i = i0; i < i1; i++) dd[i * step] = col;+ for (int i = i0; i < i1; i++) dd[o + i * step] = col;} else {unsigned aa = (a * galpha + 128) >> 8;- for (int i = i0; i < i1; i++) dd[i * step] = blend(col, dd[i * step], aa);+ for (int i = i0; i < i1; i++) dd[o + i * step] = blend(col, dd[o + i * step], aa);}} else if (galpha == 32) {for (int i = i0; i < i1; i++) {unsigned c = src[i], a = al[c];- dd[i * step] = a == 255 ? pal[c] : blend(pal[c], dd[i * step], (a + 4) >> 3);+ dd[o + i * step] = a == 255 ? pal[c] : blend(pal[c], dd[o + i * step], (a + 4) >> 3);}} else {for (int i = i0; i < i1; i++) {unsigned c = src[i];- dd[i * step] = blend(pal[c], dd[i * step], (al[c] * galpha + 128) >> 8);+ dd[o + i * step] = blend(pal[c], dd[o + i * step], (al[c] * galpha + 128) >> 8);}}}diff --git a/games/championisland/src/sport_climbing.c b/games/championisland/src/sport_climbing.cindex b7197604..9feefab8 100644--- a/games/championisland/src/sport_climbing.c+++ b/games/championisland/src/sport_climbing.c@@ -11,6 +11,7 @@#include <math.h>#include <stdio.h>#include "ent.h"+#include "spr.h"enum { M_GROUND, M_JUMP, M_GRAB, M_HANG, M_FALL };enum { H_STATIC, H_MOVING, H_CIRCLING };@@ -18,6 +19,7 @@ enum { H_STATIC, H_MOVING, H_CIRCLING };#define GROUND_MAX 16#define CHECK_MAX 10#define NEVER 1e30f /* Number.MAX_SAFE_INTEGER */+#define SKY_MAX 8typedef struct {NodeId n;@@ -61,6 +63,13 @@ typedef struct {/* parallax (Aq) */bool par_init;float par_dx, par_dy, par_hx, par_hy, par_fx, par_fy;+ /* the sky (Iba's copies of one big picture, drawn by code) */+ uint16_t sky_sprite;+ int nsky;+ float sky_x[SKY_MAX], sky_y[SKY_MAX];+ float sky_ref; /* the copy whose rows the forest texture matches */+ bool tex; /* the forest texture is ready */+ int tex_cx, tex_cy;Countdown cd;bool counting;/* the end (zq) */@@ -364,12 +373,6 @@ static void start(void) {k->lantern = node_child(c, "lantern");}}-#ifdef HOST- for (int i = 0; i < S->ngrounds; i++) printf("ground %d: %.1f %.1f %.1f %.1f\n", S->grounds[i].n, S->grounds[i].r.x, S->grounds[i].r.y, S->grounds[i].r.w, S->grounds[i].r.h);- printf("goal %.1f %.1f %.1f %.1f\n", S->goal.x, S->goal.y, S->goal.w, S->goal.h);- for (int i = 0; i < S->nchecks; i++) printf("check %.1f %.1f %.1f %.1f pos %.1f %.1f\n", S->checks[i].r.x, S->checks[i].r.y, S->checks[i].r.w, S->checks[i].r.h, S->checks[i].px, S->checks[i].py);- printf("holds %d climber %.1f %.1f\n", S->nholds, rawx(S->climber), rawy(S->climber));-#endifS->mode = M_GROUND;S->DY = S->kC = S->D_ = -1;S->EL = NEVER;@@ -685,14 +688,6 @@ static void sys_parallax(void) {float cx = S->par_hx - nodes[S->map].x, cy = S->par_hy - nodes[S->map].y;nodes[p].x = S->par_dx - S->par_fx * cx;nodes[p].y = S->par_dy - S->par_fy * cy;-#ifdef SKYDBG- if (game.ticks % 10 == 0) {- float v0 = -nodes[p].y / 3, v1 = v0 + 180;- printf("t %u map %.0f sky rows %.0f..%.0f :", game.ticks, rawy(S->map), v0, v1);- for (NodeId c = nodes[p].first; c; c = nodes[c].next) printf(" %.0f", nodes[c].y);- printf("\n");- }-#endif}/* Zo: the end, with the doodle's rating */@@ -729,13 +724,7 @@ static void sys_end(void) {}}-#ifdef SKYTEST-#include "spr.h"-#endifstatic void tick(void) {-#ifdef SKYTEST- { const uint8_t *st = spr_stream(426); if (st) { z_open(rd32(st + 2), rd32(st + 6), rd32(st + 10)); z_get(NULL, 432 * SKYTEST); } }-#endifsys_back_pauses();if (menus_active()) return;sys_tutorial_once();diff --git a/games/championisland/src/sport_pingpong.c b/games/championisland/src/sport_pingpong.cindex 414ea2e3..191ae610 100644--- a/games/championisland/src/sport_pingpong.c+++ b/games/championisland/src/sport_pingpong.c@@ -478,7 +478,7 @@ static void paddle_swing(int side) { /* gt *//* ft: the power shot */static bool power_shot(void) {- if (!in.held[A_ACTION]) return false;+ if (!in.pressed[A_ACTION]) return false; /* ak.Ca: pressed this tick */if (S->pstate == 2 || S->pstate == 3 || S->my < 1) return false;SOUND(power);S->pstate = 2;@@ -934,7 +934,7 @@ static void autopilot(void) {float dx = gx - (r.x + r.w / 2), dy = gy - (r.y + r.h / 2), d = sqrtf(dx * dx + dy * dy);if (d > 2) { in.jx = dx / d; in.jy = dy / d; }}- in.held[A_ACTION] = S->my >= 1 && S->nballs >= 2;+ in.pressed[A_ACTION] = S->my >= 1 && S->nballs >= 2;}#elsestatic void autopilot(void) {}diff --git a/games/championisland/src/world.c b/games/championisland/src/world.cindex bca85519..bff317ab 100644--- a/games/championisland/src/world.c+++ b/games/championisland/src/world.c@@ -707,6 +707,15 @@ static void tick_overworld(void) {Ent *e = ent_get(W->player);Rect r;bool hb = ent_bounds(W->player, &r);+ for (int i = 0; i < ent_count(); i++) {+ NodeId n = ent_at(i);+ if (!n || !comp_has(nodes[n].T, C_scenePortal)) continue;+ float x, y;+ ent_pos(n, &x, &y);+ Ent *pe = ent_get(n);+ if (fabsf(x - px) < 150 && fabsf(y - py) < 150)+ fprintf(stderr, " portal %s at %.0f,%.0f trig %d vis %d\n", str(comp_str(nodes[n].T, C_scenePortal, F_name)), x, y, pe ? pe->ntrig : -1, node_visible(n));+ }fprintf(stderr, "t%u in %.1f,%.1f p %.1f,%.1f v %.2f,%.2f body %d bounds %d (%.0f %.0f %.0f %.0f) solids %d label %s\n", W->tick, in.jx, in.jy,px, py, e ? e->vx : 0, e ? e->vy : 0, e ? e->body : -9, hb, r.x, r.y, r.w, r.h, W->nsolid, node_label(W->player));}@@ -730,10 +739,59 @@ static void draw_under_overworld(void) {const SceneDef scene_overworld = {"overworld", start_overworld, tick_overworld, end_overworld, draw_under_overworld, NULL, NULL};/* ---------------------------------------------------------------- interiors */+/* Ir: a room is a frame of the interior library's root (its label is the+ * scene's variant), a small map drawn at the middle of the screen */+static uint16_t room_label = NONE16;+static void start_interior(void) {- NodeId n = node_new_sym(S_interior_mbb);- node_add(game.root, n);- ent_register_tree(n);+ W = scene_state(sizeof(World));+ W->region_rain = -1;+ W->water_look = -1;+ Clip c;+ int frame = 0;+ if (clip_get(S_interior_mbb, &c) && game.variant[0]) {+ int f = clip_label(&c, game.variant);+ if (f >= 0) frame = f;+ }+ NodeId root = node_new_sym_frame(S_interior_mbb, frame);+ if (!root) return;+ node_add(game.root, root);+ ent_register_tree(root);+ translate_tree(root);+ W->map = ent_map;+ for (int i = 0; i < ent_count(); i++) {+ NodeId n = ent_at(i);+ if (n && comp_has(nodes[n].T, C_overworldPlayer)) W->player = n;+ /* sr: places are markers */+ if (n && comp_has(nodes[n].T, C_location) && !comp_has(nodes[n].T, C_boundable)) nodes[n].alpha = 0;+ }+ ent_on_trigger(on_trigger);+ phys_steps(1, 20);+ (void)room_label;}-static void tick_interior(void) {}-const SceneDef scene_interior = {"interior", start_interior, tick_interior, NULL, NULL, NULL, NULL};++static void tick_interior(void) {+ if (!W || !W->map) return;+ sys_back_map();+ sys_on_action();+ sys_sort_draw();+ sys_triggers();+ sys_player_movement();+ sys_player_dir();+ sys_jump_to_frame();+ sys_walk_idle();+ sys_storage_sprites();+ sys_sprite_dirs();+ sys_physics();+ sys_ground_height();+ sys_portals();+ sys_npcs();+ W->tick++;+}++static void end_interior(void) {+ ent_on_trigger(NULL);+ W = NULL;+}++const SceneDef scene_interior = {"interior", start_interior, tick_interior, end_interior, NULL, NULL, NULL};diff --git a/games/numdash/src/fx.c b/games/numdash/src/fx.cindex bc946f38..2508ee4b 100644--- a/games/numdash/src/fx.c+++ b/games/numdash/src/fx.c@@ -136,7 +136,7 @@ void fx_burst_screen(float x, float y, int def, color_t c, int count) {for (int i = 0; i < count; i++) spawn(def, x, y, c, true, c, true, PF_SCREEN, 1e9f);}-static float ease(int e, float t) {+static float fx_ease(int e, float t) {if (t < 0) t = 0;if (t > 1) t = 1;switch (e) {@@ -387,17 +387,17 @@ static void draw_circles(bool screen_pass) {if (c->t >= d->dur) continue;float t = c->t / d->dur, a, r;if (d->tri) {- a = t < .5f ? d->a0 + (d->a1 - d->a0) * ease(d->ea0, t * 2) : d->a1 + (d->a0 - d->a1) * ease(d->ea1, (t - .5f) * 2);+ a = t < .5f ? d->a0 + (d->a1 - d->a0) * fx_ease(d->ea0, t * 2) : d->a1 + (d->a0 - d->a1) * fx_ease(d->ea1, (t - .5f) * 2);} else if (d->ea0 == d->ea1) {- a = d->a0 + (d->a1 - d->a0) * ease(d->ea0, t);+ a = d->a0 + (d->a1 - d->a0) * fx_ease(d->ea0, t);} else {float mid = (d->a0 + d->a1) / 2;- a = t < .5f ? d->a0 + (mid - d->a0) * ease(d->ea0, t * 2) : mid + (d->a1 - mid) * ease(d->ea1, (t - .5f) * 2);+ a = t < .5f ? d->a0 + (mid - d->a0) * fx_ease(d->ea0, t * 2) : mid + (d->a1 - mid) * fx_ease(d->ea1, (t - .5f) * 2);}- if (d->er0 == d->er1) r = d->r0 + (d->r1 - d->r0) * ease(d->er0, t);+ if (d->er0 == d->er1) r = d->r0 + (d->r1 - d->r0) * fx_ease(d->er0, t);else {float mid = (d->r0 + d->r1) / 2;- r = t < .5f ? d->r0 + (mid - d->r0) * ease(d->er0, t * 2) : mid + (d->r1 - mid) * ease(d->er1, (t - .5f) * 2);+ r = t < .5f ? d->r0 + (mid - d->r0) * fx_ease(d->er0, t * 2) : mid + (d->r1 - mid) * fx_ease(d->er1, (t - .5f) * 2);}float sx, sy;to_screen(c->x, c->y, c->screen, &sx, &sy);diff --git a/games/numdash/src/game.c b/games/numdash/src/game.cindex b5ca8556..03e8bc8c 100644--- a/games/numdash/src/game.c+++ b/games/numdash/src/game.c@@ -105,6 +105,13 @@ static float closest_rotation(float rot) {s = fmodf(s, 360);return s < 0 ? s + 360 : s;}+/* Nearest of base + k * 90 degrees. */+static float closest_rotation_to(float rot, float base) {+ float r = fmodf((float)(int)rot, 360.0f);+ if (r < 0) r += 360;+ float s = fmodf(roundf((r - base) / 90) * 90 + base, 360);+ return s < 0 ? s + 360 : s;+}static float slerp_angle(float from, float to, float t) {float fx = cosf(from * .5f), fy = sinf(from * .5f), tx = cosf(to * .5f), ty = sinf(to * .5f);float dot = fx * tx + fy * ty;@@ -138,6 +145,7 @@ void game_start(Game *g, const Level *L, bool first_attempt) {p->ceiling_y = 999999;p->coyote = 1 << 30;p->on_ground = true;+ p->sl_o = p->co_o = -1;if (L->start_mode == MODE_SHIP) {p->mode = MODE_SHIP;set_bounds_for_portal(g, 150, 300);@@ -186,7 +194,7 @@ static bool box_circle(float px, float py, float h, float cx, float cy, float r)}static bool overlap(float ax, float ay, float ahw, float ahh, float bx, float by, float bhw, float bhh) {- return fabsf(ax - bx) < ahw + bhw && fabsf(ay - by) < ahh + bhh;+ return fabsf(ax - bx) <= ahw + bhw && fabsf(ay - by) <= ahh + bhh; /* cocos rects touch inclusively */}/* Separating axis test of two boxes turned by a and b radians (clockwise). */@@ -225,8 +233,318 @@ static void snap_to(Game *g, float ox, float oy) {p->snap_diff = p->x - ox;}+/* ------------------------------------------------------------ slopes+ Ported from gd3ds (its slope.c): a slope is a right triangle in its box;+ orientation 0 rises to the right with the solid below, 1 falls to the+ right, 2 and 3 are the same hanging from above. */+typedef struct { float x, y, w, h; int o; } Slope;+enum { OR_NU, OR_ND, OR_UDD, OR_UDU };+#define SLOPE_EPS 0.01f+#define SLOPE_HEAD_TOL 2.0f+static const float SLOPE_FALL[4] = {226.044054f, 280.422108f, 348.678108f, 421.200108f};++static Slope slope_of(const Level *L, const RObj *o, float x, float y) {+ const ObjDef *d = &objdefs[o->type];+ float sx, sy;+ obj_scale_xy(L, o, &sx, &sy);+ Slope s = {x, y, d->w10 * 0.1f * fabsf(sx), d->h10 * 0.1f * fabsf(sy), 0};+ int xf = obj_xf(o);+ if (xf < 0) xf = 0;+ int o4 = xf & 3, fh = (xf >> 2) & 1, fv = (xf >> 3) & 1;+ if (o4 & 1) { float t = s.w; s.w = s.h; s.h = t; }+ o4 += fh && fv ? 2 : fh ? 1 : fv ? 3 : 0;+ s.o = o4 & 3;+ return s;+}+static void slope_get(const float *a, int o, Slope *s) { *s = (Slope){a[0], a[1], a[2], a[3], o}; }+static float sl_left(const Slope *s) { return s->x - s->w / 2; }+static float sl_right(const Slope *s) { return s->x + s->w / 2; }+static float sl_top(const Slope *s) { return s->y + s->h / 2; }+static float sl_bottom(const Slope *s) { return s->y - s->h / 2; }+static float sl_gtop(const Player *p, const Slope *s) { return p->upside ? -sl_bottom(s) : sl_top(s); }+static float sl_gbottom(const Player *p, const Slope *s) { return p->upside ? -sl_top(s) : sl_bottom(s); }+static int sl_orient(const Player *p, const Slope *s) {+ int o = s->o;+ if (p->upside) o = o == OR_UDU ? OR_NU : o == OR_UDD ? OR_ND : o == OR_NU ? OR_UDU : OR_UDD;+ return o;+}+static float sl_angle(const Player *p, const Slope *s) {+ float a = atanf(s->h / s->w);+ int o = sl_orient(p, s);+ return o == OR_ND || o == OR_UDD ? -a : a;+}+static float sl_snap_angle(const Player *p, const Slope *s) {+ float a = sl_angle(p, s);+ if (s->o == OR_NU) a = -fabsf(a);+ if (s->o == OR_ND) a = fabsf(a);+ return a;+}+static float sl_expected_y(const Player *p, const Slope *s) {+ bool flipping = sl_orient(p, s) >= OR_UDD;+ float mult = (p->upside ^ flipping) ? -1 : 1, a = sl_angle(p, s), ph = phalf(p);+ float ydist = mult * ph / cosf(a), rel = s->h / s->w * (p->x - sl_left(s));+ if ((a > 0) ^ p->upside ^ flipping) return sl_bottom(s) + fminf(rel + ydist, s->h + ph);+ return sl_top(s) - fminf(rel - ydist, s->h + ph);+}+static void sl_clear(Player *p) { p->sl_o = -1; p->sl_t = 0; p->sl_down = false; }++static bool sl_touching(const Player *p, const Player *old, const Slope *s) {+ bool has = old->sl_o >= 0;+ if (has) {+ Slope os;+ slope_get(old->sl, old->sl_o, &os);+ float mult = sl_orient(p, &os) >= OR_UDD ? -1 : 1;+ has = p->vy * mult <= 0;+ }+ float deg = fabsf(sl_angle(p, s)) / DEG, snap_h = 20 * (deg / 45), mn = has ? -3 : 0;+ if (sl_right(s) < p->x - phalf(p)) return false;+ float diff = sl_orient(p, s) < OR_UDD ? grav(p, sl_expected_y(p, s)) - grav(p, p->y) : grav(p, p->y) - grav(p, sl_expected_y(p, s));+ return diff >= mn && diff <= snap_h;+}++static void sl_snap_y(Player *p, const Slope *s) {+ float ph = phalf(p), e = sl_expected_y(p, s);+ switch (sl_orient(p, s)) {+ case OR_NU:+ p->y = p->upside ? fmaxf(sl_bottom(s) - ph, e) : fminf(sl_top(s) + ph, e);+ p->time_since_ground = 0; p->on_ground = true;+ if (p->vy < 0) p->vy = 0;+ break;+ case OR_ND:+ p->y = p->upside ? fminf(e, sl_top(s) + ph) : fmaxf(e, sl_bottom(s) - ph);+ p->time_since_ground = 0; p->on_ground = true;+ if (p->vy < 0) p->vy = 0;+ break;+ case OR_UDD:+ p->y = p->upside ? fmaxf(e, sl_bottom(s) - ph) : fminf(e, sl_top(s) + ph);+ p->time_since_ground = 0; p->on_ceiling = true;+ if (p->vy > 0) p->vy = 0;+ break;+ default:+ p->y = p->upside ? fminf(sl_top(s) + ph, e) : fmaxf(sl_bottom(s) - ph, e);+ p->time_since_ground = 0; p->on_ceiling = true;+ if (p->vy > 0) p->vy = 0;+ break;+ }+}++/* How many of the nearby slopes the player touches (only the one it rides+ and the next one of the same kind count while on a slope). */+typedef struct { Slope s[8]; int n; } SlopeSet;+static int sl_count(const Player *p, const Player *old, const SlopeSet *ss) {+ int count = 0;+ Slope cur;+ bool have = p->sl_o >= 0;+ if (have) slope_get(p->sl, p->sl_o, &cur);+ float ph = phalf(p);+ for (int k = 0; k < ss->n; k++) {+ const Slope *s = &ss->s[k];+ if (!overlap(p->x, p->y, ph + .5f, ph + .5f, s->x, s->y, s->w / 2, s->h / 2) || !sl_touching(p, old, s)) continue;+ if (have) {+ float diff = s->y - cur.y;+ bool next = (cur.o == OR_NU || cur.o == OR_UDD) ? diff > 0 : diff < 0;+ bool same = s->x == cur.x && s->y == cur.y;+ if ((cur.o == sl_orient(p, s) && sl_angle(p, &cur) == sl_angle(p, s) && next) || same) count++;+ } else {+ count++;+ }+ }+ return count;+}++#define SHIP_UFO_EXIT_VY (508.248f / 4)+static void sl_calc(Game *g, const Player *old, const Slope *s, const SlopeSet *ss, bool hold) {+ Player *p = &g->p;+ float spd = SPEEDS[p->speed];+ switch (sl_orient(p, s)) {+ case OR_NU:+ if ((p->mode == MODE_UFO || p->mode == MODE_SHIP) && p->vy < SHIP_UFO_EXIT_VY && hold) p->vy = SHIP_UFO_EXIT_VY;+ if (!sl_touching(p, old, s)) { p->pend_clear = true; return; }+ if (grav_bottom(p) != sl_gtop(p, s)) sl_snap_y(p, s);+ if (grav_bottom(p) >= sl_gtop(p, s) - SLOPE_EPS && sl_count(p, old, ss) < 2) {+ /* sliding off the top: launched along the slope */+ float v = 0.9f * fminf(1.12f / sl_angle(p, s), 1.54f) * (s->h * spd / s->w);+ float t = clampf(10 * (p->t_elapsed - p->sl_t), 0.4f, 1.0f);+ if (p->mode == MODE_BALL || p->mode == MODE_SHIP) v *= 0.75f;+ if (p->mode == MODE_UFO) v *= 0.7499f;+ v *= t;+ p->inverse_rot = true;+ memcpy(p->co, p->sl, sizeof(p->co)); p->co_o = p->sl_o; p->co_t = p->sl_t; p->co_down = p->sl_down;+ p->co_ticks = 2;+ p->new_vy = v; p->has_new_vy = true;+ p->jumped = true;+ p->pend_clear = true;+ }+ break;+ case OR_ND:+ if (p->vy > 0) { p->pend_clear = true; return; }+ if (grav_bottom(p) != sl_gtop(p, s) || p->sl_down) sl_snap_y(p, s);+ if ((sl_gtop(p, s) <= grav(p, p->y) + SLOPE_EPS || (p->x - phalf(p)) - sl_right(s) > 0) && sl_count(p, old, ss) < 2) {+ p->new_vy = -SLOPE_FALL[p->speed] * (s->h / s->w); p->has_new_vy = true;+ memcpy(p->co, p->sl, sizeof(p->co)); p->co_o = p->sl_o; p->co_t = p->sl_t; p->co_down = p->sl_down;+ p->co_ticks = 2;+ p->pend_clear = true;+ }+ break;+ case OR_UDU: {+ if ((p->mode == MODE_UFO || p->mode == MODE_SHIP) && p->vy > -SHIP_UFO_EXIT_VY && !hold) p->vy = -SHIP_UFO_EXIT_VY;+ if (!sl_touching(p, old, s)) { p->pend_clear = true; return; }+ if ((p->mode == MODE_CUBE || p->mode == MODE_ROBOT) && p->ceil_inv <= 0) {+ if (grav(p, p->y - SLOPE_HEAD_TOL) > grav(p, sl_expected_y(p, s))) kill(g, -1);+ return;+ }+ if (grav_bottom(p) != sl_gtop(p, s)) sl_snap_y(p, s);+ if (grav_top(p) <= sl_gbottom(p, s) + SLOPE_EPS && sl_count(p, old, ss) < 2) {+ float v = 0.9f * fminf(1.12f / sl_angle(p, s), 1.54f) * (s->h * spd / s->w);+ float t = clampf(10 * (p->t_elapsed - p->sl_t), 0.4f, 1.0f);+ if (p->mode == MODE_BALL || p->mode == MODE_SHIP) v *= 0.75f;+ if (p->mode == MODE_UFO) v *= 0.7499f;+ v *= t;+ p->inverse_rot = true;+ memcpy(p->co, p->sl, sizeof(p->co)); p->co_o = p->sl_o; p->co_t = p->sl_t; p->co_down = p->sl_down;+ p->co_ticks = 2;+ p->pend_clear = true;+ p->new_vy = -v; p->has_new_vy = true;+ }+ break;+ }+ default:+ if (p->vy < 0) { p->pend_clear = true; return; }+ if ((p->mode == MODE_CUBE || p->mode == MODE_ROBOT) && p->ceil_inv <= 0) {+ if (grav(p, p->y - SLOPE_HEAD_TOL) > grav(p, sl_expected_y(p, s))) kill(g, -1);+ return;+ }+ if (grav_bottom(p) != sl_gtop(p, s) || p->sl_down) sl_snap_y(p, s);+ if ((sl_gtop(p, s) <= grav(p, p->y) - SLOPE_EPS || (p->x - phalf(p)) - sl_right(s) > 0) && sl_count(p, old, ss) < 2) {+ p->new_vy = SLOPE_FALL[p->speed] * (s->h / s->w); p->has_new_vy = true;+ memcpy(p->co, p->sl, sizeof(p->co)); p->co_o = p->sl_o; p->co_t = p->sl_t; p->co_down = p->sl_down;+ p->co_ticks = 2;+ p->pend_clear = true;+ }+ break;+ }+}++/* Distance from a point to a segment <= r? */+static bool seg_circle(float cx, float cy, float r, float x1, float y1, float x2, float y2) {+ float dx = x2 - x1, dy = y2 - y1, fx_ = cx - x1, fy = cy - y1, l2 = dx * dx + dy * dy;+ float t = l2 > 0 ? (fx_ * dx + fy * dy) / l2 : 0;+ t = t < 0 ? 0 : t > 1 ? 1 : t;+ float ex = cx - (x1 + t * dx), ey = cy - (y1 + t * dy);+ return ex * ex + ey * ey <= r * r;+}+static bool sl_circle_touch(const Player *p, const Slope *s) {+ float hw = s->w / 2, hh = s->h / 2, r = (phalf(p) * 2 - 4) / 2, x = s->x, y = s->y;+ bool nu = s->o == OR_NU || s->o == OR_UDD, up = s->o == OR_NU || s->o == OR_UDU, normal = s->o < OR_UDD;+ bool hyp = nu ? seg_circle(p->x, p->y, r, x - hw, y - hh, x + hw, y + hh) : seg_circle(p->x, p->y, r, x + hw, y - hh, x - hw, y + hh);+ bool ver = up ? seg_circle(p->x, p->y, r, x + hw, y - hh, x + hw, y + hh) : seg_circle(p->x, p->y, r, x - hw, y - hh, x - hw, y + hh);+ bool hor = normal ? seg_circle(p->x, p->y, r, x + hw, y - hh, x - hw, y - hh) : seg_circle(p->x, p->y, r, x + hw, y + hh, x - hw, y + hh);+ return hyp || ver || hor;+}++static void sl_collide(Game *g, const Player *old, const Slope *s, const SlopeSet *ss, bool hold) {+ Player *p = &g->p;+ if (p->npot < 4) { p->pot[p->npot][0] = sl_top(s); p->pot[p->npot][1] = sl_bottom(s); p->pot_o[p->npot++] = (int8_t)s->o; }+ bool has = old->sl_o >= 0;+ float e = sl_expected_y(p, s), ph = phalf(p), in = p->mode == MODE_WAVE ? 1.5f : 4.5f;+ if (s->o < 2 && e + (has ? 3 : 0) <= p->y) return;+ if (s->o >= 2 && e - (has ? 3 : 0) >= p->y) return;+ float clip = p->mode == MODE_SHIP || p->mode == MODE_UFO ? 7 : 10;+ int orient = sl_orient(p, s);+ float mult = orient >= OR_UDD ? -1 : 1;+ bool gsnap = p->ceil_inv > 0, cube = p->mode == MODE_CUBE || p->mode == MODE_ROBOT;+ if (orient == OR_NU || orient == OR_UDU) {+ /* inside the slope's tall side */+ if (overlap(p->x, p->y, in, in, sl_right(s), s->y, 0.5f, s->h / 2)) { kill(g, -1); return; }+ }+ if (!has && orient < OR_UDD && grav_top(p) - sl_gbottom(p, s) <= clip + 5 * !p->mini) {+ /* under a floor slope: its flat bottom is a ceiling */+ if (p->mode != MODE_WAVE && ((!cube && p->vy >= 0) || gsnap)) {+ p->vy = 0;+ if (!gsnap) p->on_ceiling = true;+ p->time_since_ground = 0;+ p->y = grav(p, sl_gbottom(p, s)) - grav(p, ph);+ } else if (overlap(p->x, p->y, in, in, s->x, s->y, s->w / 2, s->h / 2)) kill(g, -1);+ return;+ }+ if (!has && orient >= OR_UDD && sl_gtop(p, s) - grav_bottom(p) <= clip + 5 * !p->mini) {+ /* on top of a hanging slope: its flat top is a floor */+ if (p->mode != MODE_WAVE && p->vy <= 0) {+ p->vy = 0;+ if (!gsnap) p->on_ground = true;+ p->time_since_ground = 0;+ p->y = grav(p, sl_gtop(p, s)) + grav(p, ph);+ } else if (overlap(p->x, p->y, in, in, s->x, s->y, s->w / 2, s->h / 2)) kill(g, -1);+ return;+ }+ if (!has && (orient == OR_ND || orient == OR_UDD) && p->x - sl_left(s) < 0) {+ /* coming from the left onto a falling slope's top corner */+ if (sl_gtop(p, s) - grav_bottom(p) > clip) {+ if (overlap(p->x, p->y, in, in, s->x, s->y, s->w / 2, s->h / 2)) kill(g, -1);+ return;+ }+ if (p->mode != MODE_WAVE && p->vy * mult <= 0) {+ p->y = orient == OR_ND ? grav(p, sl_gtop(p, s)) + grav(p, ph) : grav(p, sl_gbottom(p, s)) - grav(p, ph);+ p->on_ground = true;+ p->inverse_rot = false;+ return;+ }+ }+ if (!gsnap && cube && orient >= 2 && !sl_circle_touch(p, s)) return;+ bool colliding = overlap(p->x, p->y, ph, ph, s->x, s->y, s->w / 2, s->h / 2);+ bool riding = p->sl_o >= 0;+ Slope cur;+ if (riding) slope_get(p->sl, p->sl_o, &cur);+ bool next = true;+ if (riding) {+ float diff = s->y - cur.y;+ next = (cur.o == OR_NU || cur.o == OR_UDD) ? diff > 0 : diff < 0;+ }+ int co = riding ? sl_orient(p, &cur) : -1;+ bool up_to_down = riding && co != orient && ((co == OR_ND && orient == OR_NU) || (co == OR_UDD && orient == OR_UDU));+ if ((!riding || co == orient || up_to_down) && sl_touching(p, old, s) && colliding && sl_gtop(p, s) - grav_bottom(p) > 2 &&+ (up_to_down || next)) {+ if (riding && sl_angle(p, s) < sl_angle(p, &cur)) return;+ float old_vel = (orient == OR_ND || orient == OR_UDD) ? grav(p, old->delta_y) : old->vy * ND_DT;+ float ang = atanf(old_vel / (SPEEDS[p->speed] * ND_DT));+ if (orient >= OR_UDD) ang = -ang;+ bool had = old->sl_o >= 0;+ if (had && riding) had = old->sl_o == p->sl_o;+ bool hit = (orient == OR_ND || orient == OR_UDD) ? ang * 5 <= sl_angle(p, s) : ang <= sl_angle(p, s);+ bool snap_down = (orient == OR_ND || orient == OR_UDD) && p->vy * mult > 0 && p->x - sl_left(s) > 0;+ if (hit || snap_down) {+ if (p->mode == MODE_WAVE) { kill(g, -1); return; } /* the wave does not ride slopes */+ if (orient >= OR_UDD) p->on_ceiling = true;+ else { p->on_ground = true; landing(p); }+ p->inverse_rot = false;+ float t_prev = p->sl_t;+ p->sl[0] = s->x; p->sl[1] = s->y; p->sl[2] = s->w; p->sl[3] = s->h; p->sl_o = (int8_t)s->o;+ p->sl_t = t_prev;+ if (snap_down && !had) {+ if (orient == OR_ND && p->vy <= 0) { p->y = grav(p, sl_gtop(p, s)) + grav(p, ph); p->sl_down = true; p->vy = 0; }+ else if (orient == OR_UDD && p->vy >= 0) { p->y = grav(p, sl_gbottom(p, s)) - grav(p, ph); p->sl_down = true; p->vy = 0; }+ }+ if (!p->sl_t) p->sl_t = old->t_elapsed;+ sl_calc(g, old, s, ss, hold);+ }+ }+}+static void solid(Game *g, unsigned i, float ox, float oy, float hw, float hh) {Player *p = &g->p;+ if (p->sl_o >= 0 && p->mode != MODE_WAVE) {+ /* riding a slope: only a falling one gives way to a block */+ Slope cur;+ slope_get(p->sl, p->sl_o, &cur);+ int o = sl_orient(p, &cur);+ if (o != OR_ND && o != OR_UDD) return;+ if (ox + hw >= p->x) { sl_clear(p); p->co_o = -1; p->co_ticks = 0; p->on_ground = true; }+ }+ /* a block level with the foot of a slope touched last tick must not catch it */+ for (int k = 0; k < p->npot; k++) {+ float bc = p->pot_o[k] < 2 ? oy + hh : oy - hh, sc = p->pot_o[k] < 2 ? p->pot[k][1] : p->pot[k][0];+ if (bc - sc < 2) return;+ }float clip = (p->mode == MODE_SHIP || p->mode == MODE_UFO ? 7.0f : 10.0f) + fabsf(p->vy) * ND_DT;float o_bottom = p->upside ? -(oy + hh) : oy - hh, o_top = p->upside ? -(oy - hh) : oy + hh;float in = p->mode == MODE_WAVE ? 1.5f : 4.5f;@@ -247,7 +565,7 @@ static void solid(Game *g, unsigned i, float ox, float oy, float hw, float hh) {p->inverse_rot = false;p->time_since_ground = 0;landing(p);- } else if (p->mode != MODE_CUBE || grav_snap) {+ } else if ((p->mode != MODE_CUBE && p->mode != MODE_ROBOT) || grav_snap) {if ((grav_top(p) - o_bottom <= clip && p->vy >= 0) || grav_snap) {if (!grav_snap) p->on_ceiling = true; else p->vy = 0;p->inverse_rot = false;@@ -489,8 +807,7 @@ static void special(Game *g, unsigned i, const RObj *o, bool hold, float ox, floset_used(g, i);if (g->dual) {g->dual = false;- if (p->second) { bool sec = p->second; *p = g->p2; p->second = sec; } /* the first body goes on */- g->p2.second = true;+ if (p->second) g->dual_swap = true;if (p->mode == MODE_CUBE || p->mode == MODE_ROBOT) { p->ground_y = 0; p->ceiling_y = 999999; }else set_bounds_for_portal(g, g->dual_y, p->mode == MODE_BALL ? BALL_HEIGHT : 300);fx(g, FX_PORTAL, 7, (int)i, ox, oy);@@ -549,8 +866,11 @@ static void hit_box(const Level *L, const RObj *o, float x, float y, float *cx,}}+static SlopeSet near_slopes; /* this tick's slopes around the player */+static void collide(Game *g, const Player *old, bool hold) {Player *p = &g->p;+ near_slopes.n = 0;/* objects around the player, in level order, where their groups put them */Near near[MAX_NEAR];unsigned n = 0;@@ -561,11 +881,22 @@ static void collide(Game *g, const Player *old, bool hold) {float x, y;if (!obj_where(g, o, &x, &y) || x < p->x - 60 || x >= p->x + 60) continue;near[n++] = (Near){o, it.gi, x, y};+ if (objdefs[o->type].shape == SHAPE_SLOPE && near_slopes.n < 8) near_slopes.s[near_slopes.n++] = slope_of(g->L, o, x, y);}bool touching_orb = false;float snap_x = p->x; /* contacts are judged before any nudge */- /* GD resolves special objects, then solids, then hazards. */+ /* GD resolves special objects, then solids, then slopes, then hazards. */for (int pass = 0; pass < 3 && !g->dead; pass++) {+ if (pass == 1 && p->left_ground) sl_clear(p);+ if (pass == 2) {+ p->npot = 0;+ for (int k = 0; k < near_slopes.n && !g->dead; k++) {+ const Slope *sl = &near_slopes.s[k];+ float ph = phalf(p);+ if (overlap(p->x, p->y, ph, ph, sl->x, sl->y, sl->w / 2, sl->h / 2)) sl_collide(g, old, sl, &near_slopes, hold);+ }+ if (g->dead) break;+ }if (pass == 2 && (p->mode == MODE_CUBE || p->mode == MODE_ROBOT) && p->on_ground) {/* stair snap against every solid under the cube, in GD's order: by100 unit section, right to left then top to bottom, then newest */@@ -645,9 +976,23 @@ static void cube_mode(Game *g, bool hold, bool pressed) {else p->target_rot += spin * ND_DT * mult;}if (p->on_ground) update_rot_dir(p);- bool coyote = p->upside && hold && p->coyote < 10;- if ((p->on_ground || coyote) && hold) {- set_velocity(p, CUBE_JUMP[p->speed], g->hold_prev);+ bool coyote = (p->upside || g->dual) && hold && p->coyote < 10;+ /* the slope under the cube, or the one it just slid off */+ Slope sl;+ int so = p->sl_o >= 0 ? p->sl_o : p->co_ticks ? p->co_o : -1;+ if (so >= 0) slope_get(p->sl_o >= 0 ? p->sl : p->co, so, &sl);+ bool on_slope = so >= 0 && sl_orient(p, &sl) < OR_UDD;+ if ((on_slope || p->on_ground || coyote) && hold) {+ if (on_slope && sl_orient(p, &sl) == OR_NU) {+ /* a jump off a rising slope gets some of its speed */+ float t = clampf(10 * (p->t_elapsed - (p->sl_o >= 0 ? p->sl_t : p->co_t)), 0.4f, 1.0f);+ float v = 0.9f * fminf(1.12f / sl_angle(p, &sl), 1.54f) * (sl.h * SPEEDS[p->speed] / sl.w);+ set_velocity(p, 0.25f * t * v + CUBE_JUMP[p->speed], false);+ p->co_ticks = 0;+ p->co_o = -1;+ } else {+ set_velocity(p, CUBE_JUMP[p->speed], g->hold_prev);+ }p->inverse_rot = false;p->buffer = BUF_END;p->on_ground = false;@@ -656,7 +1001,8 @@ static void cube_mode(Game *g, bool hold, bool pressed) {if (!pressed) p->time_since_ground = DRAG_TIME;fx(g, FX_JUMP, 0, -1, p->x, p->y);}- if (p->on_ground) p->target_rot = closest_rotation(p->rot);+ if (so >= 0) p->target_rot = closest_rotation_to(p->rot, sl_snap_angle(p, &sl) / DEG);+ else if (p->on_ground) p->target_rot = closest_rotation(p->rot);}static void ship_mode(Game *g, bool hold) {@@ -733,7 +1079,7 @@ static void ball_mode(Game *g, const Player *old) {Player *p = &g->p;p->gravity = BALL_GRAV;if (p->on_ground || p->on_ceiling) p->spin = 1;- bool coyote = p->upside && p->coyote < 16;+ bool coyote = (p->upside || g->dual) && p->coyote < 16;if ((p->on_ground || p->on_ceiling || coyote) && p->buffer == BUF_READY) {p->upside = !p->upside;set_velocity(p, BALL_JUMP[p->speed], old->buffer == BUF_READY);@@ -793,9 +1139,15 @@ static void run_player(Game *g, const Player *old, bool hold, bool pressed) {p->left_ground = false;if (p->ceil_inv > 0) p->ceil_inv -= ND_DT; else p->ceil_inv = 0;clamp_ground(g);+ if (p->co_ticks && !--p->co_ticks) p->co_o = -1;+ if (p->sl_o >= 0) {+ Slope cur;+ slope_get(p->sl, p->sl_o, &cur);+ sl_calc(g, old, &cur, &near_slopes, hold);+ }if (p->mode == MODE_CUBE) {float lerp = SPEED_MULT[p->speed] * 0.175f;- if (p->on_ground) {+ if (p->on_ground || p->sl_o >= 0) {lerp *= 3;float t = fminf(ND_DT, ND_DT * lerp) * 60;p->rot = slerp_angle(p->rot * DEG, p->target_rot * DEG, t) / DEG;@@ -818,7 +1170,13 @@ static void run_player(Game *g, const Player *old, bool hold, bool pressed) {float k = 0.15f;if (p->mode == MODE_UFO) { /* the UFO only tilts a little */k = 0.07f;- ang = p->on_ground ? 0 : p->upside ? fminf(ang * -0.4f, 0.1f) : fmaxf(ang * -0.4f, -0.1f);+ if (p->sl_o >= 0) {+ Slope cur;+ slope_get(p->sl, p->sl_o, &cur);+ ang = sl_snap_angle(p, &cur);+ } else {+ ang = p->on_ground ? 0 : p->upside ? fminf(ang * -0.4f, 0.1f) : fmaxf(ang * -0.4f, -0.1f);+ }}p->rot = slerp_angle(p->rot * DEG, ang, ND_DT * 60 * k) / DEG;}@@ -925,51 +1283,83 @@ static void camera(Game *g) {if (moved > 0) { g->ground_x += moved; g->bg_x += moved; }}-void game_step(Game *g, bool hold) {- if (g->dead || g->complete) return;+/* One tick of the body held in g->p. */+static void step_body(Game *g, bool hold, bool pressed) {Player *p = &g->p;Player old = *p;- bool pressed = hold && !g->hold_prev;p->old_on_ground = p->on_ground;if (hold) { if (p->buffer == BUF_NONE) p->buffer = BUF_READY; }else p->buffer = BUF_NONE;p->on_ground = p->on_ceiling = false;p->vel_override = false;+ p->t_elapsed += ND_DT;p->x += SPEEDS[p->speed] * ND_DT;p->y += grav(p, p->vy) * ND_DT;clamp_ground(g);p->frame++;- g->tick++;+ /* what a slope left for this tick: a launch speed and letting go of it */+ if (p->has_new_vy) { p->vy = p->new_vy; p->has_new_vy = false; }+ if (p->pend_clear) { sl_clear(p); p->pend_clear = false; }if (!g->dead && !g->ending) collide(g, &old, hold);- if (!g->dead) {- const Level *L = g->L;- if (p->x >= L->wall_x - END_START) {- if (!g->ending) {- g->ending = true;- g->end_x0 = p->x;- g->end_y0 = p->y;- if (g->wall_y == 0) g->wall_y = g->end_y0 > 60 ? g->end_y0 : 60;- }- float t = clampf(powf(g->end_t, 1.2f), 0, 1), u = 1 - t;- float mx = g->end_x0 + 40, my = g->wall_y + 150, ex = L->wall_x + 50, ey = g->wall_y - 20;- p->x = u * u * u * g->end_x0 + 3 * u * u * t * g->end_x0 + 3 * u * t * t * mx + t * t * t * ex;- p->y = u * u * u * g->end_y0 + 3 * u * u * t * g->end_y0 + 3 * u * t * t * my + t * t * t * ey;- float e = g->end_t / 0.5f;- p->rot += (e > 1 ? 1 : e * e) * ROT_SPEED * ND_DT;- g->end_t += ND_DT;- if (p->x > L->wall_x && !g->complete) {- g->complete = true;- fx(g, FX_WALL, 0, -1, (float)L->wall_x, g->wall_y);- }+ if (g->dead) return;+ const Level *L = g->L;+ if (p->x >= L->wall_x - END_START && !p->second) {+ if (!g->ending) {+ g->ending = true;+ g->end_x0 = p->x;+ g->end_y0 = p->y;+ if (g->wall_y == 0) g->wall_y = g->end_y0 > 60 ? g->end_y0 : 60;+ }+ float t = clampf(powf(g->end_t, 1.2f), 0, 1), u = 1 - t;+ float mx = g->end_x0 + 40, my = g->wall_y + 150, ex = L->wall_x + 50, ey = g->wall_y - 20;+ p->x = u * u * u * g->end_x0 + 3 * u * u * t * g->end_x0 + 3 * u * t * t * mx + t * t * t * ex;+ p->y = u * u * u * g->end_y0 + 3 * u * u * t * g->end_y0 + 3 * u * t * t * my + t * t * t * ey;+ float e = g->end_t / 0.5f;+ p->rot += (e > 1 ? 1 : e * e) * ROT_SPEED * ND_DT;+ g->end_t += ND_DT;+ if (p->x > L->wall_x && !g->complete) {+ g->complete = true;+ fx(g, FX_WALL, 0, -1, (float)L->wall_x, g->wall_y);+ }+ }+ run_player(g, &old, hold, pressed);+ p->delta_y = p->y - old.y;+}++/* The ship and the UFO read the button one tick later than the other modes+ (GD's tick order, measured by gdsolver). */+static bool reads_late(const Player *p) { (void)p; return false; }++void game_step(Game *g, bool hold) {+ if (g->dead || g->complete) return;+ bool pressed = hold && !g->hold_prev, pressed_late = g->hold_prev && !g->hold_prev2;+ float x0 = g->p.x;+ g->tick++;+ bool late = reads_late(&g->p);+ step_body(g, late ? g->hold_prev : hold, late ? pressed_late : pressed);+ if (g->dual && !g->dead && !g->complete) {+ Player t = g->p;+ g->p = g->p2;+ g->p2 = t;+ late = reads_late(&g->p);+ step_body(g, late ? g->hold_prev : hold, late ? pressed_late : pressed);+ if (g->dual_swap) {+ /* the second body left dual mode first: it goes on alone */+ g->dual_swap = false;+ g->p.second = false;+ } else {+ t = g->p;+ g->p = g->p2;+ g->p2 = t;}- run_player(g, &old, hold, pressed);}+ g->hold_prev2 = g->hold_prev;g->hold_prev = hold;g->pressed_prev = pressed;if (!g->dead) {camera(g);triggers(g);- trig_step(g, p->x - old.x);+ trig_step(g, g->p.x - x0);}}diff --git a/games/numdash/src/game.h b/games/numdash/src/game.hindex aba7681c..f19be6a8 100644--- a/games/numdash/src/game.h+++ b/games/numdash/src/game.h@@ -26,6 +26,13 @@ typedef struct {bool second; /* the dual mode's second body */bool old_on_ground, orb_touching;uint8_t hover; /* robot: hover ticks left while the button stays held */+ /* slopes (as gd3ds): the slope ridden, the one just left (coyote) and the+ ones touched last tick; orientation -1 = none */+ float sl[4], sl_t, co[4], co_t, pot[4][2];+ int8_t sl_o, co_o, pot_o[4];+ uint8_t co_ticks, npot;+ bool sl_down, co_down, pend_clear, has_new_vy;+ float t_elapsed, new_vy, delta_y;} Player;/* A colour channel: an RGB fade (t, dur in steps) plus, for 2.0+ levels,@@ -64,7 +71,7 @@ typedef struct {PulseAction pu[MAX_PULSES];uint8_t nmv, npu, touch_bits[16];uint8_t fade_effect, coins, attempt_camera, touch_done[8];- bool trail, dead, complete, ending, hold_prev, pressed_prev, dual;+ bool trail, dead, complete, ending, hold_prev, hold_prev2, pressed_prev, dual, dual_swap;float dual_y;bool menu_camera; /* fixed camera, ground scrolling on its own (main menu) */float used_below; /* objects left of this x count as used (practice) */diff --git a/games/numdash/src/objdefs.h b/games/numdash/src/objdefs.hindex 8c9713f8..cfa7ca26 100644--- a/games/numdash/src/objdefs.h+++ b/games/numdash/src/objdefs.h@@ -130,12 +130,13 @@ enum { HIT_NONE, HIT_SOLID, HIT_HAZARD, HIT_SPECIAL };enum { SHAPE_BOX, SHAPE_CIRCLE, SHAPE_SLOPE };enum { SP_NONE, SP_PAD_Y, SP_PAD_P, SP_PAD_B, SP_ORB_Y, SP_ORB_P, SP_ORB_B, SP_GRAV_N, SP_GRAV_F, SP_PORTAL_CUBE, SP_PORTAL_SHIP, SP_COIN, SP_PORTAL_BALL, SP_PORTAL_UFO, SP_SIZE_MINI, SP_SIZE_NORMAL, SP_PORTAL_WAVE, SP_PORTAL_ROBOT, SP_SPEED_0, SP_SPEED_1, SP_SPEED_2, SP_SPEED_3, SP_DUAL_ON, SP_DUAL_OFF, SP_TELEPORT, SP_ORB_G, SP_KEY, SP_TOUCH };enum { CT_OBJ, CT_BLACK, CT_WHITE, CT_P1ADD, CT_P2ADD, CT_LBG, CT_GLOW, CT_GLOW_Y, CT_GLOW_B, CT_GLOW_P, CT_BASE, CT_DETAIL };-enum { LAYER_B4, LAYER_DECO_BACK, LAYER_RODS, LAYER_ROD_BALLS, LAYER_DETAIL, LAYER_SPECIAL_GLOW, LAYER_SPECIAL, LAYER_PORTAL_BACK, LAYER_BLOCK_GLOW, LAYER_PLAYER, LAYER_COIN, LAYER_PORTAL_FRONT, LAYER_FILL, LAYER_BLOCK, LAYER_T2, LAYER_COUNT };+enum { LAYER_B4, LAYER_DECO_BACK, LAYER_RODS, LAYER_ROD_BALLS, LAYER_DETAIL, LAYER_SPECIAL_GLOW, LAYER_SPECIAL, LAYER_PORTAL_BACK, LAYER_BLOCK_GLOW, LAYER_PLAYER, LAYER_COIN, LAYER_PORTAL_FRONT, LAYER_FILL, LAYER_BLOCK, LAYER_T2, LAYER_T3, LAYER_COUNT };enum { PF_PULSE = 1, PF_RANDOM3 = 2, PF_COIN = 4, PF_ANIM = 8, PF_QUAD = 16, PF_HALF = 32 };enum { ANIM_NONE = 0, ANIM_SAW = 1, ANIM_SPIN = 2, ANIM_INVIS = 3 };/* Tile programs: ops of {op, x0, y0, x1, y1, colour type, alpha[, bottom alpha]} in half units- (2 units with TOP_BIG), y up; rectangle, or rectangle with a vertical alpha ramp. */-enum { TOP_END, TOP_RECT, TOP_VGRAD, TOP_BIG = 0x80 };+ (2 units with TOP_BIG), y up: rectangle, or one with a vertical alpha ramp; or+ {TOP_POLY, n, n x (x, y), colour type, alpha}, a convex polygon. */+enum { TOP_END, TOP_RECT, TOP_VGRAD, TOP_POLY, TOP_BIG = 0x80 };extern const uint8_t tile_prog_data[];extern const uint16_t tile_prog_off[];enum { EV_COLOR = 1, EV_FADE = 2, EV_TRAIL = 3 };diff --git a/games/numdash/src/scene.c b/games/numdash/src/scene.cindex 87cf2c56..98ae1943 100644--- a/games/numdash/src/scene.c+++ b/games/numdash/src/scene.c@@ -87,16 +87,28 @@ typedef struct {uint16_t spr; /* sprite, or tile program (K_PROG) */uint16_t scale; /* 256 = 1 */int16_t angle; /* extra clockwise rotation, 1/16 degree */- uint8_t xf, ct, alpha, layer, kind, pad;+ uint8_t xf;+ uint8_t ct, detail; /* palette entries: the colour (a program's base colour) and a program's detail colour */+ uint8_t alpha, layer, kind;} Item;/* sprite at a whole pixel; rotated / scaled sprite; four mirrored quarters- of a round object; a block drawn from rectangles; the player */-enum { K_SPRITE, K_SCALED, K_QUAD, K_PROG, K_PLAYER };+ of a round object; a block drawn from rectangles; the player. K_ADD:+ blend additively whatever the colour's own blending. */+enum { K_SPRITE, K_SCALED, K_QUAD, K_PROG, K_PLAYER, K_ADD = 0x80 };++/* Colours of the frame: one entry per colour channel of the level (copies,+ HSV, player colours and pulses resolved), then a few made per object+ (lighter shades, group pulses) and the fixed portal glows. */+typedef struct { color_t c; uint8_t a, add; } Pal;+enum { PAL_DYN = 224, PAL_DYN_END = 247, PAL_RAIN = 247, PAL_GLOW_Y = 253, PAL_GLOW_B = 254, PAL_GLOW_P = 255 };+enum { DYN_LIGHT, DYN_DARK, DYN_PULSE };+static Pal pal[256];+static uint16_t dyn_key[PAL_DYN_END - PAL_DYN];+static int ndyn;#define MAX_ITEMS 1100static Item items[MAX_ITEMS];static uint16_t order[MAX_ITEMS];static int nitems;-static color_t tint_obj, tint_p1, tint_p2, tint_lbg;static const Game *G;static SceneOpts O;static float player_sx, player_sy;@@ -116,10 +128,120 @@ static int fade_at(const Level *L, float x) {return eff;}-static void push(float sx, float sy, int spr, int xf, int ct, int alpha, int layer, int kind, int scale, int angle16) {+static void push(float sx, float sy, int spr, int xf, int ct, int detail, int alpha, int layer, int kind, int scale, int angle16) {if (nitems >= MAX_ITEMS || spr < 0 || sx < -2000 || sx > 2000 || sy < -2000 || sy > 2000) return;items[nitems++] = (Item){(int16_t)floorf(sx * 4 + .5f), (int16_t)floorf(sy * 4 + .5f), (uint16_t)spr, (uint16_t)scale, (int16_t)angle16,- (uint8_t)xf, (uint8_t)ct, (uint8_t)(alpha > 255 ? 255 : alpha), (uint8_t)layer, (uint8_t)kind, 0};+ (uint8_t)xf, (uint8_t)ct, (uint8_t)detail, (uint8_t)(alpha > 255 ? 255 : alpha), (uint8_t)layer, (uint8_t)kind};+}++/* ------------------------------------------------------------ palette */++static color_t c3(const uint8_t v[3]) { return rgb(v[0], v[1], v[2]); }+static uint8_t chan_done[MAX_CHANNELS];+static uint8_t chan_rgb[MAX_CHANNELS][3];++static void pulse_rgb(const PulseAction *pu, uint8_t out[3]);+/* A channel's colour: its own, a player colour, or a copy of another with+ HSV, then any pulses on it. */+static const uint8_t *chan_eval(const Game *g, unsigned c, int depth) {+ uint8_t *out = chan_rgb[c];+ if (chan_done[c]) return out;+ const Channel *ch = &g->ch[c];+ memcpy(out, ch->cur, 3);+ if ((ch->flags & CHF_COPY) && ch->copy < MAX_CHANNELS && depth < 4 && ch->copy != c)+ hsv_shift(chan_eval(g, ch->copy, depth + 1), ch->h, ch->s, ch->v, ch->flags, out);+ else if (ch->flags & (CHF_P1 | CHF_P2)) {+ color_t pc = (ch->flags & CHF_P1) ? O.p1 : O.p2;+ out[0] = (uint8_t)c_r(pc); out[1] = (uint8_t)c_g(pc); out[2] = (uint8_t)c_b(pc);+ }+ for (unsigned k = 0; k < g->npu; k++) {+ const PulseAction *pu = &g->pu[k];+ if ((pu->flags & 1) || pu->target != c) continue;+ uint8_t prgb[3];+ pulse_rgb(pu, prgb);+ float lv = pulse_level(pu);+ for (int j = 0; j < 3; j++) out[j] = (uint8_t)(out[j] + (prgb[j] - out[j]) * lv);+ }+ chan_done[c] = 1;+ return out;+}+static const Game *pal_game;+static void pulse_rgb(const PulseAction *pu, uint8_t out[3]) {+ if ((pu->flags & CHF_COPY) && pu->copy < MAX_CHANNELS) hsv_shift(chan_eval(pal_game, pu->copy, 2), pu->h, pu->s, pu->v, pu->flags, out);+ else memcpy(out, pu->rgb, 3);+}++static void build_palette(const Game *g) {+ const LevelExt *x = g->L->ext;+ pal_game = g;+ unsigned n = x ? x->nchans : CH_SPECIAL;+ if (n > MAX_CHANNELS) n = MAX_CHANNELS;+ memset(chan_done, 0, sizeof(chan_done));+ for (unsigned c = 0; c < n; c++) {+ const Channel *ch = &g->ch[c];+ pal[c] = (Pal){c3(chan_eval(g, c, 0)), x ? ch->op : 255, x ? (ch->flags & CHF_BLEND) != 0 : 0};+ }+ /* the fixed ones */+ pal[CH_P1] = (Pal){x && (g->ch[CH_P1].flags & CHF_COPY) ? pal[CH_P1].c : O.p1, 255, 1};+ pal[CH_P2] = (Pal){x && (g->ch[CH_P2].flags & CHF_COPY) ? pal[CH_P2].c : O.p2, 255, 1};+ pal[CH_LBG] = (Pal){c_hsv_lighten(pal[CH_BG].c, -20, 20), 255, 0};+ if (!x) { pal[CH_3DL] = pal[CH_OBJ]; pal[CH_G2] = pal[CH_G1]; }+ pal[CH_BLACK] = (Pal){0, 255, 0};+ pal[CH_WHITE] = (Pal){0xffff, 255, 0};+ pal[CH_LIGHTER] = (Pal){0xffff, 255, 0};+ pal[PAL_GLOW_Y] = (Pal){rgb(255, 255, 0), 255, 1};+ pal[PAL_GLOW_B] = (Pal){rgb(0, 255, 255), 255, 1};+ pal[PAL_GLOW_P] = (Pal){rgb(255, 0, 255), 255, 1};+ static const uint8_t rain[6][3] = {{255, 30, 30}, {255, 150, 0}, {255, 240, 0}, {40, 230, 40}, {30, 120, 255}, {170, 40, 255}};+ for (int k = 0; k < 6; k++) pal[PAL_RAIN + k] = (Pal){c3(rain[k]), 255, 0};+ ndyn = 0;+}++/* A per-frame colour made from entry `base`: a lighter or darker shade, or+ group pulse k over it (DYN_PULSE + k). Falls back to base when the slots+ run out. */+static int pal_dyn(const Game *g, int base, int kind) {+ uint16_t key = (uint16_t)(base | kind << 8);+ for (int k = 0; k < ndyn; k++) if (dyn_key[k] == key) return PAL_DYN + k;+ if (ndyn >= PAL_DYN_END - PAL_DYN) return base;+ Pal e = pal[base];+ if (kind == DYN_LIGHT) {+ e.c = c_mix(e.c, 0xffff, 110);+ } else if (kind == DYN_DARK) {+ e.c = c_scale(e.c, 150);+ } else {+ const PulseAction *pu = &g->pu[kind - DYN_PULSE];+ uint8_t prgb[3];+ pulse_rgb(pu, prgb);+ e.c = c_mix(e.c, c3(prgb), (unsigned)(pulse_level(pu) * 256));+ }+ dyn_key[ndyn] = key;+ pal[PAL_DYN + ndyn] = e;+ return PAL_DYN + ndyn++;+}++/* The palette entry of a part's colour type for an object whose base and+ detail entries are given (legacy colour types keep their fixed colours+ unless the object is painted). */+static int part_pal(int ct, int base, int detail, bool painted) {+ if (ct >= CT_RAIN0 && ct <= CT_RAIN5) return PAL_RAIN + ct - CT_RAIN0;+ switch (ct) {+ case CT_BASE_D: return pal_dyn(G, base, DYN_DARK);+ case CT_BASE_L: return pal_dyn(G, base, DYN_LIGHT);+ case CT_DETAIL_D: return pal_dyn(G, detail, DYN_DARK);+ case CT_BLACK: return CH_BLACK;+ case CT_WHITE: return CH_WHITE;+ case CT_GLOW_Y: return PAL_GLOW_Y;+ case CT_GLOW_B: return PAL_GLOW_B;+ case CT_GLOW_P: return PAL_GLOW_P;+ case CT_DETAIL: return detail;+ case CT_BASE: return base;+ case CT_OBJ: case CT_GLOW: return painted ? base : CH_OBJ;+ case CT_P1ADD: return painted ? base : CH_P1;+ case CT_P2ADD: return painted ? base : CH_P2;+ case CT_LBG: return painted ? base : CH_LBG;+ default: return CH_WHITE;+ }}static float pulse_amount(void) {@@ -149,31 +271,49 @@ void scene_prepare(const Game *g, const SceneOpts *o) {bg_col = scene_channel(g, CH_BG);g1_col = scene_channel(g, CH_G1);line_col = scene_channel(g, CH_LINE);- tint_obj = scene_channel(g, CH_OBJ);- tint_lbg = c_hsv_lighten(bg_col, -20, 20);- tint_p1 = o->p1;- tint_p2 = o->p2;float cam_x = g->cam_x;float pulse = pulse_amount();unsigned coin_frame = (unsigned)(o->time * 8) & 3;+ build_palette(g);+ const LevelExt *X = L->ext;+ /* z layer buckets of 2.0 objects (0 = the part's own layer) */+ static const uint8_t ZMAP[9] = {0, LAYER_B4, LAYER_DECO_BACK, LAYER_RODS, LAYER_DETAIL, LAYER_BLOCK, LAYER_T2, LAYER_T3, LAYER_T3};LIter it;level_iter(L, cam_x - 90, cam_x + VIEW_W + 90, &it);for (const RObj *ob; (ob = level_next(&it));) {unsigned i = it.gi;+ const ObjDef *d = &objdefs[ob->type];+ const LStyle *st = obj_style(L, ob);float obx = obj_x(ob), oby = obj_y(ob);+ unsigned galpha = 255;+ int gpulse = -1;+ if (st->groups) {+ float dx, dy;+ bool on;+ gset_state(g, st->groups, &dx, &dy, &galpha, &on);+ if (!on || !galpha) continue;+ obx += dx;+ oby += dy;+ for (unsigned k = 0; k < g->npu && gpulse < 0; k++) {+ const PulseAction *pu = &g->pu[k];+ if (!(pu->flags & 1)) continue;+ const uint16_t *set = X->gsets + st->groups;+ for (unsigned j = 1; j <= set[0]; j++) if (set[j] == pu->target) { gpulse = (int)k; break; }+ }+ }+ if ((st->flags & STF_HIDE) && !o->editor) continue;if (obx < cam_x - 90 || obx >= cam_x + VIEW_W + 90) continue;- const ObjDef *d = &objdefs[ob->type];- if (d->special == SP_COIN && game_used(g, ob, i)) continue;+ if ((d->special == SP_COIN || d->special == SP_KEY) && game_used(g, ob, i)) continue;if (o->low_detail && d->hit == HIT_NONE && !o->editor) continue;int xf = obj_xf(ob);float angle = 0; /* degrees on top of the quarter turns in xf */if (xf < 0) { angle = obj_rot(ob) * (360.f / 1024); xf = (int)(obj_flips(ob) << 2); }float rel = obx - cam_x;- float fade = o->editor ? 1 : rel < 0 || rel > VIEW_W ? 0 : rel < FADE_W ? rel / FADE_W : rel > VIEW_W - FADE_W ? (VIEW_W - rel) / FADE_W : 1;+ float fade = o->editor || (st->flags & STF_DONT_FADE) ? 1 : rel < 0 || rel > VIEW_W ? 0 : rel < FADE_W ? rel / FADE_W : rel > VIEW_W - FADE_W ? (VIEW_W - rel) / FADE_W : 1;if (fade <= 0) continue;float offx = 0, offy = 0, sc = 1;- if (fade < 1) {- int eff = fade_at(L, rel < VIEW_W / 2 ? obx + 75 : obx - (VIEW_W - PLAYER_SCREEN_X) + 75);+ if (fade < 1 && !(st->flags & STF_DONT_ENTER)) {+ int eff = X ? g->fade_effect : fade_at(L, rel < VIEW_W / 2 ? obx + 75 : obx - (VIEW_W - PLAYER_SCREEN_X) + 75);float off = (1 - fade) * 127.5f;bool high = oby - g->cam_y > VIEW_H / 2 - GROUND_OFFSET;switch (eff) {@@ -190,8 +330,11 @@ void scene_prepare(const Game *g, const SceneOpts *o) {default: break;}}+ float oscx = 1, oscy = 1;+ obj_scale_xy(L, ob, &oscx, &oscy);+ float osc = fabsf(oscx) > fabsf(oscy) ? fabsf(oscx) : fabsf(oscy);float wx = obx + offx, wy = oby + offy;- int alpha = (int)(fade * 255 + .5f);+ int alpha = (int)(fade * galpha + .5f);if (d->special == SP_COIN && (o->coins_saved >> game_coin_index(L, i) & 1)) alpha = alpha * 2 / 5;if (d->anim == ANIM_SAW || d->anim == ANIM_SPIN)angle += (d->anim == ANIM_SAW ? 360.f : 180.f) * o->time * ((i * 2654435761u >> 16 & 1) ? -1 : 1);@@ -201,32 +344,52 @@ void scene_prepare(const Game *g, const SceneOpts *o) {alpha = (int)(alpha * fmaxf(0, fminf(1, (210 - dist) / 90)) * 0.7f);if (alpha <= 0) continue;}+ /* colours: the object's own channels, or its paint */+ bool painted = st->main != 255;+ int base = painted ? st->main : d->dbase, detail = st->detail != 255 ? st->detail : d->ddetail;+ if (base == CH_LIGHTER) base = pal_dyn(g, CH_OBJ, DYN_LIGHT);+ if (detail == CH_LIGHTER) detail = pal_dyn(g, base, DYN_LIGHT);+ if (gpulse >= 0) {+ const PulseAction *pu = &g->pu[gpulse];+ if (!(pu->flags & 4)) base = pal_dyn(g, base, DYN_PULSE + gpulse);+ if (!(pu->flags & 2)) detail = pal_dyn(g, detail, DYN_PULSE + gpulse);+ }for (int k = 0; k < d->nparts; k++) {const ObjPart *pt = OBJ_PART(d, k);- if (o->low_detail && pt->ctype >= CT_GLOW) continue;+ if (o->low_detail && pt->ctype >= CT_GLOW && pt->ctype <= CT_GLOW_P) continue;int spr = pt->sprite;if (pt->flags & PF_RANDOM3) spr += (int)(i % 3);if (pt->flags & PF_COIN) spr += (int)coin_frame;float ox, oy;- part_offset(xf, pt->dx4 / 4.f * sc, pt->dy4 / 4.f * sc, &ox, &oy);+ part_offset(xf, pt->dx4 / 4.f * sc * osc, pt->dy4 / 4.f * sc * osc, &ox, &oy);if (angle != 0 && (ox != 0 || oy != 0)) {float r = -angle * 3.14159265f / 180.f, c = cosf(r), s = sinf(r), t = ox * c - oy * s;oy = ox * s + oy * c;ox = t;}float sx = (wx + ox - cam_x) * PX, sy = 240 - (GROUND_OFFSET + wy + oy - g->cam_y) * PX;- int psc = (int)(sc * 256);+ int psc = (int)(sc * osc * 256);if (pt->flags & PF_PULSE) psc = (int)(psc * (1 + 0.22f * pulse));if (pt->flags & PF_HALF) psc *= 2;int a16 = (int)(angle * 16);int kind = pt->prog ? K_PROG : (pt->flags & PF_QUAD) ? K_QUAD : (psc != 256 || a16) ? K_SCALED : K_SPRITE;- push(sx, sy, pt->prog ? pt->prog : spr, xf, pt->ctype, alpha, pt->layer, kind, psc, a16);+ int ct = pt->prog ? base : part_pal(pt->ctype, base, detail, painted);+ if (pt->ctype == CT_GLOW) kind |= K_ADD;+ int layer = pt->layer;+ if (st->zlayer) {+ bool glow = layer == LAYER_BLOCK_GLOW || layer == LAYER_SPECIAL_GLOW;+ layer = ZMAP[st->zlayer];+ if (glow && layer > 0) layer--;+ }+ int a = alpha * pal[ct].a / 255;+ if (a <= 0 && !pt->prog) continue;+ push(sx, sy, pt->prog ? pt->prog : spr, xf, ct, detail, pt->prog ? alpha : a, layer, kind, psc, a16);}}/* the player */player_sx = wx_to_sx(g, g->p.x);player_sy = wy_to_sy(g, g->p.y);- if (!g->dead && !o->hide_player) push(0, 0, 0, 0, 0, 255, LAYER_PLAYER, K_PLAYER, 256, 0);+ if (!g->dead && !o->hide_player) push(0, 0, 0, 0, 0, 0, 255, LAYER_PLAYER, K_PLAYER, 256, 0);/* sort by layer, stable */uint16_t count[LAYER_COUNT + 1] = {0};for (int k = 0; k < nitems; k++) count[items[k].layer + 1]++;@@ -239,20 +402,11 @@ void scene_prepare(const Game *g, const SceneOpts *o) {ceil_bottom = (int)floorf(g->ground_gfx * PX + .5f);}-static void tint_for(int ct, color_t *c, int *mode) {- *mode = BLEND_NORMAL;- switch (ct) {- case CT_OBJ: *c = tint_obj; break;- case CT_BLACK: *c = 0; break;- case CT_WHITE: *c = 0xffff; break;- case CT_P1ADD: *c = tint_p1; *mode = BLEND_ADD; break;- case CT_P2ADD: *c = tint_p2; *mode = BLEND_ADD; break;- case CT_LBG: *c = tint_lbg; break;- case CT_GLOW: *c = tint_obj; *mode = BLEND_ADD; break;- case CT_GLOW_Y: *c = rgb(255, 255, 0); *mode = BLEND_ADD; break;- case CT_GLOW_B: *c = rgb(0, 255, 255); *mode = BLEND_ADD; break;- default: *c = rgb(255, 0, 255); *mode = BLEND_ADD; break;- }+/* Colour of a palette entry. */+static void pal_for(int e, bool add, color_t *c, int *mode, unsigned *alpha) {+ *c = pal[e].c;+ *mode = add || pal[e].add ? BLEND_ADD : BLEND_NORMAL;+ *alpha = pal[e].a;}void scene_draw_player_icon(int mode, float cx, float cy, float rot, float scale, color_t p1, color_t p2, bool upside, unsigned alpha) {@@ -281,45 +435,74 @@ void scene_draw_player_icon(int mode, float cx, float cy, float rot, float scalegfx_sprite_ex(ball ? SPR_BALL1_P : SPR_CUBE1_P, x16, y16, a16, (int)(256 * scale), 0, p1, alpha, BLEND_NORMAL);}-/* Tile program: rectangles in half units around the item's anchor, turned- and flipped like the object (quarter turns keep them axis aligned). */+/* Tile program: rectangles, alpha ramps and convex polygons in half units+ around the item's anchor (2 units with TOP_BIG), y up, turned, flipped and+ scaled like the object. Colour types BASE and DETAIL are the object's. */static void draw_prog(const Item *it) {const uint8_t *p = tile_prog_data + tile_prog_off[it->spr];float cx = it->x * 0.25f, cy = it->y * 0.25f, s = PX * 0.5f * it->scale / 256;if (cy + 60 * s * 2 < gfx_y0 || cy - 60 * s * 2 > gfx_y1) return;+ float a = ((it->xf & 3) * 90 + it->angle / 16.f) * (3.14159265f / 180), ca = cosf(a), sa = sinf(a);+ if (fabsf(ca) < 1e-4f) ca = 0;+ if (fabsf(sa) < 1e-4f) sa = 0;+ float fx = (it->xf & XF_FLIPX) ? -s : s, fy = (it->xf & XF_FLIPY) ? -s : s;+ /* screen = centre + M * local (clockwise turn, y up locally, y down on screen) */+ float m00 = ca * fx, m01 = sa * fy, m10 = sa * fx, m11 = -ca * fy;+ bool aligned = ca == 0 || sa == 0;+ bool add = (it->kind & K_ADD) != 0;while (*p) {int op = p[0] & 0x7f;float k4 = (p[0] & TOP_BIG) ? 4 : 1;- float q[4] = {(int8_t)p[1] * k4, (int8_t)p[2] * k4, (int8_t)p[3] * k4, (int8_t)p[4] * k4};- int ct = p[5];- unsigned a0 = p[6], a1 = op == TOP_VGRAD ? p[7] : a0;- p += op == TOP_VGRAD ? 8 : 7;- /* corners after the object's flips and quarter turns (y up) */- float xs[2], ys[2];- for (int k = 0; k < 2; k++) {- float x = q[k * 2], y = q[k * 2 + 1];- part_offset(it->xf, x, y, &xs[k], &ys[k]);+ int ct, n = 4;+ unsigned a0, a1;+ float q[16];+ if (op == TOP_POLY) {+ n = p[1];+ for (int k = 0; k < n * 2; k++) q[k] = (int8_t)p[2 + k] * k4;+ p += 2 + n * 2;+ ct = p[0];+ a0 = a1 = p[1];+ p += 2;+ } else {+ for (int k = 0; k < 4; k++) q[k] = (int8_t)p[1 + k] * k4;+ ct = p[5];+ a0 = p[6];+ a1 = op == TOP_VGRAD ? p[7] : a0;+ p += op == TOP_VGRAD ? 8 : 7;}- float x0 = cx + fminf(xs[0], xs[1]) * s, x1 = cx + fmaxf(xs[0], xs[1]) * s;- float y0 = cy - fmaxf(ys[0], ys[1]) * s, y1 = cy - fminf(ys[0], ys[1]) * s;+ int e = part_pal(ct, it->ct, it->detail, true);+ if (ct == CT_OBJ || ct == CT_P1ADD || ct == CT_P2ADD || ct == CT_LBG) e = it->ct;color_t c;int mode;- tint_for(ct, &c, &mode);- unsigned al = it->alpha + 1;- if (a0 == a1) {- gfx_rectf(x0, y0, x1, y1, c, a0 * al >> 8, mode);- } else {- /* where did the top edge go: split into bands along that axis */- float tx, ty;- part_offset(it->xf, 0, 1, &tx, &ty);- const int bands = 6;- for (int b = 0; b < bands; b++) {- float f0 = (float)b / bands, f1 = (float)(b + 1) / bands;- unsigned a = (unsigned)(a0 + ((int)a1 - (int)a0) * (b + .5f) / bands) * al >> 8;- if (ty > .5f) gfx_rectf(x0, y0 + (y1 - y0) * f0, x1, y0 + (y1 - y0) * f1, c, a, mode);- else if (ty < -.5f) gfx_rectf(x0, y1 - (y1 - y0) * f1, x1, y1 - (y1 - y0) * f0, c, a, mode);- else if (tx > .5f) gfx_rectf(x1 - (x1 - x0) * f1, y0, x1 - (x1 - x0) * f0, y1, c, a, mode);- else gfx_rectf(x0 + (x1 - x0) * f0, y0, x0 + (x1 - x0) * f1, y1, c, a, mode);+ unsigned pa;+ pal_for(e, add || ct == CT_GLOW, &c, &mode, &pa);+ unsigned al = (it->alpha + 1) * pa / 255;+ if (!al) continue;+ if (op == TOP_POLY) {+ float xy[16];+ for (int k = 0; k < n; k++) {+ xy[2 * k] = cx + m00 * q[2 * k] + m01 * q[2 * k + 1];+ xy[2 * k + 1] = cy + m10 * q[2 * k] + m11 * q[2 * k + 1];+ }+ gfx_poly(xy, n, c, a0 * al >> 8, mode);+ continue;+ }+ int bands = a0 == a1 ? 1 : 6;+ for (int b = 0; b < bands; b++) {+ /* band b of the rectangle along its local y (top first) */+ float yt = q[3] + (q[1] - q[3]) * b / bands, yb = q[3] + (q[1] - q[3]) * (b + 1) / bands;+ unsigned ab = bands == 1 ? a0 : (unsigned)(a0 + ((int)a1 - (int)a0) * (b + .5f) / bands);+ float lx[4] = {q[0], q[2], q[2], q[0]}, ly[4] = {yt, yt, yb, yb}, xy[8];+ for (int k = 0; k < 4; k++) {+ xy[2 * k] = cx + m00 * lx[k] + m01 * ly[k];+ xy[2 * k + 1] = cy + m10 * lx[k] + m11 * ly[k];+ }+ if (aligned) {+ float x0 = fminf(fminf(xy[0], xy[2]), xy[4]), x1 = fmaxf(fmaxf(xy[0], xy[2]), xy[4]);+ float y0 = fminf(fminf(xy[1], xy[3]), xy[5]), y1 = fmaxf(fmaxf(xy[1], xy[3]), xy[5]);+ gfx_rectf(x0, y0, x1, y1, c, ab * al >> 8, mode);+ } else {+ gfx_poly(xy, 4, c, ab * al >> 8, mode);}}}@@ -338,7 +521,7 @@ static void draw_end_wall(void) {float oy = fmodf(G->cam_y, 30);for (float wy = -30; wy < VIEW_H + 60; wy += 30) {int y = (int)floorf(240 - (wy - oy + 15) * PX + .5f);- gfx_sprite(SPR_GRID_T, x, y, 3, tint_obj, 255, BLEND_NORMAL);+ gfx_sprite(SPR_GRID_T, x, y, 3, pal[CH_OBJ].c, 255, BLEND_NORMAL);}gfx_hgrad_alpha(x - 26, 0, 20, GFX_H, O.p1, 0, 170, BLEND_ADD);}@@ -412,22 +595,24 @@ void scene_draw(void) {if (O.editor) draw_grid();for (int k = 0; k < nitems; k++) {const Item *it = &items[order[k]];- if (it->kind == K_PLAYER) { draw_player(); continue; }- if (it->kind == K_PROG) { draw_prog(it); continue; }+ int kind = it->kind & 0x7f;+ if (kind == K_PLAYER) { draw_player(); continue; }+ if (kind == K_PROG) { draw_prog(it); continue; }const Sprite *s = sprite_def(it->spr);int ext = (s->w > s->h ? s->w : s->h) * (it->scale > 256 ? it->scale : 256) / 256 + 2;- if (it->kind == K_QUAD) ext *= 2;+ if (kind == K_QUAD) ext *= 2;int y = it->y >> 2;if (y + ext < gfx_y0 || y - ext > gfx_y1) continue;color_t c;int mode;- tint_for(it->ct, &c, &mode);- if (it->kind == K_SPRITE) {+ unsigned pa;+ pal_for(it->ct, (it->kind & K_ADD) != 0, &c, &mode, &pa);+ if (kind == K_SPRITE) {gfx_sprite(it->spr, (it->x + 2) >> 2, (it->y + 2) >> 2, it->xf, c, it->alpha + 1, mode);continue;}int a16 = (it->xf & 3) * 90 * 16 + it->angle, fl = it->xf & (XF_FLIPX | XF_FLIPY);- if (it->kind == K_SCALED) {+ if (kind == K_SCALED) {/* 90 degree transforms are expressed as rotation + flips for the bilinear path */gfx_sprite_ex(it->spr, it->x * 4, it->y * 4, a16, it->scale, fl, c, it->alpha + 1, mode);} else {diff --git a/games/numdash/tools/levels.py b/games/numdash/tools/levels.pyindex b60bb1cc..cde7d958 100644--- a/games/numdash/tools/levels.py+++ b/games/numdash/tools/levels.py@@ -592,8 +592,9 @@ def emit_objdefs():h.append('enum { PF_PULSE = 1, PF_RANDOM3 = 2, PF_COIN = 4, PF_ANIM = 8, PF_QUAD = 16, PF_HALF = 32 };')h.append('enum { ' + ', '.join('ANIM_%s = %d' % kv for kv in sorted(od.ANIM.items(), key=lambda kv: kv[1])) + ' };')h.append('/* Tile programs: ops of {op, x0, y0, x1, y1, colour type, alpha[, bottom alpha]} in half units')- h.append(' (2 units with TOP_BIG), y up; rectangle, or rectangle with a vertical alpha ramp. */')- h.append('enum { TOP_END, TOP_RECT, TOP_VGRAD, TOP_BIG = 0x80 };')+ h.append(' (2 units with TOP_BIG), y up: rectangle, or one with a vertical alpha ramp; or')+ h.append(' {TOP_POLY, n, n x (x, y), colour type, alpha}, a convex polygon. */')+ h.append('enum { TOP_END, TOP_RECT, TOP_VGRAD, TOP_POLY, TOP_BIG = 0x80 };')h.append('extern const uint8_t tile_prog_data[];')h.append('extern const uint16_t tile_prog_off[];')h.append('enum { EV_COLOR = 1, EV_FADE = 2, EV_TRAIL = 3 };')diff --git a/games/numdash/tools/objdefs.py b/games/numdash/tools/objdefs.pyindex 2a429d70..7464e1cc 100644--- a/games/numdash/tools/objdefs.py+++ b/games/numdash/tools/objdefs.py@@ -14,10 +14,11 @@ SP = ['NONE', 'PAD_Y', 'PAD_P', 'PAD_B', 'ORB_Y', 'ORB_P', 'ORB_B', 'GRAV_N', 'G'PORTAL_WAVE', 'PORTAL_ROBOT', 'SPEED_0', 'SPEED_1', 'SPEED_2', 'SPEED_3', 'DUAL_ON', 'DUAL_OFF','TELEPORT', 'ORB_G', 'KEY', 'TOUCH']# Colour types for draw parts-CT = ['OBJ', 'BLACK', 'WHITE', 'P1ADD', 'P2ADD', 'LBG', 'GLOW', 'GLOW_Y', 'GLOW_B', 'GLOW_P', 'BASE', 'DETAIL']+CT = ['OBJ', 'BLACK', 'WHITE', 'P1ADD', 'P2ADD', 'LBG', 'GLOW', 'GLOW_Y', 'GLOW_B', 'GLOW_P', 'BASE', 'DETAIL', 'BASE_D',+ 'BASE_L', 'DETAIL_D', 'RAIN0', 'RAIN1', 'RAIN2', 'RAIN3', 'RAIN4', 'RAIN5']# Layer ranks (drawing order); the player is drawn at LAYER_PLAYER.LAYERS = ['B4', 'DECO_BACK', 'RODS', 'ROD_BALLS', 'DETAIL', 'SPECIAL_GLOW', 'SPECIAL', 'PORTAL_BACK',- 'BLOCK_GLOW', 'PLAYER', 'COIN', 'PORTAL_FRONT', 'FILL', 'BLOCK', 'T2']+ 'BLOCK_GLOW', 'PLAYER', 'COIN', 'PORTAL_FRONT', 'FILL', 'BLOCK', 'T2', 'T3']# Object animations (ObjDef.anim)ANIM = {'NONE': 0, 'SAW': 1, 'SPIN': 2, 'INVIS': 3}# Part flags@@ -208,10 +209,29 @@ def edges(letters, w=2, h=15):return out+def P(pts, ct='OBJ', a=1.0):+ """Convex polygon (units, y up)."""+ return ('poly', pts, ct, a)++def encode_prog(ops):out = bytearray()for op in ops:kind = op[0]+ if kind == 'poly':+ pts = op[1]+ assert 3 <= len(pts) <= 8, op+ big = max(max(abs(x), abs(y)) for x, y in pts) > 63+ out.append(3 | (0x80 if big else 0))+ out.append(len(pts))+ for x, y in pts:+ for v in (x, y):+ c = int(round(v / 2 if big else v * 2))+ assert -128 <= c <= 127, op+ out.append(c & 255)+ out.append(CT_INDEX[op[2]])+ out.append(int(round(op[3] * 255)))+ continuebig = max(abs(v) for v in op[1:5]) > 63coords = [int(round(v / 2 if big else v * 2)) for v in op[1:5]]assert all(-128 <= c <= 127 for c in coords), opdiff --git a/games/numdash/tools/objdefs_dl.py b/games/numdash/tools/objdefs_dl.pynew file mode 100644index 00000000..aaa934b2--- /dev/null+++ b/games/numdash/tools/objdefs_dl.py@@ -0,0 +1,469 @@+"""Object catalogue of Deadlocked (level 20, GD 2.0): outline and neon+blocks, glows, 3D lines, beveled bricks, industrial blocks, pits, slopes,+animated decoration, new portals and hazards.++Hitboxes follow GD 2.0 (gmdkit's hitbox table and OpenGD's measurements);+the art is drawn here from rectangles and polygons (tile programs, units,+y up, centre origin) or from sprites in sprites_lv.py, redrawn in NumDash's+style after the originals' shapes. Colour types BASE and DETAIL follow the+object's GD colour channels (defaults in `extra`).+"""+import math++NONE, SOLID, HAZARD, SPECIAL = range(4)+F_PULSE, F_RANDOM3, F_COIN, F_ANIM, F_QUAD, F_HALF = 1, 2, 4, 8, 16, 32+# GD default z layers -> NumDash draw layers+B2, B1, T1, GL = 'RODS', 'DETAIL', 'BLOCK', 'BLOCK_GLOW'+++def R(x0, y0, x1, y1, ct='BASE', a=1.0):+ return ('rect', min(x0, x1), min(y0, y1), max(x0, x1), max(y0, y1), ct, a)+++def VG(x0, y0, x1, y1, ct, a_top, a_bottom):+ return ('vgrad', x0, y0, x1, y1, ct, a_top, a_bottom)+++def P(pts, ct='BASE', a=1.0):+ return ('poly', [(round(x * 2) / 2, round(y * 2) / 2) for x, y in pts], ct, a)+++def seg(x0, y0, x1, y1, w=1.5, ct='BASE', a=1.0):+ """A straight stroke of width w as a quad."""+ dx, dy = x1 - x0, y1 - y0+ L = math.hypot(dx, dy) or 1+ nx, ny = -dy / L * w / 2, dx / L * w / 2+ return P([(x0 + nx, y0 + ny), (x1 + nx, y1 + ny), (x1 - nx, y1 - ny), (x0 - nx, y0 - ny)], ct, a)+++def glow_band(x0, y0, x1, y1, w=4.5, a=0.45):+ """Soft glow on both sides of a stroke (two alpha ramps as bands)."""+ ops = []+ dx, dy = x1 - x0, y1 - y0+ L = math.hypot(dx, dy) or 1+ nx, ny = -dy / L, dx / L+ for k in range(3):+ d0, d1 = w * k / 3, w * (k + 1) / 3+ aa = a * (1 - (k + .5) / 3)+ for sgn in (1, -1):+ p0 = (x0 + nx * d0 * sgn, y0 + ny * d0 * sgn)+ p1 = (x1 + nx * d0 * sgn, y1 + ny * d0 * sgn)+ p2 = (x1 + nx * d1 * sgn, y1 + ny * d1 * sgn)+ p3 = (x0 + nx * d1 * sgn, y0 + ny * d1 * sgn)+ ops.append(P([p0, p1, p2, p3], 'GLOW', aa))+ return ops+++def radial(cx, cy, r, a0, a1, a_from, a_to, bands=5, ct='BASE'):+ """Radial fade from centre (alpha a_from) to radius r (a_to) over the+ angle range a0..a1 (degrees, counter-clockwise from +x), as stacked pie+ slices (each band adds its share of the alpha)."""+ ops = []+ prev = 0.0+ for k in range(bands):+ rr = r * (1 - k / bands)+ target = a_to + (a_from - a_to) * (k + 1) / bands+ step = max(0.0, 1 - (1 - target) / max(1e-6, 1 - prev)) if target < 1 else 1.0+ prev = target+ pts = [(cx, cy)]+ n = 5+ for j in range(n + 1):+ t = math.radians(a0 + (a1 - a0) * j / n)+ pts.append((cx + rr * math.cos(t), cy + rr * math.sin(t)))+ # convex pie with up to 8 points: thin out the arc+ ops.append(P(pts[:8], ct, round(step, 3)))+ return ops+++def outline(sides, w=1.5, h=15, x=15):+ """Edge strokes of a box: letters t b l r."""+ ops = []+ if 't' in sides: ops.append(R(-x, h - w, x, h))+ if 'b' in sides: ops.append(R(-x, -h, x, -h + w))+ if 'l' in sides: ops.append(R(-x, -h, -x + w, h))+ if 'r' in sides: ops.append(R(x - w, -h, x, h))+ return ops+++def outline_glow(sides, h=15, x=15, w=5.0, a=0.4):+ ops = []+ if 't' in sides: ops += [VG(-x, h, x, h + w, 'GLOW', 0, a), VG(-x, h - w, x, h, 'GLOW', a, 0)]+ if 'b' in sides: ops += [VG(-x, -h, x, -h + w, 'GLOW', a, 0), VG(-x, -h - w, x, -h, 'GLOW', 0, a)]+ if 'l' in sides: ops += glow_band(-x + .75, -h, -x + .75, h, w, a)+ if 'r' in sides: ops += glow_band(x - .75, -h, x - .75, h, w, a)+ return ops+++PROGS = {}+OBJS = []+++def prog(name, ops):+ PROGS[name] = ops+ return 'prog:' + name+++def obj(name, ids, hit, w, h, parts, special='NONE', edy=0, **extra):+ OBJS.append((name, ids, hit, w, h, special, edy, parts, extra))+++# ---------------------------------------------------------------- glows+# gradients that line block edges: opaque at the block side, base colour+# (channel 1 by default)+obj('GLOW_MED', [503], NONE, 0, 0, [(prog('g_med', [VG(-15, -10, 15, 10, 'BASE', 0, .85)]), 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_LARGE', [1011], NONE, 0, 0, [(prog('g_large', [VG(-15, -15, 15, 15, 'BASE', 0, .85)]), 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_SMALL', [1292], NONE, 0, 0, [(prog('g_small', [VG(-7.5, -5, 7.5, 5, 'BASE', 0, .85)]), 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_HALF', [1291], NONE, 0, 0, [(prog('g_half', [VG(-7.5, -10, 7.5, 10, 'BASE', 0, .85)]), 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_OUTER', [504], NONE, 0, 0, [(prog('g_outer', radial(10, -10, 20, 90, 180, .85, 0)), 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_OUTER_L', [1012], NONE, 0, 0, [(prog('g_outer_l', radial(15, -15, 30, 90, 180, .85, 0)), 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_INNER', [505], NONE, 0, 0, [(prog('g_inner', [VG(-15, -15, 15, 0, 'BASE', 0, .8), P([(0, -15), (15, -15), (15, 15), (0, 15)], 'BASE', .0)]+ + [P([(15 - w, -15), (15, -15), (15, 15), (15 - w, 15)], 'BASE', .2) for w in (5, 10, 15)]),+ 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_SLOPE1', [1273], NONE, 0, 0, [(prog('g_slope1', [P([(-7, -10), (13, 10), (13, -10)], 'BASE', .25), P([(0, -10), (13, 3), (13, -10)], 'BASE', .3),+ P([(6, -10), (13, -3), (13, -10)], 'BASE', .35)]), 0, 0, B2, 'BASE', 0)], base=1)+obj('GLOW_SLOPE2', [1274], NONE, 0, 0, [(prog('g_slope2', [P([(-4.5, -10), (15.5, 10), (15.5, -10)], 'BASE', .2), P([(5.5, -10), (15.5, 0), (15.5, -10)], 'BASE', .35)]),+ 0, 0, B2, 'BASE', 0)], base=1)++# ---------------------------------------------------------------- outline blocks (white 1.5 unit lines)+def outline_obj(name, ids, hit, w, h, sides, bw=15, bh=15):+ obj(name, ids, hit, w, h, [(prog('o_' + name.lower(), outline(sides, 1.5, bh, bw)), 0, 0, T1, 'BASE', 0),+ (prog('og_' + name.lower(), outline_glow(sides, bh, bw)), 0, 0, GL, 'GLOW', 0)])+++outline_obj('OUT_SQUARE', [467], SOLID, 30, 30, 'tblr')+obj('OUT_TOP', [468], SOLID, 30, 1.5, [(prog('o_top', [R(-15, -.75, 15, .75)]), 0, 0, T1, 'BASE', 0),+ (prog('og_top', [VG(-15, .75, 15, 5.5, 'GLOW', 0, .4), VG(-15, -5.5, 15, -.75, 'GLOW', .4, 0)]), 0, 0, GL, 'GLOW', 0)])+outline_obj('OUT_CORNER', [469], SOLID, 30, 30, 'tl')+outline_obj('OUT_TOP_PILLAR', [470], SOLID, 30, 30, 'tlr')+outline_obj('OUT_PILLAR', [471], SOLID, 30, 30, 'lr')+obj('OUT_INNER', [472], NONE, 0, 0, [(prog('o_inner', [R(-15, 13.5, -13.5, 15)]), 0, 0, T1, 'BASE', 0)])+obj('OUT_SLOPE_CORNER', [473], NONE, 0, 0, [(prog('o_slc', [P([(-15, 13.5), (-15, 15), (-12, 15)])]), 0, 0, T1, 'BASE', 0)])+obj('OUT_WSLOPE_CORNER', [474], NONE, 0, 0, [(prog('o_wslc', [P([(-15, 14), (-15, 15), (-10, 15)])]), 0, 0, T1, 'BASE', 0)])+obj('OUT_SLOPE_SIDE', [475], SOLID, 30, 1.5, [(prog('o_ss', [P([(-15, -.75), (15, -.75), (15, .75), (-12, .75)])]), 0, 0, T1, 'BASE', 0),+ (prog('og_ss', [VG(-15, .75, 15, 5, 'GLOW', 0, .35), VG(-15, -5, 15, -.75, 'GLOW', .35, 0)]), 0, 0, GL, 'GLOW', 0)])+outline_obj('OUT_SLAB', [662], SOLID, 30, 15, 'tblr', 15, 7.5)+outline_obj('OUT_SLAB_MID', [663], SOLID, 30, 15, 'tb', 15, 7.5)+outline_obj('OUT_SLAB_SIDE', [664], SOLID, 30, 15, 'tbl', 15, 7.5)+obj('OUT_THICK_TOP', [1202], SOLID, 30, 3, [(prog('o_thtop', [R(-15, -1.5, 15, 1.5)]), 0, 0, T1, 'BASE', 0),+ (prog('og_thtop', [VG(-15, 1.5, 15, 7, 'GLOW', 0, .4), VG(-15, -7, 15, -1.5, 'GLOW', .4, 0)]), 0, 0, GL, 'GLOW', 0)])+obj('OUT_THICK_SMALL', [1208], SOLID, 15, 15, [(prog('o_thsm', outline('tblr', 3, 7.5, 7.5)), 0, 0, T1, 'BASE', 0),+ (prog('og_thsm', outline_glow('tblr', 7.5, 7.5, 5)), 0, 0, GL, 'GLOW', 0)])+obj('OUT_THICK_SQUARE', [1210], SOLID, 30, 30, [(prog('o_thsq', outline('tblr', 3)), 0, 0, T1, 'BASE', 0),+ (prog('og_thsq', outline_glow('tblr')), 0, 0, GL, 'GLOW', 0)])+# slopes: a diagonal stroke (the solid triangle is below it)+obj('OUT_SLOPE', [665], SOLID, 30, 30, [(prog('o_slope', [seg(-15, -15, 15, 15, 1.8)]), 0, 0, T1, 'BASE', 0),+ (prog('og_slope', glow_band(-15, -15, 15, 15, 5)), 0, 0, GL, 'GLOW', 0)], shape='SLOPE')+obj('OUT_WSLOPE', [666], SOLID, 60, 30, [(prog('o_wslope', [seg(-30, -15, 30, 15, 1.8)]), 0, 0, T1, 'BASE', 0),+ (prog('og_wslope', glow_band(-30, -15, 30, 15, 5)), 0, 0, GL, 'GLOW', 0)], shape='SLOPE')+obj('BLOCK_WSLOPE', [652], SOLID, 60, 30, [(prog('b_wslope', [P([(-30, -15), (30, 15), (30, -15)], 'BLACK'), seg(-30, -15, 30, 15, 1.8, 'BASE'),+ P([(-18, -15), (30, 9), (30, 3), (-6, -15)], 'DETAIL', .5)]), 0, 0, T1, 'BASE', 0),+ (prog('og_wslope', glow_band(-30, -15, 30, 15, 5)), 0, 0, GL, 'GLOW', 0)], shape='SLOPE', detail=1)+# decorative black slopes+obj('DECO_SLOPE', [687], NONE, 0, 0, [(prog('d_slope', [P([(-15, -15), (15, 15), (15, -15)], 'BASE')]), 0, 0, B1, 'BASE', 0)])+obj('DECO_WSLOPE', [688], NONE, 0, 0, [(prog('d_wslope', [P([(-30, -15), (30, 15), (30, -15)], 'BASE')]), 0, 0, B1, 'BASE', 0)])+# rainbow slopes (fixed colours)+obj('RAINBOW_SLOPE', [1014], NONE, 0, 0, [(prog('rain_slope', [P([(-15 + 5 * k, -15), (15, 15 - 5 * k), (15, 15 - 5 * (k + 1)), (-15 + 5 * (k + 1), -15)], 'RAIN%d' % k)+ for k in range(6)]), 0, 0, B2, 'BASE', 0)], base=1011)+obj('RAINBOW_SQUARE', [1016], NONE, 0, 0, [(prog('rain_sq', [P([(-15, 15 - 5 * k), (15 - 5 * k, -15), (15 - 5 * (k + 1), -15), (-15, 15 - 5 * (k + 1))], 'RAIN%d' % (5 - k))+ for k in range(6) if k < 6] + [P([(-15, -15 + 0), (-15, -15), (-15, -15)], 'RAIN0', 0)][:0]),+ 0, 0, B2, 'BASE', 0)], base=1011)++# ---------------------------------------------------------------- neon blocks (base body a shade darker, detail strips)+S = 7.0 # strip width+++def neon(name, ids, body, strips, hit=NONE, w=0, h=0, **kw):+ ops = [P(b, 'BASE_D') if isinstance(b, list) else b for b in body] + strips+ obj(name, ids, hit, w, h, [(prog('n_' + name.lower(), ops), 0, 0, B2, 'BASE', 0)], detail=1, **kw)+++def rb(x0, y0, x1, y1):+ return R(x0, y0, x1, y1, 'BASE_D')+++def rd(x0, y0, x1, y1):+ return R(x0, y0, x1, y1, 'DETAIL')+++neon('NEON_TOP', [1162], [rb(-15, -15, 15, 15 - S)], [rd(-15, 15 - S, 15, 15)])+neon('NEON_TL', [1163], [rb(-15 + S, -15, 15, 15 - S)], [rd(-15, 15 - S, 15, 15), rd(-15, -15, -15 + S, 15 - S)])+neon('NEON_VPILLAR_TOP', [1164, 1175], [rb(-7.5, -15, 7.5, 15 - S)], [rd(-7.5 - S, 15 - S, 7.5 + S, 15), rd(-7.5 - S, -15, -7.5, 15 - S), rd(7.5, -15, 7.5 + S, 15 - S)])+neon('NEON_VPILLAR', [1165], [rb(-7.5, -15, 7.5, 15)], [rd(-7.5 - S, -15, -7.5, 15), rd(7.5, -15, 7.5 + S, 15)])+neon('NEON_LEFT', [1167], [rb(-15 + S, -15, 15, 15)], [rd(-15, -15, -15 + S, 15)])+neon('NEON_TL_INNER', [1168], [rb(-15, -15, 15, 15)], [rd(-15, 15 - S, -15 + S, 15)])+neon('NEON_SQUARE', [1170], [rb(-15 + S, -15 + S, 15 - S, 15 - S)], [rd(-15, 15 - S, 15, 15), rd(-15, -15, 15, -15 + S), rd(-15, -15 + S, -15 + S, 15 - S),+ rd(15 - S, -15 + S, 15, 15 - S)])+neon('NEON_SIDE_TOP', [1171], [rb(-15 + S, -15, 15, 15)], [rd(-15, -15, -15 + S, 15), rd(15 - S, 15 - S, 15, 15)])+neon('NEON_PILLAR_TL', [1173], [rb(-15 + S, -15, 15, 15 - S)], [rd(-15, 15 - S, 15, 15), rd(-15, -15, -15 + S, 15 - S), rd(15 - S, -15, 15, -15 + S)])+neon('NEON_HPILLAR', [1174], [rb(-15, -7.5, 15, 7.5)], [rd(-15, 7.5, 15, 7.5 + S), rd(-15, -7.5 - S, 15, -7.5)])+neon('NEON_HPILLAR_L', [1176], [rb(-15 + S, -7.5, 15, 7.5)], [rd(-15, 7.5, 15, 7.5 + S), rd(-15, -7.5 - S, 15, -7.5), rd(-15, -7.5, -15 + S, 7.5)])+neon('NEON_INNER', [1186], [rb(-15, -15, 15, 15)], [])+neon('NEON_INV_BOTTOM_SIDE', [1322], [rb(-15, -15 + S, 15 - S, 15)], [rd(-15, -15, 15, -15 + S), rd(15 - S, -15 + S, 15, 15)])+neon('NEON_SLOPE', [1187], [[(-15, -15), (15, 15 - S * 1.41), (15, -15)]], [P([(-15, -15), (-15 + S * 1.41, -15), (15, 15 - S * 1.41), (15, 15)], 'DETAIL')])+neon('NEON_WSLOPE', [1188], [[(-30, -15), (30, 15 - S * 1.12), (30, -15)]], [P([(-30, -15), (-30 + S * 2.2, -15), (30, 15 - S * 1.12), (30, 15)], 'DETAIL')])+neon('NEON_SLOPE_CONN', [1189], [rb(-15, -15, 15, 15)], [P([(-15, 15 - S * 1.41), (-15, 15), (-15 + S * 1.41, 15)], 'DETAIL')])+neon('NEON_WSLOPE_CONN', [1190], [rb(-15, -15, 15, 15)], [P([(-15, 15 - S * 1.12), (-15, 15), (-15 + S * 2.2, 15)], 'DETAIL')])+neon('NEON_HSLOPE_CONN', [1325], [[(-15, -15), (-15, 15), (15, 15), (15, -15)]], [P([(-15, 15 - S * 1.41), (-15, 15), (-15 + S * 1.41, 15)], 'DETAIL')])+obj('NEON_OUTLINE_TOP', [1191], NONE, 0, 0, [(prog('n_otop', [rd(-15, 15 - S, 15, 15)]), 0, 0, T1, 'BASE', 0)], detail=1)+obj('NEON_OUTLINE_INNER', [1194], NONE, 0, 0, [(prog('n_oinner', [rd(-15, 15 - S, -15 + S, 15)]), 0, 0, T1, 'BASE', 0)], detail=1)+obj('QUARTER_COLOR', [916], NONE, 0, 0, [(prog('q_color', [R(-7.5, -7.5, 7.5, 7.5)]), 0, 0, B1, 'BASE', 0)], base=1)+obj('SIXTEENTH_COLOR', [917], NONE, 0, 0, [(prog('s_color', [R(-3.75, -3.75, 3.75, 3.75)]), 0, 0, B1, 'BASE', 0)], base=1)+obj('COLOR_SQUARE', [211], NONE, 0, 0, [(prog('c_square', [R(-15, -15, 15, 15)]), 0, 0, B2, 'BASE', 0)], base=1)++# ---------------------------------------------------------------- 3D lines (3DL channel)+L3 = 1.5+obj('L3_TOP_LEFT', [506], NONE, 0, 0, [(prog('l3_tl', [seg(-15, -5, -5, 5 - L3 / 2, L3), R(-5.5, 5 - L3, 15, 5)]), 0, 0, B1, 'BASE', 0)], base=1003)+obj('L3_TOP_MID', [507], NONE, 0, 0, [(prog('l3_tm', [R(-15, 4 - L3 / 2, 15, 4 + L3 / 2)]), 0, 0, B1, 'BASE', 0)], base=1003)+obj('L3_HALF_TOP_MID', [508], NONE, 0, 0, [(prog('l3_htm', [R(-7.5, 4 - L3 / 2, 7.5, 4 + L3 / 2)]), 0, 0, B1, 'BASE', 0)], base=1003)+obj('L3_TOP_RIGHT', [509], NONE, 0, 0, [(prog('l3_tr', [seg(-6, -6, 6, 6, L3), R(-1, 5.25, 6, 6.75), R(5.25, -1, 6.75, 6)]), 0, 0, B1, 'BASE', 0)], base=1003)+obj('L3_INNER', [510], NONE, 0, 0, [(prog('l3_in', [seg(-8, -8, 0, 0, L3), R(-1, -.75, 10, .75), R(-.75, 0, .75, 10)]), 0, 0, B1, 'BASE', 0)], base=1003)+obj('L3_OUTER', [511], NONE, 0, 0, [(prog('l3_out', [seg(-6, -6, 6, 6, L3), R(-6, 5.25, 6, 6.75)]), 0, 0, B1, 'BASE', 0)], base=1003)+obj('L3_HALF_TOP_LEFT', [512], NONE, 0, 0, [(prog('l3_htl', [seg(-7.5, -5, -2.5, 4.25, L3), R(-3, 4 - L3 / 2, 7.5, 4 + L3 / 2)]), 0, 0, B1, 'BASE', 0)], base=1003)+# coloured 3D blocks (filled tops, channel 3)+obj('C3_TOP_LEFT', [578], NONE, 0, 0, [(prog('c3_tl', [P([(-15, -5), (-5, 5), (0, 5), (0, -5)]), R(0, -5, 15, 5)]), 0, 0, B2, 'BASE', 0)], base=3)+obj('C3_TOP_MID', [579], NONE, 0, 0, [(prog('c3_tm', [R(-15, -5, 15, 5)]), 0, 0, B2, 'BASE', 0)], base=3)+obj('C3_OUTER', [583], NONE, 0, 0, [(prog('c3_out', [P([(-5, -5), (5, 5), (5, -5)])]), 0, 0, B2, 'BASE', 0)], base=3)+obj('C3_HALF_TOP_LEFT', [584], NONE, 0, 0, [(prog('c3_htl', [P([(-7.5, -5), (2.5, 5), (7.5, 5), (7.5, -5)])]), 0, 0, B2, 'BASE', 0)], base=3)+obj('C3_SQUARE_MID', [624], NONE, 0, 0, [(prog('c3_sqm', [R(-15, -5, 15, 5, 'BASE_D'), R(-15, 3.5, 15, 5, 'BASE')]), 0, 0, B2, 'BASE', 0)])+obj('C3_SQUARE_OUTER', [628], NONE, 0, 0, [(prog('c3_sqo', [P([(-5, -5), (5, 5), (5, -5)], 'BASE_D')]), 0, 0, B2, 'BASE', 0)])+++def stripes(x0, x1, y0, y1, n, ct='DETAIL'):+ ops = []+ w = (x1 - x0) / n+ for k in range(n):+ xa = x0 + k * w+ ops.append(P([(xa, y0), (xa + w * .5, y0), (xa + w * .5 + (y1 - y0), y1), (xa + (y1 - y0), y1)][:4], ct))+ return ops+++obj('S3_TOP_LEFT', [980], NONE, 0, 0, [(prog('s3_tl', [P([(-15, -5), (-5, 5), (15, 5), (15, -5)], 'BLACK')] + stripes(-8, 12, -5, 5, 4)), 0, 0, B2, 'BASE', 0)], detail=1)+obj('S3_TOP_MID', [981], NONE, 0, 0, [(prog('s3_tm', [R(-15, -5, 15, 5, 'BLACK')] + stripes(-17, 13, -5, 5, 5)), 0, 0, B2, 'BASE', 0)], detail=1)+obj('S3_TOP_RIGHT', [983], NONE, 0, 0, [(prog('s3_tr', [P([(-5, -5), (5, 5), (5, -5)], 'BLACK'), P([(-1, -5), (3, -5), (5, -3), (5, 1)], 'DETAIL')]), 0, 0, B2, 'BASE', 0)], detail=1)+obj('S3_HALF_TOP_LEFT', [986], NONE, 0, 0, [(prog('s3_htl', [P([(-7.5, -5), (2.5, 5), (7.5, 5), (7.5, -5)], 'BLACK')] + stripes(-2, 6, -5, 5, 2)), 0, 0, B2, 'BASE', 0)], detail=1)++# ---------------------------------------------------------------- beveled bricks (base grey, highlights in the lighter shade)+def brick(x0, y0, x1, y1, b=1.5):+ """One beveled brick: body, light top-left bevel, dark bottom-right."""+ return [R(x0, y0, x1, y1, 'BASE'), P([(x0, y1), (x1, y1), (x1 - b, y1 - b), (x0 + b, y1 - b)], 'DETAIL'),+ P([(x0, y0), (x0, y1), (x0 + b, y1 - b), (x0 + b, y0 + b)], 'DETAIL', .7),+ P([(x0, y0), (x1, y0), (x1 - b, y0 + b), (x0 + b, y0 + b)], 'BASE_D'),+ P([(x1, y0), (x1, y1), (x1 - b, y1 - b), (x1 - b, y0 + b)], 'BASE_D')]+++def bricks(rows, mortar=True):+ ops = [R(-15, -15, 15, 15, 'BASE_D')] if mortar else []+ for (x0, y0, x1, y1) in rows:+ ops += brick(x0, y0, x1, y1)+ return ops+++BIG2 = [(-14, 1, -.5, 14), (.5, 1, 14, 14), (-14, -14, 14, -1)]+obj('BRICK_MID', [869], NONE, 0, 0, [(prog('bv_mid', bricks([(-15, 1, -.5, 15), (.5, 1, 15, 15), (-15, -15, 15, -1)])), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BRICK_BOND', [870], NONE, 0, 0, [(prog('bv_bond', bricks([(-15, 1, 15, 15), (-15, -15, -.5, -1), (.5, -15, 15, -1)])), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BRICK_LEFT1', [871], NONE, 0, 0, [(prog('bv_l1', bricks([(-14, 1, -.5, 14), (.5, 1, 15, 14), (-14, -15, 15, -1)])), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BRICK_RIGHT1', [872], NONE, 0, 0, [(prog('bv_r1', bricks([(-15, 1, -.5, 14), (.5, 1, 14, 14), (-15, -15, 14, -1)])), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BRICK_LEFT2', [1266], NONE, 0, 0, [(prog('bv_l2', bricks([(-14, 1, -.5, 15), (.5, 1, 15, 15), (-14, -14, 15, -1)])), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BRICK_RIGHT2', [1267], NONE, 0, 0, [(prog('bv_r2', bricks([(-15, 1, -.5, 15), (.5, 1, 14, 15), (-15, -14, 14, -1)])), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BRICKS1', [867], NONE, 0, 0, [(prog('bv_1', bricks([(-14, 6, -2, 14), (-1, 6, 14, 14), (-14, -4, 4, 4), (5, -4, 14, 4), (-14, -14, -5, -6), (-4, -14, 14, -6)])), 0, 0, B2, 'BASE', 0)], detail=1012)+SMALL = [(-15, 8, -6, 15), (-5, 8, 5, 15), (6, 8, 15, 15), (-15, 0, 0, 7), (1, 0, 15, 7), (-15, -8, -6, -1), (-5, -8, 5, -1), (6, -8, 15, -1), (-15, -15, 0, -9), (1, -15, 15, -9)]+obj('SBRICKS', [880], NONE, 0, 0, [(prog('bv_s', bricks(SMALL)), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('SBRICKS_RECESS', [881], NONE, 0, 0, [(prog('bv_sr', bricks([b for b in SMALL if b[1] < 8], False) + [R(-15, -15, 15, 8, 'BASE_D')][:0]), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('SBRICK_PILE_L', [882], NONE, 0, 0, [(prog('bv_pl', bricks([(4, 8, 15, 15), (-4, 0, 15, 7), (-10, -8, 15, -1), (-15, -15, 15, -9)], False)), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('SBRICK_PILE_R', [883], NONE, 0, 0, [(prog('bv_pr', bricks([(-15, 8, -4, 15), (-15, 0, 4, 7), (-15, -8, 10, -1), (-15, -15, 15, -9)], False)), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('SBRICKS_LEFT', [884], NONE, 0, 0, [(prog('bv_sl', bricks([(-13, 8, -6, 15), (-5, 8, 5, 15), (6, 8, 15, 15), (-13, 0, 0, 7), (1, 0, 15, 7), (-13, -8, -6, -1), (-5, -8, 5, -1), (6, -8, 15, -1), (-13, -15, 0, -9), (1, -15, 15, -9)], False)),+ 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BEVEL_SLAB', [891], NONE, 0, 0, [(prog('bv_slab', brick(-15, -7.5, 15, 7.5, 2)), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BEVEL_PIPE', [893], NONE, 0, 0, [(prog('bv_pipe', brick(-5, -7.5, 5, 7.5, 1.5)), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BEVEL_PIPE_CONN', [853], NONE, 0, 0, [(prog('bv_pconn', brick(-7.5, -7.5, 7.5, 7.5, 1.5)), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BEVEL_PIPE_DOWN', [857], NONE, 0, 0, [(prog('bv_pdown', brick(-5, -7.5, 5, 7.5, 1.5) + [R(-7.5, 5, 7.5, 7.5, 'DETAIL')]), 0, 0, B2, 'BASE', 0)], detail=1012)+obj('BEVEL_PIPE_UP', [859], NONE, 0, 0, [(prog('bv_pup', brick(-5, -7.5, 5, 7.5, 1.5) + [R(-7.5, -7.5, 7.5, -5, 'BASE_D')]), 0, 0, B2, 'BASE', 0)], detail=1012)++# ---------------------------------------------------------------- industrial blocks (grey frame, hazard stripes)+def indus(dark):+ body = 'BASE_D' if dark else 'BASE'+ return [R(-15, -15, 15, 15, 'BASE_L'), R(-13, -13, 13, 13, 'BLACK'), R(-11, -11, 11, 11, body, .85)]+++def hstripes(y0, y1, x0=-13, x1=13, n=5):+ ops = []+ w = (x1 - x0) / n+ for k in range(n):+ xa = x0 + k * w+ ops.append(P([(xa, y0), (xa + w * .45, y0), (xa + w * .45 + (y1 - y0) * .6, y1), (xa + (y1 - y0) * .6, y1)], 'DETAIL'))+ return ops+++for (name, ids, dark, extra_ops) in [('INDUS_TOP_L', [807], False, hstripes(11, 13)), ('INDUS_TOP_D', [808], True, hstripes(11, 13)),+ ('INDUS_CORNER_L', [809], False, hstripes(11, 13) + [P([(-13, -13), (-11, -13), (-11, 11), (-13, 11)], 'DETAIL')]),+ ('INDUS_CORNER_D', [810], True, hstripes(11, 13) + [P([(-13, -13), (-11, -13), (-11, 11), (-13, 11)], 'DETAIL')]),+ ('INDUS_PILLAR_L', [811], False, [P([(-13, -13), (-11, -13), (-11, 13), (-13, 13)], 'DETAIL'), P([(11, -13), (13, -13), (13, 13), (11, 13)], 'DETAIL')]),+ ('INDUS_PILLAR_D', [812], True, [P([(-13, -13), (-11, -13), (-11, 13), (-13, 13)], 'DETAIL'), P([(11, -13), (13, -13), (13, 13), (11, 13)], 'DETAIL')]),+ ('INDUS_PTOP_L', [813], False, hstripes(11, 13) + [R(-13, -13, -11, 11, 'DETAIL'), R(11, -13, 13, 11, 'DETAIL')]),+ ('INDUS_PTOP_D', [814], True, hstripes(11, 13) + [R(-13, -13, -11, 11, 'DETAIL'), R(11, -13, 13, 11, 'DETAIL')]),+ ('INDUS_SQUARE_L', [815], False, hstripes(11, 13) + hstripes(-13, -11)),+ ('INDUS_BOLTS_L', [817], False, [R(-10, 9, -8, 11, 'BASE_L'), R(8, 9, 10, 11, 'BASE_L'), R(-10, -11, -8, -9, 'BASE_L'), R(8, -11, 10, -9, 'BASE_L')]),+ ('INDUS_HATCH_D', [820], True, [R(-5, 3, 5, 5, 'BLACK'), R(-1, -2, 1, 3, 'BLACK')]),+ ('INDUS_INNER_L', [823], False, []), ('INDUS_INNER_D', [824], True, [])]:+ obj(name, ids, NONE, 0, 0, [(prog('i_' + name.lower(), indus(dark) + extra_ops), 0, 0, B2, 'BASE', 0)], detail=1)+obj('INDUS_SLOPE_D', [827], NONE, 0, 0, [(prog('i_slope', [P([(-15, -15), (15, 15), (15, -15)], 'BASE_L'), P([(-11, -13), (13, 11), (13, -13)], 'BASE_D')] + [seg(-9 + 6 * k, -13 + 6 * k, -5 + 6 * k, -9 + 6 * k, 3, 'DETAIL') for k in range(3)]),+ 0, 0, B2, 'BASE', 0)], detail=1)+obj('INDUS_SLOPE_CONN_L', [830], NONE, 0, 0, [(prog('i_sconn', indus(False) + [P([(-15, 11), (-15, 15), (-11, 15)], 'DETAIL')]), 0, 0, B2, 'BASE', 0)], detail=1)+for (name, ids, ends) in [('INDUS_SLAB_MID', [1079], ''), ('INDUS_SLAB_SIDE', [1080], 'l'), ('INDUS_SLAB_SINGLE', [1081], 'lr')]:+ ops = [R(-15, -7.5, 15, 7.5, 'BASE_L'), R(-15, -5.5, 15, 5.5, 'BLACK'), R(-15, -3.5, 15, 3.5, 'BASE_D', .85)] + hstripes(4, 6, -15, 15, 6) + hstripes(-6, -4, -15, 15, 6)+ if 'l' in ends: ops += [R(-15, -7.5, -12, 7.5, 'BASE_L')]+ if 'r' in ends: ops += [R(12, -7.5, 15, 7.5, 'BASE_L')]+ obj(name, ids, NONE, 0, 0, [(prog('i_' + name.lower(), ops), 0, 0, B2, 'BASE', 0)], detail=1)++# ---------------------------------------------------------------- grey patterned tiles (pixel art)+def pix_tile(body):+ return [P(b, 'BASE_L') for b in body]+++obj('PIX_TILE', [738], NONE, 0, 0, [(prog('p_tile', [R(-15, -15, 15, 15, 'BASE_L'), R(-12, -12, 12, 12, 'BASE'), R(-12, 10, 12, 12, 'BASE_L', .6)]), 0, 0, B2, 'BASE', 0)])+obj('PIX_EDGE', [668], NONE, 0, 0, [(prog('p_edge', [R(-15, -7.5, 15, 7.5, 'BASE_L'), R(-12, -4.5, 12, 4.5, 'BASE'), R(-5, 4.5, 5, 7.5, 'BASE')]), 0, 0, B2, 'BASE', 0)])+obj('PIX_INNER', [669], NONE, 0, 0, [(prog('p_inner', [P([(-15, -15), (-15, -5), (-5, -5), (-5, 5), (5, 5), (5, 15), (15, 15), (15, -15)][:8], 'BASE_L'),+ R(-12, -12, 12, -8, 'BASE'), R(8, -8, 12, 12, 'BASE')]), 0, 0, B2, 'BASE', 0)])+obj('PIX_PIPE', [671], NONE, 0, 0, [(prog('p_pipe', [R(-10, -15, 10, 15, 'BASE_L'), R(-6, -15, 6, 15, 'BASE'), R(-10, 3, 10, 7, 'BASE_L')]), 0, 0, B2, 'BASE', 0)])+obj('PIX_PIPE_BASE', [672], NONE, 0, 0, [(prog('p_pbase', [R(-15, -15, 15, 0, 'BASE_L'), R(-12, -12, 12, -3, 'BASE'), R(-10, 0, 10, 15, 'BASE_L'), R(-6, 0, 6, 15, 'BASE')]),+ 0, 0, B2, 'BASE', 0)])++# ---------------------------------------------------------------- pits (black hazards) and their shine outlines+obj('PIT_CROWN', [421], HAZARD, 9, 5.2, [(prog('pt_crown', [P([(-15, -6.5), (-15, 1), (-10, -2), (-5, 5), (0, -1), (5, 5), (10, -2), (15, 1)][:8] + [], 'BLACK'),+ R(-15, -6.5, 15, -1, 'BLACK')]), 0, 0, T1, 'BASE', 0)], edy=-8)+obj('PIT_BOWL', [446], HAZARD, 9, 7.2, [(prog('pt_bowl', [P([(-15, -9), (-15, 9), (-9, 1), (0, -2), (9, 1), (15, 9), (15, -9)], 'BLACK')]), 0, 0, T1, 'BASE', 0)])+obj('PIT_BOWL2', [447], HAZARD, 5.2, 7.2, [(prog('pt_bowl2', [P([(-15, -9), (-15, 9), (-5, -2), (15, -9)], 'BLACK')]), 0, 0, T1, 'BASE', 0)], hx=-5)+obj('PIT_SQUARE', [667], HAZARD, 9, 6, [(prog('pt_square', [R(-15, -7.5, 15, 0, 'BLACK'), R(-12, 0, -4, 7.5, 'BLACK'), R(4, 0, 12, 7.5, 'BLACK')]), 0, 0, T1, 'BASE', 0)])+obj('PIT_STAIR', [989], HAZARD, 9, 12, [(prog('pt_stair', [P([(-15, -15), (15, 15), (15, -15)], 'BLACK'), R(-7.5, -15, 0, 7.5, 'BLACK'), R(0, -15, 7.5, 15, 'BLACK')]), 0, 0, T1, 'BASE', 0)])+obj('PIT_TRI', [991], HAZARD, 2.4, 3.2, [(prog('pt_tri', [P([(-3.75, -3.75), (3.75, 3.75), (3.75, -3.75)], 'BLACK')]), 0, 0, T1, 'BASE', 0)])+obj('PIT_DOT', [720], HAZARD, 2.4, 3.2, [(prog('pt_dot', [R(-4, -3.75, 4, 3.75, 'BLACK')]), 0, 0, T1, 'BASE', 0)])+obj('PIT_WAVE_LOW', [368], HAZARD, 9, 4, [(prog('pt_wlow', [P([(-15, -5), (-15, 1), (-9, 4), (-3, 1), (3, 4), (9, 1), (15, 4), (15, -5)], 'BLACK')]), 0, 0, T1, 'BASE', 0)], edy=-8)+obj('PIT_TRI_LOW', [422], HAZARD, 6, 4.4, [(prog('pt_tlow', [P([(-15, -5), (-15, -1), (-8, 4), (15, -5)], 'BLACK')]), 0, 0, T1, 'BASE', 0)], hx=-5, edy=-8)+obj('PIT_NOTCH', [768], HAZARD, 4.5, 5.2, [(prog('pt_notch', [P([(-7.5, -4), (-7.5, 4), (0, 0), (7.5, 4), (7.5, -4)], 'BLACK')]), 0, 0, T1, 'BASE', 0)])+obj('PIT_SHINE', [719], NONE, 0, 0, [(prog('ps_sq', [R(-15, -1, -12, .5), R(-12, -1, -10.5, 8), R(-12, 7, -4, 8.5), R(-5.5, -1, -4, 8), R(-5.5, -1, 5.5, .5),+ R(4, -1, 5.5, 8), R(4, 7, 12, 8.5), R(10.5, -1, 12, 8), R(12, -1, 15, .5)]), 0, 0, B1, 'BASE', 0)], base=1)+obj('PIT_SHINE_CORNER', [721], NONE, 0, 0, [(prog('ps_corner', [R(-5, 3.5, 5, 5), R(3.5, -5, 5, 5)]), 0, 0, B1, 'BASE', 0)], base=1)+obj('PIT_SHINE_STAIR', [990], NONE, 0, 0, [(prog('ps_stair', [seg(-15, -15, -8, -8, 1.5), R(-8.75, -8.75, -7.25, 0), R(-8.75, -.75, 0, .75), seg(0, 0, 8, 8, 1.5),+ R(7.25, 8, 8.75, 15), R(8, 13.5, 15, 15)]), 0, 0, B1, 'BASE', 0)], base=1)+obj('PIT_SHINE_DIAG', [992], NONE, 0, 0, [(prog('ps_diag', [seg(-5, -5, 5, 5, 1.5)]), 0, 0, B1, 'BASE', 0)], base=1)++# ---------------------------------------------------------------- coloured spikes (outline in base, fill in detail)+def cspike(name, ids, w, h, hw, hh, edy=0):+ obj(name, ids, HAZARD, hw, hh, [(prog('cs_' + name.lower(), [P([(-w / 2, -h / 2), (0, h / 2), (w / 2, -h / 2)], 'BASE'),+ P([(-w / 2 + 3, -h / 2 + 2), (0, h / 2 - 4.5), (w / 2 - 3, -h / 2 + 2)], 'DETAIL')]), 0, 0, T1, 'BASE', 0),+ ('glow_spike', 0, 0, GL, 'GLOW', 0)], edy=edy, detail=1)+++cspike('CSPIKE', [216], 30, 30, 6, 12)+cspike('CSPIKE_SMALL', [218], 20, 19, 4, 7.6, -6)+cspike('CSPIKE_TINY', [458], 12.5, 12, 2.6, 4.8, -9)+obj('ISPIKE_TINY', [459], HAZARD, 2.6, 4.8, [(prog('is_tiny', [seg(-6, -6, 0, 6, 1.2), seg(0, 6, 6, -6, 1.2), R(-6, -6.6, 6, -5.4)]), 0, 0, T1, 'BASE', 0)], edy=-9, anim='INVIS')+obj('ISPIKE_HALF', [205], HAZARD, 6, 5.6, [(prog('is_half', [seg(-15, -6.75, 0, 6.75, 1.5), seg(0, 6.75, 15, -6.75, 1.5), R(-15, -7.5, 15, -6)]), 0, 0, T1, 'BASE', 0)], edy=-9, anim='INVIS')+obj('INVIS_SLAB', [147], SOLID, 30, 14, [(prog('is_slab', outline('tblr', 1.5, 7, 15)), 0, 0, T1, 'BASE', 0)], edy=8, anim='INVIS')++# ---------------------------------------------------------------- misc decoration+obj('WAVE_SQUARE', [1228], NONE, 0, 0, [(prog('w_square', [VG(-15, -15, 15, 15, 'BASE', .15, .45)]), 0, 0, B1, 'BASE', 0)], base=1007)+++def wave_box(inv):+ crest = [(-15, 6 if not inv else 13), (-7.5, 10 if not inv else 7), (0, 13 if not inv else 5.5), (7.5, 10 if not inv else 7), (15, 6 if not inv else 13)]+ ops = [VG(-15, -13, 15, 5.5, 'BASE', .55, .15)]+ for k in range(4):+ (xa, ya), (xb, yb) = crest[k], crest[k + 1]+ ops.append(P([(xa, 5.5), (xa, ya), (xb, yb), (xb, 5.5)], 'BASE', .55))+ return ops+++obj('CIRCLE_WAVE', [1050], NONE, 0, 0, [(prog('cw_box', wave_box(False)), 0, 0, B1, 'BASE', 0)], base=1007)+obj('CIRCLE_WAVE_INV', [1052], NONE, 0, 0, [(prog('cw_inv', wave_box(True)), 0, 0, B1, 'BASE', 0)], base=1007)+++def spike_wave(peaks):+ ops = [VG(-15, -12.75, 15, 3, 'BASE', .5, .15)]+ for (xa, xb, top) in peaks:+ ops.append(P([(xa, 3), ((xa + xb) / 2, top), (xb, 3)], 'BASE', .5))+ return ops+++obj('WATER1', [419], NONE, 0, 0, [(prog('water1', spike_wave([(-15, -5, 12.75), (-5, 5, 8), (5, 15, 12.75)])), 0, 0, B1, 'BASE', 0)], base=1007)+obj('WATER2', [420], NONE, 0, 0, [(prog('water2', spike_wave([(-15, 0, 11), (0, 15, 8)])), 0, 0, B1, 'BASE', 0)], base=1007)+obj('JAGGED_HALF', [767], NONE, 0, 0, [(prog('jagged', spike_wave([(-7.5, 7.5, 12)])), 0, 0, B1, 'BASE', 0)], base=1007)+obj('STRIPE_SLAB', [1054], NONE, 0, 0, [(prog('st_slab', [R(-15, -7.5, 15, 7.5, 'DETAIL')] + stripes(-20, 15, -7.5, 7.5, 4, 'BASE')), 0, 0, B1, 'BASE', 0)],+ base=1, detail=1010)+obj('PULSE_ARROW3', [494], NONE, 0, 0, [(prog('pa3', [P([(-11, -22), (11, 0), (-11, 22)], 'BASE')]), 0, 0, B1, 'BASE', F_PULSE)], base=1005)+obj('PULSE_TRIANGLE', [149], NONE, 0, 0, [(prog('ptri', [P([(-13, -11), (0, 11), (13, -11)], 'BASE')]), 0, 0, B1, 'BASE', F_PULSE)], base=1006)+++def link(lines):+ return [R(*l, 'BASE') for l in lines] + [P([(-2.5, 0), (0, 2.5), (2.5, 0), (0, -2.5)], 'DETAIL')]+++obj('LINK_ADJ', [1002], NONE, 0, 0, [(prog('lk_adj', link([(-1, 1, 1, 15), (1, -1, 15, 1)])), 0, 0, B1, 'BASE', 0)], base=1005, detail=1006)+obj('LINK_THREE', [1003], NONE, 0, 0, [(prog('lk_three', link([(-15, -1, 15, 1), (-1, -15, 1, -1)])), 0, 0, B1, 'BASE', 0)], base=1005, detail=1006)+obj('LINK_OPP', [1004], NONE, 0, 0, [(prog('lk_opp', link([(-15, -1, -4, 1), (4, -1, 15, 1)])), 0, 0, B1, 'BASE', 0)], base=1005, detail=1006)+obj('LINK_ONE', [1005], NONE, 0, 0, [(prog('lk_one', link([(-1, -15, 1, -4)])), 0, 0, B1, 'BASE', 0)], base=1005, detail=1006)+++def rays(n, r0, r1, w0, w1, a=.5):+ ops = []+ for k in range(n):+ t = 2 * math.pi * k / n+ c, s = math.cos(t), math.sin(t)+ pts = []+ for (r, w) in ((r0, w0), (r1, w1)):+ pts.append((c * r - s * w / 2, s * r + c * w / 2))+ for (r, w) in ((r1, w1), (r0, w0)):+ pts.append((c * r + s * w / 2, s * r - c * w / 2))+ ops.append(P(pts, 'BASE', a))+ mid = (r0 + r1) / 2+ ops.append(P([(c * r0 - s * w0 / 4, s * r0 + c * w0 / 4), (c * mid - s * w1 / 4, s * mid + c * w1 / 4), (c * mid + s * w1 / 4, s * mid - c * w1 / 4),+ (c * r0 + s * w0 / 4, s * r0 - c * w0 / 4)], 'BASE', a * .6))+ return ops+++obj('SHINE_L', [1019], NONE, 0, 0, [(prog('shine_l', rays(8, 12, 64, 4, 18, .35)), 0, 0, B1, 'BASE', 0)], base=1005, anim='SPIN')+obj('SHINE_M', [1020], NONE, 0, 0, [(prog('shine_m', rays(8, 10, 52, 3, 14, .35)), 0, 0, B1, 'BASE', 0)], base=1005, anim='SPIN')++# sprite based decoration (sprites_lv.py)+obj('SPLIT_CIRCLE_L', [997], NONE, 0, 0, [('ringseg_l', 0, 0, B1, 'BASE', F_QUAD)], base=1005, anim='SPIN')+obj('SPLIT_CIRCLE_M', [998], NONE, 0, 0, [('ringseg_m', 0, 0, B1, 'BASE', F_QUAD)], base=1005, anim='SPIN')+obj('SPLIT_CIRCLE_S', [999], NONE, 0, 0, [('ringseg_s', 0, 0, B1, 'BASE', F_QUAD)], base=1005, anim='SPIN')+obj('SPLIT_CIRCLE_XS', [1000], NONE, 0, 0, [('ringseg_xs', 0, 0, B1, 'BASE', F_QUAD)], base=1005, anim='SPIN')+obj('SWIRL_L', [1058], NONE, 0, 0, [('swirl_l', 0, 0, B1, 'BASE', 0)], base=1007, anim='SPIN')+obj('SWIRL_M', [1059], NONE, 0, 0, [('swirl_m', 0, 0, B1, 'BASE', 0)], base=1007, anim='SPIN')+obj('PICKUP_RING1', [1055], NONE, 0, 0, [('pickup_ring1', 0, 0, B1, 'BASE', F_PULSE)], base=1007, anim='SPIN')+obj('PICKUP_RING2', [1056], NONE, 0, 0, [('pickup_ring2', 0, 0, B1, 'BASE', F_PULSE)], base=1007, anim='SPIN')+obj('PICKUP_RING4', [1057], NONE, 0, 0, [('pickup_ring4', 0, 0, B1, 'BASE', F_PULSE)], base=1007, anim='SPIN')+obj('FIRE_LARGE', [920], NONE, 0, 0, [('fire_l', 0, 0, T1, 'BASE', 0), ('fire_l_in', 0, -4, T1, 'DETAIL', 0)], base=1011, detail=1, anim='FLAME')+obj('FIRE_BURST', [921], NONE, 0, 0, [('fire_burst', 0, 0, T1, 'BASE', 0), ('fire_burst_in', 0, -6, T1, 'DETAIL', 0)], base=1011, detail=1, anim='FLAME')+obj('FIRE_THIN1', [923], NONE, 0, 0, [('fire_t1', 0, 0, T1, 'BASE', 0), ('fire_t1_in', 0, -4, T1, 'DETAIL', 0)], base=1011, detail=1, anim='FLAME')+obj('FIRE_THIN2', [924], NONE, 0, 0, [('fire_t2', 0, 0, T1, 'BASE', 0), ('fire_t2_in', 0, -4, T1, 'DETAIL', 0)], base=1011, detail=1, anim='FLAME')++# ---------------------------------------------------------------- hazards with sprites+obj('COGSAW_L', [675], HAZARD, 32, 32, [('cogsaw_l', 0, 0, T1, 'BLACK', F_QUAD), ('cogsaw_l_ring', 0, 0, T1, 'BASE', F_QUAD)], shape='CIRCLE', anim='SAW')+obj('COGSAW_M', [676], HAZARD, 17.68, 17.68, [('cogsaw_m', 0, 0, T1, 'BLACK', 0), ('cogsaw_m_ring', 0, 0, T1, 'BASE', 0)], shape='CIRCLE', anim='SAW')+obj('COGSAW_S', [677], HAZARD, 12.48, 12.48, [('cogsaw_s', 0, 0, T1, 'BLACK', 0), ('cogsaw_s_ring', 0, 0, T1, 'BASE', 0)], shape='CIRCLE', anim='SAW')+obj('DARKBLADE_L', [397], HAZARD, 28.9, 28.9, [('darkblade_l', 0, 0, T1, 'BLACK', F_QUAD), ('darkblade_l_core', 0, 0, T1, 'BASE', 0)], shape='CIRCLE', anim='SAW', detail=1)+obj('DARKBLADE_M', [398], HAZARD, 17.6, 17.6, [('darkblade_m', 0, 0, T1, 'BLACK', 0), ('darkblade_m_core', 0, 0, T1, 'BASE', 0)], shape='CIRCLE', anim='SAW', detail=1)+obj('BEAST', [918], HAZARD, 24, 24, [('beast_top', 0, 8, T1, 'BASE', F_ANIM), ('beast_bot', 0, -14, T1, 'BASE', F_ANIM), ('beast_eye', 18, 12, T1, 'DETAIL', 0)],+ shape='CIRCLE', anim='CHOMP', base=1010, detail=1011)++# ---------------------------------------------------------------- portals, rings and collectables+obj('SPEED_SLOW', [200], SPECIAL, 35, 44, [('speed0', 0, 0, 'PORTAL_FRONT', 'WHITE', 0)], special='SPEED_0')+obj('SPEED_NORMAL', [201], SPECIAL, 33, 56, [('speed1', 0, 0, 'PORTAL_FRONT', 'WHITE', 0)], special='SPEED_1')+obj('SPEED_FAST', [202], SPECIAL, 51, 56, [('speed2', 0, 0, 'PORTAL_FRONT', 'WHITE', 0)], special='SPEED_2')+obj('SPEED_FASTER', [203], SPECIAL, 65, 56, [('speed3', 0, 0, 'PORTAL_FRONT', 'WHITE', 0)], special='SPEED_3')+obj('WAVE_PORTAL', [660], SPECIAL, 34, 86, [('portal_wave_front', 5, 0, 'PORTAL_FRONT', 'WHITE', 0), ('portal_wave_back', -6, 0, 'PORTAL_BACK', 'WHITE', 0)], special='PORTAL_WAVE')+obj('ROBOT_PORTAL', [745], SPECIAL, 34, 86, [('portal_robot_front', 5, 0, 'PORTAL_FRONT', 'WHITE', 0), ('portal_robot_back', -6, 0, 'PORTAL_BACK', 'WHITE', 0)], special='PORTAL_ROBOT')+obj('DUAL_PORTAL', [286], SPECIAL, 41, 91, [('portal_dual_front', 5, 0, 'PORTAL_FRONT', 'WHITE', 0), ('portal_dual_back', -6, 0, 'PORTAL_BACK', 'WHITE', 0)], special='DUAL_ON')+obj('DUAL_EXIT', [287], SPECIAL, 41, 91, [('portal_single_front', 5, 0, 'PORTAL_FRONT', 'WHITE', 0), ('portal_single_back', -6, 0, 'PORTAL_BACK', 'WHITE', 0)], special='DUAL_OFF')+obj('TELEPORT', [747], SPECIAL, 25, 90, [('portal_tele_front', 5, 0, 'PORTAL_FRONT', 'WHITE', 0), ('portal_tele_back', -6, 0, 'PORTAL_BACK', 'WHITE', 0)],+ special='TELEPORT', hx=12)+obj('ORB_GREEN', [1022], SPECIAL, 36, 36, [('orb_green', 0, 0, 'SPECIAL', 'WHITE', F_PULSE), ('glow_orb_green', 0, 0, 'SPECIAL_GLOW', 'GLOW_Y', 0)], special='ORB_G')+obj('KEY', [1275], SPECIAL, 25, 20, [('key', 0, 0, 'COIN', 'BASE', 0), ('key_detail', 0, 0, 'COIN', 'DETAIL', 0)], special='KEY', base=1, detail=1011)+obj('KEYHOLE', [1276], NONE, 0, 0, [('keyhole', 0, 0, T1, 'BASE', 0), ('keyhole_detail', 0, 0, T1, 'DETAIL', 0)], base=1, detail=1012)++# reach of the big ones (units), for streaming+RADIUS = {'GLOW_OUTER_L': 45, 'OUT_WSLOPE': 50, 'BLOCK_WSLOPE': 50, 'DECO_WSLOPE': 50, 'NEON_WSLOPE': 50, 'SHINE_L': 80, 'SHINE_M': 70,+ 'SPLIT_CIRCLE_L': 70, 'SPLIT_CIRCLE_M': 60, 'SPLIT_CIRCLE_S': 50, 'COGSAW_L': 50, 'DARKBLADE_L': 50, 'BEAST': 60, 'FIRE_LARGE': 55,+ 'FIRE_BURST': 50, 'TELEPORT': 60, 'DUAL_PORTAL': 50, 'DUAL_EXIT': 50, 'SPEED_FASTER': 45}