limit tickrate to half refresh rate
[d2d-md.git] / src / player.c
blobba7d69a0f79ec59444aad1113d33b5efb6a2d658
1 #include <genesis.h>
2 #include "thing.h"
3 #include "player.h"
4 #include "audio.h"
5 #include "utils.h"
6 #include "map.h"
7 #include "switch.h"
9 #define PLR_RUNVEL 8
10 #define PLR_JUMPVEL 10
11 #define PLR_SWIMVEL 4
13 u16 num_players = 1;
14 thing_t *th_player[2] = { NULL };
16 void plr_controls(thing_t *p, u16 btns) {
18 // noclip
19 if (btns & BUTTON_RIGHT) {
20 p->x += PLR_RUNVEL >> 3;
21 p->dir = 1;
22 p->ax = p->ay = 0;
23 p->vx = p->vy = 0;
24 } else if (btns & BUTTON_LEFT) {
25 p->x -= PLR_RUNVEL >> 3;
26 p->dir = -1;
27 p->ax = p->ay = 0;
28 p->vx = p->vy = 0;
31 if (btns & BUTTON_DOWN) {
32 p->y += PLR_RUNVEL >> 3;
33 p->ax = p->ay = 0;
34 p->vx = p->vy = 0;
35 } else if (btns & BUTTON_UP) {
36 p->y -= PLR_RUNVEL >> 3;
37 p->ax = p->ay = 0;
38 p->vx = p->vy = 0;
42 // walk
43 if ((btns & BUTTON_RIGHT) && p->ax < PLR_RUNVEL) {
44 p->ax += PLR_RUNVEL >> 3;
45 p->dir = 1;
46 } else if ((btns & BUTTON_LEFT) && p->ax > -PLR_RUNVEL) {
47 p->ax -= PLR_RUNVEL >> 3;
48 p->dir = -1;
49 } else if (p->ax) {
50 p->ax = Z_dec(p->ax, 1);
53 // jump or swim up
54 if (btns & BUTTON_B) {
55 if (p->flags & THF_INWATER)
56 p->ay = -PLR_SWIMVEL;
57 else if (p->flags & THF_ONGROUND)
58 p->ay = -PLR_JUMPVEL;
61 // shoot
62 if ((btns & BUTTON_A) && (g_ticker & 7) == 7) {
63 snd_play_sound(SFX_FIRE_PLASMA);
64 thing_t *th = thing_spawn(TH_TEST, p->x, p->y - 13, p->dir, p);
65 if (th) th->dir = p->dir;
68 // use
69 if ((btns & BUTTON_C) && (g_ticker & 7) == 7)
70 sw_use(p->x, p->y, p->def->r, p->def->h, SWF_PL_PRESS);