BOOL display::SetDisplayMode(WORD _mode, WORD _width, WORD _height, BYTE _bpp) { int error = 0; set_color_depth(_bpp); if((error = set_gfx_mode(_mode, _width, _height, 0, 0)) != 0) { LogError("Error setting graphics resolution."); LogError("Allegro returned this error message: %s", allegro_error); return false; } this->back = Surface(new surface(_width, _height, _bpp)); this->_screen = Surface(new surface(::screen)); acquire_screen(); show_mouse(::screen); acquire_screen(); this->mode = _mode; this->width = _width; this->height = _height; this->bpp = _bpp; LogMessage("Screen resolution succesfully changed."); return true; }
void initialise_screen() { if (have_allegro_window) { set_gfx_mode(GFX_SAFE, 320, 200, 0, 0); set_palette(desktop_palette); acquire_screen(); textout_centre(screen, font, "Type Here!!", SCREEN_W/2, SCREEN_H/2-60, 255); textout(screen, font, "Ctrl-M: switch between comm ports", 0, SCREEN_H/2-32, 255); textout(screen, font, "Ctrl-B: send a half second break signal", 0, SCREEN_H/2-16, 255); textout(screen, font, "Ctrl-C: quit", 0, SCREEN_H/2, 255); textout(screen, font, "Other key presses sent to current port.", 0, SCREEN_H/2+16, 255); textout(screen, font, "Current port:", 0, SCREEN_H/2+40, 255); textout(screen, font, cur_port->szName, SCREEN_W/2, SCREEN_H/2+40, 255); release_screen(); } else { printf("Ctrl-M: switch between comm ports\n"); printf("Ctrl-B: send a half second break signal\n"); printf("Ctrl-C: quit\n"); printf("Other key presses sent to current port.\n"); printf("\nCurrent port: %s\n\n", cur_port->szName); } }
//Perform frame by frame updates and blits. Set the stream //state to STOP if there are no more frames to update. void RenderToSurface(BITMAP *vscreen) { //update each frame if (g_pSample->Update(0, NULL, NULL, 0) != S_OK) { g_bAppactive = FALSE; g_pMMStream->SetState(STREAMSTATE_STOP); } else { g_bAppactive = TRUE; acquire_screen(); // Because vscreen is a DX Video Bitmap, it can be stretched // onto the screen (also a Video Bmp) but not onto a memory // bitmap (which is what "screen" is when using gfx filters) if (is_video_bitmap(screen)) { stretch_blit(vscreen, screen, 0, 0, vscreen->w, vscreen->h, screen->w / 2 - newWidth / 2, screen->h / 2 - newHeight / 2, newWidth, newHeight); } else { blit(vscreen, vsMemory, 0, 0, 0, 0, vscreen->w, vscreen->h); stretch_blit(vsMemory, screen, 0, 0, vscreen->w, vscreen->h, screen->w / 2 - newWidth / 2, screen->h / 2 - newHeight / 2, newWidth, newHeight); } release_screen(); render_to_screen(screen, 0, 0); // if we're not playing AVI sound, poll the game MP3 if (!useSound) update_polled_stuff_and_crossfade(); } }
void Game :: entry () { std::list <Team *> :: iterator team_i; char key = 0; while (key != 27) { this->draw_screen_buffer(); acquire_screen(); blit(this->screen_buffer->get_bitmap(), screen, 0, 0, 0, 0, this->screen_buffer->get_width(), this->screen_buffer->get_height()); release_screen(); // team turns (run lua scripts) for (team_i = this->teams.begin(); team_i != this->teams.end(); team_i++) (*team_i)->turn(); // move teams for (team_i = this->teams.begin(); team_i != this->teams.end(); team_i++) (*team_i)->process_action(TANK_ACTION_MOVE); // check for flag captures this->check_for_flag_captures(); rest((unsigned int) 200); if (keypressed()) key = (char) readkey(); } }
void draw_palette() { int count = 0; //loop counts int count2 = 0; //[note: as relevant names as could be bothered to make] int count3 = 0; int count4 = 0; int columns = 15; //columns,rows, needed to output all colors in default palette int rows = 15; int startx = 10; //x,y position of color output on screen int starty = 10; int tempy = 10; int color = 0; //starting color to output int pixels = 20; //pixels^2 = size of each square acquire_screen(); for(count4 = 0; count4 <= rows; count4++){ //deals with each row of palette output for(count = 0; count <= columns; count++) { //deals with each column of pallete output starty = tempy; for(count3 = 0; count3 <= pixels; count3++) { //outputs pixels for each sqr row for (count2 = 0; count2 <= pixels; count2++) { //for pixels per sample (square) if (color < 256) { putpixel(screen, startx+count2, starty, color); } } starty++; } starty = tempy; //resets starty to correct row value color++; //increments current palette color startx+=pixels; //increments column, plus relevant no. pixels } startx = 10; //resets column start to ten pixels from left tempy+=pixels; //increments row, plus relevant no. pixels } /*Prints the relevant palette name below main output on screen.*/ if (p==0) { textout_ex(screen, font, "desktop palette", 10, 340, 8, -1); textout_ex(screen, font, "default palette", 10, 340, 13, -1); } else { if (p==1) { textout_ex(screen, font, "default palette", 10, 340, 8, -1); textout_ex(screen, font, "desktop palette", 10, 340, 3, -1); } } release_screen(); }
/* upadate_screen: blit virtualscreen to screen */ void update_screen(void) { assert(vscreen); /* output */ acquire_screen(); blit(vscreen, screen, 0, 0, 0, 0, EDITOR_WIN_W, EDITOR_WIN_H); release_screen(); }
void ss_saver() { PALETTE pal; get_palette(pal); acquire_screen(); save_pcx("ss.pcx", screen, pal); release_screen(); }
// redraw destination pictures void switch_in_callback(void) { acquire_screen(); clear_bitmap(screen); release_screen(); rasta.ShowDestinationBitmap(); rasta.ShowInputBitmap(); }
void moveBall(){ ball_tempX = ball_x; ball_tempY = ball_y; if (dir == 1 && ball_x > 5 && ball_y > 5){ if( ball_x == p1_x + 15 && ball_y >= p1_y && ball_y <= p1_y + 60){ dir = rand()% 2 + 3; }else{ --ball_x; --ball_y; } } else if (dir == 2 && ball_x > 5 && ball_y < 475){ if( ball_x == p1_x + 15 && ball_y >= p1_y && ball_y <= p1_y + 60){ dir = rand()% 2 + 3; }else{ --ball_x; ++ball_y; } } else if (dir == 3 && ball_x < 635 && ball_y > 5){ if( ball_x + 5 == p2_x && ball_y >= p2_y && ball_y <= p2_y + 60){ dir = rand()% 2 + 1; }else{ ++ball_x; --ball_y; } } else if (dir == 4 && ball_x < 635 && ball_y < 475){ if( ball_x + 5 == p2_x && ball_y >= p2_y && ball_y <= p2_y + 60){ dir = rand()% 2 + 1; }else{ ++ball_x; ++ball_y; } } else { if (dir == 1 || dir == 3) ++dir; else if (dir == 2 || dir == 4) --dir; } acquire_screen(); circlefill ( buffer, ball_tempX, ball_tempY, 5, makecol( 0, 0, 0)); circlefill ( buffer, ball_x, ball_y, 5, makecol( 128, 255, 0)); draw_sprite( screen, buffer, 0, 0); release_screen(); rest(5); }
static int loop_callback(void *data) { (void)data; if (gfx_half_width) { acquire_screen(); textout_centre(screen, font, "Music has looped.", gfx_half_width, 36, 10); release_screen(); } return 0; }
static int xm_speed_zero_callback(void *data) { (void)data; if (gfx_half_width) { text_mode(0); /* In case this is overwriting "Music has looped." */ acquire_screen(); textout_centre(screen, font, "Music has stopped.", gfx_half_width, 36, 10); release_screen(); } return 0; }
void setupBoard() { //function to draw in the grid acquire_screen(); line( screen, 200, 0, 200, 480, makecol( 255, 255, 255)); line( screen, 400, 0, 400, 480, makecol( 255, 255, 255)); line( screen, 0, 150, 680, 150, makecol( 255, 255, 255)); line( screen, 0, 300, 680, 300, makecol( 255, 255, 255)); }
void setupGame() { acquire_screen(); rectfill( buffer, p1_x, p1_y, p1_x + 10, p1_y + 60, makecol ( 0, 0, 255)); rectfill( buffer, p2_x, p2_y, p2_x + 10, p2_y + 60, makecol ( 0, 0, 255)); circlefill ( buffer, ball_x, ball_y, 5, makecol( 128, 255, 0)); draw_sprite( screen, buffer, 0, 0); release_screen(); time(&secs); srand( (unsigned int)secs); dir = rand() % 4 + 1; }
void refreshscreen() { int y = 0; if (!refresh_needed) return; if (!is_windowed_mode()) y = 40; acquire_screen(); blit(virt_screen, screen, 0, 0, 0, y, 8*term_width, 400); release_screen(); refresh_needed = 0; memset(blit_rect, 0, 4); }
void inform_port_change() { if (have_allegro_window) { acquire_screen(); textout(screen, font, " ", SCREEN_W/2, SCREEN_H/2+40, 255); textout(screen, font, cur_port->szName, SCREEN_W/2, SCREEN_H/2+40, 255); printf("\n\n"); release_screen(); } else { printf("\n\nChanging to port: %s\n\n", cur_port->szName); } }
//--------------------------------------------------------------------------- // Name: draw_csl_dbuff() // Desc: Show the console buffer. //--------------------------------------------------------------------------- void draw_csl_dbuff(BITMAP *csl_dbuff, int csl_y) { acquire_screen(); if((csl_get_y() != csl_y) && (in_the_game)) { draw_level(); blit(csl_dbuff, virt, 0, csl_dbuff->h-csl_y, 0, 0, csl_dbuff->w, csl_y); blit(virt, screen, 0,0,80,0,480,480); } else { blit(csl_dbuff, screen, 0, csl_dbuff->h-csl_y, 80, 0, csl_dbuff->w, csl_y); } release_screen(); }
void p2Move() { p2_tempY = p2_y; if( key[KEY_UP] && p2_y > 0) { --p2_y; } else if( key[KEY_DOWN] && p2_y < 420) { ++p2_y; } acquire_screen(); //rectfill( buffer, p2_tempX, p2_tempY, p2_tempX + 10, p2_tempY + 60, makecol ( 0, 0, 0)); rectfill( buffer, p2_x, p2_y, p2_x + 5, p2_y + 60, makecol ( 0, 0, 0)); rectfill( buffer, p2_x+6, p2_y , p2_x + 10, p2_y + 60, makecol ( 255, 0, 0)); release_screen(); }
void p1Move() { p1_tempY = p1_y; if( key[KEY_W] && p1_y > 0) { --p1_y; } else if( key[KEY_S] && p1_y < 420) { ++p1_y; } acquire_screen(); // rectfill( buffer, p1_tempX, p1_tempY, p1_tempX + 10, p1_tempY + 60, makecol ( 0, 0, 0)); rectfill( buffer, p1_x, p1_y, p1_x + 5, p1_y + 60, makecol ( 255, 0, 0)); rectfill( buffer, p1_x +5 , p1_y , p1_x + 10, p1_y + 60, makecol ( 0, 0, 0)); release_screen(); }
int main(void) { BITMAP *memory_bitmap; int x, y; if (allegro_init() != 0) return 1; install_keyboard(); 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; } } set_palette(desktop_palette); /* make a memory bitmap sized 20x20 */ memory_bitmap = create_bitmap(20, 20); /* draw some circles onto it */ clear_bitmap(memory_bitmap); for (x=0; x<16; x++) circle(memory_bitmap, 10, 10, x, palette_color[x]); /* blit lots of copies of it onto the screen */ acquire_screen(); for (y=0; y<SCREEN_H; y+=20) for (x=0; x<SCREEN_W; x+=20) blit(memory_bitmap, screen, 0, 0, x, y, 20, 20); release_screen(); /* free the memory bitmap */ destroy_bitmap(memory_bitmap); readkey(); return 0; }
/* Section to register users and their parameters of control */ int Register() { acquire_screen(); GainBox= load_bitmap("images/Register/Gain.pcx", pal); ModeBox= load_bitmap("images/Register/Mode.pcx", pal); TiBox= load_bitmap("images/Register/Ti.pcx", pal); TdBox= load_bitmap("images/Register/Td.pcx", pal); Screen1 = load_bitmap("images/Register/Base.pcx", pal); Screen2 = load_bitmap("images/Principal/Base.pcx", pal); blit(Screen1, screen, 0, 0, 0, 0, 1024, 768); font = load_font("config/unifont.dat", NULL, NULL); Letteri=Letterk=NULL; textprintf_ex(screen, font, 150, 250, 0, -1, "Tipo de Control:"); textprintf_ex(screen, font, 210, 280, DARK_GRAY, -1, "*Manual *Automatico "); CaptureName(); }
int Validate() { acquire_screen(); B1 = load_bitmap("images/Validate/Base01.pcx", pal); B2 = load_bitmap("images/Validate/Base02.pcx", pal); system("mp3blaster sounds/GuacaGuaca.wav&"); while (!key[KEY_ENTER]) { blit(B1, screen, 0, 0, 0, 0, 1024, 768); usleep(400000); blit(B2, screen, 0, 0, 0, 0, 1024, 768); usleep(400000); system("mp3blaster sounds/GuacaGuaca.wav&"); } Register(); release_screen(); return 0; }
void bill_fade_bmp(BITMAP *bmp, int clr) { /* This makes a checkerboard pattern of pixels of a specified color, it can be used to achieve a Windows "shudown" like effect */ int yoff; int ysub; int xoff; int xadd; scare_mouse(); acquire_screen(); for(yoff=0; yoff<=SCREEN_H; yoff +=2) { for(ysub=0; ((yoff-ysub)>=0);ysub++) putpixel(bmp, ysub, yoff-ysub, clr); } for(xoff=0; xoff<=SCREEN_W; xoff +=2) { for(xadd=0; ((xoff+xadd)<=SCREEN_W); xadd++) putpixel(bmp, xoff+xadd, SCREEN_H-xadd, clr); } release_screen(); unscare_mouse(); }
/* draws the spline paths */ void draw_splines(void) { int i; acquire_screen(); clear_to_color(screen, makecol(255, 255, 255)); textout_centre_ex(screen, font, "Spline curve path", SCREEN_W/2, 8, palette_color[255], palette_color[0]); textprintf_centre_ex(screen, font, SCREEN_W/2, 32, palette_color[255], palette_color[0], "Curviness = %.2f", fixtof(curviness)); textout_centre_ex(screen, font, "Up/down keys to alter", SCREEN_W/2, 44, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "Space to walk", SCREEN_W/2, 68, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "C to display control points", SCREEN_W/2, 92, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "T to display tangents", SCREEN_W/2, 104, palette_color[255], palette_color[0]); for (i=1; i<node_count-2; i++) draw_spline(nodes[i], nodes[i+1]); for (i=1; i<node_count-1; i++) { draw_node(i); if (show_tangents) { line(screen, nodes[i].x - fixtoi(fixcos(nodes[i].tangent) * 24), nodes[i].y - fixtoi(fixsin(nodes[i].tangent) * 24), nodes[i].x + fixtoi(fixcos(nodes[i].tangent) * 24), nodes[i].y + fixtoi(fixsin(nodes[i].tangent) * 24), palette_color[1]); } } release_screen(); }
void draw() { for(unsigned int i=0;i<8;++i) { GSVECTOR temp=GSVector3TransformCoord(vertices[i], view); //std::cout<<"camera 3d="<<temp<<std::endl; GSVECTOR temp1=GSVector3TransformCoord(temp,p)/temp.getW(); _2Dpoints[i]=temp1/temp1.getW(); //std::cout<<temp.getW()<<std::endl; //std::cout<<_2Dpoints[i]<<std::endl; } /* for(unsigned int i=0;i<8;++i) { std::cout<<"X="<<static_cast<unsigned int>((_2Dpoints[i].getX()+2/2)*1920/2)<<" Y="<<static_cast<unsigned int>((2/2-_2Dpoints[i].getY())*1200/2)<<std::endl; }*/ acquire_screen(); clear_to_color( buffer, makecol( 255, 255, 255)); for(unsigned int i=0;i<12;++i) { line( buffer, static_cast<unsigned int>((_2Dpoints[line_indices[i][0]].getX()+2/2)*1920/2), static_cast<unsigned int>((2/2-_2Dpoints[line_indices[i][0]].getY())*1200/2), static_cast<unsigned int>((_2Dpoints[line_indices[i][1]].getX()+2/2)*1920/2), static_cast<unsigned int>((2/2-_2Dpoints[line_indices[i][1]].getY())*1200/2), makecol(0,0,0) ); } draw_sprite( screen, buffer, 0, 0); release_screen(); }
void moveCircle(){ tempX = x; tempY = y; dir = rand() % 4 + 1; if (dir == 1 && x != 20 && y != 20){ --x; --y; } else if (dir == 2 && x != 20 && y != 460){ --x; ++y; } else if (dir == 3 && x != 620 && y != 20){ ++x; --y; } else if (dir == 4 && x != 620 && y != 460){ ++x; ++y; } acquire_screen(); circlefill ( screen, tempX, tempY, 20, makecol( 0, 0, 0)); circlefill ( screen, x, y, 20, makecol( 255, 0, 0)); release_screen(); rest(10); }
void Draw(int cycles, int currtour, int besttour) { ///////////////////////////////////////////////////////////////////////////////////////////// // draw a graph (drawing towns and paths is too hard with the current system of random distances) // is graph of tour length at each step as well as the current best tour length // // One important thing with draw() is that it takes the current and best tour lengths and divides them // by the number of towns.. this is so that no matter how many towns there are, it wont draw off the screen // unless the MAX_DISTANCE is set over 500 // ///////////////////////////////////////////////////////////////////////////////////////////// acquire_screen(); //graph axis vline(screen, 40, 40, SCREEN_H-40, makecol(255,255,255)); hline(screen, 40, 440, SCREEN_W-40, makecol(255,255,255)); //graph axis text textout_centre(screen,font,"CYCLES",SCREEN_W/2, SCREEN_H-20,makecol(0,200,200)); textout(screen,font,"DISTANCE",1, SCREEN_H/2,makecol(0,200,200)); //graph legend rectfill(screen, SCREEN_W-200, 20, SCREEN_W-170, 40, makecol(0,200,200)); textprintf(screen,font,SCREEN_W-160, 30,makecol(255,255,255),"Current Tour"); rectfill(screen, SCREEN_W-200, 50, SCREEN_W-170, 70, makecol(255,0,0)); textprintf(screen,font,SCREEN_W-160, 60,makecol(255,255,255),"Best Tour"); //draw current cycles distance vline(screen,cycles+41,SCREEN_H-40,(SCREEN_H-40)-(currtour/NUM_TOWNS),makecol(0,200,200)); vline(screen,cycles+41,SCREEN_H-40,(SCREEN_H-40)-(besttour/NUM_TOWNS),makecol(255,0,0)); release_screen(); }
int main (void) { /* initialize the game. */ setup_allegro (MODE, WIDTH, HEIGHT, 16); setup_bmps(); setup_player(); scrollx = 0; scrolly = 0; currentmap = (MAP*)malloc (sizeof (MAP)); currentmap->initflag = 1; currentmap->idnumber = TCA_13; map_handler(); while (!key[KEY_ESC]) { get_input(); move_player(); scroll_window(); animate_player(); map_event_handler(); map_handler(); draw_player(); blit (scrollbmp, bufferbmp, scrollx, scrolly, 0, 0, WIDTH-1, HEIGHT-1); print_scroll_debug_messages(); print_player_debug_messages(); acquire_screen(); blit (bufferbmp, screen, 0, 0, 0, 0, WIDTH-1, HEIGHT-1); release_screen(); rest (20); } destroy_bmps(); allegro_exit(); return 0; }
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
int main(int argc, const char *const *argv) /* I'm const-crazy! */ { DUH *duh; /* Encapsulates the music file. */ AL_DUH_PLAYER *dp; /* Holds the current playback state. */ /* Initialise Allegro */ if (allegro_init()) return EXIT_FAILURE; /* Check that we have one argument (plus the executable name). */ if (argc != 2) usage(argv[0]); /* Tell Allegro where to find configuration data. This means you can * put any settings for Allegro in dumb.ini. See Allegro's * documentation for more information. */ set_config_file("dumb.ini"); /* Initialise Allegro's keyboard input. */ if (install_keyboard()) { allegro_message("Failed to initialise keyboard driver!\n"); return EXIT_FAILURE; } /* This function call is appropriate for a program that will play one * sample or one audio stream at a time. If you have sound effects * too, you may want to increase the parameter. See Allegro's * documentation for details on what the parameter means. Note that * newer versions of Allegro act as if set_volume_per_voice() was * called with parameter 1 initially, while older versions behave as * if -1 was passed, so you should call the function if you want * consistent behaviour. */ set_volume_per_voice(0); /* Initialise Allegro's sound output system. */ if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) { allegro_message("Failed to initialise sound driver!\n%s\n", allegro_error); return EXIT_FAILURE; } /* dumb_exit() is a function defined by DUMB. This operation arranges * for dumb_exit() to be called last thing before the program exits. * dumb_exit() does a bit of cleaning up for you. atexit() is * declared in stdlib.h. */ atexit(&dumb_exit); /* DUMB defines its own wrappers for file input. There is a struct * called DUMBFILE that holds function pointers for the various file * operations needed by DUMB. You can decide whether to use stdio * FILE objects, Allegro's PACKFILEs or something else entirely. No * wrapper is installed initially, so you must call this or * dumb_register_stdfiles() or set up your own before trying to load * modules by file name. (If you are using another method, such as * loading an Allegro datafile with modules embedded in it, then DUMB * never opens a file by file name so this doesn't apply.) */ dumb_register_packfiles(); /* Load the module file into a DUH object. Quick and dirty: try the * loader for each format until one succeeds. Note that 15-sample * mods have no identifying features, so dumb_load_mod() may succeed * on files that aren't mods at all. We therefore try that one last. */ duh = dumb_load_it(argv[1]); if (!duh) { duh = dumb_load_xm(argv[1]); if (!duh) { duh = dumb_load_s3m(argv[1]); if (!duh) { duh = dumb_load_mod(argv[1]); if (!duh) { allegro_message("Failed to load %s!\n", argv[1]); return EXIT_FAILURE; } } } } /* Read the quality values from the config file we told Allegro to * use. You may want to hardcode these or provide a more elaborate * interface via which the user can control them. */ dumb_resampling_quality = get_config_int("sound", "dumb_resampling_quality", 4); dumb_it_max_to_mix = get_config_int("sound", "dumb_it_max_to_mix", 128); /* If we're not in DOS, show a window and register our close hook * function. */ # ifndef ALLEGRO_DOS { const char *fn = get_filename(argv[1]); gfx_half_width = strlen(fn); if (gfx_half_width < 22) gfx_half_width = 22; gfx_half_width = (gfx_half_width + 2) * 4; /* set_window_title() is not const-correct (yet). */ set_window_title((char *)"DUMB Music Player"); if (set_gfx_mode(GFX_DUMB_MODE, gfx_half_width*2, 80, 0, 0) == 0) { acquire_screen(); textout_centre(screen, font, fn, gfx_half_width, 20, 14); textout_centre(screen, font, "Press any key to exit.", gfx_half_width, 52, 11); release_screen(); } else gfx_half_width = 0; } /* Silly check to get around the fact that someone stupidly removed * an old function from Allegro instead of deprecating it. The old * function was put back a version later, but we may as well use the * new one if it's there! */ # if ALLEGRO_VERSION*10000 + ALLEGRO_SUB_VERSION*100 + ALLEGRO_WIP_VERSION >= 40105 set_close_button_callback(&closehook); # else set_window_close_hook(&closehook); # endif # endif /* We want to continue running if the user switches to another * application. */ set_display_switch_mode(SWITCH_BACKGROUND); /* We have the music loaded, but it isn't playing yet. This starts it * playing. We construct a second object, the AL_DUH_PLAYER, to * represent the playing music. This means you can play the music * twice at the same time should you want to! * * Specify the number of channels (2 for stereo), which 'signal' to * play (always 0 for modules), the volume (1.0f for default), the * buffer size (4096 generally works well) and the sampling frequency * (ideally match the final output frequency Allegro is using). An * Allegro audio stream will be started. */ dp = al_start_duh(duh, 2, 0, 1.0f, get_config_int("sound", "buffer_size", 4096), get_config_int("sound", "sound_freq", 44100)); /* Register our callback functions so that they are called when the * music loops or stops. See docs/howto.txt for more information. * There is no threading issue: DUMB will only process playback * in al_poll_duh(), which we call below. */ { DUH_SIGRENDERER *sr = al_duh_get_sigrenderer(dp); DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(sr); dumb_it_set_loop_callback(itsr, &loop_callback, NULL); dumb_it_set_xm_speed_zero_callback(itsr, &xm_speed_zero_callback, NULL); } /* Main loop. */ for (;;) { /* Check for keys in the buffer. If we get one, discard it * and exit the main loop. */ if (keypressed()) { readkey(); break; } /* Poll the music. We exit the loop if al_poll_duh() has * returned nonzero (music finished) or the window has been * closed. al_poll_duh() might return nonzero if you have set * up a callback that tells the music to stop. */ if (al_poll_duh(dp) || closed) break; /* Give other threads a look-in, or allow the processor to * sleep for a bit. YIELD() is defined further up in this * file. */ YIELD(); } /* Remove the audio stream and deallocate the memory being used for * the playback state. We set dp to NULL to emphasise that the object * has gone. */ al_stop_duh(dp); dp = NULL; /* Free the DUH object containing the actual music data. */ unload_duh(duh); duh = NULL; /* All done! */ return EXIT_SUCCESS; }
/* moves a sprite along the spline path */ void walk(void) { #define MAX_POINTS 256 int points[8]; int x[MAX_POINTS], y[MAX_POINTS]; int n, i; int npoints; int ox, oy; acquire_screen(); clear_to_color(screen, makecol(255, 255, 255)); for (i=1; i<node_count-1; i++) draw_node(i); release_screen(); do { poll_mouse(); } while (mouse_b); clear_keybuf(); ox = -16; oy = -16; xor_mode(TRUE); for (n=1; n < node_count-2; n++) { npoints = (fixtoi(node_dist(nodes[n], nodes[n+1]))+3) / 4; if (npoints < 1) npoints = 1; else if (npoints > MAX_POINTS) npoints = MAX_POINTS; get_control_points(nodes[n], nodes[n+1], points); calc_spline(points, npoints, x, y); for (i=1; i<npoints; i++) { vsync(); acquire_screen(); circlefill(screen, ox, oy, 6, palette_color[2]); circlefill(screen, x[i], y[i], 6, palette_color[2]); release_screen(); ox = x[i]; oy = y[i]; poll_mouse(); if ((keypressed()) || (mouse_b)) goto getout; } } getout: xor_mode(FALSE); do { poll_mouse(); } while (mouse_b); clear_keybuf(); }