graphics.cpp: #include "/usr/include/irr/irrlicht.h" #include #include using namespace irr; using namespace scene; using namespace video; using namespace core; using namespace io; IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d(640, 480)); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); // ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(); // scene::ICameraSceneNode* // cam = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f); stringw title = "Some Game"; void render() { driver->beginScene(true, true, video::SColor(255,0,0,255)); smgr->drawAll(); device->setWindowCaption(title.c_str()); driver->endScene(); } class CMesh { protected: IAnimatedMeshSceneNode* meshnode; public: CMesh(const c8* file) { meshnode = smgr->addAnimatedMeshSceneNode(smgr->getMesh(file)); } IAnimatedMeshSceneNode* mesh() { // get mesh, SHOULD ONLY BE USED BY CGRAPHICS return meshnode; } void setPosition(int x, int y, int z) { vector3df lol(x,y,z); meshnode->setPosition(lol); } void setRotation(int x, int y, int z) { vector3df lol(x,y,z); meshnode->setRotation(lol); } void setScale(int x, int y, int z) { vector3df lol(x,y,z); meshnode->setScale(lol); } bool collision(CMesh *m, int size) { if(meshnode->getAbsolutePosition().getDistanceFrom(m->mesh()->getAbsolutePosition()) < size) return true; return false; } bool collision(ISceneNode* m, int size) { if(meshnode->getAbsolutePosition().getDistanceFrom(m->getAbsolutePosition()) < size) return true; return false; } vector3df getScale() { return meshnode->getScale(); } vector3df getPosition() { return meshnode->getPosition(); } vector3df getRotation() { return meshnode->getRotation(); } }; CMesh* LoadMap(const c8* zipArchive, const c8* map) { CMesh *m; // add .pk3 archive to the file system device->getFileSystem()->addZipFileArchive(zipArchive); // collide shit /*scene::ITriangleSelector* selector = 0; m->mesh()->setPosition(core::vector3df(-1370,-130,-1400)); selector = smgr->createOctTreeTriangleSelector( m->mesh()->getMesh(), m->mesh(), (s32)128); m->mesh()->setTriangleSelector(selector); selector->drop();*/ m = new CMesh(map); return m; }; Crapper.cpp: #include "graphics.cpp" class CMap { protected: CMesh *map; public: CMap() { map = // new CMesh("simpleMap.3ds"); LoadMap("map-20kdm2.pk3","20kdm2.bsp"); } CMesh *getMesh() { return map; } }; class CPlayer { protected: irr::scene::ICameraSceneNode *cam; // Irrlicht camera CMesh *eco; // current eco int bla; public: CPlayer() { bla = 0; cam = smgr->addCameraSceneNodeFPS(); } irr::scene::ICameraSceneNode *getCam() { return cam; } void setEco(CMesh *m) { eco = m; eco->setPosition(0,0,20); //eco->setScale(40,40,40); eco->mesh()->setParent(cam); printf("blablabla %d\n",bla); bla++; } void jump() { // to implement once gravity works // basically just set y+=35;, then // gravity will make you fall } }; class CEco { protected: CMesh *eco; int type; public: CEco(int t) { type = t; if(t == 1) // blue eco = new CMesh("blue_eco.3ds"); if(t == 2) // green eco = new CMesh("green_eco.3ds"); } void setPos(int x, int z) { eco->setPosition(x,15,z); } CMesh *getMesh() { return eco; } }; int main() { CMap *map = new CMap(); CEco *eco1 = new CEco(1); // blue CPlayer *p = new CPlayer(); eco1->setPos(15,15); while(device->run() && device) { if(eco1->getMesh()->collision(p->getCam(),110)) { // eco1->player collision? p->setEco(eco1->getMesh()); } render(); core::stringw str; str += "[Crapper v0.2] "; str += "[FPS: "; str += driver->getFPS(); str += "] "; device->setWindowCaption(str.c_str()); } };