Added comments
This commit is contained in:
parent
55f9b8b4f2
commit
9600522e10
23
src/main.cpp
23
src/main.cpp
@ -10,32 +10,42 @@ int main() {
|
||||
video::E_DRIVER_TYPE driverType = driverChoiceConsole();
|
||||
if(driverType == video::EDT_COUNT) return 1;
|
||||
|
||||
// Create eventReceiver variable
|
||||
EventReceiver eventReceiver;
|
||||
|
||||
// Create the device we'll be using
|
||||
IrrlichtDevice *device = createDevice(driverType, core::dimension2d<u32>(1280, 720), 32, true, false, false, &eventReceiver);
|
||||
if(device == 0) return 1;
|
||||
|
||||
// Create other variables we'll need
|
||||
video::IVideoDriver *driver = device->getVideoDriver();
|
||||
scene::ISceneManager *smgr = device->getSceneManager();
|
||||
gui::IGUIEnvironment *guienv = device->getGUIEnvironment();
|
||||
|
||||
// Add text to game
|
||||
guienv->addStaticText(L"Use WASD to move\nUse SPACE to jump\nUse ESC to exit", core::rect<s32>(30, 30, 120, 65), false, false, 0, -1, true);
|
||||
|
||||
// Load map
|
||||
device->getFileSystem()->addFileArchive("../res/map-20kdm2.pk3");
|
||||
scene::IAnimatedMesh *mapmesh = smgr->getMesh("20kdm2.bsp");
|
||||
scene::IMeshSceneNode *mapnode = 0;
|
||||
|
||||
if(mapmesh) {
|
||||
mapnode = smgr->addOctreeSceneNode(mapmesh->getMesh(0));
|
||||
// Create map octree node
|
||||
mapnode = smgr->addOctreeSceneNode(mapmesh->getMesh(0), 0, -1, 2048);
|
||||
}
|
||||
// Create Triangle selector for collision
|
||||
scene::ITriangleSelector *tselector = 0;
|
||||
if(mapnode) {
|
||||
// Set map position
|
||||
mapnode->setPosition(core::vector3df(-1350, -130, -1400));
|
||||
// Define triangle selector
|
||||
tselector = smgr->createOctreeTriangleSelector(mapnode->getMesh(), mapnode, 128);
|
||||
// Set the mapnode's triangle selector
|
||||
mapnode->setTriangleSelector(tselector);
|
||||
}
|
||||
|
||||
// Setup new keys
|
||||
// Setup new keys (not using default)
|
||||
SKeyMap keyMap[6];
|
||||
keyMap[0].Action = EKA_MOVE_FORWARD;
|
||||
keyMap[0].KeyCode = KEY_KEY_W;
|
||||
@ -48,6 +58,7 @@ int main() {
|
||||
keyMap[4].Action = EKA_JUMP_UP;
|
||||
keyMap[4].KeyCode = KEY_SPACE;
|
||||
|
||||
// Create camera
|
||||
scene::ICameraSceneNode *cam = smgr->addCameraSceneNodeFPS(0, 100.0f, .3f, -1, keyMap, sizeof(keyMap) / sizeof(*keyMap), true, 3.0f);
|
||||
cam->setPosition(core::vector3df(50, 50, -60));
|
||||
cam->setTarget(core::vector3df(-70, 30, -60));
|
||||
@ -58,27 +69,33 @@ int main() {
|
||||
cam->addAnimator(sanim);
|
||||
sanim->drop();
|
||||
}
|
||||
// Hide cursor
|
||||
device->getCursorControl()->setVisible(false);
|
||||
|
||||
int lastFPS = -1;
|
||||
|
||||
while(device->run()) {
|
||||
// Begin the scene
|
||||
driver->beginScene(true, true, video::SColor(0, 255, 101, 255));
|
||||
// Draw
|
||||
smgr->drawAll();
|
||||
guienv->drawAll();
|
||||
// End the scene
|
||||
driver->endScene();
|
||||
// Check for ESC key
|
||||
if(eventReceiver.IsKeyDown(KEY_ESCAPE)) {
|
||||
device->closeDevice();
|
||||
}
|
||||
|
||||
// Print FPS
|
||||
int fps = driver->getFPS();
|
||||
|
||||
if(lastFPS != fps) {
|
||||
std::cout << "FPS: " << fps << std::endl;
|
||||
lastFPS = fps;
|
||||
}
|
||||
}
|
||||
|
||||
// Drop the device and quit
|
||||
device->drop();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user