void SoundManager::PlayMusic(int num, bool loop) { DestroyMusic(); if(num==-1) return; else if(num==0) music = al_load_audio_stream("music/menu.ogg", 4, 2048); else if(num==1) music = al_load_audio_stream("music/level1.ogg", 4, 2048); if(music==NULL) { al_show_native_message_box(DisplayManager::GetInstance().GetDisplay(), "Error!", "SoundManager", "Couldn't load music", "ok sok", ALLEGRO_MESSAGEBOX_ERROR); return; } if(music==NULL) return; al_set_audio_stream_loop_secs(music, .0f, al_get_audio_stream_length_secs(music)); if(loop) al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP); else al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_ONCE); al_attach_audio_stream_to_mixer(music, mixer); al_attach_mixer_to_voice(mixer,voice); }
static int allua_audio_stream_set_playmode(lua_State * L) { ALLUA_audio_stream audio_stream = allua_check_audio_stream(L, 1); int val = luaL_checkint(L, 2); lua_pushboolean(L, al_set_audio_stream_playmode(audio_stream, val)); return 1; }
void Audio::PlayMusic( std::string Filename, bool Loop ) { if( audioVoice == 0 || audioMixer == 0 ) { return; } if( musicStream != nullptr ) { StopMusic(); } // Only play if Music is set if( FRAMEWORK->Settings->GetQuickBooleanValue( "Audio.Music", true ) ) { #ifdef WRITE_LOG fprintf( FRAMEWORK->LogFile, "Framework: Start audio file %s\n", Filename.c_str() ); #endif musicStream = al_load_audio_stream( Filename.c_str(), 4, 2048 ); if( musicStream != nullptr ) { al_attach_audio_stream_to_mixer( musicStream, audioMixer ); al_set_audio_stream_playmode( musicStream, ( Loop ? ALLEGRO_PLAYMODE_LOOP : ALLEGRO_PLAYMODE_ONCE ) ); FRAMEWORK->RegisterEventSource( al_get_audio_stream_event_source( musicStream ) ); al_set_audio_stream_playing( musicStream, true ); } else { #ifdef WRITE_LOG fprintf( FRAMEWORK->LogFile, "Framework: Could not load music '%s'\n", Filename.c_str() ); #endif } } }
int main(int argc, char * argv[]) { ALLEGRO_CONFIG *config; ALLEGRO_EVENT event; unsigned buffer_count; unsigned samples; const char *s; initialize(); if (argc < 2) { log_printf("This example needs to be run from the command line.\nUsage: %s {audio_files}\n", argv[0]); goto done; } buffer_count = 0; samples = 0; config = al_load_config_file("ex_stream_seek.cfg"); if (config) { if ((s = al_get_config_value(config, "", "buffer_count"))) { buffer_count = atoi(s); } if ((s = al_get_config_value(config, "", "samples"))) { samples = atoi(s); } al_destroy_config(config); } if (buffer_count == 0) { buffer_count = 4; } if (samples == 0) { samples = 1024; } stream_filename = argv[1]; music_stream = al_load_audio_stream(stream_filename, buffer_count, samples); if (!music_stream) { abort_example("Stream error!\n"); } loop_start = 0.0; loop_end = al_get_audio_stream_length_secs(music_stream); al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end); al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer()); al_start_timer(timer); while (!exiting) { al_wait_for_event(queue, &event); event_handler(&event); } done: myexit(); al_destroy_display(display); close_log(true); return 0; }
bool GameLogic::LoadAssets() { Bitmap.Logo = al_load_bitmap("assets/images/daklutz.png"); Bitmap.Title = al_load_bitmap("assets/images/Bitmap.Title.png"); if(!Bitmap.Title || !Bitmap.Logo) { fprintf(stderr, "Failed to load image files!\n"); return false; } if(Debug) { fprintf(stderr, "Bitmaps loaded.\n"); } // actually load the font, I loaded the same font at different sizes. Font.Small = al_load_font("assets/fonts/Geo-Regular.ttf", 24, 0); Font.Medium = al_load_font("assets/fonts/Geo-Regular.ttf", 38, 0); Font.Big = al_load_font("assets/fonts/Geo-Regular.ttf", 70, 0); if(!Font.Small || !Font.Medium || !Font.Big) { fprintf(stderr, "Failed to load fonts!\n"); return false; } if (!al_reserve_samples(2)) { fprintf(stderr, "Could not reserve samples!\n"); return false; } if(Debug) { fprintf(stderr, "Samples reserved.\n"); } Sound.HitWall = al_load_sample("assets/sounds/wall_collision.ogg"); Sound.HitPaddle = al_load_sample("assets/sounds/paddle_collision.ogg"); Sound.BackgroundMusic = al_load_audio_stream("assets/sounds/Sound.BackgroundMusic-tech.ogg", 4, 2048); if (!Sound.HitWall || !Sound.HitPaddle || !Sound.BackgroundMusic) { fprintf(stderr, "Failed to load sound files!\n"); return false; } if(Debug) { fprintf(stderr, "Sound files loaded.\n"); } if(!al_attach_audio_stream_to_mixer(Sound.BackgroundMusic, Mixer) ) { fprintf(stderr, "Failed to attach stream to default Mixer!\n"); return 1; } if(Debug) { fprintf(stderr, "Stream attached to Mixer.\n"); } if(!al_set_mixer_playing(Mixer, true)) { fprintf(stderr, "Failed to play Mixer!\n"); } if(Debug) { fprintf(stderr, "Mixer playing.\n"); } if(!al_set_audio_stream_playmode(Sound.BackgroundMusic, ALLEGRO_PLAYMODE_LOOP)) { fprintf(stderr, "Failed to loop stream!\n"); } if(Debug) { fprintf(stderr, "Stream is set to loop.\n"); } if(!al_set_audio_stream_playing(Sound.BackgroundMusic, true)) { fprintf(stderr, "Failed to play stream!\n"); } if(Debug) { fprintf(stderr, "Stream playing.\n"); } return true; }
int main(int argc, char * argv[]) { ALLEGRO_CONFIG *config; ALLEGRO_EVENT event; unsigned buffer_count; unsigned samples; const char *s; if (argc < 2) { printf("Usage: ex_stream_seek <filename>\n"); return -1; } if (!initialize()) return 1; buffer_count = 0; samples = 0; config = al_load_config_file("ex_stream_seek.cfg"); if (config) { if ((s = al_get_config_value(config, "", "buffer_count"))) { buffer_count = atoi(s); } if ((s = al_get_config_value(config, "", "samples"))) { samples = atoi(s); } al_destroy_config(config); } if (buffer_count == 0) { buffer_count = 4; } if (samples == 0) { samples = 1024; } stream_filename = argv[1]; music_stream = al_load_audio_stream(stream_filename, buffer_count, samples); if (!music_stream) { printf("Stream error!\n"); return 1; } loop_start = 0.0; loop_end = al_get_audio_stream_length_secs(music_stream); al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end); al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer()); al_start_timer(timer); while (!exiting) { al_wait_for_event(queue, &event); event_handler(&event); } myexit(); return 0; }
void playBGM_Stream(const char *str) { if (!str) return; stream = al_load_audio_stream(str, 2, 1024); if (!stream) return; al_set_audio_stream_playing(stream, true); al_set_audio_stream_playmode(stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(stream, al_get_default_mixer()); }
void AllegroMusicSample5::SetLoopMode( ISample::ELoopMode mode ) { if ( !m_pInstance ) return; ALLEGRO_PLAYMODE alMode = ALLEGRO_PLAYMODE_ONCE; switch( mode ) { case ISample::LOOPMODE_ONCE: alMode = ALLEGRO_PLAYMODE_ONCE; break; case ISample::LOOPMODE_LOOP: alMode = ALLEGRO_PLAYMODE_LOOP; break; } al_set_audio_stream_playmode( m_pInstance, alMode ); }
void playMusicOnce(const char *filename) { /* play music only once in background, terminating old music */ ALLEGRO_PLAYMODE loop = ALLEGRO_PLAYMODE_ONCE; al_stop_samples(); if (music != NULL) { al_drain_audio_stream(music); al_destroy_audio_stream(music); } music = al_load_audio_stream(filename, 4, 2048); al_set_audio_stream_playmode(music, loop); al_attach_audio_stream_to_mixer(music, mixer); }
bool StreamResource::load(void) { if (!al_is_audio_installed()) { debug_message("Skipped loading stream %s\n", filename.c_str()); return true; } stream = al_load_audio_stream(filename.c_str(), 4, 1024); if (!stream) { debug_message("Error creating stream\n"); return false; } al_set_audio_stream_playing(stream, false); al_set_audio_stream_playmode(stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(stream, al_get_default_mixer()); return true; }
void Framework::PlayMusic( std::string Filename, ALLEGRO_PLAYMODE Mode ) { #ifdef WRITE_LOG printf( "Framework: Play Music '%s'\n", Filename.c_str() ); #endif if( voice != 0 ) { musicStream = audioMgr->GetMusic( Filename ); if( musicStream != 0 ) { al_set_audio_stream_playmode( musicStream, Mode ); al_attach_audio_stream_to_mixer( musicStream, mixer ); al_set_audio_stream_playing( musicStream, true ); } else { #ifdef WRITE_LOG printf( "Framework: Could not load music '%s'\n", Filename.c_str() ); #endif } } }
void menuLoop() { bool redraw = true; al_start_timer(timer); al_attach_audio_stream_to_mixer(music, al_get_default_mixer()); al_set_audio_stream_playing(music, true); al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP); while (!menuDone) { ALLEGRO_EVENT event; al_wait_for_event(eventMenuQueue, &event); if (event.type == ALLEGRO_EVENT_TIMER) { redraw = true; //update_logic(); } else if (event.type == ALLEGRO_EVENT_KEY_DOWN) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { menuDone = true; } if (event.keyboard.keycode == ALLEGRO_KEY_DOWN) { changeGameState(Game); } if (event.keyboard.keycode == ALLEGRO_KEY_UP){ changeGameState(Menu); } //get_user_input(); } if (redraw && al_is_event_queue_empty(eventMenuQueue)) { redraw = false; al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_tinted_bitmap(background, al_map_rgba(255, 255, 255, 255), 0, 0, 0); al_draw_text(font, al_map_rgb(0, 0, 0), 0, 0, 0, "BREGA HERO"); //update_graphics(); al_flip_display(); } } }
void playMusic(const char *filename) { /* play music in background, on loop - unpause if music is already playing */ if (isMusicPaused()) { unPauseMusic(); return; } /* music not playing, start over from beginning */ ALLEGRO_PLAYMODE loop = ALLEGRO_PLAYMODE_LOOP; al_stop_samples(); if (music != NULL) { al_drain_audio_stream(music); al_destroy_audio_stream(music); } music = al_load_audio_stream(filename, 4, 2048); al_set_audio_stream_playmode(music, loop); al_attach_audio_stream_to_mixer(music, mixer); }
void set_sound_looping(sound_t* sound, bool is_looping) { al_set_audio_stream_playmode(sound->stream, is_looping ? ALLEGRO_PLAYMODE_LOOP : ALLEGRO_PLAYMODE_ONCE); }
void AudioStream::playmode(ALLEGRO_PLAYMODE playmode) { al_set_audio_stream_playmode(m_stream, playmode); }
stage *initStageWithNumber(int n){ stage *temp = malloc(sizeof(stage)); temp -> stageNum = n; temp -> stageBackground = NULL; temp -> stageAudio = NULL; temp -> bossAudio = NULL; int randomModifier = rand()%100; switch(n){ case 1: temp -> stageBackground = al_load_bitmap("Graphics/BeachSide.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 1\n"); temp -> stageAudio = al_load_audio_stream("Sound/BeachSide.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 1\n"); temp -> bossAudio = al_load_audio_stream("Sound/Marlingone.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 1\n"); al_set_audio_stream_gain(temp -> bossAudio, 1.5); temp -> targetKills = 20; temp -> limitSpawn = 4; break; case 2: temp -> stageBackground = al_load_bitmap("Graphics/RuinedVillage.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 2\n"); temp -> stageAudio = al_load_audio_stream("Sound/RuinedVillage.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 2\n"); temp -> bossAudio = al_load_audio_stream("Sound/Hueda.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 2\n"); temp -> targetKills = 40; temp -> limitSpawn = 5; randomModifier += 30; break; case 3: temp -> stageBackground = al_load_bitmap("Graphics/Macalania.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 3\n"); temp -> stageAudio = al_load_audio_stream("Sound/IceLake.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 3\n"); temp -> bossAudio = al_load_audio_stream("Sound/Cirno.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 3\n"); temp -> targetKills = 70; temp -> limitSpawn = 6; randomModifier += 40; break; case 4: temp -> stageBackground = al_load_bitmap("Graphics/Drangleic.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 4\n"); temp -> stageAudio = al_load_audio_stream("Sound/DrangleicCastle.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 4\n"); temp -> bossAudio = al_load_audio_stream("Sound/GuardianDragon.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 4\n"); temp -> targetKills = 100; temp -> limitSpawn = 6; randomModifier += 80; break; case 5: temp -> stageBackground = al_load_bitmap("Graphics/Moria.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 5\n"); temp -> stageAudio = al_load_audio_stream("Sound/DwarvenRuins.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 5\n"); temp -> bossAudio = al_load_audio_stream("Sound/Balrog.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 5\n"); temp -> targetKills = 100; temp -> limitSpawn = 6; randomModifier += 70; break; case 6: //MISSING OCEAN PALACE!!! temp -> stageBackground = al_load_bitmap("Graphics/BeachSide.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 6\n"); //MISSING OCEAN PALACE HEME!!! temp -> stageAudio = al_load_audio_stream("Sound/BeachSide.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 6\n"); temp -> bossAudio = al_load_audio_stream("Sound/Lavos.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 6\n"); temp -> targetKills = 150; temp -> limitSpawn = 7; randomModifier += 60; break; } if(randomModifier > 100){ temp -> darkPhantom = 30 + n; temp -> darkSpawn = rand()% temp -> targetKills + 1; } else{ temp -> darkPhantom = 0; temp -> darkSpawn = -1; } //temp -> darkPhantom = 30 + n; //temp -> darkSpawn = 1; al_set_audio_stream_playmode(temp -> stageAudio, ALLEGRO_PLAYMODE_LOOP); al_set_audio_stream_playmode(temp -> bossAudio, ALLEGRO_PLAYMODE_LOOP); return temp; }
int main(int argc, char *argv[]) { ALLEGRO_CONFIG *config; ALLEGRO_EVENT event; unsigned buffer_count; unsigned samples; const char *s; ALLEGRO_PLAYMODE playmode = ALLEGRO_PLAYMODE_LOOP; initialize(); if (argc > 1) { stream_filename = argv[1]; } buffer_count = 0; samples = 0; config = al_load_config_file("ex_stream_seek.cfg"); if (config) { if ((s = al_get_config_value(config, "", "buffer_count"))) { buffer_count = atoi(s); } if ((s = al_get_config_value(config, "", "samples"))) { samples = atoi(s); } if ((s = al_get_config_value(config, "", "playmode"))) { if (!strcmp(s, "loop")) { playmode = ALLEGRO_PLAYMODE_LOOP; } else if (!strcmp(s, "once")) { playmode = ALLEGRO_PLAYMODE_ONCE; } } al_destroy_config(config); } if (buffer_count == 0) { buffer_count = 4; } if (samples == 0) { samples = 1024; } music_stream = al_load_audio_stream(stream_filename, buffer_count, samples); if (!music_stream) { abort_example("Stream error!\n"); } al_register_event_source(queue, al_get_audio_stream_event_source(music_stream)); loop_start = 0.0; loop_end = al_get_audio_stream_length_secs(music_stream); al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end); al_set_audio_stream_playmode(music_stream, playmode); al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer()); al_start_timer(timer); while (!exiting) { al_wait_for_event(queue, &event); event_handler(&event); } myexit(); al_destroy_display(display); close_log(true); return 0; }
int main(int argc, char **argv) { const char *filename = "../demos/cosmic_protector/data/sfx/title_music.ogg"; ALLEGRO_VOICE *voice; ALLEGRO_MIXER *mixer; ALLEGRO_AUDIO_STREAM *stream; if (argc > 1) { filename = argv[1]; } if (!al_init()) { abort_example("Could not init Allegro.\n"); return 1; } al_init_primitives_addon(); al_init_image_addon(); al_init_acodec_addon(); al_install_keyboard(); display = al_create_display(640, 480); if (!display) { abort_example("Could not create display.\n"); return 1; } dbuf = al_create_bitmap(640, 480); bmp = al_load_bitmap("data/mysha.pcx"); if (!bmp) { abort_example("Could not load data/mysha.pcx\n"); return 1; } if (!al_install_audio()) { abort_example("Could not init sound.\n"); return 1; } voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); if (!voice) { abort_example("Could not create voice.\n"); return 1; } mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); if (!mixer) { abort_example("Could not create mixer.\n"); return 1; } if (!al_attach_mixer_to_voice(mixer, voice)) { abort_example("al_attach_mixer_to_voice failed.\n"); return 1; } stream = al_load_audio_stream(filename, 4, 2048); if (!stream) { abort_example("Could not load '%s'\n", filename); return 1; } al_set_audio_stream_playmode(stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(stream, mixer); al_set_mixer_postprocess_callback(mixer, update_meter, NULL); main_loop(); al_destroy_audio_stream(stream); al_destroy_mixer(mixer); al_destroy_voice(voice); al_uninstall_audio(); al_destroy_bitmap(dbuf); al_destroy_bitmap(bmp); return 0; }
static void * t3f_play_music_thread(void * arg) { const char * ext = NULL; ALLEGRO_PATH * path = NULL; int loop_points = 0; float loop_start = -1; float loop_end = -1; bool loop_disabled = false; const char * val = NULL; ALLEGRO_CONFIG * config = NULL; ALLEGRO_DEBUG("music thread start\n"); t3f_music_gain = 1.0; al_lock_mutex(t3f_music_mutex); if(t3f_stream) { t3f_stop_music(); } ALLEGRO_DEBUG("setting file interface\n"); al_set_new_file_interface(t3f_music_thread_file_interface); t3f_stream = al_load_audio_stream(t3f_music_thread_fn, 4, 4096); if(!t3f_stream) { al_unlock_mutex(t3f_music_mutex); t3f_set_music_state(T3F_MUSIC_STATE_OFF); return NULL; } ALLEGRO_DEBUG("configuring music\n"); /* look for loop data */ path = al_create_path(t3f_music_thread_fn); if(path) { al_set_path_extension(path, ".ini"); config = al_load_config_file(al_path_cstr(path, '/')); if(config) { val = al_get_config_value(config, "loop", "disabled"); if(val && !strcasecmp(val, "true")) { loop_disabled = true; } if(!loop_disabled) { val = al_get_config_value(config, "loop", "start"); if(val) { loop_start = atof(val); loop_points++; } val = al_get_config_value(config, "loop", "end"); if(val) { loop_end = atof(val); loop_points++; } } val = al_get_config_value(config, "settings", "gain"); if(val) { t3f_music_gain = atof(val); if(t3f_music_gain < 0.0) { t3f_music_gain = 0; } if(t3f_music_gain > 10.0) { t3f_music_gain = 10.0; } } al_destroy_config(config); } al_destroy_path(path); } if(loop_disabled) { al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_ONCE); } else { if(loop_points != 2) { /* loop entire song unless audio is MOD music */ ext = t3f_get_music_extension(t3f_music_thread_fn); if(strcmp(ext, ".xm") && strcmp(ext, ".it") && strcmp(ext, ".mod") && strcmp(ext, ".s3m")) { al_set_audio_stream_loop_secs(t3f_stream, 0.0, al_get_audio_stream_length_secs(t3f_stream)); al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP); } else { al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP); } } else { al_set_audio_stream_loop_secs(t3f_stream, loop_start, loop_end); al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP); } } ALLEGRO_DEBUG("start the music\n"); t3f_music_volume = t3f_new_music_volume; al_set_audio_stream_gain(t3f_stream, t3f_music_volume * t3f_music_gain); al_attach_audio_stream_to_mixer(t3f_stream, al_get_default_mixer()); al_unlock_mutex(t3f_music_mutex); t3f_set_music_state(T3F_MUSIC_STATE_PLAYING); return NULL; }
void InvestigationScene::setupScene() { std::vector<Point> positions; positions.push_back(pointMake(32, 48)); positions.push_back(pointMake(34, 48)); positions.push_back(pointMake(36, 48)); positions.push_back(pointMake(38, 48)); positions.push_back(pointMake(40, 49)); positions.push_back(pointMake(40, 51)); positions.push_back(pointMake(40, 53)); positions.push_back(pointMake(30, 49)); positions.push_back(pointMake(30, 51)); positions.push_back(pointMake(32, 52)); const char *fontFile = "res/AveriaSerif-Regular.ttf"; font = al_load_font(fontFile, 18, 0); if (!font) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", fontFile); } fontBig = al_load_font(fontFile, 26, 0); if (!fontBig) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", fontFile); } searchSound = al_load_sample("res/search.wav"); if (!searchSound) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", "res/search.wav"); } clickSound = al_load_sample("res/click.wav"); if (!clickSound) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", "res/click.wav"); } std::vector<TilemapLayer *> layers = TilemapLayer::parseTMXFile("res/mansion.tmx"); std::vector<TilemapLayer *>::iterator it; TilemapLayer *firstLayer = layers[0]; camera = new Camera(800, 600, firstLayer->getBoundsSize().width, firstLayer->getBoundsSize().height); for (it = layers.begin(); it < layers.end(); ++it) { TilemapLayer *layer = (TilemapLayer *) *it; layer->setCamera(camera); addToDisplayList(layer); if (layer->isCollision()) { collision = layer; } } playerSprite = new Spritesheet("res/professor_walk_cycle_no_hat.png", 64, 64); playerSprite->setTag(PLAYER_SPRITE_TAG); playerSprite->setCamera(camera); playerSprite->setPosition(pointMake(35 * 32, 50 * 32)); playerSprite->setAnchorPoint(pointMake(0.5, 0.9)); playerSprite->setAutoZOrder(true); addToDisplayList(playerSprite); mysterySeed = 0; do { mysteryTime = 0; mysterySeed = time(0); mystery = new Mystery("res/mansion.xml", mysterySeed, collision->getData(), collision->getSize().width, collision->getSize().height); while (!mystery->ended && mysteryTime < MAX_MYSTERY_DURATION) { mystery->step(); mysteryTime++; } if (!mystery->ended) { delete mystery; mystery = NULL; } } while (mystery == NULL); printf("Case seed: %d Total duration: %ld %s\n", mysterySeed, mysteryTime, timeToString(mysteryTime, true).c_str()); std::vector<Character *> characters = mystery->getCharacters(); std::vector<Character *>::iterator itChars; int i = 0; for (itChars = characters.begin(); itChars < characters.end(); ++itChars) { Character *character = (Character *) *itChars; int frame = i * 2; if (!character->dead) { int idx = rand() % positions.size(); Point pos = positions[idx]; character->position = pos; positions.erase(positions.begin() + idx); } else { frame++; } Spritesheet *sprite = new Spritesheet("res/characters.png", 64, 64); sprite->setTag(character->tag); sprite->setCamera(camera); sprite->setAnchorPoint(pointMake(0.5, 0.9)); sprite->setAutoZOrder(true); sprite->setFrame(frame); Rect tileRect = collision->getTileRect(character->position.x, character->position.y); sprite->setPosition(rectMidPoint(tileRect)); addToDisplayList(sprite); i++; } std::vector<POI *>::iterator itWeapons; i = 0; for (itWeapons = mystery->weapons.begin(); itWeapons < mystery->weapons.end(); ++itWeapons) { POI *weapon = (POI *) *itWeapons; Spritesheet *sprite = new Spritesheet("res/weapons.png", 32, 32); sprite->setTag(i + 20); sprite->setFrame(i); sprite->setCamera(camera); sprite->setAnchorPoint(pointMake(0.5, 0.5)); sprite->setZOrder(400); Rect tileRect = collision->getTileRect(weapon->position.x, weapon->position.y); sprite->setPosition(rectMidPoint(tileRect)); addToDisplayList(sprite); i++; } actionButton = new Button("action", font, BTN_TXT_COLOR, "res/btn_action.png", "res/btn_action_pressed.png"); actionButton->setZOrder(500); actionButton->setAnchorPoint(pointMake(0.5, 1)); actionButton->setPosition(pointMake(400, 400)); actionButton->setCamera(camera); actionButton->setHandler(this); addToDisplayList(actionButton); Spritesheet *bkgRoomLabel = new Spritesheet("res/bkg_room_name.png"); bkgRoomLabel->setAnchorPoint(pointMake(0.5, 0.5)); bkgRoomLabel->setPosition(pointMake(400, 40)); bkgRoomLabel->setZOrder(501); addToDisplayList(bkgRoomLabel); currentRoomLabel = new Label("room", font, al_map_rgb(0, 0, 0)); currentRoomLabel->setAnchorPoint(pointMake(0.5, 0.5)); currentRoomLabel->setPosition(bkgRoomLabel->getPosition()); currentRoomLabel->setZOrder(502); addToDisplayList(currentRoomLabel); Spritesheet *bkgWeaponLabel = new Spritesheet("res/bkg_room_name.png"); bkgWeaponLabel->setAnchorPoint(pointMake(0.5, 0.5)); bkgWeaponLabel->setPosition(pointMake(720, 40)); bkgWeaponLabel->setZOrder(501); addToDisplayList(bkgWeaponLabel); crimeWeaponLabel = new Label("No weapon", font, al_map_rgb(0, 0, 0)); crimeWeaponLabel->setAnchorPoint(pointMake(0.5, 0.5)); crimeWeaponLabel->setPosition(bkgWeaponLabel->getPosition()); crimeWeaponLabel->setZOrder(502); addToDisplayList(crimeWeaponLabel); Spritesheet *bkgAccusationLabel = new Spritesheet("res/bkg_room_name.png"); bkgAccusationLabel->setAnchorPoint(pointMake(0.5, 0.5)); bkgAccusationLabel->setPosition(pointMake(80, 40)); bkgAccusationLabel->setZOrder(501); addToDisplayList(bkgAccusationLabel); char buf[100]; sprintf(buf, "%d accusations left", MAX_ACCUSATIONS); accusationsLabel = new Label(buf, font, al_map_rgb(0, 0, 0), 120); accusationsLabel->setAnchorPoint(pointMake(0.5, 0.5)); accusationsLabel->setPosition(bkgAccusationLabel->getPosition()); accusationsLabel->setZOrder(502); addToDisplayList(accusationsLabel); bkgQuestion = new Spritesheet("res/bkg_question.png"); bkgQuestion->setAnchorPoint(pointMake(0.5, 0.5)); bkgQuestion->setPosition(pointMake(400, 300)); bkgQuestion->setZOrder(503); bkgQuestion->setVisible(false); addToDisplayList(bkgQuestion); questionLabel = new Label("question", font, al_map_rgb(0, 0, 0), 350); questionLabel->setAnchorPoint(pointMake(0.5, 0.5)); questionLabel->setPosition(pointMake(400, 120)); questionLabel->setZOrder(504); questionLabel->setVisible(false); addToDisplayList(questionLabel); whenLabel = new Label("00:00 and 00:15", fontBig, al_map_rgb(0, 0, 0)); whenLabel->setAnchorPoint(pointMake(0.5, 0.5)); whenLabel->setPosition(pointMake(400, 300)); whenLabel->setZOrder(504); whenLabel->setVisible(false); addToDisplayList(whenLabel); askQuestionButton = new Button("Ask", font, BTN_TXT_COLOR, "res/btn_med.png", "res/btn_med_pressed.png"); askQuestionButton->setZOrder(504); askQuestionButton->setAnchorPoint(pointMake(0.5, 0.5)); askQuestionButton->setPosition(pointMake(480, 490)); askQuestionButton->setHandler(this); askQuestionButton->setVisible(false); askQuestionButton->setEnabled(false); addToDisplayList(askQuestionButton); cancelQuestionButton = new Button("Cancel", font, BTN_TXT_COLOR, "res/btn_med.png", "res/btn_med_pressed.png"); cancelQuestionButton->setZOrder(504); cancelQuestionButton->setAnchorPoint(pointMake(0.5, 0.5)); cancelQuestionButton->setPosition(pointMake(300, 490)); cancelQuestionButton->setHandler(this); cancelQuestionButton->setVisible(false); cancelQuestionButton->setEnabled(false); addToDisplayList(cancelQuestionButton); bkgSpeech = new Spritesheet("res/speech.png"); bkgSpeech->setAnchorPoint(pointMake(0.35, 1)); bkgSpeech->setCamera(camera); bkgSpeech->setZOrder(503); bkgSpeech->setVisible(false); addToDisplayList(bkgSpeech); speechLabel = new Label("speech", font, al_map_rgb(0, 0, 0), 280); speechLabel->setAnchorPoint(pointMake(0.5, 0.5)); speechLabel->setCamera(camera); speechLabel->setZOrder(504); speechLabel->setVisible(false); addToDisplayList(speechLabel); speechCountLabel = new Label("1/1", font, al_map_rgb(0, 0, 0)); speechCountLabel->setAnchorPoint(pointMake(1, 0.5)); speechCountLabel->setCamera(camera); speechCountLabel->setZOrder(504); speechCountLabel->setVisible(false); addToDisplayList(speechCountLabel); speechButton = new Button(bkgSpeech->getFrameSize()); speechButton->setAnchorPoint(bkgSpeech->getAnchorPoint()); speechButton->setCamera(camera); speechButton->setZOrder(504); speechButton->setEnabled(false); speechButton->setHandler(this); addToDisplayList(speechButton); camera->setCenter(playerSprite->getPosition()); activeCharacter = NULL; activePOI = NULL; currentRoom = NULL; crimeWeapon = NULL; accusationsLeft = MAX_ACCUSATIONS; questionsAsked = 0; moving = pointMake(0, 0); moveDir = 0; curFrame = 0; endScene = false; debug = false; currentFilter.timeStart = 0; currentFilter.timeEnd = QUESTION_INTERVAL; std::string msg; msg.append(mystery->victim->name); msg.append("'s body was found around "); msg.append(timeToString(mystery->corpseFoundTime + START_TIME, false)); msg.append(" in the "); msg.append(mystery->corpseFoundRoom->name); msg.append("."); ModalDialog *dialog = new ModalDialog(msg.c_str(), font, "OK", NULL); dialog->setHandler(this); dialog->showInScene(this, 1000); music = al_load_audio_stream("res/mystery.ogg", 4, 2048); al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(music, al_get_default_mixer()); inDialogue = false; inputLocked = true; investigationStartTime = time(0); }