コード例 #1
0
ファイル: g_misc.c プロジェクト: Abstrusle/LCTourn
void wait_for_space(void)
{

 ALLEGRO_EVENT ev;

 ALLEGRO_KEYBOARD_STATE wait_key_State;

 fprintf(stdout, "\n     press space to continue\n\r");

 int unpressed = 0;

 while(TRUE)
 {
  al_wait_for_event(event_queue, &ev);
  al_get_keyboard_state(&wait_key_State);

  if(!al_key_down(&wait_key_State, ALLEGRO_KEY_SPACE))
   unpressed = 1;

  if(al_key_down(&wait_key_State, ALLEGRO_KEY_ESCAPE))
   safe_exit(0);

  if(unpressed && al_key_down(&wait_key_State, ALLEGRO_KEY_SPACE))
   return;
 };


}
コード例 #2
0
ファイル: ninja.cpp プロジェクト: ryonagana/gameengine
void NinjaMove(ALLEGRO_KEYBOARD_STATE *kb, bninja *Ninja){


        al_get_keyboard_state(kb);

    if (al_key_down(kb, ALLEGRO_KEY_LEFT))
        Ninja->x +=  Ninja->speed * AbsoluteVal(Ninja->x - SCREEN_WIDTH);


    if (al_key_down(kb, ALLEGRO_KEY_RIGHT))
        Ninja->x -=  Ninja->speed * AbsoluteVal(Ninja->x - SCREEN_WIDTH);
     // return -1.0f;


    //ALLEGRO_KEYBOARD_STATE kbdstate;


    //int key = readkey();


    //if(key[ALLEGRO_KEY_RIGHT])
    //Ninja->x -=  Ninja->speed * AbsoluteVal(Ninja->x - SCREEN_W);

    //if( key[KEY_LEFT] )
    //Ninja->x +=  Ninja->speed * AbsoluteVal(Ninja->x - SCREEN_W);

}
コード例 #3
0
ファイル: equipAligner.cpp プロジェクト: Screetch/GrandTale
void equipAligner::update(double timeStep){
	ALLEGRO_MOUSE_STATE mS;
	al_get_mouse_state(&mS);
	ALLEGRO_KEYBOARD_STATE kS;
	al_get_keyboard_state(&kS);
	ALLEGRO_EVENT ev;
	if (al_get_next_event(eventQueue,&ev)) {
			switch (ev.type) {
				case ALLEGRO_EVENT_KEY_UP: {
					if (ev.keyboard.keycode==ALLEGRO_KEY_O) {
							if (al_key_down(&kS,ALLEGRO_KEY_LCTRL)) {
								this->pickAlignmentPiece();
							}
						}
					if (ev.keyboard.keycode==ALLEGRO_KEY_S) {
							if (al_key_down(&kS,ALLEGRO_KEY_LCTRL)) {
								this->saveAlignmentPieceData();
							}
						}
					if (ev.keyboard.keycode==ALLEGRO_KEY_SPACE) {
						if (imageAlignAlpha==1) { imageAlignAlpha=0.6; }else{ imageAlignAlpha = 1;}

						}
					
					break;
				}
					 case ALLEGRO_EVENT_KEY_CHAR: {

					if (ev.keyboard.keycode==ALLEGRO_KEY_RIGHT) {
						aligningImageProperties.offsetX += 1;
					}
					if (ev.keyboard.keycode==ALLEGRO_KEY_LEFT) {
						aligningImageProperties.offsetX -= 1;
					}
					if (ev.keyboard.keycode==ALLEGRO_KEY_UP) {
						aligningImageProperties.offsetY -= 1;
					}
					if (ev.keyboard.keycode==ALLEGRO_KEY_DOWN) {
						aligningImageProperties.offsetY+= 1;
					}
					if (ev.keyboard.keycode==ALLEGRO_KEY_D) {
						selectedBodyPart++;
						if (selectedBodyPart>availableBodyParts.size()-1) {
							selectedBodyPart = 0;
						}
					}
					if (ev.keyboard.keycode==ALLEGRO_KEY_A) {
						selectedBodyPart--;
						if (selectedBodyPart<0) {
							selectedBodyPart = availableBodyParts.size()-1;
						}

					}
					break;
					 }
			}

	}

}
コード例 #4
0
bool Figura_Zawijak_Prawy::Move_0 ( ALLEGRO_KEYBOARD_STATE &keyState , const std::vector< std::array<DataMap,10> > & Map ) 
{
	if( al_key_down(&keyState , ALLEGRO_KEY_DOWN) )
	{
		//std::cout << "Figura_Kwadrat::Move" << std::endl ;
		if( Figura[1].y + 1 < 16 )
		{
			//std::cout << "Figura_Kwadrat::Move2222222222222222" << std::endl ;
			if( !Map[ (Figura[0].y + 1) ][ Figura[0].x ].Draw && !Map[ (Figura[1].y + 1) ][ Figura[1].x ].Draw &&
				!Map[ (Figura[3].y + 1) ][ Figura[3].x ].Draw )
			{

				//std::cout << "Figura_Kwadrat::Move3333333333333333333333" << std::endl ;
				for(int i = 0 ; i < 4 ; i++)
				{
					Figura[i].y = Figura[i].y + 1 ;
				}
				return true ;
			}
		}
	}
	else if( al_key_down(&keyState , ALLEGRO_KEY_LEFT) )
	{
		if( Figura[3].x - 1 >= 0 )
		{
			if( !Map[ Figura[3].y ][ Figura[3].x - 1 ].Draw && !Map[ Figura[1].y ][ Figura[1].x - 1 ].Draw )
			{
				for(int i = 0 ; i < 4 ; i++)
					Figura[i].x = Figura[i].x - 1 ;
				return true ;
			}
		}
	}
	else if( al_key_down(&keyState , ALLEGRO_KEY_RIGHT) )
	{
		if( Figura[0].x + 1 < 10 )
		{
			if( !Map[ Figura[0].y ][ Figura[0].x + 1 ].Draw && !Map[ Figura[2].y ][ Figura[2].x - 1 ].Draw) 
			{
				for(int i = 0 ; i < 4 ; i++)
					Figura[i].x = Figura[i].x + 1 ;
				return true ;
			}
		}
	}
	//ZMIANA POZYCJI
	else if( Change_Position1 )
	{
		if( al_key_down(&keyState , ALLEGRO_KEY_SPACE) )
		{
			if( Change_Position ( Map ) )
			{
				Change_Position1 = false ;
				return true ;
			}
		}
	}
	return false ;
}
コード例 #5
0
ファイル: UserInput.cpp プロジェクト: ElsonC/stonesense
/**
 * Returns a keymod bitflag consistent with allegro keycodes for the CTRL, ALT, and SHIFT keys
 * from a given keyboard state.
 */
