Mirai's Miscellaneous Misadventures
M43 / core / effects.c
1
2
3
4#include <mimimi.h>
5
6void mimimi_conveyor_tick(struct mimimi_conveyor *conveyor)
7{
8 struct mimimi_sprite *sprite;
9 struct mimimi_ground *ground;
10 unsigned char was_airborne;
11 int x1, x2, y;
12
13 sprite = conveyor->sprite;
14 ground = conveyor->ground;
15 was_airborne = conveyor->was_airborne;
16
17 conveyor->was_airborne = sprite->physics.airborne;
18
19 if (sprite->physics.airborne != 0)
20 {
21 if (was_airborne == 0)
22 sprite->physics.dx += conveyor->speed;
23 return;
24 }
25
26 x1 = (sprite->position.x - sprite->physics.width / 2) / 128;
27 x2 = (sprite->position.x + sprite->physics.width / 2) / 128;
28 y = (sprite->position.y + 64) / 128;
29
30 if (mimimi_ground_tile(ground, x1, y) != 0 || mimimi_ground_tile(ground, x2, y) != 0)
31 sprite->position.x += conveyor->speed;
32}
33
34void mimimi_positioned_physics_tick(struct mimimi_positioned_physics *physics, struct mimimi_ground *ground)
35{
36 int dx, dy;
37 unsigned char was_airborne;
38
39 dx = physics->transform.x - physics->previous.x;
40 dy = physics->transform.y - physics->previous.y;
41
42 physics->previous = physics->transform;
43
44 was_airborne = physics->was_airborne;
45 physics->was_airborne = physics->other.airborne;
46
47 physics->other.dx = physics->physics->dx;
48 physics->other.dy = physics->physics->dy;
49 physics->other.width = physics->physics->width;
50 physics->other.height = physics->physics->height;
51
52 physics->other_position = *physics->position;
53 physics->other_position.x -= physics->transform.x;
54 physics->other_position.y -= physics->transform.y;
55
56 if (physics->other.airborne == 0)
57 {
58 physics->other_position.x += dx;
59 physics->other_position.y += dy;
60 }
61
62 if (physics->physics->airborne != 0) physics->other.airborne = 1;
63 mimimi_physics_tick(physics->physics, physics->position, ground);
64 if (physics->other.airborne == 0) physics->physics->airborne = 0;
65
66 *physics->position = physics->other_position;
67 physics->position->x += physics->transform.x;
68 physics->position->y += physics->transform.y;
69
70 physics->physics->dx = physics->other.dx;
71 physics->physics->dy = physics->other.dy;
72
73 if (physics->other.airborne != 0 && was_airborne == 0)
74 {
75 physics->physics->dx += dx;
76 physics->physics->dy += dy;
77 }
78}
79
80void mimimi_trampoline_tick(struct mimimi_trampoline *trampoline)
81{
82 struct mimimi_sprite *sprite;
83 struct mimimi_ground *ground;
84 int dy;
85 int x1, x2, y;
86
87 sprite = trampoline->sprite;
88 ground = trampoline->ground;
89
90 dy = trampoline->dy;
91 trampoline->dy = 0;
92
93 if (sprite->physics.airborne != 0)
94 {
95 trampoline->dy = sprite->physics.dy;
96 return;
97 }
98
99 if (dy == 0) return;
100
101 x1 = (sprite->position.x - sprite->physics.width / 2) / 128;
102 x2 = (sprite->position.x + sprite->physics.width / 2) / 128;
103 y = (sprite->position.y + 64) / 128;
104
105 if (mimimi_ground_tile(ground, x1, y) != 0) return;
106 if (mimimi_ground_tile(ground, x2, y) != 0) return;
107
108 sprite->physics.airborne = 1;
109 sprite->physics.dy -= dy * trampoline->restitution / 256;
110}