Font::~Font() { //If _font is a synonym to Allegro's font object do not destroy it! if(_font != font) destroy_font(_font); _font = nullptr; _file.clear(); _height = 0; }
void simply_res_clear(SimplyRes *self) { while (self->images) { destroy_image(self, (SimplyImage*) self->images); } while (self->fonts) { destroy_font(self, (SimplyFont*) self->fonts); } }
void textgfx_end() { if (!virt_screen) return; destroy_bitmap(virt_screen); virt_screen = NULL; if (font8x16 != font) destroy_font(font8x16); allegro_exit(); }
UI_DATA::~UI_DATA() { UI_DATA_UNLOAD(build_button); UI_DATA_UNLOAD(highlight_build_button); UI_DATA_UNLOAD(mouse_cursor); UI_DATA_UNLOAD(resource_icon); UI_DATA_UNLOAD(logo); // release font if (lfont) destroy_font(lfont); }
int main( void ) { int depth; /* represents color depth */ /* first, set up Allegro and the graphics mode */ allegro_init(); /* initialize Allegro */ install_keyboard(); /* install the keyboard for Allegro to use */ install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, NULL ); depth = desktop_color_depth(); /* find out what color depth is on our computer */ if (depth == 0) depth = 32; set_color_depth( depth ); /* set the color depth to depth used by our computer */ set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ); /* set graphics mode */ ball = load_bitmap( "ball.bmp", NULL ); /* load the ball bitmap */ bar = load_bitmap( "bar.bmp", NULL); /* load the bar bitmap */ buffer = create_bitmap(SCREEN_W, SCREEN_H);/* create buffer */ boing = load_sample( "boing.wav" ); /* load the sound file */ pongFont = load_font( "pongfont.pcx", NULL, NULL ); /* load the font */ ball_x = SCREEN_W / 2; /* give the ball its initial x-coordinate */ ball_y = SCREEN_H / 2; /* give the ball its initial y-coordinate */ barL_y = SCREEN_H / 2; /* give left paddle its initial y-coordinate */ barR_y = SCREEN_H / 2; /* give right paddle its initial y-coordinate */ scoreL = 0; /* set left player’s score to 0 */ scoreR = 0; /* set right player’s score to 0 */ srand( time( NULL ) ); /* seed the random function ... */ direction = rand() % 4; /* and then make a random initial direction */ while ( !key[KEY_ESC] )/* until the escape key is pressed ... */ { moveBall(); /* move the ball */ respondToKeyboard(); /* respond to keyboard input */ /* now, perform double buffering */ clear_to_color( buffer, makecol( 255, 255, 255 ) ); blit( ball, buffer, 0, 0, ball_x, ball_y, ball->w, ball->h ); blit( bar, buffer, 0, 0, 0, barL_y, bar->w, bar->h ); blit( bar, buffer, 0, 0, 620, barR_y, bar->w, bar->h ); /* draw text onto the buffer */ textprintf_ex( buffer, pongFont, 75, 0, makecol( 0, 0, 0 ), -1, "Left Player Score: %d", scoreL ); textprintf_ex( buffer, pongFont, 400, 0, makecol( 0, 0, 0 ), -1, "Right Player Score: %d", scoreR ); blit( buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h ); clear_bitmap( buffer ); } /* end while */ destroy_bitmap( ball ); /* destroy the ball bitmap */ destroy_bitmap( bar ); /* destroy the bar bitmap */ destroy_bitmap( buffer ); /* destroy the buffer bitmap */ destroy_sample( boing ); /* destroy the boing sound file */ destroy_font( pongFont ); /* destroy the font */ return 0; } /* end function main */
AllegroFont::~AllegroFont() { if (mAutoFree) { if (mAllegroFont != NULL) { destroy_font(mAllegroFont); } mAllegroFont = NULL; } }
/* All good things come to an end, and * just like after a fine dinner, someone has to do * the dishes. */ static void destroy_level_data(struct level_data* ldata) { destroy_sound(ldata->music); destroy_font(ldata->font); cleanup_title(&ldata->title); cleanup_tree(&ldata->tree); destroy_image(ldata->grass_tile); destroy_image(ldata->earth_tile); destroy_wizard(ldata->wizard); destroy_timeline(ldata->timeline); free(ldata); }
Editor::Editor() { layer = 1; // Other Sprites buffer = create_bitmap( SCREEN_W, SCREEN_H); // Create map tile_map = new tileMap("data/templates/blank64x48"); // Create example tile exampleTile = new tile(0, tile_map -> getIndex()); exampleTile -> setX(0); exampleTile -> setY(0); FONT *f1, *f2, *f3, *f4, *f5; //Sets Font f1 = load_font("fonts/arial_black.pcx", NULL, NULL); f2 = extract_font_range(f1, ' ', 'A'-1); f3 = extract_font_range(f1, 'A', 'Z'); f4 = extract_font_range(f1, 'Z'+1, 'z'); //Merge fonts font = merge_fonts(f4, f5 = merge_fonts(f2, f3)); //Destroy temporary fonts destroy_font(f1); destroy_font(f2); destroy_font(f3); destroy_font(f4); destroy_font(f5); edittext = ".txt"; iter = edittext.begin(); opening = false; saving = false; }
void Game_sys::UnloadDatafilesAndCleanUp() // FUNCTION FOR DEALLOCATIONG THE MEMORY { unload_datafile( backgrounds ); backgrounds = 0; unload_datafile( bgmusic ); bgmusic = 0; unload_datafile( s_samples ); s_samples = 0; unload_datafile( playerSprites ); playerSprites = 0; unload_datafile( evilBubbleSprites ); evilBubbleSprites = 0; destroy_font( interfaceFont ); destroy_font( titleFont ); }
void Font::AdjustFont(std::string file) { if(exists(file.c_str()) == false) { throw FileNotFoundException(file); } _file = file; if(_font != font) destroy_font(_font); _font = nullptr; _font = load_bitmap_font(file.c_str(), nullptr, nullptr); _height = 0; if(_font) { _height = text_height(_font); } }
/** Destroys fonts. * Uses allegro function to reach destructor in the vtable. */ void destroy_fonts() { if (g_small_font != font) destroy_font(g_small_font); if (large != font) destroy_font(large); if (g_console_font != font) destroy_font(g_console_font); #ifdef HAVE_FREETYPE if (g_console_font_rend) gk_done_renderer(g_console_font_rend); if (g_small_font_rend) gk_done_renderer(g_small_font_rend); if (g_large_font_rend) gk_done_renderer(g_large_font_rend); if (g_console_font_keep) gk_done_keeper(g_console_font_keep); if (g_small_font_keep) gk_done_keeper(g_small_font_keep); if (g_large_font_keep) gk_done_keeper(g_large_font_keep); if (g_console_font_face) gk_unload_face(g_console_font_face); if (g_small_font_face) gk_unload_face(g_small_font_face); if (g_large_font_face) gk_unload_face(g_large_font_face); gk_library_cleanup(); #endif }
void uninstall() { destroy_bitmap(ball[1]); destroy_bitmap(ball[0]); destroy_bitmap(bar_left); destroy_bitmap(bar_right); destroy_bitmap(logo_c); destroy_bitmap(logo); destroy_bitmap(court); destroy_bitmap(screen_buffer); destroy_font(font); remove_timer(); remove_keyboard(); close13h(); }
static void test_cp437() { FONT *f = load_font(DATA_PREFIX CP437_FONT, NULL, NULL); if (!f) { puttext(font, "couldn't load " DATA_PREFIX CP437_FONT, 16, 16); return; } int c; puttext(font, "ACS to codepage 437:", 0, 0); set_char_table(acs_vt100, acs_cp437); for (c=0x60; c < 0x7f; c++) test_8bit_acs(f, c, 0x60, 0); for (c='+'; c <= '0'; c++) test_8bit_acs(f, c, '+', 254); puttext(font, "Latin-1 to CP437:", 0, 50); set_latin1_table(latin1_cp437); test_8bit_latin1(f); destroy_font(f); }
/* color_merge_fonts: * (color vtable entry) * Merges font2 with font1 and returns a new font */ FONT *merge_fonts(FONT *font1, FONT *font2) { FONT *fontout = NULL, *font2_upgr = NULL; FONT_COLOR_DATA *cf, *cf1, *cf2; if (!font1 || !font2) return NULL; if (!is_color_font(font1)) return NULL; if (is_mono_font(font2)) { font2_upgr = upgrade_to_color(font2); /* Couldn't update font */ if (!font2_upgr) return NULL; } else font2_upgr = font2; if (!is_color_font(font2_upgr)) return NULL; /* Get output font */ fontout = al_calloc(1, sizeof *fontout); fontout->height = MAX(font1->height, font2->height); fontout->is_color = true; cf = fontout->data = NULL; cf1 = font1->data; cf2 = font2_upgr->data; while (cf1 || cf2) { if (cf1 && (!cf2 || (cf1->begin < cf2->begin))) { if (cf) { cf->next = color_copy_glyph_range(cf1, cf1->begin, cf1->end); cf = cf->next; } else { cf = color_copy_glyph_range(cf1, cf1->begin, cf1->end); fontout->data = cf; } cf1 = cf1->next; } else { if (cf) { cf->next = color_copy_glyph_range(cf2, cf2->begin, cf2->end); cf = cf->next; } else { cf = color_copy_glyph_range(cf2, cf2->begin, cf2->end); fontout->data = cf; } cf2 = cf2->next; } } if (font2_upgr != font2) destroy_font(font2_upgr); return fontout; }
void triple_buffer(BITMAP **page) { int i = 0, w, repeat, active_page = 0; int time_diff, bar_number, *used_voices = NULL, hw_voices; int text_bar_height, half_bar_size; unsigned int radius; coord_t dot[2], dot_old[2], cal[2], cal_tmp[2]; wiimote *wiimote; char *fonts[NUM_MAX_FONTS] = FONTS; FONT *font_msg, *font_notes; BITMAP *background; bars *bar; /* dot_old data initialization. dot_old's X coord is not used */ dot_old[0].y = SCREEN_H; dot_old[1].y = SCREEN_H; /* Wiimote initialization*/ wiimote = *wiiuse_init(1); /* Load fonts, size of font is related to SCREEN_W */ do { font_msg = load_font(fonts[i], NULL, NULL); __ASSERT(font_msg, ERROR_CANT_LOAD_FONT(fonts[i])); w = text_length(font_msg, WIIMOTE_CONNECTION_MSG); } while (w >= SCREEN_W && ++i < (NUM_MAX_FONTS-1)); /* Notes' font is smaller than messages' font */ font_notes = load_font(fonts[i], NULL, NULL); __ASSERT(font_notes, ERROR_CANT_LOAD_FONT(fonts[i])); /* Initialize and calculate bars size, point radius, text bar height, and calculate half bar size for text output under bars */ bar = bar_create(NUM_BARS); radius = RADIUS(bar); text_bar_height = TEXT_BAR_HEIGHT; half_bar_size = HALF_BAR_SIZE(bar); /* Control the max number of available hardware voices. Though ALSA driver voices are up to 64, max hardware voices generally are 8-16. Checking the allocated voices after the driver allocation seems to be the only way */ hw_voices = get_mixer_voices(); if (hw_voices < NUM_BARS) used_voices = reallocate_voices(bar, hw_voices); /* Install timer, 10 ticks a second */ LOCK_VARIABLE(timer); LOCK_FUNCTION(inc_timer); install_int_ex(inc_timer, BPS_TO_TIMER(10)); /* Load background from file */ background = load_tga("images/back.tga", NULL); __ASSERT(background, ERROR_CANT_LOAD_IMAGE("back.tga")); /* Enables vertical syncronization*/ vsync(); i = 0; /* First frame, this lasts until wiimote is connected, the user is prompted to activate the wiimote by pressing 1 & 2 keys on the wiimote */ while(i == 0 && !keypressed()) { active_page = start_credits3buf(page, active_page); clear_keybuf(); title3buf(page, active_page, font_msg); clear_keybuf(); repeat = 0; while(repeat++ < 8 && i == 0 && !keypressed()) { stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); // background if(repeat%2 == 1) textout_centre_ex(page[active_page], font_msg, WIIMOTE_CONNECTION_MSG, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt release_bitmap(page[active_page]); /* make sure the last flip request has actually happened */ do { } while (poll_scroll()); /* post a request to display the page we just drew */ request_video_bitmap(page[active_page]); /* update counters to point to the next page */ switch (active_page) { case 0: active_page = 1; break; case 1: active_page = 2; break; case 2: active_page = 0; break; } /* Search for a wiimote */ i = wiiuse_find(&wiimote, 1, 1); } } /* Try to connect to the wiimote */ __ASSERT(wiiuse_connect(&wiimote, 1) > 0, ERROR_CANT_OPEN_WIIMOTE); /* Activate the first led on the wiimote */ wiiuse_set_leds(wiimote, WIIMOTE_LED_1); /* Activate the ir module on the wiimote */ wiiuse_set_ir(wiimote, TRUE); wiiuse_motion_sensing(wiimote, FALSE); wiiuse_set_ir_sensitivity(wiimote, 1); wiiuse_set_flags(wiimote, WIIUSE_CONTINUOUS, 0); cal[0].x = 0; cal[0].y = 0; cal[1].x = 1023; cal[1].y = 767; /* CALIBRATION LOOP */ for(repeat=0;repeat<2;repeat++) { clear_keybuf(); while(!keypressed()) { if (wiiuse_poll(&wiimote, 1)) // if there are datas pending from/to wiimote or ESC is pressed if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed wiiuse_disconnect(wiimote); destroy_bitmap(background); destroy_font(font_msg); destroy_font(font_notes); for (i=0;i<NUM_BARS;i++) { deallocate_voice(bar[i].voice); destroy_sample(bar[i].sound); } free(bar); // YO!! :-) free(used_voices); return; } /* background */ stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); if (wiimote->ir.dot[0].visible) { // if ir source is visible /* Read coords from the wiimote's ir*/ dot[0] = transpose(wiimote->ir.dot[0], cal, 0); } switch(repeat) { case 0: textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_ASX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt rect(page[active_page], dot[0].x, dot[0].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0)); break; case 1: textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_BDX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt rect(page[active_page], dot[1].x, dot[1].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0)); rect(page[active_page], -1, -1, dot[0].x, dot[0].y, makecol(0, 0, 0)); break; } circlefill(page[active_page], dot[0].x, dot[0].y, radius, makecol(0, 0, 0)); release_bitmap(page[active_page]); /* make sure the last flip request has actually happened */ do { } while (poll_scroll()); /* post a request to display the page we just drew */ request_video_bitmap(page[active_page]); /* update counters to point to the next page */ switch (active_page) { case 0: active_page = 1; break; case 1: active_page = 2; break; case 2: active_page = 0; break; } } cal_tmp[repeat].x = wiimote->ir.dot[0].x; cal_tmp[repeat].y = wiimote->ir.dot[0].y; dot[1] = dot[0]; } __ASSERT((cal_tmp[0].x < cal_tmp[1].x && cal_tmp[0].y > cal_tmp[1].y), ERROR_WHILE_CALIBRATING); cal[0].x = cal_tmp[0].x; cal[0].y = 767-cal_tmp[0].y; cal[1].x = cal_tmp[1].x; cal[1].y = 767-cal_tmp[1].y; /* MAIN LOOP */ while (TRUE) { /* Draw a frame */ if (wiiuse_poll(&wiimote, 1) || key[KEY_ESC]) // if there are datas pending from/to wiimote or ESC is pressed if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed wiiuse_disconnect(wiimote); destroy_bitmap(background); destroy_font(font_msg); destroy_font(font_notes); for (i=0;i<NUM_BARS;i++) { deallocate_voice(bar[i].voice); destroy_sample(bar[i].sound); } free(bar); // YO!! :-) free(used_voices); return; } /* background */ stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); /* Xylophone's bars and notes names */ for(i=0;i<NUM_BARS;i++) { if (bar[i].t_start != -1 && (time_diff = timer-bar[i].t_start) > TICKS_TO_BLACK) // if color animation ends bar[i].t_start = -1; if (bar[i].t_start == -1) // if no color animation bar[i].color = 0; else bar[i].color = COLORVAL(time_diff); // if color animation is running /* Draw bar */ rectfill(page[active_page], bar[i].min.x, bar[i].min.y, bar[i].max.x, bar[i].max.y, makecol(bar[i].color, bar[i].color, bar[i].color)); /* Print bar's associated note */ textout_centre_ex(page[active_page], font_notes, bar[i].note, (bar[i].min.x + half_bar_size), text_bar_height, makecol(0, 0, 0), -1); } // da normalizzare e da contenere nello schermo, ir for(i=0;i<MAX_IR_DOTS;i++) { if (wiimote->ir.dot[i].visible) { // if ir source is visible /* Read coords from the wiimote's ir*/ dot[i] = transpose(wiimote->ir.dot[i], cal, radius); /* If the ir source is under the bars and in previous frame it was above the bars, then play the sound and start the animation */ if (dot[i].y > bar[0].min.y-radius) { if(dot_old[i].y <= bar[0].min.y-radius) { /* This calculates on which bar the ir source actually is */ bar_number = is_onbar(bar, dot[i].x, NUM_BARS); /* play bar_number's sound with specified volume */ play_bar_voice(bar, bar_number, volume(dot[i].y-dot_old[i].y), used_voices, hw_voices); } /* The dot have not to go under the bars or out of the screen */ circlefill(page[active_page], dot[i].x, bar[0].min.y-radius, radius, makecol(0, 0, 0)); } else circlefill(page[active_page], dot[i].x, dot[i].y, radius, makecol(0, 0, 0)); dot_old[i].y = dot[i].y; } else dot_old[i].y = SCREEN_H; } release_bitmap(page[active_page]); /* make sure the last flip request has actually happened */ do { } while (poll_scroll()); /* post a request to display the page we just drew */ request_video_bitmap(page[active_page]); /* update counters to point to the next page */ switch (active_page) { case 0: active_page = 1; break; case 1: active_page = 2; break; case 2: active_page = 0; break; } } }
/* load_txt_font: * Loads a scripted font. */ FONT *load_txt_font(AL_CONST char *filename, RGB *pal, void *param) { char buf[1024], *font_str, *start_str = 0, *end_str = 0; char font_filename[1024]; FONT *f, *f2, *f3, *f4; PACKFILE *pack; int begin, end, glyph_pos=32; pack = pack_fopen(filename, F_READ); if (!pack) return NULL; f = f2 = f3 = f4 = NULL; while(pack_fgets(buf, sizeof(buf)-1, pack)) { font_str = strtok(buf, " \t"); if (font_str) start_str = strtok(0, " \t"); if (start_str) end_str = strtok(0, " \t"); if (!font_str || !start_str) { if (f) destroy_font(f); if (f2) destroy_font(f2); pack_fclose(pack); return NULL; } if(font_str[0] == '-') font_str[0] = '\0'; begin = strtol(start_str, 0, 0); if (end_str) end = strtol(end_str, 0, 0); else end = -1; if(begin <= 0 || (end > 0 && end < begin)) { if (f) destroy_font(f); if (f2) destroy_font(f2); pack_fclose(pack); return NULL; } /* Load the font that needs to be merged with the current font */ if (font_str[0]) { if (f2) destroy_font(f2); if (exists(font_str)) { f2 = load_font(font_str, pal, param); } else if (is_relative_filename(font_str)) { replace_filename(font_filename, filename, font_str, sizeof(font_filename)); f2 = load_font(font_filename, pal, param); } else { f2 = NULL; } if (f2) glyph_pos=get_font_range_begin(f2, -1); } if (!f2) { if (f) destroy_font(f); pack_fclose(pack); return NULL; } if (end == -1) end = begin + get_font_range_end(f2,-1) - glyph_pos; /* transpose the font to the range given in the .txt file */ f4=extract_font_range(f2,glyph_pos,glyph_pos + (end - begin)); if (f4 && (begin != glyph_pos)) { transpose_font(f4, begin - glyph_pos); } glyph_pos += (end - begin) + 1; /* FIXME: More efficient way than to repeatedely merge into a new font? */ if (f && f4) { f3 = f; f = merge_fonts(f4, f3); destroy_font(f4); destroy_font(f3); } else { f = f4; } f3=f4=NULL; } if (f2) destroy_font(f2); pack_fclose(pack); return f; }
Menu::Menu(){ // Init fmod FSOUND_Init (44100, 32, 0); // Create buffer image buffer = create_bitmap( SCREEN_W, SCREEN_H); // Load images if(!(menu = load_bitmap( ("images/gui/menu.png"), NULL))) abort_on_error( "Cannot find image images/gui/menu.png \n Please check your files and try again"); if(!(menuselect = load_bitmap( ("images/gui/menuSelector.png"), NULL))) abort_on_error( "Cannot find image images/gui/menuSelector.png \n Please check your files and try again"); if(!(help = load_bitmap( ("images/gui/help.png"), NULL))) abort_on_error( "Cannot find image images/gui/help.png \n Please check your files and try again"); if(!(cursor[0] = load_bitmap( ("images/gui/cursor1.png"), NULL))) abort_on_error( "Cannot find image images/gui/cursor1.png \n Please check your files and try again"); if(!(cursor[1] = load_bitmap( ("images/gui/cursor2.png"), NULL))) abort_on_error( "Cannot find image images/gui/cursor2.png \n Please check your files and try again"); if(!(levelSelectLeft = load_bitmap( ("images/gui/levelSelectLeft.png"), NULL))) abort_on_error( "Cannot find image images/gui/levelSelectLeft.png \n Please check your files and try again"); if(!(levelSelectRight = load_bitmap( ("images/gui/levelSelectRight.png"), NULL))) abort_on_error( "Cannot find image images/gui/levelSelectRight.png \n Please check your files and try again"); if(!(levelSelectNumber = load_bitmap( ("images/gui/levelSelectNumber.png"), NULL))) abort_on_error( "Cannot find image images/gui/levelSelectNumber.png \n Please check your files and try again"); if(!(copyright = load_bitmap( ("images/gui/copyright.png"), NULL))) abort_on_error( "Cannot find image images/gui/copyright.png \n Please check your files and try again"); if(!(credits = load_bitmap( ("images/gui/credits.png"), NULL))) abort_on_error( "Cannot find image images/gui/credits.png \n Please check your files and try again"); //Load sound effects if(!(click = load_sample(("sounds/click.wav")))){ abort_on_error( "Cannot find sound sounds/click.png \n Please check your files and try again"); } // Temporary fonts FONT *f1, *f2, *f3, *f4, *f5; //Sets Font if(!(f1 = load_font(("fonts/arial_black.pcx"), NULL, NULL))){ abort_on_error( "Cannot find font fonts/arial_black.png \n Please check your files and try again"); } f2 = extract_font_range(f1, ' ', 'A'-1); f3 = extract_font_range(f1, 'A', 'Z'); f4 = extract_font_range(f1, 'Z'+1, 'z'); //Merge fonts font = merge_fonts(f4, f5 = merge_fonts(f2, f3)); //Destroy temporary fonts destroy_font(f1); destroy_font(f2); destroy_font(f3); destroy_font(f4); destroy_font(f5); // Allow transparency set_alpha_blender(); //Variables newSelectorY = SCREEN_H - 323; selectorY = SCREEN_H - 323; selectorX = 60; mouse_control = false; selectorHovering = 0; // Create map for live background tile_map = new tileMap("data/levels/level_01"); // Set background scroll direction scrollDirection = "right"; tile_map -> y = random( 0, (tile_map -> height * 64) - SCREEN_H); tile_map -> x = 0; levelOn = 0; }
int main() { allegro_init(); install_timer(); install_keyboard(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0); set_window_title("MACAUBAU"); /// Funcoes LOCK_VARIABLE(saida_programa); LOCK_FUNCTION(fechar_X); set_close_button_callback(fechar_X); tempMsec=0; LOCK_FUNCTION(tempo_Turtle); LOCK_VARIABLE(tempMsec); install_int_ex(tempo_Msec, MSEC_TO_TIMER(1)); int exit_program = FALSE; /// BITMAPS BITMAP* buffer=create_bitmap(SCREEN_W, SCREEN_H); BITMAP* personagem=load_bitmap("imagens/m1d.bmp", NULL); BITMAP* fundo=load_bitmap("imagens/fundo.bmp",NULL); BITMAP* turtle=load_bitmap("imagens/t1.bmp", NULL); BITMAP* gameover=load_bitmap("imagens/gameover.bmp",NULL); BITMAP* fail=load_bitmap("imagens/fail.bmp",NULL); BITMAP* per[4]; per[0]=load_bitmap("imagens/m1d.bmp",NULL); per[1]=load_bitmap("imagens/m2d.bmp",NULL); per[2]=load_bitmap("imagens/m1e.bmp",NULL); per[3]=load_bitmap("imagens/m2e.bmp",NULL); /// Fonts FONT * fontscore = load_font("fontscore.pcx",NULL,NULL); /// Variaveis int score = 0,printnv=1; float nivel=1; int iPersonagem=0, seed, xPersonagem=0, colisao=0; int tempo_mov=tempMsec, tempo_animacao=tempMsec; int finalScore=0; struct turtle vetTurtle[4]={0,0,0,0}; vetTurtle[0].tempo=tempMsec; vetTurtle[1].tempo=tempMsec; vetTurtle[2].tempo=tempMsec; while(!saida_programa) { /// ENTRADA if (key[KEY_ESC]) saida_programa=TRUE; /// ATUALIZACAO DE DADOS if(tempMsec-vetTurtle[0].tempo>=20) { vetTurtle[0].yTurtle+=10*nivel; vetTurtle[0].angulo+=7; vetTurtle[0].tempo=tempMsec; } if(vetTurtle[0].yTurtle>560 && colisao!=1) { seed=time(0); srand(seed); vetTurtle[0].xTurtle=(rand()%13)*70; score+=1; vetTurtle[0].yTurtle=0; } if(tempMsec-vetTurtle[1].tempo>=20) { vetTurtle[1].yTurtle+=9*nivel; vetTurtle[1].angulo+=7; vetTurtle[1].tempo=tempMsec; } if(vetTurtle[1].yTurtle>560 && colisao!=1) { seed=time(0); srand(seed); vetTurtle[1].xTurtle=(rand()%7+rand()%7)*70; score+=1; vetTurtle[1].yTurtle=0; } if(tempMsec-vetTurtle[2].tempo>=20) { vetTurtle[2].yTurtle+=9.5*nivel; vetTurtle[2].angulo+=7; vetTurtle[2].tempo=tempMsec; } if(vetTurtle[2].yTurtle>560 && colisao!=1) { seed=time(0); srand(seed); vetTurtle[2].xTurtle=(rand()%5+rand()%8+rand()%2)*70; score+=1; vetTurtle[2].yTurtle=0; } /// * ======== MOVIMENTO PERSONAGEM ======== * /// ///*xPersonagem -- *iPersonagem -- *colisao -- *tempMsec -- *tempo_mov -- *tempo_animacao mov_Personagem(&xPersonagem, &iPersonagem, &colisao, &tempMsec, &tempo_mov, &tempo_animacao); /// * ======== COLISOES ========== * /// func_Colisao(xPersonagem,vetTurtle[0].xTurtle,vetTurtle[0].yTurtle,&colisao); func_Colisao(xPersonagem,vetTurtle[1].xTurtle,vetTurtle[1].yTurtle,&colisao); func_Colisao(xPersonagem,vetTurtle[2].xTurtle,vetTurtle[2].yTurtle,&colisao); /// * ========== NIVEIS - DIFICULDADES =========== * /// func_Nivel(score,&nivel,&printnv); if(vetTurtle[0].angulo>255) vetTurtle[0].angulo=0; if(vetTurtle[1].angulo>255) vetTurtle[1].angulo=0; if(vetTurtle[2].angulo>255) vetTurtle[2].angulo=0; /// * ======== DESENHOS ========= * /// clear(buffer); draw_sprite(buffer,fundo,0,0); if(colisao==0) draw_sprite_ex(buffer,per[iPersonagem],xPersonagem,500,0,0); else { if(score!=0)finalScore=score; draw_sprite(buffer,gameover,0,0); textprintf_ex(buffer,fontscore,300,320,makecol(181,230,29), -1, "FINAL SCORE: %d", finalScore); nivel=1; score=0; printnv=1; } /// ========== Desenho das Turtles ======== /// rotate_sprite(buffer,turtle,vetTurtle[0].xTurtle,vetTurtle[0].yTurtle,ftofix(vetTurtle[0].angulo)); rotate_sprite(buffer,turtle,vetTurtle[1].xTurtle,vetTurtle[1].yTurtle,ftofix(vetTurtle[1].angulo)); rotate_sprite(buffer,turtle,vetTurtle[2].xTurtle,vetTurtle[2].yTurtle,ftofix(vetTurtle[2].angulo)); if(vetTurtle[0].yTurtle>=500 && colisao!=1) draw_sprite(buffer,fail,vetTurtle[0].xTurtle,540); if(vetTurtle[1].yTurtle>=500 && colisao!=1) draw_sprite(buffer,fail,vetTurtle[1].xTurtle,540); if(vetTurtle[2].yTurtle>=500 && colisao!=1) draw_sprite(buffer,fail,vetTurtle[2].xTurtle,540); if(colisao!=1) { textprintf_ex(buffer,fontscore,10,10,makecol(181,230,29), -1, "SCORE: %d", score); textprintf_ex(buffer,fontscore,700,10,makecol(181,230,29), -1, "NIVEL: %d",printnv); } draw_sprite(screen, buffer,0,0); } /// DESTROY destroy_font(fontscore); destroy_bitmap(buffer); destroy_bitmap(turtle); destroy_bitmap(personagem); destroy_bitmap(fundo); allegro_exit(); return 0; }