示例#1
0
/* Finds agup.cfg and add its contents to Allegro's current config. If agup.cfg
 * is found inside a datafile, the datafile is returned (and loaded if
 * necessary).
 */
static DATAFILE *
set_theme_config (char const *path, DATAFILE *datafile)
{
	DATAFILE *dat = NULL;

	if (path) {
		char *ext = get_extension (path);
		char str[1024 * 6];

		if (!strcmp (ext, "dat")) {
			dat = load_datafile (path);
			if (!dat)
				dat = datafile;
		}
		else if (!strcmp (ext, "cfg"))
			set_config_file (path);
		else {
			replace_extension (str, path, "dat", 1024 * 6);
			dat = load_datafile (str);
			if (!dat) {
				replace_extension (str, path, "cfg", 1024 * 6);
				set_config_file (str);
			}
		}
	}
	else
		dat = datafile;

	if (dat) {
		override_config_data (dat->dat, dat->size);
	}

	return dat;
}
示例#2
0
int main(int argc, char **argv)
{
   int i, nf;
   FILE *f;

   printf("RIEXPORT for ROMIDENT v2.1\nThierry Lescot, 1998/99.\n\n");

   load_datafile(argv[0]);

   printf("DAT file revision %d.\n", g_entry);

   f=fopen("ri_games.txt","w+");
   fprintf(f, "gnumber;name\n");
   for (i=0;i!=g_entry;i++) {
      fprintf(f, "%d;\"%s\"\n", i, gtab[i].title);
   };
   fclose(f);

   f=fopen("ri_roms.txt","w+");
   fprintf(f, "gnumber;name;crc32;size\n");
   for (i=0;i!=r_entry;i++) {
      fprintf(f, "%d;\"%s\";\"%08x\";%d\n", rtab[i].game, rtab[i].rom,
               rtab[i].crc32, rtab[i].size);
   };
   fclose(f);

   return unk;
}
示例#3
0
文件: player.c 项目: cmcnab/rityears
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 );
}
示例#4
0
文件: player.c 项目: cmcnab/rityears
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;
}
示例#5
0
int main(int argc, char **argv)
{
   int i, nf;

   printf("ROMIDENT v2.1\nThierry Lescot, 1998/99.\n\n");

   load_datafile(argv[0]);

   printf("DAT file revision %d.\n", g_entry);

   if (argc<2) {
      printf("Error, specify at least one file name !\n");
      return 1;
   };

   for (nf=1;nf<argc;nf++) {
      if (argv[nf][0] == '-') {
         switch(argv[nf][1]) {
            case '&':
               ident_crc(hex2int(&argv[nf][2]));
               break;
         };
      } else {
         if ((i = checkfile(argv[nf])) == -1) {
            printf("Error, '%s' doesn't exist !\n", argv[1]);
            return 1;
         };
         ident(argv[nf]);
      };
   };

   return unk;
}
bool LoadGlobalDatafile()
{
    erlog("Loading global datafile");
    global_datafile = load_datafile("glob.dat");
    if (!global_datafile) {
        erlog("Failed to load \"glob.dat\"", 3);
        return false;
    }
    erlog("Loaded");
    return true;
}
示例#7
0
文件: usp_talon.c 项目: msikma/ceegee
/**
 * Load the test sprite into memory.
 */
