/** * @brief * Loads/reloads the sound */ void SNMSound::Load() { // Destroy currently used sound source Source *pSS = static_cast<Source*>(m_pSoundSourceHandler->GetResource()); if (pSS) delete pSS; // Get the PL sound container this scene node is in SceneContainer *pContainer = GetSceneNode().GetContainer(); while (pContainer && !pContainer->IsInstanceOf("PLSound::SCSound")) pContainer = pContainer->GetContainer(); if (pContainer) { SoundManager *pSoundManager = static_cast<SCSound*>(pContainer)->GetSoundManager(); if (pSoundManager) { Source *pSoundSource = pSoundManager->CreateSoundSource(pSoundManager->CreateSoundBuffer(m_sSound, (GetFlags() & Stream) != 0)); m_pSoundSourceHandler->SetResource(pSoundSource); pSoundSource->SetAttribute(Source::Position, GetSceneNode().GetTransform().GetPosition()); pSoundSource->SetVolume(m_fVolume); pSoundSource->Set2D((GetFlags() & No3D) != 0); pSoundSource->SetLooping(!(GetFlags() & NoLoop)); pSoundSource->SetPitch(m_fPitch); pSoundSource->SetReferenceDistance(m_fReferenceDistance); pSoundSource->SetMaxDistance(m_fMaxDistance); pSoundSource->SetRolloffFactor(m_fRolloffFactor); OnPosition(); if (!(GetFlags() & NoStartPlayback)) pSoundSource->Play(); } } }
void WorkWithSound(std::string msg,ALshort **input_audio,ALshort **output_audio) { SoundManager s; while (1) { s.input(input_audio,output_audio); //s.output(); } }
int main( int argc, char *args[] ) { bool quit = false; ScreenManager *screenManager = new ScreenManager(); SoundManager *soundManager = new SoundManager(); if ( init() == false ) { return 1; } if ( load_files() == false ) { return 1; } while ( quit == false ) { while ( SDL_PollEvent( &event ) ) { if ( event.type == SDL_KEYDOWN ) { switch ( event.key.keysym.sym ) { case SDLK_RETURN: handle_return_key(); break; default: ; } } if ( event.type == SDL_QUIT ) { quit = true; } } startScreen = screenManager->load_image( "../ScreenManager/Images/test.png" ); if ( soundManager->play_music( "../beat.wav" ) ) { return 1; } screenManager->apply_surface( 0, 0, startScreen, screen); if ( gameStart ) { //apply the gameScreen surface } else { //apply the startScreen surface } //Update the screen if ( SDL_Flip( screen ) == -1 ) { return 1; } } clean_up(); return 0; }
void SkillData::playSound() { SoundManager *soundManager = SoundManager::getInstance(); if(!sound.empty()) { std::string diretorioSound = std::string("sfx/"); diretorioSound.append(sound.c_str()); soundManager->playSound(diretorioSound, 1); } }
void AudioTest1() { return; SoundManager* soundManager = CreateSoundManager(); for(int i = 0; i < 100000; i++ ) SharedPtr<Sound> sound = soundManager->createSound("content/ptrs.wav"); //sound->removeSmartPtr }
void loadCacheSoundsCallback (const std::string &filename, intptr_t param) { SoundManager *sm; sm = (SoundManager*)param; if (!sm->enabled) { //sm->erorr(); debugLog("Disabled: Won't Load Sample ["+filename+"]"); return; } if (fileType==".ogg") { debugLog("trying to load sound " + filename); sm->loadSoundIntoBank(filename, "", ""); } }
void GameObj::move(SoundManager &sm) { if(!moveSpecial(sm)) { if(body) { // Gradual speed increase for objects with a max velocity set // (Bullets should have max Vel ZERO) // this logic will need updating! if(goSettings.getVelocityMax()) { b2Vec2 vel = body->GetLinearVelocity(); vel.x = b2Min( vel.x + 0.1f, goSettings.getVelocityMax() ); body->SetLinearVelocity( vel ); } t_move.Calculate_Ellapsed_Time(); if(t_move.TotalTime() >= TIMER_SOUND_MOVE) { SoundManager::Sounds soundID; switch(goSettings.getTypeID()) { case Settings::OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MOVE; break; case Settings::OBJ_ID_STONEWALL: soundID = sm.SND_STONEWALL_MOVE; break; // case settings.OBJ_T_DOG: soundID = sm.SND_DOG_MELEE; break; // case settings.OBJ_T_SPEARMAN: soundID = sm.SND_SPEARMAN_MELEE; break; // case settings.OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MELEE; break; default: soundID = sm.SND_DOG_MOVE; break; } sm.playSound(soundSourceID, soundID, body->GetPosition()); t_move.Reset(0.0); } } } }
void GameObj::damage(int amount, SoundManager &sm) { // Process incoming damage if(getArmor() > amount) return; // armor negates all damage else amount -= getArmor(); setHP(getHP() - amount); // SFX t_damaged.Calculate_Ellapsed_Time(); if(t_damaged.TotalTime() >= TIMER_SOUND_DAMAGED) { SoundManager::Sounds soundID; switch(goSettings.getTypeID()) { case Settings::OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_DAMAGED; break; case Settings::OBJ_ID_STONEWALL: soundID = sm.SND_STONEWALL_DAMAGED; break; // case settings.OBJ_T_DOG: soundID = sm.SND_DOG_MELEE; break; // case settings.OBJ_T_SPEARMAN: soundID = sm.SND_SPEARMAN_MELEE; break; // case settings.OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MELEE; break; default: soundID = sm.SND_ARCHER_DAMAGED; break; } sm.playSound(soundSourceID, soundID, body->GetPosition()); t_damaged.Reset(0.0); } // Special Behavior (defined in derived classes) damageSpecial(amount, sm); // Death sequence if(getHP() < 0) { death(sm); } }
void GameObj::attack(GameObj *enemy, SoundManager &sm) { // if(enemy->isAlive()) { // SFX t_melee.Calculate_Ellapsed_Time(); if(t_melee.TotalTime() >= TIMER_SOUND_MELEE) { SoundManager::Sounds soundID; switch(goSettings.getTypeID()) { case Settings::OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MELEE; break; case Settings::OBJ_ID_STONEWALL: soundID = sm.SND_STONEWALL_MELEE; break; // case settings.OBJ_T_DOG: soundID = sm.SND_DOG_MELEE; break; // case settings.OBJ_T_SPEARMAN: soundID = sm.SND_SPEARMAN_MELEE; break; // case settings.OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MELEE; break; default: soundID = sm.SND_ARCHER_DAMAGED; break; } sm.playSound(soundSourceID, soundID, body->GetPosition()); t_melee.Reset(0.0); } // DAMAGE ENEMY enemy->damage(goSettings.getDamage(), sm); // Special Behavior (defined in derived classes) attackSpecial(enemy, sm); // } }
void sound_callback(const global_planner_fall::SoundMsg::ConstPtr& msg) { std::string str = msg->filename; int numTimes = msg->num_times; std::string text_output = msg->text_output; if (text_output.length() > 0) ROS_INFO_STREAM(text_output); sound_manager.play_sound(str, numTimes); }
//--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { PBMP bContext = new BMP(); bContext->Width = ClientWidth; bContext->Height = ClientHeight; context = new FastBitmap(bContext); rm = new RenderManager(); rm->setContext(context,Canvas,ClientWidth, ClientHeight, clWhite); DoubleBuffered=true; gm = new GameManager(); gm->setRenderManager(rm); SpriteFabric *sf = SpriteFabric::getInstance(); sc = 0; map = 0; SoundManager * sm = SoundManager::getInstance(); sm->init(Button1); UserStats::getInstance()->loadFromFile("config/autoexec.txt"); }
/** Detach this sound from its manager. This means that the manager will no longer know we exist. Typically only called when either the sound or the manager is about to get deleted. Since this means update() will no longer be called, we also have to unlock the sound manually since it will no longer be able to do that itself. This means that the sound may be deleted, even if it is still playing, when the manager is deleted. However, you are still allowed to keep and manage your own SoundPtr references, but the lock/unlock system is disabled after the manager is gone. */ void detach() { if(mgr) { mgr->detach(this); mgr = NULL; } // Unlock must be last command. Object may get deleted at this // point. unlock(); }
void PPAD::update(std::vector<std::vector<int>> &colMap, Rock& rock, SoundManager& sound) { if (plateBound.intersects(rock.getBounds())) { plate.setTextureRect(sf::IntRect(32, 32, mSize.x, mSize.y)); if (!opened) { open(colMap); sound.playSound(1); opened = true; } } else if (!opened) { colMap[posD.y][posD.x] = 1; } }
void ConverseSpeech::update() { TownsSound sound; SoundManager *sm = Game::get_game()->get_sound_manager(); if(!sm->is_audio_enabled() || !sm->is_speech_enabled()) return; if(!list.empty()) { if(sm->isSoundPLaying(handle) == false) { list.pop_front(); if(!list.empty()) { sound = list.front(); handle = sm->playTownsSound(sound.filename, sound.sample_num); } } } }
/* ================== Main ================== */ int IndieLib() { //Sets the working path as the 'exe' directory. All resource paths are relative to this directory if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) { std::cout<<"\nUnable to Set the working path !"; } SoundManager * mSm = SoundManager::instance(); // ----- IndieLib intialization ----- CIndieLib *mI = CIndieLib::instance(); if (!mI->init()) return 0; Game * mGame = new Game(); bool quit = false; while (!quit && !mI->_input->quit()) { // ----- Input update ---- Sleep(10); // Take it easy, computer mI->_input->update(); quit = mGame->run(); // ----- Render ----- mI->_render->beginScene(); mI->_render->clearViewPort(0, 0, 0); mI->_entity2dManager->renderEntities2d(); //mI->_entity2dManager->renderCollisionAreas(255, 0, 0, 255); mI->_render->endScene(); } // ----- Free ----- mSm->shutdown(); mI->end(); return 0; }
int main () { printf ("EmitterAutoDelete test.\n"); try { scene_graph::Scene scene; SoundManager manager ("OpenAL", "*"); ListenerPtr listener (scene_graph::Listener::Create ()); listener->BindToParent (scene.Root ()); manager.LoadSoundLibrary (library_file); ScenePlayer scene_player; scene_player.SetListener (listener.get ()); scene_player.SetManager (&manager); ((Node*)play_sound ("declaration2", scene).get ())->RegisterEventHandler (NodeEvent_AfterDestroy, xtl::bind (&Application::Exit, 0)); Application::Run (); } catch (std::exception& exception) { printf ("exception: %s\n",exception.what ()); } catch (...) { printf ("unknown exception\n"); } printf ("exit\n"); return Application::GetExitCode (); }
SoundTest() { //soundManager = new SoundManager(); //soundManager->connectToServer("localhost",57120); // More concise method of above two lines soundManager = new SoundManager("localhost",57120); soundManager->showDebugInfo(true); // Get default sound environment env = soundManager->getSoundEnvironment(); while( !soundManager->isSoundServerRunning() ) { soundManager->startSoundServer(); } // Load sound assets //env->setAssetDirectory("menu_sounds"); showMenuSound = env->loadSoundFromFile("showMenuSound","menu_sounds/menu_load.wav"); hideMenuSound = env->loadSoundFromFile("hideMenuSound","menu_sounds/menu_closed.wav"); scrollMenuSound = env->loadSoundFromFile("scrollMenuSound","menu_sounds/menu_scroll.wav"); selectMenuSound = env->loadSoundFromFile("selectMenuSound","menu_sounds/menu_select.wav"); soundLoop = env->loadSoundFromFile("mus","Omega4Relay.wav"); SoundInstance* soundInstance = new SoundInstance(showMenuSound); soundInstance->setReverb( 1.0, 1.0 ); soundInstance->setVolume(1.0); soundInstance->setPosition( Vector3f(0,1,0) ); soundInstance->play(); rewindingSoundInstance = new SoundInstance(showMenuSound); }
void ConverseSpeech::play_speech(uint16 actor_num, uint16 sample_num) { std::string sample_file; char filename[20]; // "/speech/charxxx.sam" TownsSound sound; SoundManager *sm = Game::get_game()->get_sound_manager(); if(!sm->is_audio_enabled() || !sm->is_speech_enabled()) return; //translate the converse sample number into the CHAR number in the SPEECH directory if required. if(actor_num == 202) //GUARDS actor_num = 228; if(actor_num == 201) //WISPS actor_num = 229; sample_num--; sprintf(filename, "speech%cchar%u.sam", U6PATH_DELIMITER, actor_num); config->pathFromValue("config/ultima6/townsdir", filename, sample_file); DEBUG(0,LEVEL_DEBUGGING,"Loading Speech Sample %s:%d\n", sample_file.c_str(), sample_num); sound.filename = sample_file; sound.sample_num = sample_num; if(list.empty()) handle = sm->playTownsSound(sample_file, sample_num); list.push_back(sound); return; }
void GameObj::death(SoundManager &sm) { // SFX t_death.Calculate_Ellapsed_Time(); if(t_death.TotalTime() >= TIMER_SOUND_DEATH) { SoundManager::Sounds soundID; switch(goSettings.getTypeID()) { case Settings::OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_DEATH; break; case Settings::OBJ_ID_STONEWALL: soundID = sm.SND_STONEWALL_DEATH; break; // case settings.OBJ_T_DOG: soundID = sm.SND_DOG_MELEE; break; // case settings.OBJ_T_SPEARMAN: soundID = sm.SND_SPEARMAN_MELEE; break; // case settings.OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MELEE; break; default: soundID = sm.SND_ARCHER_DEATH; break; } sm.playSound(soundSourceID, soundID, body->GetPosition()); t_death.Reset(0.0); } // Special Behavior (defined in derived classes) deathSpecial(sm); }
void CreateMateials (NewtonWorld* world, SceneManager* sceneManager) { SoundManager* sndManager; sndManager = sceneManager->GetSoundManager(); // create the Material IDs, g_floorMaterial = NewtonMaterialCreateGroupID (world); g_woodMaterial = NewtonMaterialCreateGroupID (world); g_metalMaterial = NewtonMaterialCreateGroupID (world); // load the sound effects woodOnFloor.m_sound = sndManager->LoadSound ("boxHit.wav"); woodOnFloor.m_manager = sndManager; metalOnFloor.m_sound = sndManager->LoadSound ("metal.wav"); metalOnFloor.m_manager = sndManager; woodOnMetal.m_sound = sndManager->LoadSound ("metalBox.wav"); woodOnMetal.m_manager = sndManager; metalOnMetal.m_sound = sndManager->LoadSound ("metalMetal.wav"); metalOnMetal.m_manager = sndManager; woodOnWood.m_sound = sndManager->LoadSound ("boxBox.wav"); woodOnWood.m_manager = sndManager; //configure the Material interactions NewtonMaterialSetCollisionCallback (world, g_woodMaterial, g_floorMaterial, &woodOnFloor, NULL, GenericContactProcess); NewtonMaterialSetCollisionCallback (world, g_metalMaterial, g_floorMaterial, &metalOnFloor, NULL, GenericContactProcess); NewtonMaterialSetCollisionCallback (world, g_metalMaterial, g_woodMaterial, &woodOnMetal, NULL, GenericContactProcess); NewtonMaterialSetCollisionCallback (world, g_woodMaterial, g_woodMaterial, &woodOnWood, NULL, GenericContactProcess); NewtonMaterialSetCollisionCallback (world, g_metalMaterial, g_metalMaterial, &metalOnMetal, NULL, GenericContactProcess); }
//! When something from a server extension is received this function is called. Could be position updating of gameobject, a private message or just a notification. The ["cmd"] parameter of the event that is received reveals which extension that was spitting out the info. Based on extension this function will do different things. void NetworkManager::OnSmartFoxExtensionResponse(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent) { // get pointer to main frame. NetworkManager* ptrMainFrame = (NetworkManager*)ptrContext; // Check that we're still alive and running if (ptrMainFrame == NULL) { return; } // Get the cmd parameter of the event boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params(); boost::shared_ptr<void> ptrEventParamValueCmd = (*ptrEventParams)["cmd"]; boost::shared_ptr<string> ptrNotifiedCmd = ((boost::static_pointer_cast<string>)(ptrEventParamValueCmd)); // check the type of the command if (*ptrNotifiedCmd == "PilotEvent") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); pInputRotX = *(ptrNotifiedISFSObject->GetDouble("sgctRotY")); pInputRotZ = *(ptrNotifiedISFSObject->GetDouble("sgctRotX")); bool pInputForward = *(ptrNotifiedISFSObject->GetBool("sgctForward")); //bool pInputBackward = *(ptrNotifiedISFSObject->GetBool("sgctBackward")); accRotX += pInputRotX * accRotVal; accRotZ += pInputRotZ * accRotVal; if (pInputForward) { if (enginePowerup.getVal() <= 0.0 && navigationSpeed < accThrustMax * eInputEngine) navigationSpeed += accThrustVal * eInputEngine; else if (navigationSpeed < accThrustMax * eInputEngine * 2.0) navigationSpeed += accThrustVal * eInputEngine * 2.0; } //if (pInputBackward && navigationSpeed > -0.1) { // navigationSpeed -= accThrustVal * eInputEngine; //} } if (*ptrNotifiedCmd == "GunnerEvent") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); gInputRotX = *(ptrNotifiedISFSObject->GetDouble("sgctRotX")) * 3.0; gInputRotY = *(ptrNotifiedISFSObject->GetDouble("sgctRotY")) * 3.0; bool fire = *(ptrNotifiedISFSObject->GetBool("sgctFire")); if (fire && fireTimer <= 0.0) { //if (gEngine->isMaster()) soundManager.play("laser", osg::Vec3f(0.0f, 0.0f, 0.0f)); fireSync.setVal(true); fireTimer = fireRate / eInputTurret; } } if (*ptrNotifiedCmd == "EngineerEvent") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); eInputEngine = ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctEngine"))) * 3 + 0.5); // 0.5 - 3.5 eInputShield = 1.0 - 0.75 * ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctShield"))));// 1.0 - 0.25 (percent of damage taken) eInputTurret = ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctTurret"))) + 0.5); // 0.5 - 1.5 } if (*ptrNotifiedCmd == "BenchMarking") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); double item = *(ptrNotifiedISFSObject->GetDouble("1")); double item2 = *(ptrNotifiedISFSObject->GetDouble("2")); double item3 = *(ptrNotifiedISFSObject->GetDouble("3")); double item4 = *(ptrNotifiedISFSObject->GetDouble("4")); end = omp_get_wtime(); std::cout << "Reply from server, " << static_cast<int>((end - start) * 1000) << "ms." << endl; start = omp_get_wtime(); // send new item if (itemsSent++ < 35 && benchmarkingStarted) { boost::shared_ptr<ISFSObject> parameters(new SFSObject()); parameters->PutDouble("1", 0.923); parameters->PutDouble("2", 0.953); parameters->PutDouble("3", 0.343); parameters->PutDouble("4", 0.523); // find our room to send to. boost::shared_ptr<Room> lastJoined = ptrMainFrame->m_ptrSmartFox->LastJoinedRoom(); // Perform extensionrequest boost::shared_ptr<IRequest> extRequest(new ExtensionRequest("BenchMarking", parameters, lastJoined)); ptrMainFrame->m_ptrSmartFox->Send(extRequest); } else { benchmarkingStarted = false; itemsSent = 0; } } }
void CreateScene (NewtonWorld* world, SceneManager* sceneManager) { Entity* floor; NewtonCollision* shape; NewtonBody* floorBody; void* materialManager; SoundManager* sndManager; PhysicsMaterialInteration matInterations; sndManager = sceneManager->GetSoundManager(); // Create the material for this scene, and attach it to the Newton World materialManager = CreateMaterialManager (world, sndManager); // add the Material table matInterations.m_restitution = 0.6f; matInterations.m_staticFriction = 0.6f; matInterations.m_kineticFriction = 0.3f; matInterations.m_scrapingSound = NULL; matInterations.m_impactSound = sndManager->LoadSound ("metalMetal.wav"); AddMaterilInteraction (materialManager, m_metal, m_metal, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("boxBox.wav"); AddMaterilInteraction (materialManager, m_wood, m_wood, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("metalBox.wav"); AddMaterilInteraction (materialManager, m_metal, m_wood, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("grass0.wav"); AddMaterilInteraction (materialManager, m_wood, m_grass, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("boxHit.wav"); AddMaterilInteraction (materialManager, m_wood, m_bricks, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("grass1.wav"); AddMaterilInteraction (materialManager, m_metal, m_grass, &matInterations); AddMaterilInteraction (materialManager, m_grass, m_bricks, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("metal.wav"); AddMaterilInteraction (materialManager, m_metal, m_bricks, &matInterations); AddMaterilInteraction (materialManager, m_grass, m_grass, &matInterations); // Create a large body to be the floor floor = sceneManager->CreateEntity(); floor->LoadMesh ("LevelMesh.dat"); // add static floor Physics int materialMap[] = {m_bricks, m_grass, m_wood, m_metal}; shape = CreateMeshCollision (world, floor, materialMap); floorBody = CreateRigidBody (world, floor, shape, 0.0f); NewtonReleaseCollision (world, shape); // set the Transformation Matrix for this rigid body dMatrix matrix (floor->m_curRotation, floor->m_curPosition); NewtonBodySetMatrix (floorBody, &matrix[0][0]); // now we will use the properties of this body to set a proper world size. dVector minBox; dVector maxBox; NewtonCollisionCalculateAABB (shape, &matrix[0][0], &minBox[0], &maxBox[0]); // add some extra padding minBox.m_x -= 50.0f; minBox.m_y -= 500.0f; minBox.m_z -= 50.0f; maxBox.m_x += 50.0f; maxBox.m_y += 500.0f; maxBox.m_z += 50.0f; // set the new world size NewtonSetWorldSize (world, &minBox[0], &maxBox[0]); // add some visual entities. dFloat y0 = FindFloor (world, 0.0f, 0.0f) + 10.0f; for (int i = 0; i < 5; i ++) { Entity* smilly; NewtonBody* smillyBody; smilly = sceneManager->CreateEntity(); smilly->LoadMesh ("Smilly.dat"); smilly->m_curPosition.m_y = y0; y0 += 2.0f; smilly->m_prevPosition = smilly->m_curPosition; // add a body with a box shape shape = CreateNewtonBox (world, smilly, m_metal); smillyBody = CreateRigidBody (world, smilly, shape, 10.0f); NewtonReleaseCollision (world, shape); } // add some visual entities. y0 = FindFloor (world, 0.0f, 0.4f) + 10.5f; for (int i = 0; i < 5; i ++) { Entity* frowny; NewtonBody* frownyBody; frowny = sceneManager->CreateEntity(); frowny->LoadMesh ("Frowny.dat"); frowny->m_curPosition.m_z = 0.4f; frowny->m_curPosition.m_y = y0; y0 += 2.0f; frowny->m_prevPosition = frowny->m_curPosition; // add a body with a Convex hull shape shape = CreateNewtonConvex (world, frowny, m_wood); frownyBody = CreateRigidBody (world, frowny, shape, 10.0f); NewtonReleaseCollision (world, shape); } y0 = FindFloor (world, 0.0f, 2.0f) + 10.5f; for (int i = 0; i < 5; i ++) { Entity* frowny; NewtonBody* frownyBody; frowny = sceneManager->CreateEntity(); frowny->LoadMesh ("dumb.dat"); frowny->m_curPosition.m_z = 2.0f; frowny->m_curPosition.m_y = y0; y0 += 2.0f; frowny->m_prevPosition = frowny->m_curPosition; // add a body with a Convex hull shape int materialMap[] = {m_grass, m_wood, m_metal, m_metal}; shape = CreateNewtonCompoundFromEntitySubmesh (world, frowny, materialMap); frownyBody = CreateRigidBody (world, frowny, shape, 10.0f); NewtonReleaseCollision (world, shape); } // set the Camera EyePoint close to the scene action InitCamera (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f)); }
void update() { soundManager->poll(); env->setListenerPosition( Vector3f(0,0,0) ); }
int main() { Config::Init(); curl_global_init(CURL_GLOBAL_ALL); Network::Init(); sf::RenderWindow window(sf::VideoMode(Config::ScreenWidth(), Config::ScreenHeight(), 32), "TowerDefense"); srand(time(NULL)); const int tileSize = 32; Renderer r = Renderer(); SoundManager snd; snd.Init(); Level level(tileSize, sf::Vector2i(Config::ScreenWidth(), Config::ScreenHeight()), &r); Menu menu(&r, &window, &level, level.GetCam()); sf::Clock clock; float drawInterval = 0.0166f, updateInterval = 0.0043f; float drawTime = 0, updateTime = 0; bool ctrl = false, shft = false , alt = false; unsigned int modifierKeys = 0; while (window.isOpen()) { sf::Event Event; while (window.pollEvent(Event)) { if (Event.type == sf::Event::KeyPressed) { if (Event.key.code == sf::Keyboard::LControl || Event.key.code == sf::Keyboard::RControl) ctrl = true; else if (Event.key.code == sf::Keyboard::LShift || Event.key.code == sf::Keyboard::RShift) shft = true; else if (Event.key.code == sf::Keyboard::LAlt || Event.key.code == sf::Keyboard::RAlt) alt = true; } else if (Event.type == sf::Event::KeyReleased) { if (Event.key.code == sf::Keyboard::LControl || Event.key.code == sf::Keyboard::RControl) ctrl = false; else if (Event.key.code == sf::Keyboard::LShift || Event.key.code == sf::Keyboard::RShift) shft = false; else if (Event.key.code == sf::Keyboard::LAlt || Event.key.code == sf::Keyboard::RAlt) alt = false; } modifierKeys = (ctrl ? ModifierKeys::Control : 0) | (shft ? ModifierKeys::Shift : 0) | (alt ? ModifierKeys::Alt : 0); if (Event.type == sf::Event::Closed) window.close(); else if (Event.type == sf::Event::KeyPressed) { menu.ProcessInput(Event, modifierKeys); if (!menu.GamePaused()) level.ProcessInput(Event, modifierKeys); } else if (Event.type == sf::Event::MouseButtonPressed || Event.type == sf::Event::JoystickButtonPressed || Event.type == sf::Event::JoystickMoved || Event.type == sf::Event::MouseMoved) { if (!menu.ProcessInput(Event, modifierKeys)) level.ProcessInput(Event, modifierKeys); } else if (Event.type == sf::Event::KeyReleased || Event.type == sf::Event::MouseButtonReleased || Event.type == sf::Event::JoystickButtonReleased) { menu.ProcessInput(Event, modifierKeys); level.ProcessInput(Event, modifierKeys); } } float time = clock.getElapsedTime().asSeconds(); clock.restart(); drawTime += time; updateTime += time; menu.Update(); if (!menu.GamePaused()) { if (updateTime > updateInterval) { level.Update(time); level.CheckCollision(); updateTime = 0; } } if (drawTime > drawInterval) { window.clear(); level.Draw(&window); r.Draw(&window); window.display(); drawTime -= drawInterval; } } return EXIT_SUCCESS; }
void CreateScene (NewtonWorld* world, SceneManager* sceneManager) { Entity* floor; NewtonBody* floorBody; NewtonCollision* shape; void* materialManager; SoundManager* sndManager; PhysicsMaterialInteration matInterations; sndManager = sceneManager->GetSoundManager(); // Create the material for this scene, and attach it to the Newton World materialManager = CreateMaterialManager (world, sndManager); // add the Material table matInterations.m_restitution = 0.6f; matInterations.m_staticFriction = 0.6f; matInterations.m_kineticFriction = 0.3f; matInterations.m_scrapingSound = NULL; matInterations.m_impactSound = sndManager->LoadSound ("metalMetal.wav"); AddMaterilInteraction (materialManager, m_metal, m_metal, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("boxBox.wav"); AddMaterilInteraction (materialManager, m_wood, m_wood, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("metalBox.wav"); AddMaterilInteraction (materialManager, m_metal, m_wood, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("grass0.wav"); AddMaterilInteraction (materialManager, m_wood, m_grass, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("boxHit.wav"); AddMaterilInteraction (materialManager, m_wood, m_bricks, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("grass1.wav"); AddMaterilInteraction (materialManager, m_metal, m_grass, &matInterations); matInterations.m_impactSound = sndManager->LoadSound ("metal.wav"); AddMaterilInteraction (materialManager, m_metal, m_bricks, &matInterations); // Create a large body to be the floor floor = sceneManager->CreateEntity(); // add scene collision from a level mesh int materialMap[] = {m_bricks, m_grass, m_wood, m_metal}; shape = CreateHeightFieldCollision (world, "h2.raw", materialMap); floorBody = CreateRigidBody (world, floor, shape, 0.0f); NewtonDestroyCollision(shape); // make a visual mesh for the collision data CreateHeightFieldMesh (shape, floor); // set the matrix at the origin dVector boxP0; dVector boxP1; dMatrix matrix (floor->m_curRotation, floor->m_curPosition); NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); // place the origin of the visual mesh at the center of the height field matrix.m_posit = (boxP0 + boxP1).Scale (-0.5f); matrix.m_posit.m_w = 1.0f; floor->m_curPosition = matrix.m_posit; floor->m_prevPosition = matrix.m_posit; // relocate the body; NewtonBodySetMatrix (floorBody, &matrix[0][0]); // now we will use the properties of this body to set a proper world size. NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); // add some extra padding boxP0.m_x -= 50.0f; boxP0.m_y -= 500.0f; boxP0.m_z -= 50.0f; boxP1.m_x += 50.0f; boxP1.m_y += 500.0f; boxP1.m_z += 50.0f; // set the new world size NewtonSetWorldSize (world, &boxP0[0], &boxP1[0]); // add some visual entities. dFloat y0 = FindFloor (world, 0.0f, 0.0f) + 2.0f; for (int i = 0; i < 1; i ++) { Entity* carEnt; NewtonBody* carBody; NewtonUserJoint* carController; carEnt = sceneManager->CreateEntity(); carEnt->LoadMesh ("porche.dat"); carEnt->m_curPosition.m_y = y0; y0 += 2.0f; carEnt->m_prevPosition = carEnt->m_curPosition; // add a body with a box shape shape = CreateNewtonBox (world, carEnt, m_metal); // the mass is the Car weight divide by the Gravity carBody = CreateRigidBody (world, carEnt, shape, CAR_WEIGHT / 10.0f); NewtonDestroyCollision(shape); // Now create a RayCast Car for to control this body carController = CreateRayCastCast (carBody, sceneManager, porcheTirePositions); } y0 = FindFloor (world, 4.0f, 0.0f) + 2.0f; for (int i = 0; i < 1; i ++) { Entity* carEnt; NewtonBody* carBody; NewtonUserJoint* carController; carEnt = sceneManager->CreateEntity(); carEnt->LoadMesh ("cadillac.dat"); carEnt->m_curPosition.m_z = 4.0f; carEnt->m_curPosition.m_y = y0; y0 += 2.0f; carEnt->m_prevPosition = carEnt->m_curPosition; // add a body with a box shape shape = CreateNewtonBox (world, carEnt, m_metal); // the mass is the Car weight divide by the Gravity carBody = CreateRigidBody (world, carEnt, shape, CAR_WEIGHT / 10.0f); NewtonDestroyCollision(shape); // Now create a RayCast Car for to control this body carController = CreateRayCastCast (carBody, sceneManager, cadillackirePositions); } // initialize the camera InitCamera (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f)); }
int main(int argc, char* argv[]) { PHYSFS_init(argv[0]); setupPHYSFS(); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); SDL_EnableUNICODE(1); atexit(SDL_Quit); srand(SDL_GetTicks()); // Default is OpenGL and false // choose renderer RenderManager *rmanager = 0; SoundManager *smanager = 0; try { UserConfig gameConfig; gameConfig.loadFile("config.xml"); TextManager::createTextManager(gameConfig.getString("language")); if(gameConfig.getString("device") == "SDL") rmanager = RenderManager::createRenderManagerSDL(); else if (gameConfig.getString("device") == "GP2X") rmanager = RenderManager::createRenderManagerGP2X(); else if (gameConfig.getString("device") == "OpenGL") rmanager = RenderManager::createRenderManagerGL2D(); else { std::cerr << "Warning: Unknown renderer selected!"; std::cerr << "Falling back to OpenGL" << std::endl; rmanager = RenderManager::createRenderManagerGL2D(); } // fullscreen? if(gameConfig.getString("fullscreen") == "true") rmanager->init(800, 600, true); else rmanager->init(800, 600, false); if(gameConfig.getString("show_shadow") == "true") rmanager->showShadow(true); else rmanager->showShadow(false); SpeedController scontroller(gameConfig.getFloat("gamefps")); SpeedController::setMainInstance(&scontroller); scontroller.setDrawFPS(gameConfig.getBool("showfps")); smanager = SoundManager::createSoundManager(); smanager->init(); smanager->setVolume(gameConfig.getFloat("global_volume")); smanager->setMute(gameConfig.getBool("mute")); smanager->playSound("sounds/bums.wav", 0.0); smanager->playSound("sounds/pfiff.wav", 0.0); std::string bg = std::string("backgrounds/") + gameConfig.getString("background"); if (PHYSFS_exists(bg.c_str())) rmanager->setBackground(bg); InputManager* inputmgr = InputManager::createInputManager(); if (argc == 3) { if (strstr(argv[1], ".lua")) { gameConfig.setString("left_player_human", "false"); gameConfig.setString("left_script_name", argv[1]); } else { gameConfig.setString("left_player_human", "true"); gameConfig.setString("left_player_name", argv[1]); } if (strstr(argv[2], ".lua")) { gameConfig.setString("right_player_human", "false"); gameConfig.setString("right_script_name", argv[2]); } else { gameConfig.setString("right_player_human", "true"); gameConfig.setString("right_player_name", argv[2]); } gameConfig.saveFile("config.xml"); State::setCurrentState(new LocalGameState(), true); } int running = 1; while (running) { inputmgr->updateInput(); running = inputmgr->running(); // This is true by default for compatibility, GUI states may // disable it if necessary rmanager->drawGame(true); IMGUI::getSingleton().begin(); State::getCurrentState()->step(); rmanager = &RenderManager::getSingleton(); //RenderManager may change //draw FPS: if (scontroller.getDrawFPS()) { // We need to ensure that the title bar is only set // when the framerate changed, because setting the // title can ne quite resource intensive on some // windows manager, like for example metacity. static int lastfps = 0; int newfps = scontroller.getFPS(); if (newfps != lastfps) { std::stringstream tmp; tmp << AppTitle << " FPS: " << newfps; rmanager->setTitle(tmp.str()); } lastfps = newfps; } if (!scontroller.doFramedrop()) { rmanager->draw(); IMGUI::getSingleton().end(); BloodManager::getSingleton().step(); rmanager->refresh(); } scontroller.update(); } } catch (std::exception& e) { std::cerr << e.what() << std::endl; if (rmanager) rmanager->deinit(); if (smanager) smanager->deinit(); SDL_Quit(); PHYSFS_deinit(); exit (EXIT_FAILURE); } deinit(); exit(EXIT_SUCCESS); }
void PlaySpace::update(float time) { if(time > 0.25f) { ParticleBudget = 0; time = 0.25f; } else ParticleBudget = 500; LastDeltaTime = time; GameTime += time; GameFrame += 1; if(!Player) TimeSincePlayerDestruction += time; SoundManager* manager = SoundManager::GetInstance(); manager->setListenerPosition(CameraPos); if(IsStressTesting) time = 1.f / 30; if(!IsStressTesting) for(int i = 0; i < Systems.UsedLength; ++i) { Systems[i]->update(time, this); } for(int i = 0; i < Bullets.UsedLength; ++i) { if(Bullets[i].canBeDespawned()) Bullets.quickRemove(i--); } for(int i = 0; i < Particles.UsedLength; ++i) { if(Particles[i].canBeDespawned()) Particles.quickRemove(i--); } for(int i = 0; i < Ships.UsedLength; ++i) { if(Ships[i]->canBeDespawned()) { ObjectPointer<Ship>(Ships[i]).destroy(); // Object pointer lets other object pointers know that the object got deleted. Objects.quickRemove(Objects.findIndex(Ships[i])); Ships.quickRemove(i--); } } for(PhysicsObject* obj : Objects) obj->update(time, this); for(GravitySource& src : GravitySources) src.update(time, this); for(Bullet& obj : Bullets) obj.update(time, this); // The more particles exist the faster time passes for them, the faster they die float particleTimeFactor = Max(float(Particles.UsedLength) / SoftMaxParticleCount, 1.0f); for(Particle& particle : Particles) particle.update(time * particleTimeFactor, this); // Physics for(PhysicsObject* obj : Objects) applyPhysics(obj, time); for(Bullet& obj : Bullets) applyPhysics(&obj, time); for(Particle& particle : Particles) applyPhysics(&particle, time * particleTimeFactor); // Add gravity for(GravitySource& src : GravitySources) { float start = src.Position.X - src.Range*2; float end = src.Position.X + src.Range*2; for(auto* obj : Objects) src.influence(obj, time); for(auto& obj : Bullets) src.influence(&obj, time); for(auto& obj : Particles) src.influence(&obj, time); } for(Bullet& bullet : Bullets) for(Ship* ship : Ships) if(ship->Faction != bullet.Faction) if(ship->Status != Ship::Destroyed) if(IsIntersecting(bullet.Bounds, ship->Bounds)) ship->onHit(&bullet, this); if(Player) { CameraPos = Player->Position; Renderer.Context.Camera.Position = CameraPos; // Will be reset to true before next PlaySpace::update Player->IsShooting = false; Player->IsShootingSecondary = false; Player->IsBraking = false; Player->IsStabilizing = false; Player->IsBoosting = false; Player->Steering = 0.0f; if(!IsStressTesting) { checkSectorGeneration(Player->Position); checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead, 0)); checkSectorGeneration(Player->Position + Vec2F(0, SectorLookAhead)); checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead, 0)); checkSectorGeneration(Player->Position - Vec2F(0, SectorLookAhead)); checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead)); checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead)); checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead/2, 0)); checkSectorGeneration(Player->Position + Vec2F(0, SectorLookAhead/2)); checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead/2, 0)); checkSectorGeneration(Player->Position - Vec2F(0, SectorLookAhead/2)); checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead/2)); checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead/2)); } } ParticleBudget = 0; if(Music->isFinished()){ Music->setOffset(0); Music->resume(); }; }
void Application::init() { // The very first thing to do is to add the current directory in DynamicObjectManager's list of repositories // In case some modules would need to load some config files shared_ptr<ISource> loadChannel(new SourceFile(".", false)); shared_ptr<ISource> saveChannel(new SourceFile(".", true)); DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr(); SoundManager *soundManager = SoundManager::getInstancePtr(); GNOLL_LOG() << "Adding load/save source for current path to the DynamicObjectManager\n"; pom->addLoadSource(loadChannel); pom->addSaveSource(saveChannel); GNOLL_LOG() << "Adding load/save source for current path to the SoundManager\n"; soundManager->addLoadSource(loadChannel); soundManager->addSaveSource(saveChannel); /** * Now program options have been parsed, * program is initialized */ GNOLL_LOG() << "Instanciating modules...\n"; logModule = CLogModule::getInstancePtr(); graphicmanager = CGraphicModule::getInstancePtr(); timeModule = CTimeModule::getInstancePtr(); messageModule = CMessageModule::getInstancePtr(); soundmanager = CSoundModule::getInstancePtr(); inputEventsTranslator = CInputEventsTranslator::getInstancePtr(); statsModule = CStatsModule::getInstancePtr(); GNOLL_LOG() << "Instanciating modules...[DONE]\n"; try { GNOLL_LOG() << "Initializing message module\n"; messageModule->init(); GNOLL_LOG() << "Initializing message module [DONE]\n"; GNOLL_LOG() << "Initializing graphic module\n"; graphicmanager->init(); GNOLL_LOG() << "Initializing graphic module [DONE]\n"; GNOLL_LOG() << "Initializing input manager\n"; inputmanager.init(); GNOLL_LOG() << "Initializing input manager [DONE]\n"; GNOLL_LOG() << "Initializing sound manager\n"; soundmanager->init(); GNOLL_LOG() << "Initializing sound manager [DONE]\n"; GNOLL_LOG() << "Initializing time module\n"; timeModule->init(); GNOLL_LOG() << "Initializing time module [DONE]\n"; GNOLL_LOG() << "Initializing input event translator\n"; inputEventsTranslator->init(); GNOLL_LOG() << "Initializing input event translator [DONE]\n"; GNOLL_LOG() << "Initializing stats module\n"; statsModule->init(); GNOLL_LOG() << "Initializing stats module [DONE]\n"; } catch (Glib::ustring str) { cout << str << endl; } /* * Define the listener of the application * like the message on quit */ shared_ptr<Gnoll::ApplicationListener> listenerInput = shared_ptr<Gnoll::ApplicationListener>( new Gnoll::ApplicationListener()); messageModule->getMessageManager()->addListener ( listenerInput, Messages::MessageType(Gnoll::Input::ACTION_EVENT_TYPE) ); /** * Define the listener for the button */ CEGUI::PushButton *button_quit; button_quit = (CEGUI::PushButton *) CEGUI::WindowManager::getSingleton().getWindow("buttonQuit"); button_quit->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&Application::quit_OnClick, this)); }
void Application::analyzeArguments (int argc, char* argv[]) { // Declare the supported options. options_description desc("Allowed options"); desc.add_options() ("help,h", "Produce help message") ("log,l", value<std::string>(), "Log file name") ("load-source-directory", value< vector<string> >()->composing(), "Add a directory as a load source") ("save-source-directory", value< vector<string> >()->composing(), "Add a directory as a save source") ; variables_map vm; store(parse_command_line(argc, argv, desc), vm); notify(vm); /** * If help is required * -> Display usage * -> Exit */ if (vm.count("help")) { cout << desc; ::exit(1); } CLogModule *logModule = CLogModule::getInstancePtr(); if (vm.count("log")) { std::string logFile = vm["log"].as<std::string>(); logModule->setLogFileName(logFile); } logModule->init(); DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr(); SoundManager *soundManager = SoundManager::getInstancePtr(); CameraManager *cameraManager = CameraManager::getInstancePtr(); /** * If a loading source has to be added */ if (vm.count("load-source-directory")) { vector<string> lsd = vm["load-source-directory"].as< vector<string> >(); for (vector<string>::iterator it = lsd.begin(); it != lsd.end(); it++) { GNOLL_LOG() << "Adding new load source directory : \n"; shared_ptr<ISource> userLoadChannel(new SourceFile(*it, false, 10)); pom->addLoadSource(userLoadChannel); soundManager->addLoadSource(userLoadChannel); cameraManager->addLoadSource(userLoadChannel); } } /** * If a saving source has to be added */ if (vm.count("save-source-directory")) { vector<string> lsd = vm["save-source-directory"].as< vector<string> >(); for (vector<string>::iterator it = lsd.begin(); it != lsd.end(); it++) { GNOLL_LOG() << "Adding new save source directory : \n"; shared_ptr<ISource> userSaveChannel(new SourceFile( *it, true, 10 )); pom->addSaveSource(userSaveChannel); soundManager->addSaveSource(userSaveChannel); cameraManager->addLoadSource(userSaveChannel); } } }
int main() { sf::RenderWindow window(sf::VideoMode(1920, 1080), "Corgi Movement Simulator"); /*sf::CircleShape shape(100.f); shape.setFillColor(sf::Color::Green);*/ /*sf::Texture texture; texture.loadFromFile("Sprites/Scene10x10.png"); texture.setSmooth(true); sf::Sprite* sprite = (new sf::Sprite(texture));*/ //(*sprite).setColor(sf::Color(128, 128, 128)); //testlvlManager sf::Texture shibe; if (!shibe.loadFromFile("Sprites/Units/shibe_spread.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } Animation shibe_idle; shibe_idle.setSpriteSheet(shibe); shibe_idle.addFrame(sf::IntRect(0, 0, 128, 128)); shibe_idle.addFrame(sf::IntRect(128, 0, 128, 128)); shibe_idle.addFrame(sf::IntRect(256, 0, 128, 128)); shibe_idle.addFrame(sf::IntRect(384, 0, 128, 128)); AnimatedSprite animatedShibe(sf::seconds(0.2), false, true); animatedShibe.setPosition(0,0); animatedShibe.play(shibe_idle); TextureManager texMng; texMng.getFiles(); texMng.createTextures(); lvlManager lvl; Block b = lvl.generateTiles(lvl.buildKey(&texMng), &texMng); lvl.genMap(b, 0, 15); for (int i = 0; i < 50; i++){ Block b = lvl.generateTiles(lvl.buildKey(&texMng), &texMng); sf::Vector2<int> v = lvl.findNextSpot(b.x, b.y); if (v.x != -1) lvl.genMap(b, v.x, v.y); } SoundManager sM; sM.getFiles(); sM.createSounds(); Player p(&texMng, &(sM.soundTable.at("bark")), sf::Sprite()); //Unit test_unit(10, 10, *sprite); //Tile test(sprite, &test_unit); sf::Sprite output; lvl.genDrawable(&output); UIManager uimanager; uimanager.setTerrain(output); //uimanager.setTerrain(lvl.genDrawable()); int mousex=0, mousey=0; //lvl.testTileGen(&texMng, &window); //testTextureManager(&window); UnitManager uM(&lvl, &texMng, &p, &sM); uM.spawnUnit(doge, p.playerUnit->x + 1, p.playerUnit->y); uM.spawnUnit(turtle, p.playerUnit->x, p.playerUnit->y + 1); std::cout << p.playerUnit->x + 1 << p.playerUnit->y + 1 << std::endl; uM.gatherActions(); sf::Clock frameClock; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) window.close(); if (event.type == sf::Event::MouseButtonPressed) { mousex = sf::Mouse::getPosition(window).x; mousey = sf::Mouse::getPosition(window).y; } if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && event.type == sf::Event::MouseMoved) { uimanager.x += event.mouseMove.x-mousex; uimanager.y += event.mouseMove.y-mousey; mousex = event.mouseMove.x; mousey = event.mouseMove.y; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::P)) { uM.gatherActions(); } if (event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Button::Right) { std::cout << "clicked at " << sf::Mouse::getPosition(window).x-uimanager.x << " " << sf::Mouse::getPosition(window).y-uimanager.y << std::endl; //std::cout << "is accessible: " << lvl.isAccessible(sf::Mouse::getPosition(window).x - uimanager.x, sf::Mouse::getPosition(window).y - uimanager.y) << std::endl; int xPos = sf::Mouse::getPosition(window).x - uimanager.x; int yPos = sf::Mouse::getPosition(window).y - uimanager.y; //std::cout << lvl.map[xPos / 128][yPos / 128].pawn << std::endl; if (lvl.isAccessible(xPos, yPos)) { uM.interact(xPos/128, yPos/128, &p); std::cout << xPos/128 << yPos/128 << std::endl; std::cout << "great success !" << std::endl; } else std::cout << "no" << std::endl; } /* Zooming - Experimental if (event.type == sf::Event::MouseWheelScrolled) { uimanager.scale = signbit(event.mouseWheelScroll.delta)?uimanager.scale*0.95:uimanager.scale*1.05; }*/ } //UI Movement if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) uimanager.y += 1; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) uimanager.y -= 1; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) uimanager.x += 1; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) uimanager.x -= 1; if (sf::Mouse::getPosition(window).x < 20) uimanager.x += 1; if (sf::Mouse::getPosition(window).x > 1900) uimanager.x -= 1; if (sf::Mouse::getPosition(window).y < 20) uimanager.y += 1; if (sf::Mouse::getPosition(window).y > 1060) uimanager.y -= 1; // lvl.genDrawable(&output); // UIManager uimanager; // uimanager.setTerrain(output); sf::Time frameTime = frameClock.restart(); animatedShibe.update(frameTime); window.clear(); //sf::Sprite output2; //lvl.drawUnits(&output); //uimanager.setUnits(output2); //window.draw(*(uimanager.getUI())); //window.draw(*(uimanager.getUnits())); uimanager.setUnits(uM.getUnits()); uimanager.drawEverything(&window); window.draw(animatedShibe); //window.draw(*sprite); //window.draw(output); /*sf::Texture texture; texture.loadFromFile("Sprites\\PlayerChar.png"); texture.setSmooth(true); sf::Sprite* sprite = (new sf::Sprite(texture)); (*sprite).setColor(sf::Color(128, 128, 128)); sprite.setTexture(texture);*/ //window.draw(*sprite); //std::cout << "Current player AP: " << p.playerUnit->currAP << ". Max player AP: " << p.playerUnit->maxAP << "." << std::endl; window.display(); } return 0; }