I know that you have already chosen the answer .. but here is some actual code of how I usually do this with a single array. :)
first define it somewhere.
bool KEYS[322];
for(int i = 0; i < 322; i++) {
KEYS[i] = false;
}
SDL_EnableKeyRepeat(0,0);
Then later create a keyboard () function that will register keyboard input
void keyboard() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
game_state = 0;
break;
case SDL_KEYDOWN:
KEYS[event.key.keysym.sym] = true;
break;
case SDL_KEYUP:
KEYS[event.key.keysym.sym] = false;
break;
default:
break;
}
}
}
, , handleInput(), :
void handleInput() {
if(KEYS[SDLK_LEFT]) {
if(player->x - player->speed >= 0) {
player->x -= player->speed;
}
}
if(KEYS[SDLK_RIGHT]) {
if(player->x + player->speed <= screen->w) {
player->x += player->speed;
}
}
if(KEYS[SDLK_UP]) {
if(player->y - player->speed >= 0) {
player->y -= player->speed;
}
}
if(KEYS[SDLK_DOWN]) {
if(player->y + player->speed <= screen->h) {
player->y += player->speed;
}
}
if(KEYS[SDLK_s]) {
if(SDL_GetTicks() - player->lastShot > player->shotDelay) {
shootbeam(player->beam);
}
}
if(KEYS[SDLK_q]) {
if(player->beam == PLAYER_BEAM_CHARGE) {
player->beam = PLAYER_BEAM_NORMAL;
} else {
player->beam = PLAYER_BEAM_CHARGE;
}
}
if(KEYS[SDLK_r]) {
reset();
}
if(KEYS[SDLK_ESCAPE]) {
gamestate = 0;
}
}
, , ,
while(KEYS[SDLK_s]) {
keyboard();
}
** -: **
, , SDL ++,
http://kennycason.com/posts/2009-09-20-sdl-simple-space-shooter-game-demo-part-i.html ( - , )