int32_t getKeyMods(ALLEGRO_KEYBOARD_STATE * keyboardstate){
    int32_t keymod = 0;
    if(al_key_down(keyboardstate,ALLEGRO_KEY_LSHIFT) || al_key_down(keyboardstate,ALLEGRO_KEY_RSHIFT)){
        keymod |= ALLEGRO_KEYMOD_SHIFT;
    }
    if(al_key_down(keyboardstate,ALLEGRO_KEY_LCTRL) || al_key_down(keyboardstate,ALLEGRO_KEY_RCTRL)){
        keymod |= ALLEGRO_KEYMOD_CTRL;
    }
    if(al_key_down(keyboardstate,ALLEGRO_KEY_ALT)){
        keymod |= ALLEGRO_KEYMOD_ALT;
    }
    return keymod;
}
コード例 #6
0
void GameLevelState::Update(GameTime* gameTime)
{
	if(!al_key_down(keyState, ALLEGRO_KEY_P) && al_key_down(prevKeyState, ALLEGRO_KEY_P))
		paused = !paused;

	if(paused) {
		pauseMenu.Update(gameTime, mouseState, prevMouseState);
		if(pauseMenu.finished())
			paused = !paused;
	}
	else
		level.Update(gameTime, keyState, prevKeyState, mouseState, prevMouseState);
}
コード例 #7
0
void ImGui_ImplAllegro5_NewFrame()
{
    if (!g_Texture)
        ImGui_ImplAllegro5_CreateDeviceObjects();

    ImGuiIO &io = ImGui::GetIO();

    // Setup display size (every frame to accommodate for window resizing)
    int w, h;
    w = al_get_display_width(g_Display);
    h = al_get_display_height(g_Display);
    io.DisplaySize = ImVec2((float)w, (float)h);

    // Setup time step
    double current_time = al_get_time();
    io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
    g_Time = current_time;

    // Setup inputs
    ALLEGRO_KEYBOARD_STATE keys;
    al_get_keyboard_state(&keys);
    io.KeyCtrl = al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL);
    io.KeyShift = al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT);
    io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR);
    io.KeySuper = al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN);

    ImGui_ImplAllegro5_UpdateMouseCursor();
}
コード例 #8
0
bool Figura_Kwadrat::Move ( ALLEGRO_KEYBOARD_STATE &keyState , const std::vector< std::array<DataMap,10> > & Map )
{
	
	if( al_key_down(&keyState , ALLEGRO_KEY_DOWN) )
	{
		//std::cout << "Figura_Kwadrat::Move" << std::endl ;
		if( Figura[2].y + 1 < 16 )
		{
			//std::cout << "Figura_Kwadrat::Move2222222222222222" << std::endl ;
			if( !Map[ Figura[2].y + 1 ][ Figura[2].x ].Draw && !Map[ Figura[3].y + 1 ][ Figura[3].x ].Draw )
			{

				//std::cout << "Figura_Kwadrat::Move3333333333333333333333" << std::endl ;
				for(int i = 0 ; i < 4 ; i++)
				{
					Figura[i].y = Figura[i].y + 1 ;
				}
				return true ;
			}
		}
	}
	else if( al_key_down(&keyState , ALLEGRO_KEY_LEFT) )
	{
		if( Figura[2].x - 1 >= 0 )
		{
			if( !Map[ Figura[0].y ][ Figura[0].x - 1 ].Draw && !Map[ Figura[2].y ][ Figura[2].x - 1 ].Draw )
			{
				for(int i = 0 ; i < 4 ; i++)
					Figura[i].x = Figura[i].x - 1 ;
				return true ;
			}
		}
	}
	else if( al_key_down(&keyState , ALLEGRO_KEY_RIGHT) )
	{
		if( Figura[3].x + 1 < 10 )
		{
			if( !Map[ Figura[1].y ][ Figura[1].x + 1 ].Draw && !Map[ Figura[3].y ][ Figura[3].x + 1 ].Draw )
			{
				for(int i = 0 ; i < 4 ; i++)
					Figura[i].x = Figura[i].x + 1 ;
				return true ;
			}
		}
	}
	//ZWRACAMY TRUE JAK RUCH SIE UDAL A FALSE JAK NAPOTKALOSMY KOLIZJE
	return false ;
}
コード例 #9
0
ファイル: Controller.cpp プロジェクト: douglett/hexa
Controller::controls Controller::get() {
	al_get_keyboard_state(&keystate);

	// temporary state info
	int ts[7] = { 0 };
	int button_state_change = false;
	int opposite;

	for (int i=0; i<7; i++) 
		if ( state[i] != al_key_down(&keystate, order[i]) ) {
			state[i] = !state[i];
			ts[i] = ( state[i] ? 1 : -1 );
			button_state_change = true;

			// d-pad emulation for arrow keys
			if ((opposite = has_opposite(i)) > -1) {
				if (state[i] == 1 && state[opposite] == 1)
					ts[opposite] = -1;
				else if (state[i] == 0 && state[opposite] == 1)
					ts[opposite] = 1;
			}
		}

	controls c = { ts[0], ts[1], ts[2], ts[3], ts[4], ts[5], ts[6], button_state_change };
	return c;
}
コード例 #10
0
ファイル: Game.cpp プロジェクト: JackOfDawn/AI
void Game::processLoop()
{
	//update units
	mpUnit->update( LOOP_TARGET_TIME/1000.0f );
	mpAIUnit->update( LOOP_TARGET_TIME/1000.0f );
	mpAIUnit2->update( LOOP_TARGET_TIME/1000.0f );
	
	//draw background
	Sprite* pBackgroundSprite = mpSpriteManager->getSprite( BACKGROUND_SPRITE_ID );
	pBackgroundSprite->draw( *(mpGraphicsSystem->getBackBuffer()), 0, 0 );

	//draw units
	mpUnit->draw( GRAPHICS_SYSTEM->getBackBuffer() );
	mpAIUnit->draw( GRAPHICS_SYSTEM->getBackBuffer() );
	mpAIUnit2->draw( GRAPHICS_SYSTEM->getBackBuffer() );

	mpMessageManager->processMessagesForThisframe();

	//get input - should be moved someplace better
	ALLEGRO_MOUSE_STATE mouseState;
	al_get_mouse_state( &mouseState );

	if( al_mouse_button_down( &mouseState, 1 ) )//left mouse click
	{
		Vector2D pos( mouseState.x, mouseState.y );
		GameMessage* pMessage = new PlayerMoveToMessage( pos );
		MESSAGE_MANAGER->addMessage( pMessage, 0 );
	}



	//all this should be moved to InputManager!!!
	{
		//get mouse state
		ALLEGRO_MOUSE_STATE mouseState;
		al_get_mouse_state( &mouseState );

		//create mouse text
		stringstream mousePos;
		mousePos << mouseState.x << ":" << mouseState.y;

		//write text at mouse position
		al_draw_text( mpFont, al_map_rgb( 255, 255, 255 ), mouseState.x, mouseState.y, ALLEGRO_ALIGN_CENTRE, mousePos.str().c_str() );

		mpGraphicsSystem->swap();

		//get current keyboard state
		ALLEGRO_KEYBOARD_STATE keyState;
		al_get_keyboard_state( &keyState );

		//if escape key was down then exit the loop
		if( al_key_down( &keyState, ALLEGRO_KEY_ESCAPE ) )
		{
			mShouldExit = true;
		}
	}
}
コード例 #11
0
ファイル: UserInput.cpp プロジェクト: ElsonC/stonesense
void doRepeatActions()
{
    al_get_keyboard_state(&keyboard);
    int32_t keymod = getKeyMods(&keyboard);

    for(int keycode=0; keycode<ALLEGRO_KEY_UNKNOWN; keycode++) {
        if(isRepeatable(keycode) && al_key_down(&keyboard,keycode)) {
            doKey(keycode, keymod);
        }
    }
}
コード例 #12
0
ファイル: g_misc.c プロジェクト: Abstrusle/LCTourn
void error_call(void)
{

 ALLEGRO_EVENT ev;

 ALLEGRO_KEYBOARD_STATE error_key_State;

 fprintf(stdout, "\n\r\n\rPress space to exit (with game window as focus)");

 while(TRUE)
 {
  al_wait_for_event(event_queue, &ev);
  al_get_keyboard_state(&error_key_State);

  if(al_key_down(&error_key_State, ALLEGRO_KEY_ESCAPE)
  || al_key_down(&error_key_State, ALLEGRO_KEY_SPACE))
   safe_exit(1);
 };

}
コード例 #13
0
ファイル: kb.c プロジェクト: e-r-v/Pioneer
void update_keystate_table()
{
   al_get_keyboard_state(&keyboard);

   reset_keystate_table(keystate);

   if (al_key_down(&keyboard, ALLEGRO_KEY_UP))
      keystate[KEY_UP] = 1;

   if (al_key_down(&keyboard, ALLEGRO_KEY_DOWN))
      keystate[KEY_DOWN] = 1;

   if (al_key_down(&keyboard, ALLEGRO_KEY_LEFT))
      keystate[KEY_LEFT] = 1;

   if (al_key_down(&keyboard, ALLEGRO_KEY_RIGHT))
      keystate[KEY_RIGHT] = 1;

   if (al_key_down(&keyboard, ALLEGRO_KEY_ESCAPE))
      keystate[KEY_ESCAPE] = 1;
}
コード例 #14
0
	void run(ALLEGRO_KEYBOARD_STATE *key)
	{
		//vspeed += gravity;
		x += hspeed;
		y += vspeed;
		vspeed += gravity;
		if(al_key_down(key,ALLEGRO_KEY_UP)&&onGround == true)
		{
			vspeed = -levelSpeed*2;
			onGround = false;
		}
		if(al_key_down(key,ALLEGRO_KEY_RIGHT))
		{
			hspeed = levelSpeed;
		}
		if(al_key_down(key,ALLEGRO_KEY_LEFT))
		{
			hspeed = -levelSpeed;
		}	
		if(al_key_down(key,ALLEGRO_KEY_DOWN))
		{
			vspeed += 2;
		}
		if(!al_key_down(key,ALLEGRO_KEY_LEFT)&&!al_key_down(key,ALLEGRO_KEY_RIGHT)){hspeed = 0;};
	}
