ld33_umonster
diff src/game.cc @ 6:3b4460b34d43
progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 23 Aug 2015 05:37:09 +0300 |
parents | 93ff21458a16 |
children | 92d662deb66e |
line diff
1.1 --- a/src/game.cc Sun Aug 23 04:45:24 2015 +0300 1.2 +++ b/src/game.cc Sun Aug 23 05:37:09 2015 +0300 1.3 @@ -9,6 +9,7 @@ 1.4 #include "mesh.h" 1.5 1.6 #include "room.h" 1.7 +#include "dragon.h" 1.8 1.9 static void draw_scene(); 1.10 1.11 @@ -19,13 +20,18 @@ 1.12 1.13 unsigned int sdr_shadow, sdr_shadow_notex; 1.14 1.15 -static float cam_theta, cam_phi = 25, cam_dist = 8; 1.16 +static float cam_theta, cam_phi = 23, cam_dist = 26; 1.17 +static float cam_x, cam_y, cam_z = 9; 1.18 static bool bnstate[8]; 1.19 static int prev_x, prev_y; 1.20 +static bool gamectl = false; 1.21 1.22 static unsigned int modkeys; 1.23 1.24 1.25 +static Dragon dragon; 1.26 + 1.27 + 1.28 bool game_init() 1.29 { 1.30 if(init_opengl() == -1) { 1.31 @@ -65,6 +71,12 @@ 1.32 return false; 1.33 } 1.34 1.35 + dragon.set_position(Vector3(0, 5, 20)); 1.36 + dragon.set_direction(Vector3(0, 0, -1)); 1.37 + dragon.set_target(Vector3(0, 3, 0)); 1.38 + dragon.move_head(Vector3(0, 6, 10)); 1.39 + dragon.set_head_limits(-ROOM_WIDTH * 0.2, ROOM_WIDTH * 0.2, 1, ROOM_HEIGHT - 3); 1.40 + 1.41 Mesh::use_custom_sdr_attr = false; 1.42 1.43 assert(glGetError() == GL_NO_ERROR); 1.44 @@ -79,6 +91,8 @@ 1.45 void game_update(unsigned long time_msec) 1.46 { 1.47 cur_time = time_msec; 1.48 + 1.49 + dragon.update(); 1.50 } 1.51 1.52 void game_display() 1.53 @@ -90,12 +104,13 @@ 1.54 glTranslatef(0, 0.1, -cam_dist); 1.55 glRotatef(cam_phi, 1, 0, 0); 1.56 glRotatef(cam_theta, 0, 1, 0); 1.57 + glTranslatef(-cam_x, -cam_y, -cam_z); 1.58 1.59 - float lpos[] = {-5, 15, 10, 1}; 1.60 + float lpos[] = {0, 10, 24, 1}; 1.61 glLightfv(GL_LIGHT0, GL_POSITION, lpos); 1.62 1.63 if(opt.shadows && sdr_shadow) { 1.64 - begin_shadow_pass(Vector3(lpos[0], lpos[1], lpos[2]), Vector3(0, 0, 0), 10); 1.65 + begin_shadow_pass(Vector3(lpos[0], lpos[1], lpos[2]), Vector3(0, 0, 0), 45); 1.66 draw_scene(); 1.67 end_shadow_pass(); 1.68 1.69 @@ -142,6 +157,8 @@ 1.70 draw_teapot(); 1.71 1.72 glPopMatrix(); 1.73 + 1.74 + dragon.draw(); 1.75 } 1.76 1.77 1.78 @@ -161,6 +178,10 @@ 1.79 case 27: 1.80 quit(); 1.81 1.82 + case ' ': 1.83 + gamectl = !gamectl; 1.84 + break; 1.85 + 1.86 case 'w': 1.87 dbg_wireframe = !dbg_wireframe; 1.88 redisplay(); 1.89 @@ -170,6 +191,11 @@ 1.90 opt.shadows = !opt.shadows; 1.91 redisplay(); 1.92 break; 1.93 + 1.94 + case 'p': 1.95 + printf("camera pos(%g %g %g) rot(%g %g) d(%g)\n", 1.96 + cam_x, cam_y, cam_z, cam_theta, cam_phi, cam_dist); 1.97 + break; 1.98 } 1.99 } 1.100 } 1.101 @@ -204,6 +230,10 @@ 1.102 prev_x = x; 1.103 prev_y = y; 1.104 1.105 + if(gamectl) { 1.106 + dragon.move_head(dx * 0.1, -dy * 0.1); 1.107 + } 1.108 + 1.109 if(modkeys) { 1.110 if(bnstate[0]) { 1.111 cam_theta += dx * 0.5; 1.112 @@ -212,6 +242,19 @@ 1.113 if(cam_phi < -90) cam_phi = -90; 1.114 if(cam_phi > 90) cam_phi = 90; 1.115 } 1.116 + if(bnstate[1]) { 1.117 + float theta = DEG_TO_RAD(cam_theta); 1.118 + 1.119 + float dxp = dx * 0.1; 1.120 + float dyp = dy * 0.1; 1.121 + 1.122 + cam_x += cos(theta) * dxp - sin(theta) * dyp; 1.123 + if(modkeys & (1 << MOD_SHIFT)) { 1.124 + cam_y -= sin(theta) * dxp + cos(theta) * dyp; 1.125 + } else { 1.126 + cam_z += sin(theta) * dxp + cos(theta) * dyp; 1.127 + } 1.128 + } 1.129 if(bnstate[2]) { 1.130 cam_dist += dy * 0.1; 1.131 if(cam_dist < 0.0) cam_dist = 0.0;