diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-12-03 12:23:41 +0000 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-12-03 12:23:41 +0000 |
commit | bc01a352740c34e5f2f83efbee14e0bc9ef28ba5 (patch) | |
tree | 18fd777af7948a3caecc1c63b8a2173a0ad5d4bc | |
parent | 2822267d7b38756af7a27e7169c08dddca4f3a2c (diff) |
Implement sprinting
-rw-r--r-- | Level.cpp | 2 | ||||
-rw-r--r-- | Player.cpp | 16 | ||||
-rw-r--r-- | Player.h | 8 | ||||
-rw-r--r-- | intensemarcus.h | 1 | ||||
-rw-r--r-- | main.cpp | 8 |
5 files changed, 33 insertions, 2 deletions
@@ -110,7 +110,7 @@ void Level::draw(Screen *screen) { screen->blit(player.getX(), player.getY(), player.image, player.getClip()); // Scroll level - if (player.getX() == 0 || player.getX() >= SCREEN_WIDTH + if (player.getX() < -player.getXVel() || player.getX() >= SCREEN_WIDTH - player.getClip()->w - 32 - MOVE_AMOUNT) { if (player.getXVel() < 0 || player.getXVel() > 0) cameraX -= player.getXVel(); @@ -3,6 +3,7 @@ Player::Player() { health = 100; + sprint = false; } void Player::jump() { @@ -16,3 +17,18 @@ void Player::kill() { health = 0; // Do resetting stuff } + +void Player::setSprint(bool s) { + sprint = s; +} + +bool Player::getSprint() { + return sprint; +} + +int Player::getXVel() { + if (sprint) + return xVel * SPRINT_MULTIPLYER; + else + return xVel; +} @@ -12,8 +12,14 @@ class Player : public Creature { // Kill the player, in the game sense void kill(); + // Enable or disable sprinting + void setSprint(bool s); + bool getSprint(); + + int getXVel(); + private: - // Nothing yet! + bool sprint; }; #endif diff --git a/intensemarcus.h b/intensemarcus.h index f4ceac5..3e98220 100644 --- a/intensemarcus.h +++ b/intensemarcus.h @@ -18,6 +18,7 @@ const int ORIENT_LEFT = 3; const int GRAVITY = 3; const int JUMP_STRENGTH = 40; const int MOVE_AMOUNT = 10; +const float SPRINT_MULTIPLYER = 1.5; const int MAP_X = 48; const int MAP_Y = 12; const int TILE_SIZE = 50; @@ -45,6 +45,10 @@ int main(int argc, char* args[]) { case SDLK_UP: level.player.jump(); break; + case SDLK_LCTRL: + level.player.setSprint(true); + std::cout << "Running...\n"; + break; } } else if (event.type == SDL_KEYUP) { // Adjust player velocity @@ -55,6 +59,10 @@ int main(int argc, char* args[]) { case SDLK_RIGHT: level.player.incXVel(-MOVE_AMOUNT); break; + case SDLK_LCTRL: + level.player.setSprint(false); + std::cout << "Stop running.\n"; + break; } } |