-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper.c
60 lines (50 loc) · 1.3 KB
/
paper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "paper.h"
#include "paper_plane_icons.h"
void update_sprite_rotation(Paper* dest) {
switch(dest->rotation) {
case -3:
dest->icon = &I_PaperLeft3;
break;
case -2:
dest->icon = &I_PaperLeft2;
break;
case -1:
dest->icon = &I_PaperLeft1;
break;
case 0:
dest->icon = &I_PaperDown;
break;
case 1:
dest->icon = &I_PaperRight1;
break;
case 2:
dest->icon = &I_PaperRight2;
break;
case 3:
dest->icon = &I_PaperRight3;
break;
default:
break;
}
}
void rotate_left(Paper* dest) {
if(dest->rotation > PAPER_MIN_ROTATION) dest->rotation--;
update_sprite_rotation(dest);
}
void rotate_right(Paper* dest) {
if(dest->rotation < PAPER_MAX_ROTATION) dest->rotation++;
update_sprite_rotation(dest);
}
void paper_init(Paper* dest) {
dest->x = PAPER_START_X;
dest->rotation = 0;
dest->y = 0;
update_sprite_rotation(dest);
}
int get_gravity_from_rotation(int rotation) {
return -abs(rotation) + BASE_GRAVITY;
}
void update_position(Paper* dest, int delta_time_ms) {
dest->x += (float)dest->rotation * ROTATION_MULTIPLIER * delta_time_ms / 1000;
dest->y += (float)get_gravity_from_rotation(dest->rotation) * delta_time_ms / 1000;
}