コード例 #15
0
void Sterowanie::wybierz_sobie_klawisz(){
	
	ALLEGRO_KEYBOARD_STATE stan;
	al_get_keyboard_state(&stan);	//zbiera stan klawiatury

	if (al_key_down(&stan, gora))	//góra lub dó³
		wgore();
	else if (al_key_down(&stan, dol))
		wdol();
	else
		anigora_anidol();

	if (al_key_down(&stan, prawo))	//prawo lub lewo
		wprawo();
	else if (al_key_down(&stan, lewo))
		wlewo();
	else
		aniprawo_anilewo();

	if (al_key_down(&stan, ogien))	//ognia!
		ognia();

	if (al_key_down(&stan, ALLEGRO_KEY_ESCAPE))
		/*tutaj bêdzie kiedyœ wyjœcie*/
	{};
}
コード例 #16
0
void Menu_Screen::Handling_Keyboard( ALLEGRO_EVENT &events , ALLEGRO_KEYBOARD_STATE &keyState , ALLEGRO_TIMER *MoveFPS , ALLEGRO_TIMER *ChangeFPS )
{
	//EVENT KLAWIATURY
	if(events.type == ALLEGRO_EVENT_KEY_DOWN)
	{
		//PORUSZANIE SIE PO MENU
		if( al_key_down(&keyState , ALLEGRO_KEY_LEFT) )
		{
			if(Select_Options <= 0)
				Select_Options = 0 ;
			else
				Select_Options-- ;
		}

		else if( al_key_down(&keyState , ALLEGRO_KEY_RIGHT) )
		{
			if(Select_Options >= 1)
				Select_Options = 1 ;
			else
				Select_Options++ ;
		}

		//WYBOR POZYCJI NA MENU
		if(al_key_down(&keyState , ALLEGRO_KEY_ENTER))
			switch(Select_Options)
			{
				case 0:

					End_Menu_ = true ;
					STATE = GAME ;
					break ;

				case 1:

					End_Menu_ = true ;
					Game_ = false ;
					break ;
			}
	}//if(events.type == ALLEGRO_EVENT_KEY_DOWN)
}
コード例 #17
0
ファイル: MenuState.cpp プロジェクト: FlipskiZ/My-Games-Dump
void MenuState::update(Engine* engine){

    if(timerEvent){

        al_get_mouse_state(&mouseState);

        al_get_keyboard_state(&keyState);

        //Input +
        if(al_key_down(&keyState, ALLEGRO_KEY_ESCAPE)){
            if(lastKeyPress != ALLEGRO_KEY_ESCAPE){
                if(inGame){
                    engine->popState();
                }else{
                    engine->quit();
                }
                lastKeyPress = ALLEGRO_KEY_ESCAPE;
            }
         }
        //Input -

        //Update Entities +
        for(int i = 0; i < MAX_BUTTONS; i++){
            if(buttonList[i] != NULL && buttonList[i]->checkActive()){
                buttonList[i]->update();
                if(buttonList[i]->clicked){
                    switch(buttonList[i]->buttonId){
                        case 0:
                            engine->popState();
                            break;

                        case 1:
                            engine->changeState(PlayState::instance());
                            break;

                        case 2:
                            engine->quit();
                            break;
                    }
                }
            }
        }
        //Update Entities -

        //Rest +

        //Rest -
        engine->draw();
    }
}
コード例 #18
0
ファイル: ex_mouse.c プロジェクト: BorisCarvajal/allegro5
int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *cursor;
   ALLEGRO_MOUSE_STATE msestate;
   ALLEGRO_KEYBOARD_STATE kbdstate;
   int i;

   (void)argc;
   (void)argv;

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

   al_init_primitives_addon();
   al_install_mouse();
   al_install_keyboard();
   al_init_image_addon();
   init_platform_specific();

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

   al_hide_mouse_cursor(display);

   cursor = al_load_bitmap("data/cursor.tga");
   if (!cursor) {
      abort_example("Error loading cursor.tga\n");
   }

   do {
      al_get_mouse_state(&msestate);
      al_get_keyboard_state(&kbdstate);

      al_clear_to_color(al_map_rgb(0xff, 0xff, 0xc0));
      for (i = 1; i <= NUM_BUTTONS; i++) {
         draw_mouse_button(i, al_mouse_button_down(&msestate, i));
      }
      al_draw_bitmap(cursor, msestate.x, msestate.y, 0);
      al_flip_display();

      al_rest(0.005);
   } while (!al_key_down(&kbdstate, ALLEGRO_KEY_ESCAPE));

   return 0;
}
コード例 #19
0
ファイル: kbd_allegro5.c プロジェクト: BadrElh/microwindows
/*
 * This reads one keystroke from the keyboard, and the current state of
 * the modifier keys (ALT, SHIFT, etc).  Returns -1 on error, 0 if no data
 * is ready, 1 on a keypress, and 2 on keyrelease.
 * This is a non-blocking call.
 */
static int
allegro_Read(MWKEY *kbuf, MWKEYMOD *modifiers, MWSCANCODE *scancode)
{

  int newkey;
  static int mwkey,scanvalue;

  if (closedown == 1) return -2; /* special case ESC - terminate application*/

  if (!al_is_keyboard_installed()) return 0;

  if (al_get_next_event(a_event_queue_k, &a_event)){
     /* there are further key events */
	 if (a_event.type == ALLEGRO_EVENT_KEY_CHAR) {
	  newkey = a_event.keyboard.unichar;  
	  al_get_keyboard_state(&kbdstate);
	  char ASCII = newkey & 0xff;  
	  mwkey = ASCII;
	  //fprintf(stderr,"key char:%d,%c\n",ASCII,ASCII);  fflush(stderr);
	  scanvalue = a_event.keyboard.keycode; 
     } else {
         if (a_event.type == ALLEGRO_EVENT_KEY_UP) {
            *kbuf = mwkey;		
            *scancode = scanvalue;
            return 2; //key released    
	    } else {
	        //fprintf(stderr,"NO key\n");  fflush(stderr);
	        return 0;
        }
	}

   *modifiers = 0;
   if (al_key_down(&kbdstate, ALLEGRO_KEY_ESCAPE)) return -2; /* special case ESC - terminate application*/

   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_SHIFT)) *modifiers |= MWKMOD_SHIFT;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_CTRL))  *modifiers |= MWKMOD_CTRL;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_ALT))   *modifiers |= MWKMOD_ALT;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_ALTGR)) *modifiers |= MWKMOD_ALTGR;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_LWIN))  *modifiers |= MWKMOD_LMETA; *modifiers |= MWKMOD_META;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_RWIN))  *modifiers |= MWKMOD_RMETA; *modifiers |= MWKMOD_META;
   save_modifiers=*modifiers;
   
    *kbuf = mwkey;		
    *scancode = scanvalue;

    return 1;		/* keypress received*/
  } 
