Пример #1
0
void    Data_Close(void)
{
    assert(g_Datafile != NULL);
    list_free_custom(&g_DatafileBitmapCopy32, destroy_bitmap);
    unload_datafile(g_Datafile);
    g_Datafile = NULL;
}
Пример #2
0
void use_item( Player *p, Item *it, Level *l ) {
	DATAFILE *data;

	data = load_datafile( "dat/sprites.dat" );
	if (!data)
		fatal("Error reading datafile 'dat/sprites.dat'\n");

	V_clear( p->item_animation );
	switch ( it->type ) {
		case ITEM_POTION:
			INC2MAX( p->life, 1, MAX_LIFE );
			p->item_in_use = (4 * ANIMATION_RATE);
			p->item_timer = ANIMATION_RATE;
			p->cur_item_frame = 0;
			V_add( p->item_animation, copy_bitmap( (BITMAP *)data[9].dat ) );
			V_add( p->item_animation, copy_bitmap( (BITMAP *)data[10].dat ) );
			V_add( p->item_animation, copy_bitmap( (BITMAP *)data[11].dat ) );
			V_add( p->item_animation, copy_bitmap( (BITMAP *)data[10].dat ) );
			break;
		case ITEM_PIPE:
			/*tmp = V_length( l->sprite_images );
			V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[12].dat ) );
			V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[13].dat ) );
			V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[14].dat ) );
			V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[15].dat ) );*/
			/*create_sprite( Level *l, int type, int x, int y, int dir, int speed, int jump_rate, int shot_rate, int life, int num_of_images, ... )*/
			create_sprite( l, SPRITE_WALK, p->pos_x, 0, -1, 8, 0, 50, 2,   5, 0, 0, 1, 2, 1 );
			break;
		default:
			break;
	}

	unload_datafile( data );
}
Пример #3
0
Player *load_player() {
	Player *p = (Player *)malloc( sizeof(Player) );
	DATAFILE *data;
	BITMAP *t;

	memset( p, 0, sizeof(Player) );		
	
	data = load_datafile( "dat/sprites.dat" );
	if (!data)
		fatal("Error reading datafile 'dat/sprites.dat'\n");

	p->still_image = copy_bitmap( (BITMAP *)data[0].dat );

	p->moving_images = V_new();
	V_register_del_func( p->moving_images, (VectorFunc)destroy_bitmap );

	t = copy_bitmap( (BITMAP *)data[0].dat );
	V_add( p->moving_images, t );

	t = copy_bitmap( (BITMAP *)data[1].dat );
	V_add( p->moving_images, t );

	t = copy_bitmap( (BITMAP *)data[2].dat );
	V_add( p->moving_images, t );

	t = copy_bitmap( (BITMAP *)data[1].dat );
	V_add( p->moving_images, t );

	p->ducking_image = copy_bitmap( (BITMAP *)data[a05_marioduck].dat );
	p->jumping_image = copy_bitmap( (BITMAP *)data[a03_mariobat].dat );
	p->attack_image = copy_bitmap( (BITMAP *)data[a04_mariobat].dat );

	set_pallete( *((PALLETE *)data[Zpallete].dat) );

	unload_datafile( data );

	p->cur_image = p->still_image;
	p->width = p->cur_image->w;
	p->height = p->cur_image->h;

	p->invul = 0;
	p->life = MAX_LIFE;
	p->max_jump = MAX_JUMP;

	p->inventory = V_new();
	p->quantity = IA_new();
	p->inv_selection = 0;

	p->item_in_use = 0;
	p->cur_item_frame = 0;
	p->item_animation = V_new();
	V_register_del_func( p->item_animation, (VectorFunc)destroy_bitmap );

	p->weapon = 1;
	p->weapon_length = 20;
	p->weapon_timer = 0;
	p->weapon_speed = 15;
	p->weapon_delay = 10;
	return p;
}
Пример #4
0
void clean_up()
{
    delete currentMap;
    delete tileRepository;

    destroy_bitmap(buffer);
    unload_datafile(engine_data);

    agup_shutdown();
}
void ReleaseGlobalDatafile()
{
    erlog("Clearing global datafile memory");
    if (!global_datafile) {
        erlog("Datafile not loaded anyway", 1);
        return;
    }
    unload_datafile(global_datafile);
    erlog("Memory cleared");
}
Пример #6
0
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 );

}
Пример #7
0
static void shut_down()
{
   //clean up
   flush_config_file();
   write_log("\nShutting Down Serial Module... ");
   serial_module_shutdown();
   write_log("OK");
   write_log("\nUnloading Data File... ");
   unload_datafile(datafile);
   write_log("OK");
   write_log("\nShutting Down Allegro... ");
   allegro_exit();
   write_log("OK");
}
Пример #8
0
CGame::~CGame()
{
	int i;

	//destroy bitmaps
	destroy_bitmap(background);

	for (i=0;i<27;i++) {
		destroy_bitmap(smalltiles[i]);
	}
	
	//unload data
	unload_datafile(data);

}
Пример #9
0
int main()
{
    Setup();
    SetupBoard();
    while (!(key[KEY_ESC]) && RedLeft > 0 && BlackLeft > 0)
    {
		DrawBackGround();
		Clicks();
		CheckPlay();
        Flip();
    }
    destroy_bitmap(buffer2);
    destroy_bitmap(buffer);
    unload_datafile(data);
}
Пример #10
0
int main( void )
{
   /* 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 );
   install_timer(); /* install the timer handler */
   set_color_depth( 16 ); /* set the color depth to 16-bit */
   set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0 ); /* set graphics mode */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);/* create buffer */
   pongData = load_datafile( "pongdatafile.dat" ); /* load the datafile */
   ball_x = SCREEN_W / 2; /* give ball its initial x-coordinate */
   ball_y = SCREEN_H / 2; /* give 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 */
   /* add timer that calls moveBall every 5 milliseconds */
   install_int( moveBall, 5 );
   /* add timer that calls respondToKeyboard every 10 milliseconds */
   install_int( respondToKeyboard, 10 );
   
   while ( !key[KEY_ESC] ) /* until the escape key is pressed ... */
   {
      /* now, perform double buffering */
      clear_to_color( buffer, makecol( 255, 255, 255 ) );
      blit( pongData[BALL].dat, buffer, 0, 0, ball_x, ball_y, 40, 40 );
      blit( pongData[BAR].dat, buffer, 0, 0, 0, barL_y, 20, 100 );  
      blit( pongData[BAR].dat, buffer, 0, 0, 620, barR_y, 20, 100 );
      line( buffer, 0, 30, 640, 30, makecol( 0, 0, 0 ) );
      /* draw text onto the buffer */
      textprintf_ex( buffer, pongData[PONGFONT].dat, 75, 0, makecol( 0, 0, 0 ),
                     -1, "Left Player Score: %d", scoreL );             
      textprintf_ex( buffer, pongData[PONGFONT].dat, 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 */
 
   remove_int( moveBall ); /* remove moveBall timer */
   remove_int( respondToKeyboard ); /* remove respondToKeyboard timer */
   destroy_bitmap( buffer ); /* destroy the buffer bitmap */
   unload_datafile( pongData ); /* unload the datafile */
   return 0;
} /* end function main */
Пример #11
0
static void
used_bitmaps_cleanup (void)
{
	int i;
	for (i = 0; i < used_bitmaps_count; i++) {
		destroy_bitmap (used_bitmaps[i]);
		free (used_bitmaps_names[i]);
	}
	free (used_bitmaps);
	free (used_bitmaps_names);
	if (used_dat)
		unload_datafile (used_dat);
	used_bitmaps_count = 0;
	used_bitmaps = NULL;
	used_bitmaps_names = NULL;
	used_dat = NULL;
}
Пример #12
0
void fatal_error(char *msg)
{
   char temp_buf[512];

   if (datafile != NULL)
      unload_datafile(datafile);

   sprintf(temp_buf, "\nERROR: %s", msg);
   strcat(temp_buf, "\n\nPlease contact ScanTool.net via our website at http://www.ScanTool.net/support");
   strcat(temp_buf, "\nInclude the following information:");
   strcat(temp_buf, "\n\t- Exact error message");
   strcat(temp_buf, "\n\t- CPU type/speed, i.e. \"Pentium 100Mhz\"");
   strcat(temp_buf, "\n\t- OS, i.e. \"Windows 95\"");
   strcat(temp_buf, "\n\t- Total amount of RAM installed, i.e. \"4Mb\"\n\n");
   allegro_message(temp_buf);
   
   exit(EXIT_FAILURE);
}
Пример #13
0
static void test_unicode()
{
	FONT *f = font;
	DATAFILE *dat = load_datafile(DATA_PREFIX "font.dat");
	if (dat && dat->type == DAT_FONT)
		f = (FONT *) dat->dat;
	int c;

	puttext(font, "ACS to unicode:", 0, 0);
	set_acs_unicode_table(acs_vt100, acs_unicode);
	for (c=0x60; c < 0x7f; c++)
		test_unicode_acs(f, c, 0x60, 0);
	for (c='+'; c <= '0'; c++)
		test_unicode_acs(f, c, '+', 254);

	puttext(font, "testing UTF-8 encoder...", 0, 70);
	puttext(font, test_utf8_enc() ? "ok" : "failed!", 204, 70);

	if (dat)
		unload_datafile(dat);
}
Пример #14
0
int main() {

	FONT *lucidia_fnt;
	FONT *allegro_fnt;
	DATAFILE *dat;
	
	struct {
		float x, y, z;
		int c;
	} coord[NUM_STRINGS];
	char *string = STRING;
	int i;

	allegro_init();
	install_allegro_gl();
	install_timer();
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);
	
	install_int(the_timer, 2);

	allegro_gl_clear_settings();
	allegro_gl_set(AGL_COLOR_DEPTH, 32);
	allegro_gl_set(AGL_Z_DEPTH, 24);
	allegro_gl_set(AGL_WINDOWED, TRUE);
	allegro_gl_set(AGL_DOUBLEBUFFER, 1);
	allegro_gl_set(AGL_RENDERMETHOD, 1);
	allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER
	             | AGL_RENDERMETHOD | AGL_Z_DEPTH | AGL_WINDOWED);

	if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0)) {
		allegro_message("Error initializing OpenGL!\n");
		return -1;
	}

	install_keyboard();


	/* Load 2 copies of the datafile */	
	dat = load_datafile("lucidia.dat");

	if (!dat) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load lucidia.dat\n");
		return -2;
	}

	lucidia_fnt = allegro_gl_convert_allegro_font((FONT*)dat[0].dat,
	                                              AGL_FONT_TYPE_TEXTURED, 16.0);

	if (!lucidia_fnt) {
		unload_datafile(dat);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to convert font!\n");
		return -3;
	}

	allegro_fnt = allegro_gl_convert_allegro_font(font,
	                                              AGL_FONT_TYPE_TEXTURED, 16.0);

	if (!allegro_fnt) {
		allegro_gl_destroy_font(lucidia_fnt);
		unload_datafile(dat);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to convert font!\n");
		return -4;
	}

	
	srand(time(NULL));


	for (i = 0; i < NUM_STRINGS; i++) {
		coord[i].z = 0;
		coord[i].c = 0;
	}
	i = 0;

	/* Start nice text demo */

	/* Setup OpenGL like we want */
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);

	glViewport(0, 0, SCREEN_W, SCREEN_H);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0);

	/* Set culling mode - not that we have anything to cull */
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CCW);
			
	glMatrixMode(GL_MODELVIEW);

	do {
		int c;

		/* Update rotation angle of text */	
		glLoadIdentity();
		
		glTranslatef(0, 0, -30);
		glRotatef(-45, 1, 0, 0);
		glRotatef(-30, 0, 1, 0);

		/* Clear the screen and set a nice blender mode */
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);						
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);

		/* Print the text wheel */
		for (i = 0; i < NUM_STRINGS; i++) {			
			allegro_gl_printf(lucidia_fnt, coord[i].x, coord[i].y, coord[i].z,
			                  coord[i].c, string);
		}
		/* Update the text wheel's position */
		for (i = 0; i < NUM_STRINGS; i++) {
			int r, g, b;
			float angle2 = angle + i * M_PI * 2 / NUM_STRINGS;
			coord[i].x = 10 * cos(angle2) - 10;
			coord[i].y = 10 * sin(angle2);			
			angle2 = angle2 * 180.0 / M_PI;
#if ((((ALLEGRO_VERSION) << 16) | ((ALLEGRO_SUB_VERSION) << 8) | (ALLEGRO_WIP_VERSION)) == 0x40200)
			/* Work around an Allegro bug that's only in 4.2.0 */
			while (angle2 > 360.0f) angle2 -= 360.0f;
			while (angle2 < 0)      angle2 += 360.0f;
#endif			
			hsv_to_rgb(angle2, 1, 1, &r, &g, &b);
			coord[i].c = makeacol(r, g, b, 255);
		}
		/* Draw "AllegroGL" */
		glLoadIdentity();
		c = MID(0, (int)(255 - chrono / 100), 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING0) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 0, makecol(c, c, c), STRING0);
		c = MID(0, (int)(255 - chrono / 100) + 24, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING1) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 12, makecol(c, c, c), STRING1);
		c = MID(0, (int)(255 - chrono / 100) + 48, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING2) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 24, makecol(c, c, c), STRING2);
		c = MID(0, (int)(255 - chrono / 100) + 72, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING3) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 36, makecol(c, c, c), STRING3);
		c = MID(0, (int)(255 - chrono / 100) + 96, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING4) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 48, makecol(c, c, c), STRING4);
		c = MID(0, (int)(255 - chrono / 100) + 120, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(URL) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 60, makecol(c, c, c), URL);

		allegro_gl_flip();

		rest(2);

	} while (!key[KEY_ESC]);

	return 0;
}
Пример #15
0
/**
 * Unload the test sprite.
 */
