Mirai's Miscellaneous Misadventures
M24 / test / chapter.c
1
2
3
4#include <mimimi/chapters.h>
5#include <mimimi/senran-kagura/characters.h>
6#include <mimimi/appearances.h>
7#include <mimimi/allocators.h>
8#include <mimimi/ground.h>
9#include <mimimi/compound-behaviors.h>
10#include <mimimi/geometry.h>
11#include <mimimi/assets.h>
12#include <mimimi/engines.h>
13#include <mimimi/controls.h>
14#include <mimimi/sprites.h>
15#include <mimimi/cameras.h>
16#include <mimimi/behaviors.h>
17#include <mimimi/font.h>
18#include <mimimi/fonts.h>
19#include <mimimi/animations.h>
20
21#include <mimimi/test.h>
22
23#include "ground.c"
24
25static void mimimi_test_animation_set(struct mimimi_animation_set *set, struct mimimi_behavior *compound, struct mimimi_allocator *allocator)
26{
27 int animation_count = 8;
28 int image_count = 6;
29 int width = 48;
30 int height = 48;
31
32 int total_animation_count = 2 + animation_count;
33 int total_image_count = 2 + image_count * animation_count;
34
35 struct mimimi_animation *animations = mimimi_compound_allocate(compound, total_animation_count * sizeof *animations, allocator);
36 struct mimimi_image *images = mimimi_compound_allocate(compound, total_image_count * sizeof *images, allocator);
37 unsigned char *colors = mimimi_compound_allocate(compound, width * height * total_image_count, allocator);
38
39 set->standing = animations;
40 set->standing_animation_count = animation_count;
41 animations += animation_count;
42
43 for (int i = 0 ; i < animation_count ; i++)
44 {
45 struct mimimi_animation *animation = set->standing + i;
46 animation->count = image_count;
47 animation->images = images;
48 images += image_count;
49
50 for (int i = 0 ; i < image_count ; i++)
51 {
52 struct mimimi_image *image = animation->images + i;
53 image->width = width;
54 image->height = height;
55 image->colors = colors;
56 colors += width * height;
57
58 for (int i = 0 ; i < width * height ; i++)
59 image->colors[i] = 0;
60 }
61 }
62
63 struct mimimi_animation *knocked = animations++;
64 knocked->count = 1;
65 knocked->images = images++;
66 knocked->images[0].width = width;
67 knocked->images[0].height = height;
68 knocked->images[0].colors = colors;
69 colors += width * height;
70
71 struct mimimi_animation *falling = animations++;
72 falling->count = 1;
73 falling->images = images++;
74 falling->images[0].width = width;
75 falling->images[0].height = height;
76 falling->images[0].colors = colors;
77 colors += width * height;
78
79 set->knocked = knocked;
80 set->falling = falling;
81
82 for (int i = 0 ; i < width * height ; i++)
83 {
84 knocked->images[0].colors[i] = 0;
85 falling->images[0].colors[i] = 0;
86 }
87}
88
89static struct mimimi_appearance *mimimi_test_appearance(struct mimimi_behavior *compound, struct mimimi_allocator *allocator)
90{
91 struct mimimi_appearance *appearance = mimimi_compound_allocate(compound, sizeof *appearance, allocator);
92
93 mimimi_test_animation_set(&appearance->left, compound, allocator);
94 mimimi_test_animation_set(&appearance->right, compound, allocator);
95
96 return appearance;
97}
98
99struct mimimi_chapter *mimimi_test(struct mimimi_allocator *allocator)
100{
101 struct mimimi_behavior *compound = mimimi_compound_behavior(allocator);
102
103 struct mimimi_engine *engine = mimimi_compound_allocate(compound, sizeof *engine, allocator);
104
105 struct mimimi_chapter *chapter = mimimi_compound_allocate(compound, sizeof *chapter, allocator);
106 chapter->behavior = compound;
107 chapter->engine = engine;
108
109 struct mimimi_position *camera = mimimi_compound_allocate(compound, sizeof *camera, allocator);
110
111 struct mimimi_image *background = mimimi_compound_allocate(compound, sizeof *background, allocator);
112 background->colors = mimimi_compound_allocate(compound, mimimi_test_ground.width * 16 * mimimi_test_ground.height * 16, allocator);
113
114 background->width = mimimi_test_ground.width * 16;
115 background->height = mimimi_test_ground.height * 16;
116
117 static unsigned char ground_colors[] = {0x0D, 0x05, 0x24, 0x28, 0x92, 0xBC, 0x77};
118
119 for (int y = 0 ; y < mimimi_test_ground.height * 16 ; y++)
120 for (int x = 0 ; x < mimimi_test_ground.width * 16 ; x++)
121 {
122 unsigned char color = ground_colors[mimimi_test_ground.tiles[x / 16 + y / 16 * mimimi_test_ground.width]];
123 background->colors[x + y * mimimi_test_ground.width * 16] = color;
124 }
125
126 struct mimimi_history *history = mimimi_compound_allocate(compound, sizeof *history, allocator);
127 mimimi_compound(compound, mimimi_history(history, chapter, allocator));
128
129 struct mimimi_sprite *mirai = mimimi_sprite(&mimimi_test_ground, 11776, 7040, 80, 250, allocator);
130
131
132
133 struct mimimi_appearance *mirai_appearance = mimimi_test_appearance(compound, allocator);
134
135
136
137 mimimi_appearance(mirai_appearance, mimimi_mirai_flash, 24, 48, allocator);
138
139
140
141 mimimi_compound(compound, mirai->behavior);
142
143
144
145 struct mimimi_jump *mirai_jump = mimimi_compound_allocate(compound, sizeof *mirai_jump, allocator);
146 struct mimimi_behavior *mirai_jump_behavior = mimimi_jump(mirai_jump, mirai->physics, allocator);
147 mimimi_compound(compound, mimimi_finalizer(mirai_jump_behavior->data, mirai_jump_behavior->finish, allocator));
148
149 struct mimimi_controls *mirai_controls = mimimi_compound_allocate(compound, sizeof *mirai_controls, allocator);
150 mirai->awake_behavior = mimimi_controls(mirai_controls, mirai->walk, history, allocator);
151 mimimi_compound(compound, mimimi_finalizer(mirai->awake_behavior->data, mirai->awake_behavior->finish, allocator));
152 mirai_controls->jump = mirai_jump_behavior;
153
154 mimimi_compound(compound, mimimi_camera(camera, mirai->position, 0, -512, allocator));
155
156 mimimi_compound(compound, mimimi_background(engine, camera, background, 0, allocator));
157
158 mimimi_compound(compound, mimimi_display(engine, camera, mirai, mirai_appearance, allocator));
159
160
161
162 struct mimimi_image *overlay = mimimi_compound_allocate(compound, sizeof *overlay, allocator);
163 overlay->colors = mimimi_compound_allocate(compound, 256 * 64, allocator);
164 overlay->width = 256;
165 overlay->height = 64;
166
167 for (int i = 0 ; i < overlay->width * overlay->height ; i++)
168 overlay->colors[i] = 0;
169
170 struct mimimi_image *glyphs = (*allocator->allocate)(mimimi_font_image_count * sizeof *glyphs);
171 unsigned char *colors = (*allocator->allocate)(mimimi_font_color_count);
172
173 for (int i = 0 ; i < mimimi_font_image_count ; i++)
174 glyphs[i].colors = colors + i * mimimi_font_image_color_count;
175
176 mimimi_glyphs(glyphs, mimimi_font, 0x76);
177
178 mimimi_text(overlay, glyphs, 16, 16, "Mirai's Miscellaneous Misadventures M24");
179 mimimi_text(overlay, glyphs, 16, 32, "a Senran Kagura fangame, May 24 of 2022");
180
181 (*allocator->deallocate)(colors);
182 (*allocator->deallocate)(glyphs);
183
184 mimimi_compound(compound, mimimi_overlay(engine, overlay, 0, 0, allocator));
185
186 return chapter;
187}