6c97e38dd2fad2338034c3cff83453c5e646b5c2
[gbajam22] / src / player.c
1 #include <string.h>
2 #include "game.h"
3 #include "player.h"
4 #include "level.h"
5 #include "gbaregs.h"
6 #include "xgl.h"
7
8 void init_player(struct player *p, struct level *lvl)
9 {
10         memset(p, 0, sizeof *p);
11         p->cx = lvl->orgx;
12         p->cy = lvl->orgy;
13         cell_to_pos(lvl, lvl->orgx, lvl->orgy, &p->x, &p->y);
14         p->cell = level_cell(lvl, lvl->orgx, lvl->orgy);
15 }
16
17 void player_input(struct player *p, uint16_t bnstate)
18 {
19 #ifndef BUILD_GBA
20         p->theta = (p->theta + view_dtheta) % X_2PI;
21         if(p->theta < 0) p->theta += X_2PI;
22         p->phi += view_dphi;
23         if(p->phi > X_HPI) p->phi = X_HPI;
24         if(p->phi < -X_HPI) p->phi = -X_HPI;
25
26         view_dtheta = 0;
27         view_dphi = 0;
28 #endif
29
30         if(bnstate & KEY_UP) {
31                 p->phi += 0x800;
32                 if(p->phi > X_HPI) p->phi = X_HPI;
33         }
34         if(bnstate & KEY_DOWN) {
35                 p->phi -= 0x800;
36                 if(p->phi < -X_HPI) p->phi = -X_HPI;
37         }
38         if(bnstate & KEY_LEFT) {
39                 p->theta += 0x800;
40                 if(p->theta >= X_2PI) p->theta -= X_2PI;
41         }
42         if(bnstate & KEY_RIGHT) {
43                 p->theta -= 0x800;
44                 if(p->theta < 0) p->theta += X_2PI;
45         }
46         if(bnstate & KEY_A) {
47                 p->y += 0x2000;
48         }
49         if(bnstate & KEY_B) {
50                 p->y -= 0x2000;
51         }
52 }