コード例 #1
0
void SpaceSim::LoadAllegro()
{
	al_init(); //allegro-5.0.10-monolith-md-debug.lib

	//Anti Aliasing
	al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
	al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);

	//Creating screen
	screen_width = 1350;
	screen_height = 690;
	display = al_create_display(screen_width,screen_height);
	al_set_window_position(display,0,0);
	al_set_window_title(display, "Domitian Engine");

	//Initializing Addons
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_install_keyboard();
	al_install_audio();
	al_init_acodec_addon();

	al_reserve_samples(10);
};
コード例 #2
0
ファイル: BaseGame.cpp プロジェクト: rdelfin/SpaceTowers
void BaseGame::initScreen(ScreenType screenType, string screenTitle)
{
	if(!al_init())
	{
		al_show_native_message_box(NULL, "Error", "Error", "Could not initialize Allegro 5", NULL, 0);
		exit(-1);
	}

	int displayFlags = 0;
	switch(screenType)
	{
	case WINDOW: displayFlags = ALLEGRO_WINDOWED; break;
	case FULLSCREEN: displayFlags = ALLEGRO_FULLSCREEN; break;
	case FULLSCREEN_WINDOWED: displayFlags = ALLEGRO_FULLSCREEN | ALLEGRO_FULLSCREEN_WINDOW; break;
	default: displayFlags = ALLEGRO_WINDOWED;
	}
	al_set_new_display_flags(displayFlags);
	display = al_create_display(windowSize.x, windowSize.y);
	al_set_window_position(display, 0, 0);
	al_set_window_title(display, screenTitle.c_str());

	if(!display)
	{
		al_show_native_message_box(display, "Error", "Error", "Could not create Allegro Window", NULL, 0);
		exit(-1);
	}
}
コード例 #3
0
ファイル: Tut3.cpp プロジェクト: thiagoh/allegro5-tutorial
int main3()
{
	if(!al_init())
	{
		al_show_native_message_box(NULL, NULL, "Error", "Could not initialize Allegro 5", NULL, ALLEGRO_MESSAGEBOX_ERROR); 
		return -1;
	}
	
	al_set_new_display_flags(ALLEGRO_FULLSCREEN);
	// al_set_new_display_flags(ALLEGRO_WINDOWED);
	// al_set_new_display_flags(ALLEGRO_RESIZABLE);
	// al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
	
	ALLEGRO_DISPLAY *display = al_create_display(800, 600); 

	if(!display)
	{
		al_show_native_message_box(NULL, NULL, "Error", "Could not create Allegro 5 display", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	al_set_window_position(display, 200, 100);
	al_set_window_title(display, "CodingMadeEasy");

	// You generally want to do this after you check to see if the display was created. If the display wasn't created then there's
	// no point in calling this function

	al_rest(10.0);
	al_destroy_display(display);

	return 0;
}
コード例 #4
0
ファイル: Display.cpp プロジェクト: Feroxius/Projet-ift232
Display::Display(int width, int height)
{
    //--------------------------------------------------------------------------
    // Initialisation
    //http://liballeg.org/a5docs/5.0.10/getting_started.html
    //--------------------------------------------------------------------------

    //initialisation de l'addon pour dessiner les primitives
    al_init_primitives_addon();

    //on creer la fenetre d'affichage
    window = al_create_display(width, height);
    //on met le font noir
    al_clear_to_color(al_map_rgba(0, 0, 0, 255));
    //met a jour le display manuellement
    al_flip_display();

    //on place la fenetre en haut a gauche de l'ecran
    al_set_window_position(window, 0, 0);
	
	//Init du font
	al_init_font_addon();
	al_init_ttf_addon();
	
	font = al_load_ttf_font("Browning.ttf", 100, 0);
	font2 = al_load_ttf_font("Browning.ttf", 25, 0);

	score = "0";

}
コード例 #5
0
ファイル: gui.cpp プロジェクト: thorvalddox/roquelike
GUI::GUI()
{
    al_init();
    al_init_image_addon();
    al_init_primitives_addon();
    al_init_font_addon();
    al_install_keyboard();

    al_set_new_display_flags(ALLEGRO_WINDOWED);
    display = al_create_display(640, 480);
    al_set_window_position(display,10,10);
    al_set_window_title(display, "Rogue");

    timer = al_create_timer(1.0 / TICK_PER_S);
    queue = al_create_event_queue();

    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    viewport.view = Rectangle(0,0,640,480);

    tiles = al_load_bitmap("Images/Phoebus_tileset.png");

}
コード例 #6
0
bool GameManager::initialize()
{
	if (!al_init())
	{
		al_show_native_message_box(0,0,"ERROR!!","failed to initalize allegro!!",0,0);
		return false;
	}

	//Creating a display
	display = al_create_display(WIDTH,HEIGHT);
	
	if (!display)
	{
		al_show_native_message_box(0, 0, "ERROR!!", "failed to create display!!", 0, 0);
		return false;
	}

	al_set_window_position(display,0,0);

	//Initializing all the addons
	al_install_keyboard();
	al_init_image_addon();
	al_init_primitives_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	
	//Loading different size fonts for our game 
	font[LARGE] = al_load_font("Resources/font.ttf", 60, 0);
	assert(font[LARGE] != 0);  //only one assert is needed 

	font[MEDIUM] = al_load_font("Resources/font.ttf", 48, 0);
	 
	font[SMALL] = al_load_font("Resources/font.ttf", 12, 0);
	
	//Creating event queue
	event_queue = al_create_event_queue();
	
	//Setting timer to 60 frames per second
	timer = al_create_timer(1.0/(float)FPS);
	
	al_register_event_source(event_queue,al_get_keyboard_event_source());
	al_register_event_source(event_queue,al_get_timer_event_source(timer));

	gameDone = false;
	actSwitched = false;

	//Setting current activity to start menu
	currentAct = ACT_STARTMENU;
	
	for (int i = 0; i < 6; i++)
		keys[i] = false;
	
	draw = false;
	
	return true;
}
コード例 #7
0
ファイル: wnewwin.c プロジェクト: sesc4mt/mvcdecoder
bool _al_win_toggle_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
{
   ALLEGRO_DISPLAY_WIN *win_display = (void*)display;
   double timeout;

   switch(flag) {
      case ALLEGRO_NOFRAME: 
         _al_win_toggle_window_frame(display, win_display->window, display->w, display->h, onoff);
         return true;

      case ALLEGRO_FULLSCREEN_WINDOW:
         if (onoff == ((display->flags & ALLEGRO_FULLSCREEN_WINDOW) != 0))
            return true;

         _al_win_toggle_display_flag(display, ALLEGRO_NOFRAME, !onoff);

         if (onoff) {
            ALLEGRO_MONITOR_INFO mi;
            int adapter = al_get_current_video_adapter();
            if (adapter == -1)
                  adapter = 0;
            al_get_monitor_info(adapter, &mi);
            display->flags |= ALLEGRO_FULLSCREEN_WINDOW;
            display->w = mi.x2 - mi.x1;
            display->h = mi.y2 - mi.y1;
         }
         else {
            display->flags &= ~ALLEGRO_FULLSCREEN_WINDOW;
            display->w = win_display->toggle_w;
            display->h = win_display->toggle_h;
         }

         al_resize_display(display->w, display->h);
         timeout = al_current_time() + 3; // 3 seconds...
         while (al_current_time() < timeout) {
            if (win_display->can_acknowledge) {
               al_acknowledge_resize(display);
               break;
            }
         }

         if (onoff) {
            al_set_window_position(display, 0, 0);
            // Pop it to the front
            // FIXME: HOW?!
         }
         /* FIXME: else center the window? */
         return true;
   }
   return false;
}
コード例 #8
0
ファイル: main.cpp プロジェクト: jhonatansena/Projeto_LP1
int main(){
   ALLEGRO_DISPLAY *display;

	const float FPS = 60.0;
	//const float frameFPS = 15.0;
	const int largura = 800;
	const int altura = 600;
     Game *g = new Game();


	enum Direction { UP, DOWN, RIGHT, LEFT };

	if (!al_init()) {
		al_show_native_message_box(NULL, NULL, NULL, "Não pode iniciar o Allegro", NULL, 0);

		return -1;
	}

	// Setando tipo de janela a ser criada
	//al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
	//al_set_new_display_flags(ALLEGRO_OPENGL);
	//al_set_new_display_flags(ALLEGRO_OPENGL);
	al_set_new_display_flags(ALLEGRO_WINDOWED);

	display = al_create_display(largura, altura);

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



	ALLEGRO_KEYBOARD_STATE keyState;
	ALLEGRO_BITMAP *player = NULL;
	al_set_window_position(display,200,100);


	if (!display) {
		al_show_native_message_box(display, "Olá", "Opções do display", "Mensage,", NULL, 0);
	}


	// Mostra na tela o que está no buffer do display
	al_flip_display();

	// ***** RECEBENDO EVENTOS *****


	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();

	// registrando o teclado na fila de eventos
	al_register_event_source(event_queue, al_get_keyboard_event_source());

	// timer event
	ALLEGRO_TIMER *timer = al_create_timer( 1.0 / FPS );
	//ALLEGRO_TIMER *frametimer = al_create_timer( 1.0 / frameFPS );
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	//al_register_event_source(event_queue, al_get_timer_event_source(frametimer));


	// Game loop
	bool finalizar = false;
	bool draw = false;
	bool comer = false;
	int x = 10, y = 10;
	float velocidade = 3;
	Direction direcao = DOWN;

	srand(time(NULL)*rand());

	x = rand() % largura;
	y = rand() % altura;

    int comida_x = rand() % largura;
    int comida_y = rand() % altura;
    int cont=0;




	al_start_timer(timer);
	//al_start_timer(frametimer);

	ALLEGRO_COLOR azul = al_map_rgb(0, 0, 255);
	ALLEGRO_COLOR vermelho = al_map_rgb(255, 0, 0);

	while (!finalizar) {


		ALLEGRO_EVENT events;
		al_wait_for_event(event_queue, &events);
		al_get_keyboard_state(&keyState);


		if (events.type == ALLEGRO_EVENT_KEY_DOWN) {
			switch (events.keyboard.keycode) {
				case ALLEGRO_KEY_DOWN:
					direcao = DOWN;
					break;
				case ALLEGRO_KEY_UP:
					direcao = UP;
					break;
				case ALLEGRO_KEY_RIGHT:
					direcao = RIGHT;
					break;
				case ALLEGRO_KEY_LEFT:
					direcao = LEFT;
					break;
				case ALLEGRO_KEY_ESCAPE:
					finalizar = true;
					break;


			}
		}

		if (events.type == ALLEGRO_EVENT_TIMER) {
			switch (direcao) {
				case DOWN:
					y += velocidade;
					if(y>altura-20){
                        y =altura-20;
                        finalizar = true;
                    }

					break;
				case UP:
					y -= velocidade;
					if(y<0){
                        y=0;
                    finalizar = true;
                    }
					break;
				case RIGHT:
					x += velocidade;
					if(x > largura-20){
                        x=largura-20;
                        finalizar = true;
                    }
					break;
				case LEFT:
					x -= velocidade;
					if(x<0){
                        x=0;
                    finalizar = true;
                    }
					break;
			}

			draw = true;

		}if(Colisao(comida_x, comida_y, x, y, 20, 20)){
                    cont++;
                    if(direcao == DOWN)
                        comer = true;
                        //y -= velocidade;
                    else if(direcao == LEFT)
                        //x += velocidade;
                        comer = true;
                    else if(direcao == RIGHT)
                        //x -= velocidade;
                        comer = true;
                    else if(direcao ==UP)
                        //y +=velocidade;
                        comer = true;

                 }

		if (draw) {
            draw = false;
			// desenha retanguo 20x20 na posicao x,y nova
			//g->draw();



			if(comer){
			comer = false;
			al_draw_filled_rectangle(x, y, x+20, y+20, azul);
			al_draw_filled_circle(comida_x,comida_y, 5, vermelho);
			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0));

            comida_x = rand() % largura;
            comida_y = rand() % altura;
			al_draw_filled_circle(comida_x,comida_y, 5, vermelho);
            al_clear_to_color(al_map_rgb(0,0,0));
            if(cont>=3){
                velocidade++;
                cont=0;
            }
			//al_flip_display();
			//al_clear_to_color(al_map_rgb(0,0,0));

            }else{
            al_draw_filled_circle(comida_x,comida_y, 5, vermelho);
            al_draw_filled_rectangle(x, y, x+20, y+20, azul);
			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0));
            }// Mostra na tela o que está no buffer do display

			// preenche o buffer com preto
			al_clear_to_color(al_map_rgb(0,0,0));
		}

	}


	al_destroy_display(display);
	al_destroy_timer(timer);
	al_destroy_event_queue(event_queue);
	return  0;
}
コード例 #9
0
ファイル: Main.cpp プロジェクト: barnhen/allegro-platform
int main()
{
	// don't forget to put allegro-5.0.10-monolith-md-debug.lib
	const float FPS = 60.0f;

	ALLEGRO_DISPLAY *display;

	if(!al_init())
	{
		al_show_native_message_box(NULL,"Error","Error",
									"Cannot initialize Allegro", NULL, NULL);
		return -1;
	}

	display = al_create_display(ScreenWidth, ScreenHeight);

	if(!display)
	{
		al_show_native_message_box(NULL,"Error","Error",
									"Cannot create dsiplay", NULL, NULL);
		return -1;
	}

	al_set_window_position(display, 100, 100);

	al_install_keyboard();
	al_install_mouse();

	al_init_image_addon();
	//al_init_acodec_addon();

	al_init_font_addon();
	al_init_ttf_addon();

	ALLEGRO_TIMER *timer  = al_create_timer(1.0f / FPS);
	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	ALLEGRO_KEYBOARD_STATE keyState;

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

	bool done = false;

	InputManager input;
	ScreenManager::GetInstance().Initialize();
	ScreenManager::GetInstance().LoadContent();



	std::vector<int> keys;

	//these two below plus the IsKeyReleased are example how to use simultaneous keys
	keys.push_back(ALLEGRO_KEY_DOWN);
	keys.push_back(ALLEGRO_KEY_ESCAPE);

	float fade = 0.0f;

	al_start_timer(timer);

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

		if(input.IsKeyReleased(ev,keys))
			done=true; //closes the game
		//barnhen to check begin
		if(input.IsKeyPressed(ev, ALLEGRO_KEY_RIGHT))
			fade++;
		else if(input.IsKeyPressed(ev, ALLEGRO_KEY_LEFT))
			fade--;
		//barnhen to check end

		ScreenManager::GetInstance().Update(ev);
		ScreenManager::GetInstance().Draw(display);

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

	ScreenManager::GetInstance().UnloadContent();

	//Destroyers
	al_destroy_display(display);
	al_destroy_timer(timer);
	al_destroy_event_queue(event_queue);

	//std::cin.get();
	return 0;
}
コード例 #10
0
ファイル: ex_windows.c プロジェクト: BorisCarvajal/allegro5
int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *displays[2];
   ALLEGRO_MONITOR_INFO *info;
   int adapter_count;
   int x, y;
   ALLEGRO_FONT *myfont;
   ALLEGRO_EVENT_QUEUE *events;
   ALLEGRO_EVENT event;
   int i;

   (void)argc;
   (void)argv;

   srand(time(NULL));

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

   al_install_mouse();
   al_init_font_addon();
   al_init_image_addon();

   adapter_count = al_get_num_video_adapters();

   info = malloc(adapter_count * sizeof(ALLEGRO_MONITOR_INFO));

   for (i = 0; i < adapter_count; i++) {
      al_get_monitor_info(i, &info[i]);
   }

   x = ((info[0].x2 - info[0].x1) / 3) - (W / 2);
   y = ((info[0].y2 - info[0].y1) / 2) - (H / 2);

   al_set_new_window_position(x, y);

   displays[0] = al_create_display(W, H);

   x *= 2;
   al_set_new_window_position(x, y);

   displays[1] = al_create_display(W, H);

   if (!displays[0] || !displays[1]) {
      abort_example("Could not create displays.\n");
   }

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   myfont = al_load_font("data/fixed_font.tga", 0, 0);
   if (!myfont) {
      abort_example("Could not load font.\n");
   }

   events = al_create_event_queue();
   al_register_event_source(events, al_get_mouse_event_source());
   al_register_event_source(events, al_get_display_event_source(displays[0]));
   al_register_event_source(events, al_get_display_event_source(displays[1]));

   for (;;) {
      for (i = 0; i < 2; i++) {
        al_set_target_backbuffer(displays[i]);
        al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
        if (i == 0)
           al_clear_to_color(al_map_rgb(255, 0, 255));
        else
           al_clear_to_color(al_map_rgb(155, 255, 0));
        al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
        al_draw_textf(myfont, al_map_rgb(0, 0, 0), 50, 50, ALLEGRO_ALIGN_CENTRE, "Click me..");
        al_flip_display();
      }

      if (al_wait_for_event_timed(events, &event, 1)) {
         if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
            break;
         }
         else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
            int a = rand() % adapter_count;
            int w = info[a].x2 - info[a].x1;
            int h = info[a].y2 - info[a].y1;
            int margin = 20;
            x = margin + info[a].x1 + (rand() % (w - W - margin));
            y = margin + info[a].y1 + (rand() % (h - H - margin));
            al_set_window_position(event.mouse.display, x, y);
         }
      }
   }

   al_destroy_event_queue(events);

   al_destroy_display(displays[0]);
   al_destroy_display(displays[1]);

   free(info);

   return 0;
}
コード例 #11
0
int main(int argc, char **argv)
{
    ALLEGRO_DISPLAY *display, *ms_display;
    ALLEGRO_EVENT_QUEUE *queue;
    ALLEGRO_TIMER *timer;
    ALLEGRO_BITMAP *memory;
    char title[1024];
    bool quit = false;
    bool redraw = true;
    int wx, wy;

    (void)argc;
    (void)argv;

    if (!al_init()) {
        abort_example("Couldn't initialise Allegro.\n");
    }
    al_init_primitives_addon();

    al_install_keyboard();

    al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
    memory = create_bitmap();

    /* Create the normal display. */
    al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 0, ALLEGRO_REQUIRE);
    al_set_new_display_option(ALLEGRO_SAMPLES, 0, ALLEGRO_SUGGEST);
    display = al_create_display(300, 450);
    if (!display) {
        abort_example("Error creating display\n");
    }
    al_set_window_title(display, "Normal");

    /* Create bitmaps for the normal display. */
    al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
    bitmap_filter = al_clone_bitmap(memory);
    al_set_new_bitmap_flags(0);
    bitmap_normal = al_clone_bitmap(memory);

    font = al_create_builtin_font();

    al_get_window_position(display, &wx, &wy);
    if (wx < 160)
        wx = 160;

    /* Create the multi-sampling display. */
    al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE);
    al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);
    ms_display = al_create_display(300, 450);
    if (!ms_display) {
        abort_example("Multisampling not available.\n");
    }
    sprintf(title, "Multisampling (%dx)", al_get_display_option(
                ms_display, ALLEGRO_SAMPLES));
    al_set_window_title(ms_display, title);

    /* Create bitmaps for the multi-sampling display. */
    al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
    bitmap_filter_ms = al_clone_bitmap(memory);
    al_set_new_bitmap_flags(0);
    bitmap_normal_ms = al_clone_bitmap(memory);

    font_ms = al_create_builtin_font();

    /* Move the windows next to each other, because some window manager
     * would put them on top of each other otherwise.
     */
    al_set_window_position(display, wx - 160, wy);
    al_set_window_position(ms_display, wx + 160, wy);

    timer = al_create_timer(1.0 / 30.0);

    queue = al_create_event_queue();
    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_display_event_source(ms_display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    al_start_timer(timer);
    while (!quit) {
        ALLEGRO_EVENT event;

        /* Check for ESC key or close button event and quit in either case. */
        al_wait_for_event(queue, &event);
        switch (event.type) {
        case ALLEGRO_EVENT_DISPLAY_CLOSE:
            quit = true;
            break;

        case ALLEGRO_EVENT_KEY_DOWN:
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                quit = true;
            break;

        case ALLEGRO_EVENT_TIMER:
            bitmap_move();
            redraw = true;
            break;
        }

        if (redraw && al_is_event_queue_empty(queue)) {
            /* Draw the multi-sampled version into the first window. */
            al_set_target_backbuffer(ms_display);

            al_clear_to_color(al_map_rgb_f(1, 1, 1));

            draw(bitmap_filter_ms, 0, "filtered, multi-sample");
            draw(bitmap_normal_ms, 250, "no filter, multi-sample");

            al_flip_display();

            /* Draw the normal version into the second window. */
            al_set_target_backbuffer(display);

            al_clear_to_color(al_map_rgb_f(1, 1, 1));

            draw(bitmap_filter, 0, "filtered");
            draw(bitmap_normal, 250, "no filter");

            al_flip_display();

            redraw = false;
        }
    }

    return 0;
}
コード例 #12
0
ファイル: main.c プロジェクト: Jersono/Type-Lab4-CC3
int main(){
	/*Game Settings*/

	State state = STARTED;
	int render = 0;
	ALLEGRO_DISPLAY *display;
	ALLEGRO_EVENT_QUEUE *queue;
	ALLEGRO_TIMER *timer;
	ALLEGRO_FONT *pixelate;
	ALLEGRO_BITMAP *back1;
	ALLEGRO_BITMAP *back2;
	ALLEGRO_BITMAP *space;
	ALLEGRO_BITMAP *logo;
	struct Background bg1;
	struct Background bg2;
	struct Background bgspace;

	al_init();

	display = al_create_display(800, 600);
	al_set_window_position(display, 100, 100);
	al_set_window_title(display, "GaliType - Grupo 6");

	al_init_font_addon();
	al_init_ttf_addon();
	al_init_image_addon();
	al_install_keyboard();

	back1 = al_load_bitmap("back1.png");
	back2 = al_load_bitmap("back2.png");
	space = al_load_bitmap("space.jpg");
	logo = al_load_bitmap("logo.png");

	initBack(&bg1, 0, 0, 1.5, -1, 800, 600, back1);
	initBack(&bg2, 0, 0, 1, -1, 800, 600, back2);
	initBack(&bgspace, 0, 0, 0.5, -1, 1000, 600, space);

	queue = al_create_event_queue();
	timer = al_create_timer(1.0 / 60);

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



	pixelate = al_load_ttf_font("Pixelate.ttf", 30, 0);

	al_start_timer(timer);
	while (state != FINISHED){
		ALLEGRO_EVENT ev;
		al_wait_for_event(queue, &ev);
		if (ev.type == ALLEGRO_EVENT_KEY_DOWN){
			if (state == STARTED){
				switch (ev.keyboard.keycode)
				{
				case ALLEGRO_KEY_ESCAPE:
					state = FINISHED;
					break;
				case ALLEGRO_KEY_ENTER:
					state = SELECT_DIFFICULTY;
					break;
				}
			}
			if (state == SELECT_DIFFICULTY){
				switch (ev.keyboard.keycode){
					case ALLEGRO_KEY_1:
					case ALLEGRO_KEY_PAD_1:
						startGame(EASY);
						break;
					case ALLEGRO_KEY_2:
					case ALLEGRO_KEY_PAD_2:
						startGame(MEDIUM);
						break;
					case ALLEGRO_KEY_3:
					case ALLEGRO_KEY_PAD_3:
						startGame(HARD);
						break;
					case ALLEGRO_KEY_4:
					case ALLEGRO_KEY_PAD_4:
						startGame(TYPING_MASTER);
						break;
					case ALLEGRO_KEY_ESCAPE:
						state = STARTED;
						break;
				}
			}
		}

		else if (ev.type == ALLEGRO_EVENT_TIMER)
		{
			updateBack(&bg1);
			updateBack(&bg2);
			updateBack(&bgspace);
			render = 1;
		}
		else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
			state = FINISHED;
		}
		if (render == 1 && al_is_event_queue_empty(queue))
		{
			render = 0;
			drawBack(&bgspace);
			drawBack(&bg1);
			drawBack(&bg2);

			al_draw_bitmap(logo, 50, 25, 0);
			if (state == STARTED){
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 250, 0, "Get ready to type...");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 350, 0, "Press Enter to start a new game");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 450, 0, "Press Esc to exit.");
			}
			if (state == SELECT_DIFFICULTY){
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 250, 0, "Select difficulty:");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 300, 0, "1. Easy");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 350, 0, "2. Medium");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 400, 0, "3. Hard");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 450, 0, "4. Typing Boss");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 500, 0, "Press Esc to return...");
			}
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));

		}

	}

	al_destroy_bitmap(back1);
	al_destroy_bitmap(back2);
	al_destroy_bitmap(space);
	al_destroy_bitmap(logo);
	al_destroy_font(pixelate);
	al_destroy_display(display);
	return 0;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: trezker/SWAG
