Пример #1
0
ALLEGRO_EVENT_QUEUE *init(void) {
  if (!al_init()) {
    fprintf(stderr, "failed to initialize allegro!\n");
    exit(1);
  }

  if (!al_init_image_addon()) {
    fprintf(stderr, "nende nam addon pre obrazky. buuuu\n");
    exit(1);
  }


  ALLEGRO_EVENT_QUEUE *event_queue = NULL;
  event_queue = al_create_event_queue();
  if (!event_queue) {
    fprintf(stderr, "failed to create event queue!\n");
//    al_destroy_display(display);
    exit(1);
  }

  ALLEGRO_TIMER *timer = NULL;
  timer = al_create_timer(1.0/60.0);
  if (!timer) {
    fprintf(stderr, "failed to create timer!!!11!1\n");
    exit(1);
  }

  if (!al_install_keyboard()) {
    fprintf(stderr, "failed to install keyboard, press any key to continue\n");
    exit(1);
  }

//  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_register_event_source(event_queue,
      al_get_keyboard_event_source());

  al_start_timer(timer);

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

  return event_queue;
}
Пример #2
0
	void StateGameMode::InitState(ALLEGRO_DISPLAY *display, Settings *settings, Map *currentMap, ImageLoader *imageLoader){
		
		SetImageLoader(imageLoader);
		SetDisplay(display);
		SetSettings(settings);
		SetId(EnumDLL::STATES::EDITORMODE);
		SetEventQueue(NULL);
		SetRedraw(true);
		SetDone(false);
		SetRunning(true);
		SetKeyPressReturnVal(EnumDLL::STATES::DEFAULT);
		SetFont(al_load_font("arial.ttf", 20, 0));
		SetTimer(al_create_timer(1.0/60));
		SetEventQueue(al_create_event_queue());
		SetStateDirection(EnumDLL::STATEDIRECTION::NA);


		al_register_event_source(GetEventQueue(), al_get_keyboard_event_source());
		al_register_event_source(GetEventQueue(), al_get_mouse_event_source());
		al_register_event_source(GetEventQueue(), al_get_display_event_source(GetDisplay()));
		al_register_event_source(GetEventQueue(), al_get_timer_event_source(GetTimer()));
		SetMouseCursorPos(0,0);
		SetRightMousePos(0,0);
		SetRightMouseDown(false);
		SetLeftMouseDown(false);
		SetPlayerSelected(false);
		SetMap(currentMap);


		
		player1_ = new Player(GetSettings(),GetMap());
		player1_->SetGravityY(-9.8);

		for(int i = 0; i < GetImageLoader()->GetImageSetDictionary().size(); i++)
		{
			if(GetImageLoader()->GetImageSetDictionary()[i]->GetImageSetId() == EnumDLL::IMAGESETS::PLAYERIMAGESET)
			{
				player1_->SetObjectImageColor(GetImageLoader()->GetImageSetDictionary()[i]->GetImageDictionary()[0]);
			}
		}



		SetChosenColor(al_map_rgb_f(1,1,1));
		al_start_timer(GetTimer());
	}
