From 5dd6f1089a86e69889056f3853b373025f68026f Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Thu, 25 Nov 2010 21:12:09 +0000 Subject: Add a marcus sprite sheet, set it as the player's image, implement left/right keyboard input --- main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 55db293..7eeeabe 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,27 @@ int main(int argc, char* args[]) { // Get input while (SDL_PollEvent(&event)) { - //std::cout << "Got event.\n"; + if (event.type == SDL_KEYDOWN) { + // Adjust player velocity + switch (event.key.keysym.sym) { + case SDLK_LEFT: + level.player.incXVel(-10); + break; + case SDLK_RIGHT: + level.player.incXVel(10); + break; + } + } else if (event.type == SDL_KEYUP) { + // Adjust player velocity + switch (event.key.keysym.sym) { + case SDLK_LEFT: + level.player.incXVel(10); + break; + case SDLK_RIGHT: + level.player.incXVel(-10); + break; + } + } // Handle the user trying to close the window if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE) -- cgit v1.2.3