void unload_usp_talon_dat() {
    unload_datafile(USP_TALON_DAT);
    USP_TALON_LOADED = FALSE;
}
Пример #16
0
int main(int argc, char *argv[])
{
   DATAFILE *data;
   FONT *f;
   BITMAP *buffer;
   int i, j, k, height;
   char buf[256], tmp[256], tmp2[256];
   int counter = 0, drawn = 0;
   int scroll_w, scroll_h;
   int background_color;

   /* set the text encoding format BEFORE initializing the library */
   set_uformat(U_UNICODE);

   /*  past this point, every string that we pass to or retrieve
    *  from any Allegro API call must be in 16-bit Unicode format
    */

   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();

   /* load the datafile containing the Unicode font */
   replace_filename(buf, uconvert_ascii(argv[0], tmp), uconvert_ascii(DATAFILE_NAME, tmp2), sizeof(buf));
   data = load_datafile(buf);
   if (!data) {
      allegro_message(uconvert_ascii("Unable to load %s\n", tmp), buf);
      return -1;
   }

   /* set the graphics mode */
   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message(uconvert_ascii("Unable to set any graphic mode\n%s\n", tmp), allegro_error);
	 return 1;
      }
   }

   /* set the window title for windowed modes */
   set_window_title(uconvert_ascii("Unicode example program", tmp));

   /* create a buffer for drawing */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);

   /* get a handle to the Unicode font */
   f = data[0].dat;
   height = text_height(f);

   /* The are for the text messages. If it gets too crowded once we have more
    * languages, this can be increased.
    */
   scroll_w = SCREEN_W * 2;
   scroll_h = SCREEN_H + height;

   /* one of the bright colors in the default palette */
   background_color = 56 + AL_RAND() % 48;

   /* prepare the messages */
   for (i = 0; i < NLANGUAGES; i++) {

      /* the regular Standard C string manipulation functions don't work
       * with 16-bit Unicode, so we use the Allegro Unicode API
       */
      message[i].str = malloc(ustrsize(message[i].data) + ustrsizez(allegro_str));

      if (message[i].prefix_allegro) {
         ustrcpy(message[i].str, allegro_str);
         ustrcat(message[i].str, message[i].data);
      }
      else {
         ustrcpy(message[i].str, message[i].data);
         ustrcat(message[i].str, allegro_str);
      }

      message[i].w = text_length(f, message[i].str);
      message[i].h = text_height(f);

      /* one of the dark colors in the default palette */
      message[i].c = 104 + AL_RAND() % 144;

      message[i].dx *= 1 + AL_RAND() % 4;
      message[i].dy = AL_RAND() % 3 - 1;

      /* find not-overlapped position, try 1000 times */
      for (k = 0; k < 1000; k++) {
         message[i].x = AL_RAND() % scroll_w;
         /* make sure the message is not sliced by a screen edge */
         message[i].y = 10 + AL_RAND() % (SCREEN_H - height - 20);
         for (j = 0; j < i; j++) {
            if (overlap(i, j, 10))
               break;
         }
         if (j == i)
            break;
      }
   }

   install_int_ex(ticker, BPS_TO_TIMER(30));
   /* do the scrolling */
   while (!keypressed()) {
      /* Animation. */
      while (counter <= ticks) {
         for (i = 0; i < NLANGUAGES; i++) {
            message[i].x += message[i].dx;
            if (message[i].x >= scroll_w)
               message[i].x -= scroll_w;
            if (message[i].x < 0)
               message[i].x += scroll_w;
            message[i].y += message[i].dy;
            if (message[i].y >= scroll_h)
               message[i].y -= scroll_h;
            if (message[i].y < 0)
               message[i].y += scroll_h;
         }
         counter++;
      }

      /* Draw current frame. */
      if (drawn < counter) {
         clear_to_color(buffer, background_color);
         for (i = 0; i < NLANGUAGES; i++) {
            char *str = message[i].str;
            int x = message[i].x;
            int y = message[i].y;
            int c = message[i].c;
            /* draw it 4 times to get the wrap-around effect */
            textout_ex(buffer, f, str, x, y, c, -1);
            textout_ex(buffer, f, str, x - scroll_w, y, c, -1);
            textout_ex(buffer, f, str, x, y - scroll_h, c, -1);
            textout_ex(buffer, f, str, x - scroll_w, y - scroll_h, c, -1);
         }
         blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
         drawn = counter;
      }
      else {
         rest(10); /* We are too fast, give time to the OS. */
      }
   }

   destroy_bitmap(buffer);

   unload_datafile(data);

   return 0;
}
Пример #17
0
int main(int argc, char *argv[])
{
   char buf[256];
   int i;

   /* initialise everything */
   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_mouse();
   install_timer();

   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 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;
      }
   }

   /* load the datafile */
   replace_filename(buf, argv[0], "example.dat", sizeof(buf));
   datafile = load_datafile(buf);
   if (!datafile) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s!\n", buf);
      return 1;
   }

   set_palette(datafile[THE_PALETTE].dat);

   /* set up colors */
   gui_fg_color = makecol(0, 0, 0);
   gui_mg_color = makecol(128, 128, 128);
   gui_bg_color = makecol(200, 240, 200);
   set_dialog_color(the_dialog, gui_fg_color, gui_bg_color);

   /* white color for d_clear_proc and the d_?text_procs */
   the_dialog[0].bg = makecol(255, 255, 255);
   for (i = 4; the_dialog[i].proc; i++) {
      if (the_dialog[i].proc == d_text_proc ||
          the_dialog[i].proc == d_ctext_proc ||
          the_dialog[i].proc == d_rtext_proc)
      {
         the_dialog[i].bg = the_dialog[0].bg;
      }
   }
   
   /* fill in bitmap pointers */
   the_dialog[BITMAP_OBJECT].dp = datafile[SILLY_BITMAP].dat;
   the_dialog[ICON_OBJECT].dp = datafile[SILLY_BITMAP].dat;
   
   /* shift the dialog 2 pixels away from the border */
   position_dialog(the_dialog, 2, 2);
   
   /* do the dialog */
   do_dialog(the_dialog, -1);

   unload_datafile(datafile);
   
   return 0;
}
Пример #18
0
int opMenu()
{
     DATAFILE *menu = load_datafile("data\\menu.dat");
 	 BITMAP *buffer = create_bitmap(640,480);
 	 
 	 blit((BITMAP *)menu[1].dat, buffer, 0, 0, 0, 0, MAX_W, MAX_H);
 	 textprintf_centre_ex(buffer, font, 320, 305, makecol(0,30,50),-1, "Para trocar entre o modo fullscreen e janela, aperte ENTER.");
 	 
 	 font = (FONT *)menu[9].dat;
 	 
 	 fade_in(buffer, 10);
 	 
 	 FILE *conf = fopen("config.cdb", "wb");
 	 
 	 if (conf == NULL)
 	 {
        allegro_message("Problema com o arquivo de configuração: config.cdb");
        return 5;
     }
 	 
 	 while (!key[KEY_ESC])
 	 {
        clear(buffer);
        
        blit((BITMAP *)menu[1].dat, buffer, 0, 0, 0, 0, MAX_W, MAX_H);
 	    textprintf_centre_ex(buffer, font, 320, 305, makecol(0,30,50),-1, "Para trocar entre o modo fullscreen e janela, aperte ENTER.");
        
        if (key[KEY_ENTER])
        {
        
           if (is_windowed_mode())
           {
	          if (set_gfx_mode(GFX_AUTODETECT, MAX_W, MAX_H, 0, 0) != 0) {
		         allegro_message(allegro_error);
		         exit(-1);
	          }
	          fade_out(10);
	          unload_datafile(menu);
              destroy_bitmap(buffer);
              
              fprintf(conf, "%d", 2);
              fclose(conf);
     
              return 0;
           }
           else
           {
	          if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, MAX_W, MAX_H, 0, 0) != 0) {
		         allegro_message(allegro_error);
		         exit(-1);
	          }
	          fade_out(10);
	          unload_datafile(menu);
              destroy_bitmap(buffer);
              
              fprintf(conf, "%d", 1);
              fclose(conf);
     
              return 0;
           }
        }
        
        draw_sprite(buffer, (BITMAP *)menu[0].dat, mouse_x, mouse_y);
        
        blit(buffer, screen, 0, 0, 0, 0, MAX_W, MAX_H);
     }
     fade_out(10);
     
     unload_datafile(menu);
     destroy_bitmap(buffer);
     
     return 0;
}
Пример #19
0
int main(void)
{
 BITMAP *scrbuffer;
 DATAFILE *main_data;
 int vmode_error;

 RGB black = { 0,  0,  0 };

 // initialise allegro
 allegro_init();
 install_keyboard();
 install_timer();
 //install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

 // load main data file into memory
 main_data = load_datafile("dogfight.dat");

 // use the palette stored in the datafile and
 // set the "clear" colour from a working hot pink to an invisible black
 memcpy(&pal, main_data[MAINPAL].dat, sizeof(pal));

 // enter graphics mode -- don't debug from here --
 vmode_error = set_gfx_mode(GFX_AUTODETECT, SET_W, SET_H, 0, 0);
 if (vmode_error) {
   printf("Error setting graphics mode...\n%s\n\n", allegro_error);
   allegro_exit();
   exit(1);
 }

 set_palette(pal);
 set_color(0, &black);

 // build a colour lookup table for translucent drawing
 // NB: 128 translucency = 50%
 textout_centre_ex(screen, main_data[FONTSMALL].dat, "Dogfight by Gregory McIntyre", SCREEN_W/2, SCREEN_H/2-58, GREY+15, -1);
 textout_centre_ex(screen, font, "Loading. Please wait...", SCREEN_W/2, SCREEN_H/2-20, GREY+15, -1);
 callback_count = 0;
 create_trans_table(&trans_table, main_data[MAINPAL].dat, CLOUD_TRANSPARENCY, CLOUD_TRANSPARENCY, CLOUD_TRANSPARENCY, callback_func);

 // allocate memory for screen buffer
 scrbuffer = create_bitmap(SCREEN_W, SCREEN_H); clear(scrbuffer);

 // when everything is ready fade out and go to the title screen
 fade_out(10);
 title_page(scrbuffer, main_data);

 // free allocated memory and exit allegro
 destroy_bitmap(scrbuffer);

 unload_datafile(main_data);
 allegro_exit();

 // print a message that will be displayed at the DOS prompt on leaving
 printf("Thankyou for playing Dogfight.\n");
 printf("Dogfight was created using the Allegro game library.\n");
 printf("It's free so enjoy and distribute at your leasure.\n\n");

 printf("-------------------------------\n");
 printf("The author can be contacted at:\n\n");
 printf("[email protected]*\n\n");
 printf("-------------------------------\n\n");
 printf("Have a nice day!\n");
 printf("\n");
 printf("* Email no longer valid.\n");
 return 0;
}
Пример #20
0
int main (void)
{
// Golobal Integers
    extern int level;
    extern int lifes;
    extern int score;
    extern int health;
// Local Integers
   register int mapxoff, mapyoff;
   extern int oldpy, oldpx;
   extern int facing;
   extern int jump;
   int n, m;
  // DATAFILE *data;
//initilization    
	allegro_init();	
	install_timer();
	install_keyboard();
    set_color_depth(32);
	set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);

