Mirai's Miscellaneous Misadventures
M43 / chapters / test / setup.c
1
2
3
4#include <mimimi-chapters.h>
5
6#include "ground.c"
7
8static void mimimi_test_video_set(struct mimimi_test_video_set *tset, struct mimimi_video_set *set)
9{
10 static int video_count = 8;
11 static int image_count = 8;
12 static int width = 48;
13 static int height = 48;
14
15 int i, j, k;
16 struct mimimi_video *videos, *standing, *knocked, *falling, *jumping;
17 struct mimimi_image *images, *image;
18 unsigned char *colors;
19 void **textures;
20
21 videos = tset->videos;
22 images = tset->images;
23 colors = tset->colors;
24 textures = tset->textures;
25
26 set->standing = videos;
27 set->standing_video_count = video_count;
28 videos += video_count;
29
30 set->jumping = videos;
31 set->jumping_video_count = video_count;
32 videos += video_count;
33
34 for (i = 0 ; i < video_count ; i++)
35 {
36 standing = set->standing + i;
37 standing->count = image_count;
38 standing->images = images;
39 images += image_count;
40 standing->textures = textures;
41 textures += image_count;
42
43 for (j = 0 ; j < image_count ; j++)
44 {
45 image = standing->images + j;
46 image->width = width;
47 image->height = height;
48 image->colors = colors;
49 colors += width * height;
50 for (k = 0 ; k < width * height ; k++) image->colors[k] = 0;
51 }
52
53 jumping = set->jumping + i;
54 jumping->count = image_count;
55 jumping->images = images;
56 images += image_count;
57 jumping->textures = textures;
58 textures += image_count;
59
60 for (j = 0 ; j < image_count ; j++)
61 {
62 image = jumping->images + j;
63 image->width = width;
64 image->height = height;
65 image->colors = colors;
66 colors += width * height;
67 for (k = 0 ; k < width * height ; k++) image->colors[k] = 0;
68 }
69 }
70
71 knocked = videos++;
72 knocked->count = 1;
73 knocked->images = images++;
74 knocked->images[0].width = width;
75 knocked->images[0].height = height;
76 knocked->images[0].colors = colors;
77 knocked->textures = textures++;
78 colors += width * height;
79 for (i = 0 ; i < width * height ; i++) knocked->images[0].colors[i] = 0;
80
81 falling = videos++;
82 falling->count = 1;
83 falling->images = images++;
84 falling->images[0].width = width;
85 falling->images[0].height = height;
86 falling->images[0].colors = colors;
87 colors += width * height;
88 falling->textures = textures++;
89 for (i = 0 ; i < width * height ; i++) falling->images[0].colors[i] = 0;
90
91 set->knocked = knocked;
92 set->falling = falling;
93}
94
95static void mimimi_test_appearance(struct mimimi_test_sprite *sprite, struct mimimi_engine *engine)
96{
97 mimimi_test_video_set(&sprite->left, &sprite->appearance.left);
98 mimimi_test_video_set(&sprite->right, &sprite->appearance.right);
99
100 mimimi_appearance(&sprite->appearance, sprite->model, 24, 37);
101 mimimi_prepare_appearance(&sprite->appearance, engine);
102}
103
104static void mimimi_test_sprite(struct mimimi_test_sprite *sprite, int x, int y, struct mimimi_model *model, struct mimimi_engine *engine, struct mimimi_position *camera)
105{
106 sprite->model = model;
107 sprite->display.camera = camera;
108 sprite->display.sprite = &sprite->sprite;
109 sprite->display.appearance = &sprite->appearance;
110 sprite->display.animation_time = 0;
111 sprite->display.direction = 1;
112 sprite->display.width = 24;
113 sprite->display.height = 48;
114 mimimi_sprite(&sprite->sprite, mimimi_test_ground, x, y, 80, 250);
115 mimimi_test_appearance(sprite, engine);
116}
117
118static void mimimi_test_mango_tick(struct mimimi_test_sprite *mango, struct mimimi_history *history)
119{
120 mimimi_controls_tick(&mango->sprite.walk, history, &mimimi_jump, &mango->sprite);
121 mimimi_sprite_tick(&mango->sprite);
122}
123
124void mimimi_test_tick(void *data, unsigned char left, unsigned char right)
125{
126 struct mimimi_test *chapter;
127 chapter = data;
128 mimimi_history_tick(&chapter->history, left, right);
129 mimimi_test_mango_tick(&chapter->mango, &chapter->history);
130 mimimi_sprite_tick(&chapter->pepper.sprite);
131 mimimi_collision_tick(&chapter->collision);
132 mimimi_background_tick(&chapter->background, chapter->engine);
133 mimimi_display_tick(&chapter->pepper.display, chapter->engine);
134 mimimi_display_tick(&chapter->mango.display, chapter->engine);
135 mimimi_camera_tick(&chapter->camera, &chapter->mango.sprite.position, 0, -512);
136}
137
138static void mimimi_test_background(struct mimimi_test *chapter)
139{
140 static unsigned char colors[] = {0x0D, 0x05};
141
142 int x, y;
143 unsigned char color;
144
145 chapter->background_image.colors = chapter->background_colors;
146 chapter->background_image.width = mimimi_test_ground->width * 16;
147 chapter->background_image.height = mimimi_test_ground->height * 16;
148
149 for (y = 0 ; y < chapter->background_image.height ; y++)
150 for (x = 0 ; x < chapter->background_image.width ; x++)
151 {
152 color = colors[mimimi_ground_tile(mimimi_test_ground, x / 16, y / 16)];
153 chapter->background_image.colors[x + y * chapter->background_image.width] = color;
154 }
155
156 chapter->background.texture = (*chapter->engine->texture)(chapter->engine->data, &chapter->background_image);
157 chapter->background.camera = &chapter->camera;
158 chapter->background.x = 0;
159 chapter->background.y = 0;
160 chapter->background.z = 0;
161}
162
163void mimimi_test(void *data, struct mimimi_engine *engine)
164{
165 struct mimimi_test *chapter;
166 chapter = data;
167 chapter->engine = engine;
168 mimimi_test_sprite(&chapter->mango, 110 * 128, 36 * 128, mimimi_mango, engine, &chapter->camera);
169 mimimi_test_sprite(&chapter->pepper, 108 * 128, 36 * 128, mimimi_pepper, engine, &chapter->camera);
170 chapter->history.left = 0;
171 chapter->history.right = 0;
172 chapter->camera = chapter->mango.sprite.position;
173 chapter->camera.y -= 512;
174 mimimi_test_background(chapter);
175 chapter->collision_positions[0] = &chapter->mango.sprite.position;
176 chapter->collision_positions[1] = &chapter->pepper.sprite.position;
177 chapter->collision.count = 2;
178 chapter->collision.positions = chapter->collision_positions;
179 chapter->collision.proximity = 128;
180 chapter->collision.height = 256;
181 chapter->collision.strength = 512;
182 chapter->collision.tolerance = 64;
183}