return 0; //if no event received

}
コード例 #20
0
ファイル: ex_keyboard_focus.c プロジェクト: SaiSrini/Shooter
int main(void)
{
   ALLEGRO_COLOR black;
   ALLEGRO_COLOR red;
   ALLEGRO_KEYBOARD_STATE kbdstate;

   if (!al_init()) {
      abort_example("Error initialising Allegro.\n");
   }

   if (!al_install_keyboard()) {
      abort_example("Error installing keyboard.\n");
   }

   display1 = al_create_display(300, 300);
   display2 = al_create_display(300, 300);
   if (!display1 || !display2) {
      abort_example("Error creating displays.\n");
   }

   black = al_map_rgb(0, 0, 0);
   red = al_map_rgb(255, 0, 0);

   while (1) {
      al_get_keyboard_state(&kbdstate);
      if (al_key_down(&kbdstate, ALLEGRO_KEY_ESCAPE)) {
         break;
      }

      if (kbdstate.display == display1) {
         redraw(red, black);
      }
      else if (kbdstate.display == display2) {
         redraw(black, red);
      }
      else {
         redraw(black, black);
      }

      al_rest(0.1);
   }

   return 0;
}
コード例 #21
0
ファイル: actions.c プロジェクト: Lodus/SuperDerpy
bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
	if (state == TM_ACTIONSTATE_INIT) {
		float* f = (float*)malloc(sizeof(float));
		*f = 0;
		ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)malloc(sizeof(ALLEGRO_AUDIO_STREAM*));
		*stream = al_load_audio_stream(GetDataFilePath(GetLevelFilename(game, "levels/?/letter.flac")), 4, 1024);
		al_attach_audio_stream_to_mixer(*stream, game->audio.voice);
		al_set_audio_stream_playing(*stream, false);
		al_set_audio_stream_gain(*stream, 2.00);
		action->arguments = TM_AddToArgs(action->arguments, (void*)f);
		action->arguments = TM_AddToArgs(action->arguments, (void*)stream);
		action->arguments->next->next = NULL;
	} else if (state == TM_ACTIONSTATE_DESTROY) {
		ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value;
		al_set_audio_stream_playing(*stream, false);
		al_destroy_audio_stream(*stream);
		free(action->arguments->next->value);
		free(action->arguments->value);
		TM_DestroyArgs(action->arguments);
	} else if (state == TM_ACTIONSTATE_DRAW) {
		float* f = (float*)action->arguments->value;
		al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0);
		return false;
	} else if (state == TM_ACTIONSTATE_PAUSE) {
		ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value;
		al_set_audio_stream_playing(*stream, false);
	}	else if ((state == TM_ACTIONSTATE_RESUME) || (state == TM_ACTIONSTATE_START)) {
		ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value;
		al_set_audio_stream_playing(*stream, true);
	}
	if (state != TM_ACTIONSTATE_RUNNING) return false;

	float* f = (float*)action->arguments->value;
	*f+=5;
	if (*f>255) *f=255;
	al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0);
	struct ALLEGRO_KEYBOARD_STATE keyboard;
	al_get_keyboard_state(&keyboard);
	// FIXME: do it the proper way
	if (al_key_down(&keyboard, ALLEGRO_KEY_ENTER)) {
		return true;
	}
	return false;
}
コード例 #22
0
ファイル: main.cpp プロジェクト: JackOfDawn/AI
int main(void)
{
	gpPerformanceTracker = new PerformanceTracker();

	gpGame = new GameApp();

	gpGame->init();

	GraphicsBuffer* pWallpaper = new GraphicsBuffer( "wallpaper.bmp" );//should "live" someplace else


	bool shouldExit = false;

	while( !shouldExit )
	{
		//get current keyboard state
		ALLEGRO_KEYBOARD_STATE keyState;
		al_get_keyboard_state( &keyState );

		//if escape key was down then exit the loop
		if( al_key_down( &keyState, ALLEGRO_KEY_ESCAPE ) )
		{
			gpGame->markForExit();
		}

		gpGame->beginLoop();
		gpGame->processLoop();
		shouldExit = gpGame->endLoop();
	}

	//cleanup
	delete pWallpaper;
	gpGame->cleanup();
	delete gpGame;
	delete gpPerformanceTracker;

	gMemoryTracker.reportAllocations( std::cout );

	system("pause");

	return 0;
}
コード例 #23
0
ファイル: Camera.hpp プロジェクト: cesarl/2dGameExperiments
  inline void				inputBehavior(float time, const ALLEGRO_EVENT &ev)
  {
    static float			lastTime = -1;
    ALLEGRO_KEYBOARD_STATE		k;

    al_get_keyboard_state(&k);

    if (lastTime == -1)
      lastTime = al_get_time();
    float speed = (time - lastTime) * this->speed_;

    if (al_key_down(&k, ALLEGRO_KEY_W))
      {
	this->position_ += this->forward_ * glm::vec3(speed, speed, speed);
      }
    if (al_key_down(&k, ALLEGRO_KEY_S))
      {
	this->position_ -= this->forward_ * glm::vec3(speed, speed, speed);
      }
    if (al_key_down(&k, ALLEGRO_KEY_A))
      {
	glm::vec3 up(0.0f, 1.0f, 0.0f);
	glm::vec3 left = glm::cross(up, forward_);
	this->position_ += glm::normalize(left);
      }
    if (al_key_down(&k, ALLEGRO_KEY_D))
      {
	glm::vec3 up(0.0f, 1.0f, 0.0f);
	glm::vec3 left = glm::cross(up, forward_);
	this->position_ -= glm::normalize(left);
      }
    if (al_key_down(&k, ALLEGRO_KEY_Q))
      {
	this->position_ += glm::vec3(0.0f, speed / 20.0f, 0.0f);
      }
    if (al_key_down(&k, ALLEGRO_KEY_E))
      {
	this->position_ -= glm::vec3(0.0f, speed / 20.0f, 0.0f);
      }

    lastTime = time;
    (void)ev;
    (void)time;
  }