int load_usp_talon_dat() {
    if (USP_TALON_LOADED == TRUE) {
        return 0;
    }
    USP_TALON_DAT = load_datafile(USP_TALON_PATH);

    if (!USP_TALON_DAT) {
        return 1;
    }

    USP_TALON_LOADED = TRUE;
    return 0;
}
示例#8
0
static void
return_to_default(GtkWidget *widget, gpointer data)
{
  GtkListStore *model = (GtkListStore *)data;
  gchar *filename = get_user_desktop_file();
  /* Erase the user desktop file */
  gc_cache_remove(filename);
  g_free(filename);

  load_datafile();
  load_model_from_levels(model);

}
DATAFILE * Game_sys::LoadDatafile( char * filename ) // FUNCTION FOR EASY AND SAFE DATAFILE LOADING
{

        DATAFILE * result = load_datafile( filename );
        if( !result )
        {

            set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
            allegro_message( "Could not load datafile: %s", filename );
            exit( EXIT_FAILURE );

        }

        return result;
}
示例#10
0
FONT *load_font(char const *name, RGB *pal, void *param){
    FONT *f = al_calloc(1, sizeof *f);
    int len = strlen(name);
    if (len >= 4 && !strcmp(name + len - 4, ".dat")){
        DATAFILE *dat = load_datafile(name);
        FONT *df = dat->dat;
        f->data = df->data;
    }
    
    if (!f->is_color) {
       FONT *u = upgrade_to_color(f);
       *f = *u;
    }
    return f;
}
示例#11
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 */
示例#12
0
//Loads all sizes of lucida console from datfile to globaal array of fonts
int loadFonts(){
     DATAFILE *fontFile = NULL;
     fontFile = load_datafile("fonts.dat");
     
     if (fontFile == NULL)
        return 1;
     
     //Iterate through sizes
     for (int i = 0; i <= S20; i++){
         fonts[i] = (FONT*) fontFile[i].dat;
         
         if (fonts[i] == NULL)
            return 1;
     }
     
     return 0;
}
示例#13
0
文件: test.cpp 项目: stevenvi/lander
int main(int argc, char *argv[]) {
	printf("Initializing Allegro.\n");
	allegro_init();
	install_keyboard();
	install_timer();
	install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL);
	
	printf("Initializing DUMB.\n");
	atexit(&dumb_exit);
	dumb_register_dat_s3m_quick(DUMB_DAT_S3M);
	
	printf("Loading datafile.\n");
	DATAFILE *music = load_datafile("music.dat");
	if(!music) {
		printf("Error loading music datafile.\n");
		return 1;
	}
	
	
	printf("Loading DUH.\n");
	DUH *bgsong = (DUH*)music[0].dat;
	if(!bgsong) {
		printf("Error getting song from datafile.\n");
		return 1;
	}
	
	printf("Starting DUH player.\n");
	AL_DUH_PLAYER *bgsong_player = al_start_duh(bgsong, 2, 0, 1.0f, 4096, 48000);
	if(!bgsong_player) {
		printf("Error starting player.\n");
		return 1;
	}
	
	
	printf("Entering main loop.\n");
	while(!key[KEY_ESC]) {
		al_poll_duh(bgsong_player);
		rest(0);
	}
	
	printf("Exiting successfully.\n");
	return 0;
}
示例#14
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);
}
示例#15
0
文件: data.c 项目: dafyddcrosby/meka
//-----------------------------------------------------------------------------
// Data_Init (void)
// Load graphics, font & BIOS data from datafile
// Some data processing is done here
//-----------------------------------------------------------------------------
void            Data_Init(void)
{
    DATAFILE *  df;

    // Print loading message to console
    ConsolePrint (Msg_Get (MSG_Datafile_Loading));

    // Open and load datafile
    assert(g_Datafile == NULL);
    df = g_Datafile = load_datafile (g_Env.Paths.DataFile);
    if (g_Datafile == NULL)
        Quit_Msg (Msg_Get (MSG_Failed));
    ConsolePrint ("\n");

    // Make a copy of ALL bitmaps in their original RGBA 32-bits version
    // This is required to handle successives calls to fixup_datafile()
    g_DatafileBitmapCopy32 = NULL;

    // Assign pointers to data
	Data_UpdateNamedPointers();

    // BIOS
    // Note: BIOSes are unpacked in a bigger memory area, so they can be mapped
    // without having to handle memory accesses outside their allocated range.
    // The same trick is done on loading < 48 KB Sega 8-bits ROM images.
    BIOS_ROM            = Data_CopyInBiggerArea (df [DATA_ROM_SMS].dat,     0x2000, 0xC000);
    BIOS_ROM_Jap        = Data_CopyInBiggerArea (df [DATA_ROM_SMS_J].dat,   0x2000, 0xC000);
    BIOS_ROM_Coleco     = Data_CopyInBiggerArea (df [DATA_ROM_COLECO].dat,  0x2000, 0x2000);
    BIOS_ROM_SF7000     = Data_CopyInBiggerArea (df [DATA_ROM_SF7000].dat,  0x2000, 0x4000);

    // Patch SF-7000 BIOS (FIXME: move to sf7000.c)
    // Bios_ROM_SF7000[0x112] = Bios_ROM_SF7000[0x113] = Bios_ROM_SF7000[0x114] = 0x00;
    // Bios_ROM_SF7000[0x183] = Bios_ROM_SF7000[0x184] = Bios_ROM_SF7000[0x185] = 0x00;
    BIOS_ROM_SF7000[0x1D8] = BIOS_ROM_SF7000[0x1D9] = BIOS_ROM_SF7000[0x1DA] = 0x00;

    // Fonts
    Fonts_AddFont(F_LARGE,     df[DATA_FONT_0].dat);  // Font Large Sized
    Fonts_AddFont(F_MIDDLE,    df[DATA_FONT_1].dat);  // Font Middle Sized
    Fonts_AddFont(F_SMALL,     df[DATA_FONT_2].dat);  // Font Small Sized
}
示例#16
0
static void
locale_changed (GtkComboBox *combobox, gpointer data)
{
  const gchar *locale;
  GtkTreeIter iter;
  gchar *text = NULL;

  if (gtk_combo_box_get_active_iter (combobox, &iter))
    gtk_tree_model_get (gtk_combo_box_get_model (combobox), &iter,
			0, &text, -1);

  // Get back the locale from the locale name (French becomes fr_FR.UTF8)
  locale = gc_locale_get_locale( text );
  printf("LOCALE = %s\n", locale);

  gc_locale_set(locale);

  load_datafile();
  load_model_from_levels(model);

  // Our job is done, set back the default locale
  gc_locale_set( NULL );
}
示例#17
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;
}
示例#18
0
int CGame::SetupGame(char *argv[]) {

	int bpp = 32; //bits per pixel (truecolor)
	
	//buffers for filename manipulation
	char fullpath[255];
	char filename[10]; 

	int ret; //catches return values for processing
	int i;  //universal loop counter

	//initialise allegro stuff
	allegro_init(); 
	install_keyboard(); 
	install_mouse(); 
	install_timer();

	set_color_depth(bpp);
	
	/* Lets play the color depth game!  tries 32, 24, then 16 bit color modes */
	// set resolution to play intro movie
	ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
	/* did the video mode set properly? */
	if (ret != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);
		
		bpp = 24;
		set_color_depth(bpp);
		
		// set resolution
		ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
		/* did the video mode set properly? */
		if (ret != 0) {
			set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
			allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);

			bpp = 16;
			set_color_depth(bpp);

			// set resolution
			ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
			/* did the video mode set properly? */
			if (ret != 0) {
				set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
				allegro_message("Error setting %d bit graphics mode\n%s\nIm all out of options. Exiting", bpp, allegro_error);
				return 1;
			}
		}
	}
	
	// Load data from data.dat into memory
	textout_centre(screen,font,"NOW LOADING",SCREEN_W/2,SCREEN_H/2,makecol(255,255,255));

	sprintf(filename,"data.dat");
	replace_filename(fullpath, argv[0], filename, sizeof(fullpath));
    data = load_datafile(fullpath);
	if (!data) { 
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Cant load file %s for some reason.\nIt should be in the same directory as the .exe\n"
		"If you have deleted the debug directory to mark this then\ncopy all files from the \"required files\""
		"directory into the directory with the .exe\n\nThanks. Scarbble will now crash horribly", filename);
		return 1;
	}

	//make smaller copy of all tiles
	for (i=0;i<27;i++) {
		smalltiles[i] = create_bitmap(29,29);
		rotate_scaled_sprite(smalltiles[i], (WINDOWS_BITMAP *)data[i].dat, 0,0, 0, ftofix(0.8));
	}
		
	PlayIntro();

	AddPlayers();

	//stuff that cant be done in the players constructor
	InitialisePlayers();
	
	//set video mode to play game
	ret = set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0);
	/* did the video mode set properly? */
	if (ret != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error setting %d bit graphics mode\n%s\n", bpp, allegro_error);
		return 1;
	}
	
	//initialise the 'background' screen buffer
	background = create_bitmap(SCREEN_W, SCREEN_H);
	clear(background); //clear to black
	boardcolor = makecol(206,206,90);

	show_mouse(screen);
		
	return 0;
}
示例#19
0
int menu_play()
{
 	 DATAFILE *menu = load_datafile("data\\menu.dat");
 	 BITMAP *buffer = create_bitmap(640,480);
 	 BITMAP *mbuffer = create_bitmap(640,480);
 	 MIDI *inicio = load_midi("musics\\inicio.midi");
 	 font = (FONT *)menu[9].dat;
 	 
 	 int ret;
 	 
 	 CBotao Jogar;
 	 Jogar.Start();
 	 Jogar.img[NORMAL] = (BITMAP *)menu[2].dat;
	 Jogar.img[CIMA] = (BITMAP *)menu[3].dat;
	 Jogar.tx = 134;
  	 Jogar.ty = 30;

	 CBotao Opcoes;
	 Opcoes.Start();
	 Opcoes.img[NORMAL] = (BITMAP *)menu[4].dat;
	 Opcoes.img[CIMA] = (BITMAP *)menu[5].dat;
	 Opcoes.tx = 134;
	 Opcoes.ty = 30;
	
	 CBotao Sair;
	 Sair.Start();
	 Sair.img[NORMAL] = (BITMAP *)menu[6].dat;
	 Sair.img[CIMA] = (BITMAP *)menu[7].dat;
	 Sair.tx = 134;
	 Sair.ty = 30;

 	 
     blit((BITMAP *)menu[1].dat, buffer, 0, 0, 0, 0, 640, 480);
 	 draw_sprite(buffer, Jogar.img[NORMAL], 253, 274);
 	 draw_sprite(buffer, Opcoes.img[NORMAL], 253, 315);
 	 draw_sprite(buffer, Sair.img[NORMAL], 253, 356);
 	 
 	 
 	 play_fli("movie\\filme.flc", screen, 0 , check_escape_key);
 	 fade_in((BITMAP *)menu[10].dat, 10);
 	 play_fli("movie\\filme2.flc", screen, 0 , check_escape_key);
 	 fade_out(10);

 	 
 	 set_trans_blender(255, 255, 255, 75);
     draw_trans_sprite(buffer, (BITMAP*)menu[8].dat, 30, 480-323);

 	 fade_in(buffer, 10);
 	 play_midi(inicio, 100);
 	 
 	 while(!key[KEY_ESC])
 	 {
        rest(3);
        clear_bitmap(buffer);
        clear_to_color(mbuffer, makecol(255,0,255));

	    blit((BITMAP *)menu[1].dat, buffer, 0, 0, 0, 0, 640, 480);
	    
        if (!Jogar.Manage(buffer, 253, 274, mbuffer, "Clique aqui para Jogar"))
        {   
           ret = JOGAR;
		   break;
        }
		if (!Opcoes.Manage(buffer, 253, 315, mbuffer, "Opcoes de Jogo"))
		{
           ret = OPCOES;
		   break;
        }
		if (!Sair.Manage(buffer, 253, 356, mbuffer, "Sair do Jogo"))
		{
           ret = SAIR;
		   break;
        }
	    set_trans_blender(255, 255, 255, 70);
	    draw_trans_sprite(buffer, (BITMAP*)menu[8].dat, 30, 480-323);
	    
	    
	    draw_sprite(mbuffer, (BITMAP *)menu[0].dat, mouse_x, mouse_y);
	    
	    //textprintf_ex(buffer, font, 10, 10, makecol(0,0,0),-1, "FPS: %d", fps); 	 	 	   
	    set_trans_blender(255, 255, 255, 150);
	    draw_trans_sprite(buffer, mbuffer, 0, 0);
	    blit(buffer, screen, 0, 0, 0, 0, 640, 480);
	 }
	 fade_out(10);
	 //destroy_bitmap(mbuffer);
	 Jogar.Destroy();
	 Opcoes.Destroy();
	 Sair.Destroy();
	 destroy_bitmap(buffer);
	 
	 return ret;
}
示例#20
0
void initialize()
{
    char buf[1024];
    int i;

    // Do the libxml binary compatibility check
    initXML();

    // Initialise Allegro
    allegro_init();
    install_keyboard();
    install_mouse();
    install_timer();

    set_config_file("rpgedit.cfg");
    int grph_drv = (get_config_int("video", "fullscreen", 1)) ?
        GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED;
    int screen_w = get_config_int("video", "width", 800);
    int screen_h = get_config_int("video", "height", 600);

    if (get_config_int("tile_zoom", "grid", 1)) {
        showTileGrid = true;
    }

    set_color_conversion(
            (COLORCONV_TOTAL &
             ~(
                 COLORCONV_32A_TO_8  |
                 COLORCONV_32A_TO_15 |
                 COLORCONV_32A_TO_16 |
                 COLORCONV_32A_TO_24
              ))
            );

    int colordepth = 0;
    if (grph_drv == GFX_AUTODETECT_WINDOWED) {
        colordepth = desktop_color_depth();
    }
    if (colordepth == 0) {
        colordepth = 16;
    }
    set_color_depth(colordepth);

    if (set_gfx_mode(grph_drv, screen_w, screen_h, 0, 0) != 0) {
        set_color_depth(15);
        if (set_gfx_mode(grph_drv, screen_w, screen_h, 0, 0) != 0) {
            set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
            allegro_message("Unable to set graphic mode\n%s\n", allegro_error);
            exit(1);
        }
    }

    buffer = create_bitmap(SCREEN_W, SCREEN_H);


    // Initialize GUI look and feel stuff
    agup_init(aphoton_theme);
    gui_fg_color = agup_fg_color;
    gui_bg_color = agup_bg_color;
    gui_shadow_box_proc = d_agup_shadow_box_proc;
    gui_button_proc = d_agup_button_proc;
    gui_edit_proc = d_agup_edit_proc;
    gui_text_list_proc = d_agup_text_list_proc;

    engine_data = load_datafile("gui.dat");

    DATAFILE* font_data = find_datafile_object(engine_data, "SmallFont");
    if (font_data) font = (FONT*)font_data->dat;

    engine_font = font;

    DATAFILE* mouse_pointer = find_datafile_object(engine_data, "_MS_STD_BMP");
    if (mouse_pointer) set_mouse_sprite((BITMAP*)mouse_pointer->dat);

    DATAFILE* logo = find_datafile_object(engine_data, "MoonlightLogo");
    if (logo) about_dlg[1].dp = (BITMAP*)logo->dat;
    else console.log(CON_QUIT, CON_ALWAYS, "Error loading MoonlightLogo");

    console.log(CON_LOG, CON_ALWAYS, "Loading module \"data\"...");
    module = new Module("data");

    // Lua initialisation
    console.log(CON_LOG, CON_ALWAYS, "Initialising scripting environment...");
    initScripting();

    D_AUTOTEXT_STATUS.dp2 = status_message;
    D_AUTOTEXT_MAPINFO.dp2 = status_mapinfo;

    set_dialog_color(main_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(newmap_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(import_tileset_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(export_tileset_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(resizemap_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(about_dlg, agup_fg_color, agup_bg_color);


    // Position the dialogs on the screen
    int margin = 6;
    int zoom_w = get_config_int("tile_zoom", "zoom_width", 120) - 1;
    int zoom_h = get_config_int("tile_zoom", "zoom_height", 120) - 1;
    int x, y, w, h;

    // Main (back + menu)
    set_dialog_size(&main_dlg[0],          -2,                -2,              SCREEN_W + 4,          SCREEN_H + 4);
    set_dialog_size(&main_dlg[1],          0,                 0,               SCREEN_W,              15);

    // Status bars
    set_dialog_size(&main_dlg[6],          0,                 SCREEN_H - 17,   SCREEN_W - 256,        17);
    set_dialog_size(&main_dlg[7],          SCREEN_W - 256,    SCREEN_H - 17,   256,                   17);
    set_dialog_size(&main_dlg[8],          3,                 SCREEN_H - 14,   SCREEN_W - 262,        11);
    set_dialog_size(&main_dlg[9],          SCREEN_W - 253,    SCREEN_H - 14,   250,                   11);

    // Edit tile area
    w = zoom_w + 4;
    h = zoom_h + 4;
    x = margin;
    y = main_dlg[6].y - margin - h;
    set_dialog_size(&edit_tile_layer[0],   x,                 y,               w,                     h);
    set_dialog_size(&edit_tile_layer[1],   x + 2,             y + 2,           w - 4,                 h - 4);
    set_dialog_size(&edit_tile_layer[2],   x + margin + w,    y + h - 14,      50,                    14);

    // Color sliders
    x += w + margin;
    w = 128;
    set_dialog_size(&edit_tile_layer[8],   x,                 y,               16,                    8);
    set_dialog_size(&edit_tile_layer[9],   x,                 y + 16,          16,                    8);
    set_dialog_size(&edit_tile_layer[10],  x,                 y + 32,          16,                    8);
    set_dialog_size(&edit_tile_layer[11],  x,                 y + 48 + 8,      16,                    8);
    set_dialog_size(&edit_tile_layer[12],  x,                 y + 64 + 8,      16,                    8);
    set_dialog_size(&edit_tile_layer[3],   x + 16,            y,               w,                     8);
    set_dialog_size(&edit_tile_layer[4],   x + 16,            y + 16,          w,                     8);
    set_dialog_size(&edit_tile_layer[5],   x + 16,            y + 32,          w,                     8);
    set_dialog_size(&edit_tile_layer[6],   x + 16,            y + 48 + 8,      w,                     8);
    set_dialog_size(&edit_tile_layer[7],   x + 16,            y + 64 + 8,      w,                     8);
    set_dialog_size(&edit_tile_layer[13],  x + 16 + w + 4,    y - 1,           11,                    10);
    set_dialog_size(&edit_tile_layer[14],  x + 16 + w + 4,    y + 16 - 1,      11,                    10);
    set_dialog_size(&edit_tile_layer[15],  x + 16 + w + 4,    y + 32 - 1,      11,                    10);
    set_dialog_size(&edit_tile_layer[20],  x + 16 + w + 18,   y + 4,           18,                    32);

    // Select tile area
    x = edit_tile_layer[20].x + edit_tile_layer[20].w + margin;
    w = SCREEN_W - x - margin;
    set_dialog_size(&edit_tile_layer[16],  x,                 y,               104,                   h);
    set_dialog_size(&edit_tile_layer[17],  x + 104,           y,               w - 104,               h);
    set_dialog_size(&edit_tile_layer[18],  x + 104 + 2,       y + 2,           w - 104 - 4 - 11,      h - 4);
    set_dialog_size(&edit_tile_layer[19],  x + w - 14,        y,               14,                    h);

    // Obstacle edit stuff
    w = 24;
    h = 24;
    x = margin;
    y = main_dlg[6].y - margin - h;
    for (i = 0; i < 5; i++) {
        set_dialog_size(&edit_obstacle_layer[i],   x + i*(w+margin),     y,     w,     h);
        set_dialog_size(&edit_obstacle_layer[i+5], x + i*(w+margin) + 2, y + 2, w - 4, h - 4);
    }

    // Edit map area
    x = margin;
    y = 16 + margin;
    w = SCREEN_W - 2 * margin;
    h = edit_obstacle_layer[0].y - margin - y;
    set_dialog_size(&main_dlg[2],          x,                 y,               w,                     h);
    set_dialog_size(&main_dlg[3],          x + 2,             y + 2,           w - 15,                h - 15);
    set_dialog_size(&main_dlg[4],          x + w - 14,        y,               14,                    h - 11);
    set_dialog_size(&main_dlg[5],          x,                 y + h - 14,      w - 11,                14);
    set_dialog_size(&main_dlg[10],         x + w - 12,        y + h - 12,      10,                    10);

    // Edit objects area
    w = 160;
    h = 120;
    x = margin;
    y = main_dlg[6].y - margin - h;
    set_dialog_size(&edit_objects_layer[0], x,                y,               w,                     h);
    set_dialog_size(&edit_objects_layer[1], w + margin * 2, main_dlg[6].y - margin - 14,  97,                    14);


    // Initialize map and tile stuff
    tileRepository = new TileRepository();

    // Import tilesets specified in rpgedit.cfg
    i = 1;
    while (i > 0) 
    {
        uszprintf(buf, sizeof buf, "tileset%d", i);

        const char* filename = get_config_string(buf, "filename", NULL);
        int tile_w = get_config_int(buf, "tile_w", 16);
        int tile_h = get_config_int(buf, "tile_h", 16);
        int tile_spacing = get_config_int(buf, "tile_spacing", 0);

        if (filename) {
            if (tile_w > 0 && tile_h > 0 && tile_spacing >= 0) {
                import_tile_bitmap(filename, tile_w, tile_h, tile_spacing);
            } else {
                allegro_message("Error, incorrect parameters for automatic tile import (%s)!", filename);
                // Print warning in log file
            }
            i++;
        } else  {
            i = -1;
        }
    }

    currentMap = new SquareMap(TILES_W, TILES_H);
    ustrcpy(map_filename, "untitled.tmx");

    // Load map specified in rpgedit.cfg
    const char* filename = get_config_string("startup", "load_map", NULL);
    if (filename) {
        if (!currentMap->loadMap(filename)) {
            ustrcpy(map_filename, filename);
            object_message(&D_MAP, MSG_NEW_MAP, 0);
            set_map_changed(false);
        } else {
            console.log(CON_LOG, CON_ALWAYS,
                    "Error while loading default map (%s)!\n", filename);
        }
    }

    update_window_title();

    map_edit_mode = EM_TILE;
    menu_item_edit_objects();
    //activate_mode(edit_objects_layer);
}
示例#21
0
int main(int argc, char **argv) {
	int ret;
	char strbuf[256];
	
	allegro_init();
	
	set_color_depth(24);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Allegro says: %s\n", allegro_error);
		return 1;
	}

	install_timer();
	install_keyboard();
	install_mouse();
	if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL)==-1) printf("No sounds avaible.\n");
	graph_init();

	srand(time(0));

	set_keyboard_rate(100, 150);
	gui_bg_color = colors[gray];
	gui_fg_color = colors[black];

	LOCK_VARIABLE(counter);
	LOCK_FUNCTION(game_timer);
	install_int_ex(game_timer, BPS_TO_TIMER(6));
	
	if (argv[0][0]!='\0') {
		char *path;

		for (path=argv[0]; *path; path++) /* nothing */;
		if (path!=argv[0]) {
			for (;*path!='/' && path>=argv[0]; path--);
			path++;
			*path = '\0';
			chdir(argv[0]);
		}
	}
	
	if ((datafile = load_datafile("data.dat"))==NULL) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Datafile data.dat not found\n");
		return 1;
	}
	
	font = datafile[DATA_FONT].dat;
	gui_font_baseline = 1;

	main_dialog[0].bg = colors[darkgray];
	main_dialog[1].dp = datafile[DATA_SCREEN].dat;
	main_dialog[2].dp = datafile[DATA_LOGO].dat;

	for (ret=1; main_dialog[ret].proc; ret++) {
		main_dialog[ret].fg = colors[black];
		main_dialog[ret].bg = colors[gray];
	}
	
	while(1) {
		text_mode(-1);

		switch (do_dialog(main_dialog, -1)) {
		case DMAIN_START:
			ret = start_game();
		
			if (ret==GAME_ABORT) break;

			if (ret==GAME_END) {
				int i;
				ret=0;
				for (i=1; i<8; i++) if (players[i].points > players[ret].points) ret = i;
			}
			scare_mouse();
			clear_to_color(screen, colors[darkgray]);
			unscare_mouse();

			sprintf(strbuf, "The winner is %s!!!", players[ret].name);
			alert("GAME OVER", strbuf, NULL, "OK", NULL, 0, 0);

			report();
			break;
		case DMAIN_EDIT:
			start_editor();
			break;
		case DMAIN_EXIT:
			remove_sound();
			return 0;
		}
	}
	return 0;
}
示例#22
0
static void start_board (GcomprisBoard *agcomprisBoard)
{
  GHashTable *config = gc_db_get_board_conf();
  guint ready;

  board_paused = TRUE;

  gc_locale_set(g_hash_table_lookup( config, "locale_sound"));

  g_hash_table_destroy(config);

  ready = sounds_are_fine();

  gc_sound_bg_pause();

  if (agcomprisBoard!=NULL)
    {
      gcomprisBoard=agcomprisBoard;

      if ( gcomprisBoard->mode && g_ascii_strcasecmp(gcomprisBoard->mode, "uppercase")==0 )
	uppercase_only = TRUE;
      else
	uppercase_only = FALSE;

      gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas),
			      "click_on_letter/background.svgz");

      gc_score_start(SCORESTYLE_NOTE,
		     50,
		     50,
		     0);

      load_datafile();

      gcomprisBoard->level=1;
      gcomprisBoard->sublevel=1;

      carriage_svg_handle = gc_rsvg_load("click_on_letter/carriage.svgz");
      rsvg_handle_get_dimensions (carriage_svg_handle, &carriage_svg_dimension);

      cloud_svg_handle = gc_rsvg_load("click_on_letter/cloud.svgz");
      rsvg_handle_get_dimensions (cloud_svg_handle, &cloud_svg_dimension);

      if(ready)
	{
	  if(ready == OK)
	    click_on_letter_next_level();

	  gamewon = FALSE;
	  pause_board(FALSE);
	}

      RsvgHandle *svg_handle;
      svg_handle = gc_rsvg_load("click_on_letter/repeat.svg");
      if(svg_handle) {
	gc_bar_set_repeat_icon(svg_handle);
	g_object_unref(svg_handle);
	gc_bar_set(GC_BAR_CONFIG|GC_BAR_LEVEL|GC_BAR_REPEAT_ICON);
      } else {
	gc_bar_set(GC_BAR_CONFIG|GC_BAR_LEVEL|GC_BAR_REPEAT);
      }
      gc_bar_location(BOARDWIDTH-300, 5, 0.7);

    }

}
示例#23
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;
}
示例#24
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;
}
示例#25
0
static void init()
{
   char temp_buf[256];

   is_not_genuine_scan_tool = FALSE;
   
   /* initialize some varaibles with default values */
   strcpy(options_file_name, "scantool.cfg");
   strcpy(data_file_name, "scantool.dat");
   strcpy(code_defs_file_name, "codes.dat");
   
   datafile = NULL;
   comport.status = NOT_OPEN;
   display_mode = 0;

   set_uformat(U_ASCII);
   
   /* initialize hardware */
   write_log("\nInitializing Allegro... ");
   allegro_init();
   write_log("OK");
   
   set_window_title(WINDOW_TITLE);
   
   write_log("\nInstalling Timers... ");
   if (install_timer() != 0)
   {
      write_log("Error!");
      fatal_error("Error installing timers");
   }
   write_log("OK");
   write_log("\nInstalling Keyboard... ");
   install_keyboard();
   write_log("OK");
   write_log("\nInstalling Mouse... ");
   install_mouse();
   write_log("OK");

   /* load options from file, the defaults will be automatically substituted if file does not exist */
   write_log("\nLoading Preferences... ");
   set_config_file(options_file_name);
   /* if config file doesn't exist or is of an incorrect version */
   if (strcmp(get_config_string(NULL, "version", ""), SCANTOOL_VERSION_STR) != 0)
   {
      /* update config file */
      remove(options_file_name);
      set_config_file(options_file_name);
      set_config_string(NULL, "version", SCANTOOL_VERSION_STR);
      load_program_options();  // Load defaults
      save_program_options();
   }
   else
      load_program_options();
   write_log("OK");

   display_mode |= FULLSCREEN_MODE_SUPPORTED;
   
   write_log("\nTrying Windowed Graphics Mode... ");
   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) == 0)
   {
      display_mode |= WINDOWED_MODE_SUPPORTED;
      write_log("OK");
   }
   else
   {
      display_mode &= ~(WINDOWED_MODE_SUPPORTED | WINDOWED_MODE_SET);
      write_log(allegro_error);
   }

   if (!(display_mode & WINDOWED_MODE_SET))
   {
      write_log("\nTrying Full Screen Graphics Mode... ");
      if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) == 0)
      {
         display_mode |= FULLSCREEN_MODE_SUPPORTED;
         write_log("OK");
      }
      else
      {
         display_mode &= ~FULLSCREEN_MODE_SUPPORTED;
         write_log(allegro_error);
      }
   }
   
   if (!(display_mode & (FULLSCREEN_MODE_SUPPORTED | WINDOWED_MODE_SUPPORTED)))
      fatal_error(allegro_error);
   else if ((display_mode & WINDOWED_MODE_SUPPORTED) && !(display_mode & FULLSCREEN_MODE_SUPPORTED))
   {
      set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
      display_mode &= WINDOWED_MODE_SET;
   }
   
   write_log("\nLoading Data File... ");
   packfile_password(PASSWORD);
   datafile = load_datafile(data_file_name);
   packfile_password(NULL);
   if (datafile == NULL)
   {
      sprintf(temp_buf, "Error loading %s!", data_file_name);
      write_log(temp_buf);
      fatal_error(temp_buf);
   }
   write_log("OK");

   set_pallete(datafile[MAIN_PALETTE].dat);
   font = datafile[ARIAL12_FONT].dat;
   gui_fg_color = C_BLACK;  // set the foreground color
   gui_bg_color = C_WHITE;  // set the background color
   gui_mg_color = C_GRAY;   // set the disabled color
   set_mouse_sprite(NULL); // make mouse use current palette

   write_log("\nInitializing Serial Module... ");
   serial_module_init();
   write_log("OK");

   sprintf(temp_buf, "\nOpening COM%i... ", comport.number + 1);
   write_log(temp_buf);
   /* try opening comport (comport.status will be set) */
   open_comport();
   switch (comport.status)
   {
      case READY:
         write_log("OK");
         break;

      case NOT_OPEN:
         write_log("Error!");
         break;
         
      default:
         write_log("Unknown Status");
         break;
   }
}
示例#26
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;
}
示例#27
0
/***
  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;
}
示例#28
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;
}
示例#29
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;
}
示例#30
0
int main()
{
    init(); // inicializa

/*  #######################################################################################
                    declaração das variáveis (e algumas inicializações)
    #######################################################################################
*/
    int i,j; // controladores de loops e auxiliares
    int ticks; // controla velocidade do jogo
    int tempo_de_jogo=0; // controla o tempo de jogo
    int matriz_tela[ALTURA_MAPA/32][LARGURA_MAPA/32]; // matriz da tela
    int ajuste_mapa = 0; // variavel que cuida do movimento do mapa e dos objetos nele
    int tela = 0, selecionar = 0; //controla o carregamento de cada tela
    int tela_destino=1; // determina qual tela será carregada após a tela de carregamento
    int fase=1;
    int carrega_fase=1;
    char nome_fase[N_FASES][10]={"mapa1.txt","mapa2.txt","mapa3.txt"};
    int loading_time = 0;
    int estagio_loading=0;
    int bloqueios[3] = {TERRA, PEDRA, CHAO};
    int pause = 0;
    int tocando=0;
    int tocando_game_over=0;
    int tutorial=1;

    // abrindo os datafiles
    DATAFILE* graficos = NULL;
    DATAFILE* musicas = NULL;
    DATAFILE* efeitos = NULL;
    DATAFILE* fontes = NULL;

    packfile_password("kill");

    graficos = load_datafile("imagens.dat");
    musicas = load_datafile("musicas.dat");
    efeitos = load_datafile("efeitos.dat");
    fontes = load_datafile("fontes.dat");

    packfile_password(NULL);

    // variáveis de objetos
    Tjanelas janelas;
    Tcriatura guerreiro; // declara objeto guerreiro
    Toponentes inimigos;
    Titens itens;
    Teventos eventos;

    // declara BITMAPS
    BITMAP *buffer = create_bitmap(SCREEN_W,SCREEN_H); // Cria o buffer;
    BITMAP *mapa = create_bitmap(LARGURA_MAPA,ALTURA_MAPA); // Cria o mapa
    BITMAP *texturas[MAX_TERRENOS]; // declara a array de texturas
    BITMAP *background = create_bitmap(960,480);

    //BITMAPs do Menu
    BITMAP *menu_iniciar = (BITMAP*) graficos[MENU_1].dat;//menu iniciar
    BITMAP *menu_creditos = (BITMAP*) graficos[MENU_3].dat;
    BITMAP *menu_options = (BITMAP*) graficos[MENU_2].dat;//menu opções
    BITMAP *menu_exit = (BITMAP*) graficos[MENU_4].dat;//menu saída

    BITMAP *logo = (BITMAP*) graficos[LOGO_1].dat;

    // BITMAPS da tela de carregamento
    BITMAP *tela_loading[4];
    tela_loading[0] = (BITMAP*) graficos[CARREGAR_1].dat;
    tela_loading[1] = (BITMAP*) graficos[CARREGAR_2].dat;
    tela_loading[2] = (BITMAP*) graficos[CARREGAR_3].dat;
    tela_loading[3] = (BITMAP*) graficos[CARREGAR_4].dat;

    // Declara fontes
    FONT* corpo_texto = (FONT*) fontes[CORPO_TEXTO].dat;
    FONT* titulo_texto = (FONT*) fontes[TITULO_TEXTO].dat;

    // Declara sons
    MIDI* musica_floresta = (MIDI*) musicas[MUSICA_FLORESTA].dat;
    MIDI* musica_caverna = (MIDI*) musicas[MUSICA_CAVERNA].dat;
    MIDI* musica_chefe1 = (MIDI*) musicas[MUSICA_CHEFE_1].dat;
    MIDI* musica_chefe2 = (MIDI*) musicas[MUSICA_CHEFE_2].dat;
    MIDI* musica_chefe3 = (MIDI*) musicas[MUSICA_CHEFE_3].dat;
    MIDI* musica_menu = (MIDI*) musicas[MUSICA_MENU].dat;
    MIDI* musica_gameover = (MIDI*) musicas[MUSICA_GAMEOVER].dat;

    SAMPLE* selecao = (SAMPLE*) efeitos[SELECIONAR].dat;
    SAMPLE* confirmar = (SAMPLE*) efeitos[CONFIRMAR].dat;
    SAMPLE* espada = (SAMPLE*) efeitos[ESPADA].dat;
    SAMPLE* besta = (SAMPLE*) efeitos[BESTA].dat;
    SAMPLE* som_pause = (SAMPLE*) efeitos[PAUSE].dat;
    SAMPLE* som_dano_goblin = (SAMPLE*) efeitos[DANO_GOBLIN].dat;
    SAMPLE* som_dano_guerreiro = (SAMPLE*) efeitos[DANO_HEROI].dat;
    SAMPLE* som_cura = (SAMPLE*) efeitos[CURA].dat;
    SAMPLE* som_vinhas = (SAMPLE*) efeitos[PARALISIA].dat;
    SAMPLE* som_recuo = (SAMPLE*) efeitos[RECUO].dat;

    volume=250;
    set_volume(volume,volume);

