// The start of the Application int App::start(const std::vector<CL_String> &args) { sfx_pacman_start = CL_SoundBuffer("../../Game/Pacman/resources/start.wav"); sfx_beast_title = CL_SoundBuffer("Resources/boss.mod"); sfx_cheer = CL_SoundBuffer("Resources/cheer1.ogg"); CL_String theme; if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw CL_Exception("No themes found"); CL_GUIManager gui(theme); CL_DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("Sound Example"); win_desc.set_position(CL_Rect(200, 100, 540, 440), false); win_desc.set_visible(false); CL_Window window(&gui, win_desc); window.func_close().set(this, &App::on_close, &window); CL_GUILayoutCorners layout; window.set_layout(layout); window.create_components("Resources/layout.xml"); prepare_gui(window); window.set_visible(true); set_sound_output(); initial_time = CL_System::get_time(); gui.exec(); return 0; }
void Game::run() { //_________________________________________________________________ // V I D E O S E T T I N G S screen_x_res = 640; screen_y_res = 480; CL_DisplayWindowDescription desc; desc.set_title("Roadgeddon"); desc.set_size(CL_Size(screen_x_res, screen_y_res), true); desc.set_allow_resize(false); CL_DisplayWindow window(desc); CL_Slot slot_quit = window.sig_window_close() .connect(this,&Game::on_quit); CL_Slot slot_keyboard_key_down = (window.get_ic().get_keyboard()).sig_key_down() .connect(this,&Game::on_key_down); CL_Slot slot_keyboard_key_up = (window.get_ic().get_keyboard()).sig_key_up() .connect(this,&Game::on_key_up); CL_Slot slot_mouse_moved = (window.get_ic().get_mouse()).sig_pointer_move() .connect(this,&Game::on_pointer_move); CL_Slot slot_mouse_down = (window.get_ic().get_mouse()).sig_key_down() .connect(this,&Game::on_pointer_down); CL_Slot slot_mouse_up = (window.get_ic().get_mouse()).sig_key_up() .connect(this,&Game::on_pointer_up); gc = window.get_gc(); CL_ResourceManager resources("resources.xml"); resources_=&resources; int time_elapsed_ms = 0; int lastTime = 0; int currentTime = 0; currentTime = CL_System::get_time(); lastTime = CL_System::get_time(); //________________________________________________________________ // S O U N D S total_channels=3; current_channel=1; CL_SoundBuffer music("Music1",&resources); music.set_volume(0.3f); sound_session1.play(); sound_session2.play(); sound_session3.play(); total_samples = 6; samples.resize(total_samples); samples[0] = CL_SoundBuffer("Explosion1",&resources); samples[1] = CL_SoundBuffer("Explosion2",&resources); samples[2] = CL_SoundBuffer("Hurt1",&resources); samples[3] = CL_SoundBuffer("Hurt2",&resources); samples[4] = CL_SoundBuffer("Powerup1",&resources); samples[5] = CL_SoundBuffer("Shoot1",&resources); for(int i = 0; i<total_samples; i++) { samples[i].set_volume(0.3f); } CL_SoundBuffer_Session music_session = music.prepare(); music_session_ = &music_session; music_session.set_looping(true); music_session.play(); is_music_muted = false; //________________________________________________________________ // G A M E P R E P Map map(*this); Player player(*this); mapP = ↦ playerP = &player; time_elapsed_since_last_enemy=0; //________________________________________________________________ // O T H E R srand(CL_System::get_time()); while (!quit) { currentTime = CL_System::get_time(); time_elapsed_ms = currentTime - lastTime; lastTime = currentTime; update_game(time_elapsed_ms); update_signal.invoke(time_elapsed_ms); map.drawBackground(); draw_signal.invoke(); // Flip the display, showing on the screen what we have drawed since last call to flip() window.flip(1); // This call processes user input and other events CL_KeepAlive::process(0); // Sleep for a little while to avoid using too much of the CPU. CL_System::sleep(5); if(objects_for_deletion.size()>0) { std::list<Gameobject *>::iterator it; for(it=objects_for_deletion.begin(); it!= objects_for_deletion.end(); ++it) { delete (*it); } objects_for_deletion.clear(); } } }