in the "//begin key press" all the way down "//end key press" is the key press code
Code: Select all
#include <irrlicht.h>
#include <iostream>
#include <audiere.h>
#include <stdio.h>
#include <windows.h>
#include "newton.h"
static NewtonWorld* nWorld;
using namespace irr;
using namespace core;
using namespace scene;
using namespace audiere;
using namespace video;
using namespace io;
using namespace gui;
int main()
{
//begin key press
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(scene::IAnimatedMeshSceneNode* player_node)
{
Player_node = player_node;
}
bool OnEvent(SEvent event)
{
if(event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_KEY_W &&
event.KeyInput.PressedDown == false)
{
Player_node->setMD2Animation(scene::EMAT_RUN);
}
return false;
}
private:
scene::IAnimatedMeshSceneNode* Player_node;
};
//end key press
//Init Audiere Audio
AudioDevicePtr audiereDevice;
OutputStreamPtr stream;
audiereDevice = OpenDevice();
if (!audiereDevice)
return 1;
stream = OpenSound(audiereDevice.get(), "data/music/track6.ogg", true);
if (!stream)
return 2;
stream->setRepeat(true);
stream->setVolume(1.0f); // 50% volume
stream->play();
//End Audiere Audio
//Game
nWorld = NewtonCreate (NULL, NULL);
IrrlichtDevice *device =
createDevice(EDT_OPENGL, core::dimension2d<s32>(1024, 768), 32,
false, false, true, 0);
if (device == 0)
return 1;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
//Player and Cam Create
IAnimatedMesh* mesh = smgr->getMesh("data/models/cyborg/player.md2");
IAnimatedMeshSceneNode* player_node = smgr->addAnimatedMeshSceneNode( mesh );
if (player_node)
{
player_node->setMaterialFlag(EMF_LIGHTING, false);
player_node->setMD2Animation ( scene::EMAT_STAND);
player_node->setMaterialTexture( 0, driver->getTexture("data/models/cyborg/player.pcx") );
}
scene::ICameraSceneNode * camera;
camera = smgr->addCameraSceneNode(0, vector3df(-70,50,0), vector3df(0,0,0));
//End PLayer and Cam Create
//wep
mesh = smgr->getMesh("data/weapons/cyborg/w_bfg.md2");
IAnimatedMeshSceneNode * gun_node = smgr->addAnimatedMeshSceneNode(mesh);
if(gun_node)
{
gun_node->setParent(player_node);
gun_node->setMD2Animation ( scene::EMAT_STAND);
gun_node->setPosition(core::vector3df(0,-4,-2));
//end wep
// map
device->getFileSystem()->addZipFileArchive("data/maps/maps.pk3");
scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* q3node = 0;
if (q3levelmesh)
q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));smgr->addOctTreeSceneNode(smgr->getMesh("20kdm2.bsp"));
scene::ITriangleSelector* selector = 0;
if (q3node)
{
q3node->setPosition(core::vector3df(-1370,-130,-1400));
selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
q3node->setTriangleSelector(selector);
selector->drop();
}
//end map
//Irrlicht Logo
guienv->addImage(driver->getTexture("irrQUAKE.png"),
core::position2d<s32>(5,5));
//Irrlicht Logo End
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
camera->setTarget(player_node->getPosition());
camera->updateAbsolutePosition();
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"irrQuake: Quake irrlicht style [ FPS:";
str += fps;
str += "]";
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
}
// End Game