コード例 #24
0
ファイル: _test_allegro_display.c プロジェクト: ifzz/exsdk
int main( void ) {

   ALLEGRO_DISPLAY *display;
   ALLEGRO_KEYBOARD_STATE key_state;
   Point stars[3][NUM_STARS/3];
   float speeds[3] = { 0.0001f, 0.05f, 0.15f };
   ALLEGRO_COLOR colors[3];
   long start, now, elapsed, frame_count;
   int total_frames = 0;
   double program_start;
   double length;
   int layer, star;

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

   al_install_keyboard();
   
   display = al_create_display(WIDTH, HEIGHT);
   if (!display) {
      abort_app("Could not create display.\n");
      return 1;
   }

   colors[0] = al_map_rgba(255, 100, 255, 128);
   colors[1] = al_map_rgba(255, 100, 100, 255);
   colors[2] = al_map_rgba(100, 100, 255, 255);
         
   for (layer = 0; layer < 3; layer++) {
      for (star = 0; star < NUM_STARS/3; star++) {
         Point *p = &stars[layer][star];
         p->x = rand() % WIDTH;
         p->y = rand() % HEIGHT;
      }
   }


   start = al_get_time() * 1000;
   now = start;
   elapsed = 0;
   frame_count = 0;
   program_start = al_get_time();


   while (1) {
      if (frame_count < (1000/TARGET_FPS)) {
         frame_count += elapsed;
      }
      else {
         int X, Y;

         frame_count -= (1000/TARGET_FPS);
         al_clear_to_color(al_map_rgb(0, 0, 0));
         for (star = 0; star < NUM_STARS/3; star++) {
            Point *p = &stars[0][star];
            al_draw_pixel(p->x, p->y, colors[0]);
         }
         al_lock_bitmap(al_get_backbuffer(display), ALLEGRO_PIXEL_FORMAT_ANY, 0);

         for (layer = 1; layer < 3; layer++) {
            for (star = 0; star < NUM_STARS/3; star++) {
               Point *p = &stars[layer][star];
               // put_pixel ignores blending
               al_put_pixel(p->x, p->y, colors[layer]);
            }
         }

         /* Check that dots appear at the window extremes. */
         X = WIDTH - 1;
         Y = HEIGHT - 1;
         al_put_pixel(0, 0, al_map_rgb_f(1, 1, 1));
         al_put_pixel(X, 0, al_map_rgb_f(1, 1, 1));
         al_put_pixel(0, Y, al_map_rgb_f(1, 1, 1));
         al_put_pixel(X, Y, al_map_rgb_f(1, 1, 1));

         al_unlock_bitmap(al_get_backbuffer(display));
         al_flip_display();
         total_frames++;
      }

      now = al_get_time() * 1000;
      elapsed = now - start;
      start = now;

      for (layer = 0; layer < 3; layer++) {
         for (star = 0; star < NUM_STARS/3; star++) {
            Point *p = &stars[layer][star];
            p->y -= speeds[layer] * elapsed;
            if (p->y < 0) {
               p->x = rand() % WIDTH;
               p->y = HEIGHT;
            }
         }
      }

      al_rest(0.001);

      al_get_keyboard_state(&key_state);
      if (al_key_down(&key_state, ALLEGRO_KEY_ESCAPE))
         break;
   }

   length = al_get_time() - program_start;

   if (length != 0) {
      printf("%d FPS\n", (int)(total_frames / length));
   }

   al_destroy_display(display);

   return 0;
}
コード例 #25
0
int main(int argc, char **argv )
{
	//inits
    al_init();
    al_init_ttf_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_init_primitives_addon();
    al_reserve_samples(1000);
    al_init_image_addon();
    ALLEGRO_KEYBOARD_STATE key;
    ALLEGRO_MOUSE_STATE mouse;
    
    ALLEGRO_DISPLAY *display;
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    
    display = al_create_display(1024, 768);
    
    al_hide_mouse_cursor(display);

	//
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;
    bool redraw = true;
    timer = al_create_timer(1.0/fps);
    event_queue = al_create_event_queue();
    
    //SAMPLES
    
    
    ///OBJECTS
    cPlayer oPlayer;
    oPlayer.create();
    
    cLevel oLevel;
    oLevel.init();
    
    ////
    al_clear_to_color(al_map_rgb(0,0,0));
    al_flip_display();
    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);
    al_reserve_samples(1000);
    
    //RUN
    while(1<2)
    {  
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);
        al_get_keyboard_state(&key);
        al_get_mouse_state(&mouse);
        al_get_mouse_state_axis(&mouse,0);
        al_get_mouse_state_axis(&mouse,1);
        if(ev.type == ALLEGRO_EVENT_TIMER)
        {
			
			//Runny tunny
			{
				oLevel.createLevel();
				oPlayer.run(&key);
				//player collision check
				for(int i = 0;i<oLevel.blocknum;i++)
				{
					oPlayer.checkCollision(oLevel.oBlock[i].x,oLevel.oBlock[i].y,&key);
				}
				if(al_key_down(&key,ALLEGRO_KEY_ESCAPE))
				{
					return 0;
				}
			
			
			}
            redraw = true;
        }
        else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            break;   
        }
        if(redraw && al_is_event_queue_empty(event_queue))
        {
			//draw
			al_clear_to_color(al_map_rgb(0,0,0));
		
			oPlayer.draw();
			oLevel.draw();
			//////
		
            redraw = false;
            //
            al_flip_display();
        }
    }
    return 0;
};
コード例 #26
0
void AllegroInput5::Update( int dt )
{
	if ( m_doubleClickTimer > 0 )
		m_doubleClickTimer -= dt;
	if ( m_repeatTimer > 0 )
		m_repeatTimer -= dt;

	  // Get current transformation, to tranform reported scaled/shifted mouse coordinates into something the game can use
	const ALLEGRO_TRANSFORM *pTransform = al_get_current_inverse_transform();

	const JoystickMapping & mapping = GetJoystickMapping(0);

	ALLEGRO_EVENT ev;
	while( al_get_next_event( m_queue, &ev ) )
	{
		if ( m_hasKeyboard )
		{
			if ( ev.any.type == ALLEGRO_EVENT_KEY_DOWN )
				AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_DOWN, ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers ) );
			else if ( ev.any.type == ALLEGRO_EVENT_KEY_UP )
				AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_UP, ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers ) );
			else if ( ev.any.type == ALLEGRO_EVENT_KEY_CHAR && m_repeatTimer <= 0 )
			{
				  // Please note that some event params (like modifiers) are ONLY accessible in KEY_CHAR event!
				AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_REPEAT, ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers ) );
				m_repeatTimer = 100;
			}
		}

		if ( m_hasMouse )
		{
			float exf = ev.mouse.x;
			float eyf = ev.mouse.y;
			float edxf = ev.mouse.dx;
			float edyf = ev.mouse.dy;

			al_transform_coordinates( pTransform, &exf, &eyf );
			al_transform_coordinates( pTransform, &edxf, &edyf );

			int ex = (int)floorf( exf );
			int ey = (int)floorf( eyf );
			int edx = (int)floorf( edxf );
			int edy = (int)floorf( edyf );

			if ( ev.any.type == ALLEGRO_EVENT_MOUSE_AXES )
			{
				if ( edx != 0 || edy != 0 )
					AddEvent( InputEvent::MouseEvent( MouseEvent::MOUSE_MOVE, ex, ey, ev.mouse.dw ) );
				if ( ev.mouse.dw != 0 )
					AddEvent( InputEvent::MouseEvent( MouseEvent::MOUSE_WHEEL, ex, ey, ev.mouse.dw ) );
			}
			else if ( ev.any.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN )
			{
				MouseEvent::EType type = MouseEvent::MOUSE_B1_DOWN;
				if ( ev.mouse.button == 1 )
				{
					if ( m_doubleClickTimer > 0 )
					{
						m_doubleClickTimer = 0;
						type = MouseEvent::MOUSE_B1_DOUBLECLICK;
					}
					else
						type = MouseEvent::MOUSE_B1_DOWN;
				}
				else if ( ev.mouse.button == 2 )
					type = MouseEvent::MOUSE_B2_DOWN;
				else if ( ev.mouse.button == 3 )
					type = MouseEvent::MOUSE_B3_DOWN;
				AddEvent( InputEvent::MouseEvent( type, ex, ey, 0 ) );
			}
			else if ( ev.any.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP )
			{
				MouseEvent::EType type = MouseEvent::MOUSE_B1_UP;
				if ( ev.mouse.button == 1 )
				{
					m_doubleClickTimer = 250;
					type = MouseEvent::MOUSE_B1_UP;
				}
				else if ( ev.mouse.button == 2 )
					type = MouseEvent::MOUSE_B2_UP;
				else if ( ev.mouse.button == 3 )
					type = MouseEvent::MOUSE_B3_UP;
				AddEvent( InputEvent::MouseEvent( type, ex, ey, 0 ) );
			}
		}

		if ( m_hasGamepad )
		{
			if ( ev.any.type == ALLEGRO_EVENT_JOYSTICK_AXIS )
			{
				const int stick = ev.joystick.stick;
				const int axis  = ev.joystick.axis;
			
				if ( stick >= (int)m_gamepadSticks.size() )
					m_gamepadSticks.resize( stick + 1 );

				GamepadStick & s = m_gamepadSticks[ stick ];
				if ( axis >= (int)s.m_axis.size() )
					s.m_axis.resize( axis + 1 );

				GamepadAxis & a = s.m_axis[ axis ];

				  // Some axes on some systems has their neutral position at -1 instead of 0, so we have to adjust for it
				const float adjPos = ev.joystick.pos - mapping.GetAxisBase( ev.joystick.stick, ev.joystick.axis );
				const bool nearZero = fabs(adjPos) < 0.01f;
				
				  // We only want to send GP_AXIS event once for each direction change, like it was a digital axis or a keyboard key
				if ( nearZero )
				{
					  // If the stick is back to its neutral position, and wasn't there before, send an event about it
					if ( !a.m_unlocked )
						AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_AXIS, ev.joystick.stick, ev.joystick.axis, 0 ) );
					a.m_unlocked = true;
				}
				else
				{
					  // If the stick is outside its neutral position, and this wasn't reported before, send an event about it
					if ( a.m_unlocked )
						AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_AXIS, ev.joystick.stick, ev.joystick.axis, adjPos ) );
					a.m_unlocked = false;
				}
			}
			else if ( ev.any.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN )
			{
				AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_BUTTON_DOWN, ev.joystick.button ) );
			}
			else if ( ev.any.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_UP )
			{
				AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_BUTTON_UP, ev.joystick.button ) );
			}
		}

		if ( m_hasTouch )
		{
			float exf = ev.touch.x;
			float eyf = ev.touch.y;
			float edxf = ev.touch.dx;
			float edyf = ev.touch.dy;

			al_transform_coordinates( pTransform, &exf, &eyf );
            edxf *= pTransform->m[0][0];
            edyf *= pTransform->m[0][0];

			int ex = (int)floorf( exf );
			int ey = (int)floorf( eyf );
			int edx = (int)floorf( edxf );
			int edy = (int)floorf( edyf );

			if ( ev.any.type == ALLEGRO_EVENT_TOUCH_BEGIN )
				AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_BEGIN, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) );
			else if ( ev.any.type == ALLEGRO_EVENT_TOUCH_MOVE )
				AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_MOVE, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) );
			else if ( ev.any.type == ALLEGRO_EVENT_TOUCH_END )
				AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_END, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) );
			else if ( ev.any.type == ALLEGRO_EVENT_TOUCH_CANCEL )
				AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_CANCEL, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) );

			//GetLog().Log( CommonLog(), LL_CRITICAL, "AllegroInput: event=%i id=%i x=%f y=%f", ev.any.type, ev.touch.id, ev.touch.x, ev.touch.y );
		}
	}

	if ( m_hasKeyboard )
	{
		  // Since Allegro events don't have KEY_PRESSED, we do it other way.
		ALLEGRO_KEYBOARD_STATE state;
		al_get_keyboard_state( &state );

		for ( int i = 0; i < ALLEGRO_KEY_MAX; ++i )
		{
			  // We don't know key code for state :(
			if ( al_key_down( &state, i ) && m_keyStates[ i ] )
				AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_PRESSED, i, 0, 0 ) );

			m_keyStates[ i ] = al_key_down( &state, i )  != 0;
		}
	}
}
コード例 #27
0
ファイル: ScrollableArea.cpp プロジェクト: kruci/rGUI
    int ScrollableArea::Specific_Input(ALLEGRO_EVENT &ev)
    {
        if(wd_md->md_active == false)
            return 9;
        wd_md->Specific_Input(ev);

        zoomresetb->Specific_Input(ev);
        if(zoomresetb->wd_md->md_just_clicked == true)
        {
            float prevzoom = zoom;
            zoom = 1.0f;
            sca_mouse_z = mouse_state->z;
            scb_vertical->Change_real_size(r_size_h * zoom);
            scb_vertical->Set_change( (scb_vertical->change/prevzoom) * zoom);
            scb_horizontal->Change_real_size(r_size_w * zoom);
            scb_horizontal->Set_change((scb_horizontal->change/prevzoom) * zoom);
            scb_vertical->changed = true;
            scb_horizontal->changed = true;
        }

        if(wd_md->md_mouse_on_it == true)
        {

            if(ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == zoomkey)
            {
                sca_mouse_z = mouse_state->z;
            }

            if(al_key_down(keyboard_state, horizontalscrollkey))
            {
                scb_horizontal->Scrolling_input();
            }
            else if(al_key_down(keyboard_state, zoomkey) && (wd_bf & bf_ZOOMABLE))
            {
                prevzoom = zoom;
                if(sca_mouse_z - mouse_state->z > 0)
                {
                    zoom -= zoomstep;
                }
                else if(sca_mouse_z - mouse_state->z < 0)
                {
                    zoom += zoomstep;
                }

                if(zoom <= 0)
                {
                    zoom = zoomstep;
                }
                sca_mouse_z = mouse_state->z;

                scb_vertical->Change_real_size(r_size_h * zoom);
                scb_vertical->Set_change( (scb_vertical->change/prevzoom) * zoom);
                scb_horizontal->Change_real_size(r_size_w * zoom);
                scb_horizontal->Set_change((scb_horizontal->change/prevzoom) * zoom);
                scb_vertical->changed = true;
                scb_horizontal->changed = true;
            }
            else
            {
                scb_vertical->Scrolling_input();
            }
        }
        scb_vertical->Specific_Input(ev);
        scb_horizontal->Specific_Input(ev);

        if(scb_vertical->changed == true || scb_horizontal->changed == true)
        {
            changec_i = true;
            changec_p = true;
            scb_vertical->changed = false;
            scb_horizontal->changed = false;
        }


        for(int a = 0; a < (int)widgets.size();a++)
        {
            if( (wd_md->md_mouse_on_it == false && widgets[a]->wd_md->md_clicked == true && widgets[a]->wd_extented_input == true &&
               (ev.type == ALLEGRO_EVENT_MOUSE_AXES || ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN ||
                ev.type == ALLEGRO_EVENT_KEY_CHAR || ev.type == ALLEGRO_EVENT_KEY_DOWN))
               || wd_md->md_mouse_on_it == true) // SLOW ?
            {
                if(changec_i == true)
                {
                    widgets[a]->wd_md->Change_coords(wd_x1 + widgets[a]->orig_x1*zoom - scb_horizontal->change,
                                                     wd_y1 + widgets[a]->orig_y1*zoom - scb_vertical->change,
                                                     (widgets[a]->orig_x2 - widgets[a]->orig_x1)*zoom,
                                                     (widgets[a]->orig_y2 - widgets[a]->orig_y1)*zoom);
                }

                widgets[a]->Specific_Input(ev);
            }
        }
        changec_i = false;
    }
