void jukebox(int index,int loop) { music_stop(); if(index<0) index=MAXMIDIS-1; if(index>=MAXMIDIS) index=0; music_stop(); // Allegro's DIGMID driver (the one normally used on on Linux) gets // stuck notes when a song stops. This fixes it. if(strcmp(midi_driver->name, "DIGMID")==0) set_volume(0, 0); set_volume(-1, mixvol(tunes[index].volume,midi_volume>>1)); play_midi((MIDI*)tunes[index].data,loop); if(tunes[index].start>0) midi_seek(tunes[index].start); midi_loop_end = tunes[index].loop_end; midi_loop_start = tunes[index].loop_start; currmidi=index; master_volume(digi_volume,midi_volume); midi_paused=false; }
void restart() { if (tune != NULL) { stop_midi(); done = 0; play_midi(tune, 0); } }
//************************************* //Função Main //************************************* int main() { init(); MIDI *music = load_midi("graphics/music.mid"); play_midi(music,TRUE); int loop = true; while(loop){ objects *obj = (objects*)malloc(sizeof(objects)); spaceship *ship = (spaceship*)malloc(sizeof(spaceship)); obj->ship = ship; setShipSprite(obj->ship); game_option escolha; escolha = callMenu(); switch(escolha){ case EASY_GAME: ship->speed = 1; break; case MEDIUM_GAME: ship->speed = 3; break; case HARD_GAME: ship->speed = 5; break; case EXIT_GAME: loop = FALSE; break; } int level = 1; while(loop&&level<=6){ char path[100] = "graphics/"; char filename[100]; sprintf(filename,"stage%d.w3d",level); strcat(path,filename); FILE *stage = fopen(path,"rb"); getAllCells(obj,stage); fclose(stage); game_condition progress; int background = backgroundColor(level); progress = gameLoop(obj,background); switch(progress){ case NEXT_STAGE: level++; break; case GAME_OVER:{ BITMAP *gameOver; gameOver = load_bitmap("graphics/gameover.bmp",NULL); updateScreen(gameOver); rest(2000); level = 100; }break; case LEAVE_GAME: loop = FALSE; break; } } if(level==7){ BITMAP *win; win = load_bitmap("graphics/venceu.bmp",NULL); updateScreen(win); rest(2000); } } deinit(); return 0; }
void JVlibForm::startPlayer(int startTick) { if (pid>0) return; pid=fork(); if (!pid) { play_midi(startTick); exit(EXIT_SUCCESS); } // end pid fork } // end startPlayer
/** * Runs the jukebox code. This contains its own game loop and can only be run * by adding the /j flag at startup. * * We'll display the song name, the current time and total time. When a song * is finished, we'll wait a second and then continue with the next. * Pressing ESC will quit the jukebox. */ int start_jukebox() { // Set up everything needed to run the jukebox. initialize_jukebox(); initialize_starfield(); MIDI *curr_music; int status; while (TRUE) { CURR_TRACK = ALL_MUSIC[track_n]; // Prepare the screen. clear_to_color(buffer, palette_color[0]); // Load the next midi file. curr_music = load_midi(CURR_TRACK->file); length = get_midi_length(curr_music); // After calling get_midi_length(), midi_pos will contain the negative // number of beats, and midi_time the length of the midi in seconds. beats = -midi_pos; // Begin playback. play_midi(curr_music, FALSE); // Run the main loop; status is JUKEBOX_NEXT_SONG, JUKEBOX_PREV_SONG, // or JUKEBOX_EXIT if escape has been pressed. status = jukebox_loop(); // Prepare for the next midi file. destroy_midi(curr_music); if (status == JUKEBOX_NEXT_SONG) { // Advance; loop back to zero if we're at the end. if (++track_n >= ALL_MUSIC_AMOUNT) { track_n = 0; } } else if (status == JUKEBOX_PREV_SONG) { // Go back one track. if (--track_n < 0) { track_n = ALL_MUSIC_AMOUNT - 1; } } else if (status == JUKEBOX_EXIT) { // Escape pressed; exit the jukebox. break; } else { // Unknown status. break; } } shutdown(); return 0; }
void Sound::Sound::play (int loopmode) { if(!EnableSound) return; Calc (); if (midi) play_midi (midi, loopmode != 0); else sndPlaySound (fn, _volume, _balance); SetSpeaker (); }
void som::tocar(int repetir) { if (tipo == T_WAV) { if(!smp) return; voice = play_sample(smp,volume,posicao,frequencia,repetir); } else if (tipo == T_MID) { if(!mid) return; voice = play_midi(mid,repetir); } }
int quitGame() { BITMAP *quitBackground = NULL; quitBackground = load_bitmap("Quit Background.bmp", NULL); // Load our picture BITMAP *quitBuffer = NULL; quitBuffer = create_bitmap(1024,768); //Create an empty bitmap. MIDI *midSuspense = NULL; midSuspense = load_midi("Suspense.mid"); MIDI *midResolve = NULL; midResolve = load_midi("Resolve.mid"); draw_sprite(quitBuffer, quitBackground, 0, 0); blit(quitBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen play_midi(midSuspense, 1); readkey(); play_midi(midResolve, 0); clear_bitmap(quitBuffer); // Clear the contents of the buffer bitmap blit(quitBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen sleep(700); return 0; }
static void compile(const char *pgm, int framework) { struct patch *patch; patch = patch_do_compile("/", pgm, report, framework); if (!patch) { symtab_free(); exit(1); } if (!quiet) show_patch(patch); if (trace_var) play_midi(patch); symtab_free(); stim_put(patch->stim); /* * We can't use patch_free here because that function also accesses * image data, which isn't available in standalone builds. A simple * free(3) has the same effect in this case. */ free(patch); }
/*** * Init function */ void Initr() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); // Init time counter LOCK_VARIABLE(contadorTempo); LOCK_FUNCTION(contar_tempo); install_int_ex(contar_tempo, BPS_TO_TIMER(30)); // Count time at each 30 FPS // Init music install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL); set_volume(255, 128); // volume setup MIDI *mid = load_midi("..\\recursos\\musica.mid"); play_midi(mid,1); // Init SFX sompulo = load_sample("..\\recursos\\pulo.wav"); somponto = load_sample("..\\recursos\\ponto.wav"); somdano = load_sample("..\\recursos\\dano.wav"); // srand(time(NULL)); }
void Soundtrack::Play() { if(_isPlaying) return; _isPlaying = true; play_midi(GetMusicAt(_curTrack)->GetMidi(), (_repeat == Soundtrack::REPEAT_ONE ? true : false )); }
int main(int argc, char *argv[]) { MIDI *the_music; int length, pos; int beats, beat; int x, y, tw, th; int background_color; int text_color; int paused = 0; int done = 0; if (allegro_init() != 0) return 1; if (argc != 2) { allegro_message("Usage: 'exmidi filename.mid'\n"); return 1; } install_keyboard(); install_timer(); /* install a MIDI sound driver */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { allegro_message("Error initialising sound system\n%s\n", allegro_error); return 1; } /* read in the MIDI file */ the_music = load_midi(argv[1]); if (!the_music) { allegro_message("Error reading MIDI file '%s'\n", argv[1]); return 1; } length = get_midi_length(the_music); beats = -midi_pos; /* get_midi_length updates midi_pos to the negative number of beats (quarter notes) in the midi. */ if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); return 1; } } /* try to continue in the background */ if (set_display_switch_mode(SWITCH_BACKGROUND)) set_display_switch_mode(SWITCH_BACKAMNESIA); set_palette(desktop_palette); background_color = makecol(255, 255, 255); text_color = makecol(0, 0, 0); clear_to_color(screen, background_color); th = text_height(font); x = SCREEN_W / 2; textprintf_centre_ex(screen, font, x, SCREEN_H / 3, text_color, -1, "Driver: %s", midi_driver->name); textprintf_centre_ex(screen, font, x, SCREEN_H / 2, text_color, -1, "Playing %s", get_filename(argv[1])); /* start up the MIDI file */ play_midi(the_music, TRUE); y = 2 * SCREEN_H / 3; tw = text_length(font, "0000:00 / 0000:00"); /* wait for a key press */ while (!done) { /* P key pauses/resumes, any other key exits. */ while (keypressed()) { int k = readkey() & 255; if (k == 'p') { paused = !paused; if (paused) { midi_pause(); textprintf_centre_ex(screen, font, x, y + th * 3, text_color, -1, "P A U S E D"); } else { midi_resume(); rectfill(screen, x - tw / 2, y + th * 3, x + tw / 2, y + th * 4, background_color); } } else done = 1; } pos = midi_time; beat = midi_pos; rectfill(screen, x - tw / 2, y, x + tw / 2, y + th * 2, background_color); textprintf_centre_ex(screen, font, x, y, text_color, -1, "%d:%02d / %d:%02d", pos / 60, pos % 60, length / 60, length % 60); textprintf_centre_ex(screen, font, x, y + th, text_color, -1, "beat %d / %d", beat, beats); /* We have nothing else to do. */ rest(100); } /* destroy the MIDI file */ destroy_midi(the_music); return 0; }
void toMenu() { BITMAP *menuBuffer = NULL; menuBuffer = create_bitmap(1024,768); //Create an empty bitmap. BITMAP *menuBackground = NULL; menuBackground = load_bitmap("Menu Background.bmp", NULL); // Load our picture BITMAP *highlighter = NULL; highlighter = load_bitmap("Menu Highlighter.bmp", NULL); // Load our picture BITMAP *smoke = NULL; smoke = load_bitmap("Menu Smoke.bmp", NULL); // Load our picture MIDI *menuMusic = NULL; menuMusic = load_midi("Soundtrack1.mid"); SAMPLE *menuClick = load_sample("Click.wav"); clear_bitmap(menuBuffer); // Clear the contents of the buffer bitmap int highlightedOption = 1; int inMenu = 1; int smokePosition = 1024; int smokePosition2 = 1024; draw_sprite(menuBuffer, menuBackground, 0, 0); draw_sprite(menuBuffer, highlighter, 6, 186); blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen play_midi(menuMusic, 1); while (inMenu == 1) { draw_sprite(menuBuffer, menuBackground, 0, 0); smokePosition --; smokePosition2 -= 3; if (smokePosition <= -1024) { smokePosition = 0; } readkey(); if(key[KEY_UP]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption--; if (highlightedOption <= 0) { highlightedOption = 5; } } else if(key[KEY_DOWN]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption++; if (highlightedOption >= 6) { highlightedOption = 1; } } else if(key[KEY_ENTER]) { play_sample(menuClick, 155, 0, 4000, 0); switch (highlightedOption) { case 1: isXenoPatriots = selectRace(); newGame(); startGame(); play_midi(menuMusic, 1); break; case 2: loadGame(); break; case 3: gameOptions(); break; case 4: break; case 5: quitGame(); inMenu ^= 0; return; break; } } switch (highlightedOption) { case 1: draw_sprite(menuBuffer, highlighter, 6, 186); break; case 2: draw_sprite(menuBuffer, highlighter, 6, 278); break; case 3: draw_sprite(menuBuffer, highlighter, 6, 373); break; case 4: draw_sprite(menuBuffer, highlighter, 6, 465); break; case 5: draw_sprite(menuBuffer, highlighter, 6, 629); break; } /*draw_sprite(menuBuffer, smoke, smokePosition, 0); draw_sprite(menuBuffer, smoke, smokePosition + 1024, 0); draw_sprite(menuBuffer, smoke, smokePosition2, 0); draw_sprite(menuBuffer, smoke, smokePosition2 + 1024, 0);*/ blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen } }
void Game_sys::PlayMusic() { play_midi( (MIDI*)bgmusic[0].dat, 1 ); set_volume( 255, 100 ); }
int main() { initializeCrap(); install_int_ex(increment_speed_counter,BPS_TO_TIMER(120)); int screenMode = 0; //0 for windowed, 1 for fullscreen srand((unsigned)time(NULL)); BITMAP *buffer = create_bitmap(800,600); BITMAP *titleimg = load_bitmap("quiximgTitle.bmp",NULL); BITMAP *imgPlayers = load_bitmap("quiximgPlayerSet.bmp",NULL); MIDI *song = load_midi("quixsong.mid"); PlayerObject poPlayer[4]; LaserObject loLaser[4]; LevelObject Level; MenuObject Menu; float scrollerX = -150.0, scrollerY = 5.0; int winner; poPlayer[0].setControlScheme(0); poPlayer[1].setControlScheme(1); poPlayer[2].setControlScheme(2); poPlayer[3].setControlScheme(3); poPlayer[0].samSound = load_sample("quixp1Death.wav"); poPlayer[1].samSound = load_sample("quixp2Death.wav"); poPlayer[2].samSound = load_sample("quixp3Death.wav"); poPlayer[3].samSound = load_sample("quixp4Death.wav"); poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); int mouseDown[21]; //Kind of a crappy array --- Each button is a # //and it's set to true if that button was clicked. for (int i = 0; i < 20; i++) { mouseDown[i] = false; } while ( !Menu.isDone() ) { while (speed_counter > 0) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~ MENU SCREEN ~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ if ( Menu.getEnabled() == true ) { if (key[KEY_Z]) { if (Menu.getFullscreen() == true) { Menu.changeScreenSize(0); Menu.setFullscreen(false); } else { Menu.changeScreenSize(1); Menu.setFullscreen(true); } } if (mouse_b & 1) { mouseDownClick(&Menu, mouseDown); } else { mouseUp(&Menu, mouseDown, poPlayer, &Level, song); } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~ IN-GAME ~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ else { //Player Input1 if (key[KEY_ESC]) { play_midi(NULL, false); if (Menu.fragLimitHit == true) { Menu.fragLimitHit == false; for (int i=0; i<4; i++) { poPlayer[i].resetScore(); poPlayer[i].resetDeaths(); } poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); Menu.fragLimitHit = false; Menu.resetPressed = false; mouseDown[19] = false; } Level.setEnabled(false); Menu.setEnabled(true); } for (int i=0; i<4; i++) { if (poPlayer[i].getControlScheme() == 0) { if (key[KEY_W]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_A]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_S]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_D]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_F]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 1) { if (key[KEY_I]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_J]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_K]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_L]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_H]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 2) { if (key[KEY_UP]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_LEFT]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_DOWN]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_RIGHT]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_RCONTROL]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 3) { if (key[KEY_8_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_4_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_2_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_6_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_PLUS_PAD]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 4) { //Joystick #1 poll_joystick(); if (joy[0].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[0].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[0].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[0].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[0].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 5) { //Joystick #2 poll_joystick(); if (joy[1].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[1].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[1].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[1].stick[0].axis[0].d2) {moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[1].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 6) { //Joystick #3 poll_joystick(); if (joy[2].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[2].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[2].stick[0].axis[1].d2) {moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[2].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[2].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 7) { //Joystick #4 poll_joystick(); if (joy[3].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[3].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[3].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[3].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[3].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } } if (Level.timeForAPowerupTimer >= 60) { Level.timeForAPowerupTimer = 0; } else { Level.timeForAPowerupTimer++; } } if ( Level.getFrame() < 32 ) { Level.setFrame( Level.getFrame() + 1 ); } else { Level.setFrame(0); } //Score Bar if (Level.getFragLimit() != 0 && Level.getEnabled() == true) { scrollerX += 0.5; if (scrollerX >= 1200.0) { scrollerX = -150.0; } } for (int i=0; i<4; i++) { //Res circle if (poPlayer[i].getRespawnCounter() >= 0) { poPlayer[i].setRespawnCounter( poPlayer[i].getRespawnCounter() + 1); } //"Laser" movement if (loLaser[i].getEnabled() == true) { if (loLaser[i].getDir() == 'u') { loLaser[i].moveUp('l'); } else if (loLaser[i].getDir() == 'd') { loLaser[i].moveDown('l'); } else if (loLaser[i].getDir() == 'l') { loLaser[i].moveLeft('l'); } else if (loLaser[i].getDir() == 'r') { loLaser[i].moveRight('l'); } checkCollision(&loLaser[i], poPlayer, i, Level); } if ((poPlayer[i].returnScore() == Level.getFragLimit()) && (Level.getFragLimit() > 0)) { //Frag Limit hit Menu.fragLimitHit = true; winner = i; } } speed_counter--; }//while (speed_counter > 0) if ( Menu.getEnabled() == true ) { drawMenuStuff(buffer, Menu, titleimg, imgPlayers, Level); } else if (Menu.fragLimitHit == true) { //Show win window! floodfill (buffer, 0, 0, makecol(0,0,0)); textprintf(buffer,font,348,203,makecol(100,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,347,202,makecol(150,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,346,201,makecol(200,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,345,200,makecol(255,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,330,250,makecol(255,0,0), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,260,makecol(255,0,0), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,270,makecol(255,0,0), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,280,makecol(255,0,0), "Player 4 score: %i", poPlayer[3].returnScore() ); textprintf(buffer,font,330,249,makecol(255,255,255), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,259,makecol(255,255,255), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,269,makecol(255,255,255), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,279,makecol(255,255,255), "Player 4 score: %i", poPlayer[3].returnScore() ); textout_centre(buffer, font, "Hit esc to continue", 400, 300, makecol(255,255,255)); } else { generateBackground(buffer, Level); drawCharacters(poPlayer, Level, buffer); drawScoreBar(buffer, poPlayer, scrollerX, scrollerY, Level); if (loLaser[0].getEnabled() == true) { drawLaser(loLaser[0], buffer, Level, 0); } if (loLaser[1].getEnabled() == true) { drawLaser(loLaser[1], buffer, Level, 1); } if (loLaser[2].getEnabled() == true) { drawLaser(loLaser[2], buffer, Level, 2); } if (loLaser[3].getEnabled() == true) { drawLaser(loLaser[3], buffer, Level, 3); } } acquire_screen(); blit(buffer, screen, 0, 0, 0, 0, 800, 600); clear_bitmap(buffer); release_screen(); }//while ( !Menu.isDone() ) return 0; return 0; }
void PlayGameMusic(void) { play_midi(game_midi, 1); }
void PlayIntroMusic(void) { play_midi(intro_midi, 1); }
void MusicDriver_Allegro::PlaySong(const char *filename) { if (_midi != NULL) destroy_midi(_midi); _midi = load_midi(filename); play_midi(_midi, false); }
void main() { allegro_init(); install_keyboard(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1000, 600, 0, 0); install_int_ex(ContaMsec, MSEC_TO_TIMER(1)); install_int_ex(ContaSec, SECS_TO_TIMER(1)); install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL); MIDI* bgSound = load_midi("sounds/BGM.mid"); SAMPLE* snakeHit = load_wav("sounds/cobraDamage.wav"); SAMPLE* snakeHitSelf = load_wav("sounds/cobraDamage2.wav"); SAMPLE* snakeDeath = load_wav("sounds/cobraDeath.wav"); SAMPLE* gameOver = load_wav("sounds/gameOver.wav"); InicializaPP(); int swt = 0; struct Cobra snake[500]; //Estrutura que representa a cobra e suas bmpPartes. int xst=0, yst=10, xst2=190, yst2 = 40; //Coordenadas de referência da área de Status do jogo int xL = 0, yL = 425, xL2 = 190, yL2 = 590; //Coordenadas de referência da Tabela de Comidas buffer = create_bitmap(800,600); //Bitmap principal de desenho status = create_bitmap(200,600); //Bitmap principal de desenho clear_to_color(status, makecol(0,0,0)); clear_to_color(buffer, makecol(0,0,0)); //INICIO: Inicializacao Sprites bmpSapo = load_bitmap("images/sapo_20x20.bmp",pallet); bmpAranha = load_bitmap("images/ARANHA_20X20.bmp",pallet); bmpMaca = load_bitmap("images/MACA_20x20.bmp",pallet); bmpMilho = load_bitmap("images/milho_20X20.bmp",pallet); bmpCobraHead = load_bitmap("images/cobraHeadVerde.bmp",pallet); bmpFundo = load_bitmap("images/fundoAreia.bmp",pallet); bmpCobrinha = load_bitmap("images/cobrinha.bmp",pallet); bmpParte = load_bitmap("images/cobraCorpo2.BMP",pallet); bmpBordaVert = load_bitmap("images/bordaVert.bmp",pallet); bmpBordaHoriz = load_bitmap("images/bordaHoriz.bmp",pallet); myfont = load_font("Terminal.pcx", pallet, NULL); //Fonte personalizada //FIM: Inicializacao Sprites //INICIO: Comidas Comida cmdSapo; cmdSapo.x = 300; cmdSapo.y = 400; cmdSapo.bmp = bmpSapo; cmdSapo.spStand = load_wav("sounds/sapoStand.wav"); cmdSapo.spDie = load_wav("sounds/sapoDie.wav"); cmdSapo.visible = true; cmdSapo.ponto = 50; cmdSapo.taman = 1; Comida cmdAranha; cmdAranha.x = 60; cmdAranha.y = 500; cmdAranha.bmp = bmpAranha; cmdAranha.spStand = load_wav("sounds/sapoStand.wav"); cmdAranha.spDie = load_wav("sounds/aranhaDie.wav"); cmdAranha.visible = true; cmdAranha.ponto = 30; cmdAranha.taman = 3; Comida cmdMaca; cmdMaca.x = 100; cmdMaca.y = 100; cmdMaca.bmp = bmpMaca; cmdMaca.spStand = load_wav("sounds/sapoStand.wav"); cmdMaca.spDie = snakeBit; cmdMaca.visible = true; cmdMaca.ponto = 20; cmdMaca.taman = 4; Comida cmdMilho; cmdMilho.x = 600; cmdMilho.y = 100; cmdMilho.bmp = bmpMilho; //cmdmilho.spStand = load_wav("sounds/sapoStand.wav"); cmdMilho.spDie = snakeBit; cmdMilho.visible = true; cmdMilho.ponto = 10; cmdMilho.taman = 5; Comida cmdCobrinha; cmdCobrinha.x = 600; cmdCobrinha.y = 480; cmdCobrinha.bmp = bmpCobrinha; cmdCobrinha.spStand = load_wav("sounds/cobrinhaStand.wav"); cmdCobrinha.spDie = load_wav("sounds/cobrinhaDie.wav"); cmdCobrinha.visible = true; cmdCobrinha.ponto = 40; cmdCobrinha.taman = 2; Comida comidas[20]; comidas[0] = cmdSapo; comidas[1] = cmdAranha; comidas[2] = cmdMaca; comidas[3] = cmdMilho; comidas[4] = cmdCobrinha; comidas[5] = cmdAranha; comidas[6] = cmdMilho; comidas[7] = cmdMilho; comidas[8] = cmdMilho; comidas[9] = cmdCobrinha; comidas[10] = cmdSapo; comidas[11] = cmdAranha; comidas[12] = cmdMaca; comidas[13] = cmdMilho; comidas[14] = cmdCobrinha; comidas[15] = cmdAranha; comidas[16] = cmdMilho; comidas[17] = cmdMilho; comidas[18] = cmdMilho; comidas[19] = cmdCobrinha; //FIM: Comidas Vida vidas[6]; for (int i = 0;i < 6; i++){ vidas[i].x = i*30; vidas[i].y = 0; vidas[i].bmp = bmpCobraHead; vidas[i].visible = true; } //INICIO: Desenho da área de status do jogo. Pontos, Fase, Tamanho, Tempo, Vidas for (int i = -1;i<2;i++){rect(status, xst+i, yst+i, xst2-i, 40-i, makecol(210,192,152));} textprintf_ex(status, myfont, xst+5,68, makecol(255,0,0), -1,"Fase: 1" ); for (int i = -1;i<2;i++){rect(status, xst+i, yst+50+i, xst2-i, yst2+50-i, makecol(210,192,152));} for (int i = -1;i<2;i++){rect(status, xst+i, yst+100+i, xst2-i, yst2+100-i, makecol(210,192,152));} for (int i = -1;i<2;i++){rect(status, xst+i, yst+150+i, xst2-i, yst2+150-i, makecol(210,192,152));} for (int i = 0;i < 6; i++){ if (vidas[i].visible){ draw_sprite(status, vidas[i].bmp, vidas[i].x, vidas[i].y+195); } } //FIM: Desenho da área status do jogo. Pontos, Fase, Tamanho, Tempo, Vidas //INICIO: Desenho da Tabela de Comida do jogo. textprintf_ex(status, myfont, xL,yL-20, makecol(255,0,0 ), -1,"Comidas" ); for (int i = -1;i<2;i++){rect(status, xL+i, yL+i, xL2-i, yL2-i, makecol(210,192,152));} draw_sprite(status, bmpMilho, xL+10, yL+10); textprintf_ex(status, font, xL+40,yL+20, makecol(255,255,0 ), -1,"10 pontos" ); draw_sprite(status, bmpMaca, xL+10, yL+40); textprintf_ex(status, font, xL+40,yL+50, makecol(255,0,0 ), -1,"20 pontos" ); draw_sprite(status, bmpAranha, xL+10, yL+70); textprintf_ex(status, font, xL+40,yL+80, makecol(153,0,255 ), -1,"30 pontos" ); draw_sprite(status, bmpCobrinha, xL+10, yL+100); textprintf_ex(status, font, xL+40,yL+110, makecol(255,255,153 ), -1,"40 pontos" ); draw_sprite(status, bmpSapo, xL+10, yL+130); textprintf_ex(status, font, xL+40,yL+140, makecol(110,220,0 ), -1,"50 pontos " ); //FIM: Desenho da Tabela de Comida do jogo. //INICIO: Desenho do campo de ação da cobra. draw_sprite(buffer, bmpFundo, xC,yC); draw_sprite(buffer, bmpBordaVert, xC,yC); draw_sprite(buffer, bmpBordaVert, xC2-20,yC); draw_sprite(buffer, bmpBordaHoriz, xC,xC); draw_sprite(buffer, bmpBordaHoriz, xC,yC2-20); //FIM: Desenho do campo de ação da cobra //INICIO: Desenho da cobra snake[0].bmp = bmpCobraHead; for (int i = 1;i<tamCobra;i++){ snake[i].bmp = bmpParte; } //FIM: Desenho da cobra char control; int veloc; control = menu_inicial(); if (control == 'j'){veloc = 120;}else{veloc = 50;} play_midi(bgSound,0); draw_sprite(screen,status,800,0); DesenhaCampoAcao(); int x=20, y=20 , xx, yy; int dirx = 20, diry = 0; int tipoCol = 0; int tamComida; //Tamanho que a comida capturada aumentará a cobra int ptsComida; //Quantidade de pontos que a comida vale int pontosAtual = 0; //Quantidade de pontos while (!key[KEY_ESC]) { DesenhaCampoAcao(); if(control == 't'){ if (key[KEY_UP]){ if (dirx != 0) { diry = -20; dirx = 0; } } if (key[KEY_DOWN]){ if (dirx != 0) { diry = 20; dirx = 0; } } if (key[KEY_LEFT]){ if (diry != 0) { dirx = -20; diry = 0; } } if (key[KEY_RIGHT]){ if (diry != 0) { dirx = 20; diry = 0; } } } else if(control = 'j') { swt = inp32(0x379); if (swt == 95){ if ((countMsecCmd / 100) > 1){ if (dirx == 20 && diry == 0) { diry = 20; dirx = 0; } else if (dirx == 0 && diry == 20) { dirx = -20; diry = 0; } else if (dirx == -20 && diry == 0) { diry = -20; dirx = 0; } else if (dirx == 0 && diry == -20) { dirx = 20; diry = 0; } countMsecCmd = 0; } } if (swt == 63){ if ((countMsecCmd / 100) > 1){ if (dirx == 0 && diry == 20) { diry = 0; dirx = 20; } else if (dirx == 20 && diry == 0) { dirx = 0; diry = -20; } else if (dirx == 0 && diry == -20) { diry = 0; dirx = -20; } else if (dirx == -20 && diry == 0) { dirx = 0; diry = 20; } countMsecCmd = 0; } } } if ((countMsec / veloc) > 1){ x += dirx; y += diry; if (VerifCollision(snake, comidas, x, y, &xx, &yy, tamCobra, &tipoCol, &ptsComida, &tamComida)){ switch (tipoCol){ case 0: break; case 1://colisao com corpo textprintf_ex(screen, font, 0,560, makecol(255,0,0 ), -1,"Colisao Em : x: %d y: %d TipoCol: %d", xx, yy, tipoCol); tipoCol = 0; ResetaPosicaoCobra(snake, tamCobra); play_sample(snakeHitSelf,255,90,1000,0); if (qtdVidas > 1){qtdVidas=0;} else {qtdVidas = -1;} MostraVidas(qtdVidas,vidas); x=20; y=20; dirx = 20; diry = 0; AcendeLuzes(); break; case 2://colisao obstaculos textprintf_ex(screen, font, 0,560, makecol(255,0,0 ), -1,"Colisao Em : x: %d y: %d TipoCol: %d", xx, yy, tipoCol); tipoCol = 0; ResetaPosicaoCobra(snake, tamCobra); play_sample(snakeHit,255,90,1000,0); qtdVidas--; MostraVidas(qtdVidas,vidas); x=20; y=20; dirx = 20; diry = 0; AcendeLuzes(); break; case 3: //colisao comida textprintf_ex(screen, font, 0,560, makecol(255,0,0 ), -1,"Colisao Em : x: %d y: %d TipoCol: %d", xx, yy, tipoCol); AumentaCobra(snake, &tamCobra, tamComida, bmpParte); pontosAtual += ptsComida; tipoCol = 0; CriaComida(comidas); break; } } MoveSnake(snake, x, y, tamCobra); MostraStatus(pontosAtual, tamCobra); draw_sprite(screen,status,800,0); countMsec = 0; for (int i = 0;i < tamCobra;i++){ draw_sprite(buffer, snake[i].bmp, snake[i].x,snake[i].y); } for (int i = 0;i < 10;i++){ if (comidas[i].visible){ draw_sprite(buffer, comidas[i].bmp, comidas[i].x,comidas[i].y); } } draw_sprite(screen,buffer,0,0); IntercalaLeds(); } else if(qtdVidas < 0) { play_sample(snakeDeath,255,90,1000,0); stop_midi(); play_sample(gameOver,255,90,1000,0); GravaRank(pontosAtual, countSec, tamCobra); clear_to_color(buffer, makecol(165,229,101)); clear_to_color(screen, makecol(165,229,101)); MostraRank(); textprintf_ex(buffer, myfont, 300,500, makecol(255,0,0), -1,"Aperte ESC para sair...." ); draw_sprite(screen,buffer,0,0); break; } } while (!key[KEY_ESC]) {} FinalizaPP(); }
int menu_play() { DATAFILE *menu = load_datafile("data\\menu.dat"); BITMAP *buffer = create_bitmap(640,480); BITMAP *mbuffer = create_bitmap(640,480); MIDI *inicio = load_midi("musics\\inicio.midi"); font = (FONT *)menu[9].dat; int ret; CBotao Jogar; Jogar.Start(); Jogar.img[NORMAL] = (BITMAP *)menu[2].dat; Jogar.img[CIMA] = (BITMAP *)menu[3].dat; Jogar.tx = 134; Jogar.ty = 30; CBotao Opcoes; Opcoes.Start(); Opcoes.img[NORMAL] = (BITMAP *)menu[4].dat; Opcoes.img[CIMA] = (BITMAP *)menu[5].dat; Opcoes.tx = 134; Opcoes.ty = 30; CBotao Sair; Sair.Start(); Sair.img[NORMAL] = (BITMAP *)menu[6].dat; Sair.img[CIMA] = (BITMAP *)menu[7].dat; Sair.tx = 134; Sair.ty = 30; blit((BITMAP *)menu[1].dat, buffer, 0, 0, 0, 0, 640, 480); draw_sprite(buffer, Jogar.img[NORMAL], 253, 274); draw_sprite(buffer, Opcoes.img[NORMAL], 253, 315); draw_sprite(buffer, Sair.img[NORMAL], 253, 356); play_fli("movie\\filme.flc", screen, 0 , check_escape_key); fade_in((BITMAP *)menu[10].dat, 10); play_fli("movie\\filme2.flc", screen, 0 , check_escape_key); fade_out(10); set_trans_blender(255, 255, 255, 75); draw_trans_sprite(buffer, (BITMAP*)menu[8].dat, 30, 480-323); fade_in(buffer, 10); play_midi(inicio, 100); while(!key[KEY_ESC]) { rest(3); clear_bitmap(buffer); clear_to_color(mbuffer, makecol(255,0,255)); blit((BITMAP *)menu[1].dat, buffer, 0, 0, 0, 0, 640, 480); if (!Jogar.Manage(buffer, 253, 274, mbuffer, "Clique aqui para Jogar")) { ret = JOGAR; break; } if (!Opcoes.Manage(buffer, 253, 315, mbuffer, "Opcoes de Jogo")) { ret = OPCOES; break; } if (!Sair.Manage(buffer, 253, 356, mbuffer, "Sair do Jogo")) { ret = SAIR; break; } set_trans_blender(255, 255, 255, 70); draw_trans_sprite(buffer, (BITMAP*)menu[8].dat, 30, 480-323); draw_sprite(mbuffer, (BITMAP *)menu[0].dat, mouse_x, mouse_y); //textprintf_ex(buffer, font, 10, 10, makecol(0,0,0),-1, "FPS: %d", fps); set_trans_blender(255, 255, 255, 150); draw_trans_sprite(buffer, mbuffer, 0, 0); blit(buffer, screen, 0, 0, 0, 0, 640, 480); } fade_out(10); //destroy_bitmap(mbuffer); Jogar.Destroy(); Opcoes.Destroy(); Sair.Destroy(); destroy_bitmap(buffer); return ret; }
int main() { int field[25][50]; int python[1000][2]; int fd[2]; int k,i,j,n=1,counter=0, over,t2; char directory[] = "Music/x.mid"; allegro_init(); install_keyboard(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 272, 0, 0); install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL); BITMAP *buffer = create_bitmap(600,272); MIDI *music; while(n>0) { dir = r; length = 4; score = 0; t = 100; sp = 1; over = 0; look = 'r'; t2 = 1; python[0][0] = 15; python[0][1] = 10; python[1][0] = 15; python[1][1] = 9; python[2][0] = 15; python[2][1] = 8; python[3][0] = 15; python[3][1] = 7; srand(time(NULL)); directory[6] = intchar(rand()%9 + 1); music = load_midi(directory); play_midi(music,0); clear_to_color(screen,0x000000); opening(); menu_mode(field); init(field); position(field,python); // position the snake food(field,fd); guardi = python[length-1][0]; guardj = python[length-1][1]; display(field,python,fd,t2); while(over!=1) { if(t2<10) { t2++; } guardi = python[length-1][0]; guardj = python[length-1][1]; save = dir; python[length][0] = i; python[length][1] = j; rest(10); if(keypressed()) { dir = readkey(); } else if ((dir & 0xff) == 'w') dir =u; else if ((dir & 0xff) == 's') dir =d; else if ((dir & 0xff) == 'a') dir =l; else if ((dir & 0xff) == 'd') dir =r; if((dir==u)||(dir==d)||(dir==l)||(dir==r)) { over = analysis(field,python,fd); rest(t-10); } else if(dir==esc) { over=1; n=0; } else { dir = save; over = analysis(field,python,fd); rest(t-10); }; display(field,python,fd,t2); } portal1[0] = 50; portal1[1] = 50; portal2[0] = 50; portal2[1] = 50; clear_to_color(screen,0xFFFFFF); textout_ex(screen,font,"Score: ",225,160,0x02094A,0xF7FF0B); outnumber(265,160,score); saverec(field,python,fd); destroy_midi(music); rest(100); if(readkey()==esc) { n=0; } } destroy_bitmap(buffer); return 0; }