From 3e45e8c0bdb2218bde1c861d14df7216316bbc05 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Fri, 26 Nov 2010 13:36:32 +0000 Subject: Implement player jumping --- Player.cpp | 4 +++- intensemarcus.h | 1 + main.cpp | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Player.cpp b/Player.cpp index a7df818..9865648 100644 --- a/Player.cpp +++ b/Player.cpp @@ -7,7 +7,9 @@ Player::Player() { } void Player::jump() { - std::cout << "Player::jump(): Jumping!.\n"; + if (!yVel) { + incYVel(-JUMP_STRENGTH); + } } void Player::kill() { diff --git a/intensemarcus.h b/intensemarcus.h index 8386411..8a4dd5a 100644 --- a/intensemarcus.h +++ b/intensemarcus.h @@ -16,6 +16,7 @@ const int ORIENT_BACK = 1; const int ORIENT_RIGHT = 2; const int ORIENT_LEFT = 3; const int GRAVITY = 3; +const int JUMP_STRENGTH = 40; SDL_Surface *loadImage(std::string filename); diff --git a/main.cpp b/main.cpp index 7eeeabe..81e5896 100644 --- a/main.cpp +++ b/main.cpp @@ -42,6 +42,9 @@ int main(int argc, char* args[]) { case SDLK_RIGHT: level.player.incXVel(10); break; + case SDLK_UP: + level.player.jump(); + break; } } else if (event.type == SDL_KEYUP) { // Adjust player velocity -- cgit v1.2.3