-
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 6, 2015
1 parent
fd383de
commit b12334d
Showing
8 changed files
with
221 additions
and
24 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 12 - Animated tiles | ||
By: Limeoats | ||
Website: www.limeoats.com | ||
Twitter: @Limeoats | ||
Github: https://github.com/Limeoats/cavestory-development | ||
Reddit: http://www.reddit.com/r/Limeoats | ||
===================================================== | ||
|
||
|
||
===================================================== | ||
Problem | ||
===================================================== | ||
-All of our tiles just sit still | ||
-We want tiles that are animated on the screen | ||
-We also want them animated in Tiled | ||
-Our map isn't quite complete yet (heart container and save disk) | ||
|
||
===================================================== | ||
Details | ||
===================================================== | ||
-Npc/NpcSym.pbm | ||
-Save disk duration: 100 | ||
-Health duration: 10 | ||
|
||
===================================================== | ||
Solution | ||
===================================================== | ||
-Fix AnimatedSprite update | ||
-Convert Npc/NpcSym.pbm to png and put it in tilesets folder | ||
-Create the tiles in Tiled | ||
-Fix the tile loading | ||
-Create AnimatedTile class | ||
-Parse the animation out of the .tmx file | ||
-Modify the level class to use our new AnimatedTile | ||
|
||
|
||
===================================================== | ||
Next time | ||
===================================================== | ||
-Make Quote look up and down | ||
-while walking | ||
-while jumping | ||
-Make Quote look behind him (interacting) | ||
|
||
|
||
|
||
|
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,32 @@ | ||
#ifndef ANIMATED_TILE_H | ||
#define ANIMATED_TILE_H | ||
|
||
#include <vector> | ||
|
||
#include "tile.h" | ||
#include "globals.h" | ||
|
||
class AnimatedTile : public Tile { | ||
public: | ||
AnimatedTile(std::vector<Vector2> tilesetPositions, int duration, SDL_Texture* tileset, Vector2 size, Vector2 position); | ||
void update(int elapsedTime); | ||
void draw(Graphics &graphics); | ||
protected: | ||
int _amountOfTime = 0; | ||
bool _notDone = false; | ||
private: | ||
std::vector<Vector2> _tilesetPositions; | ||
int _tileToDraw; | ||
int _duration; | ||
}; | ||
|
||
struct AnimatedTileInfo { | ||
public: | ||
int TilesetsFirstGid; | ||
int StartTileId; | ||
std::vector<int> TileIds; | ||
int Duration; | ||
}; | ||
|
||
|
||
#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
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,36 @@ | ||
#include "animatedtile.h" | ||
#include "graphics.h" | ||
|
||
AnimatedTile::AnimatedTile(std::vector<Vector2> tilesetPositions, int duration, | ||
SDL_Texture* tileset, Vector2 size, Vector2 position) : | ||
Tile(tileset, size, tilesetPositions.at(0), position), | ||
_tilesetPositions(tilesetPositions), | ||
_duration(duration), | ||
_tileToDraw(0) | ||
{} | ||
|
||
void AnimatedTile::update(int elapsedTime) { | ||
//Timer code | ||
if (this->_amountOfTime <= 0) { | ||
if (this->_tileToDraw == this->_tilesetPositions.size() -1) { | ||
this->_tileToDraw = 0; | ||
} | ||
else { | ||
this->_tileToDraw++; | ||
} | ||
this->_amountOfTime = this->_duration; | ||
} | ||
else { | ||
this->_amountOfTime -= elapsedTime; | ||
} | ||
|
||
Tile::update(elapsedTime); | ||
} | ||
|
||
void AnimatedTile::draw(Graphics &graphics) { | ||
SDL_Rect destRect = { this->_position.x, this->_position.y, | ||
this->_size.x * globals::SPRITE_SCALE, this->_size.y * globals::SPRITE_SCALE }; | ||
SDL_Rect sourceRect = { this->_tilesetPositions.at(this->_tileToDraw).x, this->_tilesetPositions.at(this->_tileToDraw).y, | ||
this->_size.x, this->_size.y }; | ||
graphics.blitSurface(this->_tileset, &sourceRect, &destRect); | ||
} |
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