예제 #1
0
int main(int argc, char * argv[])
{
	if(!t3f_initialize("ex_gui", 640, 480, 60.0, logic, render, T3F_USE_KEYBOARD | T3F_USE_MOUSE, NULL))
	{
		return 1;
	}
	bitmap = al_load_bitmap("data/bitmap.png");
	if(!bitmap)
	{
		return 1;
	}
	font = al_load_bitmap_font("data/font.png");
	if(!font)
	{
		return 1;
	}
	t3f_set_gui_driver(NULL);
	page = t3f_create_gui(0, 0);
	t3f_add_gui_text_element(page, red_proc, "Red", font, 16, 0, t3f_color_white, T3F_GUI_ELEMENT_SHADOW);
	t3f_add_gui_text_element(page, green_proc, "Green", font, 16, 24, t3f_color_white, T3F_GUI_ELEMENT_SHADOW);
	t3f_add_gui_text_element(page, blue_proc, "Blue", font, 16, 48, t3f_color_white, T3F_GUI_ELEMENT_SHADOW);
	t3f_add_gui_image_element(page, black_proc, bitmap, 16, 120, T3F_GUI_ELEMENT_SHADOW);
	t3f_run();
	return 0;
}
예제 #2
0
int main(int argc, char * argv[])
{
	if(!t3f_initialize("ex_tilemap", 640, 480, 60.0, logic, render, T3F_USE_KEYBOARD | T3F_USE_MOUSE, NULL))
	{
		return 1;
	}
	font = al_load_bitmap_font("data/font.png");
	if(!font)
	{
		return 1;
	}
	tileset = t3f_load_tileset("data/tileset.tts");
	if(!tileset)
	{
		return 1;
	}
	tilemap = t3f_load_tilemap("data/tilemap.ttm");
	if(!tilemap)
	{
		return 1;
	}
	camera.x = 0;
	camera.y = 0;
	camera.z = 0;
	t3f_run();
	return 0;
}
예제 #3
0
파일: font.c 프로젝트: trezker/allua
static int allua_Font_load_bitmap(lua_State * L)
{
   const char *filename = luaL_checkstring(L, 1);

   ALLUA_font font = al_load_bitmap_font(filename);
   if (font)
      allua_pushFont(L, font);
   else
      lua_pushnil(L);
   return 1;
}
예제 #4
0
bool mapper_initialize(void)
{
	const char * val = NULL;

	if(!t3f_initialize("T3F Mapper", vwidth, vheight, 60.0, mapper_logic, mapper_render, T3F_USE_KEYBOARD | T3F_USE_MOUSE, NULL))
	{
		return false;
	}
	al_set_new_bitmap_flags(ALLEGRO_NO_PREMULTIPLIED_ALPHA);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
	mapper_font = al_load_bitmap_font("fonts/basic_font.png");
	if(!mapper_font)
	{
		return false;
	}

	/* load config */
	val = al_get_config_value(t3f_config, "tileset", "width");
	if(val)
	{
		mapper_tile_width = atoi(val);
	}
	val = al_get_config_value(t3f_config, "tileset", "height");
	if(val)
	{
		mapper_tile_height = atoi(val);
	}
	val = al_get_config_value(t3f_config, "tilemap", "width");
	if(val)
	{
		mapper_map_width = atoi(val);
	}
	val = al_get_config_value(t3f_config, "tilemap", "height");
	if(val)
	{
		mapper_map_height = atoi(val);
	}
	val = al_get_config_value(t3f_config, "tilemap", "layers");
	if(val)
	{
		mapper_map_layers = atoi(val);
	}

	mapper_camera.x = 0;
	mapper_camera.y = 0;
	mapper_camera.z = 0;
	return true;
}
예제 #5
0
int demo_initialize(int argc, char * argv[])
{
	if(!t3f_initialize(640, 480, 60.0, "Paintball Party 2 Tech Demo 2", demo_logic, demo_render, T3F_DEFAULT | T3F_USE_MOUSE | T3F_USE_JOYSTICK))
	{
		return 0;
	}
	demo_font = al_load_bitmap_font("demo_font.png");
	if(!demo_font)
	{
		printf("Failed to load font!\n");
		return 0;
	}
	
	t3f_3d_set_projection(&demo_camera.projection, 1.0, 1.0, 320.0, 240.0, 640, 640);
	t3f_3d_select_projection(&demo_camera.projection);
	
	demo_camera.x = 0.0;
	demo_camera.y = 0.0;
	demo_camera.z = 0.0;
	demo_camera.vx = 0;
	demo_camera.vy = 0;
	demo_camera.vw = al_get_display_width() / 2;
	demo_camera.vh = al_get_display_height() / 2;
	demo_camera.flags = 0;
	t3f_3d_set_projection(&demo_camera.projection, 0.5, 0.5, 320.0, 240.0, 640, 640);
	t3f_3d_select_projection(&demo_camera.projection);
	
	demo_tileset = t3f_load_tileset("export.ots");
	if(!demo_tileset)
	{
		return 0;
	}
	demo_tilemap = t3f_load_tilemap("export.otm");
	if(!demo_tilemap)
	{
		return 0;
	}
	demo_tilemap->tileset = demo_tileset;
	
	demo_collision_tilemap = t3f_load_collision_tilemap("export.ocm");
	if(!demo_collision_tilemap)
	{
		return 0;
	}
	
	sprite_ani[DEMO_SPRITE_STATE_STAND_RIGHT] = load_animation("mario_sr.ani");
	sprite_ani[DEMO_SPRITE_STATE_WALK_RIGHT] = load_animation("mario_wr.ani");
	sprite_ani[DEMO_SPRITE_STATE_JUMP_RIGHT] = load_animation("mario_jr.ani");
	sprite_ani[DEMO_SPRITE_STATE_FALL_RIGHT] = load_animation("mario_fr.ani");
	sprite_ani[DEMO_SPRITE_STATE_DUCK_RIGHT] = load_animation("mario_dr.ani");
	sprite_ani[DEMO_SPRITE_STATE_STAND_LEFT] = load_animation("mario_sl.ani");
	sprite_ani[DEMO_SPRITE_STATE_WALK_LEFT] = load_animation("mario_wl.ani");
	sprite_ani[DEMO_SPRITE_STATE_JUMP_LEFT] = load_animation("mario_jl.ani");
	sprite_ani[DEMO_SPRITE_STATE_FALL_LEFT] = load_animation("mario_fl.ani");
	sprite_ani[DEMO_SPRITE_STATE_DUCK_LEFT] = load_animation("mario_dl.ani");
	if(!sprite_ani)
	{
		return 0;
	}
	platform_ani = load_animation("platform.ani");
	if(!sprite_ani)
	{
		return 0;
	}
	
	platform.angle = 0.0;
	platform.x = 320 + cos(platform.angle) * 48.0;
	platform.y = 240 + sin(platform.angle) * 48.0;
	platform.cp = t3f_create_collision_object(0, 0, al_get_bitmap_width(platform_ani->bitmap[0]) * 2, al_get_bitmap_height(platform_ani->bitmap[0]) * 2, 32, 32, 0);
	platform.sticky = NULL;
/*	player.x = 0.0;
	player.y = 0.0;
	player.cp = t3f_create_collision_object(0, 0, 32, 32, 32, 32, 0);
	player.sticky = NULL;
	player.floor = 0; */
	
	player.cp = t3f_create_collision_object(5, 0, 22, 56, 32, 32, 0);
	player.x = 64.0;
	player.y = 64.0;
	player.vx = 0.0;
	player.vy = 0.0;
	player.sticky = NULL;
	player.floor = false;
	player.state = DEMO_SPRITE_STATE_STAND_RIGHT;
	player.frame = 0;
	
	controller = t3f_create_controller(4);
	if(!controller)
	{
		return 0;
	}
	al_clear_to_color(al_map_rgb(255, 0, 0));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_UP);
	al_clear_to_color(al_map_rgb(0, 255, 0));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_DOWN);
	al_clear_to_color(al_map_rgb(0, 0, 255));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_LEFT);
	al_clear_to_color(al_map_rgb(0, 0, 0));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_RIGHT);
	
	return 1;
}
예제 #6
0
파일: main.c 프로젝트: dradtke/battlechess
/* the main program body */
int main(int argc, char *argv[])
{
   ALLEGRO_PATH *font_path;
   int w = 0, h = 0;
   int www = FALSE;
   int i, n;
   int display_flags = ALLEGRO_GENERATE_EXPOSE_EVENTS;

   srand(time(NULL));
   
   al_set_org_name("liballeg.org");
   al_set_app_name("SPEED");

   if (!al_init()) {
      fprintf(stderr, "Could not initialise Allegro.\n");
      return 1;
   }
   al_init_primitives_addon();

   /* parse the commandline */
   for (i=1; i<argc; i++) {
      if (strcmp(argv[i], "-cheat") == 0) {
         cheat = TRUE;
      }
      else if (strcmp(argv[i], "-simple") == 0) {
         low_detail = TRUE;
      }
      else if (strcmp(argv[i], "-nogrid") == 0) {
         no_grid = TRUE;
      }
      else if (strcmp(argv[i], "-nomusic") == 0) {
         no_music = TRUE;
      }
      else if (strcmp(argv[i], "-www") == 0) {
         www = TRUE;
      }
      else if (strcmp(argv[i], "-fullscreen") == 0) {
         /* if no width is specified, assume fullscreen_window */
         display_flags |= w ? ALLEGRO_FULLSCREEN : ALLEGRO_FULLSCREEN_WINDOW;
      }
      else {
         n = atoi(argv[i]);

         if (!n) {
            usage();
            return 1;
         }

         if (!w) {
            w = n;
            if (display_flags & ALLEGRO_FULLSCREEN_WINDOW) {
               /* toggle from fullscreen_window to fullscreen */
               display_flags &= ~ALLEGRO_FULLSCREEN_WINDOW;
               display_flags |= ALLEGRO_FULLSCREEN;
            }
         }
         else if (!h) {
            h = n;
         }
         else {
            usage();
            return 1;
         }
      }
   }

   /* it's a real shame that I had to take this out! */
   if (www) {
      printf(
	 "\n"
	 "Unfortunately the built-in web browser feature had to be removed.\n"
	 "\n"
	 "I did get it more or less working as of Saturday evening (forms and\n"
	 "Java were unsupported, but tables and images were mostly rendering ok),\n"
	 "but the US Department of Justice felt that this was an unacceptable\n"
	 "monopolistic attempt to tie in web browsing functionality to an\n"
	 "unrelated product, so they threatened me with being sniped at from\n"
	 "the top of tall buildings by guys with high powered rifles unless I\n"
	 "agreed to disable this code.\n"
	 "\n"
	 "We apologise for any inconvenience that this may cause you.\n"
      );

      return 1;
   }
   
   if (!w || !h) {
      if (argc == 1 || (display_flags & ALLEGRO_FULLSCREEN_WINDOW)) {
         w = 640;
         h = 480;
      }
      else {
         usage();
         return 1;
      }
   }

   /* set the screen mode */
   al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
   al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);

   al_set_new_display_flags(display_flags);
   screen = al_create_display(w, h);
   if (!screen) {
      fprintf(stderr, "Error setting %dx%d display mode\n", w, h);
      return 1;
   }

   al_init_image_addon();

   /* The Allegro 5 port introduced an external data dependency, sorry.
    * To avoid performance problems on graphics drivers that don't support
    * drawing to textures, we build up transition screens on memory bitmaps.
    * We need a font loaded into a memory bitmap for those, then a font
    * loaded into a video bitmap for the game view. Blech!
    */
   font_path = get_resources_path();
   al_set_path_filename(font_path, "a4_font.tga");

   al_init_font_addon();
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   font = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }

   al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
   font_video = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font_video) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }
   
   al_destroy_path(font_path);

   /* set up everything else */
   al_install_keyboard();
   al_install_joystick();
   if (al_install_audio()) {
      if (!al_reserve_samples(8))
         al_uninstall_audio();
   }

   init_input();
   init_sound();
   init_hiscore();

   /* the main program body */
   while (title_screen()) {
      if (play_game()) {
	 show_results();
	 score_table();
      }
   }

   /* time to go away now */
   shutdown_hiscore();
   shutdown_sound();

   goodbye();

   shutdown_input();

   al_destroy_font(font);
   al_destroy_font(font_video);

   return 0;
}
예제 #7
0
int main(int argc, char *argv[])
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_FONT *font;
   ALLEGRO_AUDIO_RECORDER *recorder;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_TIMER *timer;
   int font_height;
   
   /* Frequency is the number of samples per second. */
   const int frequency = 44100;
   
   const int channels = 2;

   /* The latency is used to determine the size of the fragment buffer.
      More accurately, it represents approximately how many seconds will
      pass between fragment events. (There may be overhead latency from
      the OS or driver the adds a fixed amount of latency on top of 
      Allegro's.) 
      
      For this example, the latency should be kept relatively low since
      each fragment is processed in its entirety. Increasing the latency
      would increase the size of the fragment, which would decrease the
      accuracy of the code that processes the fragment.
      
      But if it's too low, then it will cut out too quickly. (If the
      example were more thoroughly written, the latency setting wouldn't
      actually change how the voice detection worked.)
    */
   const float latency = 0.10;

   const int max_seconds = 3; /* number of seconds of voice recording */
   
   int16_t *name_buffer;      /* stores up to max_seconds of audio */
   int16_t *name_buffer_pos;  /* points to the current recorded position */
   int16_t *name_buffer_end;  /* points to the end of the buffer */
   
   float gain = 0.0f;         /* 0.0 (quiet) - 1.0 (loud) */
   float begin_gain = 0.3f;   /* when to begin recording */
   
   bool is_recording = false;
   
   ALLEGRO_SAMPLE *spl = NULL;
   
   (void) argc;
   (void) argv;
   
   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   
   if (!al_install_audio()) {
      abort_example("Unable to initialize audio addon\n");
   }
   
   if (!al_init_acodec_addon()) {
      abort_example("Unable to initialize acoded addon\n");
   }
   
   if (!al_init_image_addon()) {
      abort_example("Unable to initialize image addon\n");
   }
   
   if (!al_init_primitives_addon()) {
      abort_example("Unable to initialize primitives addon\n");
   }
      
   al_init_font_addon();
   al_install_keyboard();
   
   font = al_load_bitmap_font("data/bmpfont.tga");
   if (!font) {
      abort_example("Unable to load data/a4_font.tga\n");
   }
   
   font_height = al_get_font_line_height(font);
   
   /* WARNING: This demo assumes an audio depth of INT16 and two channels.
      Changing those values will break the demo. Nothing here really needs to be
      changed. If you want to fiddle with things, adjust the constants at the
      beginning of the program.
    */
   
   recorder = al_create_audio_recorder(
      5 / latency,                 /* five seconds of buffer space */
      frequency * latency,         /* configure the fragment size to give us the given
                                        latency in seconds */
      frequency,                   /* samples per second (higher => better quality) */
      ALLEGRO_AUDIO_DEPTH_INT16,   /* 2-byte sample size */
      ALLEGRO_CHANNEL_CONF_2       /* stereo */
   );
   
   if (!recorder) {
      abort_example("Unable to create audio recorder\n");
   }
   
   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Unable to create display\n");
   }
   
   /* Used to play back the voice recording. */
   al_reserve_samples(1);
   
   /* store up to three seconds */
   name_buffer = al_calloc(channels * frequency * max_seconds, sizeof(int16_t));
   name_buffer_pos = name_buffer;
   name_buffer_end = name_buffer + channels * frequency * max_seconds;
   
   queue = al_create_event_queue();
   timer = al_create_timer(1 / 60.0);
   
   al_register_event_source(queue, al_get_display_event_source(display));
   al_register_event_source(queue, al_get_audio_recorder_event_source(recorder));
   al_register_event_source(queue, al_get_timer_event_source(timer));
   al_register_event_source(queue, al_get_keyboard_event_source());
   
   al_start_timer(timer);
   al_start_audio_recorder(recorder);
   
   while (true) {
      ALLEGRO_EVENT event;
      bool do_draw = false;
      
      al_wait_for_event(queue, &event);
      
      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE || 
         (event.type == ALLEGRO_EVENT_KEY_UP && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)) {
         break;
      }
      else if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
         if (spl && event.keyboard.unichar != 27) {
            al_play_sample(spl, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
         }
      }
      else if (event.type == ALLEGRO_EVENT_TIMER) {
         do_draw = true;
      }
      else if (event.type == ALLEGRO_EVENT_AUDIO_RECORDER_FRAGMENT && recorder != NULL) {
         /* Because the recording happens in a different thread (and simply because we are
            queuing up events), it's quite possible to receive (process) a fragment event
            after the recorder has been stopped or destroyed. Thus, it is important to
            somehow check that the recorder is still valid, as we are doing above.
          */
         ALLEGRO_AUDIO_RECORDER_EVENT *re = al_get_audio_recorder_event(&event);
         int16_t *buffer = re->buffer;
         int16_t low = 0, high = 0;
         unsigned int i;
         
         /* Calculate the volume by comparing the highest and lowest points. This entire
            section assumes we are using fairly small fragment size (low latency). If a 
            large fragment size were used, then we'd have to inspect smaller portions 
            of it at a time to more accurately deterine when recording started and
            stopped. */
         for (i = 0; i < channels * re->samples; ++i) {
            if (buffer[i] < low)
               low = buffer[i];
            else if (buffer[i] > high)
               high = buffer[i];
         }
         
         gain = gain * 0.25 + ((float) (high - low) / 0xffff) * 0.75;
         
         /* Set arbitrary thresholds for beginning and stopping recording. This probably
            should be calibrated by determining how loud the ambient noise is.
          */
         if (!is_recording && gain >= begin_gain && name_buffer_pos == name_buffer)
            is_recording = true;
         else if (is_recording && gain <= 0.10)
            is_recording = false;
         
         if (is_recording) {
            /* Copy out of the fragment buffer into our own buffer that holds the
               name. */
            int samples_to_copy = channels * re->samples;
            
            /* Don't overfill up our name buffer... */
            if (samples_to_copy > name_buffer_end - name_buffer_pos)
               samples_to_copy = name_buffer_end - name_buffer_pos;
            
            if (samples_to_copy) {
               /* must multiply by two, since we are using 16-bit samples */
               memcpy(name_buffer_pos, re->buffer, samples_to_copy * 2);
            }
            
            name_buffer_pos += samples_to_copy;
            if (name_buffer_pos >= name_buffer_end) {
               is_recording = false;
            }
         }
         
         if (!is_recording && name_buffer_pos != name_buffer && !spl) {
            /* finished recording, but haven't created the sample yet */
            spl = al_create_sample(name_buffer, name_buffer_pos - name_buffer, frequency, 
               ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2, false);
            
            /* We no longer need the recorder. Destroying it is the only way to unlock the device. */
            al_destroy_audio_recorder(recorder);
            recorder = NULL;
         }
      }
      
      if (do_draw) {
         al_clear_to_color(al_map_rgb(0,0,0));
         if (!spl) {
            const char *msg = "Say Your Name";
            int width = al_get_text_width(font, msg);
            
            al_draw_text(font, al_map_rgb(255,255,255),
               320, 240 - font_height / 2, ALLEGRO_ALIGN_CENTRE, msg
            );
            
            /* draw volume meter */
            al_draw_filled_rectangle(320 - width / 2, 242 + font_height / 2,
               (320 - width / 2) + (gain * width), 242 + font_height, 
               al_map_rgb(0,255,0)
            );
            
            /* draw target line that triggers recording */
            al_draw_line((320 - width / 2) + (begin_gain * width), 242 + font_height / 2,
               (320 - width / 2) + (begin_gain * width), 242 + font_height,
               al_map_rgb(255,255,0), 1.0
            );
         }
         else {
            al_draw_text(font, al_map_rgb(255,255,255), 320, 240 - font_height / 2,
               ALLEGRO_ALIGN_CENTRE, "Press Any Key");
         }
         al_flip_display();
      }
   }
   
   if (recorder) {
      al_destroy_audio_recorder(recorder);
   }
   
   al_free(name_buffer);
   
   return 0;
}
예제 #8
0
bool paddle_initialize(void)
{
	
	/* initialize the T^3 Framework
	   - create 640x480 display
	   - logic runs at 60.0 FPS, typical game refresh rate
	   - name the program "Paper Paddle" (displayed as window title when in windowed mode)
	   - use paddle_logic() and paddle_render() to handle logic and rendering
	   - use keyboard (T3F_USE_KEYBOARD), mouse (T3F_USE_MOUSE), sound (T3F_USE_SOUND), and fullscreen mode (T3F_USE_FULLSCREEN) */
	if(!t3f_initialize("Paper Paddle", 640, 480, 60.0, paddle_logic, paddle_render, T3F_USE_KEYBOARD | T3F_USE_MOUSE | T3F_USE_SOUND, NULL))
	{
		printf("Failed to initialize T^3 Framework!\n");
		return false;
	}
	
	/* load bitmaps */
	paddle_bitmap[EXAMPLE_BITMAP_BG] = al_load_bitmap("data/graphics/bg.png");
	if(!paddle_bitmap[EXAMPLE_BITMAP_BG])
	{
		printf("Failed to load image!\n");
		return false;
	}
	paddle_bitmap[EXAMPLE_BITMAP_LOGO] = al_load_bitmap("data/graphics/logo.png");
	if(!paddle_bitmap[EXAMPLE_BITMAP_LOGO])
	{
		printf("Failed to load image!\n");
		return false;
	}
	paddle_bitmap[EXAMPLE_BITMAP_PADDLE] = al_load_bitmap("data/graphics/paddle.png");
	if(!paddle_bitmap[EXAMPLE_BITMAP_PADDLE])
	{
		printf("Failed to load image!\n");
		return false;
	}
	paddle_bitmap[EXAMPLE_BITMAP_BALL] = al_load_bitmap("data/graphics/ball.png");
	if(!paddle_bitmap[EXAMPLE_BITMAP_BALL])
	{
		printf("Failed to load image!\n");
		return false;
	}
	
	/* load fonts */
	paddle_font[EXAMPLE_FONT_MENU] = al_load_bitmap_font("data/fonts/title_font.png");
	if(!paddle_font[EXAMPLE_FONT_MENU])
	{
		printf("Failed to load font!\n");
		return false;
	}
	paddle_font[EXAMPLE_FONT_GAME] = al_load_bitmap_font("data/fonts/game_font.png");
	if(!paddle_font[EXAMPLE_FONT_GAME])
	{
		printf("Failed to load font!\n");
		return false;
	}
	
	/* load sound samples */
	paddle_sample[EXAMPLE_SAMPLE_HIT] = al_load_sample("data/sounds/hit.ogg");
	if(!paddle_sample[EXAMPLE_SAMPLE_HIT])
	{
		printf("Failed to load sample!\n");
		return false;
	}
	paddle_sample[EXAMPLE_SAMPLE_SCORE] = al_load_sample("data/sounds/score.ogg");
	if(!paddle_sample[EXAMPLE_SAMPLE_SCORE])
	{
		printf("Failed to load sample!\n");
		return false;
	}
	
	/* create GUI */
	t3f_set_gui_driver(NULL);
	paddle_menu = t3f_create_gui(0, 0);
	t3f_add_gui_text_element(paddle_menu, paddle_menu_play_proc, "Play", paddle_font[EXAMPLE_FONT_MENU], 320, 240, t3f_color_black, T3F_GUI_ELEMENT_CENTRE);
	t3f_add_gui_text_element(paddle_menu, paddle_menu_quit_proc, "Quit", paddle_font[EXAMPLE_FONT_MENU], 320, 270, t3f_color_black, T3F_GUI_ELEMENT_CENTRE);
	
	return true;
}
bool
initialize ()
{
  ALLEGRO_BITMAP *temp_color_bitmap;
  ALLEGRO_BITMAP *temp_mask_bitmap;

  global.quit = false;
  al_set_app_name ("Super Battle Thor II");
  if (!al_init ())
    {
      fputs ("Error: Could not start allegro.\n", stderr);
      return false;
    }

  al_set_new_display_option (ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
  al_set_new_display_flags (ALLEGRO_GENERATE_EXPOSE_EVENTS);
  global.display = al_create_display (256, 192);
  if (!global.display)
    {
      fputs ("Error: Allegro could not create a display of 256x192 pixels.\n",
             stderr);
      return false;
    }

  if (!al_install_keyboard ())
    {
      fputs ("Allegro could not initialize the keyboard system.\n", stderr);
      return false;
    }

  global.timer = al_create_timer (ALLEGRO_BPS_TO_SECS (60));
  if (!global.timer)
    {
      fputs ("Allegro could not create a 60hrz timer.\n", stderr);
      return false;
    }

  global.queue = al_create_event_queue ();
  if (!global.queue)
    {
      fputs ("Allegro could not create an event queue.\n", stderr);
      return false;
    }
  al_register_event_source (global.queue, al_get_keyboard_event_source ());
  al_register_event_source (global.queue,
                            al_get_display_event_source (global.display));
  al_register_event_source (global.queue,
                            al_get_timer_event_source (global.timer));

  if (!al_init_image_addon ())
    {
      fputs ("Allegro could not initialize the image loading system.\n",
             stderr);
      return false;
    }

  if (!al_install_audio ())
    {
      fputs ("Allegro could not initialize the audio system.\n", stderr);
      return false;
    }
  al_reserve_samples (16);

  if (!al_init_acodec_addon ())
    {
      fputs ("Allegro could not initialize the audio file loading system.\n",
             stderr);
      return false;
    }

  al_init_font_addon ();

  /* load files */
  global.path = al_get_standard_path (ALLEGRO_PROGRAM_PATH);
  al_append_path_component (global.path, "media");

  al_set_path_filename (global.path, "proggy_tiny.png");
  global.programing_font =
    al_load_bitmap_font (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.programing_font)
    {
      fputs ("Allegro could not load proggy_tiny.png.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "mjollnir.png");
  global.sprite_bitmap[SPRITE_THOR] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sprite_bitmap[SPRITE_THOR])
    {
      fputs ("Allegro could not load mjollnir.png.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "arrows.png");
  global.arrow_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.arrow_bitmap)
    {
      fputs ("Allegro could not load arrows.png.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "background_1_2_3_4.jpg");
  global.backgrounds[BACKGROUND_1] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_1])
    {
      fputs ("Allegro could not load background_1_2_3_4.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "background_5.jpg");
  global.backgrounds[BACKGROUND_5] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_5])
    {
      fputs ("Allegro could not load background_5.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "background_6.jpg");
  global.backgrounds[BACKGROUND_6] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_6])
    {
      fputs ("Allegro could not load background_6.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "title_screen.jpg");
  global.backgrounds[BACKGROUND_TITLE] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_TITLE])
    {
      fputs ("Allegro could not load title_screen.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "game_over.jpg");
  global.backgrounds[BACKGROUND_GAME_OVER] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_GAME_OVER])
    {
      fputs ("Allegro could not load game_over.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "you_win.jpg");
  global.backgrounds[BACKGROUND_YOU_WIN] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_YOU_WIN])
    {
      fputs ("Allegro could not load you_win.jpg.\n", stderr);
      return false;
    }

  global.backgrounds[BACKGROUND_BLACK] = al_create_bitmap (256, 192);
  if (!global.backgrounds[BACKGROUND_BLACK])
    {
      fputs ("Allegro could not make a 256x192 bitmap :o", stderr);
      return false;
    }
  al_set_target_bitmap (global.backgrounds[BACKGROUND_BLACK]);
  al_clear_to_color (al_map_rgb (0, 0, 0));
  al_set_target_backbuffer (global.display);

/* start copy paste code here becasue I'm lazy */
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "0-thor.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 0-thor.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "0-thor_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 0-thor_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_THOR] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "1-giant.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 1-giant.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "1-giant_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 1-giant_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_GIANT] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "2-nidhogg.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 2-nidhogg.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "2-nidhogg_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 2-nidhogg_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_NIDHOGG] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "3-ran.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 3-ran.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "3-ran_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 3-ran_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_RAN] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "4-grendel.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 4-grendel.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "4-grendel_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 4-grendel_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_GRENDEL] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "5-fafnir.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 5-fafnir.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "5-fafnir_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 5-fafnir_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_FAFNIR] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "6-loki.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 6-loki.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "6-loki_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 6-loki_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_LOKI] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "7-fenrir.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 7-fenrir.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "7-fenrir_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 7-fenrir_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_FENRIR] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "fight.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load fight.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "fight_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load fight_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_FIGHT] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
/* loading sounds here (still copy paste) */
  al_set_path_filename (global.path, "titlescreen_loop.ogg");
  global.sounds[SOUND_TITLESCREEN_LOOP] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_TITLESCREEN_LOOP])
    {
      fputs ("Allegro could not load titlescreen_loop.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "begin_battle.ogg");
  global.sounds[SOUND_BEGIN_BATTLE] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_BEGIN_BATTLE])
    {
      fputs ("Allegro could not load begin_battle.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "battle_loop.ogg");
  global.sounds[SOUND_BATTLE_LOOP] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_BATTLE_LOOP])
    {
      fputs ("Allegro could not load battle_loop.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "dragon_loop.ogg");
  global.sounds[SOUND_DRAGON_LOOP] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_DRAGON_LOOP])
    {
      fputs ("Allegro could not load dragon_loop.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "hit_1.ogg");
  global.sounds[SOUND_HIT_1] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_HIT_1])
    {
      fputs ("Allegro could not load hit_1.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "hit_2.ogg");
  global.sounds[SOUND_HIT_2] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_HIT_2])
    {
      fputs ("Allegro could not load hit_2.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_1.ogg");
  global.sounds[SOUND_LAUGH_1] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_1])
    {
      fputs ("Allegro could not load laugh_1.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_2.ogg");
  global.sounds[SOUND_LAUGH_2] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_2])
    {
      fputs ("Allegro could not load laugh_2.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_3.ogg");
  global.sounds[SOUND_LAUGH_3] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_3])
    {
      fputs ("Allegro could not load laugh_3.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_4.ogg");
  global.sounds[SOUND_LAUGH_4] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_4])
    {
      fputs ("Allegro could not load laugh_4.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_5.ogg");
  global.sounds[SOUND_LAUGH_5] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_5])
    {
      fputs ("Allegro could not load laugh_5.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_6.ogg");
  global.sounds[SOUND_LAUGH_6] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_6])
    {
      fputs ("Allegro could not load laugh_6.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "killed_baddie.ogg");
  global.sounds[SOUND_KILLED_BADDIE] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_KILLED_BADDIE])
    {
      fputs ("Allegro could not load killed_baddie.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "got_hit.ogg");
  global.sounds[SOUND_GOT_HIT] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_GOT_HIT])
    {
      fputs ("Allegro could not load got_hit.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "you_are_dead.ogg");
  global.sounds[SOUND_YOU_ARE_DEAD] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_YOU_ARE_DEAD])
    {
      fputs ("Allegro could not you_are_dead.ogg.\n", stderr);
      return false;
    }

  global.music = NULL;

  al_destroy_path (global.path);

  return true;
}
예제 #10
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;
}
예제 #11
0
파일: Font.hpp 프로젝트: SpaceManiac/ALX
 /**
     Bitmap font constructor from file.
     @param filename name of file.
  */
 Font(std::string filename) :
     Shared(al_load_bitmap_font(filename.c_str()), al_destroy_font)
 {
 }
