Пример #1
0
int main(int argc, char *argv[])
{
   ALLEGRO_CONFIG *config;
   ALLEGRO_EVENT event;
   unsigned buffer_count;
   unsigned samples;
   const char *s;
   ALLEGRO_PLAYMODE playmode = ALLEGRO_PLAYMODE_LOOP;

   initialize();

   if (argc > 1) {
      stream_filename = argv[1];
   }

   buffer_count = 0;
   samples = 0;
   config = al_load_config_file("ex_stream_seek.cfg");
   if (config) {
      if ((s = al_get_config_value(config, "", "buffer_count"))) {
         buffer_count = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "samples"))) {
         samples = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "playmode"))) {
         if (!strcmp(s, "loop")) {
            playmode = ALLEGRO_PLAYMODE_LOOP;
         }
         else if (!strcmp(s, "once")) {
            playmode = ALLEGRO_PLAYMODE_ONCE;
         }
      }
      al_destroy_config(config);
   }
   if (buffer_count == 0) {
      buffer_count = 4;
   }
   if (samples == 0) {
      samples = 1024;
   }

   music_stream = al_load_audio_stream(stream_filename, buffer_count, samples);
   if (!music_stream) {
      abort_example("Stream error!\n");
   }
   al_register_event_source(queue, al_get_audio_stream_event_source(music_stream));

   loop_start = 0.0;
   loop_end = al_get_audio_stream_length_secs(music_stream);
   al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);

   al_set_audio_stream_playmode(music_stream, playmode);
   al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer());
   al_start_timer(timer);

   while (!exiting) {
      al_wait_for_event(queue, &event);
      event_handler(&event);
   }

   myexit();
   al_destroy_display(display);
   close_log(true);
   return 0;
}
/* Creates the default voice and mixer if they haven't been created yet. */
static bool create_default_mixer(void)
{
   int voice_frequency = 44100;
   int voice_depth = ALLEGRO_AUDIO_DEPTH_INT16;
   int mixer_frequency = 44100;
   int mixer_depth = ALLEGRO_AUDIO_DEPTH_FLOAT32;

   ALLEGRO_CONFIG *config = al_get_system_config();
   if (config) {
      const char *p;
      p = al_get_config_value(config, "audio", "primary_voice_frequency");
      if (p && p[0] != '\0') {
         voice_frequency = atoi(p);
      }
      p = al_get_config_value(config, "audio", "primary_mixer_frequency");
      if (p && p[0] != '\0') {
         mixer_frequency = atoi(p);
      }
      p = al_get_config_value(config, "audio", "primary_voice_depth");
      if (p && p[0] != '\0') {
         voice_depth = string_to_depth(p);
      }
      p = al_get_config_value(config, "audio", "primary_mixer_depth");
      if (p && p[0] != '\0') {
         mixer_depth = string_to_depth(p);
      }
   }

   if (!allegro_voice) {
      allegro_voice = al_create_voice(voice_frequency, voice_depth,
         ALLEGRO_CHANNEL_CONF_2);
      if (!allegro_voice) {
         ALLEGRO_ERROR("al_create_voice failed\n");
         goto Error;
      }
   }

   if (!allegro_mixer) {
      allegro_mixer = al_create_mixer(mixer_frequency, mixer_depth,
         ALLEGRO_CHANNEL_CONF_2);
      if (!allegro_mixer) {
         ALLEGRO_ERROR("al_create_voice failed\n");
         goto Error;
      }
   }

   if (!al_attach_mixer_to_voice(allegro_mixer, allegro_voice)) {
      ALLEGRO_ERROR("al_attach_mixer_to_voice failed\n");
      goto Error;
   }

   return true;

Error:

   if (allegro_mixer) {
      al_destroy_mixer(allegro_mixer);
      allegro_mixer = NULL;
   }

   if (allegro_voice) {
      al_destroy_voice(allegro_voice);
      allegro_voice = NULL;
   }

   return false;
}
Пример #3
0
bool initialize(int argc, char * argv[])
{
	const char * val;
	ALLEGRO_BITMAP * bp;
	
	process_arguments(argc, argv);
	if(!t3f_initialize(640, 480, 60.0, "The Devil", logic, render, T3F_DEFAULT | T3F_USE_MOUSE))
	{
		return false;
	}
	t3f_3d_set_projection(&projection, 0, 0, 640, 480, 320, 240);
	t3f_3d_select_projection(&projection);
	animation[ANIMATION_PLAYER] = t3f_load_animation_from_bitmap("data/player.png");
	if(!animation[ANIMATION_PLAYER])
	{
		return false;
	}
	animation[ANIMATION_DEMON] = t3f_load_animation_from_bitmap("data/demon.png");
	if(!animation[ANIMATION_DEMON])
	{
		return false;
	}
	animation[ANIMATION_ARCHDEMON] = t3f_load_animation_from_bitmap("data/archdemon.png");
	if(!animation[ANIMATION_ARCHDEMON])
	{
		return false;
	}
	animation[ANIMATION_PLAYER_SHOT] = t3f_load_animation_from_bitmap("data/player_shot.png");
	if(!animation[ANIMATION_PLAYER_SHOT])
	{
		return false;
	}
	animation[ANIMATION_ENEMY_SHOT] = t3f_load_animation_from_bitmap("data/enemy_shot.png");
	if(!animation[ANIMATION_ENEMY_SHOT])
	{
		return false;
	}
	animation[ANIMATION_SPIRIT] = t3f_create_animation();
	if(!animation[ANIMATION_SPIRIT])
	{
		return false;
	}
	bp = al_load_bitmap("data/spirit0.png");
	t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp);
	t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 0, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5);
	bp = al_load_bitmap("data/spirit1.png");
	t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp);
	t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 1, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5);
	bp = al_load_bitmap("data/spirit2.png");
	t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp);
	t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 2, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5);
	animation[ANIMATION_LOGO] = t3f_load_animation_from_bitmap("data/logo.png");
	if(!animation[ANIMATION_LOGO])
	{
		return false;
	}
	animation[ANIMATION_TITLE] = t3f_load_animation_from_bitmap("data/title_logo.png");
	if(!animation[ANIMATION_TITLE])
	{
		return false;
	}
	sprite_sheet = al_create_bitmap(512, 512);
	if(!sprite_sheet)
	{
		return false;
	}
	t3f_start_sprite_sheet(sprite_sheet, T3F_SPRITE_SHEET_TYPE_SPRITES);
	t3f_add_animation_to_sprite_sheet(animation[ANIMATION_PLAYER]);
	t3f_add_animation_to_sprite_sheet(animation[ANIMATION_DEMON]);
	t3f_add_animation_to_sprite_sheet(animation[ANIMATION_ARCHDEMON]);
	t3f_add_animation_to_sprite_sheet(animation[ANIMATION_PLAYER_SHOT]);
	t3f_add_animation_to_sprite_sheet(animation[ANIMATION_ENEMY_SHOT]);
	t3f_add_animation_to_sprite_sheet(animation[ANIMATION_SPIRIT]);
	t3f_finish_sprite_sheet();
	font[FONT_GAME] = al_load_bitmap_font("data/default_font.png");
	if(!font[FONT_GAME])
	{
		return false;
	}
	sample[SAMPLE_GAME_OVER] = al_load_sample("data/game_over.ogg");
	if(!sample[SAMPLE_GAME_OVER])
	{
		return false;
	}
	sample[SAMPLE_LEVEL_UP] = al_load_sample("data/level_up.ogg");
	if(!sample[SAMPLE_LEVEL_UP])
	{
		return false;
	}
	sample[SAMPLE_MAX_MULTIPLIER] = al_load_sample("data/max_multiplier.ogg");
	if(!sample[SAMPLE_MAX_MULTIPLIER])
	{
		return false;
	}
	sample[SAMPLE_HIGH_SCORE] = al_load_sample("data/high_score.ogg");
	if(!sample[SAMPLE_HIGH_SCORE])
	{
		return false;
	}
	sample[SAMPLE_TWIN_SHOT] = al_load_sample("data/twin_shot.ogg");
	if(!sample[SAMPLE_TWIN_SHOT])
	{
		return false;
	}
	sample[SAMPLE_TRIPLE_SHOT] = al_load_sample("data/triple_shot.ogg");
	if(!sample[SAMPLE_TRIPLE_SHOT])
	{
		return false;
	}
	sample[SAMPLE_POWERUP] = al_load_sample("data/powerup.ogg");
	if(!sample[SAMPLE_POWERUP])
	{
		return false;
	}
	sample[SAMPLE_SHOOT] = al_load_sample("data/shoot.ogg");
	if(!sample[SAMPLE_SHOOT])
	{
		return false;
	}
	sample[SAMPLE_HIT] = al_load_sample("data/hit.ogg");
	if(!sample[SAMPLE_HIT])
	{
		return false;
	}
	sample[SAMPLE_DIE] = al_load_sample("data/die.ogg");
	if(!sample[SAMPLE_DIE])
	{
		return false;
	}
	sample[SAMPLE_MULTIPLIER] = al_load_sample("data/multiplier.ogg");
	if(!sample[SAMPLE_MULTIPLIER])
	{
		return false;
	}
	cinema = load_cinema("data/intro.cin", 0);
	if(!cinema)
	{
		return false;
	}
	ending_cinema = load_cinema("data/ending.cin", 0);
	if(!ending_cinema)
	{
		return false;
	}
	level_color[0] = al_map_rgba(131, 0, 0, 255);
	level_color[1] = al_map_rgba(131, 22, 0, 255);
	level_color[2] = al_map_rgba(131, 46, 0, 255);
	level_color[3] = al_map_rgba(131, 68, 0, 255);
	level_color[4] = al_map_rgba(131, 99, 0, 255);
	level_color[5] = al_map_rgba(131, 126, 0, 255);
	level_color[6] = al_map_rgba(101, 131, 0, 255);
	level_color[7] = al_map_rgba(77, 131, 0, 255);
	level_color[8] = al_map_rgba(0, 131, 73, 255);
	level_color[9] = al_map_rgba(0, 105, 131, 255);
	level_color[10] = al_map_rgba(0, 135, 254, 255);
	hyperlink_set_driver(NULL);
	val = al_get_config_value(t3f_config, "Save Data", "High Score");
	if(val)
	{
		high_score = atoi(val);
	}
	t3f_play_music("data/title.xm", 0.0, 0.0);
	state = STATE_LOGO;
	return true;
}
Пример #4
0
void c_tile::load_ini(ALLEGRO_PATH * path)
{
    ALLEGRO_CONFIG * config = 0;

    const char * thepath = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);
    log_printf("Loading tile at: %s\n", thepath);
    config = al_load_config_file(thepath);
    if(!config)
    {
        DisplayErr("Cannot load tile: %s\n", thepath);
        exit(1);
    }
    char buffer[256];

    height_max = get_config_int(config, "SPRITE", "height_max", 280);
    height_min = get_config_int(config, "SPRITE", "height_min", 0);

    priority = get_config_int(config, "SPRITE", "priority", 0);

    const char * terra = al_get_config_value(config, "SPRITE", "special_terrain");
    if(terra)
        special_terrain = get_terrain_type(terra);

    const char * cons = al_get_config_value(config, "SPRITE", "special_object");
    if(cons)
        structure = get_structure_type(cons);

    s_sprite temp;
    size_t cap_layers = get_config_int(config, "SPRITE", "cap_layers");
    for(size_t i = 0; i < cap_layers; i++)
    {
        sprintf(buffer, "CAP_IMAGE_%d", i);
        temp = get_from_ini(config, buffer, path);
        if(temp.index >= 0)
            top_sprites.push_back(temp);
    }

    size_t column_layers = get_config_int(config, "SPRITE", "column_layers");
    for(size_t i = 0; i < column_layers; i++)
    {
        sprintf(buffer, "COLUMN_IMAGE_%d", i);
        temp = get_from_ini(config, buffer, path);
        if(temp.index >= 0)
            bottom_sprites.push_back(temp);
    }

    size_t surface_layers = get_config_int(config, "SPRITE", "surface_layers");
    for(size_t i = 0; i < surface_layers; i++)
    {
        sprintf(buffer, "SURFACE_IMAGE_%d", i);
        temp = get_from_ini(config, buffer, path);
        if(temp.index >= 0)
            surface_sprites.push_back(temp);
    }

    size_t intermediate_layers = get_config_int(config, "SPRITE", "intermediate_layers");
    for(size_t i = 0; i < intermediate_layers; i++)
    {
        sprintf(buffer, "INTERMEDIATE_IMAGE_%d", i);
        temp = get_from_ini(config, buffer, path);
        if(temp.index >= 0)
            intermediate_sprites.push_back(temp);
    }

    size_t object_layers = get_config_int(config, "SPRITE", "object_layers");
    for(size_t i = 0; i < object_layers; i++)
    {
        sprintf(buffer, "OBJECT_IMAGE_%d", i);
        temp = get_from_ini(config, buffer, path);
        if(temp.index >= 0)
            object_sprites.push_back(temp);
    }

}
Пример #5
0
static ALLEGRO_DISPLAY_INTERFACE *win_get_display_driver(void)
{
   const int flags = al_get_new_display_flags();
   ALLEGRO_SYSTEM *sys = al_get_system_driver();
   ALLEGRO_SYSTEM_WIN *syswin = (ALLEGRO_SYSTEM_WIN *)sys;

   /* Look up the toggle_mouse_grab_key binding.  This isn't such a great place
    * to do it, but the config file is not available in win_initialize,
    * and this is neutral between the D3D and OpenGL display drivers.
    */
   if (sys->config && !syswin->toggle_mouse_grab_keycode) {
      const char *binding = al_get_config_value(sys->config,
         "keyboard", "toggle_mouse_grab_key");
      if (binding) {
         syswin->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
            &syswin->toggle_mouse_grab_modifiers);
         if (syswin->toggle_mouse_grab_keycode) {
            ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
         }
         else {
            ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
         }
      }
   }

   /* Programmatic selection. */
