135 lines
3.1 KiB
C
135 lines
3.1 KiB
C
|
#ifndef CELL_H
|
||
|
#define CELL_H
|
||
|
|
||
|
#include "entity.h"
|
||
|
#include <memory>
|
||
|
#include <SFML/Graphics/Color.hpp>
|
||
|
|
||
|
class Hero;
|
||
|
class Level;
|
||
|
|
||
|
using HeroPtr = std::unique_ptr<Hero>;
|
||
|
using LevelPtr = std::unique_ptr<Level>;
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
|
||
|
/// Represents interface for all level cells
|
||
|
class Cell : public Entity
|
||
|
{
|
||
|
protected:
|
||
|
sf::Color cell_color;
|
||
|
|
||
|
public:
|
||
|
Cell(coordinate cell_x = 0,
|
||
|
coordinate cell_y = 0,
|
||
|
const sf::Color &color = sf::Color::White);
|
||
|
|
||
|
virtual ~Cell() = 0;
|
||
|
|
||
|
inline sf::Color color() const noexcept;
|
||
|
|
||
|
/// Determine if Hero can move onto this cell or not
|
||
|
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) = 0;
|
||
|
};
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
|
||
|
/// Any cell where Hero is free to move
|
||
|
class PassableCell : public Cell
|
||
|
{
|
||
|
public:
|
||
|
PassableCell(coordinate cell_x = 0,
|
||
|
coordinate cell_y = 0, // Brown
|
||
|
const sf::Color &color = sf::Color(165, 42, 42));
|
||
|
|
||
|
virtual ~PassableCell() override;
|
||
|
|
||
|
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||
|
};
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
|
||
|
/// A cell which requires Hero to spend a charge for bridge to move on
|
||
|
class WaterCell : public Cell
|
||
|
{
|
||
|
public:
|
||
|
WaterCell(coordinate cell_x = 0,
|
||
|
coordinate cell_y = 0,
|
||
|
const sf::Color &color = sf::Color::Blue);
|
||
|
|
||
|
virtual ~WaterCell() override;
|
||
|
|
||
|
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||
|
};
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
|
||
|
/// A cell which is impossible to move on
|
||
|
class WallCell : public Cell
|
||
|
{
|
||
|
public:
|
||
|
WallCell(coordinate cell_x = 0,
|
||
|
coordinate cell_y = 0, // Gray
|
||
|
const sf::Color &color = sf::Color(125, 125, 125));
|
||
|
|
||
|
virtual ~WallCell() override;
|
||
|
|
||
|
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||
|
};
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
|
||
|
/// A cell which gives hero a charge
|
||
|
class ChargeCell : public Cell
|
||
|
{
|
||
|
private:
|
||
|
int cell_charges;
|
||
|
|
||
|
public:
|
||
|
ChargeCell(coordinate cell_x = 0,
|
||
|
coordinate cell_y = 0,
|
||
|
int has_charges = 1,
|
||
|
const sf::Color &color = sf::Color::Green);
|
||
|
|
||
|
virtual ~ChargeCell() override;
|
||
|
|
||
|
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||
|
};
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
|
||
|
/// A cell which moves hero to next level
|
||
|
class ExitCell : public Cell
|
||
|
{
|
||
|
public:
|
||
|
ExitCell(coordinate cell_x = 0,
|
||
|
coordinate cell_y = 0,
|
||
|
const sf::Color &color = sf::Color::Red);
|
||
|
|
||
|
virtual ~ExitCell() override;
|
||
|
|
||
|
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||
|
};
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
|
||
|
/// A cell which teleports hero to following coordinates
|
||
|
class TeleportCell : public Cell
|
||
|
{
|
||
|
private:
|
||
|
coordinate new_x, new_y;
|
||
|
|
||
|
public:
|
||
|
TeleportCell(coordinate cell_x = 0,
|
||
|
coordinate cell_y = 0,
|
||
|
coordinate new_cell_x = 0,
|
||
|
coordinate new_cell_y = 0, // Purple
|
||
|
const sf::Color &color = sf::Color(128, 0, 128));
|
||
|
|
||
|
virtual ~TeleportCell() override;
|
||
|
|
||
|
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||
|
};
|
||
|
|
||
|
#endif // CELL_H
|