int main(int argc, char **argv)
{
	al_init();
	al_install_mouse();
	al_install_keyboard();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_primitives_addon();
	
	al_set_new_display_flags(ALLEGRO_WINDOWED|ALLEGRO_RESIZABLE);
	ALLEGRO_DISPLAY *display = al_create_display(640, 480);
	ALLEGRO_DISPLAY *tooldisplay = al_create_display(200, 480);
    al_set_window_position(tooldisplay, 10, 0);
    al_set_window_position(display, 220, 0);
    
	ALLEGRO_DISPLAY *current_display = tooldisplay;
	ALLEGRO_TIMER* timer = al_create_timer(1);

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	al_register_event_source(event_queue, (ALLEGRO_EVENT_SOURCE *)display);
	al_register_event_source(event_queue, (ALLEGRO_EVENT_SOURCE *)tooldisplay);
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_mouse_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	ALLEGRO_FONT* font = al_load_font("data/DejaVuSans.ttf", 12, 0);
	if(!font)
		font = al_load_font("examples/data/DejaVuSans.ttf", 12, 0);

	Layout layout;

	Layout_controller layout_controller;
	layout_controller.Set_layout(&layout);

	Tree* widget_tree = layout_controller.Get_skin().Clone<Tree>("tree");
	widget_tree->Set_text("Desktop");
	widget_tree->Select();

	Widget* root_widget = layout_controller.Get_skin().Clone<Desktop>("desktop");
	root_widget->Set_position(Vector2(0, 0));
	root_widget->Set_size(Vector2(640, 480));

	layout_controller.Set_tree(widget_tree, root_widget);
	layout_controller.Set_root(root_widget);
	layout_controller.Set_root_tree(widget_tree);
	layout_controller.Select_tree(widget_tree);

	layout.Set_skin(&layout_controller.Get_skin());
	layout.Add_widget("root", root_widget, NULL);


	Editor_controller editor_controller;
	editor_controller.Set_layout_display(display);
	editor_controller.Set_layout_controller(layout_controller);
	editor_controller.Load(layout_controller.Get_skin());

	//FPS
	Label* fps_label = layout_controller.Get_skin().Clone<Label>("label");
	fps_label->Set_text("FPS: 100");

	//Main vbox
	Vertical_box* toolvbox = layout_controller.Get_skin().Clone<Vertical_box>("vertical box");
	toolvbox->Add(editor_controller.Get_root());
	toolvbox->Add(fps_label);

	Slider_box* slider_box = layout_controller.Get_skin().Clone<Slider_box>("slider box");
	slider_box->Set_child(toolvbox);

	Desktop* desktop = layout_controller.Get_skin().Clone<Desktop>("desktop");
	desktop->Set_child(slider_box);
	desktop->Set_position(Vector2(0, 0));
	desktop->Set_size(Vector2(200, 480));

	Widget* toolroot = desktop;

	al_start_timer(timer);
	bool quit = false;
	while (!quit)
	{
		ALLEGRO_EVENT event;
		al_wait_for_event(event_queue, &event);
		if (ALLEGRO_EVENT_KEY_DOWN == event.type)
		{
			if (ALLEGRO_KEY_ESCAPE == event.keyboard.keycode)
			{
				quit=true;
			}
		}
		if (ALLEGRO_EVENT_DISPLAY_CLOSE == event.type)
		{
			quit=true;
		}
		if (ALLEGRO_EVENT_DISPLAY_RESIZE == event.type)
		{
			al_acknowledge_resize(event.display.source);
			if(event.display.source == display)
				layout_controller.Get_root()->Set_size(Vector2(event.display.width-20, event.display.height-20));
		}
		if (ALLEGRO_EVENT_DISPLAY_SWITCH_IN == event.type)
		{
			current_display = event.display.source;
		}
		
		if(current_display == tooldisplay)
		{
			toolroot->Handle_event(event);
		}
		if(current_display == display)
		{
			layout_controller.Get_root()->Handle_event(event);
		}
		
		if(ALLEGRO_EVENT_TIMER == event.type) {
			double dt = al_get_timer_speed(timer);
			editor_controller.Update();
			layout_controller.Get_skin().Update(dt);

			al_set_target_backbuffer(display);
			layout_controller.Get_root()->Render();
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));

			al_set_target_backbuffer(tooldisplay);
			toolroot->Render();

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

			double fps = 1 / dt;
			std::stringstream ss;
			ss<<fps;
			std::string fps_string;
			ss>>fps_string;
			fps_label->Set_text((std::string("FPS: ")+fps_string).c_str());

			if(dt < 1 && event.timer.count < al_get_timer_count(timer) - 4)
			{
				dt = dt * 1.1;
				al_set_timer_speed(timer, dt);
				//print("Tick too fast, setting speed to " .. timer_speed);
			}
			if(event.timer.count == al_get_timer_count(timer))
			{
				dt = dt * 0.9;
				al_set_timer_speed(timer, dt);
				//print("Tick too fast, setting speed to " .. timer_speed);
			}

			al_rest(0.001);
		}
	}
