X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgamescr.c;h=d2e021937f00912792e989e92c082678b740c716;hb=325391b617a3f5a1f17e03598baa66d00715422d;hp=4fd0b2ba8738025cf8cf081cb86ac7ae2efe2249;hpb=49c9842d3766ebb1b3a67f41774c188e7bc1ae95;p=vrtris diff --git a/src/gamescr.c b/src/gamescr.c index 4fd0b2b..d2e0219 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -2,12 +2,17 @@ #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); static int init(void); static void cleanup(void); @@ -82,9 +87,26 @@ static const long level_speed[NUM_LEVELS] = { 167, 151, 134, 117, 107, 98, 88, 79, 69, 60, 50 }; +static const float blkcolor[][4] = { + {1.0, 0.65, 0.0, 1}, + {0.16, 1.0, 0.4, 1}, + {0.65, 0.65, 1.0, 1}, + {1.0, 0.9, 0.1, 1}, + {0.0, 1.0, 1.0, 1}, + {1.0, 0.5, 1.0, 1}, + {1.0, 0.35, 0.2, 1}, + {0.5, 0.5, 0.5, 1} +}; + +#define GAMEOVER_FILL_RATE 50 + static int init(void) { + if(init_starfield() == -1) { + return -1; + } + if(!(blkmesh = cmesh_alloc()) || cmesh_load(blkmesh, "data/noisecube.obj") == -1) { error_log("failed to load block mesh\n"); return -1; @@ -106,6 +128,8 @@ static int init(void) static void cleanup(void) { cmesh_free(blkmesh); + cmesh_free(wellmesh); + glDeleteTextures(1, &tex_well); } static void start(void) @@ -122,27 +146,98 @@ 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; } dt = time_msec - prev_tick; - /* if(gameover) { int i, row = PF_ROWS - gameover; - int *ptr; + unsigned int *ptr; if(dt < GAMEOVER_FILL_RATE) { return; @@ -151,15 +246,14 @@ static void update(float dtsec) if(row >= 0) { ptr = pfield + row * PF_COLS; for(i=0; i= 0 && !just_spawned && !pause) { next_pos[0] = pos[0] + 1; @@ -330,6 +445,7 @@ static void keyboard(int key, int pressed) case '\n': case '\t': + case '0': if(!pause && cur_block >= 0) { next_pos[0] = pos[0] + 1; while(!collision(cur_block, next_pos)) {