Mirai's Miscellaneous Misadventures

M50 / chapters / chapter-I / setup.c

1/* license: AGPLv3 or later */
2/* copyright 2024 zamfofex */
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	static unsigned char colors[][5] = {{0}, {6, 0x3D, 0xC4}, {0x7D, 0x4D, 0x70, 8, 14}};
14	
15	int i;
16	struct mimimi_area *area;
17	struct mimimi_image *image;
18	
19	for (i = 1 ; i < chapter->stage.area_count ; i++)
20	{
21		area = chapter->stage.areas + i;
22		area->background_count = 1;
23		area->backgrounds = malloc(sizeof *area->backgrounds);
24		if (area->backgrounds == NULL) exit(1);
25		area->backgrounds[0].texture = mimimi_background(chapter->engine, area->ground, colors[i]);
26		area->backgrounds[0].x = 0;
27		area->backgrounds[0].y = 0;
28		area->backgrounds[0].z = 0;
29	}
30	
31	image = malloc(sizeof *image);
32	if (image == NULL) exit(1);
33	image->width = mimimi_chapter_I_background_width;
34	image->height = mimimi_chapter_I_background_height;
35	image->colors = malloc(image->width * image->height);
36	if (image->colors == NULL) exit(1);
37	mimimi_unpack_bits(image->width * image->height, image->colors, mimimi_chapter_I_background_packed);
38	chapter->stage.areas[0].background_count = 1;
39	chapter->stage.areas[0].backgrounds = malloc(sizeof *chapter->stage.areas[0].backgrounds);
40	if (chapter->stage.areas[0].backgrounds == NULL) exit(1);
41	chapter->stage.areas[0].backgrounds[0].texture = (*chapter->engine->texture)(chapter->engine->data, image);
42	chapter->stage.areas[0].backgrounds[0].x = -88;
43	chapter->stage.areas[0].backgrounds[0].y = 0;
44	chapter->stage.areas[0].backgrounds[0].z = 0;
45	
46	image = malloc(sizeof *image);
47	if (image == NULL) exit(1);
48	image->width = mimimi_chapter_I_foreground_width;
49	image->height = mimimi_chapter_I_foreground_height;
50	image->colors = malloc(image->width * image->height);
51	if (image->colors == NULL) exit(1);
52	mimimi_unpack_bits(image->width * image->height, image->colors, mimimi_chapter_I_foreground_packed);
53	chapter->stage.areas[0].foreground_count = 1;
54	chapter->stage.areas[0].foregrounds = malloc(sizeof *chapter->stage.areas[0].foregrounds);
55	if (chapter->stage.areas[0].foregrounds == NULL) exit(1);
56	chapter->stage.areas[0].foregrounds[0].texture = (*chapter->engine->texture)(chapter->engine->data, image);
57	chapter->stage.areas[0].foregrounds[0].x = 0;
58	chapter->stage.areas[0].foregrounds[0].y = 0;
59	chapter->stage.areas[0].foregrounds[0].z = 0;
60}
61
62void mimimi_chapter_I_tick(void *data, unsigned char left, unsigned char right)
63{
64	struct mimimi_chapter_I *chapter;
65	struct mimimi_sprite *player;
66	
67	chapter = data;
68	player = chapter->stage.sprites;
69	
70	mimimi_history_tick(&chapter->history, left, right);
71	mimimi_controls_tick(&chapter->stage.sprites[0].walk, &chapter->history, &mimimi_jump, chapter->stage.sprites);
72	mimimi_stage_tick(&chapter->stage, chapter->engine);
73	
74	if (chapter->progression == 0)
75	{
76		if (player->position.x < -9216)
77			chapter->progression++;
78	}
79	if (chapter->progression == 1)
80	{
81		if (mimimi_toast_dialogue_bottom_tick(&chapter->dialogue0) != 0)
82			chapter->progression++;
83	}
84	if (chapter->progression == 2)
85	{
86		if (chapter->stage.platform_sets[0].angular_platforms[0].physics.other.airborne == 0)
87			chapter->progression++;
88	}
89	if (chapter->progression == 3)
90	{
91		if (mimimi_toast_dialogue_bottom_tick(&chapter->dialogue1) != 0)
92			chapter->progression++;
93	}
94	if (chapter->progression == 4)
95	{
96		if (player->position.y <= -3712 && player->physics.airborne == 0)
97			chapter->progression++;
98	}
99	if (chapter->progression == 5)
100	{
101		if (mimimi_toast_dialogue_bottom_tick(&chapter->dialogue) != 0)
102			chapter->progression++;
103	}
104}
105
106void *mimimi_chapter_I(struct mimimi_engine *engine)
107{
108	static unsigned char colors[] = {0, 0x6B};
109	static struct mimimi_ground ground = {4, 3, {0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}};
110	static struct mimimi_ground *grounds[] = {&mimimi_chapter_I_hideout, &mimimi_chapter_I_stairs, &mimimi_chapter_I_platforming};
111	static struct mimimi_dialogue_paragraph paragraphs[] =
112	{
113		{NULL, "Mirai", "There seems to be nothing for me to do. Hmmm... Maybe I can find something to do later."},
114		{NULL, "Ryouna", "Hear that? If you come back later, then maybe you can find something to do!"},
115		{NULL, "Ryoubi", "Who are you talking to? Are you stupid or something?"},
116		{NULL, "Ryouna", "Aaah! Ryoubi, I really like when you yell insults at me!"},
117		{NULL, "Mirai", "Wha-? What are you two doing here?"},
118		{NULL, "Haruka", "Hehe, don't worry about it!"},
119	};
120	static struct mimimi_dialogue_paragraph paragraphs0[] =
121	{
122		{NULL, "Mirai", "Hmm, I wonder what's on top of those platforms..."},
123		{NULL, "Mirai", "Oh, it seems like I need to be quick if I want to get to the top."},
124	};
125	
126	struct mimimi_dialogue dialogue;
127	struct mimimi_chapter_I *chapter;
128	struct mimimi_display *display;
129	struct mimimi_platform_set *platforms;
130	void *texture;
131	
132	paragraphs0[0].model = mimimi_mirai_flash;
133	paragraphs0[1].model = mimimi_mirai_flash;
134	paragraphs[0].model = mimimi_mirai_flash;
135	paragraphs[1].model = mimimi_ryouna_flash;
136	paragraphs[2].model = mimimi_ryoubi_flash;
137	paragraphs[3].model = mimimi_ryouna_flash;
138	paragraphs[4].model = mimimi_mirai_flash;
139	paragraphs[5].model = mimimi_haruka_flash;
140	
141	chapter = malloc(sizeof *chapter);
142	if (chapter == NULL) exit(1);
143	chapter->engine = engine;
144	
145	display = malloc(sizeof *display);
146	if (display == NULL) exit(1);
147	
148	mimimi_stage(&chapter->stage, grounds, sizeof grounds / sizeof *grounds);
149	
150	chapter->progression = 0;
151	chapter->progression_counter = 0;
152	
153	dialogue.count = 1;
154	dialogue.paragraphs = paragraphs0;
155	mimimi_toast_dialogue(&chapter->dialogue0, &dialogue, engine);
156	
157	dialogue.count = 1;
158	dialogue.paragraphs = paragraphs0 + 1;
159	mimimi_toast_dialogue(&chapter->dialogue1, &dialogue, engine);
160	
161	dialogue.count = sizeof paragraphs / sizeof *paragraphs;
162	dialogue.paragraphs = paragraphs;
163	mimimi_toast_dialogue(&chapter->dialogue, &dialogue, engine);
164	
165	mimimi_display(display, mimimi_mirai_flash, engine);
166	mimimi_spawn(&chapter->stage, display, 0, 0, 80, 250);
167	
168	texture = mimimi_background(chapter->engine, &ground, colors);
169	platforms = mimimi_add_platform_set(&chapter->stage);
170	platforms->strength = 64;
171	platforms->max = 0x1300;
172	mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground, texture, -0x2600, -2048, -80, 256, 1024);
173	mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground, texture, -0x2600, -2048, -80, 256, 2048);
174	mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground, texture, -0x2600, -2048, -80, 256, 3072);
175	mimimi_spawn_angular_platform(&chapter->stage, platforms, &ground, texture, -0x2600, -2048, -80, 256, 4096);
176	
177	chapter->history.left = 0;
178	chapter->history.right = 0;
179	
180	mimimi_chapter_I_background(chapter);
181	
182	return chapter;
183}