Ejemplo n.º 1
0
static void log_key(char const *how, int keycode, int unichar, int modifiers)
{
   char multibyte[5] = {0, 0, 0, 0, 0};
   const char* key_name;

   al_utf8_encode(multibyte, unichar <= 32 ? ' ' : unichar);
   key_name = al_keycode_to_name(keycode);
   log_printf("%-8s  code=%03d, char='%s' (%4d), modifiers=%08x, [%s]\n",
      how, keycode, multibyte, unichar, modifiers, key_name);
}
Ejemplo n.º 2
0
static int allua_keycode_from_name(lua_State * L)
{
   const char *keyname = luaL_checkstring(L, 1);

   int keycode = 0;
   int i = 0;
   for (; i < ALLEGRO_KEY_MAX; ++i) {
      if (!strncmp(al_keycode_to_name(i), keyname, 32)) {
         keycode = i;
      }
   }
   lua_pushinteger(L, keycode);
   return 1;
}
Ejemplo n.º 3
0
		void KeyboardEvent::run_procs(VALUE *observer, int type, int *keycode)
		{
			for (int i = 0; i < RARRAY_LEN(*observer); i++)
			{

				if (keycode_names)
					key = rb_str_new_cstr(al_keycode_to_name(*keycode));
				else if (unichar)
					key = rb_str_new_cstr((char*)keycode);
				else
					key = INT2FIX(*keycode);
				
				rb_proc_call_with_block(rb_ary_entry(*observer, i), 1, &key, 
								        rb_ary_entry(*observer, i));
			}
		}