#ifdef ALLEGRO_CFG_D3D
   if (flags & ALLEGRO_DIRECT3D_INTERNAL) {
      if (d3d_available) {
         return _al_display_d3d_driver();
      }
      ALLEGRO_WARN("Direct3D graphics driver not available.\n");
      return NULL;
   }
#endif
#ifdef ALLEGRO_CFG_OPENGL
   if (flags & ALLEGRO_OPENGL) {
      return _al_display_wgl_driver();
   }
#endif

   /* Selection by configuration file.  The configuration value is non-binding.
    * The user may unknowingly set a value which was configured out at compile
    * time.  The value should have no effect instead of causing a failure.
    */
   if (sys->config) {
      const char *s = al_get_config_value(sys->config, "graphics", "driver");
      if (s) {
         ALLEGRO_DEBUG("Configuration value graphics.driver = %s\n", s);
         if (0 == _al_stricmp(s, "DIRECT3D") || 0 == _al_stricmp(s, "D3D")) {
#ifdef ALLEGRO_CFG_D3D
            if (d3d_available) {
               al_set_new_display_flags(flags | ALLEGRO_DIRECT3D_INTERNAL);
               return _al_display_d3d_driver();
            }
#endif
         }
         else if (0 == _al_stricmp(s, "OPENGL")) {
#ifdef ALLEGRO_CFG_OPENGL
            al_set_new_display_flags(flags | ALLEGRO_OPENGL);
            return _al_display_wgl_driver();
#endif
         }
         else if (0 != _al_stricmp(s, "DEFAULT")) {
            ALLEGRO_WARN("Graphics driver selection unrecognised: %s\n", s);
         }
      }
   }

   /* Automatic graphics driver selection. */
   /* XXX is implicitly setting new_display_flags the desired behaviour? */
