ISceneNode* ArrowPrototypeFactory::getArrowPrototype(unsigned char type, float offset) { ISceneNode* newArrow = prototypes[type]->clone(parent, smgr); newArrow->setVisible(true); //if (offest != 0.0) { newArrow->setPosition( vector3df(newArrow->getPosition().X, ARROW_HEIGHT - offset, newArrow->getPosition().Z)); // printf ("offset is %f. \n", offset); //} return newArrow; }
//----------------------------------------------------------------------- Bool CCSEntityLineMoveAcion::isNeedMoveToStartPos() { if ( !mEntity ) return false; if ( !mEntity->getEntity() ) return false ; ISceneNode* sceneNode = mEntity->getEntity()->getSceneNode(); if( !sceneNode ) { return false ; } Vec3 currPos; sceneNode->getPosition(currPos); Vec3 ec = mEndPos - currPos; Vec3 es = mEndPos - mStartPos; ec.y = 0; es.y = 0; Flt currDis = ec.length(); Flt dis = es.length(); if ( currDis > dis ) return true; return false; }
void LayerNode::render() { video::IVideoDriver* driver = SceneManager->getVideoDriver(); ISceneNode* cameraNode = SceneManager->getActiveCamera(); core::matrix4 mxTrans = cameraNode->getAbsoluteTransformation(); core::vector3df vCamPos = cameraNode->getPosition(); core::vector3df vCamScale = cameraNode->getScale(); core::vector3df vCamRot = cameraNode->getRotation(); //Zoom factor: for Factor=0, zoom = 1; for Factor=1, zoom = vCamScale; vCamScale.X = 1 - ( (1 - vCamScale.X) * m_paraxZoomFactor ); vCamScale.Y = 1 - ( (1 - vCamScale.Y) * m_paraxZoomFactor ); core::vector3df vCamPos2 = cameraNode->getPosition(); // Apply Offset core::vector3df vOffset(m_offsetX, m_offsetY, 0); // Apply parallax factor vCamPos2.X *= m_paraxFactorX; vCamPos2.Y *= m_paraxFactorY; mxTrans = core::matrix4().setTranslation(vCamPos)* core::matrix4().setScale(vCamScale)* core::matrix4().setTranslation(-vCamPos)* core::matrix4().setRotationDegrees(vCamRot)* core::matrix4().setTranslation(-vCamPos)* // remove camera offset because is applied automatically later by Irrlicht core::matrix4().setTranslation(vOffset)* // apply offset without parallax factor to make easy to adjust layer core::matrix4().setTranslation(vCamPos2) // then apply modified by parallax factor camera position ; driver->setMaterial(Material); driver->setTransform(video::ETS_WORLD, mxTrans*AbsoluteTransformation); Drawing::draw2DImage( driver, m_texture, core::recti( 0, 0, m_width, m_height), core::IdentityMatrix, true, video::SColor(255, 255, 255, 255)); }
void ActionManager::checkForCapture(){ //if one of the enemies gets the destination you lose for(unsigned int i = 0; i < craftPool.size(); i++) if(craftPool[i]->isMoveFinished()){ craftPool[i]->remove();//remove it from scene delete craftPool[i]; craftPool.erase(i); //remove it from pool ISceneNode* fighter = device->getSceneManager()->getSceneNodeFromId(NEWGAME_ELEMENT::NEWGAME_FIGHTER); fighter->setVisible(false); createExplosion(fighter->getPosition(), 12); gameOver(); } }
int Java_zte_irrlib_scene_SceneNode_nativeUpdatePosition( JNIEnv* env, jobject defaultObj, jobject jvec, jboolean isAbsolute, jint Id) { ISceneNode* node = smgr->getSceneNodeFromId(Id); if (!node) { WARN_NODE_NOT_FOUND(Id, UpdatePosition); return -1; } if (isAbsolute) { node->updateAbsolutePosition(); utils->setVector3dFromvector3df(env, jvec, node->getAbsolutePosition()); } else utils->setVector3dFromvector3df(env, jvec, node->getPosition()); return 0; }
void ActionManager::collisionProjectileVsCraft(){ //check for collisions between crafts and projectiles for(unsigned int i = 0; i < craftPool.size(); i++) for(unsigned int j = 0; j < projectilePool.size(); j++) if(collisionCheck(craftPool[i]->getSceneNode(), projectilePool[j]->getAnimatedMeshSceneNode())){ ISceneNode* craftNode = 0; if(craftPool[i]->getSceneNode()->getID() < ENEMY_CRAFT_THRESHOLD) //define type of craft whether it is enemy or not craftNode = craftPool[i]->getSceneNode(); ISceneNode* projectileNode = (ISceneNode*)projectilePool[j]->getAnimatedMeshSceneNode(); if(craftNode && projectileNode){ createExplosion(craftNode->getPosition(), 12); craftPool[i]->remove(); //remove craft delete craftPool[i]; //release its memory craftPool.erase(i); //remove from active pool projectilePool[j]->remove(); //remove projectile delete projectilePool[j]; projectilePool.erase(j); updateScore(10); } } }
// ---------------------------------------------------------------------------- void Track::exportElements(std::ofstream& stream, bool obj) { ISceneManager* sm = Editor::getEditor()->getSceneManager(); ISceneNode* node; stringc name; int i = 1; while ((node = sm->getSceneNodeFromId(MAGIC_NUMBER + i))) { name = node->getName(); vector3df pos, rot, sca; if (node->isVisible() && name != "banana" && name != "item" && name != "small-nitro" && name != "big-nitro" && (name.equalsn("obj/", 4) == obj)) { pos = node->getPosition(); rot = node->getRotation(); sca = node->getScale(); if (name.equalsn("obj/", 4)) { stream << " <static-object model=\"" << Editor::toRelative(name).c_str(); copyObj(name); ITexture* tex; for (int j = 0; (tex = node->getMaterial(0).getTexture(j)); j++) copyObj(stringc("obj/") + Editor::toRelative(tex->getName())); } // export as static-object else { stream << " <library name=\"" << Editor::getLib(node->getName()).c_str(); } // export as library stream << "\" xyz=\""; stream << pos.X << " " << pos.Y << " " << pos.Z << "\" hpr=\""; stream << rot.X << " " << rot.Y << " " << rot.Z << "\" scale=\""; stream << sca.X << " " << sca.Y << " " << sca.Z << "\"/>\n"; } i++; } } // exportElements
void ActionManager::collisionCraftVsCraft(){ for(unsigned int i = 0; i < craftPool.size(); i++) for(unsigned int j = i + 1; j < craftPool.size(); j++) if(collisionCheck(craftPool[i]->getSceneNode(), craftPool[j]->getSceneNode())){ ISceneNode* fighter; ISceneNode* craft; bool isFighter = false; if(craftPool[i]->getSceneNode()->getID() == NEWGAME_ELEMENT::NEWGAME_FIGHTER){ fighter = craftPool[i]->getSceneNode(); craft = craftPool[j]->getSceneNode(); isFighter = true; } else if (craftPool[j]->getSceneNode()->getID() == NEWGAME_ELEMENT::NEWGAME_FIGHTER){ fighter = craftPool[j]->getSceneNode(); craft = craftPool[i]->getSceneNode(); isFighter = true; } if(isFighter){ craft->setVisible(false); fighter->setVisible(false); createExplosion(fighter->getPosition(), 12); gameOver(); } } }
int main() { srand(time(NULL)); int numPlayers = 4; //Setup irrlicht MyEventReceiver Receiver; IrrlichtDevice *device = createDevice(EDT_OPENGL,dimension2d<u32>(SCREENX,SCREENY),32,FULLSCREEN,false,false,&Receiver); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); //Load key config Receiver.KeyConfig.loadFromFile("KeyConfig.txt"); //Generate maze MazeGenerator MG; /* MG.NewSize(495,497,495,497); MG.Generate("DrunkenWalk2",500,numPlayers);//500,numPlayers); MG.Minimise(); MG.MinimalSolids(false); MG.ConvertLoneToCover();*/ MG.MapFromFile("Maps/01g.txt", "Maps/01m.txt", "Maps/01e.txt"); vector<int> PlayerStartPos; PlayerStartPos.push_back(10); PlayerStartPos.push_back(11); PlayerStartPos.push_back(12); PlayerStartPos.push_back(13); MG.ParseForPlayerStartPositions(PlayerStartPos); //Setup textures ITexture *FloorTexture = driver->getTexture("Textures/Floor.png"); ITexture *WallTexture = driver->getTexture("Textures/Wall.png"); ITexture *CoverTexture = driver->getTexture("Textures/Cover.png"); //Import maze MazeRenderer MR; MR.CreateFromMazeGenerator( MG, smgr ); MR.SetTextures( FloorTexture, WallTexture, CoverTexture ); //Setup camera GameCamera gameCam(70); gameCam.camera = smgr->addCameraSceneNode(); gameCam.camera->setPosition( vector3df( (MR.XSize/2)*MR.TileSize, 40, (MR.YSize/2)*MR.TileSize ) ); gameCam.camera->setRotation( vector3df(0,90,90)); //Create players (4) for testing //Have to use an array as you can't copy boost::threads which pushing into vectors does EntityManager PlayerManager(numPlayers); //Textures ITexture* PlayerTexture[4]; PlayerTexture[0] = driver->getTexture("Textures/Player1.png"); PlayerTexture[1] = driver->getTexture("Textures/Player2.png"); PlayerTexture[2] = driver->getTexture("Textures/Player3.png"); PlayerTexture[3] = driver->getTexture("Textures/Player4.png"); //Names vector<std::string> PlayerName; PlayerName.push_back("Motoko"); PlayerName.push_back("Saito"); PlayerName.push_back("Batou"); PlayerName.push_back("Togusa"); //use this method to get starting cells for an enemy group vector<v2d> vv = GetFreeCells(MG.Convert(),MG.StartX,MG.StartY,4); //HUD test hud HUD(guienv,dimension2d<s32>(SCREENX,SCREENY),"Font\\myfont.xml"); for (int i = 0; i < numPlayers; i++ ) { PlayerManager.GetEntity(i)->Construct(smgr,MG.Convert(), PlayerTexture[i]); PlayerManager.GetEntity(i)->Stats.Name = PlayerName[i]; PlayerManager.GetEntity(i)->Stats.MaxHealth = 100; PlayerManager.GetEntity(i)->Stats.RestoreAll(); PlayerManager.GetEntity(i)->X = MG.XStarts[i]; PlayerManager.GetEntity(i)->Y = MG.YStarts[i]; PlayerManager.GetEntity(i)->Stats.MovementSteps = 5+i; PlayerManager.GetEntity(i)->ReachableTile = driver->getTexture("Textures/TurnReachable.png"); PlayerManager.GetEntity(i)->UnreachableTile = driver->getTexture("Textures/TurnUnreachable.png"); PlayerManager.GetEntity(i)->Stats.RealFiringDistance = 100; PlayerManager.GetEntity(i)->CellShootable = driver->getTexture("Textures/CellShootable.png"); PlayerManager.GetEntity(i)->CellShootableCover = driver->getTexture("Textures/CellShootableCover.png"); PlayerManager.GetEntity(i)->Position(); path filename = "Avatars/"; filename.append(PlayerName[i].c_str()); filename.append(".png"); PlayerManager.GetEntity(i)->Avatar = driver->getTexture( filename ); //test stats PlayerManager.GetEntity(i)->Stats.Accuracy = 100; PlayerManager.GetEntity(i)->Stats.Attack = 100; PlayerManager.GetEntity(i)->Stats.AttackVariance = 0; PlayerManager.GetEntity(i)->Stats.Defense = 0; PlayerManager.GetEntity(i)->Stats.DefenseVariance = 0; } // Create the 3D cursor ISceneNode *Cursor = smgr->addSphereSceneNode(4); //Setup AI int numEnemies = 1; EntityManager EnemyManager(numEnemies); //Textures (none for now) //Need to keep track of all entity positions, so they don't get placed ontop of each other vector<Entity*> EntityList( PlayerManager.GetEntityList() ); for (int i = 0; i < numEnemies; i++) { EnemyManager.GetEntity(i)->Construct(smgr,MG.Convert(), driver->getTexture("Textures/Enemy.png")); EnemyManager.GetEntity(i)->Stats.Name = PlayerName[i]; EnemyManager.GetEntity(i)->Stats.MaxHealth = 100; EnemyManager.GetEntity(i)->Stats.RestoreAll(); EnemyManager.GetEntity(i)->Stats.MovementSteps = 5+i; EnemyManager.GetEntity(i)->Stats.RealFiringDistance = 100; EnemyManager.GetEntity(i)->Stats.Attack = 50; EnemyManager.GetEntity(i)->Stats.Accuracy = 100; //Stats //steup random position EnemyManager.GetEntity(i)->AI_SetRandomDestination(EntityList); EnemyManager.GetEntity(i)->X = EnemyManager.GetEntity(i)->AI_DestinationX; EnemyManager.GetEntity(i)->Y = EnemyManager.GetEntity(i)->AI_DestinationY; //new path will be created EnemyManager.GetEntity(i)->Position(); EnemyManager.GetEntity(i)->AI_State = AI::Patrol; EnemyManager.GetEntity(i)->isAI = true; EntityList.push_back(EnemyManager.GetEntity(i)); } bool rkf = false; //Game loop while (device->run()) { //Create a list of all entities EntityList.clear(); vector<Entity*> EnemyList( EnemyManager.GetEntityList() ); EntityList.insert( EntityList.end(), EnemyList.begin(), EnemyList.end() ); /* * * * * * * * * * * * * * */ /* Player switching module */ /* * * * * * * * * * * * * * */ for (int i = 0; i < PlayerManager.Size; i++) PlayerManager.GetEntity(i)->CheckIfDead(); PlayerManager.ManageCharacterSwitching(Receiver); /* * * * * * * * * * * */ /* Pathfinding module */ /* * * * * * * * * * * */ PlayerManager.GetCurrentEntity()->UpdatePathDisplayTimer(); if (Receiver.MouseState.LeftButtonDown && PlayerManager.GetCurrentEntity()->NewPathDisplayTimer < 1) PlayerManager.GetCurrentEntity()->CreatePathToDestination(EntityList,smgr,Receiver,Cursor->getPosition(),dimension2d<s32>(MR.XSize,MR.YSize),MG.Convert()); /* * * * * * * * * * * * * */ /* Update position module */ /* * * * * * * * * * * * * */ PlayerManager.GetCurrentEntity()->Position(); /* * * * * * * * * * * */ /* Follow path module */ /* * * * * * * * * * * */ if (Receiver.IsKeyDown(Receiver.KeyConfig.FOLLOW_PATH)) PlayerManager.GetCurrentEntity()->FollowPath(EntityList); /* * * * * * * * * */ /* End turn module */ /* * * * * * * * * */ if (Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN) && !rkf) { rkf = true; PlayerManager.EndTurn(); EnemyManager.AI_StartTurn(EntityList, PlayerManager, smgr, Receiver, irr::core::dimension2d<s32>(MR.XSize,MR.YSize), MG.Convert(), MR.MetaTriangleSelector, MR.MetaCoverTriangleSelector); PlayerManager.StartTurn(); } else if (!Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN)) rkf = false; /* * * * * * * * */ /* Cursor module */ /* * * * * * * * */ Cursor->setPosition( vftovi(MouseTo3D( Receiver, MR.CollisionManager, MR.TriSelector)) ); /* * * * * * * * */ /* Camera module */ /* * * * * * * * */ gameCam.Update(Receiver,PlayerManager.GetCurrentEntity()->Node); /* * * * * * * * * * * * */ /* Stats monitor module */ /* * * * * * * * * * * * */ for (int i=0;i<PlayerManager.Size;i++) PlayerManager.GetEntity(i)->Stats.MonitorAll(); /* * * * * * * * * * */ /* Draw scene module */ /* * * * * * * * * * */ driver->beginScene(true,true,SColor(255,100,101,140)); smgr->drawAll(); guienv->drawAll(); HUD.Draw(guienv,PlayerManager.GetCurrentEntity()->Stats,PlayerManager.GetCurrentEntity()->Avatar); //HUD.DrawAIDebug(guienv,*EnemyManager.GetEntity(0),PlayerManager); driver->endScene(); /* * * * * * * */ /* Menu module */ /* * * * * * * */ if (Receiver.IsKeyDown(Receiver.KeyConfig.MENU)) return 0; /* * * * * * * * * * * * */ /* Firing display module */ /* * * * * * * * * * * * */ if (!Receiver.IsKeyDown(KEY_KEY_S)) PlayerManager.GetCurrentEntity()->ShootDisplayKeyFlag = false; else { PlayerManager.GetCurrentEntity()->ShootDisplayKeyFlag = true; PlayerManager.GetCurrentEntity()->DisplayAllCellsThatCanBeShotUsingThreads(smgr,MR.CollisionManager,MR.MetaTriangleSelector,MR.MetaCoverTriangleSelector); } /* * * * * * * * * */ /* Firing module * */ /* * * * * * * * * */ if (Receiver.MouseState.RightButtonDown && !PlayerManager.GetCurrentEntity()->RightMouseFlag) { PlayerManager.GetCurrentEntity()->RightMouseFlag = true; //second playerManager needs to replaced with enemyManager when in place, the function will also need to be edited FireAtTarget(Receiver, PlayerManager, EnemyManager, MR, smgr, Cursor); } else if (!Receiver.MouseState.RightButtonDown) PlayerManager.GetCurrentEntity()->RightMouseFlag = false; } return 0; }
static bool checkBBoxIntersection(IrrlichtDevice * device, ISceneManager * smgr) { video::IVideoDriver* driver = device->getVideoDriver(); // add camera scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(); camera->setPosition(core::vector3df(30, 30, 30)); camera->setTarget(core::vector3df(8.f, 8.f, 8.f)); camera->setID(0); // add a cube to pick scene::ISceneNode* cube = smgr->addCubeSceneNode(30, 0, -1, core::vector3df(0,0,0),core::vector3df(30,40,50)); bool result=true; for (u32 round=0; round<2; ++round) { driver->beginScene(true, true, video::SColor(100, 50, 50, 100)); smgr->drawAll(); driver->endScene(); core::matrix4 invMat = cube->getAbsoluteTransformation(); invMat.makeInverse(); s32 hits=0; u32 start = device->getTimer()->getRealTime(); for (u32 i=10; i<150; ++i) { for (u32 j=10; j<110; ++j) { const core::position2di pos(i, j); // get the line used for picking core::line3df ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(pos, camera); invMat.transformVect(ray.start); invMat.transformVect(ray.end); hits += (cube->getBoundingBox().intersectsWithLine(ray)?1:0); } } u32 duration = device->getTimer()->getRealTime()-start; logTestString("bbox intersection checks %d hits (of 14000).\n", hits); hits = -hits; start = device->getTimer()->getRealTime(); for (u32 i=10; i<150; ++i) { for (u32 j=10; j<110; ++j) { const core::position2di pos(i, j); // get the line used for picking core::line3df ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(pos, camera); invMat.transformVect(ray.start); invMat.transformVect(ray.end); hits += (IntersectBox(ray.start, (ray.end-ray.start).normalize(), cube->getBoundingBox())?1:0); } } u32 duration2 = device->getTimer()->getRealTime()-start; logTestString("bbox intersection resulted in %d misses at a speed of %d (old) compared to %d (new).\n", abs(hits), duration, duration2); if (duration>(duration2*1.2f)) logTestString("Consider replacement of bbox intersection test.\n"); result &= (hits==0); assert(result); // second round without any hits, so check opposite direction camera->setTarget(core::vector3df(80.f, 80.f, 80.f)); } ISceneNode* node = smgr->addSphereSceneNode(5.f, 16, 0, -1, core::vector3df(0, 0, 1), core::vector3df(), core::vector3df(0.3f, 0.3f, 0.3f)); cube->remove(); cube = smgr->addCubeSceneNode(10.f, 0, -1, core::vector3df(0, 6.5f, 1), core::vector3df(), core::vector3df(10, 0.1f, 1.f)); camera->setPosition(core::vector3df(0, 0, 10)); camera->setTarget(core::vector3df()); u32 count=0; for (u32 i=0; i<30; ++i) { driver->beginScene(true, true, video::SColor(100, 50, 50, 100)); smgr->drawAll(); driver->endScene(); count += node->getTransformedBoundingBox().intersectsWithBox(cube->getTransformedBoundingBox())?1:0; node->setPosition(node->getPosition()+core::vector3df(.5f,.5f,0)); if (i==8 && count != 0) result=false; if (i==17 && count != 9) result=false; } if (count != 9) result=false; smgr->clear(); return result; }
// ---------------------------------------------------------------------------- void Track::build() { IrrlichtDevice* device = Editor::getEditor()->getDevice(); PHYSFS_setWriteDir(Editor::getEditor()->getTrackDir().c_str()); PHYSFS_mkdir(m_file_name.c_str()); path p = Editor::getEditor()->getTrackDir() + m_file_name; CMeshBuffer<S3DVertex2TCoords>* mb = m_terrain->build(p); SMesh smesh; smesh.addMeshBuffer(mb); for (u32 i = 1; i < m_roads.size(); i++) { IRoad* r = m_roads[i]; if (r->getSpline()->getPointNum()>1) smesh.addMeshBuffer(((Road*)r)->getMeshBuffer()); } B3DMeshWriter* writer = new B3DMeshWriter(device->getFileSystem()); IWriteFile *file; file = device->getFileSystem()->createAndWriteFile((p + "/track.b3d").c_str()); writer->writeMesh(file, &smesh); file->drop(); delete writer; m_driveline->build(p); std::ofstream mat; mat.open((p + "/materials.xml").c_str()); mat << "<materials>\n"; mat << " <material name=\"splatt.png\" graphical-effect=\"splatting\""; SMaterial m = m_terrain->getMaterial(0); for (int i = 1; i < 5; i++) { mat << " splatting-texture-" << i << "=\""; mat << Editor::toRelative(m.getTexture(i+1)->getName()).c_str(); mat << "\""; } mat << "/>\n"; if (m_gravity_road) { for (u32 i = 1; i < m_roads.size(); i++) { stringc tex = m_roads[i]->getTexName(); if (tex.size()>0) { mat << " <material name=\""; mat << tex.c_str(); mat << "\" has-gravity=\"yes\" />\n"; } } // roads } // gravity road mode mat <<"</materials>\n"; mat.close(); stringw track; track += "<track name = \""; track += m_track_name + L"\"\n"; track += " version = \"5\"\n"; track += " groups = \"made-by-STK-TE\"\n"; track += " designer = \""; track += m_designer + "\"\n"; track += " music = \""; track += m_music.c_str(); track += "\"\n"; track += " screenshot = \"screenshot.jpg\"\n"; track += " smooth-normals = \"true\"\n"; track += " reverse = \"Y\"\n>\n"; track += "</track>\n"; PHYSFS_uint64 len = 4 * track.size(); char* dst = new char[len]; #ifdef _WIN32 PHYSFS_utf8FromUcs2((PHYSFS_uint16*)track.c_str(),dst,len); #else PHYSFS_utf8FromUcs4((PHYSFS_uint32*)track.c_str(), dst, len); #endif FILE* f; f = fopen((p + "/track.xml").c_str(), "wb"); fwrite(dst, sizeof(char), strlen(dst), f); fclose(f); delete[] dst; std::ofstream scene; scene.open((p + "/scene.xml").c_str()); scene << "<scene>\n"; scene << " <track model=\"track.b3d\" x=\"0\" y=\"0\" z=\"0\">\n"; exportElements(scene, true); scene << " </track>\n"; exportElements(scene, false); ISceneManager* sm = Editor::getEditor()->getSceneManager(); ISceneNode* node; int i = 1; stringc name; while ((node = sm->getSceneNodeFromId(MAGIC_NUMBER + i))) { name = node->getName(); vector3df pos; if (node->isVisible() && (name == "banana" || name == "item" || name == "small-nitro" || name == "big-nitro")) { pos = node->getPosition(); scene << " <" << name.c_str() << " x=\"" << pos.X << "\" y=\"" << pos.Y << "\" z=\"" << pos.Z << "\" />\n"; } i++; } scene << Viewport::get()->getSky()->getXmlString().c_str(); Viewport::get()->printCheckLine(&scene); scene << " <default-start karts-per-row = \"3\"\n"; scene << " forwards-distance =\"1.50\"\n"; scene << " sidewards-distance=\"3.00\"\n"; scene << " upwards-distance =\"0.10\"/>\n"; scene << "</scene>\n"; scene.close(); MsgWndw::get()->showMsg(_("Track exported!")); } // build
// ---------------------------------------------------------------------------- void Track::save() { FILE* pFile = 0; path p = Editor::getEditor()->getMapsPath() + "/" + m_file_name.c_str(); pFile = fopen(p.c_str(), "wb"); if (!pFile) { MsgWndw::get()->showMsg(_("Save failed: file could not be created!\n")); return; } // SIGN u64 sign = TOP_SECRET_SIGNATURE_NUMBER; fwrite(&sign, sizeof(u64), 1, pFile); // TRACK NAME u8 size = m_track_name.size() + 1; fwrite(&size, sizeof(u8), 1, pFile); fwrite(m_track_name.c_str(), sizeof(wchar_t), size, pFile); // DESIGNER NAME size = m_designer.size() + 1; fwrite(&size, sizeof(u8), 1, pFile); fwrite(m_designer.c_str(), sizeof(wchar_t), size, pFile); // FILE NAME size = m_file_name.size() + 1; fwrite(&size, sizeof(u8), 1, pFile); fwrite(m_file_name.c_str(), sizeof(c8), size, pFile); // MUSIC size = m_music.size() + 1; fwrite(&size, sizeof(u8), 1, pFile); fwrite(m_music.c_str(), sizeof(c8), size, pFile); // TERRAIN m_terrain->save(pFile); // SKY Viewport::get()->getSky()->save(pFile); // GRAVITY ROAD FLAG fwrite(&m_gravity_road, sizeof(bool), 1, pFile); // ROADS size = m_roads.size(); fwrite(&size, sizeof(u8), 1, pFile); IRoad* r; for (u8 i = 0; i < size; i++) { r = m_roads[i]; r->save(pFile); } //CHECKLINES Viewport::get()->saveCheckLines(pFile); // OBJECTS ISceneManager* sm = Editor::getEditor()->getSceneManager(); ISceneNode* node; u32 num = Viewport::getLastEntityID() - MAGIC_NUMBER; u32 vnum = 0; for (u32 i = 0; i < num; i++) { node = sm->getSceneNodeFromId(MAGIC_NUMBER + i + 1); if (node && node->isVisible()) vnum++; } fwrite(&vnum, sizeof(u32), 1, pFile); for (u32 i = 0; i < num; i++) { node = sm->getSceneNodeFromId(MAGIC_NUMBER + i + 1); assert(node); if (node->isVisible()) { fwrite(&node->getPosition(), sizeof(vector3df), 1, pFile); fwrite(&node->getRotation(), sizeof(vector3df), 1, pFile); fwrite(&node->getScale(), sizeof(vector3df), 1, pFile); u8 size = strlen(node->getName()) + 1; fwrite(&size, sizeof(u8), 1, pFile); fwrite(node->getName(), sizeof(c8), size, pFile); } } fclose(pFile); Editor::getEditor()->addToRecentlyOpenedList(m_file_name); MsgWndw::get()->showMsg(_("Track saved!\n")); } // save
// (private) // gets a highlighted scene node if there is one void GameInstance::updateSelector(){ // if a highlighted node exists, deselect. If it is still // selected this frame, it will be re-selected below. if (highlightedSceneNode) { highlightedSceneNode = 0; } // get a pointer to whichever scene node is targetted (if any) ISceneNode * selected = selector->getTarget(); if (selected){ highlightedSceneNode = selected; } // If no vehicle is currently being carried and the right mouse button is // pressed, check if we're currently targetting (highlighting) a vehicle. // If so, then pick it up. if (!carriedVehicle && ((BorbiesEventReceiver *)receiver)->isRightMouseDown()){ VehicleInstance * vehicle = (VehicleInstance *)(vehicles->getObject(highlightedSceneNode)); if(vehicle) { // if vehicle was in fact selected, pick it up carriedVehicle = vehicle; // VehicleInstance* (carriedVehicle) carriedVehicle->stop(); // remove all animators from the vehicle objCarry->pickUp(highlightedSceneNode); // ISceneNode* (highlighted) // remove the vehicle's collision so it doesn't make Borbie glitch out this->removeCollision(carriedVehicle->getNode()->getTriangleSelector()); // flag carried vehicle as no longer pickable carriedVehicle->getNode()->setID(IDFlag_IsNotPickable); // display the target marker on the GUI this->hud->setTargetMarkerEnabled(true); //set hands invisible this->hands->setVisible(false); } } // If we're currently carrying a vehicle, and the left mouse button is // pressed, throw it and break someone's face. if (carriedVehicle && !vehicleThrown && ((BorbiesEventReceiver *)receiver)->isLeftMouseDown()) { // get the player's target node ISceneNode *target = selector->getThrowTarget(); //target->setVisible(false); if(target) std::cout << "Target in sight at distance = " << target->getPosition().getDistanceFrom(carriedVehicle-> getNode()->getPosition()) << std::endl; // throw the selected object at the found target; if target is null // (not found), it will just fly to the maximum distance possible. // This will start an animator to fly to the target. objCarry->throwObj(target); //turn hands back on this->hands->setVisible(true); vehicleThrown = true; // hide the target marker (no longer needed) this->hud->setTargetMarkerEnabled(false); } // update thrownObject (checks if vehicles need to be thrown) this->updateThrownObject(); }
/****************************************************************************** * Apply explosion damage to all objects within the radius of the given * gameObject, scaled based on distance from the explosion, up to a maximum * damage as dictated by the given object's damage value. Explosions * affect vehicles, buildings, enemies, and Borbie. *****************************************************************************/ void GameInstance::applyExplosionDamage(GameObject *explodingObject) { // get the exploding object's variables GameObjectType explodingType = explodingObject->getObjectType(); ISceneNode *explodingNode = explodingObject->getNode(); float explosionRadius = explodingObject->getExplosionRadius(); float explosionDamage = explodingObject->getExplosionDamage(); vector3df explodePos = explodingNode->getPosition(); // calculate damage to enemies int numEnemies = enemies->objList.size(); for(int i=0; i<numEnemies; i++){ ISceneNode *curNode = enemies->objList[i]->getNode(); // if current node is the exploding node, ignore it if(curNode == explodingNode) continue; // if current node is NOT visible or if it already blew up, ignore it else if(!curNode->isVisible() || enemies->objList[i]->hasExploded()) continue; float distance = curNode->getPosition().getDistanceFrom(explodePos); if(distance <= explosionRadius){ int damage = explosionDamage; // max damage if(distance > 400){ // if more than 400 away, scale down damage float scale = (distance-400) / (explosionRadius-400); damage = int(explosionDamage * scale); } enemies->objList[i]->applyDamage(damage); } } // calculate damage for buildings int numBuild = buildings->objList.size(); for(int i=0; i<numBuild; i++){ ISceneNode *curNode = buildings->objList[i]->getNode(); // if current node is the exploding node, ignore it if(curNode == explodingNode) continue; // if current node is NOT visible, ignore it else if(!curNode->isVisible() || buildings->objList[i]->hasExploded()) continue; // otherwise, check if the distance is close enough, and apply damage // based on the distance to the explosion center. Offset position by 200 // since the buildings are not positioned relative to their center. float distance = curNode->getPosition().getDistanceFrom(explodePos); if(distance <= explosionRadius){ int damage = explosionDamage; // max damage if(distance > 400){ // if more than 400 away, scale down damage float scale = (distance-400) / (explosionRadius-400); damage = int(explosionDamage * scale); } // if the exploding object is a building, reduce splash damage // to prevent instant-killing an entire city. That would suck. if(explodingType == TYPE_BUILDING) damage = damage / 20; buildings->objList[i]->applyDamage(damage); } } // calculate damage for vehicles int numVehicles = vehicles->objList.size(); for(int i = 0 ; i < numVehicles ; i++){ ISceneNode *curNode = vehicles->objList[i]->getNode(); // if current node is the exploding node, ignore it if(curNode == explodingNode) continue; // if current node is NOT visible, ignore it else if(!curNode->isVisible() || vehicles->objList[i]->hasExploded()) continue; // otherwise, check if the distance is close enough, and apply damage // based on the distance to the explosion center float distance = curNode->getPosition().getDistanceFrom(explodePos); if(distance <= explosionRadius){ int damage = explosionDamage; // max damage if(distance > 400){ // if more than 400 away, scale down damage float scale = (distance-400) / (explosionRadius-400); damage = int(explosionDamage * scale); } vehicles->objList[i]->applyDamage(damage); } } // if Borbie is already dead, don't kill her again :( if(player->hasExploded()) return; // apply damage to borbie herself (the player) float distance = player->getNode()->getPosition().getDistanceFrom(explodePos); // if a vehicle, lower the explosion radius that applies to borbie if(explodingType == TYPE_VEHICLE) explosionRadius = 600; if(distance <= explosionRadius){ int damage = explosionDamage; // max damage if(distance > 400){ // if more than 400 away, scale down damage float scale = (distance-400) / (explosionRadius-400); damage = int(explosionDamage * scale); } player->applyDamage(damage/2); // reduce damage by half } }
virtual bool OnEvent(const SEvent& event) { // Escape swaps Camera Input if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown == false) { if (event.KeyInput.Key == irr::KEY_ESCAPE) { if (g_Device) { scene::ICameraSceneNode * camera = g_Device->getSceneManager()->getActiveCamera(); if (camera) { camera->setInputReceiverEnabled( !camera->isInputReceiverEnabled()); } return true; } } } else if (event.EventType == EET_GUI_EVENT) { s32 id = event.GUIEvent.Caller->getID(); //IGUIEnvironment* env = g_Device->getGUIEnvironment(); switch (event.GUIEvent.EventType) { case EGET_SCROLL_BAR_CHANGED: { IGUIScrollBar* scroll = (IGUIScrollBar*) event.GUIEvent.Caller; const s32 pos = scroll->getPos(); if (id == GUI_ID_SPEED_SCROLL) { g_CameraAnimator->setMoveSpeed(pos * pos / 100000.0); } else if (id == GUI_ID_LEVEL) { //g_EarthVisualization->setLevel(pos); } } break; case EGET_CHECKBOX_CHANGED: { IGUICheckBox* checkBox = (IGUICheckBox*) event.GUIEvent.Caller; if (id == GUI_ID_WIREFRAME) { g_EarthVisualization->setWireframe(checkBox->isChecked()); } else if (id == GUI_ID_MESH_UPDATE) { g_EarthVisualization->setMeshGenerated( checkBox->isChecked()); } } break; default: break; } } else if (event.EventType == EET_USER_EVENT) { if (event.UserEvent.UserData1 == ANIMATION_MOVE_EVENT) { ISceneNode* node = (ISceneNode*) event.UserEvent.UserData2; g_EarthVisualization->setViewerPoint(node->getPosition()); g_LevelScroll->setPos(g_EarthVisualization->getLevel()); } } return false; }