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.

Among Us: every Skeld task's minigame, the fixes, cameras and the button

Mason363b0fade1e2d71
diff --git a/games/amongus/src/data.bin b/games/amongus/src/data.bin
index 6fdd6da2..34c592b7 100644
Binary files a/games/amongus/src/data.bin and b/games/amongus/src/data.bin differ
diff --git a/games/amongus/src/data.h b/games/amongus/src/data.h
index e6e69d37..790eb7f0 100644
--- a/games/amongus/src/data.h
+++ b/games/amongus/src/data.h
@@ -1,27 +1,281 @@
/* Among Us: what's in data.bin (made by tools/pack.py) */
#ifndef AU_DATA_H
#define AU_DATA_H
-#define N_PICS 145
+#include <stdint.h>
+#define N_PICS 203
#define N_FONTS 4
-#define BLOB_SHIP 149
-#define BLOB_MIX 150
+#define BLOB_SHIP 207
+#define BLOB_FRONT_MASKS 208
+#define BLOB_MG_CARD 209
+#define BLOB_MG_WIRES 210
+#define BLOB_MG_ASTEROIDS 211
+#define BLOB_MG_ALIGN 212
+#define BLOB_MG_SCAN 213
+#define BLOB_MG_SAMPLE 214
+#define BLOB_MG_FUEL1 215
+#define BLOB_MG_FUEL2 216
+#define BLOB_MG_SIMON 217
+#define BLOB_MG_GARBAGE 218
+#define BLOB_MG_UPLOAD 219
+#define BLOB_MG_CALIBRATE 220
+#define BLOB_MG_COURSE 221
+#define BLOB_MG_LEAVES 222
+#define BLOB_MG_MANIFOLDS 223
+#define BLOB_MG_STEERING 224
+#define BLOB_MG_SHIELDS 225
+#define BLOB_MG_DIVERT 226
+#define BLOB_MG_ACCEPT 227
+#define BLOB_MG_HANDS 228
+#define BLOB_MG_LIGHTS 229
+#define BLOB_MG_COMMS 230
+#define BLOB_MG_KEYPAD 231
+#define BLOB_MG_CAMS 232
+#define BLOB_MG_EMERGENCY 233
+#define BLOB_MIX 234
#define N_MIX 256
+#define MG_X 160
+#define MG_Y 112
enum { FONT_SMALL, FONT_MID, FONT_BIG, FONT_HUGE };
#define SHIP_OX 1117
#define SHIP_OY 274
-#define PIC_IDLE 100
-#define PIC_WALK 101
-#define PIC_GHOST 113
+#define PIC_IDLE 42
+#define PIC_WALK 43
+#define PIC_GHOST 55
#define N_GHOST 24
-#define PIC_DEAD 137
-#define PIC_JUMP 138
-#define PIC_DOOR_SIDE 58
-#define PIC_DOOR_FRONT 70
+#define PIC_DEAD 79
+#define PIC_JUMP 80
+#define PIC_IDLE_BIG 87
+#define PIC_DOOR_SIDE 0
+#define PIC_DOOR_FRONT 12
#define DOOR_CLOSE_FRAMES 4
#define DOOR_OPEN_FRAMES 8
-#define PIC_VENT 82
+#define PIC_VENT 24
#define N_VENT_FRAMES 18
-typedef struct { uint16_t pic; int16_t x, y; float z; } FrontRec;
+/* where an object in front covers the floor: a bit a pixel, rows of whole bytes, lowest bit first */
+typedef struct { uint32_t off; int16_t x, y; uint16_t w, h; float z; } FrontRec;
#define N_FRONT 58
-static const FrontRec FRONT[58] = {{0, 1946, 1403, 4.45048e-07f}, {1, 1968, 1474, 4.45048e-07f}, {2, 1950, 1423, 1.01725e-06f}, {3, 1396, 763, 1.40841e-06f}, {4, 1555, 763, 1.40841e-06f}, {5, 1279, 828, -3.88f}, {6, 1432, 946, -0.00820028f}, {7, 1559, 948, -0.00832028f}, {8, 1389, 947, -0.00832028f}, {9, 1454, 946, -0.1282f}, {10, 1153, 754, -1.6f}, {11, 2599, 617, -0.00520021f}, {12, 2543, 519, -0.00292054f}, {13, 2410, 531, -3.88f}, {14, 2523, 752, -0.0060402f}, {15, 2545, 617, -0.00472013f}, {16, 2512, 543, -0.00352021f}, {17, 1868, 50, 0.00187957f}, {18, 1716, 234, 0.00031986f}, {19, 1959, 156, -0.28f}, {20, 1665, 29, -3.64f}, {21, 1746, 1138, -0.52f}, {22, 1711, 1312, -0.0136004f}, {23, 1960, 1127, -0.0107205f}, {24, 1940, 1293, -0.52f}, {25, 2170, 561, -1.6f}, {26, 347, 986, -0.0100005f}, {27, 317, 1051, -0.0101205f}, {28, 398, 845, -1.6f}, {29, -683, 509, -4.0012f}, {30, -737, 571, -0.4012f}, {31, 868, 1220, -0.0126404f}, {32, 1037, 1190, -0.0246404f}, {33, 1040, 1137, -0.0366404f}, {34, 881, 1374, -0.0126524f}, {35, -373, 1123, -0.0112006f}, {36, -360, 1261, -0.0113206f}, {37, -189, 1053, -4.012f}, {38, -189, 1271, -4.012f}, {39, -330, 1134, -4.012f}, {40, -427, 1272, -0.0113206f}, {41, -300, 1247, -0.0113206f}, {42, -188, 1133, -0.0110806f}, {43, 537, 95, -1.48f}, {44, -313, 613, -1.6f}, {45, -375, 147, 0.000799815f}, {46, -362, 285, 0.000679815f}, {47, -191, 78, -4.0f}, {48, -191, 295, -4.0f}, {49, -332, 158, -4.0f}, {50, -429, 296, 0.000679815f}, {51, -302, 271, 0.000679815f}, {52, -190, 157, 0.000919815f}, {53, 1398, 1596, -0.0172001f}, {54, 1409, 1624, -0.0292001f}, {55, 1332, 1428, -4.12f}, {56, 1606, 1526, -0.0162406f}, {57, 1248, 1526, -0.01624f}};
+static const FrontRec FRONT[58] = {{0, 1946, 1403, 97, 144, 4.45048e-07f}, {1872, 1968, 1474, 67, 72, 4.45048e-07f}, {2520, 1950, 1423, 67, 72, 1.01725e-06f}, {3168, 1396, 763, 20, 12, 1.40841e-06f}, {3204, 1555, 763, 23, 12, 1.40841e-06f}, {3240, 1279, 828, 271, 189, -3.88f}, {9666, 1432, 946, 96, 52, -0.00820028f}, {10290, 1559, 948, 17, 34, -0.00832028f}, {10392, 1389, 947, 14, 34, -0.00832028f}, {10460, 1454, 946, 56, 29, -0.1282f}, {10663, 1153, 754, 16, 12, -1.6f}, {10687, 2599, 617, 34, 71, -0.00520021f}, {11042, 2543, 519, 38, 39, -0.00292054f}, {11237, 2410, 531, 163, 196, -3.88f}, {15353, 2523, 752, 27, 35, -0.0060402f}, {15493, 2545, 617, 33, 37, -0.00472013f}, {15678, 2512, 543, 32, 32, -0.00352021f}, {15806, 1868, 50, 39, 48, 0.00187957f}, {16046, 1716, 234, 72, 21, 0.00031986f}, {16235, 1959, 156, 59, 52, -0.28f}, {16651, 1665, 29, 264, 235, -3.64f}, {24406, 1746, 1138, 210, 229, -0.52f}, {30589, 1711, 1312, 74, 45, -0.0136004f}, {31039, 1960, 1127, 59, 19, -0.0107205f}, {31191, 1940, 1293, 21, 82, -0.52f}, {31437, 2170, 561, 16, 12, -1.6f}, {31461, 347, 986, 102, 79, -0.0100005f}, {32488, 317, 1051, 33, 30, -0.0101205f}, {32638, 398, 845, 202, 32, -1.6f}, {33470, -683, 509, 191, 333, -4.0012f}, {41462, -737, 571, 74, 81, -0.4012f}, {42272, 868, 1220, 156, 161, -0.0126404f}, {45492, 1037, 1190, 34, 16, -0.0246404f}, {45572, 1040, 1137, 28, 36, -0.0366404f}, {45716, 881, 1374, 17, 23, -0.0126524f}, {45785, -373, 1123, 149, 131, -0.0112006f}, {48274, -360, 1261, 23, 32, -0.0113206f}, {48370, -189, 1053, 10, 36, -4.012f}, {48442, -189, 1271, 10, 36, -4.012f}, {48514, -330, 1134, 33, 14, -4.012f}, {48584, -427, 1272, 24, 22, -0.0113206f}, {48650, -300, 1247, 104, 21, -0.0113206f}, {48923, -188, 1133, 30, 73, -0.0110806f}, {49215, 537, 95, 16, 12, -1.48f}, {49239, -313, 613, 16, 12, -1.6f}, {49263, -375, 147, 149, 131, 0.000799815f}, {51752, -362, 285, 23, 32, 0.000679815f}, {51848, -191, 78, 10, 36, -4.0f}, {51920, -191, 295, 10, 36, -4.0f}, {51992, -332, 158, 33, 14, -4.0f}, {52062, -429, 296, 24, 21, 0.000679815f}, {52125, -302, 271, 104, 21, 0.000679815f}, {52398, -190, 157, 30, 73, 0.000919815f}, {52690, 1398, 1596, 100, 52, -0.0172001f}, {53366, 1409, 1624, 87, 38, -0.0292001f}, {53784, 1332, 1428, 211, 172, -4.12f}, {58428, 1606, 1526, 25, 59, -0.0162406f}, {58664, 1248, 1526, 26, 59, -0.01624f}};
+#define PIC_MG_CARD_TOP 88
+#define MG_CARD_TOP_X 160
+#define MG_CARD_TOP_Y 46
+#define PIC_MG_CARD_FRONT 89
+#define MG_CARD_FRONT_X 117
+#define MG_CARD_FRONT_Y 195
+#define PIC_MG_CARD_CARD 90
+#define MG_CARD_CARD_X 117
+#define MG_CARD_CARD_Y 188
+#define PIC_MG_CARD_GREEN 91
+#define MG_CARD_GREEN_X 246
+#define MG_CARD_GREEN_Y 65
+#define PIC_MG_CARD_RED 92
+#define MG_CARD_RED_X 230
+#define MG_CARD_RED_Y 65
+#define PIC_MG_WIRES_HEAD 93
+#define MG_WIRES_HEAD_X 103
+#define MG_WIRES_HEAD_Y 52
+static const int16_t MG_WIRES_HEAD_XY[4][2] = {{103, 52}, {103, 94}, {103, 135}, {103, 177}};
+#define PIC_MG_WIRES_RNODE 94
+#define MG_WIRES_RNODE_X 232
+#define MG_WIRES_RNODE_Y 53
+static const int16_t MG_WIRES_RNODE_XY[4][2] = {{232, 53}, {232, 94}, {232, 136}, {232, 177}};
+#define PIC_MG_WIRES_SYM 95
+#define MG_WIRES_SYM_X 67
+#define MG_WIRES_SYM_Y 52
+static const int16_t MG_WIRES_SYM_XY[4][2] = {{67, 52}, {67, 94}, {67, 135}, {67, 177}};
+#define PIC_X_WIREICONS0001 96
+#define PIC_X_WIREICONS0002 97
+#define PIC_X_WIREICONS0003 98
+#define PIC_X_WIREICONS0004 99
+#define PIC_MG_ASTEROIDS_RETICLE 100
+#define MG_ASTEROIDS_RETICLE_X 160
+#define MG_ASTEROIDS_RETICLE_Y 112
+#define PIC_X_WEAPONS_ASTEROID1 101
+#define PIC_X_WEAPONS_ASTEROID2 102
+#define PIC_X_WEAPONS_ASTEROID3 103
+#define PIC_X_WEAPONS_ASTEROID4 104
+#define PIC_X_WEAPONS_ASTEROID5 105
+#define PIC_X_WEAPONS_EXPLOSION 106
+#define PIC_MG_ALIGN_SLIDER 107
+#define MG_ALIGN_SLIDER_X 222
+#define MG_ALIGN_SLIDER_Y 112
+#define PIC_MG_ALIGN_ENGINE 108
+#define MG_ALIGN_ENGINE_X 198
+#define MG_ALIGN_ENGINE_Y 112
+#define PIC_MG_SAMPLE_LIQUID 109
+#define MG_SAMPLE_LIQUID_X 110
+#define MG_SAMPLE_LIQUID_Y 112
+static const int16_t MG_SAMPLE_LIQUID_XY[5][2] = {{110, 112}, {135, 112}, {160, 112}, {186, 112}, {211, 112}};
+#define PIC_MG_SAMPLE_BUTTON 110
+#define MG_SAMPLE_BUTTON_X 160
+#define MG_SAMPLE_BUTTON_Y 180
+static const int16_t MG_SAMPLE_BUTTON_XY[5][2] = {{160, 180}, {135, 180}, {110, 180}, {185, 180}, {210, 180}};
+#define PIC_MG_SAMPLE_CONFIRM 111
+#define MG_SAMPLE_CONFIRM_X 227
+#define MG_SAMPLE_CONFIRM_Y 200
+#define PIC_MG_FUEL1_BUTTON 112
+#define MG_FUEL1_BUTTON_X 272
+#define MG_FUEL1_BUTTON_Y 188
+#define PIC_MG_FUEL1_LIGHT 113
+#define MG_FUEL1_LIGHT_X 261
+#define MG_FUEL1_LIGHT_Y 159
+#define PIC_MG_SIMON_BUTTON 114
+#define MG_SIMON_BUTTON_X 199
+#define MG_SIMON_BUTTON_Y 97
+static const int16_t MG_SIMON_BUTTON_XY[9][2] = {{199, 97}, {227, 97}, {255, 97}, {199, 125}, {227, 125}, {255, 125}, {199, 152}, {227, 152}, {255, 152}};
+#define PIC_MG_SIMON_LIGHT 115
+#define MG_SIMON_LIGHT_X 54
+#define MG_SIMON_LIGHT_Y 63
+#define PIC_X_SSBUTTON1 116
+#define PIC_X_SSBUTTON2 117
+#define PIC_X_SSBUTTON3 118
+#define PIC_X_SSBUTTON4 119
+#define PIC_X_SSBUTTON5 120
+#define PIC_X_SSBUTTON6 121
+#define PIC_X_SSBUTTON7 122
+#define PIC_X_SSBUTTON8 123
+#define PIC_X_SSBUTTON9 124
+#define PIC_X_SSLIGHTS1 125
+#define PIC_X_SSLIGHTS2 126
+#define PIC_X_SSLIGHTS3 127
+#define PIC_X_SSLIGHTS4 128
+#define PIC_X_SSLIGHTS5 129
+#define PIC_MG_GARBAGE_HANDLE 130
+#define MG_GARBAGE_HANDLE_X 230
+#define MG_GARBAGE_HANDLE_Y 86
+#define PIC_MG_GARBAGE_BARS 131
+#define MG_GARBAGE_BARS_X 230
+#define MG_GARBAGE_BARS_Y 112
+#define PIC_X_GARBAGE_1 132
+#define PIC_X_GARBAGE_2 133
+#define PIC_X_GARBAGE_3 134
+#define PIC_X_GARBAGE_4 135
+#define PIC_X_GARBAGE_5 136
+#define PIC_X_GARBAGE_6 137
+#define PIC_MG_UPLOAD_TOWER 138
+#define MG_UPLOAD_TOWER_X 233
+#define MG_UPLOAD_TOWER_Y 84
+#define PIC_MG_UPLOAD_BUTTON 139
+#define MG_UPLOAD_BUTTON_X 160
+#define MG_UPLOAD_BUTTON_Y 138
+#define PIC_MG_UPLOAD_BAR 140
+#define MG_UPLOAD_BAR_X 146
+#define MG_UPLOAD_BAR_Y 136
+#define PIC_X_DATATRANSFER_FOLDEROPEN0001 141
+#define PIC_X_DATATRANSFER_FOLDEROPEN0002 142
+#define PIC_X_DATATRANSFER_FOLDEROPEN0003 143
+#define PIC_X_DATATRANSFER_FOLDEROPEN0004 144
+#define PIC_X_DATATRANSFER_FOLDEROPEN0005 145
+#define PIC_X_DATATRANSFER_FILEFILL 146
+#define PIC_X_DATATRANSFER_DOWNLOADBUTTON 147
+#define PIC_MG_CALIBRATE_SPIN1 148
+#define MG_CALIBRATE_SPIN1_X 104
+#define MG_CALIBRATE_SPIN1_Y 51
+#define PIC_MG_CALIBRATE_SPIN2 149
+#define MG_CALIBRATE_SPIN2_X 104
+#define MG_CALIBRATE_SPIN2_Y 110
+#define PIC_MG_CALIBRATE_SPIN3 150
+#define MG_CALIBRATE_SPIN3_X 104
+#define MG_CALIBRATE_SPIN3_Y 170
+#define PIC_MG_CALIBRATE_LIT1 151
+#define MG_CALIBRATE_LIT1_X 138
+#define MG_CALIBRATE_LIT1_Y 52
+#define PIC_MG_CALIBRATE_LIT2 152
+#define MG_CALIBRATE_LIT2_X 137
+#define MG_CALIBRATE_LIT2_Y 110
+#define PIC_MG_CALIBRATE_LIT3 153
+#define MG_CALIBRATE_LIT3_X 137
+#define MG_CALIBRATE_LIT3_Y 171
+#define PIC_MG_COURSE_SHIP 154
+#define MG_COURSE_SHIP_X 160
+#define MG_COURSE_SHIP_Y 112
+#define PIC_MG_COURSE_END 155
+#define MG_COURSE_END_X 254
+#define MG_COURSE_END_Y 116
+#define PIC_X_NAV_CHARTCOURSE_CHECKPT 156
+#define PIC_X_NAV_CHARTCOURSE_START 157
+#define PIC_X_O2_LEAF1 158
+#define PIC_X_O2_LEAF2 159
+#define PIC_X_O2_LEAF3 160
+#define PIC_X_O2_LEAF4 161
+#define PIC_X_O2_LEAF5 162
+#define PIC_X_O2_LEAF6 163
+#define PIC_X_O2_LEAF7 164
+#define PIC_X_REACTORBUTTON01 165
+#define PIC_X_REACTORBUTTON02 166
+#define PIC_X_REACTORBUTTON03 167
+#define PIC_X_REACTORBUTTON04 168
+#define PIC_X_REACTORBUTTON05 169
+#define PIC_X_REACTORBUTTON06 170
+#define PIC_X_REACTORBUTTON07 171
+#define PIC_X_REACTORBUTTON08 172
+#define PIC_X_REACTORBUTTON09 173
+#define PIC_X_REACTORBUTTON10 174
+#define PIC_MG_STEERING_CROSS 175
+#define MG_STEERING_CROSS_X 222
+#define MG_STEERING_CROSS_Y 58
+#define PIC_MG_SHIELDS_HEX 176
+#define MG_SHIELDS_HEX_X 160
+#define MG_SHIELDS_HEX_Y 112
+static const int16_t MG_SHIELDS_HEX_XY[7][2] = {{160, 112}, {112, 84}, {161, 56}, {208, 84}, {209, 141}, {160, 169}, {110, 140}};
+#define PIC_MG_DIVERT_SWITCH 177
+#define MG_DIVERT_SWITCH_X 85
+#define MG_DIVERT_SWITCH_Y 167
+#define PIC_MG_ACCEPT_SWITCH 178
+#define MG_ACCEPT_SWITCH_X 160
+#define MG_ACCEPT_SWITCH_Y 113
+#define PIC_MG_LIGHTS_SWITCH 179
+#define MG_LIGHTS_SWITCH_X 83
+#define MG_LIGHTS_SWITCH_Y 166
+static const int16_t MG_LIGHTS_SWITCH_XY[5][2] = {{83, 166}, {122, 166}, {161, 166}, {200, 166}, {238, 166}};
+#define PIC_MG_LIGHTS_LIGHT 180
+#define MG_LIGHTS_LIGHT_X 83
+#define MG_LIGHTS_LIGHT_Y 193
+static const int16_t MG_LIGHTS_LIGHT_XY[5][2] = {{83, 193}, {122, 193}, {161, 193}, {200, 193}, {238, 193}};
+#define PIC_MG_COMMS_DIAL 181
+#define MG_COMMS_DIAL_X 223
+#define MG_COMMS_DIAL_Y 175
+#define PIC_MG_COMMS_DIALSHADOW 182
+#define MG_COMMS_DIALSHADOW_X 223
+#define MG_COMMS_DIALSHADOW_Y 179
+#define PIC_MG_COMMS_GLASS 183
+#define MG_COMMS_GLASS_X 127
+#define MG_COMMS_GLASS_Y 108
+#define PIC_MG_COMMS_LIGHT 184
+#define MG_COMMS_LIGHT_X 259
+#define MG_COMMS_LIGHT_Y 141
+static const int16_t MG_COMMS_LIGHT_XY[2][2] = {{247, 140}, {259, 141}};
+#define PIC_MG_KEYPAD_NOTE 185
+#define MG_KEYPAD_NOTE_X 257
+#define MG_KEYPAD_NOTE_Y 65
+#define PIC_MG_KEYPAD_X 186
+#define MG_KEYPAD_X_X 124
+#define MG_KEYPAD_X_Y 185
+#define PIC_MG_KEYPAD_CHECK 187
+#define MG_KEYPAD_CHECK_X 196
+#define MG_KEYPAD_CHECK_Y 185
+#define PIC_MG_KEYPAD_K1 188
+#define MG_KEYPAD_K1_X 124
+#define MG_KEYPAD_K1_Y 77
+#define PIC_X_ADMIN_KEYPAD_0 189
+#define PIC_X_ADMIN_KEYPAD_1 190
+#define PIC_X_ADMIN_KEYPAD_2 191
+#define PIC_X_ADMIN_KEYPAD_3 192
+#define PIC_X_ADMIN_KEYPAD_4 193
+#define PIC_X_ADMIN_KEYPAD_5 194
+#define PIC_X_ADMIN_KEYPAD_6 195
+#define PIC_X_ADMIN_KEYPAD_7 196
+#define PIC_X_ADMIN_KEYPAD_8 197
+#define PIC_X_ADMIN_KEYPAD_9 198
+#define PIC_MG_EMERGENCY_CLOSED 199
+#define MG_EMERGENCY_CLOSED_X 160
+#define MG_EMERGENCY_CLOSED_Y 94
+#define PIC_MG_EMERGENCY_OPEN 200
+#define MG_EMERGENCY_OPEN_X 230
+#define MG_EMERGENCY_OPEN_Y 73
+#define PIC_MG_EMERGENCY_BUTTON 201
+#define MG_EMERGENCY_BUTTON_X 160
+#define MG_EMERGENCY_BUTTON_Y 154
+#define PIC_MG_EMERGENCY_BUBBLE 202
+#define MG_EMERGENCY_BUBBLE_X 160
+#define MG_EMERGENCY_BUBBLE_Y 172
#endif
diff --git a/games/amongus/src/gfx.c b/games/amongus/src/gfx.c
index 67bb0e42..a7083b81 100644
--- a/games/amongus/src/gfx.c
+++ b/games/amongus/src/gfx.c
@@ -140,6 +140,46 @@ void gfx_pic(const Pic *p, float x, float y, float sx, float sy, float angle, co
}
}
+void gfx_tiles(const TilePic *s, int x, int y) {
+ const uint16_t *map = tile_map(s);
+ x -= s->ox, y -= s->oy;
+ int y0 = gfx_y0 - y, y1 = y0 + BAND; /* the band's rows in the picture */
+ if (y1 <= 0 || y0 >= s->th * 16) return;
+ int ty0 = y0 < 0 ? 0 : y0 >> 4, ty1 = (y1 - 1) >> 4;
+ if (ty1 >= s->th) ty1 = s->th - 1;
+ int tx0 = x < 0 ? (-x) >> 4 : 0, tx1 = (SCREEN_W - 1 - x) >> 4;
+ if (tx1 >= s->tw) tx1 = s->tw - 1;
+ for (int ty = ty0; ty <= ty1; ty++) {
+ int r0 = ty * 16 < y0 ? y0 - ty * 16 : 0, r1 = ty * 16 + 16 > y1 ? y1 - ty * 16 : 16;
+ for (int tx = tx0; tx <= tx1; tx++) {
+ unsigned t = map[ty * s->tw + tx];
+ if (t == T_EMPTY) continue;
+ int sx = x + tx * 16;
+ int c0 = sx < 0 ? -sx : 0, c1 = sx + 16 > SCREEN_W ? SCREEN_W - sx : 16;
+ const uint8_t *d = tile_data(s, t);
+ const uint16_t *pal = (const uint16_t *)(const void *)d;
+ bool clear = t & T_CLEAR;
+ for (int r = r0; r < r1; r++) {
+ uint16_t *row = gfx_band + (y + ty * 16 + r - gfx_y0) * SCREEN_W + sx;
+ const uint8_t *src = d + 32 + r * 8;
+ if (!clear) {
+ int c = c0;
+ if (c & 1) row[c] = pal[src[c >> 1] & 15], c++;
+ for (; c + 1 < c1; c += 2) {
+ uint8_t b = src[c >> 1];
+ row[c] = pal[b >> 4], row[c + 1] = pal[b & 15];
+ }
+ if (c < c1) row[c] = pal[src[c >> 1] >> 4];
+ } else
+ for (int c = c0; c < c1; c++) {
+ unsigned k = c & 1 ? src[c >> 1] & 15 : src[c >> 1] >> 4;
+ if (k != 15) row[c] = pal[k];
+ }
+ }
+ }
+ }
+}
+
void gfx_fill(int x, int y, int w, int h, uint16_t c, int alpha) {
int y0 = y > gfx_y0 ? y : gfx_y0, y1 = y + h < gfx_y0 + BAND ? y + h : gfx_y0 + BAND;
if (x < 0) w += x, x = 0;
diff --git a/games/amongus/src/gfx.h b/games/amongus/src/gfx.h
index 1b1a6a66..d0c2b9f2 100644
--- a/games/amongus/src/gfx.h
+++ b/games/amongus/src/gfx.h
@@ -40,6 +40,8 @@ void gfx_spr_clip(const Pic *p, int x, int y, bool flip, const uint16_t *pal, in
void gfx_pic(const Pic *p, float x, float y, float sx, float sy, float angle, const uint16_t *pal, int alpha);
/* a picture tinted by c (alpha kept): the outlines of usable consoles */
void gfx_spr_tint(const Pic *p, int x, int y, uint16_t c, int alpha);
+/* a tiled picture with its pivot at (x, y) */
+void gfx_tiles(const TilePic *s, int x, int y);
void gfx_fill(int x, int y, int w, int h, uint16_t c, int alpha);
void gfx_rect(int x, int y, int w, int h, int t, uint16_t c);
void gfx_line(float x0, float y0, float x1, float y1, float w, uint16_t c, int alpha);
diff --git a/games/amongus/src/mg.c b/games/amongus/src/mg.c
index eb88fd75..89794f9a 100644
--- a/games/amongus/src/mg.c
+++ b/games/amongus/src/mg.c
@@ -1,66 +1,813 @@
-/* Among Us: the minigames (each task's and each fix's panel), the emergency button and the cameras. */
+/* Among Us: the minigames, made for the keypad: each task's panel from the game's own pictures, at the phone's
+ * size (40 px a unit), its root at MG_X, MG_Y. This file: opening and closing, and the first half of them. */
#include <math.h>
#include <stdio.h>
#include <string.h>
-#include "game.h"
-#include "gfx.h"
+#include "mg.h"
#include "view.h"
#include "world.h"
void hud_keys(const char *s);
-typedef struct {
- uint8_t task, kind, done, pad;
- float t, done_t;
-} MgHead;
-#define MG ((MgHead *)(void *)g.mg)
+#define WHITE 0xFFFF
+#define BLACK 0x0000
+
+void mg_keys(const char *s) { hud_keys(s); }
+void mg_bg(int blob_id) { gfx_tiles(tilepic(blob_id), MG_X, MG_Y); }
+void mg_status(const char *s, int y, uint16_t c) { gfx_text(FONT_MID, MG_X, y, s, c, BLACK, 1, 1); }
+
+static int kind_of(int cons, int task) {
+ if (task < MAX_TASKS) {
+ const Task *t = &g.p[g.me].tasks[task];
+ switch (TASK_DEFS[t->def].type) {
+ case T_SWIPE_CARD: return MG_CARD;
+ case T_FIX_WIRING: return MG_WIRES;
+ case T_CLEAR_ASTEROIDS: return MG_ASTEROIDS;
+ case T_ALIGN_ENGINE: return MG_ALIGN;
+ case T_SUBMIT_SCAN: return MG_SCAN;
+ case T_INSPECT_SAMPLE: return MG_SAMPLE;
+ case T_FUEL_ENGINES: return MG_FUEL;
+ case T_START_REACTOR: return MG_SIMON;
+ case T_EMPTY_CHUTE:
+ case T_EMPTY_GARBAGE: return MG_GARBAGE;
+ case T_UPLOAD_DATA: return MG_UPLOAD;
+ case T_CALIBRATE: return MG_CALIBRATE;
+ case T_CHART_COURSE: return MG_COURSE;
+ case T_CLEAN_O2: return MG_LEAVES;
+ case T_UNLOCK_MANIFOLDS: return MG_MANIFOLDS;
+ case T_STABILIZE: return MG_STEERING;
+ case T_PRIME_SHIELDS: return MG_SHIELDS;
+ case T_DIVERT_POWER: return t->step ? MG_ACCEPT : MG_DIVERT;
+ }
+ }
+ const ConsoleRec *C = &CONSOLES[cons];
+ if (C->kind == 2) return MG_EMERGENCY;
+ if (C->kind == 3) return MG_CAMS;
+ if (C->types >> T_RESET_REACTOR & 1) return MG_HANDS;
+ if (C->types >> T_RESTORE_O2 & 1) return MG_KEYPAD;
+ if (C->types >> T_FIX_LIGHTS & 1) return MG_LIGHTS;
+ return MG_COMMS;
+}
+
+static void open1(int kind);
void mg_open(int cons, int task) {
memset(g.mg, 0, sizeof g.mg);
- g.mg_cons = (uint8_t)cons;
- MG->task = (uint8_t)task;
+ M->cons = (uint8_t)cons;
+ M->task = (uint8_t)(task < MAX_TASKS ? task : NONE);
+ M->kind = (uint8_t)kind_of(cons, task);
g.overlay = O_TASK;
+ if (M->kind <= MG_COURSE) open1(M->kind);
+ else mg2_open(M->kind);
}
bool mg_blocks_move(void) { return g.overlay != O_NONE; }
+void mg_finish(void) {
+ if (M->done) return;
+ M->done = 1;
+ M->done_t = 0;
+ if (M->task != NONE) task_step_done(g.me, M->task);
+}
+
+static void tick1(uint32_t keys, uint32_t pressed);
+static void draw1(void);
+
void mg_tick(uint32_t keys, uint32_t pressed) {
- MG->t += DT;
- if (g.overlay == O_EMERGENCY) {
- if (pressed & (K_OK | K_EXE)) {
- g.overlay = O_NONE;
- start_meeting(g.me, NONE);
- }
- if (pressed & K_BACK) g.overlay = O_NONE;
+ M->t += DT;
+ if (M->done) {
+ /* the panel stays a moment, then closes (Minigame.Close after the task is done) */
+ M->done_t += DT;
+ if (M->done_t > 0.75f || (pressed & K_BACK)) g.overlay = O_NONE;
return;
}
- if (g.overlay == O_CAMS) {
- if (pressed & K_BACK) g.overlay = O_NONE;
+ /* a sabotage fixed meanwhile, or the player dead: closed */
+ if (M->kind >= MG_HANDS && M->kind <= MG_KEYPAD && !g.sab) {
+ g.overlay = O_NONE;
return;
}
if (pressed & K_BACK) {
g.overlay = O_NONE;
return;
}
- (void)keys;
- if (pressed & K_OK) {
- if (MG->task < MAX_TASKS) task_step_done(g.me, MG->task);
- g.overlay = O_NONE;
- }
+ if (M->kind <= MG_COURSE) tick1(keys, pressed);
+ else mg2_tick(keys, pressed);
}
void mg_draw(void) {
view_draw();
- gfx_fill(0, 0, SCREEN_W, SCREEN_H, 0x0000, 120);
- if (g.overlay == O_CAMS) {
- for (int k = 0; k < N_CAMS; k++) {
- int x = 8 + (k & 1) * 156, y = 8 + (k >> 1) * 108;
- view_camera((V2){CAMS[k].x, CAMS[k].y}, 104.0f / (2 * CAMS[k].size), x, y, 148, 104);
+ gfx_fill(0, gfx_y0, SCREEN_W, BAND, BLACK, 110);
+ if (M->kind <= MG_COURSE) draw1();
+ else mg2_draw();
+}
+
+/* ---- Swipe Card (CardSlideGame: AcceptedTime 0.33-0.6 s) ---- */
+
+#define CARD_Y 82
+#define CARD_X0 72
+#define CARD_X1 248
+
+static void card_tick(uint32_t keys, uint32_t pressed) {
+ /* phase 0 in the wallet, 1 at the reader, 2 swiping, 3 a bad read shown */
+ if (M->phase == 0 && (pressed & K_OK)) M->phase = 1, M->a = CARD_X0, snprintf(M->text, sizeof M->text, "Please swipe card");
+ else if (M->phase == 1 && (keys & K_RIGHT)) M->phase = 2, M->b = 0, M->c = 0;
+ else if (M->phase == 2) {
+ M->b += DT;
+ if (keys & K_RIGHT) {
+ M->c += DT;
+ float v = 30 * M->c; /* faster as it's held (a finger's swipe) */
+ if (v > 12) v = 12;
+ M->a += v * DT * PX_PER_UNIT;
}
- hud_keys("Back close");
- return;
+ if (M->a >= CARD_X1) {
+ M->a = CARD_X1;
+ if (M->b < 0.33f) snprintf(M->text, sizeof M->text, "Too fast. Try again.");
+ else if (M->b > 0.6f) snprintf(M->text, sizeof M->text, "Too slow. Try again.");
+ else {
+ snprintf(M->text, sizeof M->text, "Accepted. Thank you.");
+ M->flags = 2;
+ mg_finish();
+ return;
+ }
+ M->phase = 3, M->flags = 1, M->c = 0;
+ } else if (!(keys & K_RIGHT) && M->c > 0) {
+ snprintf(M->text, sizeof M->text, "Bad read. Try again.");
+ M->phase = 3, M->flags = 1, M->c = 0;
+ }
+ } else if (M->phase == 3) {
+ M->a += (CARD_X0 - M->a) * 0.3f;
+ M->c += DT;
+ if (M->c > 0.4f) M->phase = 1, M->a = CARD_X0;
+ }
+}
+
+static void card_draw(void) {
+ mg_bg(BLOB_MG_CARD);
+ if (M->phase == 0) {
+ gfx_spr(pic(PIC_MG_CARD_CARD), MG_CARD_CARD_X, MG_CARD_CARD_Y, false, NULL, 256);
+ gfx_spr(pic(PIC_MG_CARD_FRONT), MG_CARD_FRONT_X, MG_CARD_FRONT_Y, false, NULL, 256);
+ } else {
+ gfx_spr(pic(PIC_MG_CARD_FRONT), MG_CARD_FRONT_X, MG_CARD_FRONT_Y, false, NULL, 256);
+ gfx_spr(pic(PIC_MG_CARD_CARD), (int)M->a, CARD_Y, false, NULL, 256);
+ }
+ gfx_spr(pic(PIC_MG_CARD_TOP), MG_CARD_TOP_X, MG_CARD_TOP_Y, false, NULL, 256);
+ /* the lights: red for a bad read, green when accepted */
+ gfx_spr(pic(PIC_MG_CARD_RED), MG_CARD_RED_X, MG_CARD_RED_Y, false, NULL, 256);
+ if (M->flags != 1) gfx_spr_tint(pic(PIC_MG_CARD_RED), MG_CARD_RED_X, MG_CARD_RED_Y, BLACK, 160);
+ gfx_spr(pic(PIC_MG_CARD_GREEN), MG_CARD_GREEN_X, MG_CARD_GREEN_Y, false, NULL, 256);
+ if (M->flags != 2) gfx_spr_tint(pic(PIC_MG_CARD_GREEN), MG_CARD_GREEN_X, MG_CARD_GREEN_Y, BLACK, 160);
+ gfx_text(FONT_MID, 74, 26, M->phase == 0 ? "Please insert card" : M->text, rgb565(0x4CFF4C), 0, 0, 0);
+ mg_keys(M->phase == 0 ? "OK take the card out Back close" : "hold right to swipe Back close");
+}
+
+/* ---- Fix Wiring (WireMinigame): red, blue, yellow, magenta ---- */
+
+static const uint32_t WIRE_COLORS[4] = {0xFF0000, 0x2626FF, 0xFFEB04, 0xFF00FF};
+
+static void wires_open(void) {
+ for (int k = 0; k < 4; k++) M->order[k] = (uint8_t)k, M->order[4 + k] = (uint8_t)k;
+ for (int s = 0; s < 2; s++)
+ for (int k = 3; k > 0; k--) {
+ int j = rnd_n(k + 1);
+ uint8_t t = M->order[s * 4 + k];
+ M->order[s * 4 + k] = M->order[s * 4 + j], M->order[s * 4 + j] = t;
+ }
+ for (int k = 0; k < 4; k++) M->state[k] = NONE; /* where each left wire is plugged */
+}
+
+static void wires_tick(uint32_t pressed) {
+ /* phase 0: choosing a wire on the left; 1: carrying it to the right */
+ if (pressed & K_UP) M->n = (uint8_t)((M->n + 3) & 3);
+ if (pressed & K_DOWN) M->n = (uint8_t)((M->n + 1) & 3);
+ if (M->phase == 0) {
+ if (pressed & K_OK && M->state[M->n] == NONE) M->sel = M->n, M->phase = 1;
+ } else {
+ if (pressed & K_OK) {
+ int left = M->order[M->sel], right = M->order[4 + M->n];
+ if (left == right) {
+ M->state[M->sel] = M->n;
+ int done = 0;
+ for (int k = 0; k < 4; k++) done += M->state[k] != NONE;
+ if (done == 4) mg_finish();
+ }
+ M->phase = 0;
+ /* the next free wire */
+ for (int k = 0; k < 4; k++)
+ if (M->state[(M->sel + k) & 3] == NONE) {
+ M->n = (uint8_t)((M->sel + k) & 3);
+ break;
+ }
+ }
+ }
+}
+
+static void wire(int y0, int x1, int y1, uint32_t col) {
+ gfx_line(88, (float)y0, (float)x1, (float)y1, 9, BLACK, 256);
+ gfx_line(88, (float)y0, (float)x1, (float)y1, 6, rgb565(col), 256);
+}
+
+static void wires_draw(void) {
+ mg_bg(BLOB_MG_WIRES);
+ for (int k = 0; k < 4; k++) {
+ int ly = MG_WIRES_HEAD_XY[k][1], ry = MG_WIRES_RNODE_XY[k][1];
+ uint32_t lc = WIRE_COLORS[M->order[k]], rc = WIRE_COLORS[M->order[4 + k]];
+ /* the right ends */
+ gfx_fill(234, ry - 5, 30, 10, BLACK, 256);
+ gfx_fill(234, ry - 4, 30, 8, rgb565(rc), 256);
+ gfx_spr(pic(PIC_MG_WIRES_RNODE), MG_WIRES_RNODE_XY[k][0], ry, false, NULL, 256);
+ gfx_spr(pic(PIC_X_WIREICONS0001 + M->order[4 + k]), 254, ry, false, NULL, 256);
+ /* the left wires: plugged, carried or waiting */
+ gfx_fill(56, ly - 5, 34, 10, BLACK, 256);
+ gfx_fill(56, ly - 4, 34, 8, rgb565(lc), 256);
+ int hx = MG_WIRES_HEAD_XY[k][0], hy = ly;
+ if (M->state[k] != NONE) hx = 220, hy = MG_WIRES_RNODE_XY[M->state[k]][1];
+ else if (M->phase == 1 && M->sel == k) hx = 205, hy = MG_WIRES_RNODE_XY[M->n][1];
+ if (hx != MG_WIRES_HEAD_XY[k][0]) wire(ly, hx, hy, lc);
+ gfx_spr(pic(PIC_MG_WIRES_HEAD), hx, hy, false, NULL, 256);
+ gfx_fill(hx - 10, hy - 3, 7, 6, rgb565(lc), 256);
+ gfx_spr(pic(PIC_X_WIREICONS0001 + M->order[k]), MG_WIRES_SYM_XY[k][0], ly, false, NULL, 256);
+ /* the lights: on when a wire is in */
+ if (M->state[k] != NONE) {
+ gfx_fill(64, ly - 18, 10, 4, 0xFFE0, 256);
+ gfx_fill(248, MG_WIRES_RNODE_XY[M->state[k]][1] - 18, 10, 4, 0xFFE0, 256);
+ }
+ }
+ /* the choice */
+ int y = M->phase == 0 ? MG_WIRES_HEAD_XY[M->n][1] : MG_WIRES_RNODE_XY[M->n][1];
+ int x = M->phase == 0 ? 46 : 272;
+ float q[6] = {(float)x - 6, (float)y - 7, (float)x - 6, (float)y + 7, (float)x + 6, (float)y};
+ if (M->phase) q[0] = q[2] = (float)x + 6, q[4] = (float)x - 6;
+ gfx_poly(q, 3, rgb565(0x05FF00), 256);
+ mg_keys(M->phase == 0 ? "up down choose a wire OK pick it up Back close" : "up down choose where OK plug it in");
+}
+
+/* ---- Clear Asteroids (WeaponsMinigame: 20 to destroy) ---- */
+
+#define AST_X0 60
+#define AST_X1 260
+#define AST_Y0 12
+#define AST_Y1 212
+
+static void ast_tick(uint32_t keys, uint32_t pressed) {
+ Task *t = &g.p[g.me].tasks[M->task];
+ /* the reticle */
+ float sp = 160 * DT;
+ if (keys & K_LEFT) M->a -= sp;
+ if (keys & K_RIGHT) M->a += sp;
+ if (keys & K_UP) M->b -= sp;
+ if (keys & K_DOWN) M->b += sp;
+ if (M->t < DT * 1.5f) M->a = 160, M->b = 112;
+ if (M->a < AST_X0 + 10) M->a = AST_X0 + 10;
+ if (M->a > AST_X1 - 10) M->a = AST_X1 - 10;
+ if (M->b < AST_Y0 + 10) M->b = AST_Y0 + 10;
+ if (M->b > AST_Y1 - 10) M->b = AST_Y1 - 10;
+ /* asteroids come in from the right */
+ M->c -= DT;
+ if (M->c <= 0) {
+ M->c = 0.5f + rnd_f() * 0.6f;
+ for (int k = 0; k < 10; k++) {
+ Thing *a = &M->th[k];
+ if (a->on) continue;
+ a->on = 1;
+ a->kind = (uint8_t)rnd_n(5);
+ a->x = AST_X1 + 30;
+ a->y = AST_Y0 + 20 + rnd_f() * (AST_Y1 - AST_Y0 - 40);
+ a->vx = -(40 + rnd_f() * 50);
+ a->vy = (rnd_f() - 0.5f) * 40;
+ a->a = 0;
+ break;
+ }
+ }
+ for (int k = 0; k < 10; k++) {
+ Thing *a = &M->th[k];
+ if (!a->on) continue;
+ if (a->on == 2) {
+ a->a += DT;
+ if (a->a > 0.3f) a->on = 0;
+ continue;
+ }
+ a->x += a->vx * DT, a->y += a->vy * DT;
+ if (a->x < AST_X0 - 40 || a->y < AST_Y0 - 40 || a->y > AST_Y1 + 40) a->on = 0;
+ }
+ if (M->flags) M->flags--;
+ if (pressed & K_OK) {
+ M->flags = 4; /* the shot's lines, a few frames */
+ for (int k = 0; k < 10; k++) {
+ Thing *a = &M->th[k];
+ if (a->on != 1) continue;
+ float dx = a->x - M->a, dy = a->y - M->b;
+ if (dx * dx + dy * dy < 20 * 20) {
+ a->on = 2, a->a = 0;
+ task_step_done(g.me, M->task);
+ if (task_done(t)) M->done = 1, M->done_t = -0.5f;
+ break;
+ }
+ }
+ }
+}
+
+static void ast_draw(void) {
+ mg_bg(BLOB_MG_ASTEROIDS);
+ for (int k = 0; k < 10; k++) {
+ const Thing *a = &M->th[k];
+ if (!a->on) continue;
+ const Pic *p = pic(a->on == 2 ? PIC_X_WEAPONS_EXPLOSION : PIC_X_WEAPONS_ASTEROID1 + a->kind);
+ gfx_spr_clip(p, (int)a->x, (int)a->y, false, NULL, 256, AST_X0, AST_Y0, AST_X1, AST_Y1);
+ }
+ if (M->flags) {
+ gfx_line(AST_X0, AST_Y1, M->a, M->b, 2, rgb565(0x7CFC7C), 256);
+ gfx_line(AST_X1, AST_Y1, M->a, M->b, 2, rgb565(0x7CFC7C), 256);
+ }
+ gfx_spr(pic(PIC_MG_ASTEROIDS_RETICLE), (int)M->a, (int)M->b, false, NULL, 256);
+ char b[32];
+ const Task *t = &g.p[g.me].tasks[M->task];
+ snprintf(b, sizeof b, "Destroyed: %d", t->step);
+ gfx_text(FONT_MID, AST_X0 + 6, AST_Y1 - 6, b, rgb565(0x7CFC7C), BLACK, 1, 0);
+ mg_keys("arrows aim OK fire Back close");
+}
+
+/* ---- Align Engine Output (AlignGame: the slider on its arc, YRange +-2.13) ---- */
+
+static void align_open(void) {
+ M->a = (rnd() & 1 ? 1 : -1) * (1.0f + rnd_f() * 1.0f); /* the slider, in units */
+}
+
+static void align_tick(uint32_t keys) {
+ if (keys & K_UP) M->a += 1.6f * DT;
+ if (keys & K_DOWN) M->a -= 1.6f * DT;
+ if (M->a > 2.13f) M->a = 2.13f;
+ if (M->a < -2.13f) M->a = -2.13f;
+ if (!(keys & (K_UP | K_DOWN)) && fabsf(M->a) < 0.06f) {
+ M->a = 0;
+ mg_finish();
+ }
+}
+
+static void align_draw(void) {
+ mg_bg(BLOB_MG_ALIGN);
+ float y = M->a * PX_PER_UNIT;
+ /* the engine turns with the slider */
+ gfx_pic(pic(PIC_MG_ALIGN_ENGINE), MG_ALIGN_ENGINE_X, MG_ALIGN_ENGINE_Y, 1, 1, -M->a * 0.2f, NULL, 256);
+ /* the centre line, and the slider on its arc */
+ gfx_line(70, MG_Y, 205, MG_Y, 1, M->done ? rgb565(0x37FF37) : rgb565(0xFF4040), 200);
+ float R = 230, dx = R - sqrtf(R * R - y * y);
+ gfx_spr(pic(PIC_MG_ALIGN_SLIDER), MG_ALIGN_SLIDER_X - (int)dx, MG_Y - (int)y, false, NULL, 256);
+ mg_keys("up down move the slider to the middle Back close");
+}
+
+/* ---- Submit Scan (MedScanMinigame: one at a time on the scanner) ---- */
+
+int scanning_player(void) {
+ for (int i = 0; i < g.nplayers; i++)
+ if (i != g.me && g.p[i].alive && g.p[i].busy && g.p[i].bot.task < MAX_TASKS &&
+ TASK_DEFS[g.p[i].tasks[g.p[i].bot.task].def].type == T_SUBMIT_SCAN)
+ return i;
+ return -1;
+}
+
+static void scan_tick(void) {
+ Player *P = &g.p[g.me];
+ if (M->phase == 0) {
+ int w = scanning_player();
+ if (w < 0) {
+ M->phase = 1, M->b = 0;
+ /* onto the scanner */
+ P->pos = (V2){CONSOLES[M->cons].x, CONSOLES[M->cons].y - 0.05f};
+ P->flip = 0;
+ } else
+ M->sel = (uint8_t)w;
+ } else if (M->phase == 1) {
+ M->b += DT;
+ P->busy = 1;
+ if (M->b >= 10) {
+ P->busy = 0;
+ mg_finish();
+ }
+ }
+}
+
+static void scan_draw(void) {
+ mg_bg(BLOB_MG_SCAN);
+ const Player *P = &g.p[g.me];
+ char b[64];
+ if (M->phase == 0) snprintf(b, sizeof b, "Waiting for %s...", COLOR_NAMES[g.p[M->sel].color]);
+ else snprintf(b, sizeof b, M->done ? "Scan complete" : "Scanning...");
+ gfx_text(FONT_MID, 72, 191, b, WHITE, 0, 0, 0);
+ if (M->phase) {
+ /* the readout and the bar */
+ static const char *const BT[] = {"O-", "A+", "B-", "AB", "O+", "A-"};
+ snprintf(b, sizeof b, "ID: %c%c%c%c%c HT: 3' 6\" WT: 92lb", 'A' + P->color, 'K' + P->color % 7, 'R', 'D' + P->color % 5,
+ 'X' - P->color % 4);
+ gfx_text(FONT_SMALL, 72, 46, b, WHITE, 0, 0, 0);
+ snprintf(b, sizeof b, "C: %s BT: %s", COLOR_NAMES[P->color], BT[P->color % 6]);
+ gfx_text(FONT_SMALL, 72, 60, b, WHITE, 0, 0, 0);
+ float f = M->b / 10;
+ if (f > 1) f = 1;
+ gfx_fill(70, 160, (int)(180 * f), 10, rgb565(0x00C017), 256);
+ }
+ mg_keys("stay still while the scan runs Back close");
+}
+
+/* ---- Inspect Sample (SampleMinigame: 60 s for the reagent) ---- */
+
+static void sample_open(void) {
+ const Task *t = &g.p[g.me].tasks[M->task];
+ if (t->timer == 0) M->phase = 3, M->sel = 2, M->n = (uint8_t)rnd_n(5);
+ else if (t->timer > 0) M->phase = 2;
+}
+
+static void sample_tick(uint32_t pressed) {
+ Task *t = &g.p[g.me].tasks[M->task];
+ if (M->phase == 0 && (pressed & K_OK)) M->phase = 1, M->b = 0;
+ else if (M->phase == 1) {
+ M->b += DT;
+ if (M->b > 2) {
+ M->phase = 2;
+ t->timer = 60;
+ }
+ } else if (M->phase == 2 && t->timer == 0) M->phase = 3, M->sel = 2, M->n = (uint8_t)rnd_n(5);
+ else if (M->phase == 3) {
+ if (pressed & K_LEFT) M->sel = (uint8_t)((M->sel + 4) % 5);
+ if (pressed & K_RIGHT) M->sel = (uint8_t)((M->sel + 1) % 5);
+ if (pressed & K_OK) {
+ if (M->sel == M->n) mg_finish();
+ else {
+ /* a wrong one: start over */
+ M->phase = 0;
+ t->timer = -1;
+ }
+ }
+ }
+}
+
+static void sample_draw(void) {
+ mg_bg(BLOB_MG_SAMPLE);
+ const Task *t = &g.p[g.me].tasks[M->task];
+ /* the tubes, filled from left to right */
+ int filled = M->phase == 1 ? (int)(M->b / 2 * 5.99f) : M->phase >= 2 ? 5 : 0;
+ for (int k = 0; k < 5; k++) {
+ if (k >= filled) continue;
+ int x = MG_SAMPLE_LIQUID_XY[k][0], y = MG_SAMPLE_LIQUID_XY[k][1];
+ gfx_spr(pic(PIC_MG_SAMPLE_LIQUID), x, y, false, NULL, 256);
+ if (M->phase == 3 && k == M->n) gfx_spr_tint(pic(PIC_MG_SAMPLE_LIQUID), x, y, 0xF800, 200);
+ }
+ /* the buttons under them, left to right */
+ static const uint8_t ORDER[5] = {2, 1, 0, 3, 4};
+ for (int k = 0; k < 5; k++) {
+ int i = ORDER[k];
+ gfx_spr(pic(PIC_MG_SAMPLE_BUTTON), MG_SAMPLE_BUTTON_XY[i][0], MG_SAMPLE_BUTTON_XY[i][1], false, NULL, 256);
+ if (M->phase == 3 && M->sel == k) gfx_rect(MG_SAMPLE_BUTTON_XY[i][0] - 9, MG_SAMPLE_BUTTON_XY[i][1] - 9, 18, 18, 2, 0xFFE0);
+ }
+ gfx_spr(pic(PIC_MG_SAMPLE_CONFIRM), MG_SAMPLE_CONFIRM_X, MG_SAMPLE_CONFIRM_Y, false, NULL, 256);
+ char b[40];
+ if (M->phase == 0) snprintf(b, sizeof b, "Press to start");
+ else if (M->phase == 1) snprintf(b, sizeof b, "Adding reagent.");
+ else if (M->phase == 2) snprintf(b, sizeof b, "%ds remaining", (int)ceilf(t->timer));
+ else snprintf(b, sizeof b, M->done ? "Thank you!" : "Select anomaly.");
+ gfx_text(FONT_SMALL, MG_X, 204, b, rgb565(0x7CFC7C), 0, 0, 1);
+ mg_keys(M->phase == 0 ? "OK start Back close"
+ : M->phase == 3 ? "left right choose the odd one OK select" : "Back close (it keeps going)");
+}
+
+/* ---- Fuel Engines (RefuelStage: hold 3 s; the can in Storage, then each engine) ---- */
+
+static void fuel_tick(uint32_t keys) {
+ if (keys & K_OK) {
+ M->b += DT / 3;
+ if (M->b >= 1) M->b = 1, mg_finish();
+ }
+}
+
+static void fuel_draw(void) {
+ const Task *t = &g.p[g.me].tasks[M->task];
+ bool can = !(t->step & 1);
+ /* black behind the glass, the fuel rising behind the outline */
+ if (can) gfx_fill(98, 31, 117, 140, BLACK, 256);
+ else gfx_fill(121, 21, 79, 162, BLACK, 256);
+ if (can) {
+ int h = (int)(M->b * 112);
+ gfx_fill(104, 162 - h, 98, h, rgb565(0xC4AA14), 256);
+ } else {
+ int h = (int)(M->b * 116);
+ gfx_fill(146, 168 - h, 26, h, rgb565(0xC4AA14), 256);
+ }
+ mg_bg(can ? BLOB_MG_FUEL1 : BLOB_MG_FUEL2);
+ gfx_spr(pic(PIC_MG_FUEL1_BUTTON), MG_FUEL1_BUTTON_X, MG_FUEL1_BUTTON_Y, false, NULL, 256);
+ gfx_spr(pic(PIC_MG_FUEL1_LIGHT), MG_FUEL1_LIGHT_X, MG_FUEL1_LIGHT_Y, false, NULL, 256);
+ if (!M->done) gfx_spr_tint(pic(PIC_MG_FUEL1_LIGHT), MG_FUEL1_LIGHT_X, MG_FUEL1_LIGHT_Y, BLACK, 140);
+ gfx_spr(pic(PIC_MG_FUEL1_LIGHT), MG_FUEL1_LIGHT_X + 22, MG_FUEL1_LIGHT_Y, false, NULL, 256);
+ gfx_spr_tint(pic(PIC_MG_FUEL1_LIGHT), MG_FUEL1_LIGHT_X + 22, MG_FUEL1_LIGHT_Y, M->done ? 0x07E0 : 0x0200, 220);
+ mg_keys("hold OK to fill Back close");
+}
+
+/* ---- Start Reactor (SimonSaysGame: 5 rounds, one more light each) ---- */
+
+static void simon_open(void) {
+ for (int k = 0; k < 5; k++) M->order[k] = (uint8_t)rnd_n(9);
+ M->phase = 0, M->b = -0.6f;
+}
+
+static int simon_key(uint32_t pressed) {
+ /* the digit keys as the grid (7 8 9 on top), or the cursor */
+ static const int8_t DIG[10] = {-1, 6, 7, 8, 3, 4, 5, 0, 1, 2};
+ for (int d = 1; d <= 9; d++)
+ if (pressed & ((uint32_t)K_D0 << d)) return DIG[d];
+ if (pressed & K_LEFT) M->sel = (uint8_t)(M->sel % 3 ? M->sel - 1 : M->sel + 2);
+ if (pressed & K_RIGHT) M->sel = (uint8_t)(M->sel % 3 == 2 ? M->sel - 2 : M->sel + 1);
+ if (pressed & K_UP) M->sel = (uint8_t)((M->sel + 6) % 9);
+ if (pressed & K_DOWN) M->sel = (uint8_t)((M->sel + 3) % 9);
+ if (pressed & K_OK) return M->sel;
+ return -1;
+}
+
+static void simon_tick(uint32_t pressed) {
+ Task *t = &g.p[g.me].tasks[M->task];
+ int round = t->step; /* this round shows round + 1 lights */
+ M->b += DT;
+ if (M->phase == 0) {
+ /* the computer's side: a light each 0.5 s */
+ if (M->b >= (round + 1) * 0.5f + 0.2f) M->phase = 1, M->n = 0, M->b = 0;
+ } else if (M->phase == 1) {
+ int k = simon_key(pressed);
+ if (k >= 0) {
+ M->stage = (uint8_t)k, M->c = 0.25f;
+ if (k != M->order[M->n]) {
+ M->phase = 2, M->b = 0; /* wrong: red, then from the start */
+ t->step = 0;
+ } else if (++M->n > round) {
+ task_step_done(g.me, M->task);
+ if (task_done(t)) M->done = 1, M->done_t = 0;
+ else M->phase = 0, M->b = -0.6f;
+ }
+ }
+ } else if (M->phase == 2 && M->b > 1) M->phase = 0, M->b = -0.6f;
+ if (M->c > 0) M->c -= DT;
+}
+
+static void simon_draw(void) {
+ mg_bg(BLOB_MG_SIMON);
+ const Task *t = &g.p[g.me].tasks[M->task];
+ int round = t->step;
+ const float S = 1.35f * PX_PER_UNIT;
+ /* the left screen: the light now shown */
+ int lit = -1;
+ if (M->phase == 0 && M->b >= 0) {
+ int k = (int)(M->b / 0.5f);
+ if (k <= round && fmodf(M->b, 0.5f) < 0.38f) lit = M->order[k];
+ }
+ for (int k = 0; k < 9; k++) {
+ int x = (int)(MG_X + (-1.72f + 0.47f * (k % 3)) * S), y = (int)(MG_Y - (0.23f - 0.47f * (k / 3)) * S);
+ uint16_t c = M->phase == 2 ? 0xF800 : k == lit ? rgb565(0x3D8CFF) : 0x0000;
+ if (c) gfx_fill(x - 11, y - 11, 23, 23, c, 256);
+ }
+ /* the buttons */
+ for (int k = 0; k < 9; k++) {
+ int x = MG_SIMON_BUTTON_XY[k][0], y = MG_SIMON_BUTTON_XY[k][1];
+ gfx_spr(pic(PIC_X_SSBUTTON1 + k), x, y, false, NULL, 256);
+ if (M->c > 0 && M->stage == k) gfx_spr_tint(pic(PIC_X_SSBUTTON1 + k), x, y, rgb565(0x3D8CFF), 150);
+ if (M->phase == 1 && M->sel == k) gfx_rect(x - 13, y - 13, 26, 26, 2, rgb565(0x1CFF00));
+ }
+ /* the rounds' lights on both sides */
+ for (int k = 0; k < 5; k++) {
+ bool on = k < round || (M->phase == 1 && k < M->n);
+ for (int s = 0; s < 2; s++) {
+ int x = (int)(MG_X + ((s ? 0.57f : -1.97f) + 0.34f * k) * S), y = (int)(MG_Y - 0.91f * S);
+ gfx_spr(pic(PIC_X_SSLIGHTS1 + k), x, y, false, NULL, 256);
+ bool show = s ? on : k <= round;
+ if (!show) gfx_spr_tint(pic(PIC_X_SSLIGHTS1 + k), x, y, BLACK, 140);
+ }
+ }
+ mg_keys(M->phase == 1 ? "repeat it: 7 8 9 / 4 5 6 / 1 2 3, or arrows and OK" : "watch the lights Back close");
+}
+
+/* ---- Empty Garbage / Empty Chute (EmptyGarbageMinigame: pull the lever and hold) ---- */
+
+static void garbage_open(void) {
+ const Task *t = &g.p[g.me].tasks[M->task];
+ bool leaves = TASK_DEFS[t->def].type == T_EMPTY_CHUTE;
+ for (int k = 0; k < 12; k++) {
+ Thing *a = &M->th[k];
+ a->on = 1;
+ a->kind = (uint8_t)(leaves ? rnd_n(7) : 10 + rnd_n(6));
+ a->x = 75 + rnd_f() * 95;
+ a->y = 110 + rnd_f() * 90;
+ a->vy = 0;
+ a->a = rnd_f() * 6.28f;
+ }
+}
+
+static void garbage_tick(uint32_t keys) {
+ bool pull = keys & K_DOWN;
+ M->a += ((pull ? 1.0f : 0) - M->a) * 0.35f; /* the handle: 0 up, 1 down */
+ int left = 0;
+ for (int k = 0; k < 12; k++) {
+ Thing *a = &M->th[k];
+ if (!a->on) continue;
+ if (M->a > 0.8f) {
+ a->vy += 900 * DT;
+ a->y += a->vy * DT;
+ a->a += DT * 3;
+ if (a->y > 240) a->on = 0;
+ }
+ left += a->on;
+ }
+ if (!left && !M->done) mg_finish();
+}
+
+static void garbage_draw(void) {
+ mg_bg(BLOB_MG_GARBAGE);
+ for (int k = 0; k < 12; k++) {
+ const Thing *a = &M->th[k];
+ if (!a->on) continue;
+ const Pic *p = pic(a->kind >= 10 ? PIC_X_GARBAGE_1 + a->kind - 10 : PIC_X_O2_LEAF1 + a->kind);
+ gfx_pic(p, a->x, a->y, 1, 1, a->a, NULL, 256);
+ }
+ gfx_spr(pic(PIC_MG_GARBAGE_BARS), MG_GARBAGE_BARS_X, MG_GARBAGE_BARS_Y, false, NULL, 256);
+ gfx_spr(pic(PIC_MG_GARBAGE_HANDLE), MG_GARBAGE_HANDLE_X, MG_GARBAGE_HANDLE_Y + (int)(M->a * 52), false, NULL, 256);
+ mg_keys("hold down to pull the lever Back close");
+}
+
+/* ---- Upload / Download Data (UploadDataGame) ---- */
+
+static void upload_tick(uint32_t pressed) {
+ if (M->phase == 0 && (pressed & K_OK)) M->phase = 1, M->b = 0;
+ else if (M->phase == 1) {
+ M->b += DT;
+ if (M->b >= 8.5f) mg_finish();
+ }
+}
+
+static void upload_draw(void) {
+ mg_bg(BLOB_MG_UPLOAD);
+ const Task *t = &g.p[g.me].tasks[M->task];
+ bool up = t->step == 1;
+ int fr = M->phase ? (M->b < 0.2f ? (int)(M->b * 20) : 4) : 0;
+ if (fr > 4) fr = 4;
+ /* the folders, the file running between them */
+ gfx_spr(pic(PIC_X_DATATRANSFER_FOLDEROPEN0001 + fr), 106, 104, false, NULL, 256);
+ gfx_spr(pic(PIC_X_DATATRANSFER_FOLDEROPEN0001 + fr), 214, 104, false, NULL, 256);
+ if (up) gfx_spr(pic(PIC_MG_UPLOAD_TOWER), MG_UPLOAD_TOWER_X, MG_UPLOAD_TOWER_Y, false, NULL, 256);
+ if (M->phase == 1 && !M->done) {
+ float f = fmodf(M->b, 1.2f) / 1.2f;
+ gfx_pic(pic(PIC_X_DATATRANSFER_FILEFILL), 110 + f * 100, 92 - sinf(f * 3.14159f) * 30, 0.35f, 0.35f, 0, NULL, 256);
+ }
+ const char *src = up ? "My Tablet" : ROOM_NAMES[TASK_DEFS[t->def].room], *dst = up ? "Headquarters" : "My Tablet";
+ gfx_text(FONT_SMALL, 98, 125, src, BLACK, 0, 0, 1);
+ gfx_text(FONT_SMALL, 222, 125, dst, BLACK, 0, 0, 1);
+ if (M->phase == 0) {
+ gfx_spr(pic(up ? PIC_MG_UPLOAD_BUTTON : PIC_X_DATATRANSFER_DOWNLOADBUTTON), MG_UPLOAD_BUTTON_X, MG_UPLOAD_BUTTON_Y,
+ false, NULL, 256);
+ } else {
+ float f = M->b / 8.5f;
+ if (f > 1) f = 1;
+ gfx_fill(83, 133, 154, 9, rgb565(0x1B1B1B), 256);
+ gfx_fill(83, 133, (int)(154 * f), 9, rgb565(0x0A8200), 256);
+ char b[40];
+ snprintf(b, sizeof b, "%d%%", (int)(f * 100));
+ gfx_text(FONT_SMALL, 244, 142, b, WHITE, 0, 0, 0);
+ if (M->done) snprintf(b, sizeof b, "Complete");
+ else snprintf(b, sizeof b, "Estimated Time: %ds", (int)ceilf(8.5f - M->b));
+ gfx_text(FONT_SMALL, 84, 154, b, WHITE, 0, 0, 0);
+ }
+ mg_keys(M->phase == 0 ? (up ? "OK upload Back close" : "OK download Back close") : "wait for the transfer");
+}
+
+/* ---- Calibrate Distributor (SweepMinigame: stop each dial on its contact) ---- */
+
+static void calib_tick(uint32_t pressed) {
+ /* the dials turn (each faster), the current one stops when OK is pressed on its contact */
+ for (int k = 0; k < 3; k++)
+ if (M->state[k] == 0) M->v[k] = fmodf(M->v[k] + DT * (2.2f + 0.9f * k), 6.2831853f);
+ int k = M->n;
+ if (k < 3 && (pressed & K_OK)) {
+ float a = M->v[k];
+ if (a > 3.14159f) a -= 6.2831853f;
+ if (fabsf(a) < 0.35f) {
+ M->state[k] = 1, M->v[k] = 0, M->n++;
+ if (M->n == 3) mg_finish();
+ } else {
+ /* a miss: all of them again */
+ for (int j = 0; j < 3; j++) M->state[j] = 0;
+ M->n = 0;
+ M->c = 0.5f;
+ }
+ }
+ if (M->c > 0) M->c -= DT;
+}
+
+static void calib_draw(void) {
+ mg_bg(BLOB_MG_CALIBRATE);
+ static const int16_t SP[3][2] = {{MG_CALIBRATE_SPIN1_X, MG_CALIBRATE_SPIN1_Y},
+ {MG_CALIBRATE_SPIN2_X, MG_CALIBRATE_SPIN2_Y},
+ {MG_CALIBRATE_SPIN3_X, MG_CALIBRATE_SPIN3_Y}};
+ static const int16_t LIT[3][2] = {{MG_CALIBRATE_LIT1_X, MG_CALIBRATE_LIT1_Y},
+ {MG_CALIBRATE_LIT2_X, MG_CALIBRATE_LIT2_Y},
+ {MG_CALIBRATE_LIT3_X, MG_CALIBRATE_LIT3_Y}};
+ static const uint32_t GAUGE[3] = {0xFFE300, 0x5261FF, 0x6EFAFF};
+ for (int k = 0; k < 3; k++) {
+ gfx_pic(pic(PIC_MG_CALIBRATE_SPIN1 + k), SP[k][0], SP[k][1], 1, 1, -M->v[k], NULL, 256);
+ if (M->state[k]) {
+ gfx_spr(pic(PIC_MG_CALIBRATE_LIT1 + k), LIT[k][0], LIT[k][1], false, NULL, 256);
+ gfx_fill(194, (int)(44 + 59.3f * k) - 6, 52, 12, rgb565(GAUGE[k]), 256);
+ }
+ if (k == M->n && !M->done) gfx_rect(201, (int)(60 + 59.3f * k) - 10, 20, 20, 2, rgb565(0x00FF00));
+ }
+ if (M->c > 0) mg_status("Calibration failed", 214, 0xF800);
+ mg_keys("OK when the dial lines up with its contact Back close");
+}
+
+/* ---- Chart Course (CourseMinigame: along the dotted course) ---- */
+
+static void course_open(void) {
+ /* the start, three stars, the destination */
+ M->v[0] = 58, M->v[1] = 100 + rnd_f() * 30;
+ for (int k = 1; k < 4; k++) M->v[2 * k] = 58 + 49 * k, M->v[2 * k + 1] = 62 + rnd_f() * 96;
+ M->v[6] = MG_COURSE_END_X, M->v[7] = MG_COURSE_END_Y;
+ M->n = 0, M->a = 0;
+}
+
+static void course_tick(uint32_t keys) {
+ if (!(keys & (K_RIGHT | K_OK))) return;
+ float sp = 110 * DT;
+ while (sp > 0 && M->n < 3) {
+ float x0 = M->v[2 * M->n], y0 = M->v[2 * M->n + 1], x1 = M->v[2 * M->n + 2], y1 = M->v[2 * M->n + 3];
+ float l = sqrtf((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
+ if (M->a + sp < l) {
+ M->a += sp;
+ sp = 0;
+ } else {
+ sp -= l - M->a;
+ M->a = 0, M->n++;
+ }
+ }
+ if (M->n >= 3) mg_finish();
+}
+
+static void course_draw(void) {
+ mg_bg(BLOB_MG_COURSE);
+ for (int k = 0; k < 3; k++) {
+ float x0 = M->v[2 * k], y0 = M->v[2 * k + 1], x1 = M->v[2 * k + 2], y1 = M->v[2 * k + 3];
+ float l = sqrtf((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
+ for (float d = 4; d < l - 4; d += 9) {
+ float x = x0 + (x1 - x0) * d / l, y = y0 + (y1 - y0) * d / l;
+ gfx_fill((int)x - 1, (int)y - 1, 3, 3, k < M->n ? rgb565(0xFFFFFF) : rgb565(0xB4D7FF), 256);
+ }
+ }
+ gfx_spr(pic(PIC_X_NAV_CHARTCOURSE_START), (int)M->v[0], (int)M->v[1], false, NULL, 256);
+ for (int k = 1; k < 4; k++) gfx_spr(pic(PIC_X_NAV_CHARTCOURSE_CHECKPT), (int)M->v[2 * k], (int)M->v[2 * k + 1], false, NULL, 256);
+ gfx_spr(pic(PIC_MG_COURSE_END), (int)M->v[6], (int)M->v[7], false, NULL, 256);
+ int k = M->n < 3 ? M->n : 2;
+ float x0 = M->v[2 * k], y0 = M->v[2 * k + 1], x1 = M->v[2 * k + 2], y1 = M->v[2 * k + 3];
+ float l = sqrtf((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)), f = M->n < 3 ? M->a / l : 1;
+ float ang = atan2f(y1 - y0, x1 - x0) + 1.5707963f;
+ gfx_pic(pic(PIC_MG_COURSE_SHIP), x0 + (x1 - x0) * f, y0 + (y1 - y0) * f, 1, 1, ang, NULL, 256);
+ mg_keys("hold right to fly the course Back close");
+}
+
+/* ---- the first half's dispatch ---- */
+
+static void open1(int kind) {
+ switch (kind) {
+ case MG_WIRES: wires_open(); break;
+ case MG_ALIGN: align_open(); break;
+ case MG_SAMPLE: sample_open(); break;
+ case MG_SIMON: simon_open(); break;
+ case MG_GARBAGE: garbage_open(); break;
+ case MG_COURSE: course_open(); break;
+ default: break;
+ }
+}
+
+static void tick1(uint32_t keys, uint32_t pressed) {
+ switch (M->kind) {
+ case MG_CARD: card_tick(keys, pressed); break;
+ case MG_WIRES: wires_tick(pressed); break;
+ case MG_ASTEROIDS: ast_tick(keys, pressed); break;
+ case MG_ALIGN: align_tick(keys); break;
+ case MG_SCAN: scan_tick(); break;
+ case MG_SAMPLE: sample_tick(pressed); break;
+ case MG_FUEL: fuel_tick(keys); break;
+ case MG_SIMON: simon_tick(pressed); break;
+ case MG_GARBAGE: garbage_tick(keys); break;
+ case MG_UPLOAD: upload_tick(pressed); break;
+ case MG_CALIBRATE: calib_tick(pressed); break;
+ case MG_COURSE: course_tick(keys); break;
+ }
+}
+
+static void draw1(void) {
+ switch (M->kind) {
+ case MG_CARD: card_draw(); break;
+ case MG_WIRES: wires_draw(); break;
+ case MG_ASTEROIDS: ast_draw(); break;
+ case MG_ALIGN: align_draw(); break;
+ case MG_SCAN: scan_draw(); break;
+ case MG_SAMPLE: sample_draw(); break;
+ case MG_FUEL: fuel_draw(); break;
+ case MG_SIMON: simon_draw(); break;
+ case MG_GARBAGE: garbage_draw(); break;
+ case MG_UPLOAD: upload_draw(); break;
+ case MG_CALIBRATE: calib_draw(); break;
+ case MG_COURSE: course_draw(); break;
}
- gfx_fill(60, 40, 200, 150, rgb565(0x404040), 256);
- gfx_text(FONT_BIG, 160, 110, g.overlay == O_EMERGENCY ? "EMERGENCY" : "Task", 0xFFFF, 0, 0, 1);
- hud_keys("OK do it Back close");
}
diff --git a/games/amongus/src/mg.h b/games/amongus/src/mg.h
new file mode 100644
index 00000000..25bb160e
--- /dev/null
+++ b/games/amongus/src/mg.h
@@ -0,0 +1,40 @@
+/* Among Us: the minigames' shared state (mg.c, mg2.c). */
+#ifndef AU_MG_H
+#define AU_MG_H
+#include "game.h"
+#include "gfx.h"
+
+enum {
+ MG_CARD, MG_WIRES, MG_ASTEROIDS, MG_ALIGN, MG_SCAN, MG_SAMPLE, MG_FUEL, MG_SIMON, MG_GARBAGE, MG_UPLOAD,
+ MG_CALIBRATE, MG_COURSE, MG_LEAVES, MG_MANIFOLDS, MG_STEERING, MG_SHIELDS, MG_DIVERT, MG_ACCEPT, MG_HANDS,
+ MG_LIGHTS, MG_COMMS, MG_KEYPAD, MG_CAMS, MG_EMERGENCY, N_MG
+};
+
+typedef struct {
+ float x, y, vx, vy, a;
+ uint8_t kind, on, pad[2];
+} Thing; /* an asteroid, a leaf, a piece of garbage */
+
+typedef struct {
+ uint8_t kind, task, cons, done; /* task: the player's task, or NONE */
+ uint8_t sel, phase, n, flags;
+ uint8_t stage, held, pad0, pad1;
+ float t, done_t, a, b, c;
+ uint8_t order[16], state[16];
+ float v[8];
+ Thing th[12];
+ char text[48];
+} Mg;
+_Static_assert(sizeof(Mg) <= sizeof(((Game *)0)->mg), "the minigame's state");
+#define M ((Mg *)(void *)g.mg)
+
+void mg_finish(void); /* the step done (or the sabotage's part) */
+void mg_status(const char *s, int y, uint16_t c);
+void mg_bg(int blob_id);
+void mg_keys(const char *s);
+
+/* each minigame: opened, a tick, drawn (mg2.c holds the second half) */
+void mg2_open(int kind);
+void mg2_tick(uint32_t keys, uint32_t pressed);
+void mg2_draw(void);
+#endif
diff --git a/games/amongus/src/mg2.c b/games/amongus/src/mg2.c
new file mode 100644
index 00000000..6f90d3cb
--- /dev/null
+++ b/games/amongus/src/mg2.c
@@ -0,0 +1,519 @@
+/* Among Us: the minigames' second half: the O2 filter, the manifolds, steering, shields, power, and the sabotages'
+ * fixes (the reactor's hands, the lights' switches, the comms' dial, the oxygen keypad), the cameras and the
+ * emergency button. */
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#include "mg.h"
+#include "view.h"
+#include "world.h"
+
+#define WHITE 0xFFFF
+#define BLACK 0x0000
+
+/* noise for the pictures only (the game's own random numbers stay the game's) */
+static uint32_t noise_state = 0x1234567;
+static uint32_t noise(void) {
+ noise_state ^= noise_state << 13, noise_state ^= noise_state >> 17, noise_state ^= noise_state << 5;
+ return noise_state;
+}
+
+/* ---- Clean O2 Filter (LeafMinigame: the leaves out through the left) ---- */
+
+#define LEAF_X0 96
+#define LEAF_X1 255
+#define LEAF_EXIT 98
+
+static void leaves_open(void) {
+ M->n = 6;
+ for (int k = 0; k < 6; k++) {
+ Thing *a = &M->th[k];
+ a->on = 1;
+ a->kind = (uint8_t)rnd_n(7);
+ a->x = 140 + rnd_f() * 105;
+ a->y = 30 + rnd_f() * 165;
+ a->a = rnd_f() * 6.28f;
+ }
+ M->a = 200, M->b = 112; /* the hand */
+ M->sel = NONE;
+}
+
+static void leaves_tick(uint32_t keys, uint32_t pressed) {
+ float sp = 150 * DT;
+ if (keys & K_LEFT) M->a -= sp;
+ if (keys & K_RIGHT) M->a += sp;
+ if (keys & K_UP) M->b -= sp;
+ if (keys & K_DOWN) M->b += sp;
+ if (M->a < 70) M->a = 70;
+ if (M->a > LEAF_X1) M->a = LEAF_X1;
+ if (M->b < 18) M->b = 18;
+ if (M->b > 206) M->b = 206;
+ /* OK held: carrying the leaf under the hand */
+ if ((pressed & K_OK) && M->sel == NONE) {
+ float bd = 22 * 22;
+ for (int k = 0; k < 6; k++) {
+ Thing *a = &M->th[k];
+ float dx = a->x - M->a, dy = a->y - M->b;
+ if (a->on == 1 && dx * dx + dy * dy < bd) bd = dx * dx + dy * dy, M->sel = (uint8_t)k;
+ }
+ }
+ if (!(keys & K_OK)) M->sel = NONE;
+ for (int k = 0; k < 6; k++) {
+ Thing *a = &M->th[k];
+ if (a->on == 2) {
+ /* sucked out */
+ a->x -= 300 * DT, a->a += DT * 8;
+ if (a->x < 40) {
+ a->on = 0;
+ task_step_done(g.me, M->task);
+ if (task_done(&g.p[g.me].tasks[M->task])) M->done = 1, M->done_t = 0;
+ }
+ continue;
+ }
+ if (!a->on) continue;
+ if (M->sel == k) {
+ a->x = M->a, a->y = M->b;
+ if (a->x < LEAF_EXIT) a->on = 2, M->sel = NONE;
+ } else {
+ /* the air moves them about */
+ a->a += DT * 0.6f;
+ a->x += sinf(M->t * 1.3f + k) * 6 * DT;
+ a->y += cosf(M->t * 1.1f + 2 * k) * 6 * DT;
+ if (a->x < LEAF_EXIT + 12) a->x = LEAF_EXIT + 12;
+ }
+ }
+}
+
+static void leaves_draw(void) {
+ mg_bg(BLOB_MG_LEAVES);
+ for (int k = 0; k < 6; k++) {
+ const Thing *a = &M->th[k];
+ if (a->on) gfx_pic(pic(PIC_X_O2_LEAF1 + a->kind), a->x, a->y, 1, 1, a->a, NULL, 256);
+ }
+ /* the hand (the game's controller cursor: a green ring and its dot) */
+ gfx_disc(M->a, M->b, 13, rgb565(0x00FF0D), M->sel == NONE ? 70 : 120);
+ gfx_disc(M->a, M->b, 3, rgb565(0x00FF0D), 256);
+ mg_keys(M->sel == NONE ? "arrows move hold OK on a leaf to grab it" : "drag it out to the left");
+}
+
+/* ---- Unlock Manifolds (UnlockManifoldsMinigame: 1 to 10 in order) ---- */
+
+static void manifolds_open(void) {
+ for (int k = 0; k < 10; k++) M->order[k] = (uint8_t)k;
+ for (int k = 9; k > 0; k--) {
+ int j = rnd_n(k + 1);
+ uint8_t t = M->order[k];
+ M->order[k] = M->order[j], M->order[j] = t;
+ }
+}
+
+static void manifolds_tick(uint32_t pressed) {
+ if (M->c > 0) {
+ M->c -= DT;
+ if (M->c <= 0) M->n = 0;
+ return;
+ }
+ if (pressed & K_LEFT) M->sel = (uint8_t)(M->sel % 5 ? M->sel - 1 : M->sel + 4);
+ if (pressed & K_RIGHT) M->sel = (uint8_t)(M->sel % 5 == 4 ? M->sel - 4 : M->sel + 1);
+ if (pressed & (K_UP | K_DOWN)) M->sel = (uint8_t)((M->sel + 5) % 10);
+ if (pressed & K_OK) {
+ if (M->order[M->sel] == M->n) {
+ if (++M->n == 10) mg_finish();
+ } else
+ M->c = 0.6f; /* wrong: they all go out */
+ }
+}
+
+static void manifolds_draw(void) {
+ mg_bg(BLOB_MG_MANIFOLDS);
+ for (int k = 0; k < 10; k++) {
+ int x = MG_X + (int)((-1.70f + 0.85f * (k % 5)) * PX_PER_UNIT), y = MG_Y - (int)((k < 5 ? 0.43f : -0.43f) * PX_PER_UNIT);
+ const Pic *p = pic(PIC_X_REACTORBUTTON01 + M->order[k]);
+ gfx_spr(p, x, y, false, NULL, 256);
+ if (M->order[k] < M->n) gfx_spr_tint(p, x, y, rgb565(0x5BE0FF), 120);
+ if (M->c > 0) gfx_spr_tint(p, x, y, 0xF800, 110);
+ if (k == M->sel && !M->done) gfx_rect(x - 16, y - 16, 33, 33, 2, 0xFFE0);
+ }
+ mg_keys("arrows choose OK press, from 1 to 10 Back close");
+}
+
+/* ---- Stabilize Steering (NavigationMinigame: the crosshair to the middle) ---- */
+
+static void steering_open(void) {
+ float a = rnd_f() * 6.28f;
+ M->a = cosf(a) * 55, M->b = sinf(a) * 55;
+}
+
+static void steering_tick(uint32_t keys) {
+ float sp = 70 * DT;
+ if (keys & K_LEFT) M->a -= sp;
+ if (keys & K_RIGHT) M->a += sp;
+ if (keys & K_UP) M->b -= sp;
+ if (keys & K_DOWN) M->b += sp;
+ float d = sqrtf(M->a * M->a + M->b * M->b);
+ if (d > 80) M->a *= 80 / d, M->b *= 80 / d;
+ if (!(keys & (K_LEFT | K_RIGHT | K_UP | K_DOWN)) && d < 4) {
+ M->a = M->b = 0;
+ mg_finish();
+ }
+}
+
+static void steering_draw(void) {
+ mg_bg(BLOB_MG_STEERING);
+ int x = MG_X + (int)M->a, y = MG_Y + (int)M->b;
+ uint16_t c = M->done ? rgb565(0x37FF37) : rgb565(0x8DE8FF);
+ /* the crosshair's two lines across the round screen */
+ for (int yy = MG_Y - 88; yy <= MG_Y + 88; yy++) {
+ float w = sqrtf(88 * 88 - (float)(yy - MG_Y) * (yy - MG_Y));
+ if (yy == y) gfx_fill(MG_X - (int)w, yy, (int)(2 * w), 1, c, 256);
+ if (fabsf((float)(x - MG_X)) < w) gfx_fill(x, yy, 1, 1, c, 256);
+ }
+ gfx_spr(pic(PIC_MG_STEERING_CROSS), x, y, false, NULL, 256);
+ mg_keys("arrows move the crosshair to the middle Back close");
+}
+
+/* ---- Prime Shields (ShieldMinigame: the red ones to white) ---- */
+
+static void shields_open(void) {
+ uint8_t s;
+ do s = (uint8_t)(rnd() & 0x7F);
+ while (s == 0x7F);
+ M->n = s; /* the hexes already on, as bits */
+}
+
+static void shields_tick(uint32_t pressed) {
+ /* the arrows move to the nearest hex that way */
+ int dx = (pressed & K_RIGHT) ? 1 : (pressed & K_LEFT) ? -1 : 0, dy = (pressed & K_DOWN) ? 1 : (pressed & K_UP) ? -1 : 0;
+ if (dx || dy) {
+ int best = -1;
+ float bs = 1e9f;
+ for (int k = 0; k < 7; k++) {
+ if (k == M->sel) continue;
+ float ex = MG_SHIELDS_HEX_XY[k][0] - MG_SHIELDS_HEX_XY[M->sel][0], ey = MG_SHIELDS_HEX_XY[k][1] - MG_SHIELDS_HEX_XY[M->sel][1];
+ float along = ex * dx + ey * dy, side = fabsf(ex * dy - ey * dx);
+ if (along <= 5) continue;
+ float s = along + side * 2;
+ if (s < bs) bs = s, best = k;
+ }
+ if (best >= 0) M->sel = (uint8_t)best;
+ }
+ for (int d = 1; d <= 7; d++)
+ if (pressed & ((uint32_t)K_D0 << d)) M->sel = (uint8_t)(d - 1);
+ if (pressed & K_OK) {
+ M->n |= (uint8_t)(1 << M->sel);
+ if (M->n == 0x7F) mg_finish();
+ }
+}
+
+static void shields_draw(void) {
+ mg_bg(BLOB_MG_SHIELDS);
+ for (int k = 0; k < 7; k++) {
+ int x = MG_SHIELDS_HEX_XY[k][0], y = MG_SHIELDS_HEX_XY[k][1];
+ gfx_spr(pic(PIC_MG_SHIELDS_HEX), x, y, false, NULL, M->n >> k & 1 ? 120 : 256);
+ if (!(M->n >> k & 1)) gfx_spr_tint(pic(PIC_MG_SHIELDS_HEX), x, y, 0xF800, 200);
+ if (k == M->sel && !M->done) gfx_rect(x - 10, y - 10, 21, 21, 2, 0xFFE0);
+ }
+ mg_keys("arrows choose OK prime a red one Back close");
+}
+
+/* ---- Divert Power (DivertPowerMinigame: the target's slider up) and Accept Diverted Power ---- */
+
+/* the sliders left to right: lower engine, upper engine, weapons, shields, navigation, communications, O2, security */
+static const uint8_t DIVERT_ROOMS[8] = {R_LOWER_ENGINE, R_UPPER_ENGINE, R_WEAPONS, R_SHIELDS, R_NAV, R_COMMS, R_O2, R_SECURITY};
+static const float DIVERT_X[8] = {-1.88f, -1.36f, -0.82f, -0.27f, 0.26f, 0.79f, 1.33f, 1.87f};
+
+static int divert_target(void) {
+ const Task *t = &g.p[g.me].tasks[M->task];
+ for (int k = 0; k < 8; k++)
+ if (DIVERT_ROOMS[k] == TASK_DEFS[t->def].target) return k;
+ return 0;
+}
+
+static void divert_tick(uint32_t keys) {
+ if (keys & K_UP) M->a += DT * 1.4f;
+ if (keys & K_DOWN) M->a -= DT * 1.4f;
+ if (M->a < 0) M->a = 0;
+ if (M->a >= 1) M->a = 1, mg_finish();
+}
+
+static void divert_draw(void) {
+ mg_bg(BLOB_MG_DIVERT);
+ int tg = divert_target();
+ for (int k = 0; k < 8; k++) {
+ int x = MG_X + (int)(DIVERT_X[k] * PX_PER_UNIT);
+ float f = k == tg ? M->a : 0;
+ /* the tank fills with the power sent */
+ if (f > 0) gfx_fill(x - 4, 114 - (int)(f * 32), 9, (int)(f * 32), rgb565(0xFCFF5C), 256);
+ gfx_spr(pic(PIC_MG_DIVERT_SWITCH), x, MG_DIVERT_SWITCH_Y - (int)(f * 46), false, NULL, 256);
+ if (k == tg && !M->done) gfx_rect(x - 12, MG_DIVERT_SWITCH_Y - (int)(f * 46) - 10, 24, 20, 2, 0xFFE0);
+ }
+ char b[48];
+ snprintf(b, sizeof b, "Divert power to %s", ROOM_NAMES[DIVERT_ROOMS[tg]]);
+ gfx_text(FONT_SMALL, MG_X, 214, b, WHITE, BLACK, 1, 1);
+ mg_keys("hold up to push the lit slider Back close");
+}
+
+static void accept_tick(uint32_t pressed) {
+ if (pressed & K_OK) M->phase = 1, M->b = 0;
+ if (M->phase) {
+ M->b += DT;
+ if (M->b > 0.3f) mg_finish();
+ }
+}
+
+static void accept_draw(void) {
+ mg_bg(BLOB_MG_ACCEPT);
+ if (M->phase) {
+ /* the power through */
+ uint16_t c = rgb565(0xFCFF5C);
+ for (int k = -2; k <= 2; k++) {
+ gfx_line(52, (float)(MG_ACCEPT_SWITCH_Y + 12 * k), 150, MG_ACCEPT_SWITCH_Y, 2, c, 230);
+ gfx_line(170, MG_ACCEPT_SWITCH_Y, 268, (float)(MG_ACCEPT_SWITCH_Y + 14 * k), 2, c, 230);
+ }
+ }
+ gfx_pic(pic(PIC_MG_ACCEPT_SWITCH), MG_ACCEPT_SWITCH_X, MG_ACCEPT_SWITCH_Y, 1, 1, M->phase ? 0 : -0.7f, NULL, 256);
+ mg_keys("OK flip the switch Back close");
+}
+
+/* ---- Reset Reactor (ReactorMinigame: both hands at once) ---- */
+
+static void hands_tick(uint32_t keys) {
+ if (keys & K_OK) g.reactor_hold[CONSOLES[M->cons].id & 1] = g.me;
+}
+
+static void hands_draw(void) {
+ bool held = g.reactor_hold[CONSOLES[M->cons].id & 1] == g.me;
+ bool other = g.reactor_hold[(CONSOLES[M->cons].id & 1) ^ 1] != NONE;
+ gfx_fill(91, 49, 132, 150, held ? rgb565(0x4FE7DA) : rgb565(0x4DE3D6), 256);
+ if (held) {
+ int y = 49 + (int)(fmodf(M->t * 90, 150));
+ gfx_fill(91, y, 132, 4, WHITE, 180);
+ }
+ mg_bg(BLOB_MG_HANDS);
+ const char *s = !held ? "Hold to stop meltdown" : other ? "Reactor stabilized" : "Waiting for second user";
+ gfx_text(FONT_MID, MG_X, 37, s, BLACK, 0, 0, 1);
+ mg_keys("hold OK on the hand Back close");
+}
+
+/* ---- Fix Lights (SwitchMinigame: all five up) ---- */
+
+static void lights_tick(uint32_t pressed) {
+ if (pressed & K_LEFT) M->sel = (uint8_t)((M->sel + 4) % 5);
+ if (pressed & K_RIGHT) M->sel = (uint8_t)((M->sel + 1) % 5);
+ int flip = -1;
+ if (pressed & K_OK) flip = M->sel;
+ for (int d = 1; d <= 5; d++)
+ if (pressed & ((uint32_t)K_D0 << d)) flip = d - 1, M->sel = (uint8_t)(d - 1);
+ if (flip >= 0) g.switches ^= (uint8_t)(1 << flip);
+ if (g.switches == 0x1F) mg_finish();
+}
+
+static void lights_draw(void) {
+ mg_bg(BLOB_MG_LIGHTS);
+ for (int k = 0; k < 5; k++) {
+ bool on = g.switches >> k & 1;
+ int x = MG_LIGHTS_SWITCH_XY[k][0], y = MG_LIGHTS_SWITCH_XY[k][1];
+ gfx_pic(pic(PIC_MG_LIGHTS_SWITCH), x, y, 1, on ? 1 : -1, 0, NULL, 256);
+ int lx = MG_LIGHTS_LIGHT_XY[k][0], ly = MG_LIGHTS_LIGHT_XY[k][1];
+ gfx_spr(pic(PIC_MG_LIGHTS_LIGHT), lx, ly, false, NULL, 256);
+ gfx_spr_tint(pic(PIC_MG_LIGHTS_LIGHT), lx, ly, on ? 0x07E0 : rgb565(0x1A4D1A), 190);
+ if (k == M->sel) gfx_rect(x - 12, y - 16, 24, 32, 2, rgb565(0x2BFF00));
+ }
+ /* the graph: the light the switches let through */
+ int on = 0;
+ for (int k = 0; k < 5; k++) on += g.switches >> k & 1;
+ gfx_fill(77, 74, (int)(166 * on / 5), 14, rgb565(0xFCFF5C), 256);
+ mg_keys("left right choose OK flip (or 1-5) Back close");
+}
+
+/* ---- Fix Comms (TuneRadioMinigame: the dial onto the signal) ---- */
+
+static void comms_open(void) {
+ M->c = (rnd_f() * 2 - 1) * 1.6f; /* the station, in radians of the dial */
+ do M->a = (rnd_f() * 2 - 1) * 1.8f;
+ while (fabsf(M->a - M->c) < 0.6f);
+}
+
+static void comms_tick(uint32_t keys) {
+ if (keys & K_LEFT) M->a -= 1.4f * DT;
+ if (keys & K_RIGHT) M->a += 1.4f * DT;
+ if (M->a < -1.92f) M->a = -1.92f; /* DialRange -110..110 degrees */
+ if (M->a > 1.92f) M->a = 1.92f;
+ if (fabsf(M->a - M->c) < 0.06f) {
+ M->b += DT;
+ if (M->b > 0.6f) fix_sabotage(), M->done = 1, M->done_t = 0;
+ } else
+ M->b = 0;
+}
+
+static void wave(int cx, int cy, float amount, uint16_t c) {
+ int prevy = 0;
+ for (int x = -36; x <= 36; x++) {
+ float n = amount * (float)((int)((noise() >> 9) & 255) - 128) / 128.0f;
+ int y = cy + (int)(sinf(x * 0.17f + M->t * 6) * 10 + n * 14);
+ if (x > -36) gfx_line((float)(cx + x - 1), (float)prevy, (float)(cx + x), (float)y, 2, c, 256);
+ prevy = y;
+ }
+}
+
+static void comms_draw(void) {
+ mg_bg(BLOB_MG_COMMS);
+ float d = fabsf(M->a - M->c);
+ wave(127, 108, 0, rgb565(0x1CFF1C));
+ wave(222, 108, d > 1 ? 1 : d, rgb565(0x1CFF1C));
+ gfx_spr(pic(PIC_MG_COMMS_GLASS), MG_COMMS_GLASS_X, MG_COMMS_GLASS_Y, false, NULL, 256);
+ gfx_spr(pic(PIC_MG_COMMS_GLASS), MG_COMMS_GLASS_X + 95, MG_COMMS_GLASS_Y, false, NULL, 256);
+ gfx_pic(pic(PIC_MG_COMMS_DIALSHADOW), MG_COMMS_DIALSHADOW_X, MG_COMMS_DIALSHADOW_Y, 1, 1, M->a, NULL, 256);
+ gfx_pic(pic(PIC_MG_COMMS_DIAL), MG_COMMS_DIAL_X, MG_COMMS_DIAL_Y, 1, 1, M->a, NULL, 256);
+ /* the lights: red, green when tuned */
+ bool ok = d < 0.06f || M->done;
+ gfx_disc(247, 140, 4, ok ? rgb565(0x400000) : 0xF800, 256);
+ gfx_disc(259, 141, 4, ok ? 0x07E0 : rgb565(0x003000), 256);
+ mg_keys("left right turn the dial onto the signal Back close");
+}
+
+/* ---- Restore Oxygen (KeypadGame: the code on the note) ---- */
+
+static void keypad_tick(uint32_t pressed) {
+ if (M->c > 0) {
+ M->c -= DT;
+ if (M->c <= 0) M->n = 0;
+ return;
+ }
+ for (int d = 0; d <= 9; d++)
+ if ((pressed & ((uint32_t)K_D0 << d)) && M->n < 5) M->order[M->n++] = (uint8_t)d;
+ if ((pressed & (K_OK | K_EXE)) && M->n) {
+ uint32_t v = 0;
+ for (int k = 0; k < M->n; k++) v = v * 10 + M->order[k];
+ if (M->n == 5 && v == g.o2_code) {
+ g.o2_done |= (uint8_t)(CONSOLES[M->cons].room == R_ADMIN ? 1 : 2);
+ M->phase = 1;
+ M->done = 1, M->done_t = 0;
+ } else
+ M->c = 0.8f; /* a bad code: the display flashes and clears */
+ }
+}
+
+static void keypad_draw(void) {
+ mg_bg(BLOB_MG_KEYPAD);
+ gfx_spr(pic(PIC_MG_KEYPAD_X), MG_KEYPAD_X_X, MG_KEYPAD_X_Y, false, NULL, 256);
+ gfx_spr(pic(PIC_MG_KEYPAD_CHECK), MG_KEYPAD_CHECK_X, MG_KEYPAD_CHECK_Y, false, NULL, 256);
+ /* the sticky note with today's code */
+ gfx_spr(pic(PIC_MG_KEYPAD_NOTE), MG_KEYPAD_NOTE_X, MG_KEYPAD_NOTE_Y, false, NULL, 256);
+ char b[12];
+ snprintf(b, sizeof b, "%05u", (unsigned)g.o2_code);
+ gfx_text(FONT_BIG, MG_KEYPAD_NOTE_X - 2, MG_KEYPAD_NOTE_Y + 6, b, BLACK, 0, 0, 1);
+ /* the display */
+ for (int k = 0; k < M->n; k++) b[k] = (char)('0' + M->order[k]);
+ b[M->n] = 0;
+ if (M->c > 0 && ((int)(M->c * 8) & 1)) snprintf(b, sizeof b, "BAD");
+ if (M->phase) snprintf(b, sizeof b, "OK");
+ gfx_text(FONT_BIG, 132, 35, b, M->phase ? 0x07E0 : M->c > 0 ? 0xF800 : 0x07E0, 0, 0, 0);
+ mg_keys("type the code with the digits OK enter Back close");
+}
+
+/* ---- the cameras (SurveillanceMinigame: four views) ---- */
+
+static void cams_draw(void) {
+ mg_bg(BLOB_MG_CAMS);
+ /* the four views on the screen (x 71-248, y 42-128) */
+ for (int k = 0; k < 4; k++) {
+ int x = 71 + (k & 1) * 90, y = 42 + (k >> 1) * 44, w = 88, h = 42;
+ if (y + h <= gfx_y0 || y >= gfx_y0 + BAND) continue;
+ if (g.sab == SAB_COMMS) {
+ /* static */
+ for (int yy = y; yy < y + h; yy++)
+ if (yy >= gfx_y0 && yy < gfx_y0 + BAND)
+ for (int xx = x; xx < x + w; xx++) {
+ uint32_t r = noise();
+ gfx_band[(yy - gfx_y0) * SCREEN_W + xx] = (r & 0x100) ? 0x8C71 : 0x2104;
+ }
+ if (fmodf(M->t, 2) < 1) gfx_text(FONT_SMALL, x + w / 2, y + h / 2 + 4, "COMMS SABOTAGED", WHITE, BLACK, 1, 1);
+ continue;
+ }
+ view_camera((V2){CAMS[k].x, CAMS[k].y}, (float)h / (2 * CAMS[k].size), x, y, w, h);
+ }
+ mg_keys("Back close");
+}
+
+/* ---- the emergency button (EmergencyMinigame) ---- */
+
+static void emergency_tick(uint32_t pressed) {
+ const Player *P = &g.p[g.me];
+ M->b += DT;
+ bool can = P->alive && P->emergencies > 0 && g.emergency_cd <= 0 && g.sab != SAB_REACTOR && g.sab != SAB_O2;
+ if (can && (pressed & K_OK) && M->b > 0.3f) {
+ g.overlay = O_NONE;
+ start_meeting(g.me, NONE);
+ }
+}
+
+static void emergency_draw(void) {
+ mg_bg(BLOB_MG_EMERGENCY);
+ const Player *P = &g.p[g.me];
+ gfx_spr(pic(PIC_MG_EMERGENCY_BUTTON), MG_EMERGENCY_BUTTON_X, MG_EMERGENCY_BUTTON_Y, false, NULL, 256);
+ /* the lid lifts as the panel opens */
+ if (M->b < 0.3f) gfx_spr(pic(PIC_MG_EMERGENCY_CLOSED), MG_EMERGENCY_CLOSED_X, MG_EMERGENCY_CLOSED_Y, false, NULL, 256);
+ else gfx_spr(pic(PIC_MG_EMERGENCY_OPEN), MG_EMERGENCY_OPEN_X, MG_EMERGENCY_OPEN_Y, false, NULL, 256);
+ gfx_spr(pic(PIC_MG_EMERGENCY_BUBBLE), MG_EMERGENCY_BUBBLE_X, MG_EMERGENCY_BUBBLE_Y, false, NULL, 256);
+ char a[64], b[48];
+ b[0] = 0;
+ if (g.sab == SAB_REACTOR || g.sab == SAB_O2) snprintf(a, sizeof a, "EMERGENCY MEETINGS CANNOT");
+ else snprintf(a, sizeof a, "CREWMEMBER %s HAS", COLOR_NAMES[P->color]);
+ for (char *c = a; *c; c++)
+ if (*c >= 'a' && *c <= 'z') *c = (char)(*c - 32);
+ if (g.sab == SAB_REACTOR || g.sab == SAB_O2) snprintf(b, sizeof b, "BE CALLED DURING CRISES");
+ else if (g.emergency_cd > 0) snprintf(b, sizeof b, "EMERGENCY COOLDOWN: %ds", (int)ceilf(g.emergency_cd));
+ else snprintf(b, sizeof b, "%d EMERGENCY MEETINGS LEFT", P->alive ? P->emergencies : 0);
+ gfx_text(FONT_SMALL, MG_X, 172, a, BLACK, 0, 0, 1);
+ gfx_text(FONT_SMALL, MG_X, 186, b, BLACK, 0, 0, 1);
+ mg_keys("OK press the button Back close");
+}
+
+/* ---- the second half's dispatch ---- */
+
+void mg2_open(int kind) {
+ switch (kind) {
+ case MG_LEAVES: leaves_open(); break;
+ case MG_MANIFOLDS: manifolds_open(); break;
+ case MG_STEERING: steering_open(); break;
+ case MG_SHIELDS: shields_open(); break;
+ case MG_COMMS: comms_open(); break;
+ default: break;
+ }
+}
+
+void mg2_tick(uint32_t keys, uint32_t pressed) {
+ switch (M->kind) {
+ case MG_LEAVES: leaves_tick(keys, pressed); break;
+ case MG_MANIFOLDS: manifolds_tick(pressed); break;
+ case MG_STEERING: steering_tick(keys); break;
+ case MG_SHIELDS: shields_tick(pressed); break;
+ case MG_DIVERT: divert_tick(keys); break;
+ case MG_ACCEPT: accept_tick(pressed); break;
+ case MG_HANDS: hands_tick(keys); break;
+ case MG_LIGHTS: lights_tick(pressed); break;
+ case MG_COMMS: comms_tick(keys); break;
+ case MG_KEYPAD: keypad_tick(pressed); break;
+ case MG_EMERGENCY: emergency_tick(pressed); break;
+ default: break;
+ }
+}
+
+void mg2_draw(void) {
+ switch (M->kind) {
+ case MG_LEAVES: leaves_draw(); break;
+ case MG_MANIFOLDS: manifolds_draw(); break;
+ case MG_STEERING: steering_draw(); break;
+ case MG_SHIELDS: shields_draw(); break;
+ case MG_DIVERT: divert_draw(); break;
+ case MG_ACCEPT: accept_draw(); break;
+ case MG_HANDS: hands_draw(); break;
+ case MG_LIGHTS: lights_draw(); break;
+ case MG_COMMS: comms_draw(); break;
+ case MG_KEYPAD: keypad_draw(); break;
+ case MG_CAMS: cams_draw(); break;
+ case MG_EMERGENCY: emergency_draw(); break;
+ default: break;
+ }
+}
diff --git a/games/amongus/src/play.c b/games/amongus/src/play.c
index 4bd04a44..a38678e0 100644
--- a/games/amongus/src/play.c
+++ b/games/amongus/src/play.c
@@ -228,16 +228,12 @@ static void do_action(void) {
else enter_vent(g.me, what);
break;
case ACT_EMERGENCY:
- g.overlay = O_EMERGENCY;
- g.mg_cons = (uint8_t)what;
- memset(g.mg, 0, sizeof g.mg);
+ case ACT_CAMS:
+ mg_open(what, MAX_TASKS);
break;
case ACT_ADMIN:
g.overlay = O_ADMIN;
- break;
- case ACT_CAMS:
- g.overlay = O_CAMS;
- memset(g.mg, 0, sizeof g.mg);
+ g.sel = 0;
break;
case ACT_USE:
mg_open(what, console_use(g.me, what));
@@ -280,7 +276,7 @@ void play_tick(uint32_t keys, uint32_t pressed) {
}
} else {
walk(g.me, (V2){0, 0});
- if (g.overlay == O_TASK || g.overlay == O_EMERGENCY || g.overlay == O_CAMS) mg_tick(keys, pressed);
+ if (g.overlay == O_TASK) mg_tick(keys, pressed);
else map_tick(pressed, g.overlay);
}
int screen = g.screen;
diff --git a/games/amongus/src/res.h b/games/amongus/src/res.h
index 5a1d9a15..ce1f7dac 100644
--- a/games/amongus/src/res.h
+++ b/games/amongus/src/res.h
@@ -19,7 +19,9 @@ enum { P_4BIT = 1, P_OPAQUE = 2, P_MIX = 4 };
const Pic *pic(int id);
const void *blob(int id);
static inline const uint16_t *pic_pal(const Pic *p) { return (const uint16_t *)(const void *)(p + 1); }
-static inline const uint8_t *pic_alpha(const Pic *p) { return (const uint8_t *)(pic_pal(p) + p->ncolors); }
+static inline const uint8_t *pic_alpha(const Pic *p) {
+ return (const uint8_t *)(pic_pal(p) + (p->ncolors ? p->ncolors : 256));
+}
static inline const uint8_t *pic_px(const Pic *p) {
if (p->flags & P_MIX) return (const uint8_t *)(p + 1);
int n = p->ncolors ? p->ncolors : 256;
@@ -42,14 +44,29 @@ const Font *font(int id);
static inline const Glyph *font_glyphs(const Font *f) { return (const Glyph *)(const void *)(f + 1); }
static inline const uint8_t *font_bits(const Font *f) { return (const uint8_t *)(font_glyphs(f) + f->count); }
-/* the ship's floor: tw x th tiles of 16x16, a tile number each (0xFFFF: space), each tile 16 colours and 4-bit
- * pixels */
+/* a big picture (the ship's floor, the panels): tw x th tiles of 16x16, a tile number each (0xFFFF: nothing; bit 15:
+ * colour 15 is clear), each tile 16 colours and 4-bit pixels */
typedef struct {
uint16_t tw, th;
- uint32_t ntiles, tiles_off;
-} ShipTiles;
-static inline const uint16_t *ship_map(const ShipTiles *s) { return (const uint16_t *)(const void *)(s + 1); }
-static inline const uint8_t *ship_tile(const ShipTiles *s, int t) {
- return (const uint8_t *)s + s->tiles_off + (uint32_t)t * 160;
+ int16_t ox, oy; /* its pivot */
+ uint32_t tiles_off;
+} TilePic;
+#define T_EMPTY 0xFFFF
+#define T_CLEAR 0x8000
+static inline const TilePic *tilepic(int blob_id) { return (const TilePic *)blob(blob_id); }
+static inline const uint16_t *tile_map(const TilePic *s) { return (const uint16_t *)(const void *)(s + 1); }
+static inline const uint8_t *tile_data(const TilePic *s, unsigned t) {
+ return (const uint8_t *)s + s->tiles_off + (t & 0x7FFF) * 160u;
+}
+/* the colour at (x, y) (from the top-left), or -1 if clear */
+static inline int tile_px(const TilePic *s, int x, int y) {
+ if (x < 0 || y < 0 || x >= s->tw * 16 || y >= s->th * 16) return -1;
+ unsigned t = tile_map(s)[(y >> 4) * s->tw + (x >> 4)];
+ if (t == T_EMPTY) return -1;
+ const uint8_t *d = tile_data(s, t);
+ uint8_t b = d[32 + (y & 15) * 8 + ((x & 15) >> 1)];
+ unsigned k = x & 1 ? b & 15 : b >> 4;
+ if ((t & T_CLEAR) && k == 15) return -1;
+ return ((const uint16_t *)(const void *)d)[k];
}
#endif
diff --git a/games/amongus/src/screens.c b/games/amongus/src/screens.c
index 998bc26a..e4fe934f 100644
--- a/games/amongus/src/screens.c
+++ b/games/amongus/src/screens.c
@@ -384,7 +384,7 @@ static void draw_band(void) {
case S_PLAY:
view_draw();
if (g.overlay == O_NONE) hud_draw();
- else if (g.overlay == O_TASK || g.overlay == O_EMERGENCY || g.overlay == O_CAMS) mg_draw();
+ else if (g.overlay == O_TASK) mg_draw();
else map_draw(g.overlay);
break;
case S_KILLED:
diff --git a/games/amongus/src/view.c b/games/amongus/src/view.c
index 82fc6f35..666561e9 100644
--- a/games/amongus/src/view.c
+++ b/games/amongus/src/view.c
@@ -17,46 +17,43 @@ static inline int sy_of(float y) { return (int)floorf(-y * PX_PER_UNIT + SHIP_OY
/* ---- the floor ---- */
static void draw_tiles(void) {
- const ShipTiles *S = (const ShipTiles *)blob(BLOB_SHIP);
- const uint16_t *map = ship_map(S);
- int y0 = gfx_y0 + view.cy, y1 = y0 + BAND;
- int ty0 = y0 >> 4, ty1 = (y1 - 1) >> 4;
- int tx0 = view.cx >> 4, tx1 = (view.cx + SCREEN_W - 1) >> 4;
- for (int ty = ty0; ty <= ty1; ty++) {
- int r0 = ty * 16 < y0 ? y0 - ty * 16 : 0, r1 = ty * 16 + 16 > y1 ? y1 - ty * 16 : 16;
- for (int tx = tx0; tx <= tx1; tx++) {
- int sx = tx * 16 - view.cx;
- int c0 = sx < 0 ? -sx : 0, c1 = sx + 16 > SCREEN_W ? SCREEN_W - sx : 16;
- unsigned t = (tx >= 0 && ty >= 0 && tx < S->tw && ty < S->th) ? map[ty * S->tw + tx] : 0xFFFF;
- if (t == 0xFFFF) {
- /* space, and its stars */
- for (int r = r0; r < r1; r++) {
- uint16_t *row = gfx_band + (ty * 16 + r - view.cy - gfx_y0) * SCREEN_W + sx;
- for (int c = c0; c < c1; c++) row[c] = 0;
- }
- uint32_t h = (uint32_t)tx * 73856093u ^ (uint32_t)ty * 19349663u;
- h ^= h >> 13, h *= 0x5bd1e995u, h ^= h >> 15;
- if ((h & 3) == 0) {
- int px = (int)(h >> 8 & 15), py = (int)(h >> 12 & 15);
- if (py >= r0 && py < r1 && px >= c0 && px < c1)
- gfx_band[(ty * 16 + py - view.cy - gfx_y0) * SCREEN_W + sx + px] = (h >> 20 & 1) ? 0xFFFF : 0x8C71;
- }
- continue;
- }
- const uint8_t *tile = ship_tile(S, (int)t);
- const uint16_t *pal = (const uint16_t *)(const void *)tile;
- const uint8_t *px = tile + 32;
- for (int r = r0; r < r1; r++) {
- uint16_t *row = gfx_band + (ty * 16 + r - view.cy - gfx_y0) * SCREEN_W + sx;
- const uint8_t *src = px + r * 8;
- int c = c0;
- if (c & 1) row[c] = pal[src[c >> 1] & 15], c++;
- for (; c + 1 < c1; c += 2) {
- uint8_t b = src[c >> 1];
- row[c] = pal[b >> 4], row[c + 1] = pal[b & 15];
- }
- if (c < c1) row[c] = pal[src[c >> 1] >> 4];
- }
+ /* space and its stars, then the ship over them */
+ gfx_fill(0, gfx_y0, SCREEN_W, BAND, 0, 256);
+ int y0 = gfx_y0 + view.cy;
+ for (int ty = y0 >> 4; ty <= (y0 + BAND - 1) >> 4; ty++)
+ for (int tx = view.cx >> 4; tx <= (view.cx + SCREEN_W - 1) >> 4; tx++) {
+ uint32_t h = (uint32_t)tx * 73856093u ^ (uint32_t)ty * 19349663u;
+ h ^= h >> 13, h *= 0x5bd1e995u, h ^= h >> 15;
+ if (h & 3) continue;
+ int x = tx * 16 + (int)(h >> 8 & 15) - view.cx, y = ty * 16 + (int)(h >> 12 & 15) - view.cy;
+ if (x >= 0 && x < SCREEN_W && y >= gfx_y0 && y < gfx_y0 + BAND)
+ gfx_band[(y - gfx_y0) * SCREEN_W + x] = (h >> 20 & 1) ? 0xFFFF : 0x8C71;
+ }
+ gfx_tiles(tilepic(BLOB_SHIP), -view.cx, -view.cy);
+}
+
+/* an object in front, drawn again inside the rectangle: the floor's own pixels where it covers it */
+static void restamp(const FrontRec *F, int cx0, int cy0, int cx1, int cy1) {
+ const TilePic *S = tilepic(BLOB_SHIP);
+ const uint8_t *m = (const uint8_t *)blob(BLOB_FRONT_MASKS) + F->off;
+ int stride = (F->w + 7) >> 3;
+ int x0 = F->x - view.cx, y0 = F->y - view.cy;
+ if (cy0 < gfx_y0) cy0 = gfx_y0;
+ if (cy1 > gfx_y0 + BAND) cy1 = gfx_y0 + BAND;
+ if (cy0 < y0) cy0 = y0;
+ if (cy1 > y0 + F->h) cy1 = y0 + F->h;
+ if (cx0 < x0) cx0 = x0;
+ if (cx1 > x0 + F->w) cx1 = x0 + F->w;
+ if (cx0 < 0) cx0 = 0;
+ if (cx1 > SCREEN_W) cx1 = SCREEN_W;
+ for (int y = cy0; y < cy1; y++) {
+ const uint8_t *mr = m + (y - y0) * stride;
+ uint16_t *row = gfx_band + (y - gfx_y0) * SCREEN_W;
+ for (int x = cx0; x < cx1; x++) {
+ int u = x - x0;
+ if (!(mr[u >> 3] >> (u & 7) & 1)) continue;
+ int c = tile_px(S, x + view.cx, y + view.cy);
+ if (c >= 0) row[x] = (uint16_t)c;
}
}
}
@@ -174,9 +171,8 @@ void view_prepare(void) {
}
nfronts = 0;
for (int f = 0; f < N_FRONT; f++) {
- const Pic *p = pic(FRONT[f].pic);
int x = FRONT[f].x - view.cx, y = FRONT[f].y - view.cy;
- if (x < SCREEN_W && y < SCREEN_H && x + p->w > 0 && y + p->h > 0) fronts[nfronts++] = (uint8_t)f;
+ if (x < SCREEN_W && y < SCREEN_H && x + FRONT[f].w > 0 && y + FRONT[f].h > 0) fronts[nfronts++] = (uint8_t)f;
}
}
@@ -190,10 +186,9 @@ static void draw_items(void) {
for (int n = 0; n < nfronts; n++) {
const FrontRec *F = &FRONT[fronts[n]];
if (F->z >= it->z) continue;
- const Pic *p = pic(F->pic);
int x = F->x - view.cx, y = F->y - view.cy;
- if (x >= it->x1 || y >= it->y1 || x + p->w <= it->x0 || y + p->h <= it->y0) continue;
- gfx_spr_clip(p, x, y, false, NULL, 256, it->x0, it->y0, it->x1, it->y1);
+ if (x >= it->x1 || y >= it->y1 || x + F->w <= it->x0 || y + F->h <= it->y0) continue;
+ restamp(F, it->x0, it->y0, it->x1, it->y1);
}
/* doors in front of it */
for (int n = k + 1; n < nitems; n++) {
@@ -274,8 +269,7 @@ void view_draw(void) {
/* the ship seen through a camera (scale px a unit, centred on c, in the rectangle) */
void view_camera(V2 c, float scale, int rx, int ry, int rw, int rh) {
- const ShipTiles *S = (const ShipTiles *)blob(BLOB_SHIP);
- const uint16_t *map = ship_map(S);
+ const TilePic *S = tilepic(BLOB_SHIP);
float k = PX_PER_UNIT / scale;
int y0 = ry > gfx_y0 ? ry : gfx_y0, y1 = ry + rh < gfx_y0 + BAND ? ry + rh : gfx_y0 + BAND;
float sx0 = c.x * PX_PER_UNIT + SHIP_OX - (rw / 2) * k, sy0 = -c.y * PX_PER_UNIT + SHIP_OY - (rh / 2) * k;
@@ -283,16 +277,8 @@ void view_camera(V2 c, float scale, int rx, int ry, int rw, int rh) {
uint16_t *row = gfx_band + (y - gfx_y0) * SCREEN_W;
int py = (int)(sy0 + (y - ry) * k);
for (int x = rx; x < rx + rw; x++) {
- int px = (int)(sx0 + (x - rx) * k);
- int tx = px >> 4, ty = py >> 4;
- unsigned t = (px >= 0 && py >= 0 && tx < S->tw && ty < S->th) ? map[ty * S->tw + tx] : 0xFFFF;
- if (t == 0xFFFF) {
- row[x] = 0;
- continue;
- }
- const uint8_t *tile = ship_tile(S, (int)t);
- uint8_t b = tile[32 + (py & 15) * 8 + ((px & 15) >> 1)];
- row[x] = ((const uint16_t *)(const void *)tile)[px & 1 ? b & 15 : b >> 4];
+ int v = tile_px(S, (int)(sx0 + (x - rx) * k), py);
+ row[x] = v < 0 ? 0 : (uint16_t)v;
}
}
/* who is there */
diff --git a/games/amongus/tests/play.c b/games/amongus/tests/play.c
index 7b6bbae6..b77a0fdb 100644
--- a/games/amongus/tests/play.c
+++ b/games/amongus/tests/play.c
@@ -15,6 +15,7 @@
#include "../src/game.h"
#include "../src/gfx.h"
#include "../src/plat.h"
+#include "../src/world.h"
extern uint32_t host_keys, host_time;
extern bool game_running, autopilot;
@@ -47,6 +48,52 @@ static void parse_keys(const char *spec) {
}
}
+/* opens a minigame straight away (tests and screenshots): its kind as in mg.h */
+static void open_minigame(int kind) {
+ static const int8_t TYPE[] = {T_SWIPE_CARD, T_FIX_WIRING, T_CLEAR_ASTEROIDS, T_ALIGN_ENGINE, T_SUBMIT_SCAN,
+ T_INSPECT_SAMPLE, T_FUEL_ENGINES, T_START_REACTOR, T_EMPTY_GARBAGE, T_UPLOAD_DATA,
+ T_CALIBRATE, T_CHART_COURSE, T_CLEAN_O2, T_UNLOCK_MANIFOLDS, T_STABILIZE,
+ T_PRIME_SHIELDS, T_DIVERT_POWER, T_DIVERT_POWER};
+ g.screen = S_PLAY;
+ Player *P = &g.p[g.me];
+ if (kind < 18) {
+ for (int d = 0; d < N_TASK_DEFS; d++)
+ if (TASK_DEFS[d].type == TYPE[kind]) {
+ memset(&P->tasks[0], 0, sizeof P->tasks[0]);
+ P->tasks[0].def = (uint8_t)d;
+ P->tasks[0].data[0] = 0, P->tasks[0].data[1] = 2, P->tasks[0].data[2] = 4;
+ if (kind == 17) P->tasks[0].step = 1;
+ if (TYPE[kind] == T_INSPECT_SAMPLE) P->tasks[0].timer = -1;
+ break;
+ }
+ int c = task_console(P, &P->tasks[0]);
+ P->pos = (V2){CONSOLES[c].sx, CONSOLES[c].sy};
+ mg_open(c, 0);
+ } else if (kind <= 21) {
+ static const int SAB[] = {SAB_REACTOR, SAB_LIGHTS, SAB_COMMS, SAB_O2};
+ g.sab_cd = 0;
+ sabotage(SAB[kind - 18]);
+ for (int c = 0; c < N_CONSOLES; c++) {
+ const ConsoleRec *C = &CONSOLES[c];
+ int t = SAB[kind - 18] == SAB_REACTOR ? T_RESET_REACTOR : SAB[kind - 18] == SAB_LIGHTS ? T_FIX_LIGHTS
+ : SAB[kind - 18] == SAB_COMMS ? T_FIX_COMMS : T_RESTORE_O2;
+ if (!C->kind && (C->types >> t & 1)) {
+ P->pos = (V2){C->sx, C->sy};
+ mg_open(c, MAX_TASKS);
+ break;
+ }
+ }
+ } else {
+ for (int c = 0; c < N_CONSOLES; c++)
+ if (CONSOLES[c].kind == (kind == 22 ? 3 : 2)) {
+ P->pos = (V2){CONSOLES[c].sx, CONSOLES[c].sy};
+ mg_open(c, MAX_TASKS);
+ break;
+ }
+ }
+ g.cam = (V2){P->pos.x, P->pos.y + FEET_Y};
+}
+
static uint32_t frng = 1;
static uint32_t frnd(void) {
frng ^= frng << 13, frng ^= frng >> 17, frng ^= frng << 5;
@@ -54,7 +101,7 @@ static uint32_t frnd(void) {
}
int main(int argc, char **argv) {
- int frames = 300, trace = 0, start = 0, bots = -1;
+ int frames = 300, trace = 0, start = 0, bots = -1, mgkind = -1;
uint32_t seed = 0;
bool fuzz = false, draw = false;
const char *out = "build/shots";
@@ -69,6 +116,7 @@ int main(int argc, char **argv) {
else if (!strcmp(argv[i], "--trace")) trace = atoi(argv[++i]);
else if (!strcmp(argv[i], "--seed")) seed = (uint32_t)atoi(argv[++i]);
else if (!strcmp(argv[i], "--bots")) bots = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "--mg")) mgkind = atoi(argv[++i]), start = start ? start : 1;
else if (!strcmp(argv[i], "--fuzz")) fuzz = true, frng = (uint32_t)atoi(argv[++i]) * 2654435761u + 1;
else if (!strcmp(argv[i], "--shots")) {
const char *s = argv[++i];
@@ -92,6 +140,7 @@ int main(int argc, char **argv) {
g.opt.role = (uint8_t)start;
g.rng = seed * 2654435761u + 77;
game_new();
+ if (mgkind >= 0) open_minigame(mgkind);
}
uint32_t fk = 0;
static int hist[16];
diff --git a/games/amongus/tools/pack.py b/games/amongus/tools/pack.py
index 9237f0ef..613e88a7 100644
--- a/games/amongus/tools/pack.py
+++ b/games/amongus/tools/pack.py
@@ -41,7 +41,7 @@ def quantize(px, n, alpha=True):
inv = inv.reshape(-1)
if len(cols) <= k:
centers = cols.astype(np.float64)
- lab = inv
+ lab = np.arange(len(cols))
else:
w = np.array([1.0, 1.2, 0.8, 1.5])
pts = cols.astype(np.float64) * w
@@ -157,48 +157,61 @@ def make_font(path, size, first=32, last=126, bold=0):
return out
-# ---- the Skeld's floor: 16x16 tiles of 16 colours each, the same tiles stored once ----
+# ---- big pictures (the Skeld's floor, the panels): 16x16 tiles of 16 colours each, the same tiles stored once ----
TILE = 16
-
-
-def make_ship(im):
- bg = Image.new("RGBA", im.size, (0, 0, 0, 255))
- bg.alpha_composite(im)
- alpha = np.asarray(im)[:, :, 3]
- rgb = np.asarray(bg.convert("RGB"))
+T_CLEAR = 0x8000 # a tile with see-through pixels: colour 15 is clear
+
+
+def make_tiles(im, pivot=(0, 0), back=None, name=""):
+ """{u16 tw, th; i16 ox, oy; u32 tiles' offset}, a tile number each (0xFFFF: nothing there), the tiles.
+ back: the colour see-through pixels get (the ship: space); else a tile keeps them clear"""
+ im = im.convert("RGBA")
+ a8 = np.asarray(im)[:, :, 3]
+ if back is not None:
+ bg = Image.new("RGBA", im.size, back + (255,))
+ bg.alpha_composite(im)
+ rgb = np.asarray(bg.convert("RGB"))
+ else:
+ rgb = np.asarray(im)[:, :, :3]
W, H = im.size
tw, th = (W + TILE - 1) // TILE, (H + TILE - 1) // TILE
rgb = np.pad(rgb, ((0, th * TILE - H), (0, tw * TILE - W), (0, 0)))
- alpha = np.pad(alpha, ((0, th * TILE - H), (0, tw * TILE - W)))
- tmap = []
- tiles = []
- seen = {}
+ alpha = np.pad(a8, ((0, th * TILE - H), (0, tw * TILE - W)))
+ tmap, tiles, seen = [], [], {}
err = 0.0
for ty in range(th):
for tx in range(tw):
- a = alpha[ty * TILE:(ty + 1) * TILE, tx * TILE:(tx + 1) * TILE]
- if a.max() < 8:
+ a = alpha[ty * TILE:(ty + 1) * TILE, tx * TILE:(tx + 1) * TILE].reshape(-1)
+ if a.max() < 8 or (back is None and a.max() < 128):
tmap.append(0xFFFF)
continue
t = rgb[ty * TILE:(ty + 1) * TILE, tx * TILE:(tx + 1) * TILE].reshape(-1, 3)
+ clear = (a < 128) if back is None else np.zeros(len(a), bool)
px = np.hstack([t, np.full((len(t), 1), 255, np.uint8)])
- pal, idx = quantize(px, 16, alpha=False)
- err += float(((pal[idx][:, :3].astype(float) - t) ** 2).sum())
+ n = 15 if clear.any() else 16
+ pal, idx = quantize(px[~clear] if clear.any() else px, n, alpha=False)
+ full = np.full(len(t), 15, np.uint8)
+ full[~clear] = idx
+ err += float(((pal[idx][:, :3].astype(float) - t[~clear]) ** 2).sum())
p = [rgb565(*c[:3]) for c in pal] + [0] * (16 - len(pal))
- idx = idx.reshape(TILE, TILE)
- data = struct.pack("<16H", *p) + ((idx[:, 0::2] << 4) | idx[:, 1::2]).astype(np.uint8).tobytes()
+ full = full.reshape(TILE, TILE)
+ data = struct.pack("<16H", *p) + ((full[:, 0::2] << 4) | full[:, 1::2]).astype(np.uint8).tobytes()
if data not in seen:
seen[data] = len(tiles)
tiles.append(data)
- tmap.append(seen[data])
- assert len(tiles) < 0xFFFF
- head = struct.pack("<HHII", tw, th, len(tiles), 12 + 2 * len(tmap) + (-(2 * len(tmap)) % 4))
- blob = head + struct.pack("<%dH" % len(tmap), *tmap)
+ tmap.append(seen[data] | (T_CLEAR if clear.any() else 0))
+ assert len(tiles) < 0x7FFF
+ head_len = 12
+ off = head_len + 2 * len(tmap)
+ off += -off % 4
+ blob = struct.pack("<HHhhI", tw, th, int(round(pivot[0])), int(round(pivot[1])), off)
+ blob += struct.pack("<%dH" % len(tmap), *tmap)
blob += b"\0" * (-len(blob) % 4)
blob += b"".join(tiles)
- print("ship: %dx%d tiles, %d stored, %d bytes, rms %.1f" % (tw, th, len(tiles), len(blob),
- math.sqrt(err / max(1, len(tiles) * 768))))
+ if name:
+ print("%s: %dx%d tiles, %d stored, %d bytes, rms %.1f" % (name, tw, th, len(tiles), len(blob),
+ math.sqrt(err / max(1, len(tiles) * 768))))
return blob
@@ -431,19 +444,34 @@ def make_world(m, out):
open(out, "w").write("\n".join(lines) + "\n")
+def cname(s):
+ return "".join(c if c.isalnum() else "_" for c in s).upper()
+
+
+# the minigames' panels sit with their prefab's root at this screen point (40 px a unit)
+MG_X, MG_Y = 160, 112
+
+
def main():
pics = Pics()
- named = {}
+ tiles = [] # (name, blob)
+ defs = [] # data.h lines
+ D = defs.append
# the ship
sm = json.load(open(os.path.join(REF, "ship.json")))
- ship_blob = make_ship(Image.open(os.path.join(REF, "ship.png")))
+ tiles.append(("SHIP", make_tiles(Image.open(os.path.join(REF, "ship.png")), back=(0, 0, 0), name="ship")))
ox, oy = sm["origin"]
- # objects in front of players behind them
+ # objects in front of players behind them: where they cover the floor (the floor's tiles show them)
front = []
+ masks = b""
for f in sm["front"]:
- im = Image.open(os.path.join(REF, "ship", f["img"] + ".png"))
- pid = pics.add("front_" + f["img"], im, (0, 0), bits=4)
- front.append((pid, f["x"], f["y"], f["z"], f["name"]))
+ im = Image.open(os.path.join(REF, "ship", f["img"] + ".png")).convert("RGBA")
+ a = np.asarray(im)[:, :, 3] >= 128
+ w = (im.width + 7) // 8 * 8
+ a = np.pad(a, ((0, 0), (0, w - im.width)))
+ front.append((len(masks), f["x"], f["y"], im.width, im.height, f["z"]))
+ masks += np.packbits(a, axis=1, bitorder="little").tobytes()
+ tiles.append(("FRONT_MASKS", masks + b"\0" * (-len(masks) % 4)))
door_ids = {}
for kind in ("side", "front"):
dm = sm["door_" + kind]
@@ -460,12 +488,12 @@ def main():
spr = json.load(open(os.path.join(REF, "spr.json")))
mix = Mix()
- def mixframe(name, scale=0.28):
+ def mixframe(name, scale=0.28, as_name=None):
im = Image.open(os.path.join(REF, "spr", name + ".png")).convert("RGBA")
piv = spr[name]["pivot"]
k = scale * 100.0 / spr[name]["ppu"]
w, h = max(1, round(im.width * k)), max(1, round(im.height * k))
- mix.add(name, im.resize((w, h), Image.LANCZOS), (piv[0] * w / im.width, piv[1] * h / im.height))
+ mix.add(as_name or name, im.resize((w, h), Image.LANCZOS), (piv[0] * w / im.width, piv[1] * h / im.height))
mixframe("idle")
for i in range(1, 13):
mixframe("walkcolor%04d" % i)
@@ -474,7 +502,34 @@ def main():
mixframe("Dead0040")
for i in range(1, 8):
mixframe("getinVent%04d" % i)
+ mixframe("idle", 0.7, "idle_big")
mix_table, nmix = mix.pack(pics)
+
+ # the minigames: a tiled background, its moving parts, more frames
+ mg = json.load(open(os.path.join(REF, "mg.json")))
+ for name, m in mg.items():
+ N = cname(name)
+ if m["bg"]:
+ im = Image.open(os.path.join(REF, "mg", name + "_bg.png"))
+ bx, by = m["bg"]["ox"], m["bg"]["oy"]
+ # (only what the screen shows: the panel's root at MG_X, MG_Y, the key line at the bottom)
+ x0, y0 = max(0, int(bx - MG_X)), max(0, int(by - MG_Y))
+ x1, y1 = min(im.width, int(bx + SCREEN_W_PX - MG_X)), min(im.height, int(by + 228 - MG_Y))
+ im = im.crop((x0, y0, x1, y1))
+ tiles.append(("MG_" + N, make_tiles(im, (bx - x0, by - y0), name="mg " + name)))
+ for key, p in m["parts"].items():
+ im = Image.open(os.path.join(REF, "mg", "%s_%s.png" % (name, key)))
+ pid = pics.add("mg_%s_%s" % (name, key), im, (p["px"], p["py"]), bits=8 if im.width * im.height < 6000 else 4)
+ D("#define PIC_MG_%s_%s %d" % (N, cname(key), pid))
+ D("#define MG_%s_%s_X %d\n#define MG_%s_%s_Y %d" % (N, cname(key), round(MG_X + p["x"] * PPU), N,
+ cname(key), round(MG_Y - p["y"] * PPU)))
+ if len(p["all"]) > 1:
+ D("static const int16_t MG_%s_%s_XY[%d][2] = {%s};" % (N, cname(key), len(p["all"]), ", ".join(
+ "{%d, %d}" % (round(MG_X + x * PPU), round(MG_Y - y * PPU)) for x, y in p["all"])))
+ for nm, e in m["extra"].items():
+ im = Image.open(os.path.join(REF, "mg", "%s_x_%s.png" % (name, nm)))
+ pid = pics.add("x_" + nm, im, (e["px"], e["py"]), bits=8 if im.width * im.height < 6000 else 4)
+ D("#define PIC_X_%s %d" % (cname(nm), pid))
# fonts
fdir = os.path.join(REF, "fonts")
fonts = [make_font(os.path.join(fdir, "LiberationSans-Regular.ttf"), 10),
@@ -482,8 +537,8 @@ def main():
make_font(os.path.join(fdir, "LiberationSans-Bold.ttf"), 14),
make_font(os.path.join(fdir, "LiberationSans-Bold.ttf"), 24)]
- # data.bin: "AUSD", counts, offsets: pictures, fonts, the ship's tiles, the mix table
- blobs = pics.blobs + fonts + [ship_blob, mix_table]
+ # data.bin: "AUSD", counts, offsets: pictures, fonts, tiled pictures, the mix table
+ blobs = pics.blobs + fonts + [b for _, b in tiles] + [mix_table]
head = struct.pack("<4sIII", b"AUSD", len(pics.blobs), len(fonts), len(blobs))
pos = len(head) + 4 * len(blobs)
offs, body = [], b""
@@ -495,25 +550,35 @@ def main():
open(os.path.join(SRC, "data.bin"), "wb").write(out)
with open(os.path.join(SRC, "data.h"), "w") as f:
f.write("/* Among Us: what's in data.bin (made by tools/pack.py) */\n#ifndef AU_DATA_H\n#define AU_DATA_H\n")
+ f.write("#include <stdint.h>\n")
f.write("#define N_PICS %d\n#define N_FONTS %d\n" % (len(pics.blobs), len(fonts)))
- f.write("#define BLOB_SHIP %d\n#define BLOB_MIX %d\n#define N_MIX %d\n" % (len(blobs) - 2, len(blobs) - 1, nmix))
+ base = len(pics.blobs) + len(fonts)
+ for k, (nm, _) in enumerate(tiles):
+ f.write("#define BLOB_%s %d\n" % (nm, base + k))
+ f.write("#define BLOB_MIX %d\n#define N_MIX %d\n" % (len(blobs) - 1, nmix))
+ f.write("#define MG_X %d\n#define MG_Y %d\n" % (MG_X, MG_Y))
f.write("enum { FONT_SMALL, FONT_MID, FONT_BIG, FONT_HUGE };\n")
f.write("#define SHIP_OX %d\n#define SHIP_OY %d\n" % (round(ox), round(oy)))
f.write("#define PIC_IDLE %d\n#define PIC_WALK %d\n#define PIC_GHOST %d\n#define N_GHOST 24\n#define PIC_DEAD %d\n"
- "#define PIC_JUMP %d\n" % (pics.ids["idle"], pics.ids["walkcolor0001"], pics.ids["ghostbob0001"],
- pics.ids["Dead0040"], pics.ids["getinVent0001"]))
+ "#define PIC_JUMP %d\n#define PIC_IDLE_BIG %d\n" % (
+ pics.ids["idle"], pics.ids["walkcolor0001"], pics.ids["ghostbob0001"], pics.ids["Dead0040"],
+ pics.ids["getinVent0001"], pics.ids["idle_big"]))
f.write("#define PIC_DOOR_SIDE %d\n#define PIC_DOOR_FRONT %d\n#define DOOR_CLOSE_FRAMES %d\n"
"#define DOOR_OPEN_FRAMES %d\n" % (door_ids["side"][0], door_ids["front"][0],
sm["door_side"]["close"], sm["door_side"]["open"]))
f.write("#define PIC_VENT %d\n#define N_VENT_FRAMES %d\n" % (vent_ids[0], len(vent_ids)))
- f.write("typedef struct { uint16_t pic; int16_t x, y; float z; } FrontRec;\n")
+ f.write("/* where an object in front covers the floor: a bit a pixel, rows of whole bytes, lowest bit first */\n")
+ f.write("typedef struct { uint32_t off; int16_t x, y; uint16_t w, h; float z; } FrontRec;\n")
f.write("#define N_FRONT %d\nstatic const FrontRec FRONT[%d] = {%s};\n" % (len(front), len(front), ", ".join(
- "{%d, %d, %d, %s}" % (p, x, y, fl(z)) for p, x, y, z, _ in front)))
+ "{%d, %d, %d, %d, %d, %s}" % (o, x, y, w, h, fl(z)) for o, x, y, w, h, z in front)))
+ f.write("\n".join(defs) + "\n")
f.write("#endif\n")
make_world(sm, os.path.join(SRC, "world.h"))
- print("data.bin: %d bytes (pictures %d, fonts %d, ship %d)" % (
- len(out), sum(len(b) for b in pics.blobs), sum(len(b) for b in fonts), len(ship_blob)))
+ print("data.bin: %d bytes (pictures %d, fonts %d, tiled %d)" % (
+ len(out), sum(len(b) for b in pics.blobs), sum(len(b) for b in fonts), sum(len(b) for _, b in tiles)))
+
+SCREEN_W_PX = 320
if __name__ == "__main__":
main()