#ifdef ALLEGRO_CFG_D3D
   if (d3d_available) {
      al_set_new_display_flags(flags | ALLEGRO_DIRECT3D_INTERNAL);
      return _al_display_d3d_driver();
   }
#endif
#ifdef ALLEGRO_CFG_OPENGL
   {
      al_set_new_display_flags(flags | ALLEGRO_OPENGL);
      return _al_display_wgl_driver();
   }
#endif
   ALLEGRO_WARN("No graphics driver available.\n");
   return NULL;
}
static const char *get_string(const char *key)
{
    const char *v = al_get_config_value(ex.config, "", key);
    return (v) ? v : key;
}
Пример #7
0
int main(void)
{
   ALLEGRO_CONFIG *cfg;
   const char *value;
   ALLEGRO_CONFIG_SECTION *iterator;
   ALLEGRO_CONFIG_ENTRY *iterator2;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   open_log();

   cfg = al_load_config_file("data/sample.cfg");
   if (!cfg) {
      abort_example("Couldn't load data/sample.cfg\n");
   }

   value = al_get_config_value(cfg, NULL, "old_var");
   TEST("global var", value && !strcmp(value, "old global value"));

   value = al_get_config_value(cfg, "section", "old_var");
   TEST("section var", value && !strcmp(value, "old section value"));

   value = al_get_config_value(cfg, "", "mysha.xpm");
   TEST("long value", value && strlen(value) == 1394);
   
   /* Test whether iterating through our whole sample.cfg returns all
    * sections and entries, in order.
    */

   value = al_get_first_config_section(cfg, &iterator);
   TEST("section1", value && !strcmp(value, ""));
   
   value = al_get_first_config_entry(cfg, value, &iterator2);
   TEST("entry1", value && !strcmp(value, "old_var"));
   
   value = al_get_next_config_entry(&iterator2);
   TEST("entry2", value && !strcmp(value, "mysha.xpm"));
   
   value = al_get_next_config_entry(&iterator2);
   TEST("entry3", value == NULL);

   value = al_get_next_config_section(&iterator);
   TEST("section2", value && !strcmp(value, "section"));
   
   value = al_get_first_config_entry(cfg, value, &iterator2);
   TEST("entry4", value && !strcmp(value, "old_var"));
   
   value = al_get_next_config_entry(&iterator2);
   TEST("entry5", value == NULL);

   value = al_get_next_config_section(&iterator);
   TEST("section3", value);
   
   value = al_get_first_config_entry(cfg, value, &iterator2);
   TEST("entry6", value);
   
   value = al_get_next_config_entry(&iterator2);
   TEST("entry7", value == NULL);
   
   value = al_get_next_config_section(&iterator);
   TEST("section4", value == NULL);
   
   

   al_set_config_value(cfg, "", "new_var", "new value");
   al_set_config_value(cfg, "section", "old_var", "new value");

   TEST("save_config", al_save_config_file("test.cfg", cfg));

   log_printf("Done\n");

   al_destroy_config(cfg);

   close_log(true);

   return passed ? 0 : 1;
}
Пример #8
0
int main(void)
{
int X_ROOMS=13;
int Y_ROOMS=16;
int X_ROOM_SIZE=256;
int Y_ROOM_SIZE=128;
int SCALE_FACTOR=4;
int X_TILE_SIZE=8;
int Y_TILE_SIZE=8;
int LAST_OBJECT=0;
int actid=0;
int error=0;
ALLEGRO_CONFIG *cfg;
ALLEGRO_BITMAP *bmp,*virt,*tmp=NULL;
ALLEGRO_DISPLAY *display;
ALLEGRO_KEYBOARD_STATE key;
ALLEGRO_FONT *font;
signed int xcursor=0;
signed int ycursor=0;
signed char x=0;
signed char y=0;
signed char finex=0;
signed char finey=0;
char finish=0;
ALLEGRO_COLOR black,white,red,color;
int scale_cursor_x=0;
int scale_cursor_y=0;
int i=0;
int a=0;
unsigned char r,g,b=0;
char pngfilename[20];
char *tmpbuf;
char buf[5];
char buf2[5];

	/* Iniciar el rollo */
	tmpbuf=(char *)malloc(sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE);
	memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE);
	al_init();
	al_init_image_addon();
	al_init_primitives_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	cfg=al_load_config_file("sacagraf.cfg");
	if (cfg==NULL)
	{
		cfg=al_create_config();
		al_add_config_section(cfg,"Ajustes");
		al_add_config_section(cfg,"Objetos");
		al_set_config_value(cfg,"Ajustes","Habitaciones en horizontal","13");
		al_set_config_value(cfg,"Ajustes","Habitaciones en vertical","16");
		al_set_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels","256");
		al_set_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels","128");
		al_set_config_value(cfg,"Ajustes","Ancho minimo del caracter original","8");
		al_set_config_value(cfg,"Ajustes","Alto minimo del caracter original","8");
		al_set_config_value(cfg,"Ajustes","Factor de escalado","4");
		al_set_config_value(cfg,"Objetos","Ultimo","0");
		al_save_config_file("sacagraf.cfg",cfg);
	}

	X_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en horizontal"));
	Y_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en vertical"));
	X_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels"));
	Y_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels"));
	SCALE_FACTOR=atoi(al_get_config_value(cfg,"Ajustes","Factor de escalado"));
	X_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto minimo del caracter original"));
	Y_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho minimo del caracter original"));
	LAST_OBJECT=atoi(al_get_config_value(cfg,"Objetos","Ultimo"));
	actid=LAST_OBJECT;

	al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
	display=al_create_display(X_ROOM_SIZE*SCALE_FACTOR,192*SCALE_FACTOR);
	bmp=al_load_bitmap("map.png");
	virt=al_create_bitmap(X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR);
	font=al_load_ttf_font("proggy.ttf",6*SCALE_FACTOR,0);
	al_install_keyboard();
	black=al_map_rgb(0,0,0);
	white=al_map_rgba_f(1,1,1,1);
	red=al_map_rgba_f(1,0,0,0.7);

	/* Que empiece la fiesta */
	while(!finish)
	{
		al_get_keyboard_state(&key);
		if (al_key_down(&key,ALLEGRO_KEY_ESCAPE))
		{
			finish=1;
		}

		if (al_key_down(&key,ALLEGRO_KEY_LCTRL))
		{
			finex=0;
			finey=0;
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				x++;
				if (x==X_ROOMS) x=X_ROOMS-1;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				x--;
				if (x<0) x=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				y--;
				if (y<0) y=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				y++;
				if (y>Y_ROOMS-1) y=Y_ROOMS-1;
			}
		}
		else if (al_key_down(&key,ALLEGRO_KEY_LSHIFT))
		{
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				finex++;
				if (finex>X_TILE_SIZE) finex=X_TILE_SIZE;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				finex--;
				if (finex<-X_TILE_SIZE) finex=-X_TILE_SIZE;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				finey--;
				if (finey<-Y_TILE_SIZE) finey=-Y_TILE_SIZE;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				finey++;
				if (finey>Y_TILE_SIZE) finey=Y_TILE_SIZE;
			}
		}
		else if (al_key_down(&key,ALLEGRO_KEY_ALT))
		{
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				scale_cursor_x++;
				//if (finex>8) finex=8;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				scale_cursor_x--;
				//if (finex<0) finex=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				scale_cursor_y--;
				//if (finey<0) finey=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				scale_cursor_y++;
				//if (finey>8) finey=8;
			}
		}
		else
		{
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				xcursor+=X_TILE_SIZE*SCALE_FACTOR;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				xcursor-=X_TILE_SIZE*SCALE_FACTOR;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				ycursor-=Y_TILE_SIZE*SCALE_FACTOR;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				ycursor+=Y_TILE_SIZE*SCALE_FACTOR;
			}
		}

		al_clear_to_color(black);
		al_set_target_bitmap(virt);
		//al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,white);
		al_draw_bitmap_region(bmp,0+(x*X_ROOM_SIZE)+finex,0+(y*Y_ROOM_SIZE)+finey,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,0);
		al_set_target_bitmap(al_get_backbuffer(display));
		al_draw_scaled_bitmap(virt,0,0,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR,0);
		al_draw_line(0,512,1024,512,white,0);
		al_draw_textf(font,al_map_rgba(200,200,200,200),0,520,0,"mapa x: %d  mapa y: %d  habitacion nº: %d  ajuste fino x: %d  ajuste fijo y: %d",x,y,x+(y*13),finex,finey);
		if (error)
		{
			al_draw_textf(font,al_map_rgba(200,200,200,200),0,540,0,"Patron repetido");
			al_flip_display();
			al_rest(1);
			error=0;
		}


		if (al_key_down(&key,ALLEGRO_KEY_ENTER))
		{
			tmp=al_create_bitmap((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x),(Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y));
			al_set_target_bitmap(tmp);
			al_draw_bitmap_region(al_get_backbuffer(display),xcursor,ycursor,(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)+(X_TILE_SIZE*SCALE_FACTOR),(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)+(Y_TILE_SIZE*SCALE_FACTOR),0,0,0);

			memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE);
			memset(buf,0,5);

			for (i=0;i<(Y_TILE_SIZE*scale_cursor_y*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR);i+=SCALE_FACTOR)
			{
				for (a=0;a<(X_TILE_SIZE*scale_cursor_x*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR);a+=SCALE_FACTOR)
				{
					color=al_get_pixel(tmp,a,i);
					al_unmap_rgb(color,&r,&g,&b);
					if (!r && !g && !b)
					{
						strcat(tmpbuf,"0");
					}
					else
					{
						strcat(tmpbuf,"1");
					}
				}
			}

			/* Ya está la secuencia del gráfico en tmpbuf, examinamos todas las secuencias anteriores */

			error=0;
			for (i=0;i<actid;i++)
			{
				memset(buf2,0,5);
				sprintf(buf2,"%d",i);

				if (!strcmp(al_get_config_value(cfg,"Objetos",buf2),tmpbuf))
				{
					error=i;
				}
			}

			/* Si no hay secuencias repetidas lo grabamos */
			if (!error)
			{
				sprintf(buf,"%d",actid);
				al_set_config_value(cfg,"Objetos",buf,tmpbuf);
				memset(pngfilename,0,20);
				sprintf(pngfilename,"dec%d.png",actid);
				al_save_bitmap(pngfilename,tmp);
				actid++;
			}

			al_destroy_bitmap(tmp);
		}

		al_set_target_bitmap(al_get_backbuffer(display));
		//al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,red);
		al_draw_filled_rectangle(xcursor,ycursor,xcursor+((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)),ycursor+((Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)),red);
		al_flip_display();
		al_rest(0.1);
	}

	memset(buf,0,5);
	sprintf(buf,"%d",actid);
	al_set_config_value(cfg,"Objetos","Ultimo",buf);
	al_save_config_file("sacagraf.cfg",cfg);
	al_destroy_font(font);
	al_uninstall_keyboard();
	al_destroy_bitmap(bmp);
	al_destroy_bitmap(virt);
	al_destroy_display(display);
	al_destroy_config(cfg);
	al_shutdown_ttf_addon();
	al_shutdown_font_addon();
	al_shutdown_image_addon();
	al_shutdown_primitives_addon();
	free(tmpbuf);
	return 0;
}
Пример #9
0
static void * t3f_play_music_thread(void * arg)
{
    const char * ext = NULL;
    ALLEGRO_PATH * path = NULL;
    int loop_points = 0;
    float loop_start = -1;
    float loop_end = -1;
    bool loop_disabled = false;
    const char * val = NULL;
    ALLEGRO_CONFIG * config = NULL;

    ALLEGRO_DEBUG("music thread start\n");
    t3f_music_gain = 1.0;
    al_lock_mutex(t3f_music_mutex);
    if(t3f_stream)
    {
        t3f_stop_music();
    }
    ALLEGRO_DEBUG("setting file interface\n");
    al_set_new_file_interface(t3f_music_thread_file_interface);
    t3f_stream = al_load_audio_stream(t3f_music_thread_fn, 4, 4096);
    if(!t3f_stream)
    {
        al_unlock_mutex(t3f_music_mutex);
        t3f_set_music_state(T3F_MUSIC_STATE_OFF);
        return NULL;
    }

    ALLEGRO_DEBUG("configuring music\n");
    /* look for loop data */
    path = al_create_path(t3f_music_thread_fn);
    if(path)
    {
        al_set_path_extension(path, ".ini");
        config = al_load_config_file(al_path_cstr(path, '/'));
        if(config)
        {
            val = al_get_config_value(config, "loop", "disabled");
            if(val && !strcasecmp(val, "true"))
            {
                loop_disabled = true;
            }
            if(!loop_disabled)
            {
                val = al_get_config_value(config, "loop", "start");
                if(val)
                {
                    loop_start = atof(val);
                    loop_points++;
                }
                val = al_get_config_value(config, "loop", "end");
                if(val)
                {
                    loop_end = atof(val);
                    loop_points++;
                }
            }
            val = al_get_config_value(config, "settings", "gain");
            if(val)
            {
                t3f_music_gain = atof(val);
                if(t3f_music_gain < 0.0)
                {
                    t3f_music_gain = 0;
                }
                if(t3f_music_gain > 10.0)
                {
                    t3f_music_gain = 10.0;
                }
            }
            al_destroy_config(config);
        }
        al_destroy_path(path);
    }

    if(loop_disabled)
    {
        al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_ONCE);
    }
    else
    {
        if(loop_points != 2)
        {
            /* loop entire song unless audio is MOD music */
            ext = t3f_get_music_extension(t3f_music_thread_fn);
            if(strcmp(ext, ".xm") && strcmp(ext, ".it") && strcmp(ext, ".mod") && strcmp(ext, ".s3m"))
            {
                al_set_audio_stream_loop_secs(t3f_stream, 0.0, al_get_audio_stream_length_secs(t3f_stream));
                al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP);
            }
            else
            {
                al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP);
            }
        }
        else
        {
            al_set_audio_stream_loop_secs(t3f_stream, loop_start, loop_end);
            al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP);
        }
    }
    ALLEGRO_DEBUG("start the music\n");
    t3f_music_volume = t3f_new_music_volume;
    al_set_audio_stream_gain(t3f_stream, t3f_music_volume * t3f_music_gain);
    al_attach_audio_stream_to_mixer(t3f_stream, al_get_default_mixer());
    al_unlock_mutex(t3f_music_mutex);
    t3f_set_music_state(T3F_MUSIC_STATE_PLAYING);
    return NULL;
}
Пример #10
0
static generator_data* load_generator_data(char const *name,
    ALLEGRO_CONFIG *cfg) {
  generator_data *data = malloc(sizeof(generator_data));
  data->name = malloc(strlen(name) + 1);
  strcpy(data->name, name);
  data->spawn_rate = atof(al_get_config_value(cfg, name, "spawn_rate"));
  data->spawn_velocity = atof(al_get_config_value(cfg, name, "spawn_velocity"));
  data->max_velocity = atof(al_get_config_value(cfg, name, "max_velocity"));
  data->deceleration = atof(al_get_config_value(cfg, name, "deceleration"));
  data->min_duration = atof(al_get_config_value(cfg, name, "min_duration"));
  data->max_duration = atof(al_get_config_value(cfg, name, "max_duration"));
  data->start_radius = atof(al_get_config_value(cfg, name, "start_radius"));
  data->end_radius = atof(al_get_config_value(cfg, name, "end_radius"));
  data->spawn_arc = DEGTORAD(atof(al_get_config_value(cfg, name, "spawn_arc")));
  data->start_color = string_to_color(
      al_get_config_value(cfg, name, "start_color"));
  data->end_color = string_to_color(
      al_get_config_value(cfg, name, "end_color"));
  return data;
}
Пример #11
0
billiard_ball *create_billiard_balls()
{
	int i;
	const int key_size = 256;
	char key[key_size];
	billiard_ball *balls = malloc(sizeof(billiard_ball) * BALL_COUNT);
	ALLEGRO_CONFIG *config = al_load_config_file(BCONFIG_FPATH);

	if(!balls)
	{
		perror("fail to malloc for billiard balls");
		return NULL;
	}

	if(!config)
	{
		perror("fail to load billiard_ball.config");
		free(balls);
		return NULL;
	}

	for(i = 0 ; i < BALL_COUNT ; i ++)
	{
		balls[i].number = i;
		balls[i].is_on_table = 1;
		balls[i].dx = 0;
		balls[i].dy = 0;

		// prepare the key for reading config file
		memset(key, '\0', key_size);
		sprintf(key, "ball%d", i);

		// read the score for each ball
		balls[i].score = atoi(al_get_config_value(config, key, "score"));

		// read the bitmap
		balls[i].bitmap = al_load_bitmap(
				al_get_config_value(config, "pictures", key));
		if(!balls[i].bitmap)
		{
			perror("fail to load billiard ball bitmap");
			free(balls);
			return NULL;
		}
		// load in bitmap width and height
		balls[i].bitmap_sw = al_get_bitmap_width(balls[i].bitmap);
		balls[i].bitmap_sh = al_get_bitmap_height(balls[i].bitmap);

		// read the initial position
		balls[i].cx = atof(al_get_config_value(config, key, "start_x"));
		balls[i].cy = atof(al_get_config_value(config, key, "start_y"));

		// read the collision sound file
		balls[i].collision_sound = al_load_sample(
				al_get_config_value(config, key, "collision_sound"));
		if(!balls[i].collision_sound)
		{
			perror("fail to load billiard ball collision sound");
			al_destroy_bitmap(balls[i].bitmap);
			free(balls);
			return NULL;
		}
	}

	/* DEBUG
	// ball colors
	balls[0].color = al_map_rgb(255, 255, 255);
	balls[1].color = al_map_rgb(255, 191, 0);
	balls[2].color = al_map_rgb(0, 0, 255);
	balls[3].color = al_map_rgb(255, 0, 0);
	balls[4].color = al_map_rgb(191, 0, 255);
	balls[5].color = al_map_rgb(255, 128, 0);
	balls[6].color = al_map_rgb(1, 225, 1);
	balls[7].color = al_map_rgb(138, 8, 8);
	balls[8].color = al_map_rgb(0, 0, 0);
	*/

	/* DEBUG
	balls[0].cx = 600;
	balls[0].cy = TABLE_Y_POSITION + TABLE_HEIGHT / 2;

	balls[1].cx = 260;
	balls[1].cy = TABLE_Y_POSITION + TABLE_HEIGHT / 2;

	balls[2].cx = balls[1].cx - 2 * BILLIARD_BALL_RADIUS * cos(PI / 6);
	balls[2].cy = balls[1].cy - 2 * BILLIARD_BALL_RADIUS * sin(PI / 6);

	balls[3].cx = balls[1].cx - 2 * BILLIARD_BALL_RADIUS * cos(PI / 6);
	balls[3].cy = balls[1].cy + 2 * BILLIARD_BALL_RADIUS * sin(PI / 6);

	for(i = 4 ; i <= 6 ; i ++)
		balls[i].cx = balls[1].cx - 4 * BILLIARD_BALL_RADIUS * cos(PI / 6);
	balls[4].cy = balls[1].cy - 2 * BILLIARD_BALL_RADIUS;
	balls[5].cy = balls[1].cy;
	balls[6].cy = balls[1].cy + 2 * BILLIARD_BALL_RADIUS;

	for(i = 7 ; i <= 8 ; i ++)
	{
		balls[i].cx = balls[i - 5].cx - 4 * BILLIARD_BALL_RADIUS * cos(PI / 6);
		balls[i].cy = balls[i - 5].cy;
	}
	*/
	// destroy the config file handler
	al_destroy_config(config);
	return balls;
}