コード例 #14
0
ファイル: Source.cpp プロジェクト: RobLukas/PJP_GitHub_VS2015
int main() 
{
	int state = MENU;

	float TimeGame = 0;
	int frame = 0;
	int GameFPS = 0;
	

	//=========== INFO ACHIEVEMENTS

	int Points = 0;
	int Golds = 0;
	int TimeInGame = 0;

	//=========== Allegro variable
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_BITMAP *background = NULL;
	ALLEGRO_BITMAP *background_game = NULL;
	ALLEGRO_BITMAP *wall1 = NULL;
	ALLEGRO_BITMAP *wall = NULL;
	ALLEGRO_TIMER *timer = NULL;

	//=========== Program init
	if (!al_init())
		return -1;
	
	//=========== FullScreen
	al_set_new_display_flags(ALLEGRO_FULLSCREEN);

	//=========== Create our display object
	display = al_create_display(Width, Height);

	if (!display)
		return -1;

	//=========== Addon init
	al_init_font_addon();
	al_init_ttf_addon();
	al_install_keyboard();
	al_init_primitives_addon();
	al_create_display;
	al_init_image_addon();

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

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

	ALLEGRO_FONT *subtitles = al_load_font("BuxtonSketch.ttf", 40, NULL);
  	ALLEGRO_FONT *titles = al_load_font("BuxtonSketch.ttf", 100, NULL);
	ALLEGRO_FONT *setting_titles = al_load_font("BuxtonSketch.ttf", 55, NULL);
	ALLEGRO_FONT *options_titles = al_load_font("BuxtonSketch.ttf", 10, NULL);
	ALLEGRO_FONT *fps = al_load_font("arial.ttf", 18, NULL);

	al_set_window_position(display, 200, 200);

	background = al_load_bitmap("tlo1.bmp");
	background_game = al_load_bitmap("tlo_gry.png");
	wall1 = al_load_bitmap("wall1.bmp");

	int x = 0;
	int y = 0;

	//=========== MENU
	al_draw_bitmap(background, x, y, 0);
	al_draw_textf(titles, al_map_rgb(0, 0, 0), Width/2, Height/4.5, ALLEGRO_ALIGN_CENTRE, "SNAKE !");
	al_draw_textf(subtitles, al_map_rgb(0, 0, 0), 400, Height / 2 + 50, ALLEGRO_ALIGN_CENTRE, "Nowa gra");
	al_draw_textf(options_titles, al_map_rgb(0, 0, 0), 495, Height / 2 + 70, ALLEGRO_ALIGN_CENTRE, "[ENTER]");
	al_draw_textf(options_titles, al_map_rgb(0, 0, 0), 495, Height / 2 + 120, ALLEGRO_ALIGN_CENTRE, "[TAB]");
	al_draw_textf(options_titles, al_map_rgb(0, 0, 0), 495, Height / 2 + 170, ALLEGRO_ALIGN_CENTRE, "[ESC]");
	al_draw_textf(subtitles, al_map_rgb(0, 0, 0), 400, Height / 2 + 100, ALLEGRO_ALIGN_CENTRE, "Ustawienia");
	al_draw_textf(subtitles, al_map_rgb(0, 0, 0), 400, Height / 2 + 150, ALLEGRO_ALIGN_CENTRE, "Zamknij gre");

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

	TimeGame = al_current_time();
	al_start_timer(timer);

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

		//=========== INPUT
		if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch (ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				keys[ESCAPE] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true;
				break;
			case ALLEGRO_KEY_TAB:
				keys[TAB] = true;
				break;
			}
		}
		else if (ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch (ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				keys[ESCAPE] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = false;
				break;
			case ALLEGRO_KEY_TAB:
				keys[TAB] = false;
				break;
			}
		}
		else if (ev.type == ALLEGRO_EVENT_TIMER)
		{
			Return = true;

			frame++;
			if (al_current_time() - GameFPS >= 1)
			{
				TimeGame = al_current_time();
				GameFPS = frame;
				frame = 0;
			}

			if (state == MENU)
			{
				if (keys[ESCAPE])
				{
					done = true;
				}
				al_draw_bitmap(background, x, y, 0);
				al_draw_textf(titles, al_map_rgb(0, 0, 0), Width / 2, Height / 4.5, ALLEGRO_ALIGN_CENTRE, "SNAKE !");
				al_draw_textf(subtitles, al_map_rgb(0, 0, 0), 400, Height / 2 + 50, ALLEGRO_ALIGN_CENTRE, "Nowa gra");
				al_draw_textf(subtitles, al_map_rgb(0, 0, 0), 400, Height / 2 + 100, ALLEGRO_ALIGN_CENTRE, "Ustawienia");
				al_draw_textf(subtitles, al_map_rgb(0, 0, 0), 400, Height / 2 + 150, ALLEGRO_ALIGN_CENTRE, "Zamknij gre");
				al_draw_textf(options_titles, al_map_rgb(0, 0, 0), 495, Height / 2 + 70, ALLEGRO_ALIGN_CENTRE, "[ENTER]");
				al_draw_textf(options_titles, al_map_rgb(0, 0, 0), 495, Height / 2 + 120, ALLEGRO_ALIGN_CENTRE, "[TAB]");
				al_draw_textf(options_titles, al_map_rgb(0, 0, 0), 495, Height / 2 + 170, ALLEGRO_ALIGN_CENTRE, "[ESC]");
			}

			else if (state == PLAY)
			{
				al_clear_to_color(al_map_rgb(0, 0, 0));
				al_draw_bitmap(background_game, x, y, 0);
				//WallFunction(wall1, 0, 0, );
				al_flip_display();
			}

			else if (state == GAMEOVER)
			{
				al_clear_to_color(al_map_rgb(0, 0, 0));

			}

			else if (state = SETTING)
			{
				al_clear_to_color(al_map_rgb(0, 0, 0));
				al_draw_bitmap(background, x, y, 0);
				al_draw_textf(setting_titles, al_map_rgb(0, 0, 0), Width / 2, Height / 4.5, ALLEGRO_ALIGN_CENTRE, "Ustawienia");
				al_draw_textf(subtitles, al_map_rgb(0, 0, 0), 250, Height / 2 + 50, ALLEGRO_ALIGN_CENTRE, "Dzwiek: ");

				al_flip_display();
			}
		}

		if (Return && al_is_event_queue_empty(event_queue))
		{
			Return = false;
			al_draw_textf(fps, al_map_rgb(255, 0, 255), 5, 5, 0, "FPS: %d", GameFPS);

			{
				if (state == MENU)
				{
					if (keys[ENTER])
					{
						state = PLAY;
					}
				}
				else if (state == MENU)
				{
					if (keys[TAB])
					{
						state = SETTING;
					}
				}
				else if (state == PLAY)
				{
					if (keys[ESCAPE])
					{
						state = MENU;
					}
				}
				else if (state == SETTING)
				{
					if (keys[ESCAPE])
					{
						state = MENU;
					}
				}
				else if (state == GAMEOVER)
				{
					if (keys[ESCAPE])
					{
						state = MENU;
					}
				}
				else if (state = MENU)
				{
					if (keys[ESCAPE])
					{
						done = true;
					}
				}
			}

			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
		}
	}
	al_destroy_font(fps);
	al_destroy_timer(timer);
	al_destroy_event_queue(event_queue);
	al_destroy_display(display);

	return 0;
}
コード例 #15
0
ファイル: Tut27.cpp プロジェクト: thiagoh/allegro5-tutorial
int main() {

	ALLEGRO_DISPLAY *display;

	const float FPS = 60.0;
	const float frameFPS = 15.0;

	float degrees = 0.0f;

	if (!al_init())
		al_show_native_message_box(NULL, "Error", NULL, "Could not Initialize Allegro", NULL, NULL); 

	display = al_create_display(ScreenWidth, ScreenHeight);

	if (!display)
		al_show_native_message_box(NULL, "Error", NULL, "Could not create Allegro Display", NULL, NULL);

	al_set_window_position(display, 200, 200);

	bool done = false, draw = true, active = false;
	float moveSpeed = 5;
	int dir = NONE;

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

	SpriteSeq iory1SpriteSeq = SpriteUtil::process("iory-yagami.png", al_map_rgba(255, 0, 0, 255));
	SpriteSeq iory2SpriteSeq = SpriteUtil::process("iory-yagami.png", al_map_rgba(255, 0, 0, 255));
	
	iory1SpriteSeq.setX(200);
	iory2SpriteSeq.setX(200);

	iory1SpriteSeq.setY(200);
	iory2SpriteSeq.setY(200);

	ALLEGRO_KEYBOARD_STATE keyState;

	ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS);
	ALLEGRO_TIMER *frameTimer = al_create_timer(1.0 / frameFPS);

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_timer_event_source(frameTimer));
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_keyboard_event_source());

	al_start_timer(timer);
	al_start_timer(frameTimer);

	while(!done)
	{
		ALLEGRO_EVENT events; 
		al_wait_for_event(event_queue, &events);
		al_get_keyboard_state(&keyState);

		if (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			done = true;
		}
		else if (events.type == ALLEGRO_EVENT_TIMER)
		{
			if (events.timer.source == timer)
			{
				dir = NONE;
				active = true;
				
				if (al_key_down(&keyState, ALLEGRO_KEY_DOWN)) {
				
					iory1SpriteSeq.incY(moveSpeed);
					
					if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT))
					{
						iory1SpriteSeq.incX(moveSpeed);
						dir = DOWN_RIGHT;
						
					} else if (al_key_down(&keyState, ALLEGRO_KEY_LEFT)) {
					
						iory1SpriteSeq.decX(moveSpeed);
						dir = DOWN_LEFT;
					}
					
				} else if (al_key_down(&keyState, ALLEGRO_KEY_UP)) {
				
					iory1SpriteSeq.decY(moveSpeed);
					
					if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT)) {
					
						iory1SpriteSeq.incX(moveSpeed);
						dir = UP_RIGHT;

					} else if (al_key_down(&keyState, ALLEGRO_KEY_LEFT)) {

						iory1SpriteSeq.decX(moveSpeed);
						dir = UP_LEFT;
					}
				
				} else if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT)) {
				
					iory1SpriteSeq.incX(moveSpeed);
					dir = RIGHT;
					
				} else if (al_key_down(&keyState, ALLEGRO_KEY_LEFT)) {
				
					iory1SpriteSeq.decX(moveSpeed);
					dir = LEFT;
					
				} else {
				
					active = false;
				}

				if (al_key_down(&keyState, ALLEGRO_KEY_W))
					degrees++; 
				else if (al_key_down(&keyState, ALLEGRO_KEY_S))
					degrees--;

				if (degrees >= 360 || degrees <= -360)
					degrees = 0;
					
			} else if (events.timer.source == frameTimer) {
			
				iory1SpriteSeq.next();

				if (!iory1SpriteSeq.hasNext())
					iory1SpriteSeq.reset();
					
				iory2SpriteSeq.next();

				if (!iory2SpriteSeq.hasNext())
					iory2SpriteSeq.reset();

			}

			draw = true;
		}

		if (draw) {
		
			Sprite sprite1 = iory1SpriteSeq.current();
			Sprite sprite2 = iory2SpriteSeq.current();
			
			iory1SpriteSeq.setInFrontOf(&iory2SpriteSeq);
			iory2SpriteSeq.setInFrontOf(&iory1SpriteSeq);
			
			al_draw_bitmap(iory2SpriteSeq.getSubBitmap(), iory2SpriteSeq.getX(), iory2SpriteSeq.getY(), iory2SpriteSeq.getDrawFlags());
			al_draw_bitmap(iory1SpriteSeq.getSubBitmap(), iory1SpriteSeq.getX(), iory1SpriteSeq.getY(), iory1SpriteSeq.getDrawFlags());
			
			//al_draw_rotated_bitmap(iory1SpriteSeq.getSubBitmap(), sprite1.width/2, sprite1.height/2, iory1SpriteSeq.getX(), iory1SpriteSeq.getY(), 
			//						degrees * 3.1415 / 180, iory1SpriteSeq.getDrawFlags());
			
			//al_draw_tinted_bitmap(sprite.bitmap, al_map_rgb(255, 0, 0), x, y, NULL);
			
			//al_draw_scaled_bitmap(subBitmap, 16, 16, 16, 16, x, y, 32 * degrees, 32 * degrees, NULL);
			
			ALLEGRO_COLOR red = al_map_rgb(255,0,0);
			ALLEGRO_COLOR blue = al_map_rgb(0,0,255);

			al_draw_line(
				(float) iory1SpriteSeq.getX(), 
				(float) iory1SpriteSeq.getY() - 10.10, 
				(float) iory1SpriteSeq.getX(), 
				(float) iory1SpriteSeq.getY() - 20.0, 
				red, 
				1.0);

			al_draw_line(
				(float) iory1SpriteSeq.getCenterX(), 
				(float) iory1SpriteSeq.getY() - 30.0, 
				(float) iory1SpriteSeq.getCenterX(), 
				(float) iory1SpriteSeq.getY() - 40.0, 
				blue, 
				1.0);

			al_draw_line(
				(float) iory2SpriteSeq.getX(), 
				(float) iory2SpriteSeq.getY() - 10.10, 
				(float) iory2SpriteSeq.getX(), 
				(float) iory2SpriteSeq.getY() - 20.0, 
				red, 
				1.0);

			al_draw_line(
				(float) iory2SpriteSeq.getCenterX(), 
				(float) iory2SpriteSeq.getY() - 30.0, 
				(float) iory2SpriteSeq.getCenterX(), 
				(float) iory2SpriteSeq.getY() - 40.0, 
				blue, 
				1.0);
			
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
		}
	}
	
	al_destroy_display(display);
	al_destroy_timer(timer);
	al_destroy_event_queue(event_queue);

	return 0;
}
コード例 #16
0
ファイル: ex_noframe.c プロジェクト: sesc4mt/mvcdecoder
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *bitmap;
   ALLEGRO_EVENT_QUEUE *events;
   ALLEGRO_EVENT event;
   bool down = false;
   int down_x = 0, down_y = 0;
   ALLEGRO_TIMER *timer;
   bool frame = false;

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

   al_install_mouse();
   al_install_keyboard();
   al_init_image_addon();

   al_set_new_display_flags(ALLEGRO_NOFRAME);
   display = al_create_display(300, 200);
   
   bitmap = al_load_bitmap("data/fakeamp.bmp");
   if (!bitmap) {
      abort_example("Error loading fakeamp.bmp\n\n");
      return 1;
   }

   timer = al_install_timer(1.0f/30.0f);

   events = al_create_event_queue();
   al_register_event_source(events, al_get_mouse_event_source());
   al_register_event_source(events, al_get_keyboard_event_source());
   al_register_event_source(events, al_get_display_event_source(display));
   al_register_event_source(events, al_get_timer_event_source(timer));

   al_start_timer(timer);

   for (;;) {
      al_wait_for_event(events, &event);
      if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
         if (event.mouse.button == 1 && event.mouse.x) {
            down = true;
            down_x = event.mouse.x;
            down_y = event.mouse.y;
         }
         if (event.mouse.button == 2) {
            frame = !frame;
            al_toggle_display_flag(ALLEGRO_NOFRAME, frame);
         }
      }
      else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
      else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
         if (event.mouse.button == 1) {
            down = false;
         }
      }
      else if (event.type == ALLEGRO_EVENT_MOUSE_AXES) {
         if (down) {
            int cx, cy;
            if (al_get_mouse_cursor_position(&cx, &cy)) {
               al_set_window_position(display, cx - down_x, cy - down_y);
            }
         }
      }
      else if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
	    event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
      else if (event.type == ALLEGRO_EVENT_TIMER) {
         al_draw_bitmap(bitmap, 0, 0, 0);
         al_flip_display();
      }
   }

   al_uninstall_timer(timer);
   al_destroy_event_queue(events);
   al_destroy_display(display);

   return 0;
}
コード例 #17
0
ファイル: mario.cpp プロジェクト: SocratesDz/kyks
int main()

