예제 #1
0
void InputContext::TriggerMouseEvent(MouseEvent &mouse)
{
    emit MouseEventReceived(&mouse);

    switch(mouse.eventType)
    {
    case MouseEvent::MouseMove: emit MouseMove(&mouse); break;
    case MouseEvent::MouseScroll: emit MouseScroll(&mouse); break;
    case MouseEvent::MousePressed:
        switch(mouse.button)
        {
        case MouseEvent::LeftButton: emit MouseLeftPressed(&mouse); break;
        case MouseEvent::RightButton: emit MouseRightPressed(&mouse); break;
        case MouseEvent::MiddleButton: emit MouseMiddlePressed(&mouse); break;
            ///\todo XButton1 and XButton2 support?
        }
        break;
    case MouseEvent::MouseReleased: 
        switch(mouse.button)
        {
        case MouseEvent::LeftButton: emit MouseLeftReleased(&mouse); break;
        case MouseEvent::RightButton: emit MouseRightReleased(&mouse); break;
        case MouseEvent::MiddleButton: emit MouseMiddleReleased(&mouse); break;
            ///\todo XButton1 and XButton2 support?
        }
        break;
    case MouseEvent::MouseDoubleClicked: emit MouseDoubleClicked(&mouse); break;
    default:
        assert(false);
        break;
    }
}
예제 #2
0
void SugoiGame::PollEvents() {
	sr::Event event;
	while (m_window->PollEvent(event)) {
		switch (event.type) {

		case sr::Event::WINDOW_CLOSED:
			m_window->Close();
			break;

		case sr::Event::KEY_PRESSED:
			KeyPressed(event.key.keyCode, event.key.alt, event.key.control, event.key.shift, event.key.system);
			break;

		case sr::Event::KEY_RELEASED:
			KeyReleased(event.key.keyCode, event.key.alt, event.key.control, event.key.shift, event.key.system);
			break;

		case sr::Event::MOUSE_PRESSED:
			if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_1) {
				MouseLeftPressed();
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_2) {
				MouseRightPressed();
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_3) {
				MouseMiddlePressed();
			}
			break;

		case sr::Event::MOUSE_RELEASED:
			if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_1) {
				MouseLeftReleased(event.mouseClicked.x, event.mouseClicked.y);
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_2) {
				MouseRightReleased();
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_3) {
				MouseMiddleReleased();
			}
			break;

		case sr::Event::MOUSE_MOVED:
			MouseMoved(event.mouseMoved.x, event.mouseMoved.y);
			break;

		case sr::Event::MOUSE_SCROLLED:
			MouseScroll(event.mouseScrolled.xoffset, event.mouseScrolled.yoffset);
			break;
		}
	}
}
예제 #3
0
/*-----------------------------------------------------------------
 * @Desc: the acutal Takeover game-playing is done here
 *
 *
 *-----------------------------------------------------------------*/
