Mirai's Miscellaneous Misadventures

M45 / core / mechanics.c

1/* license: AGPLv3 or later */
2/* copyright 2023 zamfofex */
3
4#include <mimimi.h>
5
6void mimimi_linear_propagate(struct mimimi_momentum *momentum, int value, int x0, int scale, int weight)
7{
8	momentum->dx += ((value - x0) * 256 / scale - momentum->x) * weight / 256;
9}
10
11void mimimi_linear_apply(struct mimimi_momentum *momentum, int *value, int x0, int scale)
12{
13	*value = momentum->x * scale / 256 + x0;
14}
15
16void mimimi_angular_propagate(struct mimimi_momentum *momentum, struct mimimi_position *position, int x0, int y0, int a0, int scale, int weight)
17{
18	int a, x, y, dx;
19	
20	x = position->x - x0;
21	y = position->y - y0;
22	a = mimimi_angle(x, y);
23	
24	dx = (a / 64 - a0) - momentum->x * scale / 256;
25	
26	dx = mimimi_mod(dx, 256);
27	if (dx > 128) dx = dx - 256;
28	momentum->dx += dx * weight / scale;
29}
30
31void mimimi_angular_apply(struct mimimi_momentum *momentum, struct mimimi_position *position, int x0, int y0, int a0, int scale, int length)
32{
33	int a, x, y;
34	
35	a = mimimi_mod(momentum->x * scale / 256 + a0, 256);
36	
37	x = mimimi_sine[a] * length / 128;
38	y = mimimi_cosine[a] * length / 128;
39	
40	position->x = x + x0;
41	position->y = y + y0;
42}