Пример #3
0
bool WPJInputUtil::Init()
{
	int bRet;

	//	init input hardware driver
	bRet = al_is_keyboard_installed() && al_is_mouse_installed();

	//	init event_queue
	m_pEventQueue = al_create_event_queue();
	if (bRet && m_pEventQueue)
	{
		al_register_event_source(m_pEventQueue, al_get_keyboard_event_source());
		al_register_event_source(m_pEventQueue, al_get_mouse_event_source());
		al_register_event_source(m_pEventQueue, al_get_display_event_source(m_pDisplay));
	}

	return bRet;
}
Пример #4
0
EventQueue::EventQueue(Renderer* r) {
	//Obtém a event queue do Allegro, a registra e a torna default
	//Nós vamos obter nossos eventos a partir dela
	_allegro_queue = al_create_event_queue();

	// Inicia os subsistemas de teclado e mouse do Allegro
	al_install_keyboard();
	al_install_mouse();

	//Registra para receber eventos do display, do mouse e do teclado
	al_register_event_source(_allegro_queue,
		al_get_display_event_source(r->GetDisplay()));
	al_register_event_source(_allegro_queue,
		al_get_mouse_event_source());
	al_register_event_source(_allegro_queue,
		al_get_keyboard_event_source());

}
Пример #5
0
BaseGame::BaseGame(Vector2 windowSize, ScreenType screenType, string screenTitle, double fps) : fps(fps),
                   windowSize(windowSize), running(true)
{
	initScreen(screenType, screenTitle);
	initModules();

	al_get_keyboard_state(&keyState);
	al_get_mouse_state(&mouseState);

	eventQueue = al_create_event_queue();
	timer = al_create_timer(1/this->fps);

	//Events to read
	al_register_event_source(eventQueue, al_get_keyboard_event_source());
	al_register_event_source(eventQueue, al_get_timer_event_source(timer));
	al_register_event_source(eventQueue, al_get_display_event_source(display));
	al_register_event_source(eventQueue, al_get_mouse_event_source());
}
Пример #6
0
/* initialises the input emulation */
void init_input()
{
   ALLEGRO_JOYSTICK *joy;

   keybuf_len = 0;
   keybuf_mutex = al_create_mutex();

   input_queue = al_create_event_queue();
   al_register_event_source(input_queue, al_get_keyboard_event_source());
   al_register_event_source(input_queue, al_get_display_event_source(
			    al_get_current_display()));

   if (al_get_num_joysticks() > 0) {
      joy = al_get_joystick(0);
      if (joy)
	 al_register_event_source(input_queue, al_get_joystick_event_source(joy));
   }
}
Пример #7
0
GUI::~GUI()
{
	al_stop_timer(timer);
	al_unregister_event_source(queue, al_get_keyboard_event_source());
	al_unregister_event_source(queue, al_get_display_event_source(display));
	al_unregister_event_source(queue, al_get_timer_event_source(timer));
	al_destroy_event_queue(queue);

	al_destroy_bitmap(tiles);
	al_destroy_display(display);

	al_uninstall_keyboard();
	al_shutdown_font_addon();
	al_shutdown_primitives_addon();
	al_shutdown_image_addon();

    al_uninstall_system();
}
Пример #8
0
int main(int argc, char **argv)
{
   (void)argc;
   (void)argv;

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

   al_init_primitives_addon();
   al_install_keyboard();
   al_init_image_addon();
   al_init_font_addon();
   init_platform_specific();

   al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Error creating display\n");
   }

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

   picture = al_load_bitmap("data/mysha.pcx");
   if (!picture) {
      abort_example("mysha.pcx not found\n");
   }
   
   font = al_load_font("data/fixed_font.tga", 0, 0);
   if (!font) {
      abort_example("data/fixed_font.tga not found.\n");
   }

   redraw();
   run();

   al_destroy_display(display);

   al_destroy_event_queue(queue);

   return 0;
}
Пример #9
0
InputCatcher::InputCatcher(ALLEGRO_DISPLAY *display)
{
    // Create an event queue, and error if it fails
    event_queue = al_create_event_queue();
    if (!event_queue)
    {
        fprintf(stderr, "Fatal Error: Could not create event queue!");
        throw -1;
    }

    // Connect the window, keyboard and mouse events to this event queue
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
//    al_register_event_source(event_queue, al_get_mouse_event_source(display));

    std::ifstream configfile("config.json");
    config << configfile;
    configfile.close();
}
Пример #10
0
int CEngine::Init(void)
{
	// Init Allegro core.
	if (!al_init())
		return -1;
	// Load/manipulate image files.
	if (!al_init_image_addon())
		return -2;
	// Ability to draw primitives.
	if (!al_init_primitives_addon())
		return -3;
	// To receive keyboard events.
	if (!al_install_keyboard())
		return -4;
	// To receive mouse events.
	if (!al_install_mouse())
		return -5;

	m_display = al_create_display(1000, 600);
	if (!m_display)
		return -10;
	m_timer = al_create_timer(1.0f / 60.0f);
	if (!m_timer)
		return -11;
	m_evQ = al_create_event_queue();
	if (!m_evQ)
		return -12;

	// Get display events.
	al_register_event_source(m_evQ, al_get_display_event_source(m_display));
	// Get timer events.
	al_register_event_source(m_evQ, al_get_timer_event_source(m_timer));
	// Get keyboard events.
	al_register_event_source(m_evQ, al_get_keyboard_event_source());
	// Get mouse events.
	al_register_event_source(m_evQ, al_get_mouse_event_source());

	// Renderer that controls what is shown on the screen.
	m_renderer = new CRenderer(this);

	return 0;
}
Пример #11
0
static void show_image(ALLEGRO_BITMAP *bmp)
{
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());

   while (true) {
      al_draw_bitmap(bmp, 0, 0, 0);
      al_flip_display();
      al_wait_for_event(queue, &event);
      if (event.type == ALLEGRO_EVENT_KEY_DOWN
            && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
   }

   al_destroy_event_queue(queue);
}
Пример #12
0
DrawingClass::DrawingClass (int w, int h, Interface *interface) {
  al_init();
  mDisplay = al_create_display(w, h);
  al_set_window_title(mDisplay, "Tower Defense");
  mEventQueue = al_create_event_queue();
  mTimer = al_create_timer (1.0/((float)ConstFps));

  mInterface = interface;

  al_init_font_addon();
  al_init_ttf_addon();
  al_init_primitives_addon();
  al_install_mouse();
  al_install_keyboard();
  assert(al_install_audio());
  assert(al_init_acodec_addon());
  assert(al_reserve_samples(1));
  al_init_image_addon();

  al_register_event_source(mEventQueue, al_get_display_event_source(mDisplay));
  al_register_event_source(mEventQueue, al_get_timer_event_source(mTimer));
  al_register_event_source(mEventQueue, al_get_mouse_event_source());
  al_register_event_source(mEventQueue, al_get_keyboard_event_source());

  float tileSize = interface->GetTileSize();
  mBigFont = al_load_font("DejaVuSans.ttf", tileSize, 0);
  mFont = al_load_font("DejaVuSans.ttf", tileSize/2, 0);
  mSmallFont = al_load_font("DejaVuSans.ttf", tileSize/4, 0);
  mMusic = 0;

//  mBackground = al_create_bitmap(tileSize, tileSize);
  mBackground = al_load_bitmap("Images/grass.png");

/*   al_set_target_bitmap(mBackground);
 *   al_draw_filled_circle(tileSize/2, tileSize/2, tileSize/2, al_map_rgb(0, 255, 0));
 *   al_set_target_bitmap(al_get_backbuffer(mDisplay));
 */

  CreateMap();
}
Пример #13
0
bool Allegro::setup(int _width, int _height) {

#if(DEBUG_ALLEGROHELPER)
	con->print(debug, "- Allegro::setup - Start\n");
#endif

	// Arguments pass
	width = _width;
	height = _height;

	// Create display
	display = al_create_display(_width, _height);
	if (!display) {
		con->print(fatal, "failed to create display!\n");
		return false;
	}
#if(DEBUG_ALLEGROHELPER)
	con->print(debug, "-- Allegro::setup - al_create_display() successful\n");
#endif

	// Create Event Queue
	event_queue = al_create_event_queue();
	if (!event_queue) {
		con->print(fatal, "failed to create event_queue!\n");
		al_destroy_display(display);
		return false;
	}
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_mouse_event_source());
#if(DEBUG_ALLEGROHELPER)
	con->print(debug, "-- Allegro::setup - al_create_event_queue() successful\n");
