//Sounds void ce_game::playSounds(){ //Walk sound if not already playing if ((key[KEY_A] || key[KEY_D] || key[KEY_LEFT] || key[KEY_RIGHT]) && (player->isWalkingLeft || player->isWalkingRight) && !jumpSound){ if (!walkSound){ walkSound = true; play_sample(walk,255,128,1000,10000); } }else{ walkSound = false; stop_sample(walk); } //Ladder sound if not already playing if ((key[KEY_W] || key[KEY_S] || key[KEY_UP] || key[KEY_DOWN]) && player->isClimbing && !jumpSound){ if (!ladderSound){ ladderSound = true; play_sample(ladder,255,128,1000,10000); } }else{ ladderSound = false; stop_sample(ladder); } //Jump sound if not already playing if (player->isJumping){ if (!jumpSound){ jumpSound = true; play_sample(jump,255,128,1000,10000); } }else{ jumpSound = false; stop_sample(jump); } }
void ce_game::end_game(){ isPlaying = false; //Stop sounds stop_sample(walk); stop_sample(jump); stop_sample(ladder); //Play ending sound if (hasWon){ play_sample(win,255,128,1000,0); }else{ play_sample(death,255,128,1000,0); } }
int makeSlider(slider_t *theSlider) { SAMPLE *slideNoise = makeSample("Menu_Sounds/SliderNoise.wav"); BITMAP *bar = makeBitmap("Menu_Images/Slider.bmp"); if (mouse_b && menu_mouseIsOverSlider(theSlider)) { theSlider->position += (mouse_x - theSlider->position)/ 4; stop_sample(slideNoise); play_sample(slideNoise, 155, 0, 1000, 0); } draw_sprite(menuBuffer, bar, theSlider->position - 10, theSlider->top + 5); theSlider->current = (int)(((theSlider->position - theSlider->left) * theSlider->values)/theSlider->width) + 1; if (theSlider->current > theSlider->values) { theSlider->current = theSlider->values; } else if (theSlider->current < 1) { theSlider->current = 1; } return (theSlider->current); }
static inline void tur_do_laser(game_data_t *gd, turret_t *turret) { /* shoot something? */ turret->laser_fire = 0; if (turret->target_monster != NULL) { if ((fixtoi(turret->angle) == fixtoi(turret->desired_angle)) && tur_target_within_range(turret, (int)turret->target_monster->x + 16, (int)turret->target_monster->y + 16)) { if (tur_target_within_sight(turret, (int)turret->target_monster->x + 16, (int)turret->target_monster->y + 16) == 1) { if (turret->fire_reset_count == 0) { turret->fire_reset_count = 1; turret->laser_fire = 1; stop_sample(gd->samples->gun_laser); play_sample(gd->samples->gun_laser, 255, 128, 1000, 0); /* register damage */ monster_register_hit(turret->target_monster, 0.5); } } } } if (turret->fire_reset_count > 0) turret->fire_reset_count--; tur_rotate(turret); tur_target(turret); }
void movemissile() { samExplosion2 = load_sample("C:\\Sanchit\\Game Pack\\Sprites\\explosion2.wav"); int x = points[curpoint].x ; int y = points[curpoint].y ; scare_mouse(); rectfill(buffer,x-6,y-3,x+6,y+1,BLACK); if (getpixel(screen,x,y) == GREEN) { destroyed++; updatescore(); rectfill(buffer, 2, 14, 636, 352, BLACK); } else { putpixel(buffer,x,y-3,SMOKE); circlefill(buffer,x,y,2,BLUE); } unscare_mouse(); curpoint++; if (curpoint >= totalpoints) { play_sample(samExplosion2, 128, 128, 1000, 0); destroyed++; explosion2(screen, x, y, BLACK); textout_ex( screen, font, "Game Over", 300, 230, makecol( 255, 0, 0), makecol( 0, 0, 0)); rest(2000); textprintf(screen,font,300,245,makecol(255,255,255), "Final Score=%d", score); rest(2000); stop_sample(samSong); stop_sample(samExplosion2); score=-1; openscreen(); } }
void MYWAVE::restart() { if (wave != NULL) { done = 0; paused = 0; stop_sample(wave); voice = play_sample(wave, vol, panning, 1000, 0); } }
void MYWAVE::internal_destroy() { // Stop sound and decrease reference count. stop_sample(wave); sound_cache_free((char*)wave, true); wave = NULL; _destroyThis = false; done = 1; }
void som::parar() { if (tipo == T_WAV) { if(!smp) return; stop_sample(smp); } else if (tipo == T_MID) { if(!mid) return; stop_midi(); } }
int get_adc_sample(int chan) { int count; int value = -1; int sum; set_chan_list(chan, 1); set_avg_mode(chan, NO_AVG_MODE, SAMPLE_NUM_8); set_sample_mux(chan, g_chan_mux[chan]); set_detect_mux(g_chan_mux[chan]); set_idle_mux(g_chan_mux[chan]); // for revb enable_sample_engine(); start_sample(); // Read any CBUS register to delay one clock // cycle after starting the sampling engine // The bus is really fast and we may miss that it started { count = READ_CBUS_REG(ISA_TIMERE); } count = 0; while (delta_busy() || sample_busy() || avg_busy()){ if (++count > 10000){ printf("ADC busy error.\n"); goto adc_sample_end; } } stop_sample(); sum = 0; count = 0; value = get_fifo_sample(); while (get_fifo_cnt()){ value = get_fifo_sample() & 0x3ff; if ((value != 0x1fe) && (value != 0x1ff)){ sum += value & 0x3ff; count++; } } value = (count) ? (sum / count) : (-1); adc_sample_end: #if AML_ADC_SAMPLE_DEBUG printf("ch%d = %d, count=%d\n", chan, value, count); #endif //AML_ADC_SAMPLE_DEBUG disable_sample_engine(); set_sc_phase(); return value; }
void exit_sequence(Game* game){ //check exit keypress if(key[KEY_ESC] || key[KEY_Q]){ fprintf(fpLog, "Game paused.\n"); stop_sample(game->bgMusic); //ensure exit textprintf_ex(screen, font, 5, 5, makecol(255, 255, 255), -1, "Press Q again to quit."); clear_keybuf(); if(readkey() >> 8 == KEY_Q){ game->running = false; }else{
int get_adc_sample(int chan) { int count; int value; int sum; if (!gp_saradc) return -1; spin_lock(&gp_saradc->lock); set_chan_list(chan, 1); set_avg_mode(chan, NO_AVG_MODE, SAMPLE_NUM_8); set_sample_mux(chan, chan_mux[chan]); set_detect_mux(chan_mux[chan]); set_idle_mux(chan_mux[chan]); // for revb enable_sample_engine(); start_sample(); // Read any CBUS register to delay one clock cycle after starting the sampling engine // The bus is really fast and we may miss that it started { count = get_reg(ISA_TIMERE); } count = 0; while (delta_busy() || sample_busy() || avg_busy()) { if (++count > 10000) { printk(KERN_ERR "ADC busy error.\n"); goto end; } } stop_sample(); sum = 0; count = 0; value = get_fifo_sample(); while (get_fifo_cnt()) { value = get_fifo_sample() & 0x3ff; if ((value != 0x1fe) && (value != 0x1ff)) { sum += value & 0x3ff; count++; } } value = (count) ? (sum / count) : (-1); end: //printk("ch%d = %d, count=%d\n", chan, value, count); disable_sample_engine(); spin_unlock(&gp_saradc->lock); return value; }
void pingpong_score() { if(for_scoring==2) count2++; else if(for_scoring==1) count1++; textprintf(screen,font,60,2,makecol(255,255,255), "P1=%d", count1); textprintf(screen,font,540,2,makecol(255,255,255), "P2=%d", count2); if(count1==5 || count2==5) { declare_winner(); stop_sample(samSong); openscreen(); } startNew(); }
void showIntro() { SAMPLE *copyAmbient = makeSample("Menu_Sounds/Intro Wind.wav"); BITMAP *copyBackground = makeBitmap("Menu_Images/Copyright Intro Screen.bmp"); double startTime; blit(copyBackground, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen play_sample(copyAmbient, 255, 0, 1000, 0); startTime = time(0); while (startTime + 10 > time(0) && !key[KEY_ESC]) { } stop_sample(copyAmbient); destroy_sample(copyAmbient); destroy_bitmap(copyBackground); }
void EffectsManager::announcerQuip(int which) { //destroy_sample(currentAnnouncer); stop_sample(currentAnnouncer); if ( which >= 41 && which < 156 ) // only do announcers { //char filename[] = "DATA/sfx/GAME_0000.wav"; //filename[15] = (which/100)%10 + '0'; //filename[16] = (which/10)%10 + '0'; //filename[17] = (which % 10) + '0'; currentAnnouncer = basic_sfx[which];// load_sample(filename); if ( currentAnnouncer != NULL ) { playSFXOnce(currentAnnouncer); } } }
void printScenarioOptions() { static int firstTime = 1; static slider_t moneySlider; if (firstTime) { initializeSlider(&moneySlider, 493, 190, 442, 50, 4, 1, 700); } static MENUBUTTON forwardArrow; initializeButton(&forwardArrow, 920, 677, 57, 50, "Menu_Images/Forward Arrow.bmp"); BITMAP *newBackground = makeBitmap("Menu_Images/Scenario Menu 01.bmp"); draw_sprite(menuBuffer, newBackground, 0, 0); makeSlider(&moneySlider); if (menu_mouseIsOver(&forwardArrow)) { forwardArrow.picture = makeBitmap("Menu_Images/Forward ArrowH.bmp"); } else if (!menu_mouseIsOver(&forwardArrow)) { forwardArrow.picture = makeBitmap("Menu_Images/Forward Arrow.bmp"); } if (mouse_b) { if (menu_mouseIsOver(&forwardArrow)) { showAssignment(); stop_sample(newAmbient); loadingPhase = 0; inGame = 1; initializeAllObjects(); initializeMapSquares(); SPQR_Game(); emptyGame(); } } draw_sprite(menuBuffer, forwardArrow.picture, forwardArrow.left, forwardArrow.top); firstTime = 0; }
int pingpong() { buffer = create_bitmap( 640, 480); BITMAP *BGpong = load_bitmap("C:\\Sanchit\\Game Pack\\Sprites\\BGpong.bmp", NULL); samSong = load_sample("C:\\Sanchit\\Game Pack\\Sprites\\pingpong.wav"); play_sample(samSong, 128, 128, 1000, 1); setupGame(); while( !key[KEY_ESC]) { draw_sprite(buffer, BGpong, 0,0); textprintf(buffer,font,60,2,makecol(255,255,255), "P1=%d", count1); textprintf(buffer,font,540,2,makecol(255,255,255), "P2=%d", count2); p1Move(); p2Move(); moveBall(); checkWin(); if(scored==1) pingpong_score(); if(key[KEY_BACKSPACE]) { count1=0; count2=0; ball_x=320; ball_y=240; p1_x = 20; p1_y = 210; p2_x = 620; p2_y = 210; stop_sample(samSong); openscreen(); } } return 0; }
// -2 -> hole -1 -> all chances are over 0 -> ball lost 1 -> successful int ball::update_position(int value) { play_sample(swing, VOLUME, PANNING, PITCH, TRUE); rest(100); stop_sample(swing); currx = initx; curry = inity; for (int i=0; i<value-50; i+=5) { //without -50 level 3 was not working properly impossible to hit condition currx+=xspeed; curry+=yspeed; blit(buffer, screen, 0, 0, 0, 0, 640, 480); draw_sprite(screen, image, currx, curry); if(HOLE.is_inside(currx, curry, currx+width, curry+height)) { //birdie blit(buffer, screen, 0, 0, 0, 0, 640, 480); draw_sprite(screen, image, 60, 60); //draw ball inside hole blit(win, screen, 0, 0, 0, 0, 640, 480); rest(2500); return -2; } //check for ball in water for level 1 if (level == 1) { if (!(((curry > 15 && curry<156) && (currx >16 && currx<615)) || ((curry > 156 && curry<460) && (currx >475 && currx<615)))) { return(ball_lost()); } } //for level 2 else if (level == 2) { if (!((((curry>15&&curry<120)||(curry>360&&curry<465)) && (currx>23&&currx<617)) || ((curry>120&&curry<360)&&(currx>430&&currx<617)))) { return(ball_lost()); } } //for level 3 else if (level == 3) { if (!((((curry>15&&curry<110)||(curry>380&&curry<450)) && (currx>22&&currx<618)) || ((curry>110&&curry<380)&&(currx>498&&currx<618)) || ((curry>140&&curry<380)&&(currx>22&&currx<110)))) { return(ball_lost()); } } rest(260-value); //rest before repeating loop } initx = currx; inity = curry; if (ball_left < 0) { draw_sprite(screen, gameover, 0, 0); rest(2500); return -1;} //All chances are over return 1; //successful }
void update_crusher() { if (alarm_crazy_time < 0) { if (alarm_time_blue >= 0) { alarm_time_blue++; if (1000*alarm_time_blue/FRAMES_PER_SECOND > alarm_msec_blue) alarm_time_blue = -1; } if (alarm_time_red >= 0) { alarm_time_red++; if (1000*alarm_time_red/FRAMES_PER_SECOND > alarm_msec_red) alarm_time_red = -1; } } else { alarm_crazy_time++; if (alarm_crazy_time > FRAMES_PER_SECOND*3/2) { stop_sample(datafile[SAMP_ALARM].dat); alarm_crazy_time = -1; alarm_time_blue = -1; alarm_time_red = -1; } else { alarm_crazy_switch++; if (alarm_crazy_switch > FRAMES_PER_SECOND/8) { alarm_crazy_switch = 0; if (alarm_time_blue >= 0) { alarm_time_blue = -1; alarm_time_red = 0; } else { alarm_time_blue = 0; alarm_time_red = -1; } } } } }
void Sound::Sample::draw() { // Erste Rechnung: 255 ist volle Lautstaerke, 0 - 20 ist unsere Skala. // Mittlere 127: In der Mitte des Bildschirms // Mittlere 1000: Normale Schnelligkeit // Hintere 0: Kein Loop if (sample) { if (unique && (loud || (quiet && !last_was_loud))) stop_sample(sample); if (loud) { last_was_loud = true; play_sample(sample, useR->sound_volume * 256 / 20, 127, 1000, 0); } else if (quiet) { last_was_loud = false; play_sample(sample, useR->sound_volume * 64 / 20, 127, 1000, 0); } loud = false; quiet = false; } }
void newGame() { BITMAP *loadScreen = NULL; loadScreen = load_bitmap("Loading Screen.bmp", NULL); // Load our picture BITMAP *newBuffer = NULL; newBuffer = create_bitmap(1024,768); //Create an empty bitmap. float creditPosition = 1024; int aKey = -1; creditPosition = advanceCredits(0, creditPosition); creditPosition = advanceCredits(735, creditPosition); creditPosition = advanceCredits(1590, creditPosition); creditPosition = advanceCredits(2500, creditPosition); stop_midi(); SAMPLE *transmission1 = load_sample("Transmission1.wav"); play_sample(transmission1, 255, 0, 1000, 0); fallingText(); stop_sample(transmission1); draw_sprite(newBuffer, loadScreen, 0, 0); blit(newBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen while (!key[KEY_SPACE]) { readkey(); } return; }
int main(int argc, char *argv[]) {//start of main function //set gameover = true to stop the game from loading before the player plays GAMEOVER=true; //variable declerations int id; //variables used for the threads pthread_t pthread0; pthread_t pthread1; int threadid0 = 0; int threadid1 = 1; int threadid2 = 2; int threadid3 = 3; int threadid4 = 4; int threadid5 = 5; int threadid6 = 6; //set is intro to true to play the intro bool inIntro =true; //variable used to display the players message char *playermessage; //map variables int mapxoff = 0; int mapyoff = 0; //game speed variables declerations and initalization int frames_per_sec=0; int frames_done=0; int old_time =0; int totaltime=0; //declare allegro variables //BITMAP *buffer; BITMAP *intro; //initalize the classes //player *owl; sprite *hearts[3]; sprhandler = new spritehandler(); snake *snakeboss; //initalize allegro allegro_init(); install_keyboard(); install_timer(); set_keyboard_rate(1000,1000); install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL); //initalize the screen set_color_depth(COLORDEPTH); set_gfx_mode(MODE,WIDTH,HEIGHT,0,0); //lock both the varibale and the funciton to be used by the interrupt handler LOCK_VARIABLE(ticks); LOCK_FUNCTION(ticker); //install the interrupt handler which calls the ticker 60 times a second install_int_ex(ticker,BPS_TO_TIMER(FPS)); //lock both the varibale and the funciton to be used by the interrupt handler //these LOCK_VARIABLE(gametime); LOCK_FUNCTION(game_time_ticker); //install the interrupt handler which calls the game time ticker //game time ticker is in 10ths of seconds install_int_ex(game_time_ticker,BPS_TO_TIMER(10)); //create back buffer buffer = create_bitmap(SCREEN_W, SCREEN_H); //create the intro screen by loading the bitmap into the intro buffer intro = load_bitmap("flightless title.bmp",NULL); if(!intro){ allegro_message("Error loading intro image"); return 1; } //seed the random function srand(time(NULL)); //load fonts FONT *dicot_22_font; PALETTE palette; //load the the font for the header of the application dicot_22_font = load_font("dicot_22.pcx", palette, NULL); //load and display the intro screen while(inIntro) { //display the intro screen for the game blit(intro,screen,0,0,0,0,SCREEN_W,SCREEN_H); //wait for the player to press enter to start the game if(key[KEY_ENTER]){ inIntro=false; GAMEOVER=false; } //if the player presses esc then exit the game and the intro if(key[KEY_ESC]){ inIntro=false; GAMEOVER=true; } } //for as many badies make sprites to hold the bugs for(int i=0;i<BADIES;i++) { //initalize the bug sprite bug[i] = new bugs(); //load the bug sprite sheet if(!bug[i]->load("bug.bmp")){ allegro_message("Error loading bug sprite"); return 1; } //initalize the bug propertys bug[i]->init(); //add sprites to the sprite handler sprhandler->addbugs(bug[i]); } //initalize the player owl = new player(); //load the players sprite sheet if(!owl->load("owl sprite_new.bmp")){ allegro_message("Error loading owl sprite"); return 1; } //initalize the sprite properties owl->init(); //add the player object to the sprite handler sprhandler->addsprite(owl); //create the new snake object snakeboss = new snake(); //load the snake if(!snakeboss->load("snake_Tiles.bmp")){ allegro_message("Error loading snake sprite"); return 1; } //initalize the snake snakeboss->init(); //snakeboss->alive=false; //add the snake to the sprite handler sprhandler->addboss(snakeboss); //create for loop to load the players health indicator for(int i=1;i<4;i++) { //create new sprite objects to hold the images hearts[i-1] = new sprite(); //load the players health image if(!hearts[i-1]->load("FullHealth.bmp")){ allegro_message("Error loading player Health"); return 1; } //set sprite properties hearts[i-1]->x = SCREEN_W-35*i; hearts[i-1]->y = 10; hearts[i-1]->width = 30; hearts[i-1]->height = 30; hearts[i-1]->velx = 0; hearts[i-1]->vely = 0; hearts[i-1]->animcolumns = 0; hearts[i-1]->curframe = 0; hearts[i-1]->totalframes =1; hearts[i-1]->animdir = 0; //object type of non moving sprite hearts[i-1]->objecttype=2; hearts[i-1]->alive=0; //add the players health to the sprite handler sprhandler->addsprite(hearts[i-1]); } //create the music samples SAMPLE *ingamesong; //load the wav file into the samples //main game soundtrack ingamesong=load_sample("melo-24_Clip.wav"); if(ingamesong==NULL){ allegro_message("Error loading game soundtrack"); return 1; } //use mappy.h global function MapLoad to load the .FMP file MapLoad("flightless.FMP"); //play the sample music int playing = play_sample(ingamesong,150,125,1000,true); //start the clock to time the player startTime = time(NULL); //create the thread for player id = pthread_create(&pthread0, NULL, playerdraw_thread, (void*)&threadid5); //create the thread for the bugs id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid0); id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid1); id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid2); id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid3); id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid4); //create the thread to draw the snake id = pthread_create(&pthread1, NULL, snakedraw_thread, (void*)&threadid0); //main game loop while (!GAMEOVER) { while (ticks==0) { rest(1); } while(ticks>0) { if(key[KEY_ESC]) { playermessage="You quit :( Please come back again."; GAMEOVER=true; } //get the previous value of ticks and store them old_ticks=ticks; //each time we hit this loop we increment the mapxoffset +1 if(mapxoff<mapwidth*mapblockwidth) { //if the player is not hiding update the map if(owl->state!=2) { mapxoff++; } } //draw the background tiles via the mappy global funciton MapDrawBG MapDrawBG(buffer,mapxoff,0,0,0,WIDTH-1,HEIGHT-1); //draw the players health indicator based on the owls health/30 for (int i=0;i<((owl->health)/30);i++) { hearts[i]->draw(buffer); } //lock the varibales to protect them from the unsynced threads pthread_mutex_lock(&threadsafe); //get the player input owl->getinput(); sprhandler->updatebugs(); sprhandler->updatesnake(); //decrement the ticks ticks--; //unlock the mutex pthread_mutex_unlock(&threadsafe); //if the logic is taking too long abort and draw the screen if(old_ticks<=ticks) break; } //for every second that passess we need to call this function if(gametime - old_time >= 10) { //frames_per_sec holds the number of frames drawn in the last sec frames_per_sec = frames_done; //reset these variables for the next second frames_done =0; old_time=gametime; } //Decrement the players health if(gametime%120==0) { owl->takedamage(2); } if(sprhandler->getsnakes(0)->alive==false && gametime%400==0) { sprhandler->getsnakes(0)->resurrect(); } //check players health if(owl->health<=0) { playermessage="You have died...please remeber to eat next time."; GAMEOVER=true; } //stop the window from scrolling if(GAMEOVER==true ||mapxoff>=mapwidth*mapblockwidth-WIDTH) { if(mapxoff>=mapwidth*mapblockwidth-WIDTH) playermessage="Great job player you passed the game! Way to go."; //stop the map from moving mapxoff=mapwidth*mapblockwidth-WIDTH; //stop the music from playing stop_sample(ingamesong); //create the music samples SAMPLE *cheer=NULL; //load the wav file into the sample cheer=load_sample("app.wav"); if(cheer==NULL){ allegro_message("Error loading game soundtrack"); return 1; } //play the sample music play_sample(cheer,255,125,1000,true); //message the player...even if they are a quiter! textprintf_ex(screen,dicot_22_font,200,SCREEN_H/2,makecol(255,0,0),-1,playermessage); rest(2000); GAMEOVER=true; } //show frames fer second on the screen by pressing "cntrl f" if(key[KEY_F]) { if(key_shifts & KB_CTRL_FLAG) { //switch the showFPS flag to display the FPS SHOWFPS=!SHOWFPS; } //SHOWFPS=SHOWFPS; } if(SHOWFPS==true) textprintf_ex(buffer,font,20,20,WHITE,0,"frames= :%d",frames_per_sec); if(key[KEY_H]) { if(key_shifts & KB_CTRL_FLAG) { //switch the SHOWHEALTH flag to display the FPS SHOWHEALTH=!SHOWHEALTH; } //SHOWHEALTH=SHOWHEALTH; } //update the screen using a double buffering technique acquire_screen(); blit(buffer,screen,0,0,0,0,WIDTH,HEIGHT); release_screen(); //everytime we bilt from buffer to screen increase frames_done frames_done++; } //find the time that the game ended endTime = time(NULL); //kill the mutex (thread protection) pthread_mutex_destroy(&threadsafe); //call to create the final image to present to the user create_close(buffer,dicot_22_font,owl); //Garbage Collection clean up all of the objects that are being used in memory remove_keyboard(); remove_timer(); //destory the bitmaps that we are using destroy_bitmap(buffer); destroy_bitmap(intro); //destroy the map MapFreeMem(); //delete the sprites delete sprhandler; //call to allegro exit allegro_exit(); return 0; }//end of main
/** * Stop a sample from playing, which is required if you have set a * sample going in looped mode. If there are several copies of the * sample playing, it will stop them all. */ static VALUE sample_stop(VALUE self) { SAMPLE *sample; Data_Get_Struct(self, SAMPLE, sample); stop_sample(sample); return self; }
void shutdown_crusher() { stop_sample(datafile[SAMP_CRUSHER_MOTOR].dat); stop_sample(datafile[SAMP_ALARM].dat); }
void playSFXOnce(SAMPLE* sample) { stop_sample(sample); play_sample(sample, 255, 127, 1000, 0); }
static bool physics_in (struct anim *g) { struct coord nc; struct pos np, pbf, pmt, pmtf, pmtb, npmbo, npmbo_nf; struct frame nf; struct frame_offset fo; if (g->i == 0) { next_frame (&g->f, &g->f, &g->fo); int dirf = (g->f.dir == LEFT) ? -1 : +1; int dirb = (g->f.dir == LEFT) ? +1 : -1; survey (_mt, pos, &g->f, &nc, &pmt, &np); prel (&pmt, &pmtf, +0, dirf); prel (&pmt, &pmtb, +0, dirb); if (! is_strictly_traversable (&pmt) || ! is_strictly_traversable (&pmtf) || ! is_strictly_traversable (&pmtb)) place_in_initial_fall (g); } /* fall speed */ if (g->i > 0) g->fo.dx = -g->inertia; if (g->i > 4) { int speed = +21 + 3 * (g->i - 5); g->fo.dy = (speed > 33) ? 33 : speed; } /* land on ground */ struct frameset *frameset = get_guard_fall_frameset (g->type); fo.b = frameset[g->i > 2 ? 2 : g->i].frame; fo.dx = frameset[g->i > 2 ? 2 : g->i].dx; fo.dy = frameset[g->i > 2 ? 2 : g->i].dy; if (g->i > 0) g->fo.dx = -g->inertia; if (g->i > 2) { int speed = +21 + 3 * (g->i - 5); fo.dy = (speed > 33) ? 33 : speed; } fo.dy += 8; survey (_mbo, pos, &g->f, &nc, &np, &npmbo); next_frame (&g->f, &nf, &fo); survey (_mbo, pos, &nf, &nc, &np, &npmbo_nf); if (g->i > 2 && ! is_strictly_traversable (&npmbo) && npmbo.floor != npmbo_nf.floor) { g->inertia = g->cinertia = 0; if (is_colliding (&g->f, &g->fo, +16, false, &g->ci)) { if (g->ci.t != WALL) g->f.c.x += (g->f.dir == LEFT) ? +16 : -16; else g->f.c.x += (g->f.dir == LEFT) ? +8 : -8; } survey (_bf, pos, &g->f, &nc, &pbf, &np); /* pos2view (&pbf, &pbf); */ frameset = get_guard_vigilant_frameset (g->type); g->f.b = frameset[0].frame; place_on_the_ground (&g->f, &g->f.c); shake_loose_floor_row (&pbf); if (g->i >= 8 && ! g->immortal && ! g->fall_immune) { g->hurt = true; g->splash = true; g->current_lives--; if (g->i >= 10) g->current_lives = 0; if (g->current_lives > 0) g->uncouch_slowly = true; } else if (g->i > 3) { play_sample (hit_ground_sample, g->f.c.room); g->hurt = false; } else g->hurt = false; stop_sample (g->sample, scream_sample); survey (_mt, pos, &g->f, &nc, &pmt, &np); g->p = pmt; if (con (&pmt)->fg == SPIKES_FLOOR && ! spikes_floor_at_pos (&pmt)->inactive) guard_die_spiked (g); else if (g->current_lives <= 0) { play_sample (hit_ground_fatal_sample, g->f.c.room); guard_die_suddenly (g); g->death_reason = FALL_DEATH; } else { place_on_the_ground (&g->f, &g->f.c); g->f.c.y++; guard_vigilant (g); } return false; } return true; }
void goToNewGameMenu() { int i = 0; int finishedSelecting = 0; BITMAP *check = makeBitmap("Menu_Images/Checked Box.bmp"); BITMAP *empty = makeBitmap("Menu_Images/Check Box.bmp"); MENUBUTTON aToggle[3]; initializeButton(&aToggle[0], 65, 38, 314, 46, "Menu_Images/Check Box.bmp"); initializeButton(&aToggle[1], 65, 111, 314, 46, "Menu_Images/Check Box.bmp"); initializeButton(&aToggle[2], 65, 186, 314, 46, "Menu_Images/Check Box.bmp"); MENUBUTTON backArrow; initializeButton(&backArrow, 10, 715, 50, 50, "Menu_Images/Back Arrow.bmp"); int toggleClicked = -1; BITMAP *newBackground = makeBitmap("Menu_Images/New Game Initial.bmp"); BITMAP *mouse = makeBitmap("Menu_Images/Mouse.bmp"); newAmbient = makeSample("Menu_Sounds/Battle Drums.wav"); SAMPLE *toggleNoise = makeSample("Menu_Sounds/ToggleNoise.wav"); play_sample(newAmbient, 100, 0, 1000, 1); while (1) { if (mouse_b) { for (i = 0; i <= 2; i++) { if (menu_mouseIsOver(&aToggle[i])) { toggleClicked = i; aToggle[i].picture = check; stop_sample(toggleNoise); play_sample(toggleNoise, 255, 0, 1000, 0); finishedSelecting = 1; //newBackground = load_bitmap("New Game Background 01.bmp", NULL); } } if (menu_mouseIsOver(&backArrow)) { stop_sample(newAmbient); return; } } for (i = 0; i <= 2; i++) { if (toggleClicked != i) { aToggle[i].picture = empty; } } draw_sprite(menuBuffer, newBackground, 0, 0); if (finishedSelecting) { if (toggleClicked == 0) { textprintf_centre_ex(menuBuffer, font, 500, 300, makecol(255, 255, 255), -1, "Not availible in the demo version!"); //printCampaignOptions(); } if (toggleClicked == 1) { printScenarioOptions(); } if (toggleClicked == 2) { textprintf_centre_ex(menuBuffer, font, 500, 300, makecol(255, 255, 255), -1, "Not availible in the demo version!"); //printBattleOptions(); } } if (menu_mouseIsOver(&backArrow)) { backArrow.picture = makeBitmap("Menu_Images/Back ArrowH.bmp"); } else { backArrow.picture = makeBitmap("Menu_Images/Back Arrow.bmp"); } draw_sprite(menuBuffer, backArrow.picture, backArrow.left, backArrow.top); for (i = 0; i <= 2; i++) { draw_sprite(menuBuffer, aToggle[i].picture, aToggle[i].left, aToggle[i].top); } draw_sprite(menuBuffer, mouse, mouse_x, mouse_y); blit(menuBuffer, screen, 0,0,0,0,1024,768); clear_bitmap(menuBuffer); } stop_sample(newAmbient); }
void printCampaignOptions() { int i = 0; static int firstTime = 1; static int timeClicked = 0; static int sliderClicked = 1; BITMAP *check = makeBitmap("Menu_Images/Checked Box.bmp"); BITMAP *empty = makeBitmap("Menu_Images/Check Box.bmp"); static MENUBUTTON aSlider[3]; static MENUBUTTON forwardArrow; static MENUBUTTON tutorial; BITMAP *newBackground = makeBitmap("Menu_Images/Campaign Menu 01.bmp"); BITMAP *slider = makeBitmap("Menu_Images/Slider.bmp"); static BITMAP *difficulties[3]; SAMPLE *slideNoise = makeSample("Menu_Sounds/SliderNoise.wav"); if (firstTime) { initializeButton(&aSlider[0], 490, 180, 150, 50, "Menu_Images/Slider.bmp"); initializeButton(&aSlider[1], 625, 180, 150, 50, "Menu_Images/Slider.bmp"); initializeButton(&aSlider[2], 810, 180, 150, 50, "Menu_Images/Slider.bmp"); initializeButton(&forwardArrow, 920, 677, 57, 50, "Menu_Images/Forward Arrow.bmp"); initializeButton(&tutorial, 530, 340, 290, 46, "Menu_Images/Checked Box.bmp"); difficulties[0] = makeBitmap("Menu_Images/Senator.bmp"); difficulties[1] = makeBitmap("Menu_Images/Consul.bmp"); difficulties[2] = makeBitmap("Menu_Images/Emperor.bmp"); } draw_sprite(menuBuffer, newBackground, 0, 0); if (menu_mouseIsOver(&forwardArrow)) { forwardArrow.picture = makeBitmap("Menu_Images/Forward ArrowH.bmp"); } else if (!menu_mouseIsOver(&forwardArrow)) { forwardArrow.picture = makeBitmap("Menu_Images/Forward Arrow.bmp"); } switch(sliderClicked) { case 0: draw_sprite(menuBuffer, slider, 498, 197); draw_sprite(menuBuffer, difficulties[0], 617, 255); break; case 1: draw_sprite(menuBuffer, slider, 700, 197); draw_sprite(menuBuffer, difficulties[1], 617, 255); break; case 2: draw_sprite(menuBuffer, slider, 913, 197); draw_sprite(menuBuffer, difficulties[2], 617, 255); break; } if (mouse_b) { for (i = 0; i <= 2; i++) { if (menu_mouseIsOver(&aSlider[i])) { sliderClicked = i; stop_sample(slideNoise); play_sample(slideNoise, 155, 0, 1000, 0); break; } } if (menu_mouseIsOver(&forwardArrow)) { return; } if (menu_mouseIsOver(&tutorial) && timeClicked < time(0)) { timeClicked = time(0); if (tutorial.picture == empty) { tutorial.picture = check; } else { tutorial.picture = empty; } } } draw_sprite(menuBuffer, tutorial.picture, tutorial.left, tutorial.top); draw_sprite(menuBuffer, forwardArrow.picture, forwardArrow.left, forwardArrow.top); firstTime = 0; }
int savecity() { buffer = create_bitmap(640,480); samSong = load_sample("C:\\Sanchit\\Game Pack\\Sprites\\savecity.wav"); samExplosion1 = load_sample("C:\\Sanchit\\Game Pack\\Sprites\\explosion1.wav"); textout(buffer,font,"Save City (ESC to quit)",0,1,WHITE); updatescore(); // rect(buffer, 0, 12, SCREEN_W-2, SCREEN_H-2, RED); city = load_bitmap("C:\\Sanchit\\Game Pack\\Sprites\\city.bmp", NULL); for (n = 0; n < 5; n++) masked_blit(city, buffer, 0, 0, 20+n*120, SCREEN_H-city->h-2, city->w, city->h); crosshair = load_bitmap("C:\\Sanchit\\Game Pack\\Sprites\\crosshair.bmp", NULL); set_mouse_sprite(crosshair); set_mouse_sprite_focus(15,15); show_mouse(buffer); play_sample(samSong, 128, 128, 1000, 1); while (!key[KEY_ESC]) { //above the red was border get destroyed rect(buffer, 0, 12, SCREEN_W-2, SCREEN_H-2, RED); mx = mouse_x; my = mouse_y; mb = (mouse_b & 1); if (destroyed) firenewmissile(); if (mb) { explosion1(screen,mx,my,GREEN); play_sample(samExplosion1, 40, 128, 1000, 0); } movemissile(); blit(buffer,screen,0,0,0,0,640,480); if(key[KEY_BACKSPACE]) { score=-1; firenewmissile(); stop_sample(samSong); openscreen(); } if(key[KEY_ESC]) { exit(1); } if(score>=0 && score <5) rest(10); else if(score>=5 && score<10) rest(9); else if(score>=10 && score<15) rest(8); else if(score>=15 && score<20) rest(7); else if(score>=20 && score<25) rest(6); else if(score>=25 && score<30) rest(5); else if(score>=30 && score<35) rest(4); else if(score>=35 && score<40) rest(3); else if(score>=40 && score<45) rest(2); else if(score>=45) rest(1); } set_mouse_sprite(NULL); destroy_bitmap(city); destroy_bitmap(crosshair); // openscreen(); return 0; }
void printBattleOptions() { static slider_t aBattleSlider[3]; static int firstTime = 1; static int characterClicked = 0; static BITMAP *godNames[3]; if (firstTime) { initializeSlider(&aBattleSlider[0], 493, 190, 442, 50, 4, 1, 700); initializeSlider(&aBattleSlider[1], 493, 315, 442, 50, 4, 1, 700); initializeSlider(&aBattleSlider[2], 493, 600, 442, 50, 4, 1, 700); firstTime = 0; godNames[0] = makeBitmap("Menu_Images/Jupiter Name.bmp"); godNames[1] = makeBitmap("Menu_Images/Mars Name.bmp"); godNames[2] = makeBitmap("Menu_Images/Neptune Name.bmp"); } BITMAP *newBackground = makeBitmap("Menu_Images/Single Battle Menu 01.bmp"); int i = 0; int j = 0; static MENUBUTTON forwardArrow; initializeButton(&forwardArrow, 920, 677, 57, 50, "Menu_Images/Forward Arrow.bmp"); static MENUBUTTON aGod[3]; initializeButton(&aGod[0], 475, 434, 129, 66, "Menu_Images/Zeus.bmp"); initializeButton(&aGod[1], 649, 434, 129, 66, "Menu_Images/Mars.bmp"); initializeButton(&aGod[2], 825, 434, 129, 66, "Menu_Images/Neptune.bmp"); static SAMPLE *aGodSound[3]; aGodSound[0] = makeSample("Menu_Sounds/Jupiter.wav"); aGodSound[1] = makeSample("Menu_Sounds/Mars.wav"); aGodSound[2] = makeSample("Menu_Sounds/Neptune.wav"); draw_sprite(menuBuffer, newBackground, 0, 0); for(i = 0; i <= 2; i++) { makeSlider(&aBattleSlider[i]); } if (menu_mouseIsOver(&forwardArrow)) { forwardArrow.picture = makeBitmap("Menu_Images/Forward ArrowH.bmp"); } else { forwardArrow.picture = makeBitmap("Menu_Images/Forward Arrow.bmp"); } if (mouse_b) { for (i=0; i<=2; i++) { if (menu_mouseIsOver(&aGod[i])) { characterClicked = i; for (j=0; j<=2; j++) { stop_sample(aGodSound[i]); } play_sample(aGodSound[i], 155, 0, 1000, 0); } } if (menu_mouseIsOver(&forwardArrow)) { return; } } aGod[0].picture = makeBitmap("Menu_Images/Zeus.bmp"); aGod[1].picture = makeBitmap("Menu_Images/Mars.bmp"); aGod[2].picture = makeBitmap("Menu_Images/Neptune.bmp"); switch(characterClicked) { case 0: aGod[0].picture = makeBitmap("Menu_Images/ZeusH.bmp"); break; case 1: aGod[1].picture = makeBitmap("Menu_Images/MarsH.bmp"); break; case 2: aGod[2].picture = makeBitmap("Menu_Images/NeptuneH.bmp"); break; } for (i=0; i<=2; i++) { draw_sprite(menuBuffer, aGod[i].picture, aGod[i].left, aGod[i].top); } draw_sprite(menuBuffer, godNames[characterClicked], 616, 515); draw_sprite(menuBuffer, forwardArrow.picture, forwardArrow.left, forwardArrow.top); }
int main(int argc, char *argv[]) { allegInitializations(); loadEssentials(); int i = 0; MENUBUTTON aButton[5]; initializeButton(&aButton[0], 359, 356, 305, 55, "Menu_Images/Check Box.bmp"); initializeButton(&aButton[1], 359, 432, 305, 55, "Menu_Images/Check Box.bmp"); initializeButton(&aButton[2], 359, 507, 305, 55, "Menu_Images/Check Box.bmp"); initializeButton(&aButton[3], 359, 583, 305, 55, "Menu_Images/Check Box.bmp"); initializeButton(&aButton[4], 359, 659, 305, 55, "Menu_Images/Check Box.bmp"); int buttonClicked = 0; menuBuffer = create_bitmap(1024,768); BITMAP *menuBackground[7]; menuBackground[0] = makeBitmap("Menu_Images/Menu Background 04.bmp"); menuBackground[1] = makeBitmap("Menu_Images/Menu Background 05.bmp"); menuBackground[2] = makeBitmap("Menu_Images/Menu Background 06.bmp"); menuBackground[3] = makeBitmap("Menu_Images/Menu Background 07.bmp"); menuBackground[4] = makeBitmap("Menu_Images/Menu Background 08.bmp"); menuBackground[5] = makeBitmap("Menu_Images/Menu Background 09.bmp"); menuBackground[6] = makeBitmap("Menu_Images/Menu Background 10.bmp"); BITMAP *highlighter = makeBitmap("Menu_Images/Menu Selector.bmp"); // Load our picture BITMAP *mouse = makeBitmap("Menu_Images/Mouse.bmp"); // Load our picture BITMAP *mouseH = makeBitmap("Menu_Images/MouseH.bmp"); // Load our picture SAMPLE *menuClick[5]; menuClick[0] = makeSample("Menu_Sounds/Menu Select 1.wav"); menuClick[1] = makeSample("Menu_Sounds/Menu Select 2.wav"); menuClick[2] = makeSample("Menu_Sounds/Menu Select 3.wav"); menuClick[3] = makeSample("Menu_Sounds/Menu Select 4.wav"); menuClick[4] = makeSample("Menu_Sounds/Menu Select 5.wav"); double startTime = 0; SAMPLE *menuButtonClick[5]; menuButtonClick[0] = makeSample("Menu_Sounds/New Game.wav"); menuButtonClick[1] = makeSample("Menu_Sounds/Load Game.wav"); menuButtonClick[2] = makeSample("Menu_Sounds/Options.wav"); menuButtonClick[3] = makeSample("Menu_Sounds/Credits.wav"); menuButtonClick[4] = makeSample("Menu_Sounds/Quit Game.wav"); SAMPLE *menuAmbient = makeSample("Menu_Sounds/Menu Ambient.wav"); int randomizer = 0; srand(time(0)); showIntro(); draw_sprite(menuBuffer, menuBackground[0], 0, 0); draw_sprite(menuBuffer, highlighter, 6, 186); blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen play_sample(menuAmbient, 255, 0, 1000, 1); while (true) { if (fireCounter != fireCheck) { randomizer = rand() % 7; fireCheck = fireCounter; } draw_sprite(menuBuffer, menuBackground[randomizer], 0, 0); draw_sprite(menuBuffer, mouse, mouse_x, mouse_y); if (mouse_b) { draw_sprite(menuBuffer, mouseH, mouse_x, mouse_y); for (i = 0; i <= 4; i++) { if (menu_mouseIsOver(&aButton[i])) { buttonClicked = i; } } switch (buttonClicked) { case 0: play_sample(menuButtonClick[0], 200, 0, 1000, 0); stop_sample(menuClick[randomizer]); stop_sample(menuAmbient); goToNewGameMenu(); play_sample(menuAmbient, 255, 0, 1000, 1); buttonClicked = -1; break; case 1: play_sample(menuButtonClick[1], 200, 0, 1000, 0); //loadGame(); break; case 2: play_sample(menuButtonClick[2], 200, 0, 1000, 0); break; case 3: play_sample(menuButtonClick[3], 50, 0, 1000, 0); break; case 4: stop_sample(menuAmbient); play_sample(menuButtonClick[4], 255, 0, 1000, 0); startTime = time(0); while (startTime + 4 > time(0)) { } return 0; break; default: stop_sample(menuClick[randomizer]); randomizer = rand() % 5; play_sample(menuClick[randomizer], 255, 0, 500, 0); break; } } else { buttonClicked = -1; } blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen clear_bitmap(menuBuffer); // Clear the contents of the buffer bitmap } }END_OF_MAIN()