//load data
data = load_datafile("test.dat");
    temp = (BITMAP *)data[NEWGUY_BMP].dat;
    for (n=0; n<4; n++)
    player_image[n] = grabframe(temp,43,77,0,0,4,n);
    destroy_bitmap(temp);
    temp2 = (BITMAP *)data[BAT1_BMP].dat;
    for (m=0; m<2; m++)
    bat_img[m] = grabframe(temp2,87,72,0,0,2,m);
    destroy_bitmap(temp2);

    test_img = load_bitmap("test.bmp", NULL);
gameover:
Start();
first:
//initilize Player
    player = malloc(sizeof(SPRITE));
    player->x = 80;
    player->y = 200;
    player->curframe=0;
    player->framecount=0;
    player->framedelay=11;
    player->maxframe=3;
    player->width=player_image[0]->w;
    player->height=player_image[0]->h;
//initilize Bat
    bat = malloc(sizeof(SPRITE));
    bat->x = 170;
    bat->y = 100;
    bat->curframe=0;
    bat->framecount=0;
    bat->framedelay=11;
    bat->maxframe=1;
    bat->width=bat_img[0]->w;
    bat->height=bat_img[0]->h;
    bat->dir = 0;
    bat->xspeed = 0;
//ini test
test = malloc(sizeof(SPRITE));
    test->x = 270;
    test->y = 400;
    test->curframe=0;
    test->framecount=0;
    test->framedelay=11;
    test->maxframe=1;
    test->width=bat_img[0]->w;
    test->height=bat_img[0]->h;
    test->dir = 0;
    test->xspeed = 0;

