-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
episode 10 - the level class - part 4
- Loading branch information
mark
committed
Sep 29, 2015
1 parent
c2ce873
commit 2d4ffc0
Showing
11 changed files
with
338 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
===================================================== | ||
Remaking Cavestory in C++ | ||
Episode 10 - The level class - Part 4 | ||
By: Limeoats | ||
Website: www.limeoats.com | ||
Twitter: @Limeoats | ||
Github: https://github.com/Limeoats/cavestory-development | ||
Reddit: http://www.reddit.com/r/Limeoats | ||
===================================================== | ||
|
||
|
||
===================================================== | ||
Problem | ||
===================================================== | ||
-We need gravity to be applied to our character | ||
-Collision! | ||
-Specify spawn point in Tiled | ||
|
||
|
||
|
||
===================================================== | ||
Details | ||
===================================================== | ||
-Gravity constants: | ||
GRAVITY = 0.002f; | ||
GRAVITY_CAP = 0.8f; | ||
|
||
-Spawn point: 280, 252 | ||
|
||
|
||
===================================================== | ||
Solution | ||
===================================================== | ||
-Add gravity to the player | ||
-Create "side" namespace in globals | ||
-Create the rectangle class | ||
-Add collisionRects vector to Level | ||
-Draw the collisions in Tiled | ||
-Parse the collisions | ||
-Check tile collisions! | ||
-Bounding box | ||
-getCollisionSide in sprite class | ||
-handleTileCollisions in player class | ||
-Finally, add it all to the game class!! | ||
-Draw spawn point in Tiled | ||
-Parse it and save it in spawn point | ||
-Change spawn point in game class to use it | ||
|
||
===================================================== | ||
Next time | ||
===================================================== | ||
-We finally finished the level class!!!!!!!! | ||
...or did we? | ||
|
||
-SLOPES | ||
-A very complicated subject | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef RECTANGLE_H | ||
#define RECTANGLE_H | ||
|
||
#include "globals.h" | ||
|
||
class Rectangle { | ||
public: | ||
Rectangle() {} | ||
|
||
Rectangle(int x, int y, int width, int height) : | ||
_x(x), | ||
_y(y), | ||
_width(width), | ||
_height(height) | ||
{} | ||
|
||
const int getCenterX() const { return this->_x + this->_width / 2; } | ||
const int getCenterY() const { return this->_y + this->_height / 2; } | ||
|
||
const int getLeft() const { return this->_x; } | ||
const int getRight() const { return this->_x + this->_width; } | ||
const int getTop() const { return this->_y; } | ||
const int getBottom() const { return this->_y + this->_height; } | ||
|
||
const int getWidth() const { return this->_width; } | ||
const int getHeight() const { return this->_height; } | ||
|
||
const int getSide(const sides::Side side) const { | ||
return | ||
side == sides::LEFT ? this->getLeft() : | ||
side == sides::RIGHT ? this->getRight() : | ||
side == sides::TOP ? this->getTop() : | ||
side == sides::BOTTOM ? this->getBottom() : | ||
sides::NONE; | ||
} | ||
|
||
//bool collidesWith | ||
//Takes in another Rectangle and checks if the two are colliding | ||
const bool collidesWith(const Rectangle &other) const { | ||
return | ||
this->getRight() >= other.getLeft() && | ||
this->getLeft() <= other.getRight() && | ||
this->getTop() <= other.getBottom() && | ||
this->getBottom() >= other.getTop(); | ||
} | ||
|
||
const bool isValidRectangle() const { | ||
return (this->_x >= 0 && this->_y >= 0 && this->_width >= 0 && this->_height >= 0); | ||
} | ||
|
||
private: | ||
int _x, _y, _width, _height; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.