aboutsummaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorJacobF <queatz@gmail.com>2011-09-07 10:56:04 -0400
committerJacobF <queatz@gmail.com>2011-09-07 10:56:04 -0400
commitf31b0a3361c0c39b9f6f6ee440b93293690bbe02 (patch)
tree126e984c14fd67d53c257f98f2acfc22ee7c32e4 /src/game.cpp
parent5c1074aa7d568169ab79574b20cd8978ae95cb36 (diff)
downloadminetest-f31b0a3361c0c39b9f6f6ee440b93293690bbe02.tar.gz
minetest-f31b0a3361c0c39b9f6f6ee440b93293690bbe02.tar.bz2
minetest-f31b0a3361c0c39b9f6f6ee440b93293690bbe02.zip
Display which tool the player is holding
And some simple animation when trying to dig...
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp
index dc3ed2456..86f1939c3 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -956,7 +956,10 @@ void the_game(
v3f(BS*100, BS*2, BS*100), // Look from
v3f(BS*100+1, BS*2, BS*100), // Look to
-1 // Camera ID
- );
+ );
+
+ // Do this so children rotate accordingly (tool)
+ camera->bindTargetAndRotation(true);
if(camera == NULL)
{
@@ -973,6 +976,44 @@ void the_game(
f32 camera_pitch = 0; // "up/down"
/*
+ Tool
+ */
+
+ v3f tool_wield_position(0.6, -0.6, 1.0);
+ v3f tool_wield_rotation(-25, 180, -25);
+ float tool_wield_animation = 0.0;
+ scene::IMeshSceneNode *tool_wield;
+ {
+ scene::SMesh *mesh = new scene::SMesh();
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[4] =
+ {
+ video::S3DVertex(-0.5,0,0, 0,0,0, c, 0,1),
+ video::S3DVertex(0.5,0,0, 0,0,0, c, 1,1),
+ video::S3DVertex(0.5,0.5,0, 0,0,0, c, 1,0),
+ video::S3DVertex(-0.5,0.5,0, 0,0,0, c, 0,0),
+ };
+ u16 indices[] = {0,1,2,2,3,0};
+ buf->append(vertices, 4, indices, 6);
+ // Set material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ // Add to mesh
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+
+ tool_wield = smgr->addMeshSceneNode(mesh, camera);
+ mesh->drop();
+ }
+ tool_wield->setVisible(false);
+ tool_wield->setPosition(tool_wield_position);
+ tool_wield->setRotation(tool_wield_rotation);
+
+ client.setPlayerWield(tool_wield);
+
+ /*
Clouds
*/
@@ -1920,6 +1961,7 @@ void the_game(
}
}
+
if(input->getRightClicked())
{
std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
@@ -1986,6 +2028,14 @@ void the_game(
else{
}
+
+ if(input->getLeftState())
+ // Tool animation loops 0.0 - 1.0
+ tool_wield_animation = fmod(tool_wield_animation + dtime * 3.0, 1.0);
+ else
+ // Return tool to holding position if not digging
+ tool_wield_animation /= 1.5;
+
} // selected_object == NULL
input->resetLeftClicked();
@@ -2103,6 +2153,14 @@ void the_game(
);
}
+ /*
+ Animate tool
+ */
+ {
+ tool_wield->setRotation(tool_wield_rotation - sin(tool_wield_animation * PI) * 40.0);
+ tool_wield->setPosition(tool_wield_position - sin(tool_wield_animation * PI) / 3.0);
+ }
+
/*
Update gui stuff (0ms)