loadlevel();

    //main loop
	while (!key[KEY_ESC])
	{
      oldpy = player->y; 
      oldpx = player->x;

if (player->x > 3000)
        {level = 2;
		goto first;}

if (lifes == 0)
{lifes = 3;
          goto gameover;}

if (health < 1)
{lifes -=1;
  health =100;
  goto first;}

  updateEnemy(150, 300, test);
  updateEnemy(150, 300, bat);       
  enemycoll(player->x, player->y, bat);       
  keyinput();
//collition control
	if (!facing) 
        { 
            if (collided(player->x, player->y + player->height)) 
                player->x = oldpx; 
                if (collidedobj(player->x, player->y + player->height))
                   {ClearCell(player->x, player->y + player->height); 
                   AddScore();}
                      if (collidedkill(player->x+9, player->y + player->height))
                         {health -= 25;}        
        }
		else 
        { 
            if (collided(player->x + player->width, player->y + player->height)) 
                player->x = oldpx; 
                if (collidedobj(player->x + player->width, player->y + player->height))
                   {ClearCell(player->x + player->width, player->y + player->height);
                   AddScore();}
                      if (collidedkill(player->x + player->width-15, player->y + player->height))
                         {health -= 25;}        
        }
		
        //update the map scroll position
		mapxoff = player->x + player->width/2 - WIDTH/2 + 10;
		mapyoff = player->y + player->height/2 - HEIGHT/2 + 10;
        //avoid moving beyond the map edge
		if (mapxoff < 0) mapxoff = 0;
		if (mapxoff > (mapwidth * mapblockwidth - WIDTH))
            mapxoff = mapwidth * mapblockwidth - WIDTH;
		if (mapyoff < 0) 
            mapyoff = 0;
		if (mapyoff > (mapheight * mapblockheight - HEIGHT)) 
            mapyoff = mapheight * mapblockheight - HEIGHT;

        //draw the background tiles
		MapDrawBG(buffer, mapxoff, mapyoff, 0, 0, WIDTH-1, HEIGHT-1);
        //draw foreground tiles
		MapDrawFG(buffer, mapxoff, mapyoff, 0, 0, WIDTH-1, HEIGHT-1, 0);
        //draw the player's sprite
		if (facing) 
            draw_sprite(buffer, player_image[player->curframe], 
                (player->x-mapxoff), (player->y-mapyoff+1));
		else 
            draw_sprite_h_flip(buffer, player_image[player->curframe], 
                (player->x-mapxoff), (player->y-mapyoff));

        //blit the double buffer 
		vsync();
        acquire_screen();
		if (bat->dir == 1)
           draw_sprite(buffer, bat_img[bat->curframe],(bat->x-mapxoff),(bat->y-mapyoff));
        else
           draw_sprite_h_flip(buffer, bat_img[bat->curframe],(bat->x-mapxoff),(bat->y-mapyoff)); 
        
        draw_sprite(buffer, test_img,(test->x-mapxoff),(test->y-mapyoff));
        textprintf(buffer,font,0,0,9999999,"lifes = %d  Score = %d  Health = %d",lifes,score,health);
        blit(buffer, screen, 0, 0, 0, 0, WIDTH-1, HEIGHT-1);
       	release_screen();

	} //End of game loop




    for (n=0; n<4; n++)
        destroy_bitmap(player_image[n]);
    for (m=0; m<2; m++)
        destroy_bitmap(bat_img[m]);

