void ChangeState(int &state, int newState) { if (state == TITLE){} else if (state == PLAYING) { for (iter = objects.begin(); iter != objects.end(); ++iter) { if ((*iter)->GetID() != TRACTOR && (*iter)->GetID() != MISC) (*iter)->SetAlive(false); } } else if (state == LOST){} state = newState; if (state == TITLE) al_play_sample_instance(songInstance); else if (state == PLAYING) { tractor->Init(); al_stop_sample_instance(songInstance); al_stop_sample_instance(songInstance3); al_play_sample_instance(songInstance2); } else if (state == LOST) { al_stop_sample_instance(songInstance2); al_play_sample_instance(songInstance3); } }
bool AllegroSoundSample5::Stop() { if ( !m_pInstance ) return false; return al_stop_sample_instance( m_pInstance ); }
void bgm_stop() { if (bgm_id == -1) return; al_stop_sample_instance(bgm_channel); SampleIter it = samples.find(bgm_id); al_destroy_sample(it->second); samples.erase(it); bgm_id = -1; }
/* Function: al_stop_samples */ void al_stop_samples(void) { unsigned int i; for (i = 0; i < _al_vector_size(&auto_samples); i++) { ALLEGRO_SAMPLE_INSTANCE **slot = _al_vector_ref(&auto_samples, i); ALLEGRO_SAMPLE_INSTANCE *spl = (*slot); al_stop_sample_instance(spl); } }
void Gamestate_Unload(struct Game *game, struct MenuResources* data) { al_stop_sample_instance(data->music); al_destroy_bitmap(data->bg); al_destroy_bitmap(data->title); al_destroy_bitmap(data->monster); al_destroy_font(data->font); //al_destroy_sample_instance(data->music); al_destroy_sample_instance(data->click); //al_destroy_sample(data->sample); al_destroy_sample(data->click_sample); }
void stopMusic(Music *music) { if (!music) return; ALLEGRO_SAMPLE_INSTANCE *instance = music->getInstance(); if (instance) { al_stop_sample_instance(instance); if (music == currentMusic) currentMusic = NULL; } }
void play(double id) { // try to get the sample SampleIter it = samples.find(id); if (it == samples.end()) { cout << "could not find sample: " << id << endl; return; } // play, adding to play stack current_channel = (current_channel+1) % SAMPLE_MAX; al_stop_sample_instance( effects[current_channel] ); al_set_sample( effects[current_channel], it->second ); al_play_sample_instance( effects[current_channel] ); }
/* Stop any sample instances which are still playing a sample buffer which * is about to be destroyed. */ static void stop_sample_instances_helper(void *object, void (*func)(void *), void *userdata) { ALLEGRO_SAMPLE_INSTANCE *splinst = object; /* This is ugly. */ if (func == (void (*)(void *)) al_destroy_sample_instance && al_get_sample_data(al_get_sample(splinst)) == userdata && al_get_sample_instance_playing(splinst)) { al_stop_sample_instance(splinst); } }
bool Type(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { struct GamestateResources *data = TM_GetArg(action->arguments, 0); if (state == TM_ACTIONSTATE_RUNNING) { strncpy(data->text, text, data->pos++); data->text[data->pos] = 0; if (strcmp(data->text, text) != 0) { TM_AddBackgroundAction(data->timeline, Type, TM_AddToArgs(NULL, 1, data), 60 + rand() % 60, "type"); } else{ al_stop_sample_instance(data->kbd); } return true; } return false; }
void GameMenu::processEvent(ALLEGRO_EVENT& event) { if(event.type == ALLEGRO_EVENT_KEY_DOWN){ if(!event.keyboard.repeat){ if(event.keyboard.keycode == ALLEGRO_KEY_UP|| event.keyboard.keycode == ALLEGRO_KEY_LEFT) { up(); } if(event.keyboard.keycode == ALLEGRO_KEY_DOWN|| event.keyboard.keycode == ALLEGRO_KEY_RIGHT) { down(); } if(event.keyboard.keycode == ALLEGRO_KEY_ENTER) { if(selected == start) { al_stop_sample_instance(GFX::introInstance); al_play_sample_instance(GFX::herewegoInstance); quit = true; reset(); GameSwitch::alternateWorld(1); } if(selected == highscore) { al_play_sample_instance(GFX::oneupInstance); quit = true; reset(); GameSwitch::alternateWorld(3); } if(selected == option) { al_play_sample_instance(GFX::oneupInstance); quit = true; reset(); GameSwitch::alternateWorld(5); } if(selected == exit) { al_play_sample_instance(GFX::oneupInstance); quit = true; } } } } }
/* Function: al_stop_sample */ void al_stop_sample(ALLEGRO_SAMPLE_ID *spl_id) { int *id; ASSERT(spl_id->_id != -1); ASSERT(spl_id->_index < (int) _al_vector_size(&auto_samples)); ASSERT(spl_id->_index < (int) _al_vector_size(&auto_sample_ids)); id = _al_vector_ref(&auto_sample_ids, spl_id->_index); if (*id == spl_id->_id) { ALLEGRO_SAMPLE_INSTANCE **slot, *spl; slot = _al_vector_ref(&auto_samples, spl_id->_index); spl = (*slot); al_stop_sample_instance(spl); } }
void t3f_clear_sample_queue(void) { int i; for(i = 0; i < T3F_MAX_QUEUED_SAMPLES; i++) { t3f_sample_queue[i] = NULL; } t3f_queued_samples = 0; if(al_get_sample_instance_playing(t3f_queue_sample_instance)) { al_stop_sample_instance(t3f_queue_sample_instance); al_destroy_sample_instance(t3f_queue_sample_instance); t3f_queue_sample_instance = NULL; } }
ScreenMain::~ScreenMain() { if(background != nullptr) al_destroy_bitmap(background); for(int a = 0;a < (int)buttons.size();a++) { delete buttons[a]; } buttons.clear(); if(SCAbout != nullptr) delete SCAbout; if(SCPlay != nullptr) delete SCPlay; if(SCGame != nullptr) delete SCGame; if(raycallback != nullptr) delete raycallback; if(colider != nullptr) delete colider; if(zemak_bitmap != nullptr) al_destroy_bitmap(zemak_bitmap); if(zemak_button != nullptr) delete zemak_button; if(hlasky_font != nullptr) al_destroy_font(hlasky_font); al_stop_sample_instance(intro_music_instance); al_detach_sample_instance(intro_music_instance); if(intro_music_instance != nullptr) al_destroy_sample_instance(intro_music_instance); if(intro_music != nullptr) al_destroy_sample(intro_music); /*for(int a = 0;a < (int)hlasky.size();a++) { global::audio_player->Stop_sample_instance(&hlasky[a]->instance); al_destroy_sample(hlasky[a]->sample); al_destroy_sample_instance(hlasky[a]->instance); delete hlasky[a]; } hlasky.clear();*/ }
/* the main music player function */ static void music_player() { int i, note; for (i=0; i<NUM_PARTS; i++) { if (part_time[i] <= 0) { note = part_pos[i][0]; part_time[i] = part_pos[i][1]; al_stop_sample_instance(part_voice[i]); if (i == 3) { if (note == 1) { al_set_sample(part_voice[i], bd); al_set_sample_instance_pan(part_voice[i], PAN(128)); } else if (note == 2) { al_set_sample(part_voice[i], snare); al_set_sample_instance_pan(part_voice[i], PAN(160)); } else { al_set_sample(part_voice[i], hihat); al_set_sample_instance_pan(part_voice[i], PAN(96)); } al_play_sample_instance(part_voice[i]); } else { if (note > 0) { al_set_sample_instance_speed(part_voice[i], freq_table[note]/22050.0); al_play_sample_instance(part_voice[i]); } } part_pos[i] += 2; if (!part_pos[i][1]) part_pos[i] = part_ptr[i]; } part_time[i]--; } }
void Menu_Stop(struct Game* game) { FadeGameState(game, false); al_stop_sample_instance(game->menu.music); al_stop_sample_instance(game->menu.rain_sound); }
void stopBGM() { if (!bgmInstance) return; al_stop_sample_instance(bgmInstance); }
void Audio::StopMusic(){ //// STOP BACKGROUND MUSIC al_stop_sample_instance(MusicInstance); };
static int allua_sample_instance_stop(lua_State * L) { ALLUA_sample_instance si = allua_check_sample_instance(L, 1); lua_pushboolean(L, al_stop_sample_instance(si)); return 1; }
void Gamestate_Stop(struct Game *game, struct dosowiskoResources* data) { al_stop_sample_instance(data->sound); }
int main(int argc, char **argv) { ALLEGRO_VOICE *voice; ALLEGRO_MIXER *mixer; ALLEGRO_SAMPLE_INSTANCE *sample; int i; char const **filenames; int n; if (argc < 2) { n = 1; filenames = malloc(sizeof *filenames); filenames[0] = "data/testing.ogg"; } else { n = argc - 1; filenames = malloc(sizeof *filenames * n); for (i = 1; i < argc; ++i) { filenames[i - 1] = argv[i]; } } if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log(); al_init_acodec_addon(); if (!al_install_audio()) { abort_example("Could not init sound!\n"); } voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); if (!voice) { abort_example("Could not create ALLEGRO_VOICE.\n"); } mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); if (!mixer) { abort_example("al_create_mixer failed.\n"); } if (!al_attach_mixer_to_voice(mixer, voice)) { abort_example("al_attach_mixer_to_voice failed.\n"); } sample = al_create_sample_instance(NULL); if (!sample) { abort_example("al_create_sample failed.\n"); } for (i = 0; i < n; ++i) { ALLEGRO_SAMPLE *sample_data = NULL; const char *filename = filenames[i]; float sample_time = 0; /* Load the entire sound file from disk. */ sample_data = al_load_sample(filename); if (!sample_data) { abort_example("Could not load sample from '%s'!\n", filename); continue; } if (!al_set_sample(sample, sample_data)) { abort_example("al_set_sample_instance_ptr failed.\n"); continue; } if (!al_attach_sample_instance_to_mixer(sample, mixer)) { abort_example("al_attach_sample_instance_to_mixer failed.\n"); goto done; } /* Play sample in looping mode. */ al_set_sample_instance_playmode(sample, ALLEGRO_PLAYMODE_LOOP); al_play_sample_instance(sample); sample_time = al_get_sample_instance_time(sample); log_printf("Playing '%s' (%.3f seconds) 3 times", filename, sample_time); al_rest(sample_time); if (!al_set_sample_instance_gain(sample, 0.5)) { abort_example("Failed to set gain.\n"); } al_rest(sample_time); if (!al_set_sample_instance_gain(sample, 0.25)) { abort_example("Failed to set gain.\n"); } al_rest(sample_time); al_stop_sample_instance(sample); log_printf("\nDone playing '%s'\n", filename); /* Free the memory allocated. */ al_set_sample(sample, NULL); al_destroy_sample(sample_data); } al_destroy_sample_instance(sample); al_destroy_mixer(mixer); al_destroy_voice(voice); al_uninstall_audio(); done: close_log(true); return 0; }
int main(int argc, char **argv) { ALLEGRO_VOICE *voice; ALLEGRO_MIXER *mixer; ALLEGRO_MIXER *submixer[2]; ALLEGRO_SAMPLE_INSTANCE *sample[2]; ALLEGRO_SAMPLE *sample_data[2]; float sample_time; float max_sample_time; int i; if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log(); if (argc < 3) { log_printf("This example needs to be run from the command line.\nUsage: %s file1 file2\n", argv[0]); goto done; } al_init_acodec_addon(); if (!al_install_audio()) { abort_example("Could not init sound!\n"); } voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); if (!voice) { abort_example("Could not create ALLEGRO_VOICE.\n"); } mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); submixer[0] = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); submixer[1] = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); if (!mixer || !submixer[0] || !submixer[1]) { abort_example("al_create_mixer failed.\n"); } if (!al_attach_mixer_to_voice(mixer, voice)) { abort_example("al_attach_mixer_to_voice failed.\n"); } for (i = 0; i < 2; i++) { const char *filename = argv[i + 1]; sample_data[i] = al_load_sample(filename); if (!sample_data[i]) { abort_example("Could not load sample from '%s'!\n", filename); } sample[i] = al_create_sample_instance(NULL); if (!sample[i]) { abort_example("al_create_sample failed.\n"); } if (!al_set_sample(sample[i], sample_data[i])) { abort_example("al_set_sample_ptr failed.\n"); } if (!al_attach_sample_instance_to_mixer(sample[i], submixer[i])) { abort_example("al_attach_sample_instance_to_mixer failed.\n"); } if (!al_attach_mixer_to_mixer(submixer[i], mixer)) { abort_example("al_attach_mixer_to_mixer failed.\n"); } } /* Play sample in looping mode. */ for (i = 0; i < 2; i++) { al_set_sample_instance_playmode(sample[i], ALLEGRO_PLAYMODE_LOOP); al_play_sample_instance(sample[i]); } max_sample_time = al_get_sample_instance_time(sample[0]); sample_time = al_get_sample_instance_time(sample[1]); if (sample_time > max_sample_time) max_sample_time = sample_time; log_printf("Playing..."); al_rest(max_sample_time); al_set_sample_instance_gain(sample[0], 0.5); al_rest(max_sample_time); al_set_sample_instance_gain(sample[1], 0.25); al_rest(max_sample_time); al_stop_sample_instance(sample[0]); al_stop_sample_instance(sample[1]); log_printf("Done\n"); /* Free the memory allocated. */ for (i = 0; i < 2; i++) { al_set_sample(sample[i], NULL); al_destroy_sample(sample_data[i]); al_destroy_sample_instance(sample[i]); al_destroy_mixer(submixer[i]); } al_destroy_mixer(mixer); al_destroy_voice(voice); al_uninstall_audio(); done: close_log(true); return 0; }
void ParaMusicaPrincipal(ALLEGRO_SAMPLE_INSTANCE *SongInstance) { al_stop_sample_instance(SongInstance); }
void Gamestate_Stop(struct Game *game, struct GamestateResources* data) { al_stop_sample_instance(data->sound); al_stop_sample_instance(data->kbd); al_stop_sample_instance(data->key); }
int main() { bool quit = false; int gamestate = 0; srand(time(NULL)); int change_bkg = 0; int stopwatch = 120; bool iddle = false; int bulletID=0; int bulletCount=0; ALLEGRO_DISPLAY* display; ALLEGRO_TIMER* timer_0p2; ALLEGRO_TIMER* timer_1; ALLEGRO_TIMER* timer_60; ALLEGRO_EVENT_QUEUE* event_queue; ALLEGRO_EVENT ev; ALLEGRO_BITMAP* img_home_screen; ALLEGRO_BITMAP* img_dica_h1n1; ALLEGRO_BITMAP* img_background0; ALLEGRO_BITMAP* img_game_over; ALLEGRO_BITMAP* img_you_win; ALLEGRO_BITMAP* img_heart; ALLEGRO_BITMAP* img_medal; ALLEGRO_BITMAP* img_clock; ALLEGRO_BITMAP* img_block1; ALLEGRO_BITMAP* img_block2; ALLEGRO_BITMAP* img_player_walking; ALLEGRO_BITMAP* img_player_walking_shoot; ALLEGRO_BITMAP* img_player_immobile; ALLEGRO_BITMAP* img_player_immobile_shoot; ALLEGRO_BITMAP* img_player_jump; ALLEGRO_BITMAP* img_player_jump_shoot; ALLEGRO_BITMAP* img_player_bullet; ALLEGRO_BITMAP* img_enemy1; ALLEGRO_BITMAP* img_boss1; ALLEGRO_BITMAP* img_enemy_bullet; ALLEGRO_SAMPLE* spl_theme; ALLEGRO_SAMPLE* spl_playerShoot; ALLEGRO_SAMPLE* spl_mlk; ALLEGRO_SAMPLE_INSTANCE* instance_theme; ALLEGRO_SAMPLE_INSTANCE* instance_playerShoot; ALLEGRO_SAMPLE_INSTANCE* instance_mlk; ALLEGRO_FONT* fonte16; /* Estruturas */ s_object player; s_object block[LINHA_MAX][COLUNA_MAX]; s_object enemy1[LINHA_MAX][COLUNA_MAX]; for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { /* Cria o player */ if(mapa[i][j] == 1) { player.y = i*16 - 24; player.x = j*64 + 24; player.speed = 3; player.direction = 1; player.live = true; player.life = 100; block[i][j].live = false; } /* Cria os Blocos */ if(mapa[i][j] == 2) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 3) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 4) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 5) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = false; } /* Cria os Inimigos */ if(mapa[i][j] == 6) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = -1; enemy1[i][j].life = 3; enemy1[i][j].live = true; block[i][j].live = false; } if(mapa[i][j] == 7 || mapa[i][j] == 8) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = 1; enemy1[i][j].life = 3; enemy1[i][j].live = false; block[i][j].live = false; } if(mapa[i][j] == 9) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = -1; enemy1[i][j].life = 25; enemy1[i][j].live = false; block[i][j].live = false; } } } s_bullet playerBullet[NUM_BULLET]; s_bullet enemyBullet[NUM_BULLET]; for(i=0; i<NUM_BULLET; i++) { playerBullet[i].x = 0; playerBullet[i].y = 0; playerBullet[i].speed = 5; playerBullet[i].direction = 1; playerBullet[i].live = false; enemyBullet[i].x = 0; enemyBullet[i].y = 0; enemyBullet[i].speed = 5; enemyBullet[i].direction = 0; enemyBullet[i].live = false; } s_animation walking; walking.maxFrame = 8; walking.frameDelay = 5; walking.frameCount = 0; walking.curFrame = 0; walking.frameHeight = 40; walking.frameWidth = 40; s_animation jumping; jumping.maxFrame = 7; jumping.frameDelay = 5; jumping.frameCount = 0; jumping.curFrame = 0; jumping.frameHeight = 52; jumping.frameWidth = 40; s_animation immobile; immobile.maxFrame = 7; immobile.frameDelay = 15; immobile.frameCount = 0; immobile.curFrame = 0; immobile.frameHeight = 40; immobile.frameWidth = 40; s_animation anim_enemy1; anim_enemy1.maxFrame = 3; anim_enemy1.frameDelay = 15; anim_enemy1.frameCount = 0; anim_enemy1.curFrame = 0; anim_enemy1.frameHeight = 40; anim_enemy1.frameWidth = 40; /* Faz com que as teclas comecem em false */ for(i=0; i<KEY_MAX; i++) { keys[i] = false; } /* Carrega as configuracoes (teclado, audio, etc) */ al_init(); al_install_keyboard(); al_init_image_addon(); al_install_audio(); al_init_acodec_addon(); al_init_font_addon(); al_init_ttf_addon(); /* Erros ao criar algo */ display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { printf("Erro ao criar o display"); exit(-1); } timer_0p2 = al_create_timer(5.0); timer_1 = al_create_timer(1.0); timer_60 = al_create_timer(1/60.0); if(!timer_0p2) { printf("Erro ao criar o timer de 0.2 FPS"); exit(-1); } if(!timer_1) { printf("Erro ao criar o timer de 1 FPS"); exit(-1); } if(!timer_60) { printf("Erro ao criar o timer de 60 FPS"); exit(-1); } event_queue = al_create_event_queue(); if(!event_queue) { printf("Erro ao criar o event_queue"); exit(-1); } /* Carregando as Imagens */ img_home_screen = al_load_bitmap("Sprites/Background/home_screen.png"); img_dica_h1n1 = al_load_bitmap("Sprites/Background/dica_h1n1.png"); img_background0 = al_load_bitmap("Sprites/Background/background_h1n1.png"); img_you_win = al_load_bitmap("Sprites/Background/you_win.png"); img_game_over = al_load_bitmap("Sprites/Background/game_over.png"); img_heart = al_load_bitmap("Sprites/heart.png"); img_medal = al_load_bitmap("Sprites/medal.png"); img_clock = al_load_bitmap("Sprites/clock.png"); img_block1 = al_load_bitmap("Sprites/block1.png"); img_block2 = al_load_bitmap("Sprites/block2.png"); img_player_walking = al_load_bitmap("Sprites/Player/player_walking.png"); img_player_walking_shoot = al_load_bitmap("Sprites/Player/player_walking_shoot.png"); img_player_immobile = al_load_bitmap("Sprites/Player/player_immobile.png"); img_player_immobile_shoot = al_load_bitmap("Sprites/Player/player_immobile_shoot.png"); img_player_jump = al_load_bitmap("Sprites/Player/player_jump.png"); img_player_jump_shoot = al_load_bitmap("Sprites/Player/player_jump_shoot.png"); img_player_bullet = al_load_bitmap("Sprites/Player/player_bullet.png"); img_enemy1 = al_load_bitmap("Sprites/Enemies/enemy_h1n1.png"); img_boss1 = al_load_bitmap("Sprites/Enemies/boss_h1n1.png"); img_enemy_bullet = al_load_bitmap("Sprites/Enemies/enemy_bullet.png"); /* Carregando os Samples */ al_reserve_samples(10); spl_theme = al_load_sample("Sounds/theme.wav"); spl_playerShoot = al_load_sample("Sounds/shoot.wav"); spl_mlk = al_load_sample("Sounds/mlk.wav"); instance_theme = al_create_sample_instance(spl_theme); instance_playerShoot = al_create_sample_instance(spl_playerShoot); instance_mlk = al_create_sample_instance(spl_mlk); al_set_sample_instance_gain(instance_playerShoot, 0.5); al_attach_sample_instance_to_mixer(instance_theme, al_get_default_mixer()); al_attach_sample_instance_to_mixer(instance_playerShoot, al_get_default_mixer()); al_attach_sample_instance_to_mixer(instance_mlk, al_get_default_mixer()); /* Registra os Eventos */ al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer_0p2)); al_register_event_source(event_queue, al_get_timer_event_source(timer_1)); al_register_event_source(event_queue, al_get_timer_event_source(timer_60)); al_register_event_source(event_queue, al_get_keyboard_event_source()); /* Carregando os timers */ al_start_timer(timer_0p2); al_start_timer(timer_1); al_start_timer(timer_60); /* Carregando a fonte */ fonte16 = al_load_ttf_font("Joystix.TTF", 16, 0); if (!fonte16) { printf("Erro ao carregar Joystix.TTF\n"); exit(1); } while(!quit) { switch(gamestate) { case 0: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } if(ev.keyboard.keycode == ALLEGRO_KEY_SPACE) /* Faz com que o jogo inicie ao pressionar space */ { change_bkg++; if(change_bkg >= 2) { gamestate = 1; } } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); if(change_bkg == 0) { al_draw_bitmap(img_home_screen, 0, 0, 0); } if(change_bkg == 1) { al_draw_bitmap(img_dica_h1n1, 0, 0, 0); if(++anim_enemy1.frameCount >= anim_enemy1.frameDelay) { if(++anim_enemy1.curFrame >= anim_enemy1.maxFrame) { anim_enemy1.curFrame = 0; } anim_enemy1.frameCount = 0; } al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, 330, 320, 0); al_draw_bitmap_region(img_boss1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, 450, 320, 0); } al_flip_display(); } } break; case 1: if(force>= -7.5) { force-=0.5; /* Queda */ } /* Toca a música de fundo */ if(!al_get_sample_instance_playing(instance_theme) && !al_get_sample_instance_playing(instance_mlk)) { al_play_sample_instance(instance_theme); } /* Fechar o display */ al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { quit = true; } /* Evento de quando a tecla eh pressionada */ if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: quit = true; break; case ALLEGRO_KEY_SPACE: keys[KEY_SPACE]=true; break; case ALLEGRO_KEY_UP: keys[KEY_UP] = true; if(jump == false) { jump = true; force = gravity; } break; case ALLEGRO_KEY_LEFT: keys[KEY_RIGHT]=false; keys[KEY_LEFT]=true; break; case ALLEGRO_KEY_RIGHT: keys[KEY_LEFT]=false; keys[KEY_RIGHT]=true; break; case ALLEGRO_KEY_F1: if(!al_get_sample_instance_playing(instance_mlk)) { al_play_sample_instance(instance_mlk); al_stop_sample_instance(instance_theme); } break; case ALLEGRO_KEY_M: if(al_get_sample_instance_playing(instance_mlk)) { al_stop_sample_instance(instance_mlk); } break; } } /* Evento de quando a tecla eh solta */ if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_SPACE: keys[KEY_SPACE]=false; break; case ALLEGRO_KEY_UP: keys[KEY_UP] = false; break; case ALLEGRO_KEY_LEFT: keys[KEY_LEFT]=false; break; case ALLEGRO_KEY_RIGHT: keys[KEY_RIGHT]=false; break; } } if(ev.type == ALLEGRO_EVENT_TIMER) { if(ev.timer.source == timer_0p2) { if((iddle == false) && (keys[KEY_RIGHT] == false) && (keys[KEY_LEFT] == false) && (jump == false)) { iddle = true; } } if(ev.timer.source == timer_1) { stopwatch--; } if(ev.timer.source == timer_60) { /* Posicionamento do player*/ player.y-=force; if(keys[KEY_RIGHT]) { player.direction = 1; player.x+=player.speed; } if(keys[KEY_LEFT]) { player.direction = -1; player.x-=player.speed; } if(keys[KEY_SPACE]) { for(i=0; i<NUM_BULLET; i++) { if(!al_get_sample_instance_playing(instance_playerShoot)) { playerShoot(&player, &playerBullet[i], instance_playerShoot); } } } /*Posicionamento do Inimigo */ for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { if(player.x > enemy1[i][j].x + 40) { enemy1[i][j].direction = 1; } else if(player.x + 40 <= enemy1[i][j].x) { enemy1[i][j].direction = -1; } } } /* ~~Posicionamento do projetil~~ */ /* Chance do Inimigo Atirar */ chance_enemy_shoot = rand() % 40; for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { enemyShoot(&player, &enemy1[i][j], enemyBullet, &bulletID, &bulletCount); } } for(i=0; i<NUM_BULLET; i++) { if(!playerBullet[i].live) { playerBullet[i].direction = player.direction; } if(playerBullet[i].live) { if(playerBullet[i].direction == -1) { playerBullet[i].x-=playerBullet[i].speed; } else if(playerBullet[i].direction == 1) { playerBullet[i].x+=playerBullet[i].speed; } } if(enemyBullet[i].live) { if(enemyBullet[i].direction == -1) { enemyBullet[i].x-=enemyBullet[i].speed; } if(enemyBullet[i].direction == 1) { enemyBullet[i].x+=enemyBullet[i].speed; } } } /* Prende a Camera no Personagem */ cameraX = player.x-(SCREEN_W/2); cameraY = player.y-(SCREEN_H/2); /* Fazer com que a camera nao passe dos limites do mapa */ if (cameraX < 0) cameraX = 0; if (cameraY < 0) cameraY = 0; if (cameraX > WORLD_W - SCREEN_W) cameraX = WORLD_W - SCREEN_W; if (cameraY > WORLD_H - SCREEN_H) cameraY = WORLD_H - SCREEN_H; /* Colisoes + check trap */ for (i = 0; i<LINHA_MAX; i++) { for(j = 0; j<COLUNA_MAX; j++) { for(k=0; k<NUM_BULLET; k++) { collision_bullet_player(&player, &enemyBullet[k], img_enemy_bullet, &bulletCount, 40, 40); } if(block[i][j].live == true) { if(mapa[i][j] == 2) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 3) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 4) { check_trap(&player, &block[i][j], &enemy1[i][j], 4); collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 5) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } for(k=0; k<NUM_BULLET; k++) { collision_bullet_tiles(&playerBullet[k], &block[i][j], img_player_bullet, img_block2, 0, &bulletCount); collision_bullet_tiles(&enemyBullet[k], &block[i][j], img_player_bullet, img_block2, 1, &bulletCount); } } if(block[i][j].live == false) { if(mapa[i][j] == 5) { check_trap(&player, &block[i][j], &enemy1[i][j], 5); } if(mapa[i][j] == 6) { collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 7) { check_trap(&player, &block[i][j], &enemy1[i][j], 7); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 8) { check_trap(&player, &block[i][j], &enemy1[i][j], 8); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 9) { check_trap(&player, &block[i][j], &enemy1[i][j], 9); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } } } } collision_player_wall(&player, &jumping, img_block1); /* ~~Desenha o Background~~ */ al_draw_bitmap(img_background0, 0 - cameraX, 0 - cameraY, 0); /* ~~Animação dos inimigos~~ */ if(++anim_enemy1.frameCount >= anim_enemy1.frameDelay) { if(++anim_enemy1.curFrame >= anim_enemy1.maxFrame) { anim_enemy1.curFrame = 0; } anim_enemy1.frameCount = 0; } /* ~~Desenha os Blocos/Inimigos~~ */ for (i = 0; i<LINHA_MAX; i++) { for(j = 0; j<COLUNA_MAX; j++) { if(mapa[i][j] == 2 && block[i][j].live == true) { al_draw_bitmap(img_block1, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 3 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 4 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 5 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if((mapa[i][j] == 6 || mapa[i][j] == 7 || mapa[i][j] == 8) && (enemy1[i][j].direction == -1) && (enemy1[i][j].live == true)) { al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, 0); } if((mapa[i][j] == 6 || mapa[i][j] == 7 || mapa[i][j] == 8) && (enemy1[i][j].direction == 1) && (enemy1[i][j].live == true)) { al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(mapa[i][j] == 9 && enemy1[i][j].live == true) { al_draw_bitmap_region(img_boss1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, 0); } } } /* ~~Desenho do player~~ */ /* Player parado */ if(iddle == true) { if(++immobile.frameCount >= immobile.frameDelay) { if(++immobile.curFrame >= immobile.maxFrame) { immobile.curFrame = 0; iddle = false; } immobile.frameCount = 0; } } if((keys[KEY_SPACE] == false) && (jump == false) && ((!keys[KEY_LEFT] && player.direction == -1) || player.x == 64)) { al_draw_bitmap_region(img_player_immobile, immobile.curFrame * immobile.frameWidth, 0, immobile.frameWidth, immobile.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if((keys[KEY_SPACE] == false) && (jump == false) && ((!keys[KEY_RIGHT] && player.direction == 1) || player.x == WORLD_W - (64-immobile.frameWidth))) { al_draw_bitmap_region(img_player_immobile, immobile.curFrame * immobile.frameWidth, 0, immobile.frameWidth, immobile.frameHeight, player.x - cameraX, player.y - cameraY, 0); } if((keys[KEY_SPACE] == true) && (jump == false) && ((!keys[KEY_LEFT] && player.direction == -1))) { al_draw_bitmap(img_player_immobile_shoot, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if((keys[KEY_SPACE] == true) && (jump == false) && ((!keys[KEY_RIGHT] && player.direction == 1))) { al_draw_bitmap(img_player_immobile_shoot, player.x - cameraX, player.y - cameraY, 0); } /* Player andando */ if(++walking.frameCount >= walking.frameDelay) { if(++walking.curFrame >= walking.maxFrame) { walking.curFrame = 0; } walking.frameCount = 0; } if(keys[KEY_SPACE] == false) { if(jump == false && keys[KEY_LEFT] && player.direction == -1) { al_draw_bitmap_region(img_player_walking, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(jump == false && keys[KEY_RIGHT] && player.direction == 1) { al_draw_bitmap_region(img_player_walking, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } if(keys[KEY_SPACE] == true) { if(jump == false && keys[KEY_LEFT] && player.direction == -1) { al_draw_bitmap_region(img_player_walking_shoot, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(jump == false && keys[KEY_RIGHT] && player.direction == 1) { al_draw_bitmap_region(img_player_walking_shoot, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } /* Player pulando */ if(jump == true) { if(++jumping.frameCount >= jumping.frameDelay) { if(++jumping.curFrame >= jumping.maxFrame) { jumping.curFrame = 0; } jumping.frameCount = 0; } if(keys[KEY_SPACE] == false) { if(player.direction == -1) { al_draw_bitmap_region(img_player_jump, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(player.direction == 1) { al_draw_bitmap_region(img_player_jump, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } else if(keys[KEY_SPACE] == true) { if(player.direction == -1) { al_draw_bitmap_region(img_player_jump_shoot, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(player.direction == 1) { al_draw_bitmap_region(img_player_jump_shoot, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } } /* ~~Desenho dos projeteis~~ */ for(i=0; i<NUM_BULLET; i++) { if(playerBullet[i].live) { al_draw_bitmap(img_player_bullet, playerBullet[i].x - cameraX, playerBullet[i].y - cameraY, 0); } if(enemyBullet[i].live) { al_draw_bitmap(img_enemy_bullet, enemyBullet[i].x - cameraX, enemyBullet[i].y - cameraY, 0); } } /* Pontuacao e Porcentagem de Vida */ al_draw_bitmap(img_heart, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 20, 0, ALLEGRO_ALIGN_LEFT, ("%03d"), player.life); al_draw_bitmap(img_medal, 64, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 80, 0, ALLEGRO_ALIGN_LEFT, ("%04d"), scores); al_draw_bitmap(img_clock, 144, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 160, 0, ALLEGRO_ALIGN_LEFT, ("%03d"), stopwatch); } /* Termino da Fase */ if(enemyKilled == ENEMY_MAX) /* You Win! */ { scores = scores + (25 * stopwatch) + (10*player.life); gamestate = 2; } if(player.life <= 0 || stopwatch == 0) /* Game Over! */ { gamestate = 3; } /* Troca o display */ al_flip_display(); } break; case 2: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(img_you_win, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(0, 0, 0), SCREEN_W/2, SCREEN_H - 48, ALLEGRO_ALIGN_CENTRE, "Seus pontos: %d", scores); al_draw_textf(fonte16, al_map_rgb(0, 0, 0), SCREEN_W/2, SCREEN_H - 32, ALLEGRO_ALIGN_CENTRE, "Pressione Esc para sair"); al_flip_display(); } } break; case 3: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(img_game_over, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 0, 0), SCREEN_W/2, SCREEN_H - 48, ALLEGRO_ALIGN_CENTRE, "Seus pontos: %d", scores); al_draw_textf(fonte16, al_map_rgb(255, 0, 0), SCREEN_W/2, SCREEN_H - 32, ALLEGRO_ALIGN_CENTRE, "Pressione Esc para sair"); al_flip_display(); } } break; } } /* Destruindo as variaveis */ al_destroy_display(display); al_destroy_event_queue(event_queue); al_destroy_timer(timer_0p2); al_destroy_timer(timer_1); al_destroy_timer(timer_60); al_destroy_bitmap(img_home_screen); al_destroy_bitmap(img_dica_h1n1); al_destroy_bitmap(img_background0); al_destroy_bitmap(img_heart); al_destroy_bitmap(img_medal); al_destroy_bitmap(img_clock); al_destroy_bitmap(img_block1); al_destroy_bitmap(img_block2); al_destroy_bitmap(img_player_walking); al_destroy_bitmap(img_player_walking_shoot); al_destroy_bitmap(img_player_immobile); al_destroy_bitmap(img_player_immobile_shoot); al_destroy_bitmap(img_player_jump); al_destroy_bitmap(img_player_jump_shoot); al_destroy_bitmap(img_player_bullet); al_destroy_bitmap(img_enemy1); al_destroy_bitmap(img_boss1); al_destroy_bitmap(img_enemy_bullet); al_destroy_sample(spl_theme); al_destroy_sample(spl_playerShoot); al_destroy_sample(spl_mlk); return 0; }
void StopSong(Audio* const audio) { al_stop_sample_instance(audio->song_sample_instance); }
int main(int argc, char **argv) { ALLEGRO_VOICE *voice; ALLEGRO_SAMPLE_INSTANCE *sample; int i; if (argc < 2) { fprintf(stderr, "Usage: %s {audio_files}\n", argv[0]); return 1; } if (!al_init()) { fprintf(stderr, "Could not init Allegro.\n"); return 1; } al_init_acodec_addon(); if (!al_install_audio()) { fprintf(stderr, "Could not init sound!\n"); return 1; } for (i = 1; i < argc; ++i) { ALLEGRO_SAMPLE *sample_data = NULL; const char *filename = argv[i]; ALLEGRO_CHANNEL_CONF chan; ALLEGRO_AUDIO_DEPTH depth; unsigned long freq; float sample_time = 0; /* Load the entire sound file from disk. */ sample_data = al_load_sample(filename); if (!sample_data) { fprintf(stderr, "Could not load sample from '%s'!\n", filename); continue; } sample = al_create_sample_instance(NULL); if (!sample) { fprintf(stderr, "al_create_sample failed.\n"); return 1; } if (!al_set_sample(sample, sample_data)) { fprintf(stderr, "al_set_sample failed.\n"); continue; } depth = al_get_sample_instance_depth(sample); chan = al_get_sample_instance_channels(sample); freq = al_get_sample_instance_frequency(sample); fprintf(stderr, "Loaded sample: %i-bit depth, %i channels, %li Hz\n", (depth < 8) ? (8+depth*8) : 0, (chan>>4)+(chan%0xF), freq); fprintf(stderr, "Trying to create a voice with the same specs... "); voice = al_create_voice(freq, depth, chan); if (!voice) { fprintf(stderr, "Could not create ALLEGRO_VOICE.\n"); return 1; } fprintf(stderr, "done.\n"); if (!al_attach_sample_instance_to_voice(sample, voice)) { fprintf(stderr, "al_attach_sample_instance_to_voice failed.\n"); return 1; } /* Play sample in looping mode. */ al_set_sample_instance_playmode(sample, ALLEGRO_PLAYMODE_LOOP); al_play_sample_instance(sample); sample_time = al_get_sample_instance_time(sample); fprintf(stderr, "Playing '%s' (%.3f seconds) 3 times", filename, sample_time); al_rest(sample_time * 3); al_stop_sample_instance(sample); fprintf(stderr, "\n"); /* Free the memory allocated. */ al_set_sample(sample, NULL); al_destroy_sample(sample_data); al_destroy_sample_instance(sample); al_destroy_voice(voice); } al_uninstall_audio(); return 0; }