Mirai's Miscellaneous Misadventures
M51 / chapters / chapter-I / setup.c
1
2
3
4#include <stdlib.h>
5
6#include <mimimi-chapters.h>
7
8#include "ground.c"
9#include "background.c"
10
11static void mimimi_chapter_I_background(struct mimimi_chapter_I *chapter)
12{
13 int i;
14 struct mimimi_area *area;
15 struct mimimi_image *image;
16
17 for (i = 1 ; i < chapter->stage.area_count ; i++)
18 {
19 area = chapter->stage.areas + i;
20 area->background_count = 1;
21 area->backgrounds = malloc(sizeof *area->backgrounds);
22 if (area->backgrounds == NULL) exit(1);
23 area->backgrounds[0].texture = mimimi_background(chapter->engine, area->ground, mimimi_chapter_I_colors[i]);
24 area->backgrounds[0].x = 0;
25 area->backgrounds[0].y = 0;
26 area->backgrounds[0].z = 0;
27 }
28
29 image = malloc(sizeof *image);
30 if (image == NULL) exit(1);
31 image->width = mimimi_chapter_I_background_width;
32 image->height = mimimi_chapter_I_background_height;
33 image->colors = malloc(image->width * image->height);
34 if (image->colors == NULL) exit(1);
35 mimimi_unpack_bits(image->width * image->height, image->colors, mimimi_chapter_I_background_packed);
36 chapter->stage.areas[0].background_count = 1;
37 chapter->stage.areas[0].backgrounds = malloc(sizeof *chapter->stage.areas[0].backgrounds);
38 if (chapter->stage.areas[0].backgrounds == NULL) exit(1);
39 chapter->stage.areas[0].backgrounds[0].texture = (*chapter->engine->texture)(chapter->engine->data, image);
40 chapter->stage.areas[0].backgrounds[0].x = -88;
41 chapter->stage.areas[0].backgrounds[0].y = 0;
42 chapter->stage.areas[0].backgrounds[0].z = 0;
43
44 image = malloc(sizeof *image);
45 if (image == NULL) exit(1);
46 image->width = mimimi_chapter_I_foreground_width;
47 image->height = mimimi_chapter_I_foreground_height;
48 image->colors = malloc(image->width * image->height);
49 if (image->colors == NULL) exit(1);
50 mimimi_unpack_bits(image->width * image->height, image->colors, mimimi_chapter_I_foreground_packed);
51 chapter->stage.areas[0].foreground_count = 1;
52 chapter->stage.areas[0].foregrounds = malloc(sizeof *chapter->stage.areas[0].foregrounds);
53 if (chapter->stage.areas[0].foregrounds == NULL) exit(1);
54 chapter->stage.areas[0].foregrounds[0].texture = (*chapter->engine->texture)(chapter->engine->data, image);
55 chapter->stage.areas[0].foregrounds[0].x = 0;
56 chapter->stage.areas[0].foregrounds[0].y = 0;
57 chapter->stage.areas[0].foregrounds[0].z = 0;
58}
59
60static void mimimi_chapter_I_size(struct mimimi_engine *engine)
61{
62 int width, height;
63
64 if (engine->size.width / engine->size.height < 2)
65 {
66 height = 256;
67 width = height * engine->size.width / engine->size.height;
68 }
69 else
70 {
71 width = 512;
72 height = width * engine->size.height / engine->size.width;
73 }
74
75 if (width < 256)
76 {
77 width = 256;
78 height = width * engine->size.height / engine->size.width;
79 if (height > 384) height = 384;
80 }
81 if (height < 192)
82 {
83 height = 192;
84 width = height * engine->size.width / engine->size.height;
85 if (width > 512) width = 512;
86 }
87
88 engine->size.width = width;
89 engine->size.height = height;
90}
91
92static void mimimi_chapter_I_background_tick(struct mimimi_chapter_I *chapter)
93{
94 struct mimimi_engine *engine;
95 int x, y;
96
97 engine = chapter->engine;
98
99 for (y = 0 ; y < engine->size.height ; y += 256)
100 for (x = 0 ; x < engine->size.width ; x += 256)
101 (*engine->stamp)(engine->data, x, y, chapter->background);
102}
103
104void mimimi_chapter_I_tick(void *data, unsigned char left, unsigned char right)
105{
106 struct mimimi_chapter_I *chapter;
107 struct mimimi_sprite *player;
108
109 chapter = data;
110 player = chapter->stage.sprites;
111
112 mimimi_chapter_I_size(chapter->engine);
113
114 mimimi_history_tick(&chapter->history, left, right);
115 mimimi_controls_tick(&chapter->stage.sprites[0].walk, &chapter->history, &mimimi_jump, chapter->stage.sprites);
116 mimimi_chapter_I_background_tick(chapter);
117 mimimi_stage_tick(&chapter->stage, chapter->engine);
118
119 if (chapter->progression == 0)
120 {
121 if (player->position.x < -0x1800)
122 chapter->progression++;
123 }
124 if (chapter->progression == 1)
125 {
126 if (mimimi_toast_dialogue_bottom_tick(&chapter->tutorial) != 0)
127 chapter->progression++;
128 }
129 if (chapter->progression == 2)
130 {
131 if (player->position.x < -0x5600)
132 chapter->progression++;
133 }
134 if (chapter->progression == 3)
135 {
136 if (mimimi_toast_dialogue_bottom_tick(&chapter->dialogue0) != 0)
137 chapter->progression++;
138 }
139 if (chapter->progression == 4)
140 {
141 if (chapter->stage.platform_sets[0].angular_platforms[0].physics.other.airborne == 0)
142 chapter->progression++;
143 }
144 if (chapter->progression == 5)
145 {
146 if (mimimi_toast_dialogue_bottom_tick(&chapter->dialogue1) != 0)
147 chapter->progression++;
148 }
149 if (chapter->progression == 6)
150 {
151 if (player->position.y <= -0x2280 && player->physics.airborne == 0)
152 chapter->progression++;
153 }
154 if (chapter->progression == 7)
155 {
156 if (mimimi_toast_dialogue_bottom_tick(&chapter->dialogue) != 0)
157 chapter->progression++;
158 }
159}
160
161void *mimimi_chapter_I(struct mimimi_engine *engine)
162{
163 static struct mimimi_image background;
164 static unsigned char background_colors[256 * 256];
165 static unsigned char colors0[] = {0, 0x6B};
166 static unsigned char colors1[] = {0, 8};
167 static struct mimimi_ground ground0 = {4, 3, {0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}};
168 static struct mimimi_ground ground1 = {5, 3, {0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0}};
169 static struct mimimi_dialogue_paragraph paragraphs[] =
170 {
171 {NULL, "Mirai", "There seems to be nothing for me to do. Hmmm... Maybe I can find something to do later."},
172 {NULL, "Ryouna", "Hear that? If you come back later, then maybe you can find something to do!"},
173 {NULL, "Ryoubi", "Who are you talking to? Are you stupid or something?"},
174 {NULL, "Ryouna", "Aaah! Ryoubi, I really like when you yell insults at me!"},
175 {NULL, "Mirai", "Wha-? What are you two doing here?"},
176 {NULL, "Haruka", "Hehe, don't worry about it!"},
177 };
178 static struct mimimi_dialogue_paragraph paragraphs0[] =
179 {
180 {NULL, "Haruka", "Press a direction twice to jump!"},
181 {NULL, "Mirai", "Hmm, I wonder what's on top of those platforms..."},
182 {NULL, "Mirai", "Oh, it seems like I need to be quick if I want to get to the top."},
183 };
184
185 struct mimimi_dialogue dialogue;
186 struct mimimi_chapter_I *chapter;
187 struct mimimi_display *display;
188 struct mimimi_platform_set *platforms;
189 void *texture;
190 int x, y;
191
192 mimimi_chapter_I_size(engine);
193
194 paragraphs0[0].model = mimimi_haruka_flash;
195 paragraphs0[1].model = mimimi_mirai_flash;
196 paragraphs0[2].model = mimimi_mirai_flash;
197 paragraphs[0].model = mimimi_mirai_flash;
198 paragraphs[1].model = mimimi_ryouna_flash;
199 paragraphs[2].model = mimimi_ryoubi_flash;
200 paragraphs[3].model = mimimi_ryouna_flash;
201 paragraphs[4].model = mimimi_mirai_flash;
202 paragraphs[5].model = mimimi_haruka_flash;
203
204 chapter = malloc(sizeof *chapter);
205 if (chapter == NULL) exit(1);
206 chapter->engine = engine;
207
208 display = malloc(sizeof *display);
209 if (display == NULL) exit(1);
210
211 mimimi_stage(&chapter->stage, mimimi_chapter_I_stage, sizeof mimimi_chapter_I_stage / sizeof *mimimi_chapter_I_stage);
212
213 chapter->progression = 0;
214 chapter->progression_counter = 0;
215
216 dialogue.count = 1;
217 dialogue.paragraphs = paragraphs0;
218 mimimi_toast_dialogue(&chapter->tutorial, &dialogue, engine);
219
220 dialogue.count = 1;
221 dialogue.paragraphs = paragraphs0 + 1;
222 mimimi_toast_dialogue(&chapter->dialogue0, &dialogue, engine);
223
224 dialogue.count = 1;
225 dialogue.paragraphs = paragraphs0 + 2;
226 mimimi_toast_dialogue(&chapter->dialogue1, &dialogue, engine);
227
228 dialogue.count = sizeof paragraphs / sizeof *paragraphs;
229 dialogue.paragraphs = paragraphs;
230 mimimi_toast_dialogue(&chapter->dialogue, &dialogue, engine);
231
232 mimimi_display(display, mimimi_mirai_flash, engine);
233 mimimi_spawn(&chapter->stage, display, 0, 0, 80, 250);
234
235 texture = mimimi_background(chapter->engine, &ground0, colors0);
236 platforms = mimimi_add_platform_set(&chapter->stage);
237 platforms->strength = 64;
238 platforms->max = 0x1300;
239
240 mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground0, texture, -0x5800, -0x1C80, -80, 256, 1024);
241 mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground0, texture, -0x5800, -0x1C80, -80, 256, 2048);
242 mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground0, texture, -0x5800, -0x1C80, -80, 256, 3072);
243 mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground0, texture, -0x5800, -0x1C80, -80, 256, 4096);
244
245 texture = mimimi_background(chapter->engine, &ground1, colors1);
246 platforms = mimimi_add_platform_set(&chapter->stage);
247 platforms->strength = 0;
248 platforms->min = 0;
249 platforms->max = 1024;
250
251 mimimi_spawn_linear_platform(&chapter->stage, platforms, &ground1, texture, -0x4B00, -0x700, 256);
252 mimimi_spawn_linear_platform(&chapter->stage, platforms, &ground1, texture, -0x4800, -0x800, -256);
253 mimimi_spawn_linear_platform(&chapter->stage, platforms, &ground1, texture, -0x4F00, -0xC00, 256);
254 mimimi_spawn_linear_platform(&chapter->stage, platforms, &ground1, texture, -0x4F00, -0xD00, -256);
255
256 chapter->history.left = 0;
257 chapter->history.right = 0;
258
259 mimimi_chapter_I_background(chapter);
260
261 for (y = 0 ; y < 256 ; y++)
262 for (x = 0 ; x < 256 ; x++)
263 background_colors[x + y * 256] = 1;
264
265 background.colors = background_colors;
266 background.width = 256;
267 background.height = 256;
268 chapter->background = (*engine->texture)(engine->data, &background);
269
270 return chapter;
271}