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); } }
int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { if ((game->menu.menustate==MENUSTATE_OPTIONS) && ((ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) { al_play_sample_instance(game->menu.click); ChangeMenuState(game,MENUSTATE_PAUSE); } else if ((game->menu.menustate==MENUSTATE_VIDEO) && ((ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) { al_play_sample_instance(game->menu.click); ChangeMenuState(game,MENUSTATE_OPTIONS); if (game->menu.options.fullscreen!=game->fullscreen) { al_toggle_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, game->menu.options.fullscreen); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); game->fullscreen = game->menu.options.fullscreen; if (game->fullscreen) al_hide_mouse_cursor(game->display); else al_show_mouse_cursor(game->display); Shared_Unload(game); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); SetupViewport(game); Shared_Load(game); #ifndef __clang__ void Progress(struct Game *game, float p) { al_set_target_bitmap(al_get_backbuffer(game->display)); al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), game->viewportWidth*0.0234, game->viewportHeight*0.84, ALLEGRO_ALIGN_LEFT, "Loading..."); al_draw_filled_rectangle(0, game->viewportHeight*0.985, game->viewportWidth, game->viewportHeight, al_map_rgba(128,128,128,128)); al_draw_filled_rectangle(0, game->viewportHeight*0.985, p*game->viewportWidth, game->viewportHeight, al_map_rgba(255,255,255,255)); al_flip_display(); }
void UpdateRockets(struct Game *game, struct RocketsResources *data, struct Rocket* rockets) { struct Rocket *tmp = rockets; while (tmp) { tmp->dy+= tmp->modifier; if (!tmp->blown) { tmp->dx+= (tmp->dx > 0) ? (-tmp->modifier / 5 + 0.001) : (tmp->modifier / 5 - 0.001); } MoveCharacter(game, tmp->character, tmp->dx, tmp->dy, tmp->blown ? 0 : ((tmp->dx > 0) ? 0.0166 : -0.0166)); AnimateCharacter(game, tmp->character, 1); if (!tmp->blown) { if (((((GetCharacterY(game, tmp->character) > 90) && (rand() % 4 == 0) && (tmp->dy > 0)))) && (GetCharacterX(game, tmp->character) > -20 && GetCharacterX(game, tmp->character) < 320)) { tmp->blown = true; tmp->modifier = 0; tmp->character->angle = 0; tmp->dx = 0; tmp->dy = 0; SelectSpritesheet(game, tmp->character, "boom"); MoveCharacter(game, tmp->character, 5, 5, 0); if (!((GetCharacterX(game, tmp->character) > 140) && (GetCharacterX(game, tmp->character) < 180))) { if (!data->lost) { AdvanceLevel(game, false); data->lost = true; data->flash = 4; data->counter = 0; TM_AddDelay(data->timeline, 3500); if (game->data->mediator.lives > 0) { TM_AddAction(data->timeline, switchMinigame, NULL, "switchMinigame"); } else { TM_AddAction(data->timeline, theEnd, NULL, "theEnd"); } data->spawnspeed = 10; al_play_sample_instance(data->riot_sound); } al_play_sample_instance(data->boom_sound); } } else if (GetCharacterX(game, tmp->character) < -20 || GetCharacterX(game, tmp->character) > 320) { tmp->blown = true; tmp->modifier = 0; tmp->character->angle = 0; tmp->dx = 0; tmp->dy = 0; SelectSpritesheet(game, tmp->character, "blank"); al_play_sample_instance(data->boom_sound); } } tmp=tmp->next; } }
void Menu_Load(struct Game *game) { if (!game->menu.loaded) return; game->menu.cloud_position = 100; game->menu.cloud2_position = 100; ChangeMenuState(game,MENUSTATE_MAIN); al_play_sample_instance(game->menu.music); al_play_sample_instance(game->menu.rain_sound); FadeGameState(game, true); }
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; } } } } }
bool AllegroSoundSample5::Play() { if ( !m_pInstance ) return false; return al_play_sample_instance( m_pInstance ); }
bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (!action->arguments) { action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float))); action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(game->viewportWidth, game->viewportHeight)); } float* fadeloop; ALLEGRO_BITMAP* fade_bitmap; fadeloop = (float*)action->arguments->value; fade_bitmap = (ALLEGRO_BITMAP*)action->arguments->next->value; if (state == TM_ACTIONSTATE_INIT) { *fadeloop = 255; al_set_target_bitmap(fade_bitmap); al_clear_to_color(al_map_rgb(0,0,0)); al_set_target_bitmap(al_get_backbuffer(game->display)); } else if (state == TM_ACTIONSTATE_RUNNING) { *fadeloop-=10; if (*fadeloop<=0) return true; } else if (state == TM_ACTIONSTATE_DRAW) { al_draw_tinted_bitmap(fade_bitmap,al_map_rgba_f(1,1,1,*fadeloop/255.0),0,0,0); } else if (state == TM_ACTIONSTATE_DESTROY) { al_destroy_bitmap(fade_bitmap); free(fadeloop); TM_DestroyArgs(action->arguments); action->arguments = NULL; al_play_sample_instance(game->level.music); } return false; }
struct Rocket* CreateRocket(struct Game *game, struct RocketsResources* data, struct Rocket* rockets, bool right) { struct Rocket *n = malloc(sizeof(struct Rocket)); n->next = NULL; n->prev = NULL; n->dx = (right ? -1.5 : 1.5) + (rand() / (float)RAND_MAX) * 0.6 - 0.3; n->dy = -2.1 + (rand() / (float)RAND_MAX) * 0.5 - 0.25; n->modifier = 0.025; n->blown = false; n->character = CreateCharacter(game, "rocket"); n->character->spritesheets = data->rocket_template->spritesheets; n->character->shared = true; SelectSpritesheet(game, n->character, rand() % 2 ? "rock" : rand() % 2 ? "bottle" : "bottle2"); SetCharacterPosition(game, n->character, (right ? 250 : 50) + rand() % 90 - 40, 100, right ? -0.33 : 0.33); al_play_sample_instance(data->jump_sound); data->currentspawn = data->spawnspeed + (data->spawnspeed * 0.1) * (float)(rand() / (float)RAND_MAX * 2) - (data->spawnspeed * 0.05); if (rockets) { struct Rocket *tmp = rockets; while (tmp->next) { tmp=tmp->next; } tmp->next = n; n->prev = tmp; return rockets; } else { return n; } }
void GameMenu::loop(void) { bool refresh = true; quit = false; ALLEGRO_EVENT event; al_set_sample_instance_playmode(GFX::introInstance,ALLEGRO_PLAYMODE_LOOP); al_play_sample_instance(GFX::introInstance); //animação do menu barraInferior1.setImagem(GFX::blocksBar); barraInferior1.setSpeed(-1,0); barraInferior1.setPosition(0,0); barraInferior2.setImagem(GFX::blocksBar); barraInferior2.setSpeed(-1,0); barraInferior2.setPosition(al_get_bitmap_width(GFX::blocksBar),0); barraSuperior1.setImagem(GFX::blocksBar); barraSuperior1.setSpeed(-1,0); barraSuperior1.setPosition(0,GVC::SCREENHEIGHT-al_get_bitmap_height(GFX::blocksBar)); barraSuperior2.setImagem(GFX::blocksBar); barraSuperior2.setSpeed(-1,0); barraSuperior2.setPosition(al_get_bitmap_width(GFX::blocksBar),GVC::SCREENHEIGHT-al_get_bitmap_height(GFX::blocksBar)); while(!quit) { al_wait_for_event(Allegro::event_queue, &event); switch(event.type) { case ALLEGRO_EVENT_TIMER: refresh = true; update(); // Update game logic break; case ALLEGRO_EVENT_DISPLAY_CLOSE: quit = true; break; default: processEvent(event); // Get user input break; } if(refresh && al_is_event_queue_empty(Allegro::event_queue)) { refresh = false; draw(); // Draw game state al_flip_display(); al_draw_bitmap(GFX::menuInicial,0,0,0); } } }
void Pause_Load(struct Game* game) { ALLEGRO_BITMAP *fade = al_create_bitmap(game->viewportWidth, game->viewportHeight); al_set_target_bitmap(fade); al_clear_to_color(al_map_rgb(0,0,0)); al_set_target_bitmap(al_get_backbuffer(game->display)); //game->pause.bitmap = fade; ChangeMenuState(game,MENUSTATE_PAUSE); PrintConsole(game,"Game paused."); al_play_sample_instance(game->menu.click); }
void playBGM(ALLEGRO_SAMPLE *sample) { if (!sample) return; bgmInstance = al_create_sample_instance(sample); if (!bgmInstance) return; al_attach_sample_instance_to_mixer(bgmInstance, al_get_default_mixer()); al_play_sample_instance(bgmInstance); }
/* 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 Gamestate_Start(struct Game *game, struct MenuResources* data) { data->title_pos = 0; data->screen_pos = 180; data->invisible = true; data->monster_pos = -202; data->starting = false; ChangeMenuState(game,data,MENUSTATE_HIDDEN); al_play_sample_instance(data->music); }
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] ); }
void SoundManager::playMusic(Music *music, float vol, ALLEGRO_PLAYMODE mod) { if (!music) return; ALLEGRO_SAMPLE_INSTANCE *inst = streams[music->sound->id]->instance; if (!al_get_sample_instance_playing(inst)) { setVolume(music, vol); if (v_mute_music) muteMusic(); al_set_sample_instance_playmode(inst, mod); al_play_sample_instance(inst); } }
void playMusic(Music *music, float volume) { if (!music) return; if (currentMusic) stopMusic(currentMusic); ALLEGRO_SAMPLE_INSTANCE *instance = music->getInstance(); if (instance) { al_set_sample_instance_gain(instance, volume); al_play_sample_instance(instance); currentMusic = music; } }
static void t3f_play_queued_sample(void) { int i; if(t3f_sample_queue[0]) { t3f_queue_sample_instance = al_create_sample_instance(t3f_sample_queue[0]); al_set_sample_instance_gain(t3f_queue_sample_instance, t3f_sound_volume); al_set_sample_instance_speed(t3f_queue_sample_instance, 1.0); al_set_sample_instance_pan(t3f_queue_sample_instance, 0.0); al_play_sample_instance(t3f_queue_sample_instance); for(i = 0; i < t3f_queued_samples - 1; i++) { t3f_sample_queue[i] = t3f_sample_queue[i + 1]; } t3f_sample_queue[i] = NULL; t3f_queued_samples--; } }
void Gamestate_Start(struct Game *game, struct GamestateResources* data) { data->pos = 1; data->fade = 0; data->tan = 64; data->tick = 0; data->fadeout = false; data->underscore=true; strcpy(data->text, "#"); TM_AddDelay(data->timeline, 300); TM_AddQueuedBackgroundAction(data->timeline, FadeIn, TM_AddToArgs(NULL, 1, data), 0, "fadein"); TM_AddDelay(data->timeline, 1500); TM_AddAction(data->timeline, Play, TM_AddToArgs(NULL, 1, data->kbd), "playkbd"); TM_AddQueuedBackgroundAction(data->timeline, Type, TM_AddToArgs(NULL, 1, data), 0, "type"); TM_AddDelay(data->timeline, 3200); TM_AddAction(data->timeline, Play, TM_AddToArgs(NULL, 1, data->key), "playkey"); TM_AddDelay(data->timeline, 50); TM_AddAction(data->timeline, FadeOut, TM_AddToArgs(NULL, 1, data), "fadeout"); TM_AddDelay(data->timeline, 1000); TM_AddAction(data->timeline, End, NULL, "end"); al_play_sample_instance(data->sound); }
void Gamestate_Start(struct Game *game, struct dosowiskoResources* data) { al_set_sample_instance_gain(game->data->muzyczka.instance.drums, 0.0); al_set_sample_instance_gain(game->data->muzyczka.instance.fg, 0.0); al_set_sample_instance_gain(game->data->muzyczka.instance.bg, 1.5); char *end = ""; data->score = strtol(GetConfigOptionDefault(game, "Mediator", "score", "0"), &end, 10); if (game->data->mediator.score > data->score) { char text[255]; snprintf(text, 255, "%d", game->data->mediator.score); SetConfigOption(game, "Mediator", "score", text); data->score = game->data->mediator.score; } al_ungrab_mouse(); if (!game->config.fullscreen) al_show_mouse_cursor(game->display); al_play_sample_instance(data->sound); }
static bool do_play_sample(ALLEGRO_SAMPLE_INSTANCE *splinst, ALLEGRO_SAMPLE *spl, float gain, float pan, float speed, ALLEGRO_PLAYMODE loop) { if (!al_set_sample(splinst, spl)) { ALLEGRO_ERROR("al_set_sample failed\n"); return false; } if (!al_set_sample_instance_gain(splinst, gain) || !al_set_sample_instance_pan(splinst, pan) || !al_set_sample_instance_speed(splinst, speed) || !al_set_sample_instance_playmode(splinst, loop)) { return false; } if (!al_play_sample_instance(splinst)) { ALLEGRO_ERROR("al_play_sample_instance failed\n"); return false; } return true; }
int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { if (ev->keyboard.keycode==ALLEGRO_KEY_UP) { game->menu.selected--; if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected--; al_play_sample_instance(game->menu.click); } else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) { game->menu.selected++; if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected++; al_play_sample_instance(game->menu.click); } if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) { char *text; al_play_sample_instance(game->menu.click); switch (game->menu.menustate) { case MENUSTATE_MAIN: switch (game->menu.selected) { case 0: UnloadGameState(game); game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_DISCLAIMER; break; case 1: ChangeMenuState(game,MENUSTATE_OPTIONS); break; case 2: UnloadGameState(game); game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_ABOUT; break; case 3: return 1; break; } break; case MENUSTATE_AUDIO: text = malloc(255*sizeof(char)); switch (game->menu.selected) { case 0: game->music--; if (game->music<0) game->music=10; sprintf(text, "%d", game->music); SetConfigOption("SuperDerpy", "music", text); al_set_mixer_gain(game->audio.music, game->music/10.0); break; case 1: game->fx--; if (game->fx<0) game->fx=10; sprintf(text, "%d", game->fx); SetConfigOption("SuperDerpy", "fx", text); al_set_mixer_gain(game->audio.fx, game->fx/10.0); break; case 2: game->voice--; if (game->voice<0) game->voice=10; sprintf(text, "%d", game->voice); SetConfigOption("SuperDerpy", "voice", text); al_set_mixer_gain(game->audio.voice, game->voice/10.0); break; case 3: ChangeMenuState(game,MENUSTATE_OPTIONS); break; } free(text); break; case MENUSTATE_OPTIONS: switch (game->menu.selected) { case 0: ChangeMenuState(game,MENUSTATE_CONTROLS); break; case 1: ChangeMenuState(game,MENUSTATE_VIDEO); break; case 2: ChangeMenuState(game,MENUSTATE_AUDIO); break; case 3: ChangeMenuState(game,MENUSTATE_MAIN); break; default: break; } break; case MENUSTATE_PAUSE: switch (game->menu.selected){ case 0: PrintConsole(game,"Game resumed."); al_destroy_bitmap(game->pause.bitmap); game->pause.bitmap = NULL; ResumeGameState(game); game->gamestate = game->loadstate; break; case 1: game->gamestate=game->loadstate; UnloadGameState(game); game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_MAP; break; case 2: ChangeMenuState(game,MENUSTATE_OPTIONS); break; case 3: return 1; default: break; } break; case MENUSTATE_CONTROLS: switch (game->menu.selected) { case 3: ChangeMenuState(game,MENUSTATE_OPTIONS); break; default: break; } break; case MENUSTATE_VIDEO: switch (game->menu.selected) { case 0: game->menu.options.fullscreen = !game->menu.options.fullscreen; if (game->menu.options.fullscreen) SetConfigOption("SuperDerpy", "fullscreen", "1"); else SetConfigOption("SuperDerpy", "fullscreen", "0"); break; case 3: if ((game->menu.options.fullscreen==game->fullscreen) && (game->menu.options.fps==game->fps) && (game->menu.options.width==game->width) && (game->menu.options.height==game->height)) { ChangeMenuState(game,MENUSTATE_OPTIONS); } else { PrintConsole(game, "video settings changed, restarting..."); game->restart = true; return 1; } break; default: break; } break; default: return 1; break; } } else if (ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) { switch (game->menu.menustate) { case MENUSTATE_OPTIONS: ChangeMenuState(game,MENUSTATE_MAIN); break; case MENUSTATE_VIDEO: ChangeMenuState(game,MENUSTATE_OPTIONS); break; case MENUSTATE_AUDIO: ChangeMenuState(game,MENUSTATE_OPTIONS); break; case MENUSTATE_CONTROLS: ChangeMenuState(game,MENUSTATE_OPTIONS); break; case MENUSTATE_PAUSE: PrintConsole(game,"Game resumed."); al_destroy_bitmap(game->pause.bitmap); game->pause.bitmap = NULL; ResumeGameState(game); game->gamestate = game->loadstate; break; default: return 1; break; } } if (game->menu.selected==-1) game->menu.selected=3; if (game->menu.selected==4) game->menu.selected=0; return 0; }
void Gamestate_Logic(struct Game *game, struct RocketsResources* data) { if ((data->spawncounter == data->currentspawn) && ((data->counter < data->timelimit) || (data->lost))) { if (rand() % 2 == 0) { data->rockets_left = CreateRocket(game, data, data->rockets_left, false); } else { data->rockets_right = CreateRocket(game, data, data->rockets_right, true); } data->spawncounter = 0; } if (!data->flash) { UpdateRockets(game, data, data->rockets_left); UpdateRockets(game, data, data->rockets_right); } else { data->flash--; } if (data->lost) { data->zadyma++; if (data->zadyma >= 255) { data->zadyma = 255; } } AnimateCharacter(game, data->usa_flag, 1); AnimateCharacter(game, data->ru_flag, 1); AnimateCharacter(game, data->riot, 1); if ((data->lost) && (data->hearts > 80)) { AnimateCharacter(game, game->data->mediator.heart, 1); if (game->data->mediator.heart->pos == 6) { al_play_sample_instance(data->boom_sound); } } if (data->lost) { data->hearts++; } if (data->won) { AnimateCharacter(game, data->euro, 1); } if ((data->counter >= data->timelimit) && (!data->lost) && (!data->won)) { bool stillthere = false; struct Rocket *tmp = data->rockets_left; while (tmp) { if (!tmp->blown) { stillthere = true; break; } tmp = tmp->next; } tmp = data->rockets_right; while (tmp) { if (!tmp->blown) { stillthere = true; break; } tmp = tmp->next; } if (!stillthere) { SelectSpritesheet(game, data->euro, "euro"); SetCharacterPosition(game, data->euro, 0, 0, 0); al_play_sample_instance(data->wuwu_sound); data->won = true; AdvanceLevel(game, true); SelectSpritesheet(game, data->usa_flag, "poland"); SelectSpritesheet(game, data->ru_flag, "poland"); TM_AddDelay(data->timeline, 2500); TM_AddAction(data->timeline, switchMinigame, NULL, "switchMinigame"); } } void iterate(struct Rocket *start) { struct Rocket *tmp1 = start; while (tmp1) { if (!tmp1->blown) { // if (CheckCollision(game, data, data->cursor, tmp1->character)) { if ( (abs(GetCharacterY(game, tmp1->character) - GetCharacterY(game, data->cursor)) <= 10) && (((GetCharacterX(game, tmp1->character) <= GetCharacterX(game, data->cursor) + al_get_bitmap_width(data->cursor->bitmap)) && (GetCharacterX(game, tmp1->character) + al_get_bitmap_width(tmp1->character->bitmap) >= GetCharacterX(game, data->cursor) + al_get_bitmap_width(data->cursor->bitmap))) || ((GetCharacterX(game, tmp1->character) + al_get_bitmap_width(tmp1->character->bitmap) >= GetCharacterX(game, data->cursor)) && (GetCharacterX(game, tmp1->character) + al_get_bitmap_width(tmp1->character->bitmap) <= GetCharacterX(game, data->cursor) + al_get_bitmap_width(data->cursor->bitmap))) )) { if (GetCharacterY(game, tmp1->character) < GetCharacterY(game, data->cursor)) { tmp1->dx = 0; tmp1->dy = 0; tmp1->modifier = 0; tmp1->blown = true; SelectSpritesheet(game, tmp1->character, "blank"); } else if (tmp1->dy < 0) { tmp1->dy *= -1; } al_play_sample_instance(data->rocket_sound); } } tmp1 = tmp1->next; } } iterate(data->rockets_left); iterate(data->rockets_right); data->counter++; data->spawncounter++; data->cloud_rotation += 0.002; TM_Process(data->timeline); }
void Audio::PlayMusic(){ //// PLAY BACKGROUND MUSIC al_play_sample_instance(MusicInstance); };
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; }
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; }
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; }
bool Play(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { ALLEGRO_SAMPLE_INSTANCE *data = TM_GetArg(action->arguments, 0); if (state == TM_ACTIONSTATE_RUNNING) al_play_sample_instance(data); return true; }
// bgm void bgm_play(string fname) { bgm_stop(); bgm_id = create(fname.c_str()); al_set_sample( bgm_channel, samples.find(bgm_id)->second ); al_play_sample_instance(bgm_channel); }
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 PlaySong(Audio* const audio) { al_play_sample_instance(audio->song_sample_instance); }