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