-
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.
- Loading branch information
Showing
7 changed files
with
192 additions
and
4 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,45 @@ | ||
===================================================== | ||
Remaking Cavestory in C++ | ||
Episode 17 - Enemies | ||
By: Limeoats | ||
Website: www.limeoats.com | ||
Twitter: @Limeoats | ||
Github: https://github.com/Limeoats/cavestory-development | ||
Reddit: http://www.reddit.com/r/Limeoats | ||
===================================================== | ||
|
||
|
||
===================================================== | ||
Problem | ||
===================================================== | ||
-We don't have any monsters in our game yet :( | ||
|
||
|
||
|
||
===================================================== | ||
Details | ||
===================================================== | ||
-We'll be using the Bat in NpcCemet | ||
|
||
3, 2, 32, "FlyLeft", 16, 16 | ||
3, 2, 48, "FlyRight", 16, 16 | ||
|
||
|
||
===================================================== | ||
Solution | ||
===================================================== | ||
-Get NpcCemet.pbm, make background transparent, make it a png and put it in sprites folder | ||
-Create Enemy base class | ||
-Create Bat class extending off of Enemy | ||
-Add bat spawn points to Tiled | ||
-Parse enemy info out of tmx file and into an Enemy vector | ||
-Update and draw from the level class | ||
|
||
|
||
===================================================== | ||
Next time | ||
===================================================== | ||
-Move the bat | ||
-Collision with the bat (and damage to the player) | ||
-Damage numbers? (maybe two episodes from now) | ||
|
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,43 @@ | ||
#ifndef ENEMY_H | ||
#define ENEMY_H | ||
|
||
#include "animatedsprite.h" | ||
#include "globals.h" | ||
#include "player.h" | ||
|
||
#include <string> | ||
|
||
class Graphics; | ||
|
||
class Enemy : public AnimatedSprite { | ||
public: | ||
Enemy(); | ||
Enemy(Graphics &graphics, std::string filePath, int sourceX, int sourceY, | ||
int width, int height, Vector2 spawnPoint, int timeToUpdate); | ||
virtual void update(int elapsedTime, Player &player); | ||
virtual void draw(Graphics &graphics); | ||
|
||
const inline int getMaxHealth() const { return this->_maxHealth; } | ||
const inline int getCurrentHealth() const { return this->_currentHealth; } | ||
protected: | ||
Direction _direction; | ||
|
||
int _maxHealth; | ||
int _currentHealth; | ||
}; | ||
|
||
|
||
class Bat : public Enemy { | ||
public: | ||
Bat(); | ||
Bat(Graphics &graphics, Vector2 spawnPoint); | ||
void update(int elapsedTime, Player &player); | ||
void draw(Graphics &graphics); | ||
|
||
void animationDone(std::string currentAnimation); | ||
void setupAnimations(); | ||
private: | ||
}; | ||
|
||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "enemy.h" | ||
|
||
//Base enemy class | ||
Enemy::Enemy() {} | ||
|
||
Enemy::Enemy(Graphics &graphics, std::string filePath, int sourceX, int sourceY, int width, int height, | ||
Vector2 spawnPoint, int timeToUpdate) : | ||
AnimatedSprite(graphics, filePath, sourceX, sourceY, width, height, | ||
spawnPoint.x, spawnPoint.y, timeToUpdate), | ||
_direction(LEFT), | ||
_maxHealth(0), | ||
_currentHealth(0) | ||
{} | ||
|
||
void Enemy::update(int elapsedTime, Player &player) { | ||
AnimatedSprite::update(elapsedTime); | ||
} | ||
|
||
void Enemy::draw(Graphics &graphics) { | ||
AnimatedSprite::draw(graphics, this->_x, this->_y); | ||
} | ||
|
||
|
||
//Bat class | ||
Bat::Bat() {} | ||
|
||
Bat::Bat(Graphics &graphics, Vector2 spawnPoint) : | ||
Enemy(graphics, "content/sprites/NpcCemet.png", 32, 32, 16, 16, spawnPoint, 140) | ||
{ | ||
this->setupAnimations(); | ||
this->playAnimation("FlyLeft"); | ||
} | ||
|
||
void Bat::update(int elapsedTime, Player &player) { | ||
this->_direction = player.getX() > this->_x ? RIGHT : LEFT; | ||
this->playAnimation(this->_direction == RIGHT ? "FlyRight" : "FlyLeft"); | ||
Enemy::update(elapsedTime, player); | ||
} | ||
|
||
void Bat::draw(Graphics &graphics) { | ||
Enemy::draw(graphics); | ||
} | ||
|
||
void Bat::animationDone(std::string currentAnimation) { | ||
|
||
} | ||
|
||
void Bat::setupAnimations() { | ||
this->addAnimation(3, 2, 32, "FlyLeft", 16, 16, Vector2(0,0)); | ||
this->addAnimation(3, 2, 48, "FlyRight", 16, 16, Vector2(0,0)); | ||
} |
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