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.

Crossy Road: characters and the prize machine (work in progress: 380 bytes over in NumPlay.nwa)

Mason3638b4a5145093b
diff --git a/games/crossyroad/src/chars.h b/games/crossyroad/src/chars.h
new file mode 100644
index 00000000..62163008
--- /dev/null
+++ b/games/crossyroad/src/chars.h
@@ -0,0 +1,118 @@
+// The prize machine's characters, from Crossy Road's own models (tools/chars.py writes it).
+#define NCHARS 12
+#define NCC 42 // colours
+#define CHAR_MAXB 40
+#define CHAR_PAL \
+ [C_CHAR + 0] = 0xFFFF, [C_CHAR + 1] = 0x8C71, \
+ [C_CHAR + 2] = 0xEBEF, [C_CHAR + 3] = 0x79A6, \
+ [C_CHAR + 4] = 0xEC4D, [C_CHAR + 5] = 0x79E5, \
+ [C_CHAR + 6] = 0x6268, [C_CHAR + 7] = 0x20A2, \
+ [C_CHAR + 8] = 0x6D51, [C_CHAR + 9] = 0x2A88, \
+ [C_CHAR + 10] = 0x936E, [C_CHAR + 11] = 0x4165, \
+ [C_CHAR + 12] = 0xAC72, [C_CHAR + 13] = 0x51E8, \
+ [C_CHAR + 14] = 0xFF6F, [C_CHAR + 15] = 0x8BE6, \
+ [C_CHAR + 16] = 0xDBEC, [C_CHAR + 17] = 0x71A4, \
+ [C_CHAR + 18] = 0xFFFF, [C_CHAR + 19] = 0x8C51, \
+ [C_CHAR + 20] = 0x8BD3, [C_CHAR + 21] = 0x3989, \
+ [C_CHAR + 22] = 0xFED1, [C_CHAR + 23] = 0x8B88, \
+ [C_CHAR + 24] = 0x832C, [C_CHAR + 25] = 0x3924, \
+ [C_CHAR + 26] = 0x9799, [C_CHAR + 27] = 0x440D, \
+ [C_CHAR + 28] = 0xA450, [C_CHAR + 29] = 0x51E7, \
+ [C_CHAR + 30] = 0xE6B6, [C_CHAR + 31] = 0x738B, \
+ [C_CHAR + 32] = 0x830B, [C_CHAR + 33] = 0x3923, \
+ [C_CHAR + 34] = 0xEE95, [C_CHAR + 35] = 0x7B6A, \
+ [C_CHAR + 36] = 0xAFFB, [C_CHAR + 37] = 0x544E, \
+ [C_CHAR + 38] = 0x6B0B, [C_CHAR + 39] = 0x2924, \
+ [C_CHAR + 40] = 0x83CE, [C_CHAR + 41] = 0x3185, \
+ [C_CHAR + 42] = 0xF77A, [C_CHAR + 43] = 0x83EE, \
+ [C_CHAR + 44] = 0x8B2B, [C_CHAR + 45] = 0x3924, \
+ [C_CHAR + 46] = 0xA40E, [C_CHAR + 47] = 0x49A5, \
+ [C_CHAR + 48] = 0xFCB2, [C_CHAR + 49] = 0x8228, \
+ [C_CHAR + 50] = 0x7AEB, [C_CHAR + 51] = 0x3103, \
+ [C_CHAR + 52] = 0xD36D, [C_CHAR + 53] = 0x6945, \
+ [C_CHAR + 54] = 0x5ACB, [C_CHAR + 55] = 0x18E3, \
+ [C_CHAR + 56] = 0xF77E, [C_CHAR + 57] = 0x8410, \
+ [C_CHAR + 58] = 0xEEB6, [C_CHAR + 59] = 0x7B6B, \
+ [C_CHAR + 60] = 0x738E, [C_CHAR + 61] = 0x2965, \
+ [C_CHAR + 62] = 0xA555, [C_CHAR + 63] = 0x528A, \
+ [C_CHAR + 64] = 0xD6BA, [C_CHAR + 65] = 0x6B6E, \
+ [C_CHAR + 66] = 0xFFBD, [C_CHAR + 67] = 0x842F, \
+ [C_CHAR + 68] = 0x62CA, [C_CHAR + 69] = 0x20E3, \
+ [C_CHAR + 70] = 0xAB4C, [C_CHAR + 71] = 0x5124, \
+ [C_CHAR + 72] = 0xFFFF, [C_CHAR + 73] = 0x8C71, \
+ [C_CHAR + 74] = 0x5AEB, [C_CHAR + 75] = 0x1904, \
+ [C_CHAR + 76] = 0x52AA, [C_CHAR + 77] = 0x18C3, \
+ [C_CHAR + 78] = 0xC6A8, [C_CHAR + 79] = 0x6381, \
+ [C_CHAR + 80] = 0x7B26, [C_CHAR + 81] = 0x3120, \
+ [C_CHAR + 82] = 0x8C51, [C_CHAR + 83] = 0x39E7, \
+
+// boxes: x (4 bits), y (5), z (5), width - 1 (4), height - 1 (5), depth - 1 (5), colour (4), in voxels
+static const uint32_t char_box[] = {
+ // Chicken
+ 0x03254842, 0x030548F2, 0x01114242, 0x02884650, 0x02884658, 0x11844D14,
+ 0x018148E2, 0x0008C063, 0x210456D4, 0x21008A01, 0x108456B4, 0x21008A06,
+ 0x008152E2, 0x20080C12, 0x20080C17, 0x20801001, 0x300150E2, 0x20801003,
+ 0x20801006, 0x20801008,
+ // Duck
+ 0x031546B2, 0x128A4460, 0x24854042, 0x108D5062, 0x3184D4D3, 0x430146A2,
+ 0x10854072, 0x5180C800, 0x5180C806, 0x12014692, 0x20814062, 0x1080C093,
+ 0x40080CD1, 0x400810D1, 0x50080A12, 0x50080A17, 0x40080CD8, 0x400810D8,
+ 0x40000ED1, 0x10000EE1, 0x40000EF1, 0x40000ED8, 0x10000EE8, 0x40000EF8,
+ // BabyDuck
+ 0x03254642, 0x030546F2, 0x01114042, 0x02884460, 0x02884468, 0x1184D4D3,
+ 0x1180C800, 0x1180C806, 0x018146E2, 0x0080C093, 0x008150E2, 0x10080A12,
+ 0x10080A17, 0x20014EE2,
+ // Penguin
+ 0x01B60A22, 0x13960302, 0x111E0022, 0x119602A2, 0x21849325, 0x009E0622,
+ 0x11180471, 0x1118047B, 0x2280C402, 0x2280C407, 0x11040470, 0x21004613,
+ 0x21004618, 0x1104047C, 0x30080B21, 0x30080F21, 0x30080B2B, 0x30080F2B,
+ 0x30000D21, 0x10000D31, 0x30000D41, 0x30000D2B, 0x10000D3B, 0x30000D4B,
+ // Zombie
+ 0x0198C074, 0x110CC2E3, 0x21854052, 0x01184072, 0x12044290, 0x12044298,
+ 0x01044202, 0x01044206, 0x20884226, 0x008442B0, 0x30844222, 0x008442B8,
+ 0x00180672, 0x20804242, 0x00080673, 0x100406A3, 0x000406C3,
+ // Wizard
+ 0x01A58400, 0x019484D2, 0x128502A1, 0x10148C42, 0x00058200, 0x028042D0,
+ 0x028042D5, 0x118102C1, 0x00848112, 0x201C1286, 0x20181206, 0x10010291,
+ 0x30008AC2, 0x000082D2, 0x00008CD2, 0x00008102, 0x01000C76, 0x00800C70,
+ 0x10040C81, 0x10040C85, 0x00000E71, 0x30000E72, 0x30001276, 0x200010F6,
+ // Ghost
+ 0x02494403, 0x00944670, 0x0094467A, 0x00814003, 0x00044A70, 0x00044E70,
+ 0x008406B2, 0x008406B9, 0x00044A7A, 0x00044E7A,
+ // Kiwi
+ 0x04A1C252, 0x12915653, 0x040C4070, 0x040C407A, 0x20905C05, 0x22808602,
+ 0x22808607, 0x11008642, 0x11008647, 0x30081A62, 0x30081E62, 0x20080813,
+ 0x20080818, 0x30081A69, 0x30081E69, 0x20801202, 0x20801204, 0x20801207,
+ 0x20801209, 0x30001C62, 0x00001C72, 0x30001C82, 0x30001C69, 0x00001C79,
+ 0x30001C89,
+ // Sheep
+ 0x062E8270, 0x12959CC2, 0x02051D23, 0x1085A8E2, 0x1081A912, 0x0180C461,
+ 0x0180D261, 0x10941CB1, 0x10884602, 0x10885402, 0x20884632, 0x20885432,
+ 0x300C80E4, 0x0180C466, 0x0180D266, 0x10884607, 0x10885407, 0x20884637,
+ 0x20885437, 0x10941CB9, 0x1001A8C2, 0x400128D3, 0x00011B33, 0x500820E1,
+ 0x500824E1, 0x1080A904, 0x500820E9, 0x500824E9, 0x10802902, 0x10802908,
+ 0x500022E1, 0x600022F1, 0x50002301, 0x60002903, 0x60002907, 0x500022E9,
+ 0x600022F9, 0x50002309,
+ // Vampire
+ 0x003D8200, 0x11998400, 0x111D8470, 0x20208A72, 0x010184F0, 0x101C4A70,
+ 0x101C4A75, 0x30848B02, 0x41008922, 0x00018000, 0x00044CE0, 0x00044CE5,
+ 0x11000CD0, 0x30008CF2, 0x30008902, 0x40008912, 0x11000CD6, 0x308010C0,
+ 0x00004AF0, 0x00004AF5, 0x308010C6, 0x300012D0, 0x300012D6,
+ // Gray_Rabbit
+ 0x019D8410, 0x01959050, 0x02850C31, 0x00899A80, 0x00890C51, 0x001C4210,
+ 0x001C4215, 0x001092B0, 0x10188212, 0x001092B4, 0x21085850, 0x200C8062,
+ 0x21085855, 0x12004400, 0x12004405, 0x10850C11, 0x000198A0, 0x11005001,
+ 0x00845011, 0x30049E82, 0x11005004, 0x00845014, 0x001014B0, 0x001014B2,
+ 0x001014B4, 0x001014B6, 0x100C14B1, 0x100C14B5, 0x21009852, 0x21009872,
+ 0x00008282, 0x00019880, 0x30019890, 0x40809862, 0x10841013, 0x000014F1,
+ 0x50001C63, 0x000014F5,
+ // Frank
+ 0x021DC060, 0x11108210, 0x210CC2E2, 0x11108215, 0x21044CA0, 0x3100C322,
+ 0x21044CA6, 0x21808200, 0x21808205, 0x11044243, 0x00044AA0, 0x00044AA6,
+ 0x40800301, 0x40000506,
+};
+static const uint16_t char_at[NCHARS + 1] = {0, 20, 44, 58, 82, 99, 123, 133, 158, 196, 219, 257, 271};
+// west and south corner (half voxels), voxel (1/2000 tile)
+static const int8_t char_hdr[NCHARS][3] = {{-10, -14, 100}, {-10, -14, 100}, {-10, -14, 90}, {-13, -13, 90}, {-10, -6, 125}, {-7, -10, 125}, {-12, -8, 110}, {-12, -17, 80}, {-11, -22, 80}, {-7, -10, 120}, {-7, -16, 110}, {-8, -9, 125}};
+static const uint8_t char_cols_at[NCHARS + 1] = {0, 4, 10, 13, 17, 21, 25, 26, 30, 37, 42, 48, 53};
+static const uint8_t char_cols[] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 8, 7, 8, 5, 9, 10, 11, 0, 12, 13, 14, 15, 10, 0, 16, 17, 18, 19, 20, 7, 0, 21, 22, 23, 12, 24, 0, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41};
diff --git a/games/crossyroad/src/crossy.c b/games/crossyroad/src/crossy.c
index dbdcfdcb..c192db6e 100644
--- a/games/crossyroad/src/crossy.c
+++ b/games/crossyroad/src/crossy.c
@@ -44,6 +44,8 @@ const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level")))
// Helpers used from many places are kept out of line: smaller code.
#define NOINLINE __attribute__((noinline))
+#include "chars.h"
+
// ---------------------------------------------------------------------------
// Palette indices (the colors are in the constant data below).
@@ -54,7 +56,7 @@ enum {
C_ROAD, C_ROAD_O, C_ROAD_SH, C_ROAD_OSH, C_ROAD_SIDE, C_DASH, C_DASH_O,
C_WATER, C_WATER_O, C_WATER_SH, C_WATER_OSH, C_FOAM,
C_RAIL, C_RAIL_S, C_TIE, C_TIE_S, C_RAIL_SH, C_TIE_SH,
- C_WHITE, C_GRAY, C_COMB, C_COMB_S, C_BEAK, C_BEAK_S, C_EYE,
+ C_WHITE, C_GRAY,
C_LEAF, C_LEAF_A, C_LEAF_B, C_TRUNK, C_TRUNK_E,
C_ROCK, C_ROCK_S,
C_LOG, C_LOG_BARK, C_LOG_S, C_LOG_END, C_LOG_SH,
@@ -71,8 +73,9 @@ enum {
C_POLE_R, C_POLE_RS, C_POLE_W, C_POLE_WS, C_LAMP_OFF, C_LAMP_ON, C_SIGNAL, C_SIGNAL_S,
C_COIN, C_COIN_S, C_COIN_C,
C_EAGLE, C_EAGLE_S, C_EAGLE_H, C_EAGLE_HS, C_EAGLE_B, C_EAGLE_BS,
- C_BTN, C_BTN_S, C_GOLD, C_OUTLINE,
- NCOLORS
+ C_BTN, C_BTN_S, C_GOLD, C_OUTLINE, C_TAN, C_TAN_S,
+ C_CHAR, // the characters' colors, top and side (chars.h)
+ NCOLORS = C_CHAR + 2 * NCC
};
// ---------------------------------------------------------------------------
@@ -81,14 +84,15 @@ enum {
typedef struct { uint8_t t, s, e; } Mat; // top, south, east colors
enum {
- M_WHITE, M_COMB, M_BEAK, M_EYE, M_TRUNK, M_ROCK, M_LOG, M_LOG_BARK, M_LILY,
+ M_WHITE, M_TRUNK, M_ROCK, M_LOG, M_LOG_BARK, M_LILY,
M_BLACK, M_CABIN, M_UNDER, M_HUB,
M_BLUE, M_BLUE2, M_GREEN, M_GREEN2, M_YELLOW, M_YELLOW2, M_ORANGE, M_ORANGE2, M_PURPLE, M_PURPLE2,
M_RED, M_TBLUE, M_TGREEN, M_BOX, M_BOX2,
M_TRAIN, M_TRAIN2, M_TRAIN_W, M_TRAIN_Y,
M_POLE_R, M_POLE_W, M_SIGNAL, M_LAMP_OFF, M_LAMP_ON,
- M_EAGLE, M_EAGLE_H, M_EAGLE_B,
- NMATS
+ M_EAGLE, M_EAGLE_H, M_EAGLE_B, M_GOLD, M_TAN,
+ M_CHAR, // the characters' colors (made by init_palette)
+ NMATS = M_CHAR + NCC
};
// ---------------------------------------------------------------------------
@@ -109,6 +113,7 @@ enum {
MD_ROCK,
MD_SIGNAL, // lamps off, left on, right on
MD_EAGLE = MD_SIGNAL + 3,
+ MD_MACHINE, // the prize machine
NMODELS
};
@@ -146,23 +151,22 @@ struct Rom {
uint16_t pal[NCOLORS]; // RGB565 of each color
uint8_t shade_pairs[16][2]; // color, its shadowed version
Mat mats[NMATS];
- Box shapes[101];
+ Box shapes[110];
uint8_t shape_at[13];
- uint8_t model_def[NMODELS][4];
+ uint8_t model_def[NMODELS - MD_CAR][4];
uint8_t obstacle_pct[12];
uint8_t kinds[4];
int8_t dx[4], dz[4];
- // (a language build has a V too, for French)
- char font_chars[NP_TEXT_EXTRA ? 31 : 30];
- uint8_t font_w[NP_TEXT_EXTRA ? 30 : 29];
- uint16_t font[NP_TEXT_EXTRA ? 30 : 29][10];
+ char font_chars[36];
+ uint8_t font_w[35];
+ uint16_t font[35][10];
uint16_t hand_ol[14], hand_in[14];
char save_name[15];
char s_crossy[7], s_road[5];
#if NP_TEXT_EXTRA
- char s_new_top[24], s_quit[24], s_quit_q[24], s_no[8], s_yes[8];
+ char s_new_top[24], s_quit[24], s_quit_q[24], s_no[8], s_yes[8], s_play[16], s_togo[24], s_names[NCHARS][24];
#else
- char s_new_top[8], s_quit[10], s_quit_q[11], s_no[3], s_yes[4];
+ char s_new_top[8], s_quit[10], s_quit_q[11], s_no[3], s_yes[4], s_play[5], s_togo[8], s_names[NCHARS][13];
#endif
};
@@ -177,6 +181,9 @@ struct State {
int pause_sel; // on the pause screen: 0 the game, 1 Quit game
int quitting, quit_sel; // the "QUIT GAME?" question is open; 1 on YES
int score, top_score, coins;
+ int chr, browse, prize, won, dark; // the character played, the one shown, the prize machine's step, its prize
+ uint32_t owned; // the characters won (bit 0, the Chicken, from the start)
+ float char_k; // the character's size (its voxels' in 1/40 tile, over 2)
int gen_next, set_left, set_type, prev_dir, start_end;
uint32_t rng_s;
uint8_t *fs_buf;
@@ -201,7 +208,7 @@ struct State {
Part parts[NPARTS];
struct Rom rom;
Lane lanes[NLANES];
- Box boxpool[420];
+ Box boxpool[4 * CHAR_MAXB + 420];
uint16_t strip[SW * STRIP] __attribute__((aligned(4)));
uint8_t fb[SW * SH] __attribute__((aligned(4)));
};
@@ -240,6 +247,13 @@ static struct State G;
#define score G.score
#define top_score G.top_score
#define coins G.coins
+#define chr G.chr
+#define browse G.browse
+#define prize G.prize
+#define won G.won
+#define dark G.dark
+#define owned G.owned
+#define char_k G.char_k
#define gen_next G.gen_next
#define set_left G.set_left
#define set_type G.set_type
@@ -264,7 +278,7 @@ static struct State G;
enum { M_V0 = NMATS, M_V1, M_V2 };
#define NONE 0xFF
-enum { S_CHICKEN, S_CAR, S_TRUCK, S_ENGINE, S_WAGON, S_LOG, S_LILY = S_LOG + 3, S_ROCK, S_SIGNAL, S_EAGLE };
+enum { S_CAR, S_TRUCK, S_ENGINE, S_WAGON, S_LOG, S_LILY = S_LOG + 3, S_ROCK, S_SIGNAL, S_EAGLE, S_MACHINE };
// Per model: shape | quarter turns clockwise << 4 (4: mirrored east-west), variants.
#define CAR(t, s, sign) {S_CAR, t, s, sign}, {S_CAR | 4 << 4, t, s, sign}
@@ -294,8 +308,6 @@ static const struct Rom rom_init = {
[C_TIE] = RGB(127, 85, 79), [C_TIE_S] = RGB(54, 33, 29),
[C_RAIL_SH] = RGB(74, 71, 76), [C_TIE_SH] = RGB(54, 33, 29),
[C_WHITE] = RGB(255, 255, 255), [C_GRAY] = RGB(144, 144, 144),
- [C_COMB] = RGB(239, 130, 131), [C_COMB_S] = RGB(117, 55, 53),
- [C_BEAK] = RGB(240, 146, 107), [C_BEAK_S] = RGB(120, 63, 43), [C_EYE] = RGB(31, 17, 13),
[C_LEAF] = RGB(208, 234, 90), [C_LEAF_A] = RGB(100, 112, 39), [C_LEAF_B] = RGB(91, 101, 33),
[C_TRUNK] = RGB(64, 41, 35), [C_TRUNK_E] = RGB(58, 32, 27),
[C_ROCK] = RGB(252, 239, 254), [C_ROCK_S] = RGB(111, 103, 108),
@@ -325,7 +337,8 @@ static const struct Rom rom_init = {
[C_EAGLE_H] = RGB(250, 250, 250), [C_EAGLE_HS] = RGB(150, 150, 150),
[C_EAGLE_B] = RGB(255, 170, 60), [C_EAGLE_BS] = RGB(140, 80, 24),
[C_BTN] = RGB(86, 196, 248), [C_BTN_S] = RGB(36, 150, 220), [C_GOLD] = RGB(248, 232, 77),
- [C_OUTLINE] = RGB(0, 0, 0),
+ [C_OUTLINE] = RGB(0, 0, 0), [C_TAN] = RGB(203, 179, 171), [C_TAN_S] = RGB(105, 89, 83),
+ CHAR_PAL
},
.shade_pairs = {
{C_GRASS, C_GRASS_SH}, {C_GRASS2, C_GRASS_SH}, {C_GRASS_O, C_GRASS_OSH}, {C_GRASS2_O, C_GRASS_OSH},
@@ -334,8 +347,7 @@ static const struct Rom rom_init = {
{C_RAIL, C_RAIL_SH}, {C_TIE, C_TIE_SH}, {C_LOG, C_LOG_SH}, {C_LOG_BARK, C_LOG_SH}, {C_LILY, C_LILY_S},
},
.mats = {
- [M_WHITE] = {C_WHITE, C_GRAY, C_GRAY}, [M_COMB] = {C_COMB, C_COMB_S, C_COMB_S},
- [M_BEAK] = {C_BEAK, C_BEAK_S, C_BEAK_S}, [M_EYE] = {C_EYE, C_EYE, C_EYE},
+ [M_WHITE] = {C_WHITE, C_GRAY, C_GRAY},
[M_TRUNK] = {C_TRUNK, C_TRUNK, C_TRUNK_E}, [M_ROCK] = {C_ROCK, C_ROCK_S, C_ROCK_S},
[M_LOG] = {C_LOG, C_LOG_S, C_LOG_END}, [M_LOG_BARK] = {C_LOG_BARK, C_LOG_S, C_LOG_END},
[M_LILY] = {C_LILY, C_LILY_S, C_LILY_S},
@@ -356,21 +368,11 @@ static const struct Rom rom_init = {
[M_LAMP_OFF] = {C_LAMP_OFF, C_LAMP_OFF, C_LAMP_OFF}, [M_LAMP_ON] = {C_LAMP_ON, C_LAMP_ON, C_LAMP_ON},
[M_EAGLE] = {C_EAGLE, C_EAGLE_S, C_EAGLE_S}, [M_EAGLE_H] = {C_EAGLE_H, C_EAGLE_HS, C_EAGLE_HS},
[M_EAGLE_B] = {C_EAGLE_B, C_EAGLE_BS, C_EAGLE_BS},
+ [M_GOLD] = {C_COIN, C_COIN_S, C_COIN_S}, [M_TAN] = {C_TAN, C_TAN_S, C_TAN_S},
},
// Model shapes, facing north (creatures) or east (vehicles). Materials M_V0..M_V2
// are filled in per model (colors, lamps); a variant of NONE drops the box.
.shapes = {
- // chicken
- {-6, 0, -2, 3, 6, 3, M_BEAK}, {3, 0, -2, 3, 6, 3, M_BEAK}, // legs
- {-6, 0, 1, 3, 1, 2, M_BEAK}, {3, 0, 1, 3, 1, 2, M_BEAK}, // toes
- {-6, 6, -9, 12, 12, 16, M_WHITE}, // body
- {-9, 9, -6, 3, 6, 9, M_WHITE}, {6, 9, -6, 3, 6, 9, M_WHITE}, // wings
- {-4, 14, -12, 8, 6, 3, M_WHITE}, // tail
- {-6, 18, -3, 12, 14, 10, M_WHITE}, // head
- {-2, 32, -1, 5, 4, 7, M_COMB}, // comb
- {-2, 24, 7, 4, 3, 3, M_BEAK}, // beak
- {-2, 21, 7, 4, 3, 1, M_COMB}, // wattle
- {-7, 26, 2, 1, 2, 2, M_EYE}, {6, 26, 2, 1, 2, 2, M_EYE}, // eyes
// car: wheels, chassis, two-tone body, cabin with windows, taxi sign
{-21, 0, -18, 12, 10, 4, M_BLACK}, {-21, 0, 14, 12, 10, 4, M_BLACK}, {-17, 3, -19, 4, 4, 1, M_HUB},
{9, 0, -18, 12, 10, 4, M_BLACK}, {9, 0, 14, 12, 10, 4, M_BLACK}, {13, 3, -19, 4, 4, 1, M_HUB},
@@ -419,17 +421,29 @@ static const struct Rom rom_init = {
{-30, 10, -6, 22, 3, 14, M_EAGLE}, {8, 10, -6, 22, 3, 14, M_EAGLE}, {-8, 4, -12, 16, 12, 22, M_EAGLE},
{-6, 7, 10, 12, 4, 9, M_EAGLE_H}, {-6, 10, -21, 12, 10, 9, M_EAGLE_H}, {-2, 12, -25, 4, 4, 4, M_EAGLE_B},
{-6, 0, -8, 3, 4, 3, M_EAGLE_B}, {3, 0, -8, 3, 4, 3, M_EAGLE_B},
+ // prize machine, after the original's: a red cabinet on a yellow stand, its chute and handle facing
+ // south, a glass case of prize balls, a red roof
+ {-26, 0, -26, 52, 4, 52, M_GOLD}, {-20, 4, -20, 40, 40, 40, M_RED},
+ {-8, 10, -21, 16, 16, 1, M_LOG}, {-10, 8, -24, 20, 2, 4, M_GOLD},
+ {8, 22, -22, 8, 8, 2, M_GOLD}, {10, 24, -26, 4, 4, 4, M_WHITE},
+ {-21, 44, -21, 42, 3, 42, M_TAN}, {-20, 47, -20, 40, 5, 40, M_LOG},
+ {-18, 52, -18, 3, 44, 3, M_WHITE}, {15, 52, -18, 3, 44, 3, M_WHITE},
+ {-18, 52, 15, 3, 44, 3, M_WHITE}, {15, 52, 15, 3, 44, 3, M_WHITE},
+ {-15, 52, -15, 10, 10, 10, M_BLUE}, {-5, 52, -15, 10, 10, 10, M_YELLOW}, {5, 52, -15, 10, 10, 10, M_PURPLE},
+ {5, 52, -5, 10, 10, 10, M_ORANGE}, {-15, 52, -5, 10, 10, 10, M_GREEN},
+ {-12, 62, -13, 10, 10, 10, M_ORANGE}, {1, 62, -13, 10, 10, 10, M_GREEN}, {-5, 62, -1, 10, 10, 10, M_BLUE},
+ {-6, 72, -8, 10, 10, 10, M_RED},
+ {-21, 96, -21, 42, 2, 42, M_TAN}, {-21, 98, -21, 42, 5, 42, M_RED},
},
- .shape_at = {0, 14, 29, 44, 51, 56, 61, 68, 77, 80, 82, 93, 101},
+ .shape_at = {0, 15, 30, 37, 42, 47, 54, 63, 66, 68, 79, 87, 110},
.model_def = {
- {S_CHICKEN}, {S_CHICKEN | 1 << 4}, {S_CHICKEN | 2 << 4}, {S_CHICKEN | 3 << 4},
CAR(M_BLUE, M_BLUE2, NONE), CAR(M_GREEN, M_GREEN2, NONE), CAR(M_YELLOW, M_YELLOW2, M_YELLOW),
CAR(M_ORANGE, M_ORANGE2, NONE), CAR(M_PURPLE, M_PURPLE2, NONE),
TRUCK(M_RED), TRUCK(M_TBLUE), TRUCK(M_TGREEN),
{S_ENGINE}, {S_ENGINE | 4 << 4}, {S_WAGON},
{S_LOG}, {S_LOG + 1}, {S_LOG + 2}, {S_LILY}, {S_ROCK},
{S_SIGNAL, M_LAMP_OFF, M_LAMP_OFF}, {S_SIGNAL, M_LAMP_ON, M_LAMP_OFF}, {S_SIGNAL, M_LAMP_OFF, M_LAMP_ON},
- {S_EAGLE},
+ {S_EAGLE}, {S_MACHINE},
},
.obstacle_pct = {10, 10, 20, 20, 25, 25, 30, 30, 35, 40, 45, 50}, // tree density by distance (25 rows each)
.kinds = {L_GRASS, L_ROAD, L_RIVER, L_RAIL},
@@ -437,16 +451,9 @@ static const struct Rom rom_init = {
.dz = {1, 0, -1, 0},
// Font: the original's blocky digits (decoded from the game) and matching
// capitals. 10 rows; bit 11 is the leftmost column.
-#if NP_TEXT_EXTRA
- .font_chars = "0123456789ACDEGILMNOPQRSTUWY?V",
-#else
- .font_chars = "0123456789ACDEGILMNOPQRSTUWY?",
-#endif
+ .font_chars = "0123456789ACDEGILMNOPQRSTUWY?VBFHKZ",
.font_w = {10, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 10, 12, 10, 10, 10, 10, 10, 10, 10, 10, 12, 10, 10,
-#if NP_TEXT_EXTRA
- 10,
-#endif
- },
+ 10, 10, 10, 10, 10, 10},
.font = {
GLYPH(0x1FE, 0x3FF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x1FE), // 0
GLYPH(0x3C0, 0x3E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0), // 1
@@ -477,9 +484,13 @@ static const struct Rom rom_init = {
{0xF0F, 0xF0F, 0xF0F, 0xF6F, 0xF6F, 0xFFF, 0xFFF, 0xF9F, 0xF0F, 0xF0F}, // W
GLYPH(0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x1FE, 0x078, 0x078, 0x078, 0x078), // Y
GLYPH(0x1FE, 0x3FF, 0x00F, 0x00F, 0x07E, 0x078, 0x078, 0x000, 0x078, 0x078), // ?
-#if NP_TEXT_EXTRA
GLYPH(0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x1CE, 0x1CE, 0x0FC, 0x0FC, 0x078), // V
-#endif
+ // (the characters' names)
+ GLYPH(0x3FE, 0x3FF, 0x3CF, 0x3CF, 0x3FE, 0x3FF, 0x3CF, 0x3CF, 0x3FF, 0x3FE), // B
+ GLYPH(0x1FF, 0x3FF, 0x3C0, 0x3C0, 0x3F8, 0x3F8, 0x3C0, 0x3C0, 0x3C0, 0x3C0), // F
+ GLYPH(0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x3FF, 0x3CF, 0x3CF, 0x3CF, 0x3CF), // H
+ GLYPH(0x3CF, 0x3CF, 0x3DE, 0x3FC, 0x3F8, 0x3F8, 0x3FC, 0x3DE, 0x3CF, 0x3CF), // K
+ GLYPH(0x3FF, 0x3FF, 0x00F, 0x01E, 0x03C, 0x078, 0x0F0, 0x1E0, 0x3FF, 0x3FF), // Z
},
// Pixel-art pointing hand (tap hint), 12x14: outline and fill masks.
.hand_ol = {0x0E0, 0x1B0, 0x1B0, 0x1BE, 0x1B5, 0x7B5, 0x9D5, 0x8C1,
@@ -494,6 +505,11 @@ static const struct Rom rom_init = {
.s_quit_q = T("QUIT GAME?"),
.s_no = T("NO"),
.s_yes = T("YES"),
+ .s_play = T("PLAY"),
+ .s_togo = T("# TO GO"), // (# is the coins still to get)
+ // the characters, in chars.h's order: their names in the original
+ .s_names = {T("CHICKEN"), T("MALLARD"), T("BABY DUCK"), T("PENGUIN"), T("ZOMBIE"), T("MAD WIZARD"), T("GHOST"),
+ T("KIWI"), T("FLUFFY SHEEP"), T("VAMPIRE"), T("GREY BUNNY"), T("FRANKENSTEIN")},
};
#endif
@@ -520,8 +536,13 @@ static const struct Rom rom_init = {
#define str_quit_q G.rom.s_quit_q
#define str_no G.rom.s_no
#define str_yes G.rom.s_yes
+#define str_play G.rom.s_play
+#define str_togo G.rom.s_togo
+#define str_names G.rom.s_names
+_Static_assert(NCOLORS <= 256, "palette indices are bytes");
static void init_palette(void) {
+ for (int k = 0; k < NCC; k++) mats[M_CHAR + k] = (Mat){(uint8_t)(C_CHAR + 2 * k), (uint8_t)(C_CHAR + 2 * k + 1), (uint8_t)(C_CHAR + 2 * k + 1)};
for (int i = 0; i < NCOLORS; i++) shade[i] = i;
for (unsigned i = 0; i < sizeof(shade_pairs) / sizeof(shade_pairs[0]); i++) shade[shade_pairs[i][0]] = shade_pairs[i][1];
}
@@ -708,8 +729,8 @@ static NOINLINE int behind(const Box *a, const Box *b) {
}
static void sort_boxes(Box *bx, int n) {
- Box out[32];
- uint32_t used = 0;
+ Box out[CHAR_MAXB];
+ uint64_t used = 0;
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++) {
if (used >> i & 1) continue;
@@ -718,36 +739,61 @@ static void sort_boxes(Box *bx, int n) {
if (j != i && !(used >> j & 1) && behind(&bx[j], &bx[i]) && !behind(&bx[i], &bx[j])) ok = 0;
if (ok) {
out[k] = bx[i];
- used |= 1u << i;
+ used |= (uint64_t)1 << i;
break;
}
}
memcpy(bx, out, n * sizeof(Box));
}
+// Model id at dst: n boxes turned r quarter turns clockwise (4: mirrored east-west), in drawing order.
+static NOINLINE void put_model(int id, Box *dst, const Box *src, int n, int r) {
+ int reach = 0;
+ for (int i = 0; i < n; i++) {
+ Box b = src[i];
+ int x0 = b.x, x1 = b.x + b.w, z0 = b.z, z1 = b.z + b.d;
+ if (r == 1) { b.x = z0; b.w = z1 - z0; b.z = -x1; b.d = x1 - x0; }
+ else if (r == 2) { b.x = -x1; b.z = -z1; }
+ else if (r == 3) { b.x = -z1; b.w = z1 - z0; b.z = x0; b.d = x1 - x0; }
+ else if (r == 4) b.x = -x1; // mirror east-west
+ dst[i] = b;
+ int e = b.x < 0 ? -b.x : b.x;
+ if (b.x + b.w > e) e = b.x + b.w;
+ if (b.y + b.h > e) e = b.y + b.h;
+ if (-b.z > e) e = -b.z;
+ if (b.z + b.d > e) e = b.z + b.d;
+ if (e > reach) reach = e;
+ }
+ sort_boxes(dst, n);
+ models[id] = (Mdl){(uint16_t)(dst - boxpool), (uint8_t)n, (uint8_t)reach};
+}
+
+// The player's four facings, from character c's boxes (chars.h), in half voxels: drawn char_k times bigger.
+static void build_char(int c) {
+ Box bx[CHAR_MAXB];
+ const int8_t *h = char_hdr[c];
+ int n = 0;
+ for (int i = char_at[c]; i < char_at[c + 1]; i++) {
+ uint32_t v = char_box[i];
+ bx[n++] = (Box){(int8_t)(h[0] + 2 * (v & 15)), (int8_t)(2 * (v >> 4 & 31)), (int8_t)(h[1] + 2 * (v >> 9 & 31)),
+ (uint8_t)(2 * (v >> 14 & 15) + 2), (uint8_t)(2 * (v >> 18 & 31) + 2), (uint8_t)(2 * (v >> 23 & 31) + 2),
+ (uint8_t)(M_CHAR + char_cols[char_cols_at[c] + (v >> 28)])};
+ }
+ for (int r = 0; r < 4; r++) put_model(MD_CHICKEN + r, boxpool + r * CHAR_MAXB, bx, n, r);
+ char_k = (uint8_t)h[2] * 0.01f;
+}
+
static void build_models(void) {
- Box *dst = boxpool;
- for (int id = 0; id < NMODELS; id++) {
- const uint8_t *def = model_def[id];
- int s = def[0] & 15, r = def[0] >> 4, n = 0, reach = 0;
+ Box *dst = boxpool + 4 * CHAR_MAXB, tmp[CHAR_MAXB];
+ for (int id = MD_CAR; id < NMODELS; id++) {
+ const uint8_t *def = model_def[id - MD_CAR];
+ int s = def[0] & 15, n = 0;
for (int i = shape_at[s]; i < shape_at[s + 1]; i++) {
Box b = shapes[i];
if (b.m >= M_V0 && (b.m = def[1 + b.m - M_V0]) == NONE) continue;
- int x0 = b.x, x1 = b.x + b.w, z0 = b.z, z1 = b.z + b.d;
- if (r == 1) { b.x = z0; b.w = z1 - z0; b.z = -x1; b.d = x1 - x0; }
- else if (r == 2) { b.x = -x1; b.z = -z1; }
- else if (r == 3) { b.x = -z1; b.w = z1 - z0; b.z = x0; b.d = x1 - x0; }
- else if (r == 4) b.x = -x1; // mirror east-west
- dst[n++] = b;
- int e = b.x < 0 ? -b.x : b.x;
- if (b.x + b.w > e) e = b.x + b.w;
- if (b.y + b.h > e) e = b.y + b.h;
- if (-b.z > e) e = -b.z;
- if (b.z + b.d > e) e = b.z + b.d;
- if (e > reach) reach = e;
+ tmp[n++] = b;
}
- sort_boxes(dst, n);
- models[id] = (Mdl){(uint16_t)(dst - boxpool), (uint8_t)n, (uint8_t)reach};
+ put_model(id, dst, tmp, n, def[0] >> 4);
dst += n;
}
}
@@ -766,7 +812,7 @@ static void draw_model_s(int id, float wx, float wy, float wz, float sx, float s
const float u = 1.0f / 40.0f;
const Box *b = boxpool + m->off;
for (int i = 0; i < m->n; i++, b++) {
- const Mat *t = &mats[b->m];
+ const Mat *t = &mats[dark ? M_BLACK : b->m];
draw_cuboid(wx + b->x * u * sx, wy + b->y * u * sy, wz + b->z * u * sz, wx + (b->x + b->w) * u * sx,
wy + (b->y + b->h) * u * sy, wz + (b->z + b->d) * u * sz, t->t, t->s, t->e);
}
@@ -1039,7 +1085,7 @@ static void gen_lane(void) {
// ---------------------------------------------------------------------------
// Gameplay
-enum { ST_TITLE, ST_PLAY, ST_DEAD, ST_OVER };
+enum { ST_TITLE, ST_PLAY, ST_DEAD, ST_OVER, ST_CHARS, ST_PRIZE };
enum { D_NONE, D_PANCAKE, D_SPLAT, D_TRAIN, D_DROWN, D_LOG, D_EAGLE };
@@ -1486,7 +1532,7 @@ static void draw_coin(float x, float g, float z) {
typedef struct { float key; uint8_t kind, a, md; } Item;
enum { I_MODEL, I_TREE, I_PAD, I_LOG, I_SIGNAL, I_COIN, I_PLAYER };
-static void draw_player(void) { draw_model_s(MD_CHICKEN + P.face, P.x, P.base + P.y, P.z, P.sx, P.sy, P.sz); }
+static void draw_player(void) { draw_model_s(MD_CHICKEN + P.face, P.x, P.base + P.y, P.z, P.sx * char_k, P.sy * char_k, P.sz * char_k); }
static void draw_lane_objects(int row) {
Lane *L = lane_at(row);
@@ -1540,7 +1586,7 @@ static void draw_lane_objects(int row) {
} else if (d->kind == I_COIN) {
shadow_box(x - 0.14f, x + 0.14f, row - 0.05f, row + 0.05f, g + 0.1f, g + 0.54f, g);
} else if (d->kind == I_PLAYER) {
- shadow_model_s(MD_CHICKEN + P.face, P.x, P.base + P.y, P.z, g, P.sx, P.sy, P.sz);
+ shadow_model_s(MD_CHICKEN + P.face, P.x, P.base + P.y, P.z, g, P.sx * char_k, P.sy * char_k, P.sz * char_k);
} else {
shadow_model(d->md, x, g, row - (d->kind == I_SIGNAL ? 0.43f : 0), g);
}
@@ -1778,11 +1824,12 @@ static void draw_hand(int x, int y) {
}
}
-static void draw_tap_hint(void) {
+// The hand tapping at (x, y) from below.
+static void draw_tap_at(int x, int y) {
float ph = st_time / 0.6f;
ph -= (int)ph;
int up = ph > 0.5f ? 4 : 0;
- int x = (int)(sx_of(P.x, P.z)) + 2, y = (int)(sy_of(P.x, P.base, P.z)) + 14 - up;
+ y -= up;
draw_hand(x, y);
if (up) { // tap marks around the fingertip
fill_rect(x + 10, y - 9, 2, 5, C_WHITE);
@@ -1793,6 +1840,8 @@ static void draw_tap_hint(void) {
}
}
+static void draw_tap_hint(void) { draw_tap_at((int)(sx_of(P.x, P.z)) + 2, (int)(sy_of(P.x, P.base, P.z)) + 14); }
+
static void draw_play_button(int cx, int y) {
fill_rect(cx - 33, y + 2, 66, 42, C_OUTLINE);
fill_rect(cx - 31, y, 62, 46, C_OUTLINE);
@@ -1830,7 +1879,120 @@ static void draw_quit_question(void) {
draw_small_button(200, 132, str_yes, quit_sel);
}
+// ---------------------------------------------------------------------------
+// The characters and the prize machine: 100 coins for one not won yet
+
+static int all_owned(void) { return owned == (1u << NCHARS) - 1; }
+
+static const char *char_name(int c) { return str_names[c]; }
+
+// A model on a screen of its own: the world's origin at (x, y), s times its size.
+static void draw_at(int id, int x, int y, float s) {
+ float sox = ox, soy = oy;
+ ox = (float)x, oy = (float)y;
+ draw_model_s(id, 0, 0, 0, s, s, s);
+ ox = sox, oy = soy;
+}
+
+// A prize ball, s tiles wide, standing on (x, y): its blue half below (halves & 1), its white half above,
+// lift tiles up (halves & 2).
+static void draw_ball(int x, int y, float s, float lift, int halves) {
+ float sox = ox, soy = oy, h = 0.5f * s;
+ ox = (float)x, oy = (float)y;
+ if (halves & 1) draw_cuboid(-h, 0, -h, h, h, h, C_BLUE_T, C_BLUE_S, C_BLUE_S2);
+ if (halves & 2) draw_cuboid(-h, h + lift, -h, h, 2 * h + lift, h, C_WHITE, C_GRAY, C_GRAY);
+ ox = sox, oy = soy;
+}
+
+// A key's way: a white triangle pointing left (dir -1) or right, its tip at x.
+static void draw_arrow(int x, int y, int dir) {
+ for (int i = 0; i <= 10; i++) fill_rect(x - dir * i, y - i, 1, 2 * i + 1, C_OUTLINE);
+ for (int i = 2; i <= 9; i++) fill_rect(x - dir * i, y - i + 2, 1, 2 * i - 3, C_WHITE);
+}
+
+static void button_box(int x, int y, int c) {
+ fill_rect(x, y, 52, 46, C_OUTLINE);
+ fill_rect(x + 2, y + 2, 48, 42, C_WHITE);
+ fill_rect(x + 4, y + 4, 44, 38, c);
+}
+
+// Game over: the character played on the left (Left: the characters), the prize machine on the right
+// (Right) once there are 100 coins, the coins still to get before that.
+static void draw_side_buttons(int y) {
+ button_box(48, y, C_BTN);
+ draw_at(MD_CHICKEN + 2, 74, y + 36, 1.25f * char_k);
+ draw_arrow(28, y + 23, -1);
+ if (all_owned()) return;
+ if (coins >= 100) {
+ button_box(220, y, C_GOLD);
+ draw_ball(246, y + 34, 0.7f, 0, 3);
+ draw_arrow(292, y + 23, 1);
+ } else {
+ char buf[NP_TEXT_EXTRA ? 40 : 16], *o = buf;
+ for (const char *t = str_togo; *t; t++)
+ if (*t == '#') {
+ itoa_(100 - coins, o);
+ while (*o) o++;
+ } else {
+ *o++ = *t;
+ }
+ *o = 0;
+ text_ol(246 - text_width(buf, 1) / 2, y + 18, buf, 1, C_WHITE);
+ }
+}
+
+// The characters, one at a time (Left, Right): a black shape for one not won yet; OK plays one won.
+static void draw_chars(void) {
+ fill_rect(0, 0, SW, SH, C_BTN);
+ int got = owned >> browse & 1;
+ const char *nm = got ? char_name(browse) : "?";
+ text_ol(160 - text_width(nm, 2) / 2, 16, nm, 2, C_WHITE);
+ dark = !got;
+ draw_at(MD_CHICKEN + 2, 160, 184, 4.0f * char_k);
+ dark = 0;
+ draw_arrow(16, 120, -1);
+ draw_arrow(304, 120, 1);
+ if (got) draw_small_button(160, 208, str_play, 1);
+}
+
+// The prize machine: OK turns its handle (100 coins), it shakes and drops a ball; OK opens the ball.
+#define MX 170
+#define MY 150
+static void draw_prize(void) {
+ fill_rect(0, 0, SW, SH, C_BTN);
+ float t = st_time;
+ if (prize <= 1) {
+ int jx = prize == 1 && t < 0.6f ? (((int)(t * 30)) & 1 ? 2 : -2) : 0;
+ draw_at(MD_MACHINE, MX + jx, MY, 2.0f);
+ if (prize == 0) draw_tap_at(MX + 2, MY + 8);
+ else if (t >= 0.6f) { // out of the chute, down to the floor in front, a bounce
+ float u = (t - 0.6f) * 2.5f;
+ if (u > 1) u = 1;
+ int x = MX - 11 - (int)(u * 13), y = MY + 1 + (int)(u * 45) - (int)(u > 0.7f ? (1 - u) * 30 : 0);
+ draw_ball(x, y, 1.2f, 0, 3);
+ }
+ } else if (prize == 2) { // the ball, close, waiting to be opened
+ float w = (float)(((int)(t * 6)) & 1);
+ draw_ball(160, 176 - (int)w, 2.4f, 0, 3);
+ draw_tap_at(162, 190);
+ } else { // open: its top flies off, the new character comes up out of it
+ float g = t * 3.3f;
+ if (g > 1) g = 1;
+ draw_ball(160, 200, 2.4f, 0, 1);
+ draw_at(MD_CHICKEN + 2, 160, 200 + (int)(PYY * 1.2f), 4.0f * char_k * g);
+ if (t < 0.6f) draw_ball(160, 200, 2.4f, t * 14, 2);
+ text_ol(160 - text_width(char_name(won), 2) / 2, 44, char_name(won), 2, C_WHITE);
+ if (t > 0.5f) draw_small_button(160, 214, str_play, 1);
+ }
+ draw_coins_hud();
+}
+
static void render(void) {
+ if (state == ST_CHARS || state == ST_PRIZE) {
+ if (state == ST_CHARS) draw_chars();
+ else draw_prize();
+ return;
+ }
draw_world();
char buf[16];
if (state == ST_TITLE) {
@@ -1852,6 +2014,7 @@ static void render(void) {
}
float u = clampf((st_time - 0.3f) * 5, 0, 1);
draw_play_button(160, SH + 4 - (int)(u * 66));
+ draw_side_buttons(SH + 4 - (int)(u * 64));
}
}
draw_coins_hud();
@@ -1866,11 +2029,13 @@ static void render(void) {
#include "../../common/epsilon_app.h"
// The calculator keeps its files in RAM; the userland header of the running
-// firmware slot tells where. Top score and coins go in a tiny record named
-// "crossyroad.sav", written only after the whole file system checks out.
+// firmware slot tells where. Top score, coins, the characters won and the one played go in a
+// tiny record named "crossyroad.sav", written only after the whole file system checks out
+// (one from before the characters, top score and coins, is read and replaced).
#if (PLATFORM_DEVICE && !defined(HOST)) || defined(SAVE_TEST)
#define FS_MAGIC 0xEE0BDDBAu
-#define SAVE_LEN 12
+#define SAVE_LEN 20
+#define SAVE_LEN1 12
static uint16_t rd16(const uint8_t *p) { return (uint16_t)(p[0] | p[1] << 8); }
static void wr16(uint8_t *p, uint32_t v) { p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8); }
@@ -1886,7 +2051,7 @@ static uint8_t *fs_walk(uint8_t **found) {
if (n < 4 || p + n > end) return 0;
const char *a = (const char *)p + 2, *b = save_name;
while (*a && *a == *b) a++, b++;
- if (!*a && !*b && n == 2 + sizeof(save_name) + SAVE_LEN) *found = p;
+ if (!*a && !*b && (n == 2 + sizeof(save_name) + SAVE_LEN || n == 2 + sizeof(save_name) + SAVE_LEN1)) *found = p;
p += n;
}
}
@@ -1918,9 +2083,17 @@ static void load_save(void) {
uint8_t *f;
if (!fs_buf || !fs_walk(&f) || !f) return;
const uint8_t *d = f + 2 + sizeof(save_name);
- uint32_t v[3];
- for (int i = 0; i < 3; i++) v[i] = d[4 * i] | d[4 * i + 1] << 8 | d[4 * i + 2] << 16 | (uint32_t)d[4 * i + 3] << 24;
- if (save_sum(v[0], v[1]) != v[2] || v[0] > 999999999 || v[1] > 999999999) return;
+ uint32_t v[5];
+ for (int i = 0; i < 5; i++) v[i] = d[4 * i] | d[4 * i + 1] << 8 | d[4 * i + 2] << 16 | (uint32_t)d[4 * i + 3] << 24;
+ if (v[0] > 999999999 || v[1] > 999999999) return;
+ if (rd16(f) == 2 + sizeof(save_name) + SAVE_LEN1) {
+ if (save_sum(v[0], v[1]) != v[2]) return;
+ } else if (save_sum(save_sum(v[0], v[1]), v[2] * 31u + v[3]) != v[4] || v[3] >= NCHARS || !(v[2] >> v[3] & 1)) {
+ return;
+ } else {
+ owned = v[2] | 1;
+ chr = (int)v[3];
+ }
top_score = (int)v[0];
coins = (int)v[1];
}
@@ -1929,6 +2102,12 @@ static NOINLINE void write_save(void) {
uint8_t *f, *end;
if (!fs_buf || !(end = fs_walk(&f))) return;
uint32_t n = 2 + sizeof(save_name) + SAVE_LEN;
+ if (f && rd16(f) != n) { // (one from before the characters: out, the rest moved down over it)
+ uint32_t old = rd16(f);
+ for (uint8_t *q = f; q + old < end + 2; q++) *q = q[old];
+ end -= old;
+ f = 0;
+ }
if (!f) { // append a new record if it fits
if (end + n + 2 > fs_buf + fs_size) return;
f = end;
@@ -1936,11 +2115,21 @@ static NOINLINE void write_save(void) {
memcpy(f + 2, save_name, sizeof(save_name));
wr16(f, n);
}
- uint32_t v[3] = {(uint32_t)top_score, (uint32_t)coins, save_sum((uint32_t)top_score, (uint32_t)coins)};
+ uint32_t v[5] = {(uint32_t)top_score, (uint32_t)coins, owned, (uint32_t)chr, 0};
+ v[4] = save_sum(save_sum(v[0], v[1]), v[2] * 31u + v[3]);
uint8_t *d = f + 2 + sizeof(save_name);
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 5; i++)
for (int j = 0; j < 4; j++) d[4 * i + j] = (uint8_t)(v[i] >> (8 * j));
}
+#elif defined(HOST)
+// (on a computer: coins and characters to start with, for trying the prize machine)
+#include <stdlib.h>
+static void load_save(void) {
+ if (getenv("CROSSY_COINS")) coins = atoi(getenv("CROSSY_COINS"));
+ if (getenv("CROSSY_OWNED")) owned = (uint32_t)strtoul(getenv("CROSSY_OWNED"), 0, 0) | 1;
+ if (getenv("CROSSY_CHR")) chr = atoi(getenv("CROSSY_CHR")) % NCHARS, owned |= 1u << chr;
+}
+static void write_save(void) {}
#else
static void load_save(void) {}
static void write_save(void) {}
@@ -1983,6 +2172,10 @@ static void present(void) {
static void update(float dt) {
game_time += dt;
st_time += dt;
+ if (state == ST_CHARS || state == ST_PRIZE) {
+ if (state == ST_PRIZE && prize == 1 && st_time >= 1.1f) prize = 2, st_time = 0;
+ return;
+ }
update_lanes(dt);
update_parts(dt);
if (state == ST_TITLE || state == ST_PLAY) {
@@ -2054,7 +2247,9 @@ int main(int argc, char *argv[]) {
np_app_begin();
init_palette();
build_models();
+ owned = 1;
load_save();
+ build_char(chr);
new_game();
P.face = 2;
show_logo = 1;
@@ -2076,6 +2271,36 @@ int main(int argc, char *argv[]) {
else if (ok && quit_sel) break;
else if (ok) quitting = 0;
dir = -1;
+ } else if (state == ST_CHARS || state == ST_PRIZE) {
+ if (PRESSED(eadk_key_back)) { // back to the game over screen, with the character played
+ build_char(chr);
+ state = ST_OVER;
+ st_time = 1;
+ } else if (restarting) {
+ } else if (state == ST_CHARS && (PRESSED(eadk_key_left) || PRESSED(eadk_key_right))) {
+ browse = (browse + (PRESSED(eadk_key_right) ? 1 : NCHARS - 1)) % NCHARS;
+ build_char(browse);
+ } else if (state == ST_CHARS && ok && (owned >> browse & 1)) {
+ chr = browse;
+ write_save();
+ restarting = 1, restart_t = 0;
+ } else if (ok && prize == 0) { // 100 coins: one not won yet, at random, played from now on
+ int left = 0, k = 0;
+ for (int c = 0; c < NCHARS; c++) left += !(owned >> c & 1);
+ int r = irand(left);
+ while ((owned >> k & 1) || r--) k++;
+ won = chr = k;
+ owned |= 1u << k;
+ coins -= 100;
+ write_save();
+ prize = 1, st_time = 0;
+ } else if (ok && prize == 2) {
+ build_char(won);
+ prize = 3, st_time = 0;
+ } else if (ok && prize == 3 && st_time > 0.5f) {
+ restarting = 1, restart_t = 0;
+ }
+ dir = -1;
} else if (PRESSED(eadk_key_back)) {
if (state == ST_PLAY && !paused) paused = 1, pause_sel = 0;
else if (paused) paused = 0;
@@ -2102,6 +2327,10 @@ int main(int argc, char *argv[]) {
} else if (state == ST_OVER && st_time > 0.4f && dir == 0) {
restarting = 1;
restart_t = 0;
+ } else if (state == ST_OVER && st_time > 0.4f && dir == 3) {
+ state = ST_CHARS, browse = chr, st_time = 0;
+ } else if (state == ST_OVER && st_time > 0.4f && dir == 1 && coins >= 100 && !all_owned()) {
+ state = ST_PRIZE, prize = 0, st_time = 0;
}
}
uint64_t now = eadk_timing_millis();
diff --git a/games/crossyroad/tools/chars.py b/games/crossyroad/tools/chars.py
new file mode 100644
index 00000000..2f25995e
--- /dev/null
+++ b/games/crossyroad/tools/chars.py
@@ -0,0 +1,258 @@
+#!/usr/bin/env python3
+"""The prize machine's characters, from Crossy Road's own models: writes src/chars.h.
+
+ python3 -I tools/chars.py DATA [src/chars.h]
+
+DATA is the Data folder of Crossy Road 1.3.7825 for iOS (Payload/*.app/Data in the .ipa). Needs UnityPy.
+
+Each character is a voxel model coloured by its vertices, its voxels from 0.03 to 0.0625 of a tile (and some start
+half a voxel off). Its faces are filled into
+voxels, then the voxels anything can see (all but the ones under it) are covered by as few boxes as the search
+finds, none overlapping, each of one colour (the hidden voxels inside take any). The boxes are checked against
+the game's own drawing order (sort_boxes) in all four facings.
+
+chars.h: the boxes of every character packed in 32 bits (in voxels from its west, bottom, south corner: x 4 bits,
+y 5, z 5, width - 1: 4, height - 1: 5, depth - 1: 5, its colour 4), where each one's start (char_at), where its
+corner is in half voxels and how big its voxels are, in 1/2000 tile (char_hdr), its colours (char_cols from
+char_cols_at) and the colours, top and side, the way the game lights them (CHAR_PAL)."""
+import itertools
+import sys
+
+# (mesh, the original's number for it) in the original's order; the Chicken first, as the one to start with
+# (the ones whose boxes come to more than sort_boxes takes, or that it can't put in an order, are left out)
+CHARS = [("Chicken", 19), ("Duck", 4), ("BabyDuck", 5), ("Penguin", 6), ("Zombie", 8), ("Wizard", 10),
+ ("Ghost", 23), ("Kiwi", 25), ("Sheep", 30), ("Vampire", 34), ("Gray_Rabbit", 40), ("Frank", 49)]
+MAXB = 40 # the boxes sort_boxes takes
+
+
+def meshes(data):
+ import UnityPy
+ from UnityPy.helpers.MeshHelper import MeshHandler
+ want = {m for m, _ in CHARS}
+ out = {}
+ for o in UnityPy.load(data).objects:
+ if o.type.name != "Mesh":
+ continue
+ d = o.read()
+ if d.m_Name not in want or d.m_Name in out:
+ continue
+ h = MeshHandler(d)
+ h.process()
+ if not h.m_Colors:
+ continue
+ V, C, tris = h.m_Vertices, h.m_Colors, h.get_triangles()
+ flat = not isinstance(V[0], (list, tuple))
+ n = len(V) // 3 if flat else len(V)
+ vert = [tuple(V[3 * i:3 * i + 3]) if flat else tuple(V[i]) for i in range(n)]
+ cflat = not isinstance(C[0], (list, tuple))
+ col = [tuple(C[4 * i:4 * i + 3]) if cflat else tuple(C[i][:3]) for i in range(n)]
+ col = [tuple(int(round(x * 255)) if isinstance(x, float) and x <= 1 else int(x) for x in c) for c in col]
+ if tris and isinstance(tris[0], list) and tris[0] and isinstance(tris[0][0], (list, tuple)):
+ tris = [t for sub in tris for t in sub]
+ if tris and not isinstance(tris[0], (list, tuple)):
+ tris = [tris[i:i + 3] for i in range(0, len(tris), 3)]
+ out[d.m_Name] = (vert, col, [tuple(t) for t in tris])
+ missing = want - set(out)
+ if missing:
+ raise SystemExit("not found: " + ", ".join(sorted(missing)))
+ return out
+
+
+def grid(vert):
+ """the model's voxel size and, per axis, where its voxels start (0 or half a voxel)"""
+ u = [sorted(set(round(p[k], 5) for p in vert)) for k in range(3)]
+ g = min(b - a for k in range(3) for a, b in zip(u[k], u[k][1:]))
+ for k in range(3):
+ for v in u[k]:
+ assert abs(v / g - round(v / g)) < 0.02 or abs(v / g - round(v / g + 0.5) + 0.5) < 0.02, (k, v, g)
+ off = [round((u[k][0] / g) % 1 * 2) / 2 % 1 for k in range(3)]
+ return g, off
+
+
+def voxels(vert, col, tris):
+ """voxel -> its colour (None inside, where no face says), in the model's own voxels (see grid)"""
+ g, off = grid(vert)
+ vert = [tuple(p[k] / g - off[k] for k in range(3)) for p in vert]
+ S = 1
+ surf = {}
+ for t in tris:
+ p = [vert[i] for i in t]
+ e1 = [p[1][k] - p[0][k] for k in range(3)]
+ e2 = [p[2][k] - p[0][k] for k in range(3)]
+ nrm = [e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]]
+ a = max(range(3), key=lambda k: abs(nrm[k]))
+ if abs(nrm[a]) < 1e-12:
+ continue
+ sgn = 1 if nrm[a] > 0 else -1
+ plane = round(p[0][a] / S)
+ o = [k for k in range(3) if k != a]
+ q = [(v[o[0]] / S, v[o[1]] / S) for v in p]
+
+ def inside(x, y):
+ def cr(u, v):
+ return (v[0] - u[0]) * (y - u[1]) - (v[1] - u[1]) * (x - u[0])
+ d = (cr(q[0], q[1]), cr(q[1], q[2]), cr(q[2], q[0]))
+ return not (min(d) < 0 < max(d))
+ for u in range(int(min(x for x, _ in q)) - 1, int(max(x for x, _ in q)) + 1):
+ for v in range(int(min(y for _, y in q)) - 1, int(max(y for _, y in q)) + 1):
+ if inside(u + 0.5, v + 0.5):
+ cell = [0, 0, 0]
+ cell[o[0]], cell[o[1]] = u, v
+ cell[a] = plane - 1 if sgn > 0 else plane
+ surf.setdefault((a, sgn, tuple(cell)), col[t[0]])
+ cols, lines = {}, {}
+ for (a, s, c), cl in surf.items():
+ cols.setdefault(c, cl)
+ if a == 0:
+ lines.setdefault((c[1], c[2]), []).append((c[0], s))
+ vox = {}
+ for (y, z), marks in lines.items(): # inside: from a face looking west to the next looking east
+ start = None
+ for x, s in sorted(marks):
+ if s < 0 and start is None:
+ start = x
+ elif s > 0 and start is not None:
+ for xx in range(start, x + 1):
+ vox[(xx, y, z)] = cols.get((xx, y, z))
+ start = None
+ for c, cl in cols.items():
+ vox.setdefault(c, cl)
+ return vox
+
+
+def boxes(vox):
+ """the fewest boxes the search finds covering what can be seen, none overlapping"""
+ def seen(c):
+ x, y, z = c
+ return any((x + a, y + b, z + d) not in vox for a, b, d in ((1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, -1)))
+ need = {c: vox[c] for c in vox if vox[c] is not None and seen(c)}
+ taken, out, left = set(), [], set(need)
+
+ def grow(c, k, order):
+ lo, hi = list(c), [c[0] + 1, c[1] + 1, c[2] + 1]
+
+ def ok(q):
+ return q in vox and q not in taken and need.get(q, k) == k
+ changed = True
+ while changed:
+ changed = False
+ for ax in order:
+ for d in (1, -1):
+ while True:
+ rng = [range(lo[i], hi[i]) for i in range(3)]
+ rng[ax] = [hi[ax]] if d > 0 else [lo[ax] - 1]
+ if all(ok(q) for q in itertools.product(*rng)):
+ if d > 0:
+ hi[ax] += 1
+ else:
+ lo[ax] -= 1
+ changed = True
+ else:
+ break
+ cells = list(itertools.product(*[range(lo[i], hi[i]) for i in range(3)]))
+ return sum(q in need for q in cells), lo, hi, cells
+ while left:
+ best = max((grow(c, need[c], order) + (need[c],) for c in sorted(left)
+ for order in itertools.permutations(range(3))), key=lambda g: g[0])
+ gain, lo, hi, cells, k = best
+ taken.update(cells)
+ left.difference_update(cells)
+ out.append((lo[0], lo[1], lo[2], hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2], k))
+ return out
+
+
+def game_order_ok(bx):
+ """crossy.c's sort_boxes after build_models' turn r: does every step find a box to draw next?"""
+ for r in range(4):
+ t = []
+ for (x, y, z, w, h, d, k) in bx:
+ x0, x1, z0, z1 = 2 * x, 2 * (x + w), 2 * z, 2 * (z + d)
+ if r == 1:
+ x0, x1, z0, z1 = z0, z1, -x1, -x0
+ elif r == 2:
+ x0, x1, z0, z1 = -x1, -x0, -z1, -z0
+ elif r == 3:
+ x0, x1, z0, z1 = -z1, -z0, x0, x1
+ t.append((x0, 2 * y, z0, x1 - x0, 2 * h, z1 - z0)) # (half voxels: the order is the same)
+
+ def behind(a, b):
+ return a[0] + a[3] <= b[0] or a[2] >= b[2] + b[5] or a[1] + a[4] <= b[1]
+ used = set()
+ for _ in t:
+ for i in range(len(t)):
+ if i not in used and all(j == i or j in used or not (behind(t[j], t[i]) and not behind(t[i], t[j]))
+ for j in range(len(t))):
+ used.add(i)
+ break
+ else:
+ return False
+ return True
+
+
+def lit(c):
+ """the game's top and side colours for a vertex colour (fitted to its chicken)"""
+ top = tuple(min(255, int(0.8 * v + 54)) for v in c)
+ side = tuple(min(255, int(0.53 * v + 6)) for v in c)
+ return top, side
+
+
+def rgb565(c):
+ return (c[0] >> 3) << 11 | (c[1] >> 2) << 5 | c[2] >> 3
+
+
+def main():
+ data = sys.argv[1]
+ dest = sys.argv[2] if len(sys.argv) > 2 else "src/chars.h"
+ M = meshes(data)
+ pal, packed, at, cols, cols_at, hdr = [], [], [0], [], [0], []
+ for name, num in CHARS:
+ g, off = grid(M[name][0])
+ bx = boxes(voxels(*M[name]))
+ if len(bx) > MAXB or not game_order_ok(bx):
+ raise SystemExit(f"{name}: {len(bx)} boxes, or no drawing order")
+ x0 = min(b[0] for b in bx)
+ z0 = min(b[2] for b in bx)
+ assert min(b[1] for b in bx) == 0 and off[1] == 0
+ hdr.append((2 * x0 + round(2 * off[0]), 2 * z0 + round(2 * off[2]), round(g * 2000)))
+ assert abs(g * 2000 - hdr[-1][2]) < 1e-6 and all(-128 <= v < 128 for v in hdr[-1][:2])
+ own = []
+ for (x, y, z, w, h, d, k) in bx:
+ if k not in own:
+ own.append(k)
+ v = (x - x0, y, z - z0, w - 1, h - 1, d - 1, own.index(k))
+ for f, bits in zip(v, (4, 5, 5, 4, 5, 5, 4)):
+ assert 0 <= f < 1 << bits, (name, v)
+ packed.append(v[0] | v[1] << 4 | v[2] << 9 | v[3] << 14 | v[4] << 18 | v[5] << 23 | v[6] << 28)
+ for k in own:
+ c = lit(k)
+ if c not in pal:
+ pal.append(c)
+ cols.append(pal.index(c))
+ at.append(len(packed))
+ cols_at.append(len(cols))
+ print(f"{name} ({num:03d}): {len(bx)} boxes, {len(own)} colours, voxels {g} tile")
+ with open(dest, "w") as f:
+ f.write("// The prize machine's characters, from Crossy Road's own models (tools/chars.py writes it).\n")
+ f.write(f"#define NCHARS {len(CHARS)}\n#define NCC {len(pal)} // colours\n#define CHAR_MAXB {MAXB}\n")
+ f.write("#define CHAR_PAL \\\n")
+ for i, (top, side) in enumerate(pal):
+ f.write(f" [C_CHAR + {2 * i}] = 0x{rgb565(top):04X}, [C_CHAR + {2 * i + 1}] = 0x{rgb565(side):04X}, \\\n")
+ f.write("\n// boxes: x (4 bits), y (5), z (5), width - 1 (4), height - 1 (5), depth - 1 (5), colour (4), in voxels\n")
+ f.write("static const uint32_t char_box[] = {\n")
+ for i in range(len(CHARS)):
+ vals = [f"0x{v:08X}" for v in packed[at[i]:at[i + 1]]]
+ f.write(f" // {CHARS[i][0]}\n")
+ for j in range(0, len(vals), 6):
+ f.write(" " + ", ".join(vals[j:j + 6]) + ",\n")
+ f.write("};\n")
+ f.write("static const uint16_t char_at[NCHARS + 1] = {" + ", ".join(map(str, at)) + "};\n")
+ f.write("// west and south corner (half voxels), voxel (1/2000 tile)\n")
+ f.write("static const int8_t char_hdr[NCHARS][3] = {" + ", ".join("{%d, %d, %d}" % h for h in hdr) + "};\n")
+ f.write("static const uint8_t char_cols_at[NCHARS + 1] = {" + ", ".join(map(str, cols_at)) + "};\n")
+ f.write("static const uint8_t char_cols[] = {" + ", ".join(map(str, cols)) + "};\n")
+ n = 4 * len(packed) + 2 * (len(CHARS) + 1) + 3 * len(CHARS) + len(CHARS) + 1 + len(cols) + 4 * len(pal)
+ print(f"{len(packed)} boxes, {len(pal)} colours: {n} bytes")
+
+
+if __name__ == "__main__":
+ main()