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 --- Creature.cpp | 2 ++ Level.cpp | 8 ++++++-- main.cpp | 22 +++++++++++++++++++++- marcussheet.png | Bin 0 -> 45602 bytes 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 marcussheet.png diff --git a/Creature.cpp b/Creature.cpp index 0463e5a..7693cb9 100644 --- a/Creature.cpp +++ b/Creature.cpp @@ -3,6 +3,8 @@ Creature::Creature() { std::cout << "Creature::Creature(): Creature created.\n"; + xVel = 0; + yVel = 0; } int Creature::getXVel() { diff --git a/Level.cpp b/Level.cpp index 0dec3ef..6c0f80c 100644 --- a/Level.cpp +++ b/Level.cpp @@ -29,14 +29,18 @@ void Level::changeLevel(int levelNo) { // Load background image if (!(background = loadImage("space.png"))) std::cout << "Level::changeLevel: Error loading background image.\n"; + + // Make player into a Marcus + player.setImage("marcussheet.png"); } void Level::move() { - //std::cout << "Level::move(): Moving level items.\n"; + player.setX(player.getX() + player.getXVel()); } void Level::draw(Screen *screen) { - //std::cout << "Level::draw(): Drawing into the screen.\n"; // Blit background screen->blit(0, 0, background); + + screen->blit(player.getX(), player.getY(), player.image); } 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) diff --git a/marcussheet.png b/marcussheet.png new file mode 100644 index 0000000..6083fac Binary files /dev/null and b/marcussheet.png differ -- cgit v1.2.3