void cargar_bitmap(){ start = load_wav("asd/pacman_beginning.wav"); dead = load_wav("asd/pacman_death.wav"); eat = load_wav("asd/pacman_chomp.wav"); enem1 = load_bitmap("asd/enemigo1.bmp", NULL); enemy1 = create_bitmap(30,30); enem2 = load_bitmap("asd/enemigo2.bmp", NULL); enemy2 = create_bitmap(30,30); enem3 = load_bitmap("asd/enemigo3.bmp", NULL); enemy3 = create_bitmap(30,30); enem4 = load_bitmap("asd/enemigo4.bmp", NULL); enemy4 = create_bitmap(30,30); buffer = create_bitmap(880, 600); rock = load_bitmap("asd/rocaII.bmp", NULL); dish1 = load_bitmap("asd/comida1.bmp", NULL); dish2 = load_bitmap("asd/comida2.bmp", NULL); dish3 = load_bitmap("asd/comida3.bmp", NULL); dish4 = load_bitmap("asd/comida4.bmp", NULL); dish5 = load_bitmap("asd/comida5.bmp", NULL); pac = load_bitmap("asd/pacman.bmp", NULL); pacman = create_bitmap(33,33); portada = load_bitmap("asd/portada.bmp", NULL); fondo = load_bitmap("asd/fondo.bmp", NULL); life = load_bitmap("asd/live.bmp", NULL); restart = load_bitmap("asd/restart.bmp", NULL); die = load_bitmap("asd/muerte.bmp", NULL); }
void eof_mix_init(void) { int i; char fbuffer[1024] = {0}; eof_log("eof_mix_init() entered", 1); eof_sound_clap = load_wav("eof.dat#clap.wav"); if(!eof_sound_clap) { allegro_message("Couldn't load clap sound!"); } eof_sound_metronome = load_wav("eof.dat#metronome.wav"); if(!eof_sound_metronome) { allegro_message("Couldn't load metronome sound!"); } eof_sound_grid_snap = load_wav("eof.dat#gridsnap.wav"); if(!eof_sound_grid_snap) { allegro_message("Couldn't load seek sound!"); } for(i = 0; i < EOF_MAX_VOCAL_TONES; i++) { //Load piano tones (void) snprintf(fbuffer, sizeof(fbuffer) - 1, "eof.dat#piano.esp/NOTE_%02d_OGG", i); eof_sound_note[i] = eof_mix_load_ogg_sample(fbuffer); } eof_sound_cowbell = eof_mix_load_ogg_sample("percussion.dat#cowbell.ogg"); eof_sound_chosen_percussion = eof_sound_cowbell; //Until the user specifies otherwise, make cowbell the default percussion eof_sound_tambourine1 = eof_mix_load_ogg_sample("percussion.dat#tambourine1.ogg"); eof_sound_tambourine2 = eof_mix_load_ogg_sample("percussion.dat#tambourine2.ogg"); eof_sound_tambourine3 = eof_mix_load_ogg_sample("percussion.dat#tambourine3.ogg"); eof_sound_triangle1 = eof_mix_load_ogg_sample("percussion.dat#triangle1.ogg"); eof_sound_triangle2 = eof_mix_load_ogg_sample("percussion.dat#triangle2.ogg"); eof_sound_woodblock1 = eof_mix_load_ogg_sample("percussion.dat#woodblock1.ogg"); eof_sound_woodblock2 = eof_mix_load_ogg_sample("percussion.dat#woodblock2.ogg"); eof_sound_woodblock3 = eof_mix_load_ogg_sample("percussion.dat#woodblock3.ogg"); eof_sound_woodblock4 = eof_mix_load_ogg_sample("percussion.dat#woodblock4.ogg"); eof_sound_woodblock5 = eof_mix_load_ogg_sample("percussion.dat#woodblock5.ogg"); eof_sound_woodblock6 = eof_mix_load_ogg_sample("percussion.dat#woodblock6.ogg"); eof_sound_woodblock7 = eof_mix_load_ogg_sample("percussion.dat#woodblock7.ogg"); eof_sound_woodblock8 = eof_mix_load_ogg_sample("percussion.dat#woodblock8.ogg"); eof_sound_woodblock9 = eof_mix_load_ogg_sample("percussion.dat#woodblock9.ogg"); eof_sound_woodblock10 = eof_mix_load_ogg_sample("percussion.dat#woodblock10.ogg"); eof_sound_clap1 = eof_mix_load_ogg_sample("percussion.dat#clap1.ogg"); eof_sound_clap2 = eof_mix_load_ogg_sample("percussion.dat#clap2.ogg"); eof_sound_clap3 = eof_mix_load_ogg_sample("percussion.dat#clap3.ogg"); eof_sound_clap4 = eof_mix_load_ogg_sample("percussion.dat#clap4.ogg"); }
/********************************************//** * \brief Charge un son * * \param path char* Chemin du son a charger * \return SAMPLE* * ***********************************************/ SAMPLE *son_load_check(char *path) { SAMPLE *ptr = load_wav(path); if (ptr == NULL) ft_error("load sound"); return ptr; }
void Sound::sndLoadSound (const std::string &SoundFilename) { if(!EnableSound) return; if (!Sounds[SoundFilename]) Sounds[SoundFilename] = load_wav (SoundFilename.c_str()); }
bool Sound::load(const std::string& file_name) { std::string extension = String::lower(file_name.substr(file_name.find_last_of(".") + 1)); if(extension == "wav" || extension == "wave") { return load_wav(file_name); } if(extension == "raw" || extension == "pcm") { return load_pcm(file_name); } return load_ogg(file_name); }
void Load_SFX(unsigned char i, const char* directory) { #ifdef DEBUG fprintf(stderr, "Loading sound effect %d (%s) in memory\n", i, directory); #endif if (sfx_id[i]) { destroy_sample(sfx_id[i]); } sfx_id[i] = load_wav(directory); }
unsigned int Resources::audio(const std::string &audioFile) { std::string fullpath; if (audioMap.find(audioFile) == audioMap.end()) { DEBUG_PRINT("loading " << audioFile); if (search_path(audioFile, fullpath)) { audioMap[audioFile] = load_wav(fullpath); } else { DEBUG_ERROR("file " << audioFile << " doesnt exist or not reachable"); } } else { DEBUG_PRINT("using already loaded " << audioFile); } return audioMap[audioFile]; }
SOUNDCLIP *my_load_wave(const char *filename, int voll, int loop) { #ifdef MAC_VERSION SAMPLE *new_sample = load_wav(filename); #else SAMPLE *new_sample = load_sample(filename); #endif if (new_sample == NULL) return NULL; thiswave = new MYWAVE(); thiswave->wave = new_sample; thiswave->vol = voll; thiswave->firstTime = 1; thiswave->repeat = loop; return thiswave; }
int startGame(){ configAll(); BITMAP * nave = load_bitmap("img/35x45/nave.bmp",NULL); BITMAP * alien = load_bitmap("img/35x45/alien.bmp", NULL); BITMAP * gun = load_bitmap("img/35x45/gun.bmp", NULL); BITMAP * init = load_bitmap("img/start.bmp", NULL); BITMAP * bg = load_bitmap("img/bartop.bmp", NULL); BITMAP * buffer = create_bitmap(SCREEN_W,SCREEN_H); SAMPLE * sound = load_wav("wav/tiro.wav"); SAMPLE * music = load_sample("wav/laserHit.wav"); initStart(buffer,init); install_int_ex(countXa,SECS_TO_TIMER(1)); install_int_ex(countGun,MSEC_TO_TIMER(1)); gameControll(nave,buffer,alien,gun,bg,sound,music); destroyAll(nave,buffer,alien,gun,init,bg,sound,music); return 0; }
bool som::carregar(string arquivo) { if(!egl_init) return false; string ext = arquivo.substr(arquivo.size()-4,arquivo.size()-1); std::transform(ext.begin(), ext.end(), ext.begin(),static_cast < int(*)(int) > (tolower)); if (ext == ".wav") { tipo = T_WAV; if(smp) { destroy_sample(smp); voice = -1; } smp = load_wav(arquivo.c_str()); if(!smp) { egl_erro("Erro carregando arquivo: " + arquivo); egl_debug = true; return false; } } else { tipo = T_MID; if(mid) { destroy_midi(mid); voice = -1; } mid = load_midi(arquivo.c_str()); if(!mid) { egl_erro("Erro carregando arquivo: " + arquivo); egl_debug = true; return false; } } return true; }
void *loom_asset_soundDeserializer( void *buffer, size_t bufferLen, LoomAssetCleanupCallback *dtor ) { loom_asset_sound_t *sound = (loom_asset_sound_t*)lmAlloc(gAssetAllocator, sizeof(loom_asset_sound_t)); memset(sound, 0, sizeof(loom_asset_sound_t)); unsigned char *charBuff = (unsigned char *)buffer; // Look for magic header in buffer. if(charBuff[0] == 0x4f && charBuff[1] == 0x67 && charBuff[2] == 0x67 && charBuff[3] == 0x53) { // It's an Ogg, assume vorbis and throw it to stb_vorbis. int channels = 0; short *outputBuffer = NULL; int sampleCount = stb_vorbis_decode_memory(charBuff, (int)bufferLen, &channels, &outputBuffer); if(sampleCount < 0) { lmLogError(gSoundAssetGroup, "Failed to decode Ogg Vorbis"); loom_asset_soundDtor(&sound); return NULL; } sound->channels = channels; sound->bytesPerSample = 2; sound->sampleCount = sampleCount; sound->bufferSize = sampleCount * channels * 2; sound->sampleRate = 44100; // TODO: This should be variable // We can skip this if we get clever about allocations in stbv. sound->buffer = lmAlloc(gAssetAllocator, sound->bufferSize); memcpy(sound->buffer, outputBuffer, sound->bufferSize); free(outputBuffer); } else if((charBuff[0] == 0x49 // ID3 && charBuff[1] == 0x44 && charBuff[2] == 0x33) || (charBuff[0] == 0xff // Missing ID3 Tag && charBuff[1] == 0xfb)) { // It's an MP3, y'all! short *outBuffer = (short*)lmAlloc(gAssetAllocator, MP3_MAX_SAMPLES_PER_FRAME * 2); mp3_info_t mp3Info; // Decode once to get total size. size_t totalBytes = 0; size_t bytesRead = 0, bytesLeft = bufferLen; mp3_decoder_t decmp3 = mp3_create(); for(;;) { int bytesDecoded = mp3_decode(decmp3, charBuff + bytesRead, (int)bytesLeft, outBuffer, &mp3Info); bytesRead += bytesDecoded; bytesLeft -= bytesDecoded; totalBytes += mp3Info.audio_bytes; if(bytesDecoded > 0) continue; // Clean up. mp3_done(decmp3); break; } // Great, set up the sound asset. // TODO: Warn about non 44.1khz mp3s. sound->channels = mp3Info.channels; sound->bytesPerSample = 2; sound->sampleCount = (int)totalBytes / sound->bytesPerSample; sound->bufferSize = sound->channels * sound->bytesPerSample * sound->sampleCount; sound->sampleRate = 44100; // TODO: This should be variable sound->buffer = lmAlloc(gAssetAllocator, sound->bufferSize); // Decode again to get real samples. decmp3 = mp3_create(); bytesRead = 0; bytesLeft = bufferLen; int curBufferOffset = 0; for(;;) { int bytesDecoded = mp3_decode(decmp3, charBuff + bytesRead, (int)bytesLeft, outBuffer, &mp3Info); bytesRead += bytesDecoded; bytesLeft -= bytesDecoded; memcpy(((unsigned char*)sound->buffer) + curBufferOffset, outBuffer, mp3Info.audio_bytes); curBufferOffset += mp3Info.audio_bytes; if(bytesDecoded > 0) continue; // Clean up. mp3_done(decmp3); break; } // Awesome, all set! lmFree(gAssetAllocator, outBuffer); } else if(charBuff[0] == 0x52 // 'RIFF' && charBuff[1] == 0x49 && charBuff[2] == 0x46 && charBuff[3] == 0x46) { // We've got a wav file wav_info wav; bool wavLoadSuccess = load_wav(charBuff, bufferLen, NULL, &wav); if (!wavLoadSuccess) { lmLogError(gSoundAssetGroup, "Failed to load wav format info"); loom_asset_soundDtor(sound); return 0; } sound->channels = wav.numChannels; sound->bytesPerSample = wav.sampleSize / 8; // wav sample size is in bits if (sound->bytesPerSample != 1 && sound->bytesPerSample != 2) { lmLogError(gSoundAssetGroup, "Unsupported wav format. Currently only 8-bit or 16-bit PCM are supported"); loom_asset_soundDtor(sound); return 0; } sound->bufferSize = wav.sampleDataSize; sound->sampleCount = sound->bufferSize / sound->bytesPerSample; sound->sampleRate = wav.samplesPerSecond; sound->buffer = lmAlloc(gAssetAllocator, sound->bufferSize); bool dataCopySuccess = load_wav(charBuff, bufferLen, (uint8_t*)sound->buffer, NULL); if (!dataCopySuccess) { lmLogError(gSoundAssetGroup, "Failed to copy wav data"); loom_asset_soundDtor(sound); return 0; } } else { lmLogError(gSoundAssetGroup, "Failed to identify sound buffer by magic number!"); loom_asset_soundDtor(sound); return 0; } *dtor = loom_asset_soundDtor; if(!sound->buffer) { lmLogError(gSoundAssetGroup, "Sound load failed due to this cryptic reason: %s", "(unknown)"); lmFree(gAssetAllocator, sound); return 0; } lmLogDebug(gSoundAssetGroup, "Sound allocation: %d bytes", sound->bufferSize); return sound; }
blit(muertebmp,enemigom,0,0,0,0,33,33);//carga la imagen sobre el buffer pacman draw_sprite(buffer,enemigom,_x,_y); blit(buffer, screen ,0,0,0,0,1280,600); rest(80); _x = 0; _y = 0; vidaenemigo--; } } int main() { allegro_init(); install_keyboard(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED,1280, 600 , 0, 0); //inicializa la musica en allegro if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { allegro_message("Error: inicializando sistema de sonido\n%s\n", allegro_error); return 1; } // ajuste de volumen set_volume(70, 70);//cuanto se oye a la izquierdsa y a la derecha intro = load_wav("music/start.wav"); sirenafantasma = load_wav("music/sirene.wav"); muertes = load_wav("music/muerte.wav"); buffer = create_bitmap(1280,600); //870 570 pacman = create_bitmap(33,33); complemento = create_bitmap(400,600); vid =create_bitmap(33,33); ataqueb = create_bitmap(33,33); atabmp = load_bitmap("images/ataque.bmp",NULL); roca = load_bitmap("images/tile2.bmp",NULL); pacbmp =load_bitmap("images/tank2.bmp", NULL); comida = load_bitmap("images/Comida.bmp",NULL); muertebmp = load_bitmap("images/muerte1.bmp",NULL); combmp =load_bitmap("images/complemento.bmp",NULL); vidas = load_bitmap("images/vidas.bmp",NULL); mapa1 mapa; enemigo A1(30*1,30*18) ; enemigo A2(30*27,30*1) ; enemigo A3(30*14,30*11) ; enemigo A4(30*27,30*18) ; enemigo A5(30*27,30*18); personaje1 personaje; personaje2 personaje3; play_sample(intro,200,150,1000,0); // volumen,sonido,,velocidad a la que se reproduce,distribucion 1000 es punto medio,para que no se repita rest(4000); play_sample(sirenafantasma,150,150,1000,1); while (!key[KEY_ESC] && mapa.game_over()) { if(A1.getvida()==0 && A2.getvida()==0 && A3.getvida()==0 && A4.getvida()==0) return false; personaje.mover_personaje(); mapa.dibujar_mapa(); personaje.dibujar_personaje(); personaje.ataque(); personaje.ataque1(); personaje3.dibujar_personaje(); personaje3.mover_personaje(); A1.mover_enemigo(); A2.mover_enemigo(); A4.mover_enemigo(); A3.mover_enemigo(); personaje3.ataque(); personaje3.ataque1(); A1.ataque2(); A1.ataque_enemigo(); A2.ataque2(); A2.ataque_enemigo(); A4.ataque2(); A4.ataque_enemigo(); A3.ataque2(); A3.ataque_enemigo(); A1.muerte_enemigo(); A2.muerte_enemigo();
void Load_Music(const char* directory) { Clean_Music(); music = load_wav(directory); }
int main(int argc, char *argv[]) { // mallocated stuff float * wave_buffer; float * aa_buffer; float * work_buffer; float * frame_buffer; float * dft_bins; unsigned int * frequencies; unsigned int * volumes; unsigned char * out_buffer; unsigned char consolidate; unsigned long wave_size, work_size; unsigned int frame_size, frame_inc; unsigned int i; int ofs; unsigned long idx; unsigned long c, m, k, t, f; unsigned int kmax; float max_power; float in_r, sum_r, sum_i; float ratio; unsigned long frame_idx = 0, frames; char outfilepath[256]; unsigned int ext; puts("PSGTalk 0.3 - furrtek 2017\n"); // Overlap = 0 // Data: ######################## (24) // Frames: AAAAAAAA // BBBBBBBB // CCCCCCCC // Count: 3 // Length: 8 = 24 / 3 * (0 + 1) // Offset: 8 = Length * (1 - 0) // Overlap = 0.5 // Data: ######################## (24) // Frames: AAAAAAAAAAAA // BBBBBBBBBBBB // CCCCCCCCCCCC // Count: 3 // Length: 12 = 24 / 3 * (0.5 + 1) // Offset: Length * (1 - 0.5) // Defaults overlap = 0.25; updates_per_frame = 2; psg_channels = 3; sim = 0; mode = MODE_VGM; fps = 60; freq_res = 64; if (parse_args(argc, argv)) return 1; wave_size = load_wav(argv[argc - 1], &wave_buffer); if (!wave_size) { puts("Can't load wave file.\n"); return 1; } // Anti-alias filtering aa_buffer = calloc(wave_size, sizeof(float)); if (aa_buffer == NULL) { puts("Memory allocation failed\n"); free(wave_buffer); return 1; } lowpass(wave_buffer, aa_buffer, 8192.0, samplerate_in, wave_size); // Decimate ratio = ((float)samplerate_in / 8192.0); work_size = (int)(wave_size / ratio); work_buffer = calloc(work_size, sizeof(float)); if (work_buffer == NULL) { puts("Memory allocation failed\n"); free(wave_buffer); free(aa_buffer); return 1; } for (i = 0; i < work_size; i++) work_buffer[i] = aa_buffer[(int)(i * ratio)]; update_rate = fps * updates_per_frame; frame_size = (8192.0 * (overlap + 1.0)) / update_rate; frame_inc = (float)frame_size * (1.0 - overlap); m = 1; // Discrimination between power peaks frames = work_size / frame_inc; // Total number of frames freq_step = (8192 / freq_res) / 2; frame_buffer = calloc(frame_size, sizeof(float)); dft_bins = calloc(freq_res, sizeof(float)); frequencies = calloc(frames * psg_channels, sizeof(unsigned int)); volumes = calloc(frames * psg_channels, sizeof(unsigned int)); if ((dft_bins == NULL) || (frame_buffer == NULL) || (frequencies == NULL) || (volumes == NULL)) { puts("Memory allocation failed\n"); return 1; } if (!make_LUTs(frame_size)) { puts("Table generation failed\n"); return 1; } // Show recap printf("Frames: %lu\n", frames); printf("Overlap: %u%%\n", (unsigned int)(overlap * 100.0)); printf("Samplerate: %luHz -> %uHz\n", samplerate_in, 8192); printf("Resolution: %uHz\n", freq_step); printf("Update rate: %u/frame (%uHz @ %ufps)\n", updates_per_frame, update_rate, fps); printf("PSG channels: %u\n", psg_channels); printf("Mode: %s\n", modestr[mode]); f = 0; do { // Copy frame memcpy(frame_buffer, &work_buffer[f], frame_size * sizeof(float)); // Apply window for (t = 0; t < frame_size; t++) frame_buffer[t] *= window_lut[t]; // Do DFT for (k = 0; k < freq_res; k++) { // For each output element sum_r = 0; sum_i = 0; for (t = 0; t < frame_size; t++) { // For each input element c = ((32768 * t * k / 2) / frame_size) & 0x7FFF; in_r = frame_buffer[t]; sum_r += (in_r * cos_lut[c]); sum_i += (in_r * sin_lut[c]); } sum_r /= frame_size; sum_i /= frame_size; dft_bins[k] = sqrt((sum_i * sum_i) + (sum_r * sum_r)); //if (f == 0) printf("SAMP=%f POW=%f (%uHz)\n", frame_buffer[k], dft_bins[k], k * freq_step); } // Find highest peaks consolidate = 0; for (c = 0; c < psg_channels; c++) { idx = (frame_idx * psg_channels) + c; if (consolidate) { max_power -= 0.4; frequencies[idx] = frequencies[idx - 1]; volumes[idx] = lintolog(max_power); } else { // Find highest power and its associated frequency (skip DC bin) max_power = 0; for (k = 1; k < (frame_size - 1); k++) { if (dft_bins[k] > max_power) { max_power = dft_bins[k]; kmax = k; } } // Clear surrounding bins if needed for (t = 0; t < m; t++) { ofs = kmax - t - 1; if (ofs >= 0) dft_bins[ofs] = 0; ofs = kmax + t + 1; if (ofs < freq_res) dft_bins[ofs] = 0; } frequencies[idx] = kmax; volumes[idx] = lintolog(max_power); } consolidate = (max_power >= 0.4) ? 1 : 0; if (frame_idx == 0) printf("C%lu=%uHz\n", c, kmax * freq_step); // DEBUG } frame_idx++; f += frame_inc; printf("\rComputing frame %lu/%lu.", frame_idx, frames); } while (f < (work_size - frame_size)); puts(" Done.\n"); // Generate output file strcpy(outfilepath, argv[argc - 1]); ext = strlen(outfilepath) - 3; if (mode == MODE_VGM) { outfilepath[ext++] = 'v'; outfilepath[ext++] = 'g'; outfilepath[ext] = 'm'; } else { outfilepath[ext++] = 'b'; outfilepath[ext++] = 'i'; outfilepath[ext] = 'n'; } FILE * fo = fopen(outfilepath, "wb"); if (mode == MODE_RAW) { out_raw(&out_buffer, frequencies, volumes, frame_idx, freq_res); } else if (mode == MODE_VGM) { out_vgm(&out_buffer, frequencies, volumes, frame_idx); } else if (mode == MODE_NGP) { out_ngp(&out_buffer, frequencies, volumes, frame_idx); } fwrite(out_buffer, file_length, 1, fo); fclose(fo); free(out_buffer); puts("Output file written."); printf("Size: %lukB\n", file_length / 1024); // Generate simulation file if needed if (sim) { if (gen_sim(frame_size, frame_idx, psg_channels, frequencies, volumes)) puts("\nSimulation file written.\n"); } free(frequencies); free(volumes); free(frame_buffer); free(wave_buffer); free(work_buffer); free(dft_bins); system("pause"); //return 0; return 0; }
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(); }
void IntercalaLeds(); volatile int countMsec; // Variável Global volatile int countSec; // Variável Global volatile int countMsecCmd; // Variável Global volatile int countMsecLed; // Variável Global void ContaMsec(); void ContaSec(); PALLETE pallet; BITMAP* buffer; BITMAP* status; SAMPLE* snakeBit = load_wav("sounds/snakeEat.wav"); int tamCobra = 2; int qtdVidas = 6; int xC=0, yC=0, xC2=780, yC2 = 580; //Coordenadas do campo de ação da cobra int as = 0; BITMAP* bmpSapo; BITMAP* bmpAranha; BITMAP* bmpMaca; BITMAP* bmpMilho; BITMAP* bmpCobraHead; BITMAP* bmpFundo;