1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Display which tool the player is holding

And some simple animation when trying to dig...
This commit is contained in:
JacobF 2011-09-07 10:56:04 -04:00
parent 5c1074aa7d
commit f31b0a3361
6 changed files with 137 additions and 30 deletions

View file

@ -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)
{
@ -972,6 +975,44 @@ void the_game(
f32 camera_yaw = 0; // "right/left"
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)