コード例 #28
0
void ImGui_ImplA5_NewFrame()
{
    if (!g_Texture) 
        Imgui_ImplA5_CreateDeviceObjects();

    ImGuiIO &io = ImGui::GetIO();

    // Setup display size (every frame to accommodate for window resizing)
    int w, h;
    w = al_get_display_width(g_Display);
    h = al_get_display_height(g_Display);
    io.DisplaySize = ImVec2((float)w, (float)h);

    // Setup time step
    double current_time = al_get_time();
    io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
    g_Time = current_time;

    // Setup inputs
    ALLEGRO_KEYBOARD_STATE keys;
    al_get_keyboard_state(&keys);
    io.KeyCtrl = al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL);
    io.KeyShift = al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT);
    io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR);

    ALLEGRO_MOUSE_STATE mouse;
    if (keys.display == g_Display) 
    {
        al_get_mouse_state(&mouse);
        io.MousePos = ImVec2((float)mouse.x, (float)mouse.y);
    }
    else 
    {
        io.MousePos = ImVec2(-1, -1);
    }

    al_get_mouse_state(&mouse);
    io.MouseDown[0] = mouse.buttons & (1 << 0);
    io.MouseDown[1] = mouse.buttons & (1 << 1);
    io.MouseDown[2] = mouse.buttons & (1 << 2);

    // Hide OS mouse cursor if ImGui is drawing it
    if (io.MouseDrawCursor)
    {
        al_set_mouse_cursor(g_Display, g_MouseCursorInvisible);
    }
    else
    {
        ALLEGRO_SYSTEM_MOUSE_CURSOR cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT;
        switch (ImGui::GetMouseCursor())
        {
        case ImGuiMouseCursor_TextInput:    cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_EDIT; break;
        case ImGuiMouseCursor_Move:         cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_MOVE; break;
        case ImGuiMouseCursor_ResizeNS:     cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_N; break;
        case ImGuiMouseCursor_ResizeEW:     cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E; break;
        case ImGuiMouseCursor_ResizeNESW:   cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NE; break;
        case ImGuiMouseCursor_ResizeNWSE:   cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NW; break;
        }
        al_set_system_mouse_cursor(g_Display, cursor_id);
    }

    // Start the frame
    ImGui::NewFrame();
}
コード例 #29
0
ファイル: main.c プロジェクト: emanuele-f/fuzzy_project
int main(int argc, char *argv[])
{
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *evqueue = NULL;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_KEYBOARD_STATE keyboard_state;
    ALLEGRO_EVENT event;
    ALLEGRO_FONT *font;
    ALLEGRO_BITMAP *clock_hand, *clock_quadrant, *bow, *sword;
    float clock_ray = 0, clock_angle = 0;
    int clock_ray_alpha;
    float soul_interval = SOUL_TIME_INTERVAL;
    FuzzyPlayer *player, *cpu;
    FuzzyGame * game;

	bool running = true;
	bool redraw = true;

	int map_x = 13*16, map_y = 5*16;
	int screen_width = WINDOW_WIDTH;
	int screen_height = WINDOW_HEIGHT;
    double curtime;

	/* Initialization */
    fuzzy_iz_error(al_init(), "Failed to initialize allegro");
    fuzzy_load_addon("image", al_init_image_addon());
    fuzzy_load_addon("primitives", al_init_primitives_addon());
    fuzzy_load_addon("keyboard", al_install_keyboard());
    fuzzy_load_addon("mouse", al_install_mouse());
    al_init_font_addon();

	fuzzy_iz_error(timer = al_create_timer(1.0 / FPS), "Cannot create FPS timer");
    fuzzy_iz_error(evqueue = al_create_event_queue(), "Cannot create event queue");
	fuzzy_iz_error(display = al_create_display(screen_width, screen_height),
      "Cannot initialize display");
    al_set_window_title(display, WINDOW_TITLE);
    fuzzy_iz_error(font = al_load_font(fuzzy_res(FONT_FOLDER, "fixed_font.tga"), 0, 0), "Cannot load 'fixed_font.tga'");
    clock_hand = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_hand.png"));
    fuzzy_iz_error(clock_hand, "Cannot load clock handle");
    clock_quadrant = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_quadrant.png"));
    fuzzy_iz_error(clock_hand, "Cannot load clock quadrant");
    bow = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "bow.png"));
    fuzzy_iz_error(clock_hand, "Cannot load bow image");
    sword = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "sword.png"));
    fuzzy_iz_error(clock_hand, "Cannot load sword image");

	/* Queue setup */
	al_register_event_source(evqueue, al_get_display_event_source(display));
	al_register_event_source(evqueue, al_get_timer_event_source(timer));
	al_register_event_source(evqueue, al_get_keyboard_event_source());
    al_register_event_source(evqueue, al_get_mouse_event_source());

    /* Game setup */
    game = fuzzy_game_new("level000.tmx");
    player = fuzzy_player_new(game, FUZZY_PLAYER_LOCAL, "Dolly");
    cpu = fuzzy_player_new(game, FUZZY_PLAYER_CPU, "CPU_0");

    fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 34, 30);
    fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 33, 30);
    fuzzy_chess_add(game, cpu, FUZZY_FOO_LINK, 40, 30);
    bool showing_area = false;
    FuzzyChess *chess, *focus = NULL;

	al_clear_to_color(al_map_rgb(0, 0, 0));
    al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0);
	al_flip_display();