#endif

#if(DEBUG_ALLEGROHELPER)
	con->print(debug, "- Allegro::setup - Success\n");
#endif

	return true;
}
Пример #14
0
int main()
{
	al_init();

	ALLEGRO_DISPLAY *display;
	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(800, 600);
	
	al_install_keyboard();

	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, al_get_keyboard_event_source());

	while(1)
	{
		ALLEGRO_EVENT event;
		if (al_get_next_event(event_queue, &event))
		{
			if (ALLEGRO_EVENT_DISPLAY_CLOSE == event.type)
			{
				break;
			}
			if(ALLEGRO_EVENT_KEY_UP == event.type)
			{
				if(event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
					break;
				}
			}
		}
		
		al_flip_display();
		al_clear_to_color(al_map_rgb(0, 0, 0));

		al_rest(0.001);
	}

	al_destroy_event_queue(event_queue);
	al_destroy_display(display);
}
int main(void)
{
   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }

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

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Error creating display\n");
      return 1;
   }

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

   myfont = al_load_font("data/font.tga", 0, 0);
   if (!myfont) {
      abort_example("font.tga not found\n");
      return 1;
   }

   while (!quit) {
      if (al_get_new_bitmap_flags() & ALLEGRO_FORCE_LOCKING)
         al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
      else
         al_set_new_bitmap_flags(ALLEGRO_FORCE_LOCKING);
      run();
   }

   al_destroy_event_queue(queue);  
   
   return 0;
}
Пример #16
0
bool Init()
{
    if (LoadConfigurationData(applicationConfig, styleConfig) == false)
        return false;

    al_init();

    if (applicationConfig.bfullscreen == true)
    {
        al_set_new_display_flags(ALLEGRO_FULLSCREEN);
    }
    al_set_app_name(applicationConfig.strAppName.c_str());
    al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE);
    display = al_create_display(applicationConfig.iDispW, applicationConfig.iDispH);

    al_install_keyboard();
    al_install_mouse();
    al_init_primitives_addon();
    al_init_image_addon();
    al_init_font_addon();
    al_init_ttf_addon();

    timer = al_create_timer(applicationConfig.dFps);
    queue = al_create_event_queue();
    textFont = al_load_ttf_font(styleConfig.strFontPath.c_str(), styleConfig.iFontSize, NULL);

    if ((display == nullptr) || (timer == nullptr) || (queue == nullptr) || (textFont == nullptr))
    {
        std::cout << "ERROR: Either the display, timer, queue or font failed to initialize!" << std::endl
            << "0x" << display << " 0x" << timer << " 0x" << queue << " 0x" << textFont << std::endl;
        return false;
    }

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

    return true;
}
Пример #17
0
int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_TIMER *timer;

   (void)argc;
   (void)argv;

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

   al_install_keyboard();
   al_install_mouse();
   al_init_image_addon();
   al_init_font_addon();
   init_platform_specific();

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Error creating display\n");
   }

   init();

   timer = al_create_timer(1.0 / ex.FPS);

   ex.queue = al_create_event_queue();
   al_register_event_source(ex.queue, al_get_keyboard_event_source());
   al_register_event_source(ex.queue, al_get_mouse_event_source());
   al_register_event_source(ex.queue, al_get_display_event_source(display));
   al_register_event_source(ex.queue, al_get_timer_event_source(timer));

   al_start_timer(timer);
   run();

   al_destroy_event_queue(ex.queue);  

   return 0;
}
Пример #18
0
Dialog::Dialog(const Theme & theme, ALLEGRO_DISPLAY *display,
      int grid_m, int grid_n):
   theme(theme),
   display(display),
   grid_m(grid_m),
   grid_n(grid_n),
   x_padding(1),
   y_padding(1),

   draw_requested(true),
   quit_requested(false),
   mouse_over_widget(NULL),
   mouse_down_widget(NULL),
   key_widget(NULL),

   event_handler(NULL)
{
   this->event_queue = al_create_event_queue();
   al_register_event_source(this->event_queue, al_get_keyboard_event_source());
   al_register_event_source(this->event_queue, al_get_mouse_event_source());
   al_register_event_source(this->event_queue, al_get_display_event_source(display));
}
Пример #19
0
void GameEngine::Init()
{
	done = false;

	input = new InputHandler();
	collisionDetector = new CollisionDetector();

	menuState = new State_Menu();
	gameState = new State_Game();

	states.push_back(menuState);
	states.push_back(gameState);

	

	al_init(); //Initialises the allegro library
	al_install_keyboard();
	al_install_mouse();
	
	al_set_new_display_flags(ALLEGRO_RESIZABLE);
	al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
	al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR);
	al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
	al_set_new_display_option(ALLEGRO_SAMPLES, 6, ALLEGRO_SUGGEST);

    display = al_create_display(WIDTH, HEIGHT);
	al_set_window_title(display, "Vinctus Arce");
    
    eventQueue = al_create_event_queue();
    al_register_event_source(eventQueue, al_get_display_event_source(display));
    al_register_event_source(eventQueue, al_get_keyboard_event_source());
	al_register_event_source(eventQueue, al_get_mouse_event_source());

    timer = al_create_timer(1.0f / FPS);
    al_register_event_source(eventQueue, al_get_timer_event_source(timer));
    al_start_timer(timer);

	PushState(menuState);
}
Пример #20
0
void Juego::init(){
    //Iniciando Componentes (Imagenes y teclado)
    al_init();
    al_init_image_addon();
    al_install_keyboard();


    //Iniciando Pantalla "display"
    display = al_create_display(this->filas*50,this->cols*50);

    //Creando Timer y Eventero
    this->timer = al_create_timer(1.0/ this->FPS);
    this->event_queue = al_create_event_queue();

    //Registradores de eventos
    al_register_event_source(this->event_queue, al_get_display_event_source(this->display));
    al_register_event_source(this->event_queue, al_get_keyboard_event_source());
    al_register_event_source(this->event_queue, al_get_timer_event_source(this->timer));

    al_flip_display();
    al_start_timer(this->timer);
}
Пример #21
0
void Core::Init()
{
	// Attempt to initialize allegro; if unsuccessful, show an error.
	if (!al_init())
	{
		al_show_native_message_box(NULL, "Error", "Error", 
			"Failed to initialize Allegro.", NULL, NULL);
	}

	// Attempt to create display; if unsuccessful, show an error.
	al_set_new_display_flags(ALLEGRO_OPENGL);
	display = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT);
	if (!display)
	{
		al_show_native_message_box(NULL, "Error", "Error", 
			"Failed to create display.", NULL, NULL);
	}

	// Install keyboard, mouse and image addons
	al_install_keyboard();
	al_install_mouse();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();

	// Create timer
	timer = al_create_timer(1.0f / FPS);

	// Create event queue and register event sources
	evQueue = al_create_event_queue();
	al_register_event_source(evQueue, al_get_keyboard_event_source());
	al_register_event_source(evQueue, al_get_timer_event_source(timer));
	al_register_event_source(evQueue, al_get_display_event_source(display));

	player.Init(this);
	food.Init(player);
	powerup.Init(player);
	overlay.Init();
}
void init_allegro(){
  if(!al_init()) {
    fprintf(stderr, "Failed to initialize allegro!\n");
  }

  if(!al_install_keyboard()) {
    fprintf(stderr, "Failed to initialize the keyboard!\n");
  }

  if(!al_init_primitives_addon()) {
    fprintf(stderr, "failed to create primitives addon!\n");
  }

  al_init_font_addon();
  default_font = al_create_builtin_font();
  if (!default_font)
    fprintf(stderr, "Failed to create builtin font");

  timer = al_create_timer(1.0 / FPS);
  if(!timer) {
    fprintf(stderr, "failed to create timer!\n");
  }

  display = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT);
  if(!display){
    fprintf(stderr, "Failed to create display!\n");
  }

  event_queue = al_create_event_queue();
  if(!event_queue) {
    fprintf(stderr, "failed to create event_queue!\n");
  }

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

  atexit(destroy_allegro);
}
Пример #23
0
void init(void)
{
    if (!al_init())
        abort_game("Failed to initialize allegro");
 
    if (!al_install_keyboard())
        abort_game("Failed to install keyboard");
    if (!al_init_primitives_addon())
        abort_game("Failed to install primitives");
    al_init_font_addon(); // initialize the font addon
    al_init_ttf_addon();// initialize the ttf (True Type Font) addon 

    timer = al_create_timer(1.0 / 60);
    if (!timer)
        abort_game("Failed to create timer");
 
    ALLEGRO_DISPLAY_MODE disp_data;
    al_get_display_mode(0, &disp_data);
   
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    //display = al_create_display(disp_data.width, disp_data.height);
    display = al_create_display(800, 480);
    if (!display)
        abort_game("Failed to create display");
 
    event_queue = al_create_event_queue();
    if (!event_queue)
        abort_game("Failed to create event queue");
    
    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));
    
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
    
    font = al_load_ttf_font("src/Atari_Full.ttf", 16,0 );

    done = false;
}
Пример #24
0
void
error_display(const char *text)
{
  ALLEGRO_DISPLAY *disp;
  ALLEGRO_EVENT_QUEUE *ev_queue;
  ALLEGRO_FONT *font;

  al_init();
  al_install_keyboard();
  al_install_mouse();
  al_init_font_addon();

  al_set_new_display_flags(ALLEGRO_WINDOWED);
  al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
  disp = al_create_display(640, 480);
  al_set_window_title(disp, "mruby-minigame");

  ev_queue = al_create_event_queue();

  al_register_event_source(ev_queue, al_get_display_event_source(disp));
  al_register_event_source(ev_queue, al_get_keyboard_event_source());
  al_register_event_source(ev_queue, al_get_mouse_event_source());

  font = al_create_builtin_font();

  for (;;) {
    ALLEGRO_EVENT ev;
    while (al_get_next_event(ev_queue, &ev)) {
      if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) goto done;
    }

    al_clear_to_color(al_map_rgb(200, 120, 120));
    al_draw_multiline_text(font, al_map_rgb(255, 255, 255), 64, 64, 640-64, 10, ALLEGRO_ALIGN_LEFT, text);
    al_flip_display();
  }