Ejemplo n.º 4
0
void ask_for_level(al_defs *al, char *name) {
  int pos=0;
  name[0]='\0';
  ALLEGRO_EVENT ev;
  while(true) {
    draw_background(al);
    al_draw_text(al->menu_font,al_map_rgb(255,255,255),
        al->width/2,80,ALLEGRO_ALIGN_CENTRE,"Please enter the level name:");
    al_draw_textf(al->menu_font,al_map_rgb(150,150,150),
        al->width/2,140,ALLEGRO_ALIGN_CENTRE,"%s",name);
    al_draw_text(al->hint_font, al_map_rgb(120,120,120),
        al->width/2,al->height-40,ALLEGRO_ALIGN_CENTRE,
        "Only alphanumeric and spacebar (will be shown as underscore)");
    al_flip_display();
    al_wait_for_event(al->queue, &ev);
    if(ev.type != ALLEGRO_EVENT_KEY_DOWN)
      continue;

    if(ev.keyboard.keycode==ALLEGRO_KEY_ENTER) {
      if(strcmp(name,"levels")!=0)
        break;
    }

    if(ev.keyboard.keycode==ALLEGRO_KEY_BACKSPACE) {
      if(pos>0) 
        name[--pos]='\0';
    }

    if((ev.keyboard.keycode > 0 && ev.keyboard.keycode < 37) 
        || ev.keyboard.keycode == 75) {
      if(ev.keyboard.keycode==75) {
        name[pos++] = '_';
      }else{
        name[pos++] = *(al_keycode_to_name(ev.keyboard.keycode));
      }
      name[pos]='\0';
      if(pos>200) pos--;
    }
  }
}
Ejemplo n.º 5
0
void SettingsStage::Render()
{
	ALLEGRO_COLOR itemColour = al_map_rgb(255, 255, 255);
	ALLEGRO_COLOR selectedColour = al_map_rgb(255, 255, 0);
	ALLEGRO_COLOR disabledColour = al_map_rgb(96, 96, 96);

	al_clear_to_color( al_map_rgb( 48, 64, 96 ) );

	int yPos = 40 - scrollPosition;
	int curItem = 0;
	al_draw_text( titleFont, al_map_rgb( 255, 192, 96 ), FRAMEWORK->Display_GetWidth() / 2, yPos, ALLEGRO_ALIGN_CENTRE, "Video" );
	yPos += titleFontHeight;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Fullscreen : Yes" );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Shader : Scanlines" );
	yPos += itemFontHeight; curItem++;

	yPos += 20;
	al_draw_text( titleFont, al_map_rgb( 255, 192, 96 ), FRAMEWORK->Display_GetWidth() / 2, yPos, ALLEGRO_ALIGN_CENTRE, "Audio" );
	yPos += titleFontHeight;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Music: %s", (FRAMEWORK->Settings->GetQuickBooleanValue( "Audio.Music", true ) ? "Yes" : "No") );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "SoundFX : %s", (FRAMEWORK->Settings->GetQuickBooleanValue( "Audio.SFX", true ) ? "Yes" : "No") );
	yPos += itemFontHeight; curItem++;

	yPos += 20;
	al_draw_text( titleFont, al_map_rgb( 255, 192, 96 ), FRAMEWORK->Display_GetWidth() / 2, yPos, ALLEGRO_ALIGN_CENTRE, "Left Player Controls" );
	yPos += titleFontHeight;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Up Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Left.Up", ALLEGRO_KEY_UP ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Down Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Left.Down", ALLEGRO_KEY_DOWN ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Send Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Left.Send", ALLEGRO_KEY_RIGHT ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 1 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Left.Inv1", ALLEGRO_KEY_Q ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 2 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Left.Inv2", ALLEGRO_KEY_A ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 3 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Left.Inv3", ALLEGRO_KEY_Z ) ) );
	yPos += itemFontHeight; curItem++;

	yPos += 20;
	al_draw_text( titleFont, al_map_rgb( 255, 192, 96 ), FRAMEWORK->Display_GetWidth() / 2, yPos, ALLEGRO_ALIGN_CENTRE, "Right Player Controls" );
	yPos += titleFontHeight;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Up Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Right.Up", ALLEGRO_KEY_PGUP ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Down Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Right.Down", ALLEGRO_KEY_PGDN ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Send Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Right.Send", ALLEGRO_KEY_HOME ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 1 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Right.Inv1", ALLEGRO_KEY_O ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 2 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Right.Inv2", ALLEGRO_KEY_K ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 3 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Right.Inv3", ALLEGRO_KEY_M ) ) );
	yPos += itemFontHeight; curItem++;

	yPos += 20;
	al_draw_text( titleFont, al_map_rgb( 255, 192, 96 ), FRAMEWORK->Display_GetWidth() / 2, yPos, ALLEGRO_ALIGN_CENTRE, "Network Game Controls" );
	yPos += titleFontHeight;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Up Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Network.Up", ALLEGRO_KEY_PGUP ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Down Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Network.Down", ALLEGRO_KEY_PGDN ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Send Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Network.Send", ALLEGRO_KEY_HOME ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 1 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Network.Inv1", ALLEGRO_KEY_O ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 2 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Network.Inv2", ALLEGRO_KEY_K ) ) );
	yPos += itemFontHeight; curItem++;
	al_draw_textf( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Inventory 3 Key : %s", al_keycode_to_name( FRAMEWORK->Settings->GetQuickIntegerValue( "Network.Inv3", ALLEGRO_KEY_M ) ) );
	yPos += itemFontHeight; curItem++;

	yPos += 20;
	al_draw_text( titleFont, al_map_rgb( 255, 192, 96 ), FRAMEWORK->Display_GetWidth() / 2, yPos, ALLEGRO_ALIGN_CENTRE, "Other" );
	yPos += titleFontHeight;
	al_draw_text( itemFont, (selectedItem == curItem ? selectedColour : itemColour), 40, yPos, ALLEGRO_ALIGN_LEFT, "Return" );
	yPos += itemFontHeight; curItem++;

	Shader* s = new ShaderScanlines();
	s->Apply( FRAMEWORK->Display_GetCurrentTarget() );
	delete s;
}
Ejemplo n.º 6
0
static int allua_keycode_to_name(lua_State * L)
{
   int keycode = luaL_checkint(L, 1);
   lua_pushstring(L, al_keycode_to_name(keycode));
   return 1;
}
Ejemplo n.º 7
0
void Tela::processa_eventos() {
    /* processa eventos do servidor X, atualizando a posicao do mouse
     * e ultima _tecla pressionada na variavel da tela. */
    ALLEGRO_EVENT event;

    // al_wait_for_event(queue, &event);
    while (al_get_next_event(queue, &event)) {
        switch (event.type) {
        /* _tecla foi pressionada */
	case ALLEGRO_EVENT_KEY_CHAR:
	  {
#if 0
	    const char* keyname = al_keycode_to_name(event.keyboard.keycode);
	    printf("code %x modif %x char '%c' name '%s' (q=%d)\n", event.keyboard.keycode,
		   event.keyboard.modifiers, (char)event.keyboard.keycode, keyname, 'Q');
#endif
	    _tecla = event.keyboard.keycode;
	    _modif = event.keyboard.modifiers;
	    break;
	  }
#if 0
        case ALLEGRO_EVENT_KEY_DOWN: {
            /* const char* keyname = al_keycode_to_name(event.keyboard.keycode);
            printf("code %d char '%c' name '%s' (q=%d)\n",
            event.keyboard.keycode,
              (char)event.keyboard.keycode, keyname, 'Q');*/
            _tecla = event.keyboard.keycode;
            break;
        }
#endif
        case ALLEGRO_EVENT_MOUSE_AXES: {
            _rato.x = XX2U(event.mouse.x);
            _rato.y = YX2U(event.mouse.y);
            break;
        }
        case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: {
            if (event.mouse.button == 1)
                _botao = true;
            break;
        }
        case ALLEGRO_EVENT_MOUSE_BUTTON_UP: {
            if (event.mouse.button == 1)
                _botao = false;
            break;
        }
        case ALLEGRO_EVENT_TIMER: {
            break;
        }
#if 0
	  /* _botao de fechar janela pressionado */
	  case ALLEGRO_EVENT_DISPLAY_CLOSE:
		  {
			  return;
			  break;
		  }
#endif
        default:
            break;
        }
    }
}
Ejemplo n.º 8
0
int main()
{
  if(!ALLEGRO5_INIT) allegro5_init();
  
  short int      option;
  char           options_list[][50] =
                 {
                   "Start",
                   "Exit",
                   "Help",
                   "-"
                 };
  
  volatile int       i = 0;
  long int           life = 100;
  char               key_char[50];
  bool               terminou = false,
                     redraw   = true;
  LifeBar            lifeBar;
  Font               global_font;
  ALLEGRO_EVENT      ev;
  
  lifeBar.open(200, 0, 0, SCREEN_W/2, 50, "resource\\LifeBars\\001.bmp", INVISIBLE);
  
  global_font.open("resource\\Font\\impressedMetal.ttf", 32, 0, WHITE);
  log.append("Font...OK");
  
  Loading(global_font);
  
  option = StartGame(
    "resource\\StartGame\\Sprites\\intro.bmp", 
    "resource\\StartGame\\Snd\\background.wav", 
    "resource\\StartGame\\Sprites\\csr.bmp", 
    "resource\\StartGame\\Snd\\csr.wav", 
    "resource\\Font\\impressedMetal.ttf", 
    options_list);
  
  log.append("\t\tLoop principal");
    
  al_start_timer(global_timer);
  
  al_clear_to_color(BLACK);
  al_flip_display();
  
  while(!terminou)
  {
    al_wait_for_event(eventos_globais, &ev);
    
    switch(ev.type)
    {
      case ALLEGRO_EVENT_DISPLAY_CLOSE:
        terminou = true;
        break;
        
      case ALLEGRO_EVENT_TIMER:
        if(ev.timer.source == global_timer)
          redraw = true;
        break;
        
      case KEY_DOWN:
        strcpy(key_char, al_keycode_to_name(ev.keyboard.keycode));
        
        if( StringCompareNoCase(key_char, "escape") ) terminou = true;
        
        else if( StringCompareNoCase(key_char, "down") ){ }
          
        else if( StringCompareNoCase(key_char, "up") ){ }
        
        else if( StringCompareNoCase(key_char, "right") ){ }
          
        else if( StringCompareNoCase(key_char, "left") ){ }
        
      break;
      
      /**************************
          Soltou uma tecla
      ***************************/
      case KEY_UP:
        strcpy(key_char, al_keycode_to_name(ev.keyboard.keycode));
        break;
    }
    
    if(redraw && al_is_event_queue_empty(eventos_globais) && !terminou)
    {
      redraw = false;

      al_set_target_bitmap(al_get_backbuffer(display));
      
      lifeBar.print(life);
      if(life > 0)life--;
      else
        life = 200;
      global_font.print(0, SCREEN_H/2, "Teste");

      al_flip_display();
      al_clear_to_color(BLACK);
    }
  }
  
  al_stop_samples();
  
  Fim("resource\\Font\\Resident_Evil_Large.ttf");
  
  al_destroy_display(display);
  al_destroy_event_queue(eventos_globais);
  al_destroy_timer(global_timer);
  
  log.append("\t\tLoop principal...OK");
  log.append("[FIM]");
  log.close();
}