1
0
Fork 0

Move platform using keyboard keys

This commit is contained in:
Gregory Eremin 2015-09-29 21:18:43 +03:00
parent c01a19a9ee
commit a0b460a5cc
1 changed files with 30 additions and 0 deletions

View File

@ -53,6 +53,36 @@ int main(int argc, char const *argv[]) {
// Render the rect to the screen
SDL_RenderPresent(renderer);
SDL_Event e;
bool quit = false;
while (!quit) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
quit = true;
}
if (e.type == SDL_KEYDOWN) {
switch (e.key.keysym.sym) {
case SDLK_q:
quit = true;
break;
case SDLK_LEFT:
platform.x-=5;
break;
case SDLK_RIGHT:
platform.x+=5;
break;
}
}
// Re-rendering
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderFillRect(renderer, &platform);
SDL_RenderPresent(renderer);
}
}
SDL_DestroyWindow(window);
SDL_Quit();