-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mark
committed
Oct 1, 2015
1 parent
2d4ffc0
commit fd383de
Showing
9 changed files
with
259 additions
and
2 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,49 @@ | ||
===================================================== | ||
Remaking Cavestory in C++ | ||
Episode 11 - Slopes (and jumping)! | ||
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 to be able to run up and down slopes | ||
-Currently, we only have rectangular "tile" collisions | ||
-We need to be able to jump | ||
|
||
===================================================== | ||
Details | ||
===================================================== | ||
-Polyline slopes | ||
-const float JUMP_SPEED = 0.7f; | ||
|
||
|
||
===================================================== | ||
Solution | ||
===================================================== | ||
-New Object layer in Tiled "slopes" | ||
-Draw slopes with the Polyline tool | ||
-Utils class: string split function | ||
-Create the slope class | ||
-Create list of slopes in level class | ||
-Parse them out of the .tmx file | ||
-Handle the slope collisions (player and game classes) | ||
-Player jumping | ||
|
||
|
||
===================================================== | ||
Next time | ||
===================================================== | ||
-Animated Tiled objects | ||
-The health chest | ||
-The save floppy disk | ||
|
||
|
||
|
||
|
||
|
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,52 @@ | ||
#ifndef SLOPE_H | ||
#define SLOPE_H | ||
|
||
#include "globals.h" | ||
|
||
#include <cmath> | ||
|
||
class Slope { | ||
public: | ||
Slope() {} | ||
Slope(Vector2 p1, Vector2 p2) : | ||
_p1(p1), | ||
_p2(p2) | ||
{ | ||
if (this->_p2.x - this->_p1.x != 0) { | ||
this->_slope = (fabs(this->_p2.y) - fabs(this->_p1.y)) / (fabs(this->_p2.x) - fabs(this->_p1.x)); | ||
} | ||
} | ||
|
||
const inline float getSlope() const { | ||
return this->_slope; | ||
} | ||
|
||
const bool collidesWith(const Rectangle &other) const { | ||
return | ||
(other.getRight() >= this->_p2.x && | ||
other.getLeft() <= this->_p1.x && | ||
other.getTop() <= this->_p2.y && | ||
other.getBottom() >= this->_p1.y) || | ||
(other.getRight() >= this->_p1.x && | ||
other.getLeft() <= this->_p2.x && | ||
other.getTop() <= this->_p1.y && | ||
other.getBottom() >= this->_p2.y) || | ||
(other.getLeft() <= this->_p1.x && | ||
other.getRight() >= this->_p2.x && | ||
other.getTop() <= this->_p1.y && | ||
other.getBottom() >= this->_p2.y) || | ||
(other.getLeft() <= this->_p2.x && | ||
other.getRight() >= this->_p1.x && | ||
other.getTop() <= this->_p2.y && | ||
other.getBottom() >= this->_p1.y); | ||
} | ||
|
||
const inline Vector2 getP1() const { return this->_p1; } | ||
const inline Vector2 getP2() const { return this->_p2; } | ||
|
||
private: | ||
Vector2 _p1, _p2; | ||
float _slope; | ||
}; | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef UTILS_H | ||
#define UTILS_H | ||
|
||
class Utils { | ||
public: | ||
|
||
//unsigned int split | ||
//split a string <txt> everywehre a certain character <ch> is found | ||
//store the resulting substrings in a vector <strs> | ||
//returns the size of the vector | ||
static unsigned int split(const std::string &txt, std::vector<std::string> &strs, char ch) { | ||
int pos = txt.find(ch); | ||
int initialPos = 0; | ||
strs.clear(); | ||
while (pos != std::string::npos) { | ||
strs.push_back(txt.substr(initialPos, pos - initialPos + 1)); | ||
initialPos = pos + 1; | ||
|
||
pos = txt.find(ch, initialPos); | ||
} | ||
//Add the last one | ||
strs.push_back(txt.substr(initialPos, std::min<int>(pos, txt.size() - (initialPos + 1)))); | ||
|
||
return strs.size(); | ||
} | ||
}; | ||
|
||
#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