player movement (to be cont.)
authorJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 15 Sep 2021 11:03:19 +0000 (14:03 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 15 Sep 2021 11:03:19 +0000 (14:03 +0300)
src/game.c
src/player.h

index 65c7636..a997b69 100644 (file)
@@ -51,8 +51,6 @@ int game_init(void)
        player.cx = lvl.px;
        player.cy = lvl.py;
 
-       printf("start pos: %d,%d\n", player.cx, player.cy);
-
        return 0;
 }
 
@@ -62,8 +60,38 @@ void game_shutdown(void)
        free_program(sdr_foo);
 }
 
+#define STEP_INTERVAL  1000
+
+void update(float dt)
+{
+       static long prev_step;
+       int step[][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
+
+       cgm_vec3 vdir = {0, 0, -1};
+
+       upd_player_xform(&player);
+       cgm_vmul_m3v3(&vdir, player.view_xform);
+
+       player.dir = (int)(2.0f * (atan2(vdir.z, vdir.x) + M_PI) / M_PI + 0.5f);
+
+       /*
+       if(time_msec - prev_step >= STEP_INTERVAL) {
+               if(input[INP_FWD]) {
+               }
+       }
+       */
+}
+
 void game_display(void)
 {
+       float dt;
+       static long prev_msec;
+
+       dt = (prev_msec - time_msec) / 1000.0f;
+       prev_msec = time_msec;
+
+       update(dt);
+
        glClearColor(0.1, 0.1, 0.1, 1);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
@@ -72,7 +100,6 @@ void game_display(void)
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(proj_matrix);
 
-       upd_player_xform(&player);
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(player.view_xform);
 
index d4d47b3..f7451c9 100644 (file)
@@ -13,6 +13,7 @@ struct player {
        cgm_vec3 vpos;          /* VR position within the cell */
        cgm_quat vrot;          /* VR orientation */
 
+       int dir;                        /* cardinal direction, clockwise, 0 is west */
        float height;
 
        /* view matrix, derived from all of the above by upd_player_xform */