예제 #12
0
파일: Font.hpp 프로젝트: SpaceManiac/ALX
 /**
     Bitmap font constructor from file.
     @param filename name of file.
  */
 Font(const char *filename) :
     Shared(al_load_bitmap_font(filename), al_destroy_font)
 {
 }
예제 #13
0
int main(void)
{
	//primitive variable
	const int FPS = 60;
	bool done = false;
	bool redraw = true;
	bool isGameOver = false;

	//object variables
	struct SpaceShip ship;
	struct Bullet bullets[NUM_BULLETS];
	struct Comet comets[NUM_COMETS];

	//Allegro variables
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_BITMAP *shipImage;
	ALLEGRO_BITMAP *cometImage;
	ALLEGRO_BITMAP *bulletImage;

	ALLEGRO_FONT *font = NULL;
	ALLEGRO_PATH *font_path;

	//Initialization Functions
	if (!al_init())										//initialize Allegro
		return -1;

	display = al_create_display(WIDTH, HEIGHT);		//create our display object

	if (!display)										//test display object
		return -1;

	// inicio inicializacao fontes
	al_init_image_addon();

	font_path = get_resources_path();
	al_set_path_filename(font_path, "a4_font.tga");

	al_init_font_addon();
	al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
	font = al_load_bitmap_font(al_path_cstr(font_path, '/'));
	if (!font)
	{
		return 1;
	}

	al_destroy_path(font_path);
	// termino inicializacao fontes

	al_init_primitives_addon();
	al_install_keyboard();
	al_init_image_addon();

	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 / FPS);

	shipImage = al_load_bitmap("spaceship_by_arboris.png");
	al_convert_mask_to_alpha(shipImage, al_map_rgb(255, 0, 255));

	bulletImage = al_load_bitmap("bullets_by_arboris.png");
	al_convert_mask_to_alpha(bulletImage, al_map_rgb(255, 0, 255));

	cometImage = al_load_bitmap("asteroid-1-96.png");

	srand(time(NULL ));

	//Game Init
	ship = InitShip(shipImage);

	// init bullets
	int i = 0;
	while (i < NUM_BULLETS)
	{
		bullets[i].ID = BULLET;
		bullets[i].speed = 10;
		bullets[i].live = false;

		bullets[i].maxFrame = 143;
		bullets[i].curFrame = 0;
		bullets[i].frameCount = 0;
		bullets[i].frameDelay = 2;
		bullets[i].frameWidth = 20;
		bullets[i].frameHeight = 10;
		bullets[i].animationColumns = 1;

		bullets[i].animationRow = 1;

		bullets[i].image = bulletImage;

		i++;
	}

	// init comets
	i = 0;
	while (i < NUM_COMETS)
	{
		comets[i].ID = ENEMY;
		comets[i].live = false;
		comets[i].speed = 5;
		comets[i].boundx = 35;
		comets[i].boundy = 35;

		comets[i].maxFrame = 143;
		comets[i].curFrame = 0;
		comets[i].frameCount = 0;
		comets[i].frameDelay = 2;
		comets[i].frameWidth = 96;
		comets[i].frameHeight = 96;
		comets[i].animationColumns = 21;

		if (rand() % 2)
			comets[i].animationDirection = 1;
		else
			comets[i].animationDirection = -1;

		comets[i].image = cometImage;

		i++;
	}

	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	al_start_timer(timer);

	while (!done)
	{
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

		if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			done = true;
		}
		else if (ev.type == ALLEGRO_EVENT_TIMER)
		{
			redraw = true;
			if (keys[UP])
				ship = MoveShipUp(ship);
			else if (keys[DOWN])
				ship = MoveShipDown(ship);
			else
				ship = ResetShipAnimation(ship, 1);

			if (keys[LEFT])
				ship = MoveShipLeft(ship);
			else if (keys[RIGHT])
				ship = MoveShipRight(ship);
			else
				ship = ResetShipAnimation(ship, 2);

			if (!isGameOver)
			{
				//UpdateBullet
				int i = 0;
				while (i < NUM_BULLETS)
				{
					if (bullets[i].live)
					{
						bullets[i].x += bullets[i].speed;
						if (bullets[i].x > WIDTH)
							bullets[i].live = false;
					}

					i++;
				}

				// start comet
				i = 0;
				while (i < NUM_COMETS)
				{
					if (!comets[i].live)
					{
						if (rand() % 500 == 0)
						{
							comets[i].live = true;
							comets[i].x = WIDTH;
							comets[i].y = 30 + rand() % (HEIGHT - 60);

							break;
						}
					}

					i++;
				}

				// UpdateComet(Comet comets[], int size)
				i = 0;
				while (i < NUM_COMETS)
				{
					if (comets[i].live)
					{
						if (++comets[i].frameCount >= comets[i].frameDelay)
						{
							comets[i].curFrame += comets[i].animationDirection;
							if (comets[i].curFrame >= comets[i].maxFrame)
								comets[i].curFrame = 0;
							else if (comets[i].curFrame <= 0)
								comets[i].curFrame = comets[i].maxFrame - 1;

							comets[i].frameCount = 0;
						}

						comets[i].x -= comets[i].speed;
					}

					i++;
				}

				// collide bullet
				i = 0;
				while (i < NUM_BULLETS)
				{
					if (bullets[i].live)
					{
						int j = 0;
						while (j < NUM_COMETS)
						{
							if (comets[j].live)
							{
								if (bullets[i].x
										> (comets[j].x - comets[j].boundx)
										&& bullets[i].x
												< (comets[j].x
														+ comets[j].boundx)
										&& bullets[i].y
												> (comets[j].y
														- comets[j].boundy)
										&& bullets[i].y
												< (comets[j].y
														+ comets[j].boundy))
								{
									bullets[i].live = false;
									comets[j].live = false;

									ship.score++;
								}
							}

							j++;
						}
					}

					i++;
				}

				// collide comet
				i = 0;
				while (i < NUM_COMETS)
				{
					if (comets[i].live)
					{
						if (comets[i].x - comets[i].boundx
								< ship.x + ship.boundx
								&& comets[i].x + comets[i].boundx
										> ship.x - ship.boundx
								&& comets[i].y - comets[i].boundy
										< ship.y + ship.boundy
								&& comets[i].y + comets[i].boundy
										> ship.y - ship.boundy)
						{
							ship.lives--;
							comets[i].live = false;
						}
						else if (comets[i].x < 0)
						{
							comets[i].live = false;
							ship.lives--;
						}
					}

					i++;
				}

				if (ship.lives <= 0)
					isGameOver = true;
			}
		}
		else if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch (ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true;

				//FireBullet
				int i = 0;
				while (i < NUM_BULLETS)
				{
					if (!bullets[i].live)
					{
						bullets[i].x = ship.x + 17;
						bullets[i].y = ship.y;
						bullets[i].live = true;
						break;
					}

					i++;
				}

				break;
			}
		}
		else if (ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch (ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = false;
				break;
			}
		}

		if (redraw && al_is_event_queue_empty(event_queue))
		{
			redraw = false;

			if (!isGameOver)
			{
				DrawShip(ship);
				DrawBullet(bullets, NUM_BULLETS);
				DrawComet(comets, NUM_COMETS);
				al_draw_textf(font, al_map_rgb(255, 0, 255), 5, 5, 0,
						"Player has %i lives left. Player has destroyed %i objects",
						ship.lives, ship.score);
			}
			else
			{
				al_draw_textf(font, al_map_rgb(0, 255, 255), WIDTH / 2,
						HEIGHT / 2, ALLEGRO_ALIGN_CENTRE,
						"Game Over. Final Score: %i", ship.score);
			}

			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
		}
	}

	al_destroy_bitmap(bulletImage);
	al_destroy_bitmap(cometImage);
	al_destroy_bitmap(shipImage);
	al_destroy_event_queue(event_queue);
	al_destroy_timer(timer);
	al_destroy_font(font);
	al_destroy_display(display);					//destroy our display object

	return 0;
}