CAllegroDisplay::CAllegroDisplay(int width,int height,int color_depth,char *error_file) { /* Init the error log handler */ error_log = fopen(error_file,"at"); if (error_file == NULL) { error_log = stdout; PrintError("Error opening error_log file!!!\n"); } /* Init allegro graphic library */ allegro_init(); install_timer(); install_keyboard(); install_mouse(); alfont_init(); show_mouse(NULL); /* Try to init display resolution */ set_color_depth(color_depth); if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,width,height,0,0)) fatalError(allegro_error); set_display_switch_mode(SWITCH_PAUSE); srandom(time(0)); }
void init_font_renderer() { #ifdef USE_ALFONT alfont_init(); alfont_text_mode(-1); #endif for (int i = 0; i < MAX_FONTS; i++) { fontRenderers[i] = NULL; fontRenderers2[i] = NULL; } }
void init() { int depth, res; allegro_init(); alfont_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);//GFX_AUTODETECT//GFX_AUTODETECT_WINDOWED if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); /* add other initializations here */ }
/*** Function : install() Returns : TRUE on succes, FALSE on failure Purpose : Will install game variables, sets up the entire game. ***/ bool install() { // Each time we run the game, we clear out the logbook FILE *fp; fp = fopen("log.txt", "wt"); if (fp) { fprintf(fp, "Counter-Strike 2D Logbook\n"); fprintf(fp, "-------------------------\n\n"); // print head of logbook fclose(fp); } logbook("--------------"); logbook("Initialization"); logbook("--------------"); // init game map.init(); game.init(); steam.init(); logbook("Creating entity types."); game.install_entities(); // Logbook notification logbook("\n-------"); logbook("Allegro"); logbook("-------"); // ALLEGRO - INIT if (allegro_init() != 0) return false; logbook(allegro_id); yield_timeslice(); logbook("yield_timeslice()"); int r = install_timer(); if (r > -1) logbook("install_timer()"); else { logbook("FAILED"); return false; } alfont_init(); logbook("alfont_init()"); install_keyboard(); logbook("install_keyboard()"); install_mouse(); logbook("install_mouse()"); logbook("setting up timer functions / locking functions & memory"); /* set up the interrupt routines... */ LOCK_VARIABLE(RUNNING_TIMER_tenth); LOCK_VARIABLE(RUNNING_TIMER_fps); LOCK_FUNCTION(timer_tenth); LOCK_FUNCTION(fps_proc); install_int(timer_tenth, 10); install_int(fps_proc, 1000); logbook("Timers installed"); frame_count = fps = 0; // set window title char title[80]; sprintf(title, "Counter-Strike 2D"); // Set window title set_window_title(title); char window_title[256]; sprintf(window_title, "Window title set: [%s]", title); logbook(window_title); set_color_depth(16); // run in 16 bit mode if (game.windowed) { int r = set_gfx_mode(GFX_AUTODETECT_WINDOWED, game.screen_x, game.screen_y, game.screen_x, game.screen_y); if (r > -1) { // Succes } else { // GFX_DIRECTX_ACCEL / GFX_AUTODETECT r = set_gfx_mode(GFX_DIRECTX_ACCEL, game.screen_x, game.screen_y, game.screen_x, game.screen_y); if (r > -1) { game.windowed = false; logbook("Could not enter windowed-mode; settings.d3 adjusted"); } else { logbook("ERROR - !"); return false; } } } else { int r = set_gfx_mode(GFX_AUTODETECT, game.screen_x, game.screen_y, game.screen_x, game.screen_y); // succes if (r > -1) { } else { logbook("ERROR - !!"); return false; } } text_mode(0); logbook("Loading font data"); // loading font game_font = alfont_load_font("gfx\\font\\tahoma.ttf"); if (game_font != NULL) { alfont_set_font_size(game_font, 20); // set size } else allegro_message("Error loading tahoma.ttf!"); // CS Font cs_font = alfont_load_font("gfx\\font\\cs.ttf"); if (cs_font != NULL) { alfont_set_font_size(cs_font, 20); // set size } else allegro_message("Error loading cs.ttf"); alfont_text_mode(-1); if (set_display_switch_mode(SWITCH_BACKGROUND) < 0) { set_display_switch_mode(SWITCH_PAUSE); logbook("Display 'switch and pause' mode set"); } else logbook("Display 'switch to background' mode set"); // sound logbook("Initializing sound"); int s = install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); /*** Bitmap Creation ***/ bmp_screen = create_bitmap(game.screen_x, game.screen_y); if (bmp_screen == NULL) { logbook("ERROR: Could not create bitmap: bmp_screen"); return false; } else logbook("Bitmap created: bmp_screen"); bmp_collide = create_bitmap(game.screen_x, game.screen_y); if (bmp_collide == NULL) { logbook("ERROR: Could not create bitmap: bmp_collide"); return false; } else logbook("Bitmap created: bmp_collide"); /*** End of Bitmap Creation ***/ // load datafiles graphics = load_datafile("graphics.dat"); if (graphics == NULL) { logbook("ERROR: Could not load datafile: graphics.dat"); return false; } else logbook("Datafile loaded: graphics.dat"); // Shadows shadows = load_datafile("shadows.dat"); if (shadows == NULL) { logbook("ERROR: Could not load datafile: shadows.dat"); return false; } else logbook("Datafile loaded: shadows.dat"); // HUD hud = load_datafile("hud.dat"); if (hud == NULL) { logbook("ERROR: Could not load datafile: hud.dat"); return false; } else logbook("Datafile loaded: hud.dat"); //set_color_conversion(COLORCONV_NONE); set_color_conversion(COLORCONV_MOST); logbook("Color conversion method set"); // setup mouse speed set_mouse_speed(2,2); logbook("Mouse speed set"); logbook(""); logbook("----"); logbook("GAME "); logbook("----"); game.LOAD_TexturesFromDataFile("data//de_aztec.dat"); // DATA_Init(); // randomize timer srand( (unsigned)time( NULL ) ); //srand(time(NULL)); // normal sounds are loud, the music is lower (its background music, so it should not be disturbing) set_volume(255, 200); set_trans_blender(128, 128, 128, 128); logbook(""); logbook("--------------"); logbook("BATTLE CONTROL"); logbook("--------------"); logbook("\n3...2...1... GO!\n"); return true; }
bool Application::Init() { // logfile if (ENABLE_LOGFILE) { logFile = fopen(LOGFILE,"w"); } log("starting game\n"); srand(time(NULL)); // allegro log("initializing Allegro\n"); if (allegro_init() != 0) return false; // // graphics // log("initializing graphics\n"); set_color_depth(COLOR_DEPTH); int card; if (FULL_SCREEN) card = GFX_AUTODETECT_FULLSCREEN; else card = GFX_AUTODETECT_WINDOWED; if (set_gfx_mode(card,SCREEN_WIDTH,SCREEN_HEIGHT,0,0) != 0) return false; canvas = create_bitmap_ex(COLOR_DEPTH,screen->w,screen->h); if (canvas == NULL) return false; loadingImg = load_bitmap("data/loading.bmp",NULL); if (loadingImg == NULL) return false; blit(loadingImg,screen,0,0,0,0,screen->w,screen->h); // // font system // log("initializing font system\n"); if (alfont_init() != ALFONT_OK) return false; font = alfont_load_font(FONT_FILE); if (font == NULL) return false; // // keyboard // log("initializing keyboard\n"); if (install_keyboard() != 0) return false; memset(prevKeyState,0,256); // // mouse // log("initializing mouse\n"); numMouseButtons = install_mouse(); if (numMouseButtons < 0) return false; mouseButtons = new bool[numMouseButtons+1]; prevMouseButtons = new bool[numMouseButtons+1]; mousePressedLocs = new MousePos[numMouseButtons+1]; for (int button = 0; button < numMouseButtons+1; button++) { mouseButtons[button] = false; prevMouseButtons[button] = false; mousePressedLocs[button].x = -1; mousePressedLocs[button].y = -1; } // timer log("initializing timer\n"); if (install_timer() != 0) return false; // // sound // log("initializing base sound\n"); if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL) != 0) return false; set_volume(ALLEGRO_SOUND_VOLUME,ALLEGRO_SOUND_VOLUME); // initialized successfully! log("initialization completed successfully\n"); KeepRunning = true; return true; }
int main( int argc, char *argv[] ) { int screenMode = GFX_AUTODETECT_WINDOWED; BITMAP *backbuf; TitleScreen *mode_titlescreen; CityMode *mode_city; bool showConsole = false; //args for (int i=1; i < argc; i++) { if (!strcmp(argv[i],"-fullscreen") ) { screenMode = GFX_AUTODETECT_FULLSCREEN; } } // Init alleg allegro_init(); install_keyboard(); install_mouse(); set_color_depth( 16 ); // Turn on the screeny goodness if (set_gfx_mode(screenMode, 640,480, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set 640x480 graphic mode\n%s\n", allegro_error); return 1; } alfont_init(); //set_color_conversion(COLORCONV_TOTAL); //drawing_mode(DRAW_MODE_TRANS, NULL,0,0); // fonts font_console = alfont_load_font("Graphics/fonts/ProFontWindows.ttf"); alfont_set_font_size(font_console, 12); font_title = alfont_load_font("Graphics/fonts/AbductionIII.ttf"); alfont_set_font_size( font_title, 24 ); font_game = alfont_load_font("Graphics/fonts/archtura.ttf" ); alfont_set_font_size( font_game, 24 ); // screen backbuf = create_bitmap( 640, 480 ); rectfill( backbuf, 0,0, 640, 480, 0x0 ); SpriteGraphic *testgfx = new SpriteGraphic( "testship" ); Sprite *test = new Sprite( testgfx ); test->m_x = 10; test->m_y = 70; // game mode mode_titlescreen = new TitleScreen(); mode_city = new CityMode(); g_mode = mode_titlescreen; // init scripts script_init( font_console ); // The main loop while (1) { if (g_mode) { g_mode->update(); } g_mode->draw( backbuf ); #if 0 // draw the game if (Map::g_activeMap) { Map::g_activeMap->draw( backbuf ); // DBG: Map scrolling Map::g_activeMap->m_scroll = ((float)mouse_y / 480.0) * ((Map::g_activeMap->m_maphite-15)*32); } else { rectfill( backbuf, 0,0, 640, 480, 0x0 ); alfont_textout_centre( backbuf, font_game, "Infection", 320, 200, makecol(200, 0, 0) ); } // draw the sprites test->draw( backbuf ); char buff[200]; sprintf( buff, "testy %d m2s %d scroll %d", test->m_y, Map::mapYtoScreenY( test->m_y ), Map::getScroll() ); alfont_textout( backbuf, font_console, buff, 320, 200, makecol(255,255,255) ); #endif // draw the console if (showConsole) { draw_console( backbuf ); } // event handler if (keypressed()) { int k = readkey(); int kk = k >>8; // mode specific keypress g_mode->key_pressed( k ); // global keypress if (kk==KEY_TILDE) { showConsole = !showConsole; } else if (showConsole) { // send key to console console_key( k ); } else { switch(k>>8) { case KEY_DOWN: test->m_y += 10; break; case KEY_UP: test->m_y -= 10; break; } } } if (key[KEY_ESC]) { //exit(0); break; } // Blit the screen vsync(); acquire_screen(); blit( backbuf, screen, 0, 0, 0, 0, 640, 480 ); release_screen(); yield_timeslice(); } return 0; }