Skip to content

Commit

Permalink
episode 13 - looking up and down
Browse files Browse the repository at this point in the history
  • Loading branch information
Limeoats committed Oct 7, 2015
1 parent b12334d commit 3aade4b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 3 deletions.
39 changes: 39 additions & 0 deletions notes/episode 13 - looking up and down.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
=====================================================
Remaking Cavestory in C++
Episode 13 - Looking up and down
By: Limeoats
Website: www.limeoats.com
Twitter: @Limeoats
Github: https://github.com/Limeoats/cavestory-development
Reddit: http://www.reddit.com/r/Limeoats
=====================================================

=====================================================
Problem
=====================================================
-Quote needs to be able to look up and down
-Quote also needs to look backwards to interact with things


=====================================================
Details
=====================================================
-MyChar.png


=====================================================
Solution
=====================================================
-Add new animations
-Add functions to player for lookUp, stopLookingUp, lookDown, stopLookingDown
-Call these functions from the game class


=====================================================
Next time
=====================================================
-The HUD (or part of it at least)
-We'll get health displayed on the screen



24 changes: 24 additions & 0 deletions source/headers/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ class Player : public AnimatedSprite {
/* void jump
* Starts jumping
*/

/* void lookUp
* The player looks up
*/
void lookUp();

/* void stopLookingUp
* The player stops looking up
*/
void stopLookingUp();

/* void lookDown
* The player looks down OR interacts (turns around)
*/
void lookDown();

/* void stopLookingDown
* The player stops looking down or interacting
*/
void stopLookingDown();

void jump();

virtual void animationDone(std::string currentAnimation);
Expand All @@ -49,6 +70,9 @@ class Player : public AnimatedSprite {
Direction _facing;

bool _grounded;

bool _lookingUp;
bool _lookingDown;
};

#endif
14 changes: 14 additions & 0 deletions source/src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ void Game::gameLoop() {
this->_player.moveRight();
}

if (input.isKeyHeld(SDL_SCANCODE_UP) == true) {
this->_player.lookUp();
}
else if (input.isKeyHeld(SDL_SCANCODE_DOWN) == true) {
this->_player.lookDown();
}

if (input.wasKeyReleased(SDL_SCANCODE_UP) == true) {
this->_player.stopLookingUp();
}
if (input.wasKeyReleased(SDL_SCANCODE_DOWN) == true) {
this->_player.stopLookingDown();
}

if (input.wasKeyPressed(SDL_SCANCODE_Z) == true) {
this->_player.jump();
}
Expand Down
56 changes: 53 additions & 3 deletions source/src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ void Player::setupAnimations() {
this->addAnimation(1, 0, 16, "IdleRight", 16, 16, Vector2(0,0));
this->addAnimation(3, 0, 0, "RunLeft", 16, 16, Vector2(0,0));
this->addAnimation(3, 0, 16, "RunRight", 16, 16, Vector2(0,0));
this->addAnimation(1, 3, 0, "IdleLeftUp", 16, 16, Vector2(0,0));
this->addAnimation(1, 3, 16, "IdleRightUp", 16, 16, Vector2(0,0));
this->addAnimation(3, 3, 0, "RunLeftUp", 16, 16, Vector2(0,0));
this->addAnimation(3, 3, 16, "RunRightUp", 16, 16, Vector2(0,0));
this->addAnimation(1, 6, 0, "LookDownLeft", 16, 16, Vector2(0,0));
this->addAnimation(1, 6, 16, "LookDownRight", 16, 16, Vector2(0,0));
this->addAnimation(1, 7, 0, "LookBackwardsLeft", 16, 16, Vector2(0,0));
this->addAnimation(1, 7, 16, "LookBackwardsRight", 16, 16, Vector2(0,0));
}

void Player::animationDone(std::string currentAnimation) {}
Expand All @@ -42,22 +50,64 @@ const float Player::getY() const {
}

void Player::moveLeft() {
if (this->_lookingDown == true && this->_grounded == true) {
return;
}
this->_dx = -player_constants::WALK_SPEED;
this->playAnimation("RunLeft");
if (this->_lookingUp == false) {
this->playAnimation("RunLeft");
}
this->_facing = LEFT;
}

void Player::moveRight() {
if (this->_lookingDown == true && this->_grounded == true) {
return;
}
this->_dx = player_constants::WALK_SPEED;
this->playAnimation("RunRight");
if (this->_lookingUp == false) {
this->playAnimation("RunRight");
}
this->_facing = RIGHT;
}

void Player::stopMoving() {
this->_dx = 0.0f;
this->playAnimation(this->_facing == RIGHT ? "IdleRight" : "IdleLeft");
if (this->_lookingUp == false && this->_lookingDown == false) {
this->playAnimation(this->_facing == RIGHT ? "IdleRight" : "IdleLeft");
}
}

void Player::lookUp() {
this->_lookingUp = true;
if (this->_dx == 0) {
this->playAnimation(this->_facing == RIGHT ? "IdleRightUp" : "IdleLeftUp");
}
else {
this->playAnimation(this->_facing == RIGHT ? "RunRightUp" : "RunLeftUp");
}
}

void Player::stopLookingUp() {
this->_lookingUp = false;
}

void Player::lookDown() {
this->_lookingDown = true;
if (this->_grounded == true) {
//We need to interact (turn backwards)
this->playAnimation(this->_facing == RIGHT ? "LookBackwardsRight" : "LookBackwardsLeft");
}
else {
this->playAnimation(this->_facing == RIGHT? "LookDownRight" : "LookDownLeft");
}
}

void Player::stopLookingDown() {
this->_lookingDown = false;
}


void Player::jump() {
if (this->_grounded) {
this->_dy = 0;
Expand Down

0 comments on commit 3aade4b

Please sign in to comment.