summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-05-29 15:02:23 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-05-29 15:02:23 +0200
commit08bc996d3673124bfb4221d5a7dc5b48a9ebbee4 (patch)
tree734ccbca4b207559f3ef035640739734a4d64ef2
parentdec532e0574dfc900d4693e78cf5a9b4c35be204 (diff)
Fixed underwater movement.
-rw-r--r--scene.cpp14
-rw-r--r--scene.h1
2 files changed, 10 insertions, 5 deletions
diff --git a/scene.cpp b/scene.cpp
index 059e2ca..491ec67 100644
--- a/scene.cpp
+++ b/scene.cpp
@@ -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);
diff --git a/scene.h b/scene.h
index 7b6808c..a3e2ee3 100644
--- a/scene.h
+++ b/scene.h
@@ -30,6 +30,7 @@ class Scene {
bool gravity;
bool dialog;
bool flying;
+ bool underwater;
Terrain::Node *last_node;