/*  #######################################################################################
                                fim da declaração das variáveis
    #######################################################################################
*/

    // configura saída com o botão x no alto da tela
    exit_program = FALSE;
    LOCK_FUNCTION(fecha_programa);
    LOCK_VARIABLE(exit_program);
    set_close_button_callback(fecha_programa); // fecha a qualquer momento com o botão fechar

    // timer
    timer=0;
    LOCK_FUNCTION(incrementa_timer);
    LOCK_VARIABLE(timer);
    install_int_ex(incrementa_timer,BPS_TO_TIMER(60)); // para que o jogo execute 60 vezes por segundo

    ticks = timer; // velocidade do jogo

    // Processo de repetição principal
    while (!exit_program)
    {
        // loop válido, executado 60 vezes por segundo
        while(ticks<=timer && !exit_program)
        {
            // tela de menu
            if(tela==0)
            {
                clear_bitmap(buffer);
                keyboard_input();
                menu_inicial(buffer, &selecionar, menu_iniciar, menu_options, menu_exit,menu_creditos,&loading_time, &tela,
                             &estagio_loading,&tela_destino,&fase,&carrega_fase,&tempo_de_jogo,selecao,confirmar,&tocando,
                             musica_menu);
            }

            // tela de loading
            else if (tela == 9)
            {
                clear_bitmap(buffer);
                tela_carregamento(buffer, tela_loading, &loading_time,tela_destino, &tela,logo);
                carrega_elementos_fase(&carrega_fase,&estagio_loading,matriz_tela,nome_fase,fase,&itens,&guerreiro,&inimigos,
                                       &janelas,background,texturas,&eventos,mapa,graficos);
            }

            // tela de jogo
            else if(tela==1)
            {
                // toca a musica da fase se não estiver tocando
                tocar(&tocando,fase,musica_floresta,musica_caverna);

                // atualiza estado do teclado
                keyboard_input();

                pausar(&pause,&selecionar,som_pause); // verifica se pressionou pause

                // limpa bitmaps de armazenamento
                clear_bitmap(buffer); // Limpa o buffer;
                clear_bitmap(guerreiro.sprite); // Limpa bitmap guerreiro
                clear_bitmap(inimigos.goblins_guerreiros.goblins[0].sprite); // Limpa bitmap goblin tipo 1
                clear_bitmap(inimigos.goblins_guerreiros.goblins[1].sprite); // Limpa bitmap goblin tipo 1

                if (!pause) // pause pode travar toda a lógica e tempo de jogo, exceto os eventos
                {
                    // incrementa o tempo de jogo
                    tempo_de_jogo++;

                    // Lógica do jogo
                    tocou_oponente(&guerreiro,&inimigos,tempo_de_jogo,som_dano_guerreiro);
                    verificar_status(&guerreiro,&inimigos,tempo_de_jogo,&itens);
                    movimento_guerreiro(&guerreiro,matriz_tela, bloqueios,som_recuo);
                    ataque_guerreiro(&guerreiro,tempo_de_jogo,&inimigos,espada,som_dano_goblin);

                    calcular_ajuste_mapa(&guerreiro,&ajuste_mapa);
                    acoes_goblins(&inimigos,&guerreiro,tempo_de_jogo,matriz_tela,bloqueios,&itens,espada,besta,som_dano_guerreiro,
                                  som_vinhas);
                    verifique_efeito_item(&itens,&guerreiro,&inimigos,tempo_de_jogo,som_dano_guerreiro,som_cura);
                    movimento_itens(&itens,&guerreiro,tempo_de_jogo,matriz_tela,bloqueios);
                }

                verificar_evento(&pause,fase,&eventos,&guerreiro,&janelas,matriz_tela,bloqueios,&ajuste_mapa,musica_chefe1,
                                 musica_chefe2,musica_chefe3,confirmar);

                // Desenhar
                draw_sprite(buffer,background,ajuste_mapa/10,0);
                draw_sprite(buffer, mapa, ajuste_mapa, 0); // manda mapa para o buffer na posição mov_mapa
                desenhar_todos_goblins(&inimigos,buffer,ajuste_mapa,tempo_de_jogo);
                desenhar_guerreiro(buffer,&guerreiro,&inimigos,ajuste_mapa,tempo_de_jogo,graficos); // desenha guerreiro e manda para buffer
                desenhar_itens(buffer,&itens,ajuste_mapa);
                desenhos_evento(buffer,fase,&eventos,&janelas,&guerreiro,corpo_texto,titulo_texto,&inimigos);

                pause_menu(&pause,&eventos,buffer,&selecionar,&tela,tempo_de_jogo,&tela_destino,&loading_time,
                           selecao,confirmar,&tocando);
                game_over(&pause,&eventos,buffer,&selecionar,&tela,tempo_de_jogo,&tela_destino,&loading_time,selecao,confirmar,
                          &tocando,musica_gameover,&guerreiro,&estagio_loading,&tocando_game_over,&carrega_fase,graficos);

                // se inicio da fase, coloca um efeito de opacidade
                efeito_inicio_fase(&eventos,&pause,buffer,graficos,confirmar,fase,&tutorial);

                // nova fase?
                verifica_nova_fase(&guerreiro,&fase,&carrega_fase,&tela,&loading_time,&estagio_loading,&tela_destino,
                                   &inimigos.chefes,&eventos,&tocando,&pause,buffer);

                blit(buffer,screen,0,0,0,0,LARGURA_SCREEN,ALTURA_SCREEN); // Manda o buffer para a tela;


            }
            // tela de opçções
            else if(tela==2)
            {
                clear_bitmap(buffer);
                keyboard_input();

                menu_opcoes(buffer,graficos,selecao,confirmar,&tela);
            }
            // tela de créditos
            else if(tela==3)
            {
                clear_bitmap(buffer);
                keyboard_input();

                creditos(buffer,graficos,confirmar,&tela);
            }
            else if(tela==4)
            {
                clear_bitmap(buffer);
                keyboard_input();

                final_de_jogo(buffer,graficos,&tela,confirmar);
            }
            ticks++; // incrementa controle de velocidade do jogo
        }
    }

    deinit(); // finaliza

    // destruição de bitmaps

    destroy_bitmap(buffer);
    destroy_bitmap(mapa);
    destroy_bitmap(background);

    for(i=0;i<MAX_TERRENOS;i++)
        destroy_bitmap(texturas[i]);

    destroy_bitmap(guerreiro.sprite);
    for(i=0;i<8;i++)
        destroy_bitmap(guerreiro.vetor_sprite[i]);
    for(i=0;i<10;i++)
        destroy_bitmap(guerreiro.barraHp[i]);

    for(i=0;i<8;i++)
    {
        for(j=0;j<6;j++)
            destroy_bitmap(inimigos.goblins_guerreiros.goblins[j].vetor_sprite[i]);
        if(i!=7)
        {
            for(j=0;j<6;j++)
                destroy_bitmap(inimigos.goblins_arqueiros.goblins[j].vetor_sprite[i]);
        }
        destroy_bitmap(inimigos.chefes.chefe[0].vetor_sprite[i]);
    }

    for(i=0;i<6;i++)
    {
        destroy_bitmap(inimigos.goblins_guerreiros.goblins[i].sprite);
        destroy_bitmap(inimigos.goblins_arqueiros.goblins[i].sprite);
    }
    destroy_bitmap(inimigos.chefes.chefe[0].sprite);

    for(i=0;i<8;i++)
    {
        destroy_bitmap(itens.todosItens[i].imagem);
        destroy_bitmap(itens.todosItens[i].imagem_buffer);
    }

    return 0 ;
}