{

	// Inicializando 

	const float FPS = 60.0;
	const float gravedad = 5.0;

	if(!al_init())
	{
		al_show_native_message_box(NULL, "Fatal Error", NULL, "No se pudo inicializar Allegro", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}
	
	al_set_new_display_flags(ALLEGRO_WINDOWED); // Pone la ventana en modo Windowed
	ALLEGRO_DISPLAY *display = al_create_display(AnchoPantalla, AltoPantalla);

	// Pone la posición en la que debe salir la ventana
	al_set_window_position(display, 0, 0);

	// Pone el título de la ventana
	al_set_window_title(display, "Muévete!");

	if(!display)	// Si no se pudo crear la ventana, entonces pone un mensaje de error
	{
		al_show_native_message_box(NULL, "Error", NULL, "No se pudo crear la pantalla", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}
	// Fin de la inicialización

	al_install_keyboard();
	al_init_image_addon();

	ALLEGRO_BITMAP *image = al_load_bitmap("sprites/mario.png");
	ALLEGRO_BITMAP *mario = al_create_sub_bitmap(image, 3, 603, 16, 21);
	ALLEGRO_BITMAP *fondo = al_load_bitmap("sprites/jordy.jpg");
	ALLEGRO_BITMAP *malo  = al_load_bitmap ("sprites/enemigo.jpg");
	ALLEGRO_KEYBOARD_STATE estadoTeclado;
	ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS);
	ALLEGRO_EVENT_QUEUE *listaEventos = al_create_event_queue();

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


	// Ahora si comenzamos con lo del juego

	bool finJuego = false;
	float velocidad = 8.0, rotacion = 360.0;
	float x = AnchoPantalla/2, y = AltoPantalla/2;
	int right = 0, distancia_arma = 10;


	ALLEGRO_BITMAP *arma = al_load_bitmap("sprites/submachine.png");
	ALLEGRO_BITMAP *submachine = al_create_sub_bitmap(arma, 4, 4, 49, 21);
	al_convert_mask_to_alpha(mario, al_map_rgb(0,0,0));


	al_start_timer(timer);

	while(!finJuego)
	{
		ALLEGRO_EVENT eventos;

		al_wait_for_event(listaEventos, &eventos);


		if(eventos.type == ALLEGRO_EVENT_TIMER)
		{
			al_get_keyboard_state(&estadoTeclado);

			if(al_key_down(&estadoTeclado, ALLEGRO_KEY_Q) || al_key_down(&estadoTeclado, ALLEGRO_KEY_ESCAPE))
				finJuego = true;

			if(al_key_down(&estadoTeclado, ALLEGRO_KEY_LEFT))
			{
				right = 0;
				distancia_arma = 10;
				rotacion = 0.0;
				x -= velocidad;
			}		
			if(al_key_down(&estadoTeclado, ALLEGRO_KEY_RIGHT))
			{
				right = 1;
				distancia_arma = 0;
				rotacion = 0.0;
				x += velocidad;
			}
			if(al_key_down(&estadoTeclado, ALLEGRO_KEY_UP))
				{
					rotacion = -90.0;
					y -= velocidad;
				}
			if(al_key_down(&estadoTeclado, ALLEGRO_KEY_DOWN))
				{
					rotacion = 90.0;
					y += velocidad;
				}

		if(x <= 0) x = 0;
		if(x+32 >= AnchoPantalla) x = AnchoPantalla-32;
		if(y <= 0) y = 0;
		y += gravedad;
		if(y+42 >= AltoPantalla) y = AltoPantalla-42;

		}

		al_clear_to_color(al_map_rgb(0, 0, 0));
		al_draw_scaled_bitmap(fondo, 0, 0, 300, 290, 0, 0, AnchoPantalla, AltoPantalla, 0);
		al_draw_scaled_bitmap(mario, 0, 0, 16, 21, x, y, 32, 42, right);
		al_draw_bitmap(submachine, x - distancia_arma, y+15, right);
		al_draw_bitmap(malo, 10, 30, 0);

		al_flip_display();
	}

	al_destroy_bitmap(image);
	al_destroy_bitmap(mario);
	al_destroy_bitmap(arma);
	al_destroy_bitmap(submachine);
	al_destroy_event_queue(listaEventos);
	al_destroy_display(display);
	al_destroy_timer(timer);

	return 0;
}