done:
  return;
}
Пример #25
0
void Input::Process ()
    {
    ALLEGRO_EVENT event;

    while ( al_get_next_event(al_events, &event) )
        {
        if ( event.any.source == al_get_keyboard_event_source() )
            {
            if ( event.keyboard.type == ALLEGRO_EVENT_KEY_CHAR )
                {
                unsigned int anymods = event.keyboard.modifiers;
                // clear these first
                anymods &= ~(ALLEGRO_KEYMOD_SCROLLLOCK |
                             ALLEGRO_KEYMOD_NUMLOCK |
                             ALLEGRO_KEYMOD_CAPSLOCK);
                               
                switch ( event.keyboard.keycode )
                    {
                    // FIXME  use a proper keybinding system
                    case ALLEGRO_KEY_Q:
                        if ( (event.keyboard.modifiers & anymods) == 
                             ALLEGRO_KEYMOD_CTRL )
                            mcp::eventq.Add(event::EXIT);
                        break;

                    default:
                        break;
                    }
                }
            }
        else if ( event.any.source == al_get_mouse_event_source() )
            {
            }
        else
            assert(false);
            
        }
    }
Пример #26
0
int init_allegro(Camera *cam)
{
	if (!al_init())
		return 1;
	if (!al_install_mouse())
		return 1;
	if (!al_install_keyboard())
		return 1;
	
	al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL | ALLEGRO_OPENGL_FORWARD_COMPATIBLE | ALLEGRO_RESIZABLE);
	
	al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);

	dpy = al_create_display(cam->left + cam->width, cam->bottom + cam->height);
	glViewport(cam->left, cam->bottom, cam->width, cam->height);

	ev_queue = al_create_event_queue();
	al_register_event_source(ev_queue, al_get_display_event_source(dpy));
	al_register_event_source(ev_queue, al_get_mouse_event_source());
	al_register_event_source(ev_queue, al_get_keyboard_event_source());

	return 0;
}
Пример #27
0
  bool					init()
  {
    if (!al_install_keyboard())
      return false;
    if (!al_install_mouse())
      return false;
    this->event_queue_ = al_create_event_queue();
    if (!this->event_queue_)
      return false;
    this->timer_ = al_create_timer(1.0f / 120.0f);
    if (!this->timer_)
      return false;
    if (!al_install_joystick())
      return false;
    al_register_event_source(this->event_queue_, al_get_keyboard_event_source());
    // al_register_event_source(this->event_queue_, al_get_joystick_event_source());
    al_register_event_source(this->event_queue_, al_get_mouse_event_source());
    al_register_event_source(this->event_queue_, al_get_display_event_source(al_get_current_display()));
    al_register_event_source(this->event_queue_, al_get_timer_event_source(this->timer_));
    al_start_timer(this->timer_);

    return true;
  }
