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.

Hill Climb Racing: the end of a run draws the planks and trees it kept

Mason363d128fc416d82
diff --git a/games/hillclimb/src/car.cpp b/games/hillclimb/src/car.cpp
index 20907aa5..2237eaba 100644
--- a/games/hillclimb/src/car.cpp
+++ b/games/hillclimb/src/car.cpp
@@ -1173,8 +1173,16 @@ extern "C" void car_init(Car *c, int veh, const uint8_t levels[4]) {
snapshot(c, FLIP_NONE);
}
+/* the bridges' planks and the trees as they were when the world went (run_finish): the end of a run still draws them */
+static CarBody kept_planks[2 * MAXPLANK], kept_trees[MAXTREE];
+static int kept_which[MAXTREE], nkept_planks, nkept_trees;
+
extern "C" void car_free(void) {
- if (W) W->~b2World();
+ if (W) {
+ nkept_planks = car_planks(kept_planks, 2 * MAXPLANK);
+ nkept_trees = car_trees(kept_trees, kept_which, MAXTREE);
+ W->~b2World();
+ }
W = NULL;
}
@@ -1264,6 +1272,10 @@ extern "C" void car_numbers(float out[12]) {
extern "C" int car_planks(CarBody *out, int most) {
int n = 0;
+ if (!W) { /* (the world gone: as they were) */
+ for (; n < nkept_planks && n < most; n++) out[n] = kept_planks[n];
+ return n;
+ }
for (int i = 0; i < 2; i++)
for (int j = 0; j < bridges[i].n && n < most; j++, n++) {
b2Body *p = bridges[i].plank[j];
@@ -1274,6 +1286,10 @@ extern "C" int car_planks(CarBody *out, int most) {
extern "C" int car_trees(CarBody *out, int *which, int most) {
int n = 0;
+ if (!W) {
+ for (; n < nkept_trees && n < most; n++) out[n] = kept_trees[n], which[n] = kept_which[n];
+ return n;
+ }
for (int i = 0; i < MAXTREE && n < most; i++) {
if (trees[i].k < 0) continue;
which[n] = trees[i].k;
diff --git a/games/hillclimb/src/car.h b/games/hillclimb/src/car.h
index faaa81ab..c17b0543 100644
--- a/games/hillclimb/src/car.h
+++ b/games/hillclimb/src/car.h
@@ -48,7 +48,7 @@ typedef struct {
void car_init(Car *c, int veh, const uint8_t levels[4]);
/* one 1/60 s: gas (1), brake (-1) or neither (0); engine: there is fuel and Bill is alive */
void car_step(Car *c, int pedal, bool engine);
-/* the world's memory back (a run ends) */
+/* the world's memory back (a run ends): car_planks and car_trees then give the planks and trees as they last were */
void car_free(void);
/* a picture frame point (meters, the chassis' frame) in the world */
void car_point(const Car *c, float lx, float ly, float *wx, float *wy);
diff --git a/games/hillclimb/tests/check.py b/games/hillclimb/tests/check.py
index 60178db8..efb9f706 100644
--- a/games/hillclimb/tests/check.py
+++ b/games/hillclimb/tests/check.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Checks of Hill Climb Racing on a computer (make test): the host build, with AddressSanitizer and UBSan, through
the menus, buying, every stage's ground, every stage with every vehicle, each vehicle's numbers, how often the ground
-is worked out, the ends of a run, the saves (and the old versions' carried over) and random keys.
+is worked out, the ends of a run (drawn too), the saves (and the old versions' carried over) and random keys.
python3 tests/check.py build/play [--quick]"""
import os
@@ -233,6 +233,16 @@ def main():
check(s["mode"] == MODE_END and s["end"] == 1, f"reversing into the wall did not run out of fuel: {s}")
shutil.rmtree(d, ignore_errors=True)
+ # the end of a run, drawn: the bridges' planks (the Arctic Cave) and a knocked tree (the Forest) as they were when
+ # the run's world went (they were read from it after it was freed)
+ for st, args in (("the Arctic Cave", ["--run", "8,8", "--levels", "12,12,12,10", "--auto", "--frames", "2400"]),
+ ("the Forest", ["--run", "9,1", "--keys", "0-1500:right", "--frames", "1700"])):
+ d = fresh()
+ s = run(args + ["--draw"], d, f"the end of a run on {st}, drawn")
+ if s:
+ check(s["mode"] == MODE_END, f"the run on {st} did not end: {s}")
+ shutil.rmtree(d, ignore_errors=True)
+
# a long run: levels reached, coins collected, the best kept
d = fresh()
s = run(["--run", "0,0", "--levels", "10,10,10,8", "--auto", "--frames", "9000"], d, "a long run")