Mirai's Miscellaneous Misadventures
M24 / test / chapter.c
#include <mimimi/chapters.h>
#include <mimimi/senran-kagura/characters.h>
#include <mimimi/appearances.h>
#include <mimimi/allocators.h>
#include <mimimi/ground.h>
#include <mimimi/compound-behaviors.h>
#include <mimimi/geometry.h>
#include <mimimi/assets.h>
#include <mimimi/engines.h>
#include <mimimi/controls.h>
#include <mimimi/sprites.h>
#include <mimimi/cameras.h>
#include <mimimi/behaviors.h>
#include <mimimi/font.h>
#include <mimimi/fonts.h>
#include <mimimi/animations.h>
#include <mimimi/test.h>
#include "ground.c"
static void mimimi_test_animation_set(struct mimimi_animation_set *set, struct mimimi_behavior *compound, struct mimimi_allocator *allocator)
{
int animation_count = 8;
int image_count = 6;
int width = 48;
int height = 48;
int total_animation_count = 2 + animation_count;
int total_image_count = 2 + image_count * animation_count;
struct mimimi_animation *animations = mimimi_compound_allocate(compound, total_animation_count * sizeof *animations, allocator);
struct mimimi_image *images = mimimi_compound_allocate(compound, total_image_count * sizeof *images, allocator);
unsigned char *colors = mimimi_compound_allocate(compound, width * height * total_image_count, allocator);
set->standing = animations;
set->standing_animation_count = animation_count;
animations += animation_count;
for (int i = 0 ; i < animation_count ; i++)
{
struct mimimi_animation *animation = set->standing + i;
animation->count = image_count;
animation->images = images;
images += image_count;
for (int i = 0 ; i < image_count ; i++)
{
struct mimimi_image *image = animation->images + i;
image->width = width;
image->height = height;
image->colors = colors;
colors += width * height;
for (int i = 0 ; i < width * height ; i++)
image->colors[i] = 0;
}
}
struct mimimi_animation *knocked = animations++;
knocked->count = 1;
knocked->images = images++;
knocked->images[0].width = width;
knocked->images[0].height = height;
knocked->images[0].colors = colors;
colors += width * height;
struct mimimi_animation *falling = animations++;
falling->count = 1;
falling->images = images++;
falling->images[0].width = width;
falling->images[0].height = height;
falling->images[0].colors = colors;
colors += width * height;
set->knocked = knocked;
set->falling = falling;
for (int i = 0 ; i < width * height ; i++)
{
knocked->images[0].colors[i] = 0;
falling->images[0].colors[i] = 0;
}
}
static struct mimimi_appearance *mimimi_test_appearance(struct mimimi_behavior *compound, struct mimimi_allocator *allocator)
{
struct mimimi_appearance *appearance = mimimi_compound_allocate(compound, sizeof *appearance, allocator);
mimimi_test_animation_set(&appearance->left, compound, allocator);
mimimi_test_animation_set(&appearance->right, compound, allocator);
return appearance;
}
struct mimimi_chapter *mimimi_test(struct mimimi_allocator *allocator)
{
struct mimimi_behavior *compound = mimimi_compound_behavior(allocator);
struct mimimi_engine *engine = mimimi_compound_allocate(compound, sizeof *engine, allocator);
struct mimimi_chapter *chapter = mimimi_compound_allocate(compound, sizeof *chapter, allocator);
chapter->behavior = compound;
chapter->engine = engine;
struct mimimi_position *camera = mimimi_compound_allocate(compound, sizeof *camera, allocator);
struct mimimi_image *background = mimimi_compound_allocate(compound, sizeof *background, allocator);
background->colors = mimimi_compound_allocate(compound, mimimi_test_ground.width * 16 * mimimi_test_ground.height * 16, allocator);
background->width = mimimi_test_ground.width * 16;
background->height = mimimi_test_ground.height * 16;
static unsigned char ground_colors[] = {0x0D, 0x05, 0x24, 0x28, 0x92, 0xBC, 0x77};
for (int y = 0 ; y < mimimi_test_ground.height * 16 ; y++)
for (int x = 0 ; x < mimimi_test_ground.width * 16 ; x++)
{
unsigned char color = ground_colors[mimimi_test_ground.tiles[x / 16 + y / 16 * mimimi_test_ground.width]];
background->colors[x + y * mimimi_test_ground.width * 16] = color;
}
struct mimimi_history *history = mimimi_compound_allocate(compound, sizeof *history, allocator);
mimimi_compound(compound, mimimi_history(history, chapter, allocator));
struct mimimi_sprite *mirai = mimimi_sprite(&mimimi_test_ground, 11776, 7040, 80, 250, allocator);
struct mimimi_appearance *mirai_appearance = mimimi_test_appearance(compound, allocator);
mimimi_appearance(mirai_appearance, mimimi_mirai_flash, 24, 48, allocator);
mimimi_compound(compound, mirai->behavior);
struct mimimi_jump *mirai_jump = mimimi_compound_allocate(compound, sizeof *mirai_jump, allocator);
struct mimimi_behavior *mirai_jump_behavior = mimimi_jump(mirai_jump, mirai->physics, allocator);
mimimi_compound(compound, mimimi_finalizer(mirai_jump_behavior->data, mirai_jump_behavior->finish, allocator));
struct mimimi_controls *mirai_controls = mimimi_compound_allocate(compound, sizeof *mirai_controls, allocator);
mirai->awake_behavior = mimimi_controls(mirai_controls, mirai->walk, history, allocator);
mimimi_compound(compound, mimimi_finalizer(mirai->awake_behavior->data, mirai->awake_behavior->finish, allocator));
mirai_controls->jump = mirai_jump_behavior;
mimimi_compound(compound, mimimi_camera(camera, mirai->position, 0, -512, allocator));
mimimi_compound(compound, mimimi_background(engine, camera, background, 0, allocator));
mimimi_compound(compound, mimimi_display(engine, camera, mirai, mirai_appearance, allocator));
struct mimimi_image *overlay = mimimi_compound_allocate(compound, sizeof *overlay, allocator);
overlay->colors = mimimi_compound_allocate(compound, 256 * 64, allocator);
overlay->width = 256;
overlay->height = 64;
for (int i = 0 ; i < overlay->width * overlay->height ; i++)
overlay->colors[i] = 0;
struct mimimi_image *glyphs = (*allocator->allocate)(mimimi_font_image_count * sizeof *glyphs);
unsigned char *colors = (*allocator->allocate)(mimimi_font_color_count);
for (int i = 0 ; i < mimimi_font_image_count ; i++)
glyphs[i].colors = colors + i * mimimi_font_image_color_count;
mimimi_glyphs(glyphs, mimimi_font, 0x76);
mimimi_text(overlay, glyphs, 16, 16, "Mirai's Miscellaneous Misadventures M24");
mimimi_text(overlay, glyphs, 16, 32, "a Senran Kagura fangame, May 24 of 2022");
(*allocator->deallocate)(colors);
(*allocator->deallocate)(glyphs);
mimimi_compound(compound, mimimi_overlay(engine, overlay, 0, 0, allocator));
return chapter;
}