Пример #28
0
	void StateEditorMode::InitState(ALLEGRO_DISPLAY *display, Settings *settings, Map *currentMap, ImageLoader *imageLoader){
		
		SetImageLoader(imageLoader);
		SetDisplay(display);
		SetSettings(settings);
		SetId(EnumDLL::STATES::EDITORMODE);
		SetEventQueue(NULL);
		SetRedraw(true);
		SetDone(false);
		SetRunning(true);
		SetKeyPressReturnVal(EnumDLL::STATES::DEFAULT);
		SetFont(al_load_font("arial.ttf", 20, 0));
		SetTimer(al_create_timer(1.0/60));
		SetEventQueue(al_create_event_queue());
		SetStateDirection(EnumDLL::STATEDIRECTION::NA);


		al_register_event_source(GetEventQueue(), al_get_keyboard_event_source());
		al_register_event_source(GetEventQueue(), al_get_mouse_event_source());
		al_register_event_source(GetEventQueue(), al_get_display_event_source(GetDisplay()));
		al_register_event_source(GetEventQueue(), al_get_timer_event_source(GetTimer()));
		SetMouseCursorPos(0,0);
		SetRightMousePos(0,0);
		SetRightMouseDown(false);
		SetLeftMouseDown(false);
		SetPlayerSelected(false);
		SetMap(currentMap);



		editorOverLayController_ = new EditorOverLayController(settings, imageLoader);



		SetChosenColor(al_map_rgb_f(1,1,1));
		al_start_timer(GetTimer());
	}