void
PlayGame (void)
{
  int countdown = 100;   /* lenght of Game in 1/10 seconds */
  char count_text[80];
  int FinishTakeover = FALSE;
  int row;

  Uint32 prev_count_tick, count_tick_len;  /* tick vars for count-down */
  Uint32 prev_move_tick, move_tick_len;    /* tick vars for motion */
  Uint32 last_movekey_time, wait_move_ticks = 110;    /* number of ticks to wait before "key-repeat" */

  int up, down, set; 
  int up_counter, down_counter; 
  int wheel_up, wheel_down;

  count_tick_len = 100;   /* countdown in 1/10 second steps */
  move_tick_len  = 60;    /* allow motion at this tick-speed in ms */
  
  up = down = set = FALSE;
  up_counter = down_counter = 0;
  wheel_up = wheel_down = 0;

  prev_count_tick = prev_move_tick = SDL_GetTicks (); /* start tick clock */
  
  ResetMouseWheel ();  // forget about previous wheel events

  CountdownSound();
  while (!FinishTakeover)
    {
      cur_time = SDL_GetTicks ();
      
      /* 
       * here we register if there have been key-press events in the
       * "waiting period" between move-ticks :
       */
      if ( !up && UpPressed () )
	{
	  up = TRUE;
	  last_movekey_time = SDL_GetTicks();
	}
      if (!down && DownPressed() )
	{
	  down = TRUE;
	  last_movekey_time = SDL_GetTicks();
	}

      set  = set  || (SpacePressed() || MouseLeftPressed());

      if (WheelUpPressed()) wheel_up ++;
      if (WheelDownPressed()) wheel_down ++;

      /* allow for a WIN-key that give immedate victory */
      if ( KeyIsPressedR ('w') && CtrlPressed() && AltPressed() )
	{
	  LeaderColor = YourColor;   /* simple as that */
	  return;  /* leave now, to avoid changing of LeaderColor! */
	} 
	
      if ( cur_time > prev_count_tick + count_tick_len ) /* time to count 1 down */
	{
	  prev_count_tick += count_tick_len;  /* set for next countdown tick */
	  countdown--;
	  sprintf (count_text, "Finish-%d", countdown);
	  DisplayBanner (count_text, NULL , 0 );

	  if (countdown && (countdown%10 == 0) ) CountdownSound();
	  if (countdown == 0)
	    {
	      EndCountdownSound();
	      FinishTakeover = TRUE;
	    }

	  AnimateCurrents ();  /* do some animation on the active cables */

	} /* if (countdown_tick has occurred) */


      /* time for movement */
      if ( cur_time > prev_move_tick + move_tick_len )  
	{
	  prev_move_tick += move_tick_len; /* set for next motion tick */
	  EnemyMovements ();

	  if (wheel_up || (up && (SDL_GetTicks() - last_movekey_time > wait_move_ticks)))
	    {
	      CapsuleCurRow[YourColor]--;
	      if (CapsuleCurRow[YourColor] < 1)
		CapsuleCurRow[YourColor] = NUM_LINES;
	
	      if (!UpPressed()) up = FALSE;  
	      if (wheel_up) wheel_up --;
	    }
	  if (wheel_down || (down && (SDL_GetTicks() - last_movekey_time > wait_move_ticks)))
	    {
	      CapsuleCurRow[YourColor]++;
	      if (CapsuleCurRow[YourColor] > NUM_LINES)
		CapsuleCurRow[YourColor] = 1;

	      if (!DownPressed()) down = FALSE;
	      if (wheel_down) wheel_down --;
	    }    

	  if ( set && (NumCapsules[YOU] > 0))
	    {
	      set = FALSE;
	      row = CapsuleCurRow[YourColor] - 1;
	      if ((row >= 0) &&
		  (ToPlayground[YourColor][0][row] != KABELENDE) &&
		  (ActivationMap[YourColor][0][row] == INACTIVE))
		{
		  NumCapsules[YOU]--;
		  CapsuleCurRow[YourColor] = 0;
		  ToPlayground[YourColor][0][row] = VERSTAERKER;
		  ActivationMap[YourColor][0][row] = ACTIVE1;
		  CapsuleCountdown[YourColor][0][row] = CAPSULE_COUNTDOWN * 2;

		  Takeover_Set_Capsule_Sound ();
		}	/* if (row > 0 && ... ) */
	    } /* if ( set ) */

	  ProcessCapsules ();	/* count down the lifetime of the capsules */

	  ProcessPlayground ();
	  ProcessPlayground ();
	  ProcessPlayground ();
	  ProcessPlayground ();	/* this has to be done several times to be sure */

	  ProcessDisplayColumn ();

	} /* if (motion_tick has occurred) */

      ShowPlayground ();

    }	/* while !FinishTakeover */

  /* Schluss- Countdown */
  countdown = CAPSULE_COUNTDOWN;

  while (countdown--)
    {
      while ( SDL_GetTicks() < prev_count_tick + count_tick_len ) ;
      prev_count_tick += count_tick_len;
      ProcessCapsules ();	/* count down the lifetime of the capsules */
      ProcessCapsules ();	/* do it twice this time to be faster */
      AnimateCurrents ();
      ProcessPlayground ();
      ProcessPlayground ();
      ProcessPlayground ();
      ProcessPlayground ();	/* this has to be done several times to be sure */
      ProcessDisplayColumn ();
      ShowPlayground ();

    }	/* while (countdown) */

    return;

} /* PlayGame() */