destroy_bitmap(test_img);

    free(player);
	free(bat);
    free(test);
    destroy_bitmap(buffer);
	MapFreeMem ();
	MapFreeMem ();
    unload_datafile(data);
    allegro_exit();
	return 0;
}
Пример #21
0
int main(int argc, char *argv[])
{
   int c, w, h;
   char buf[256], buf2[256];
   ANIMATION_TYPE type;

   for (c = 1; c < argc; c++) {
      if (stricmp(argv[c], "-cheat") == 0)
         cheat = TRUE;

      if (stricmp(argv[c], "-jumpstart") == 0)
         jumpstart = TRUE;
   }

   /* The fonts we are using don't contain the full latin1 charset (not to
    * mention Unicode), so in order to display correctly author names in
    * the credits with 8-bit characters, we will convert them down to 7
    * bits with a custom mapping table. Fortunately, Allegro comes with a
    * default custom mapping table which reduces Latin-1 and Extended-A
    * characters to 7 bits. We don't even need to call set_ucodepage()!
    */
   set_uformat(U_ASCII_CP);
   
   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();
   install_mouse();

   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
      allegro_message("Error initialising sound\n%s\n", allegro_error);
      install_sound(DIGI_NONE, MIDI_NONE, NULL);
   }

   if (install_joystick(JOY_TYPE_AUTODETECT) != 0) {
      allegro_message("Error initialising joystick\n%s\n", allegro_error);
      install_joystick(JOY_TYPE_NONE);
   }

   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;
      }
   }

   get_executable_name(buf, sizeof(buf));
   replace_filename(buf2, buf, "demo.dat", sizeof(buf2));
   set_color_conversion(COLORCONV_NONE);
   data = load_datafile(buf2);
   if (!data) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s\n", buf2);
      exit(1);
   }

   if (!jumpstart) {
      intro_screen();
   }

   clear_bitmap(screen);
   set_gui_colors();
   set_mouse_sprite(NULL);

   if (!gfx_mode_select(&c, &w, &h))
      exit(1);

   if (pick_animation_type(&type) < 0)
      exit(1);

   init_display(c, w, h, type);

   generate_explosions();

   //stop_sample(data[INTRO_SPL].dat);

   clear_bitmap(screen);

   while (title_screen())
      play_game();

   destroy_display();

   destroy_explosions();

   stop_midi();

   set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);

   end_title();

   unload_datafile(data);

   allegro_exit();

   return 0;
}
Пример #22
0
void data_exit() {
	if (gData != NULL)
		unload_datafile(gData);
}