X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrtris;a=blobdiff_plain;f=src%2Fgamescr.c;h=d2e021937f00912792e989e92c082678b740c716;hp=66aa1fe865250966532e73ef9f6e667eec24cf7c;hb=325391b617a3f5a1f17e03598baa66d00715422d;hpb=257b041b5f6f64b53bafe5b4d4f8ffa67a39c0e5 diff --git a/src/gamescr.c b/src/gamescr.c index 66aa1fe..d2e0219 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -2,12 +2,14 @@ #include #include #include +#include #include "opengl.h" #include "game.h" #include "screen.h" #include "cmesh.h" #include "blocks.h" #include "logger.h" +#include "gameinp.h" int init_starfield(void); void draw_starfield(void); @@ -144,17 +146,89 @@ static void start(void) next_block = rand() % NUM_BLOCKS; memset(pfield, 0, PF_COLS * PF_ROWS * sizeof *pfield); + + ginp_repeat(500, 75, GINP_LEFT | GINP_RIGHT | GINP_DOWN); } static void stop(void) { } +#define JTHRES 0.6 + +#define CHECK_BUTTON(idx, gbn) \ + if(joy_bnstate & (1 << idx)) { \ + ginp_bnstate |= gbn; \ + } + +static void update_input(float dtsec) +{ + int num_vr_sticks; + + if((num_vr_sticks = goatvr_num_sticks()) > 0) { + float p[2]; + + goatvr_stick_pos(0, p); + + if(fabs(p[0]) > fabs(joy_axis[GPAD_LSTICK_X])) { + joy_axis[GPAD_LSTICK_X] = p[0]; + } + if(fabs(p[1]) > fabs(joy_axis[GPAD_LSTICK_Y])) { + joy_axis[GPAD_LSTICK_Y] = p[1]; + } + } + + ginp_bnstate = 0; + + /* joystick axis */ + if(joy_axis[GPAD_LSTICK_X] >= JTHRES) { + ginp_bnstate |= GINP_RIGHT; + } else if(joy_axis[GPAD_LSTICK_X] <= -JTHRES) { + ginp_bnstate |= GINP_LEFT; + } + + if(joy_axis[GPAD_LSTICK_Y] >= JTHRES) { + ginp_bnstate |= GINP_DOWN; + } else if(joy_axis[GPAD_LSTICK_Y] <= -JTHRES) { + ginp_bnstate |= GINP_UP; + } + + CHECK_BUTTON(GPAD_LEFT, GINP_LEFT); + CHECK_BUTTON(GPAD_RIGHT, GINP_RIGHT); + CHECK_BUTTON(GPAD_UP, GINP_UP); + CHECK_BUTTON(GPAD_DOWN, GINP_DOWN); + CHECK_BUTTON(GPAD_A, GINP_ROTATE); + CHECK_BUTTON(GPAD_START, GINP_PAUSE); + + update_ginp(); + + if(GINP_PRESS(GINP_LEFT)) { + game_keyboard('a', 1); + } + if(GINP_PRESS(GINP_RIGHT)) { + game_keyboard('d', 1); + } + if(GINP_PRESS(GINP_DOWN)) { + game_keyboard('s', 1); + } + if(GINP_PRESS(GINP_UP)) { + game_keyboard('\t', 1); + } + if(GINP_PRESS(GINP_ROTATE)) { + game_keyboard('w', 1); + } + if(GINP_PRESS(GINP_PAUSE)) { + game_keyboard('p', 1); + } +} + static void update(float dtsec) { static long prev_tick; long dt; + update_input(dtsec); + if(pause) { prev_tick = time_msec; return;