But I'm trying to just piece together different parts of code to see if I can figure out how stuff works here.
What I've done is:
Started with the terrain-rendering tutorial code, changed around heightmap, textures and scales a bit, tried to use code I found here on the forum to enable jumping with spacebar, tried to use code from the collision tutorial for adding a billboard for HUD, and tried to use code from the demo coming with Irrlicht for shooting.
First, here comes all of my EventReceiver code:
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(scene::ISceneNode* terrain)
{
// store pointer to terrain so we can change its drawing mode
Terrain = terrain;
}
bool OnEvent(SEvent event)
{
// check if user presses the key 'B', 'N' or 'M'
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
{
switch (event.KeyInput.Key)
{
case irr::KEY_KEY_B: // switch wire frame mode
Terrain->setMaterialFlag(video::EMF_WIREFRAME, !Terrain->getMaterial(0).Wireframe);
Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false);
return true;
case irr::KEY_KEY_N: // switch wire frame mode
Terrain->setMaterialFlag(video::EMF_POINTCLOUD, !Terrain->getMaterial(0).PointCloud);
Terrain->setMaterialFlag(video::EMF_WIREFRAME, false);
return true;
case irr::KEY_KEY_M: // toggle detail map
Terrain->setMaterialType(
Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ?
video::EMT_DETAIL_MAP : video::EMT_SOLID);
return true;
}
}
// jumping with spacebar
if(event.EventType == EET_KEY_INPUT_EVENT &&
!event.KeyInput.PressedDown && event.KeyInput.Key == KEY_SPACE)
{
vector3df pos = playernode->getPosition();
playernode->setPosition(vector3df(pos.X,pos.Y+20,pos.Z));
return true;
}
// Shooting with left mouse button
else
if ((event.EventType == EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP))
/*
Disabled the currentScene part below since I have no nextScene stuff and am not sure what it even does :P
&&
currentScene == 3)
*/
{
// shoot
shoot();
}
return false;
}
private:
scene::ISceneNode* Terrain;
void shoot();
void createParticleImpacts();
};
Code: Select all
// For jumping
vector3df pos = playerNode->getPosition();
posx = pos.X;
posy = pos.Y;
posz = pos.Z;