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: rope bridges, pine trees, gentler air control, wrapped garage texts

Mason36353ffb02afea1
diff --git a/games/hillclimb/src/car.c b/games/hillclimb/src/car.c
index fdcb422b..3f35e2fe 100644
--- a/games/hillclimb/src/car.c
+++ b/games/hillclimb/src/car.c
@@ -53,7 +53,7 @@ void car_init(Car *c, int veh, const uint8_t lv[4], float x) {
case UP_SUSPENSION: sus = f; break;
case UP_TIRES: case UP_TRACKS: tir = f; break;
case UP_AWD: awd = f; break;
- case UP_AIR: air *= 1 + 2.4f * f; break;
+ case UP_AIR: air *= 1 + 1.5f * f; break;
case UP_DOWNFORCE: down = d->downforce * f; break;
}
}
@@ -374,7 +374,7 @@ void car_step(Car *c, float gas, float brake, bool fuel) {
}
if (air && !c->touch && !c->head_hit) c->ch.w += c->air * (gas - brake) * c->ch.ii * DT;
/* a little air: nothing spins forever */
- c->ch.w *= 1 - 0.15f * DT;
+ c->ch.w *= 1 - 0.3f * DT;
find_contacts(c);
prepare_contacts();
prepare_joints(c, gas, brake, fuel);
diff --git a/games/hillclimb/src/game.c b/games/hillclimb/src/game.c
index 00605977..d20610cb 100644
--- a/games/hillclimb/src/game.c
+++ b/games/hillclimb/src/game.c
@@ -6,6 +6,7 @@
int g_mode;
bool g_running = true;
+bool g_nohud; /* (pictures for the README: the road without the dashboard) */
uint32_t g_frame;
static uint32_t held;
static int pause_sel, pause_ask, end_t;
@@ -140,7 +141,7 @@ void game_frame(uint32_t keys) {
void game_draw(void) {
gfx_begin();
switch (g_mode) {
- case MODE_RUN: run_draw(true); break;
+ case MODE_RUN: run_draw(!g_nohud); break;
case MODE_PAUSE: pause_draw(); break;
case MODE_END: end_draw(); break;
default: menu_draw(); break;
diff --git a/games/hillclimb/src/game.h b/games/hillclimb/src/game.h
index 6d384534..886d5490 100644
--- a/games/hillclimb/src/game.h
+++ b/games/hillclimb/src/game.h
@@ -66,7 +66,7 @@ typedef struct {
extern Run run;
extern int g_mode;
-extern bool g_running;
+extern bool g_running, g_nohud;
extern uint32_t g_frame;
void game_init(void);
diff --git a/games/hillclimb/src/menu.c b/games/hillclimb/src/menu.c
index bc338e4c..548c2214 100644
--- a/games/hillclimb/src/menu.c
+++ b/games/hillclimb/src/menu.c
@@ -187,6 +187,28 @@ static void help_draw(void) {
if ((t / 25) % 2 == 0) gfx_text(FONT_M, 160, 224, sv.seen_help ? "OK" : "OK: DRIVE!", rgb565(0xFFE14A), C_BLACK, 1);
}
+/* a text in lines of at most width pixels, centred on cx, 13 pixels apart */
+static void wrapped(int cx, int y, int width, const char *s) {
+ char line[96];
+ while (*s) {
+ int n = 0, fit = 0;
+ for (;;) {
+ while (s[n] && s[n] != ' ') n++;
+ if (n >= (int)sizeof line) break;
+ memcpy(line, s, (size_t)n), line[n] = 0;
+ if (gfx_text_width(FONT_S, line) > width && fit) break;
+ fit = n;
+ if (!s[n]) break;
+ n++;
+ }
+ memcpy(line, s, (size_t)fit), line[fit] = 0;
+ gfx_text(FONT_S, cx, y, line, rgb565(0xC8CDD4), C_BLACK, 1);
+ s += fit;
+ while (*s == ' ') s++;
+ y += 13;
+ }
+}
+
static void level_bar(int x, int y, int w, int level, int max) {
gfx_rrect(x, y, w, 7, 3, C_BLACK, 200);
int f = (w - 2) * (level - 1) / (max - 1 > 0 ? max - 1 : 1);
@@ -206,7 +228,7 @@ static void garage_draw(void) {
char tx[48];
if (!owned) {
price_tag(160, 176, v->price, sv.coins >= v->price);
- gfx_text(FONT_S, 160, 196, v->about, rgb565(0xC8CDD4), C_BLACK, 1);
+ wrapped(160, 196, 296, v->about);
gfx_text(FONT_S, 160, 230, sv.coins >= v->price ? "OK: buy" : "Not enough coins yet", flash ? rgb565(0xFF5A4A) : C_WHITE,
C_BLACK, 1);
return;
@@ -226,8 +248,9 @@ static void garage_draw(void) {
else {
char n[20];
format_number(n, upgrade_cost(shown, u, lv + 1));
- gfx_text(FONT_S, x + 37, y + 68, n, sv.coins >= upgrade_cost(shown, u, lv + 1) ? rgb565(0xFFE14A) : rgb565(0xFF7A6A),
- C_BLACK, 1);
+ bool can = sv.coins >= upgrade_cost(shown, u, lv + 1);
+ gfx_text(FONT_S, x + 37, y + 68, n, on ? (can ? C_BLACK : rgb565(0xA01010)) : can ? rgb565(0xFFE14A) : rgb565(0xFF7A6A),
+ on ? rgb565(0xF2B531) : C_BLACK, 1);
}
}
if (row == 0) gfx_text(FONT_S, 160, 236 - 74, "", C_WHITE, C_BLACK, 1);
diff --git a/games/hillclimb/src/vehicle.c b/games/hillclimb/src/vehicle.c
index 8d57beea..ba3eee24 100644
--- a/games/hillclimb/src/vehicle.c
+++ b/games/hillclimb/src/vehicle.c
@@ -16,14 +16,14 @@ const VehDef vehicles[NVEHICLES] = {
300, 24, {0.02f, 0.38f}, 0.95f, 0.14f, 0.16f, 0.55f, 430, 11.0f, 0, 0.95f, 760, 40, 0},
{"Motocross Bike", "Race the hills with this impressive turboed motocross bike.", 75000, IMG_ICON_BIKE,
{UP_ENGINE, UP_SUSPENSION, UP_TIRES, UP_AIR}, {12, 14, 16, 10}, {1500, 1000, 1000, 3000},
- 150, 14, {-0.05f, 0.55f}, 0.62f, 0.13f, 0.18f, 0.5f, 230, 13.0f, 0, 1.0f, 300, 40, 0},
+ 150, 14, {-0.05f, 0.55f}, 0.62f, 0.13f, 0.18f, 0.5f, 230, 13.0f, 0, 1.0f, 160, 40, 0},
{"Monster Truck", "With large wheels and a supercharged engine this car really gives a new experience for Hill "
"Climbing!", 100000, IMG_ICON_MONSTER,
{UP_ENGINE, UP_SUSPENSION, UP_TIRES, UP_AWD}, {13, 14, 15, 10}, {1500, 1200, 1200, 1500},
- 340, 48, {0.0f, 0.45f}, 1.05f, 0.26f, 0.3f, 0.45f, 820, 11.5f, 0, 1.0f, 1500, 40, 0},
+ 340, 48, {0.0f, 0.45f}, 1.05f, 0.26f, 0.3f, 0.45f, 820, 11.5f, 0, 1.0f, 1100, 40, 0},
{"Quad Bike", "4x4 quad bike with almost the same agility as the bike offers you a different ride.", 175000,
IMG_ICON_QUAD, {UP_ENGINE, UP_SUSPENSION, UP_TIRES, UP_AIR}, {13, 14, 16, 10}, {1500, 1200, 1200, 2500},
- 190, 20, {0.0f, 0.5f}, 0.7f, 0.18f, 0.22f, 0.5f, 300, 12, 1.0f, 1.0f, 520, 40, 0},
+ 190, 20, {0.0f, 0.5f}, 0.7f, 0.18f, 0.22f, 0.5f, 300, 12, 1.0f, 1.0f, 260, 40, 0},
{"Race Car", "High power and aerodynamic ultimate hill climbing vehicle. Upgrade downforce to make this car "
"follow the road like a magnet.", 250000, IMG_ICON_RACE,
{UP_ENGINE, UP_SUSPENSION, UP_TIRES, UP_DOWNFORCE}, {12, 14, 16, 12}, {1500, 1500, 1500, 2500},
@@ -34,7 +34,7 @@ const VehDef vehicles[NVEHICLES] = {
320, 22, {0.05f, 0.3f}, 1.0f, 0.11f, 0.13f, 0.6f, 560, 16, 0.6f, 1.05f, 1000, 40, 8.0f},
{"Dune Buggy", "Quick, good traction and handy hill climbing vehicle!", 800000, IMG_ICON_BUGGY,
{UP_ENGINE, UP_SUSPENSION, UP_TIRES, UP_FUEL}, {15, 15, 15, 20}, {3000, 3000, 3000, 3000},
- 260, 22, {0.1f, 0.32f}, 0.95f, 0.17f, 0.22f, 0.5f, 520, 15, 0.8f, 1.15f, 900, 52, 0},
+ 260, 22, {0.1f, 0.32f}, 0.95f, 0.17f, 0.22f, 0.5f, 520, 15, 0.8f, 1.15f, 700, 52, 0},
{"Tank", "It's a tank!", 1000000, IMG_ICON_TANK,
{UP_ENGINE, UP_SUSPENSION, UP_TRACKS, UP_FUEL}, {15, 15, 15, 20}, {3000, 3000, 3000, 3000},
900, 30, {0.0f, 0.42f}, 1.15f, 0.08f, 0.1f, 0.7f, 520, 8.0f, 1.0f, 1.45f, 2600, 40, 0},
diff --git a/games/hillclimb/tests/play.c b/games/hillclimb/tests/play.c
index 1974c65c..ca651311 100644
--- a/games/hillclimb/tests/play.c
+++ b/games/hillclimb/tests/play.c
@@ -22,7 +22,7 @@ void host_save_dir(const char *d);
typedef struct { int a, b; uint32_t k; } Hold;
static Hold holds[4096];
static int nholds;
-static int shots[4096], nshots, every;
+static int shots[4096], nshots, every, every_from, every_to = 1 << 30;
static uint32_t key_of(const char *s) {
static const char *const names[] = {"left", "right", "up", "down", "ok", "back", "home"};
@@ -45,6 +45,7 @@ static void parse_keys(const char *spec) {
}
/* a driver: gas, and in the air the pedals to land level with the ground ahead */
+static bool flipper; /* --flips: backflips in the air when there is time */
static uint32_t autopilot(void) {
const Car *c = &run.car;
if (run.over) return 0;
@@ -54,7 +55,12 @@ static uint32_t autopilot(void) {
while (a < -3.14159f) a += 6.28318f;
float d = a - slope;
if (car_airborne(c)) {
- if (d > 0.25f) return K_LEFT;
+ if (flipper && run.air_rot < 2.4f) { /* time left in the air against the turn still to make */
+ float h = c->ch.y - stage_floor(c->ch.x), g = stage->gravity, vy = c->ch.vy;
+ float left = (vy + sqrtf(vy * vy + 2 * g * (h > 0 ? h : 0))) / g, w = c->ch.w > 2 ? c->ch.w : 2;
+ if (left > (6.28f - run.air_rot) / w + 0.25f) return K_RIGHT;
+ }
+ if (d > 0.25f || (c->ch.w > 1.2f && d > -0.9f)) return K_LEFT;
if (d < -0.35f) return K_RIGHT;
return 0;
}
@@ -76,6 +82,7 @@ int main(int argc, char **argv) {
else if (!strcmp(argv[i], "--shots")) {
const char *s = argv[++i];
if (!strncmp(s, "every:", 6)) every = atoi(s + 6);
+ else if (strchr(s, '-') && strchr(s, ':')) sscanf(s, "%d-%d:%d", &every_from, &every_to, &every);
else
for (const char *p = s; *p;) {
shots[nshots++] = atoi(p);
@@ -88,6 +95,8 @@ int main(int argc, char **argv) {
else if (!strcmp(argv[i], "--levels")) sscanf(argv[++i], "%d,%d,%d,%d", &levels[0], &levels[1], &levels[2], &levels[3]);
else if (!strcmp(argv[i], "--coins")) coins = atol(argv[++i]);
else if (!strcmp(argv[i], "--auto")) autop = true;
+ else if (!strcmp(argv[i], "--nohud")) g_nohud = true;
+ else if (!strcmp(argv[i], "--flips")) autop = flipper = true;
else if (!strcmp(argv[i], "--trace")) trace = atoi(argv[++i]);
else if (!strcmp(argv[i], "--things")) { /* where the first bridges, tunnels and fuel cans of a stage are */
stage_set(atoi(argv[++i]));
@@ -136,7 +145,7 @@ int main(int argc, char **argv) {
host_keys = k;
game_frame(k);
host_time += 17;
- bool shot = every ? f % every == 0 : false;
+ bool shot = every && f >= every_from && f <= every_to ? (f - every_from) % every == 0 : false;
for (int i = 0; i < nshots; i++) shot |= shots[i] == f;
if (shot) {
game_draw();
diff --git a/games/hillclimb/tools/gif.py b/games/hillclimb/tools/gif.py
new file mode 100644
index 00000000..836947a7
--- /dev/null
+++ b/games/hillclimb/tools/gif.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+"""Frames of tests/play (PPM screenshots) into a GIF with one palette for all of them.
+
+ python3 -I tools/gif.py OUT.gif FPS [--scale 2] a.ppm b.ppm ... (or folders: their frames in order)"""
+import glob
+import os
+import sys
+
+from PIL import Image
+
+
+def main():
+ args = sys.argv[1:]
+ out, fps = args[0], float(args[1])
+ scale = 1
+ if args[2] == "--scale":
+ scale = int(args[3])
+ args = args[:2] + args[4:]
+ files = []
+ for a in args[2:]:
+ files += sorted(glob.glob(os.path.join(a, "*.ppm"))) if os.path.isdir(a) else [a]
+ frames = [Image.open(f).convert("RGB") for f in files]
+ if scale != 1:
+ frames = [f.resize((f.width * scale, f.height * scale), Image.NEAREST) for f in frames]
+ # one palette from frames spread over the whole animation
+ step = max(1, len(frames) // 24)
+ sample = frames[::step]
+ w, h = sample[0].size
+ sheet = Image.new("RGB", (w, h * len(sample)))
+ for i, f in enumerate(sample):
+ sheet.paste(f, (0, i * h))
+ pal = sheet.quantize(colors=255, method=Image.MEDIANCUT, dither=Image.NONE)
+ q = [f.quantize(palette=pal, dither=Image.NONE) for f in frames]
+ q[0].save(out, save_all=True, append_images=q[1:], duration=int(round(1000 / fps)), loop=0, optimize=True)
+ print(f"{out}: {len(q)} frames, {os.path.getsize(out)} bytes")
+
+
+if __name__ == "__main__":
+ main()