diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-05-29 15:02:23 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-05-29 15:02:23 +0200 |
commit | 08bc996d3673124bfb4221d5a7dc5b48a9ebbee4 (patch) | |
tree | 734ccbca4b207559f3ef035640739734a4d64ef2 | |
parent | dec532e0574dfc900d4693e78cf5a9b4c35be204 (diff) |
Fixed underwater movement.
-rw-r--r-- | scene.cpp | 14 | ||||
-rw-r--r-- | scene.h | 1 |
2 files changed, 10 insertions, 5 deletions
@@ -21,6 +21,7 @@ Scene::Scene() { render_terrain = true; gravity = true; flying = true; + underwater = false; last_node = NULL; @@ -186,8 +187,8 @@ void Scene::events() { render_terrain = !render_terrain; break; case SDLK_SPACE: - if(!flying) { - yvel = .02; + if(!flying || underwater) { + yvel = underwater ? .005 : .02; flying = true; } break; @@ -338,7 +339,10 @@ void Scene::render() { if(node) { if(gravity) { float y = node->get_height(pos.x, pos.z); - if(pos.y > y && !keystate[SDLK_e]) + underwater = pos.y < 30 - 1.7; + if(pos.y < 30 - 1.5 || (pos.y < 30 - 1 && y < 30 - 1)) + yvel -= 9.81 / 2000000. * steps; + else if(pos.y > y && !keystate[SDLK_e]) yvel -= 9.81 / 200000. * steps; if(yvel < -.1) yvel = -.1; @@ -546,8 +550,8 @@ void Scene::render() { float height = font->LineHeight(); glColor3f(1, 1, 1); glTranslatef(0, video::height-height, 0); - font->Render((boost::format("chunks: %d cache: %d gravity: %d steps: %d") - % terrain->chunks.size() % terrain->tc->get_size() % gravity % steps).str().c_str()); + font->Render((boost::format("chunks: %d cache: %d gravity: %d flying: %d water: %d steps: %d") + % terrain->chunks.size() % terrain->tc->get_size() % gravity % flying % underwater % steps).str().c_str()); //font->Render((boost::format("%dx%d %d levels %d nodes tree creation time: %f steps: %d update: %d") // % scene.qt->width % scene.qt->height % scene.qt->levels % scene.qt->nodes % scene.qt->init_time % steps % scene.qt->thread_running).str().c_str()); //glTranslatef(0, height, 0); @@ -30,6 +30,7 @@ class Scene { bool gravity; bool dialog; bool flying; + bool underwater; Terrain::Node *last_node; |