Skip to content

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.

Subway Surfers: tunnels, sparkles, a shake on a crash, still screens drawn once

Mason3632fe517d168a5
diff --git a/games/subway/src/app.c b/games/subway/src/app.c
index 0d361def..6874f921 100644
--- a/games/subway/src/app.c
+++ b/games/subway/src/app.c
@@ -22,6 +22,7 @@ static int shop_tab, shop_sel, shop_top;
static char note[40]; /* the shop's word on the last try */
static float note_t;
static float cam_x, cam_y; /* the run's camera, smoothed */
+static bool drawn; /* a screen that does not move is drawn once, then again when something changes */
#define CAM_Y 6.0f /* above the ground */
#define CAM_BACK 7.6f /* behind the runner */
@@ -62,6 +63,7 @@ static bool title_scene(void) {
}
static void go(int s) {
+ drawn = false;
state = s;
state_t = 0;
sel = 0;
@@ -168,6 +170,7 @@ static void camera_follow(void) {
}
void app_step(uint32_t keys, uint32_t pressed) {
+ if (pressed) drawn = false;
clock += DT;
state_t += DT;
if (note_t > 0) note_t -= DT;
@@ -330,6 +333,20 @@ static void draw_runner(void) {
}
}
+/* coins picked up: a star of light that grows and fades, carried along with the runner */
+static void draw_sparks(void) {
+ for (int i = 0; i < NSPARKS; i++) {
+ const Spark *s = &sparks[i];
+ if (s->t >= 0.3f) continue;
+ float k = s->t / 0.3f, r = 0.25f + 0.55f * k, x = pl.x + (s->x - pl.x) * 0.4f, y = s->y, z = pl.z + 0.4f;
+ int a = (int)(230 * (1 - k));
+ V3 h[4] = {{x - r, y + 0.07f, z}, {x + r, y + 0.07f, z}, {x + r, y - 0.07f, z}, {x - r, y - 0.07f, z}};
+ V3 v[4] = {{x - 0.07f, y + r, z}, {x + 0.07f, y + r, z}, {x + 0.07f, y - r, z}, {x - 0.07f, y - r, z}};
+ r_poly(h, 4, 0xFFF6B0, P_ALPHA | P_NOHAZE | P_TWOSIDED, a);
+ r_poly(v, 4, 0xFFF6B0, P_ALPHA | P_NOHAZE | P_TWOSIDED, a);
+ }
+}
+
static void draw_world(void) {
r_begin();
bool title = title_scene();
@@ -338,10 +355,18 @@ static void draw_world(void) {
else {
/* the camera swings round from the title's view */
float k = intro >= 1 ? 1 : intro * intro * (3 - 2 * intro), pitch = 0.34f + (pl.fly > 0 ? 0.05f : 0);
- scene_camera(lerp(tx, cam_x, k), lerp(ty, cam_y, k), lerp(tz, pl.z - CAM_BACK, k), lerp(tp, pitch, k));
+ /* a shake when the runner crashes */
+ float shake = 0;
+ if (pl.dead && pl.crash_t < 0.35f) {
+ float s, c;
+ r_sincos(pl.crash_t * 70, &s, &c);
+ shake = s * 0.18f * (1 - pl.crash_t / 0.35f);
+ }
+ scene_camera(lerp(tx, cam_x, k) + shake, lerp(ty, cam_y, k) + shake * 0.5f, lerp(tz, pl.z - CAM_BACK, k), lerp(tp, pitch, k));
}
scene_draw(clock);
draw_runner();
+ if (!title) draw_sparks();
}
/* ---------------------------------------------------------------- drawing: over the picture */
@@ -743,6 +768,10 @@ void app_draw(void) {
draw_shop();
return;
}
+ /* the screens over a picture that stands still */
+ bool still = state == S_RESULTS || state == S_PAUSE || state == S_QUIT || state == S_MISSIONS || state == S_HELP;
+ if (still && drawn && state_t > 0.5f) return;
+ drawn = true;
draw_world();
perf_polys = (uint32_t)r_count();
r_render(scene_background, overlay);
diff --git a/games/subway/src/game.c b/games/subway/src/game.c
index 2ce5f70f..67044997 100644
--- a/games/subway/src/game.c
+++ b/games/subway/src/game.c
@@ -17,6 +17,8 @@
Runner pl;
Run run;
Progress pg;
+Spark sparks[NSPARKS];
+static int next_spark;
const char *const char_names[NCHARS] = {"Jake", "Tricky", "Fresh", "Spike"};
const uint32_t char_price[NCHARS] = {0, 6000, 12000, 20000};
@@ -202,6 +204,7 @@ void missions_check(void) {
void run_start(void) {
memset(&run, 0, sizeof run);
memset(&pl, 0, sizeof pl);
+ for (int i = 0; i < NSPARKS; i++) sparks[i].t = 1;
pl.lane = pl.from_lane = 1;
pl.speed = 13;
pl.chase = 3.2f; /* the Inspector and his dog, right behind from the start */
@@ -276,6 +279,8 @@ static void stumble(void) {
}
static void collect(Item *it) {
+ Spark *sp = &sparks[next_spark++ % NSPARKS];
+ sp->x = it->x, sp->y = it->y, sp->z = it->z, sp->t = 0;
switch (it->kind) {
case I_COIN:
run.coins++;
@@ -357,6 +362,8 @@ static void collide(float prev_x) {
void run_step(uint32_t keys, uint32_t pressed) {
(void)keys;
if (run.toast_t > 0) run.toast_t -= DT;
+ for (int i = 0; i < NSPARKS; i++)
+ if (sparks[i].t < 1) sparks[i].t += DT;
if (pl.dead) {
pl.crash_t += DT;
if (pl.y > pl.ground) pl.y -= 4 * DT;
@@ -364,6 +371,9 @@ void run_step(uint32_t keys, uint32_t pressed) {
}
run.start_t += DT;
pl.t += DT;
+#ifdef SS_GOD
+ pl.safe = 0.1f; /* (a build for measuring speed: nothing hurts) */
+#endif
/* faster and faster: from 13 m/s towards 26 */
pl.speed = 13 + 13 * pl.t / (pl.t + 100);
float speed = pl.speed;
diff --git a/games/subway/src/game.h b/games/subway/src/game.h
index 08e65a4f..01137b3a 100644
--- a/games/subway/src/game.h
+++ b/games/subway/src/game.h
@@ -96,6 +96,13 @@ typedef struct {
} Run;
extern Run run;
+/* the sparkle of a coin picked up */
+typedef struct {
+ float x, y, z, t; /* t: its age, from 0 */
+} Spark;
+#define NSPARKS 12
+extern Spark sparks[NSPARKS];
+
void run_start(void);
void run_step(uint32_t keys, uint32_t pressed);
bool run_over(void); /* caught or crashed, and not saved */
diff --git a/games/subway/src/scene.c b/games/subway/src/scene.c
index b5d30c56..66aaa762 100644
--- a/games/subway/src/scene.c
+++ b/games/subway/src/scene.c
@@ -400,25 +400,27 @@ static void tunnel_block(float z0, float dist) {
}
if (first) {
/* the way in: a big face of brick round the opening, with a frame */
- uint32_t brick = 0x9A5A44, trim = 0x6E6A64, top = 0x7E4636;
- front(z0, -60, -WALL_X, 0, 24, brick, 0);
- front(z0, WALL_X, 60, 0, 24, brick, 0);
- front(z0, -WALL_X, WALL_X, 7.2f, 24, brick, 0);
- /* a band of darker brick on top, and a frame round the opening */
- front(z0, -60, 60, 21, 24, top, P_DECAL);
+ uint32_t brick = 0x9A5A44, trim = 0x6E6A64, line = 0x84493A, top = 0x6E3E30;
+ front(z0, -60, -WALL_X, 0, 13, brick, 0);
+ front(z0, WALL_X, 60, 0, 13, brick, 0);
+ front(z0, -WALL_X, WALL_X, 7.2f, 13, brick, 0);
+ /* courses of brick, a darker band on top, a frame round the opening */
+ if (dist < 110) {
+ for (int i = 1; i <= 4; i++) {
+ float y = 1.5f * (float)i;
+ front(z0, -60, -WALL_X - 0.9f, y, y + 0.12f, line, P_DECAL);
+ front(z0, WALL_X + 0.9f, 60, y, y + 0.12f, line, P_DECAL);
+ }
+ front(z0, -60, 60, 10.9f, 11.02f, line, P_DECAL);
+ }
+ front(z0, -60, 60, 11.6f, 13, top, P_DECAL);
front(z0, -WALL_X - 0.9f, -WALL_X, 0, 8.1f, trim, P_DECAL);
front(z0, WALL_X, WALL_X + 0.9f, 0, 8.1f, trim, P_DECAL);
front(z0, -WALL_X - 0.9f, WALL_X + 0.9f, 7.2f, 8.1f, trim, P_DECAL);
/* the subway's sign over it */
- front(z0, -3.0f, 3.0f, 10.0f, 12.4f, 0x1A1A22, P_DECAL);
- front(z0, -2.8f, 2.8f, 10.2f, 12.2f, 0x2E5FA8, P_DECAL2);
- for (int i = 0; i < 3; i++) front(z0, -2.2f + 1.6f * (float)i, -1.2f + 1.6f * (float)i, 10.7f, 11.7f, 0xF4F4F4, P_DECAL3);
- if (dist < 100)
- for (int i = 0; i < 6; i++) {
- /* lamps along the top */
- float x = -15 + 6 * (float)i;
- front(z0, x - 0.4f, x + 0.4f, 18, 18.8f, 0xFFF2B0, P_DECAL | P_NOHAZE);
- }
+ front(z0, -3.0f, 3.0f, 8.5f, 10.5f, 0x1A1A22, P_DECAL);
+ front(z0, -2.8f, 2.8f, 8.7f, 10.3f, 0x2E5FA8, P_DECAL2);
+ for (int i = 0; i < 3; i++) front(z0, -2.2f + 1.6f * (float)i, -1.2f + 1.6f * (float)i, 9.1f, 9.9f, 0xF4F4F4, P_DECAL3);
}
}