Exemplo n.º 1
0
/**
 * @brief Filters a joystick axis event.
 *    @param axis Axis generated by the event.
 *    @param value Value of the axis.
 */
static void input_joyaxis( const SDLKey axis, const int value )
{
   int i, k;
   for (i=0; i<input_numbinds; i++) {
      if (input_keybinds[i].key == axis) {
         /* Positive axis keybinding. */
         if ((input_keybinds[i].type == KEYBIND_JAXISPOS)
               && (value >= 0)) {
            k = (value > 0) ? KEY_PRESS : KEY_RELEASE;
            if ((k == KEY_PRESS) && input_keybinds[i].disabled)
               continue;
            input_key( i, k, fabs(((double)value)/32767.), 0 );
         }

         /* Negative axis keybinding. */
         if ((input_keybinds[i].type == KEYBIND_JAXISNEG)
               && (value <= 0)) {
            k = (value < 0) ? KEY_PRESS : KEY_RELEASE;
            if ((k == KEY_PRESS) && input_keybinds[i].disabled)
               continue;
            input_key( i, k, fabs(((double)value)/32767.), 0 );
         }
      }
   }
}
Exemplo n.º 2
0
/**
 * @brief Handles key repeating.
 */
void input_update( double dt )
{
   unsigned int t;

   if (input_mouseTimer > 0.) {
      input_mouseTimer -= dt;

      /* Hide if necessary. */
      if ((input_mouseTimer < 0.) && (input_mouseCounter <= 0))
         SDL_ShowCursor( SDL_DISABLE );
   }

   /* Key repeat if applicable. */
   if (conf.repeat_delay != 0) {

      /* Key must be repeating. */
      if (repeat_key == -1)
         return;

      /* Get time. */
      t = SDL_GetTicks();

      /* Should be repeating. */
      if (repeat_keyTimer + conf.repeat_delay + repeat_keyCounter*conf.repeat_freq > t)
         return;

      /* Key repeat. */
      repeat_keyCounter++;
      input_key( repeat_key, KEY_PRESS, 0., 1 );
   }
}
Exemplo n.º 3
0
/**
 * @brief Filters a joystick button event.
 *    @param event Event type (down/up).
 *    @param button Button generating the event.
 */
static void input_joyevent( const int event, const SDLKey button )
{
   int i;
   for (i=0; i<input_numbinds; i++) {
      if ((event == KEY_PRESS) && input_keybinds[i].disabled)
         continue;
      if ((input_keybinds[i].type == KEYBIND_JBUTTON) &&
            (input_keybinds[i].key == button))
         input_key(i, event, -1., 0);
   }
}
Exemplo n.º 4
0
void main()
{
	set();
	while (1)
	{
		if (!chkReverse()) break;
		marking();
		draw();
		if (turn == WHITE) //input_u();
			input_key();
		else input_c();
		if (chk_end()) break;
		chturn();
	}
	victory();
}
Exemplo n.º 5
0
/**
 * @brief Filters a keyboard event.
 *    @param event Event type (down/up).
 *    @param key Key generating the event.
 *    @param mod Modifiers active when event was generated.
 */
static void input_keyevent( const int event, SDLKey key, const SDLMod mod, const int repeat )
{
   int i;
   SDLMod mod_filtered;

   /* Filter to "Naev" modifiers. */
   mod_filtered = input_translateMod(mod);

   for (i=0; i<input_numbinds; i++) {
      if ((event == KEY_PRESS) && input_keybinds[i].disabled)
         continue;
      if ((input_keybinds[i].type == KEYBIND_KEYBOARD) &&
            (input_keybinds[i].key == key)) {
         if ((input_keybinds[i].mod == mod_filtered) ||
               (input_keybinds[i].mod == NMOD_ALL) ||
               (event == KEY_RELEASE)) /**< Release always gets through. */
            input_key(i, event, -1., repeat);
            /* No break so all keys get pressed if needed. */
      }
   }
}
Exemplo n.º 6
0
int main(void) {
    // Initial setup of the I/O ports.
    AD1PCFG = 0xFFFF;               // Default all pins to digital.
    mJTAGPortEnable(0);             // Turn off JTAG.

    // Setup the CPU.
    // System config performance.
    SYSTEMConfigPerformance(CLOCKFREQ);
#if defined(MAXIMITE) || (defined(UBW32) && defined(__DEBUG)) || \
    defined(DUINOMITE)
    // Fix the peripheral bus to the main clock speed.
    mOSCSetPBDIV(OSC_PB_DIV_1);
#endif

    INTEnableSystemMultiVectoredInt();  // Allow vectored interrupts.

    keyboard_init();       // Initialise and startup the keyboard routines.
    video_init();          // Start the video state machine.
    video_clear_screen();  // Clear the video buffer.

    DelayUs(1*1000*1000);
    while (keyboard_inkey() != -1);

    video_display_string("MAXIMITE console\r\n");

    while (1) {
      int ch = input_key();
      video_put_char(ch);
      {
          static char buf[10];
          sprintf(buf, "<%02X>", ch);
          video_display_string(buf);
      }
      if (ch == '\n') video_put_char('\r');
    }
}
Exemplo n.º 7
0
void controller_system_update(ControllerSystem* self) {
    GET_SYSTEM_COMPONENTS(self);

    for (u32 i = 0; i < components->count; ++i) {
        Entity entity = GET_ENTITY(i);
        ControllerComponent* controller = (ControllerComponent*)GET_SYSTEM_COMPONENT(i);

        MovementComponent* movement =
            (MovementComponent*)GET_COMPONENT(entity, COMPONENT_MOVEMENT);

        TransformComponent* transform =
            (TransformComponent*)GET_COMPONENT(entity, COMPONENT_TRANSFORM);

        REQUIRED_COMPONENTS(transform, movement, controller);

        f32 x = 0;
        f32 y = 0;

        if (input_key(SDL_SCANCODE_LEFT)) {
            x -= 1.f;
        }

        if (input_key(SDL_SCANCODE_RIGHT)) {
            x += 1.f;
        }

        if (input_key(SDL_SCANCODE_UP)) {
            y -= 1.f;
        }

        if (input_key(SDL_SCANCODE_DOWN)) {
            y += 1.f;
        }

        //printf("%f\n", controller->moveSpeed);

        x *= controller->moveSpeed;
        y *= controller->moveSpeed;

        vec2_set(&movement->velocity, x, y);

        if (input_key_down(SDL_SCANCODE_Z)) {
            for (u32 i = 0; i < controller->bulletSourceCount; ++i) {
                bullet_source_on(&controller->bulletSources[i]);
            }
        }
        if (input_key_up(SDL_SCANCODE_Z)) {
            for (u32 i = 0; i < controller->bulletSourceCount; ++i) {
                bullet_source_off(&controller->bulletSources[i]);
            }
        }

        for (u32 i = 0; i < controller->bulletSourceCount; ++i) {
            bullet_source_update(&controller->bulletSources[i], globals.time.delta, self->super.entityManager, &transform->position);
        }        

        //if (controller->fireTimer > 0.f) {
        //    controller->fireTimer -= globals.time.delta;
        //}

        //if (input_key(SDL_SCANCODE_Z) && controller->fireTimer <= 0.f) {
        //    Vec2 pos = vec2_clone(&transform->position);
        //    pos.x += 64;
        //    pos.y += 52;
        //    entity_create_bullet(self->super.entityManager,
        //        vec2_clone(&pos),
        //        textures_get("player_bullet_1.png"));
        //    controller->fireTimer = controller->fireDelay;
        //}
    }
}