starting to separate platform-specific code to facilitate a PC build
[gbajam22] / src / player.c
1 #include <string.h>
2 #include "player.h"
3 #include "level.h"
4 #include "gbaregs.h"
5 #include "xgl.h"
6
7 void init_player(struct player *p, struct level *lvl)
8 {
9         memset(p, 0, sizeof *p);
10         p->cx = lvl->orgx;
11         p->cy = lvl->orgy;
12         cell_to_pos(lvl, lvl->orgx, lvl->orgy, &p->x, &p->y);
13         p->cell = level_cell(lvl, lvl->orgx, lvl->orgy);
14 }
15
16 void player_input(struct player *p, uint16_t bnstate)
17 {
18         if(bnstate & KEY_UP) {
19                 p->phi += 0x800;
20                 if(p->phi > X_HPI) p->phi = X_HPI;
21         }
22         if(bnstate & KEY_DOWN) {
23                 p->phi -= 0x800;
24                 if(p->phi < -X_HPI) p->phi = -X_HPI;
25         }
26         if(bnstate & KEY_LEFT) {
27                 p->theta += 0x800;
28                 if(p->theta >= X_2PI) p->theta -= X_2PI;
29         }
30         if(bnstate & KEY_RIGHT) {
31                 p->theta -= 0x800;
32                 if(p->theta < 0) p->theta += X_2PI;
33         }
34         if(bnstate & KEY_A) {
35                 p->y += 0x2000;
36         }
37         if(bnstate & KEY_B) {
38                 p->y -= 0x2000;
39         }
40 }