#if DEBUG
	ALLEGRO_BITMAP *icon;
    int fps, fps_accum;
    double fps_time;

    icon = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "icon.tga"));
    if (icon)
        al_set_display_icon(display, icon);
    fps_accum = fps_time = 0;
    fps = FPS;
#endif
    /* Server connection */
    int svsock;
    //~ FuzzyMessage * sendmsg = fuzzy_message_new();
    svsock = fuzzy_server_connect(FUZZY_DEFAULT_SERVER_ADDRESS, FUZZY_DEFAULT_SERVER_PORT);

    _aaa_menu(game, svsock);

	/* MAIN loop */
    player->soul_time = al_get_time();
    al_start_timer(timer);
	while (running) {
        /* wait until an event happens */
		al_wait_for_event(evqueue, &event);

        switch (event.type) {
        case ALLEGRO_EVENT_TIMER:
            /* check soul ticks */
            curtime = al_get_time();
            while (curtime - player->soul_time >= soul_interval) {
                //~ fuzzy_debug("Soul tick!");
                player->soul_time += soul_interval;
                player->soul_points += SOUL_POINTS_BOOST;

                clock_ray = 1;
            }
            clock_angle = (curtime - player->soul_time)/soul_interval * FUZZY_2PI;
            if (clock_ray) {
                clock_ray = (curtime - player->soul_time)/RAY_TIME_INTERVAL * 50 + 40;
                clock_ray_alpha = (curtime - player->soul_time)/RAY_TIME_INTERVAL*(55) + 200;
                if (clock_ray >= 90)
                    clock_ray = 0;
            }

            al_get_keyboard_state(&keyboard_state);
            if (al_key_down(&keyboard_state, ALLEGRO_KEY_RIGHT)) {
                map_x += 5;
                if (map_x > (game->map->tot_width - screen_width))
                    map_x = game->map->tot_width - screen_width;
            }
            else if (al_key_down(&keyboard_state, ALLEGRO_KEY_LEFT)) {
                map_x -= 5;
                if (map_x < 0)
                    map_x = 0;
            }
            else if (al_key_down(&keyboard_state, ALLEGRO_KEY_UP)) {
                map_y -= 5;
                if (map_y < 0)
                    map_y = 0;
            }
            else if (al_key_down(&keyboard_state, ALLEGRO_KEY_DOWN)) {
                map_y += 5;
                if (map_y > (game->map->tot_height - screen_height))
                    map_y = game->map->tot_height - screen_height;
            } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_O)) {
                soul_interval = fuzzy_max(0.1, soul_interval - 0.05);
            } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_P)) {
                soul_interval += 0.05;
            }
            redraw = true;
            break;
        case ALLEGRO_EVENT_KEY_DOWN:
            if(! focus)
                break;

            _attack_area_off();

            switch(event.keyboard.keycode) {
                case ALLEGRO_KEY_W:
                    _chess_move(game, player, focus, focus->x, focus->y-1);
                    break;
                case ALLEGRO_KEY_A:
                    _chess_move(game, player, focus, focus->x-1, focus->y);
                    break;
                case ALLEGRO_KEY_S:
                    _chess_move(game, player, focus, focus->x, focus->y+1);
                    break;
                case ALLEGRO_KEY_D:
                    _chess_move(game, player, focus, focus->x+1, focus->y);
                    break;

                case ALLEGRO_KEY_K:
                    _attack_area_on();
                    break;
                case ALLEGRO_KEY_SPACE:
                    /* switch attack type */
                    if (! focus)
                        break;
                    if (focus->atkarea == &FuzzyMeleeMan)
                        focus->atkarea = &FuzzyRangedMan;
                    else
                        focus->atkarea = &FuzzyMeleeMan;
                    break;
            }
            break;
        case ALLEGRO_EVENT_DISPLAY_CLOSE:
            running = false;
            break;
        case ALLEGRO_EVENT_KEY_UP:
            break;
        case ALLEGRO_EVENT_KEY_CHAR:
            break;
        case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
            if(event.mouse.button == RIGHT_BUTTON) {
                _attack_area_on();
            } else if(event.mouse.button == LEFT_BUTTON) {
                /* world to tile coords */
                int tx = (event.mouse.x+map_x) / game->map->tile_width;
                int ty = (event.mouse.y+map_y) / game->map->tile_height;
#ifdef DEBUG
                printf("SELECT %d %d\n", tx, ty);
#endif
                if(showing_area && fuzzy_chess_inside_target_area(game, focus, tx, ty)) {
                    /* select attack target */
                    if (fuzzy_map_spy(game->map, FUZZY_LAYER_SPRITES, tx, ty) == FUZZY_CELL_SPRITE) {
                        if (fuzzy_chess_local_attack(game, player, focus, tx, ty))
                            _attack_area_off();
                    }
                } else {
                    /* select chess */
                    chess = fuzzy_chess_at(game, player, tx, ty);
                    if (chess && focus != chess) {
                        _attack_area_off();

                        if (focus != NULL) {
                            // already has a focus effect, just move it
                            fuzzy_sprite_move(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y, tx, ty);
                        } else {
                            fuzzy_sprite_create(game->map, FUZZY_LAYER_BELOW, GID_TARGET, tx, ty);
                        }
                        focus = chess;
                    } else if (! chess) {
                        if (showing_area) {
                            // just hide the attack area
                            _attack_area_off();
                        } else if(focus) {
                            // remove the focus
                            fuzzy_sprite_destroy(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y);
                            focus = NULL;
                        }
                    }
                }
            }
            break;
        default:
#ifdef DEBUG
            //~ fprintf(stderr, "Unknown event received: %d\n", event.type);
#endif
            break;
        }

        if (redraw && al_is_event_queue_empty(evqueue)) {
            curtime = al_get_time();
            fuzzy_map_update(game->map, curtime);

            // Clear the screen
            al_clear_to_color(al_map_rgb(0, 0, 0));
            al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0);

#ifdef GRID_ON
            /* Draw the grid */
            int tw = game->map->tile_width;
            int ty = game->map->tile_height;
            int x, y;
            for (x=(tw-map_x)%tw; x<screen_width; x+=tw)
                al_draw_line(x, 0, x, screen_height, al_map_rgba(7,7,7,100), 1);
            for (y=(ty-map_y)%ty; y<screen_height; y+=ty)
                al_draw_line(0, y, screen_width, y, al_map_rgba(7,7,7,100), 1);
#endif
#if DEBUG
            al_draw_filled_rounded_rectangle(screen_width-100, 4, screen_width, 30,
                8, 8, al_map_rgba(0, 0, 0, 200));
            al_draw_textf(font, al_map_rgb(255, 255, 255),
                screen_width-50, 8, ALLEGRO_ALIGN_CENTRE, "FPS: %d", fps);
#endif
            /* draw SP count */
            al_draw_filled_rounded_rectangle(4, screen_height-170, 175, screen_height-4,
                8, 8, al_map_rgba(0, 0, 0, 200));
            al_draw_textf(font, al_map_rgb(255, 255, 255),
                15, screen_height-163, ALLEGRO_ALIGN_LEFT, "SP: %d", player->soul_points);

            /* draw Soul Clock */
            al_draw_scaled_bitmap(clock_quadrant, 0, 0, 301, 301, 20, screen_height-80-139/2, 139, 139, 0);
            al_draw_scaled_rotated_bitmap(clock_hand, 160, 607, 90, screen_height-80, 0.11, 0.11, clock_angle, 0);
            al_draw_circle(90, screen_height-80, clock_ray, al_map_rgb(80, clock_ray_alpha, 80), 2.0);

            /* draw weapon */
            if (focus) {
                ALLEGRO_BITMAP * weapon;

                if (focus->atkarea == &FuzzyMeleeMan)
                    weapon = sword;
                else
                    weapon = bow;
                al_draw_scaled_bitmap(weapon, 0, 0, 90, 90, 20, 20, 60, 60, 0);
            }

            al_flip_display();
#if DEBUG
            fps_accum++;
            if (curtime - fps_time >= 1) {
                fps = fps_accum;
                fps_accum = 0;
                fps_time = curtime;
            }
#endif
            redraw = false;
        }
    }

	/* Cleanup */
    //~ void * retval;
    //~ char srvkey[FUZZY_SERVERKEY_LEN];
    //~ fuzzy_protocol_server_shutdown(svsock, sendmsg, srvkey);
    //~ fuzzy_message_del(sendmsg);
    fuzzy_game_free(game);

    al_destroy_event_queue(evqueue);
	al_destroy_display(display);
    al_destroy_timer(timer);
	return 0;
}
コード例 #30
0
int main(int argc, char **argv)
{
   float r = 0.5, g = 0.5, b = 1, ratio = 0;
   int dir = 1;
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *mysha;
   ALLEGRO_BITMAP *buffer;

   const char *tinter_shader_src[] = {
      "uniform sampler2D backBuffer;",
      "uniform float r;",
      "uniform float g;",
      "uniform float b;",
      "uniform float ratio;",
      "void main() {",
      "	vec4 color;",
      "	float avg, dr, dg, db;",
      "	color = texture2D(backBuffer, gl_TexCoord[0].st);",
      "	avg = (color.r + color.g + color.b) / 3.0;",
      "	dr = avg * r;",
      "	dg = avg * g;",
      "	db = avg * b;",
      "	color.r = color.r - (ratio * (color.r - dr));",
      "	color.g = color.g - (ratio * (color.g - dg));",
      "	color.b = color.b - (ratio * (color.b - db));",
      "	gl_FragColor = color;",
      "}"
   };
   const int TINTER_LEN = 18;
   double start;
   GLint loc;

   (void)argc;
   (void)argv;

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

   al_install_keyboard();
   al_init_image_addon();

   al_set_new_display_flags(ALLEGRO_OPENGL);
   display = al_create_display(320, 200);
   if (!display) {
      abort_example("Error creating display\n");
   }

   mysha = al_load_bitmap("data/mysha.pcx");
   if (!mysha) {
      abort_example("Could not load image.\n");
   }

   buffer = al_create_bitmap(320, 200);

   if (!al_have_opengl_extension("GL_EXT_framebuffer_object")
      && !al_have_opengl_extension("GL_ARB_fragment_shader")) {
      abort_example("Fragment shaders not supported.\n");
   }

   tinter_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

   glShaderSourceARB(tinter_shader, TINTER_LEN, tinter_shader_src, NULL);
   glCompileShaderARB(tinter_shader);
   tinter = glCreateProgramObjectARB();
   glAttachObjectARB(tinter, tinter_shader);
   glLinkProgramARB(tinter);
   loc = glGetUniformLocationARB(tinter, "backBuffer");
   glUniform1iARB(loc, al_get_opengl_texture(buffer));

   start = al_get_time();

   while (1) {
      double now, diff;
      ALLEGRO_KEYBOARD_STATE state;
      al_get_keyboard_state(&state);
      if (al_key_down(&state, ALLEGRO_KEY_ESCAPE)) {
         break;
      }
      now = al_get_time();
      diff = now - start;
      start = now;
      ratio += diff * 0.5 * dir;
      if (dir < 0 && ratio < 0) {
         ratio = 0;
         dir = -dir;
      }
      else if (dir > 0 && ratio > 1) {
         ratio = 1;
         dir = -dir;
      }

      al_set_target_bitmap(buffer);

      glUseProgramObjectARB(tinter);
      loc = glGetUniformLocationARB(tinter, "ratio");
      glUniform1fARB(loc, ratio);
      loc = glGetUniformLocationARB(tinter, "r");
      glUniform1fARB(loc, r);
      loc = glGetUniformLocationARB(tinter, "g");
      glUniform1fARB(loc, g);
      loc = glGetUniformLocationARB(tinter, "b");
      glUniform1fARB(loc, b);
      al_draw_bitmap(mysha, 0, 0, 0);
      glUseProgramObjectARB(0);

      al_set_target_backbuffer(display);
      al_draw_bitmap(buffer, 0, 0, 0);
      al_flip_display();
      al_rest(0.001);
   }

   glDetachObjectARB(tinter, tinter_shader);
   glDeleteObjectARB(tinter_shader);

   al_uninstall_system();

   return 0;
}