herdem_dog.c
/**
 * Polls SDL for what keys are being pressed and stores
 * these on the dog
 */
Polls SDL for what keys are being pressed and stores
these on the dog
Polls SDL for what keys are being pressed and stores these on the dog
void herdem_dog_input_handler(struct jty_actor *actor)
{
    SDL_Event selection;
    struct herdem_dog *dog = (herdem_dog *)actor;
    if(SDL_PeepEvents(&selection, 1,
                SDL_GETEVENT, SDL_EVENTMASK(SDL_KEYDOWN) |
                              SDL_EVENTMASK(SDL_KEYUP))){
        if (
                dog->player_actions == HERDEM_NONE &&
                selection.key.type == SDL_KEYUP
           ) {
            return;
        }
        switch(selection.key.keysym.sym){
            case SDLK_UP:
                if(selection.key.type == SDL_KEYDOWN) {
                    dog->player_actions |= HERDEM_MOVE_N;
                } else
                    dog->player_actions ^= HERDEM_MOVE_N;
                break;
            case SDLK_DOWN:
                if(selection.key.type == SDL_KEYDOWN)
                    dog->player_actions |= HERDEM_MOVE_S;
                else
                    dog->player_actions ^= HERDEM_MOVE_S;
                break;
            case SDLK_LEFT:
                if(selection.key.type == SDL_KEYDOWN)
                    dog->player_actions |= HERDEM_MOVE_W;
                else
                    dog->player_actions ^= HERDEM_MOVE_W;
                break;
            case SDLK_RIGHT:
                if(selection.key.type == SDL_KEYDOWN) {
                    dog->player_actions |= HERDEM_MOVE_E;
                }   else
                    dog->player_actions ^= HERDEM_MOVE_E;
                break;
            default:
                break;
        }
    }
    herdem_dog_calculate_acceleration(dog);
}
void herdem_dog_input_handler ( struct jty_actor * actor ) { SDL_Event selection ; struct herdem_dog * dog = ( herdem_dog * ) actor ; if ( SDL_PeepEvents ( & selection , 1 , SDL_GETEVENT , SDL_EVENTMASK ( SDL_KEYDOWN ) | SDL_EVENTMASK ( SDL_KEYUP ) ) ) { if ( dog -> player_actions == HERDEM_NONE && selection . key . type == SDL_KEYUP ) { return ; } switch ( selection . key . keysym . sym ) { case SDLK_UP : if ( selection . key . type == SDL_KEYDOWN ) { dog -> player_actions |= HERDEM_MOVE_N ; } else dog -> player_actions ^= HERDEM_MOVE_N ; break ; case SDLK_DOWN : if ( selection . key . type == SDL_KEYDOWN ) dog -> player_actions |= HERDEM_MOVE_S ; else dog -> player_actions ^= HERDEM_MOVE_S ; break ; case SDLK_LEFT : if ( selection . key . type == SDL_KEYDOWN ) dog -> player_actions |= HERDEM_MOVE_W ; else dog -> player_actions ^= HERDEM_MOVE_W ; break ; case SDLK_RIGHT : if ( selection . key . type == SDL_KEYDOWN ) { dog -> player_actions |= HERDEM_MOVE_E ; } else dog -> player_actions ^= HERDEM_MOVE_E ; break ; default : break ; } } herdem_dog_calculate_acceleration ( dog ) ; }
Polls SDL for what keys are being pressed and stores
 these on the dog
Polls SDL for what keys are being pressed and stores these on the dog