3 void init_player(struct player *p)
5 memset(p, 0, sizeof *p);
6 cgm_qcons(&p->vrot, 0, 0, 0, 1);
9 p->hp = p->hp_max = 10;
10 p->mp = p->mp_max = 10;
13 #define TWO_PI ((float)M_PI * 2.0f)
14 #define HALF_PI ((float)M_PI / 2.0f)
16 void update_player_dir(struct player *p)
21 /* TODO: take vrot into account */
22 angle = fmod(p->theta, TWO_PI);
23 if(angle < 0) angle += TWO_PI;
25 p->theta = angle; /* renormalize theta */
26 p->dir = (int)(4.0f * angle / TWO_PI + 0.5) & 3;
29 void move_player(struct player *p, int right, int fwd)
31 static const int step[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
38 rdir = (fdir + 1) & 3;
39 p->cx += step[fdir][0] * fwd + step[rdir][0] * right;
40 p->cy += step[fdir][1] * fwd + step[rdir][1] * right;
43 void turn_player(struct player *p, int turn)
47 p->theta += turn > 0 ? HALF_PI : -HALF_PI;
50 p->theta = (float)p->dir * HALF_PI; /* snap theta */
53 void upd_player_xform(struct player *p)
56 float celld = p->lvl ? p->lvl->cell_size : DEF_CELL_SIZE;
58 cgm_vcons(&pos, p->cx * celld, p->height, -p->cy * celld);
59 cgm_vadd(&pos, &p->cpos);
61 cgm_midentity(p->view_xform);
62 cgm_mprerotate_x(p->view_xform, -p->phi);
63 cgm_mprerotate_y(p->view_xform, p->theta);
64 cgm_mrotate_quat(p->view_xform, &p->vrot);
65 cgm_mpretranslate(p->view_xform, -pos.x, -pos.y, -pos.z);
68 void upd_player_vis(struct player *p)