Пример #29
0
//Constructor - loads background and buttons, registers keyboard input and sets
//the current state manager. Also initialises necessary variables
Table::Table(GamestateManager *_stateManager)
{
	m_stateManager = _stateManager;
	
	m_bgImage = al_load_bitmap("Images/Blackjack Table.jpg");

	if(m_bgImage == NULL)
		printf("Could not load Menu BG");

	m_cardIMGs = al_load_bitmap("Images/Playing Cards.png");

	if( m_cardIMGs == NULL )
		printf("Could not load Playing Cards");

	m_exitButton = al_load_bitmap("Images/Exit Button.png");

	if( m_exitButton == NULL )
		printf("Could not load Exit Button");

	m_eventQueue = al_create_event_queue();
	al_register_event_source( m_eventQueue, al_get_keyboard_event_source());

	al_reserve_samples(1);
	m_bgMusic = al_load_sample("The_Lounge.ogg");

	if( m_bgMusic == NULL )
		printf("Could not load BG Music");

	al_play_sample(m_bgMusic,1,1,1,ALLEGRO_PLAYMODE_LOOP,NULL);

	m_font = al_load_font("GOTHICB.ttf", 26, 0);

	m_state = State::State::GET_PLAYERS;
	m_keyboard = Keyboard::Keyboard::NONE;
	m_activePlayer = 0;
	m_numPlayers = 0;
}
Пример #30
0
void GameEngine::Init() {
    running = true;
    
    al_init(); //Initialises the allegro library
    al_init_image_addon();
    al_init_font_addon();
    al_init_ttf_addon();
    
    display = al_create_display(scrx, scry);
	al_set_window_title(display, "Knights");
    
	al_install_keyboard(); //Installs keyboard driver
    
    eventQueue = al_create_event_queue();
    redrawQueue = al_create_event_queue();
    al_register_event_source(eventQueue, al_get_display_event_source(display));
    al_register_event_source(eventQueue, al_get_keyboard_event_source());

    redrawTimer = al_create_timer(1.0f / FPS);
    al_register_event_source(redrawQueue, al_get_timer_event_source(redrawTimer));
    al_start_timer(redrawTimer);
    
	srand((int)time(NULL)); //Randomises the numbers used in program so that it's not the same each time.
}