cirno-puzzle/src/cell.h

187 lines
4.3 KiB
C
Raw Normal View History

#ifndef CELL_H
#define CELL_H
#include <memory>
2020-03-14 21:33:39 -04:00
#include <vector>
#include <SFML/Graphics/Color.hpp>
2020-03-14 21:33:39 -04:00
#include "entity.h"
2020-03-15 11:02:37 -04:00
namespace palette
{
2020-03-16 10:30:30 -04:00
const sf::Color Brown = sf::Color(165, 42, 42);
const sf::Color White = sf::Color(255, 255, 255);
const sf::Color Blue = sf::Color( 0, 255, 255);
const sf::Color Gray = sf::Color(125, 125, 125);
const sf::Color Green = sf::Color( 0, 255, 0);
const sf::Color Red = sf::Color(250, 0, 0);
const sf::Color Purple = sf::Color(128, 0, 128);
const sf::Color Pink = sf::Color(255, 192, 203);
2020-03-15 11:02:37 -04:00
}
2020-03-15 17:57:39 -04:00
enum CELL_TYPES {
PASSABLE_CELL = 0,
WATER_CELL,
WALL_CELL,
CHARGE_CELL,
EXIT_CELL,
TELEPORT_CELL,
TRIGGER_CELL,
N_CELLS
};
2020-03-15 11:02:37 -04:00
///////////////////////////////////////
class Hero;
class Level;
2020-03-14 21:33:39 -04:00
class Cell;
2020-03-03 11:11:04 -05:00
using HeroPtr = std::unique_ptr<Hero>;
using LevelPtr = std::unique_ptr<Level>;
2020-03-16 10:30:30 -04:00
using CellPtr = std::unique_ptr<Cell>
///////////////////////////////////////
/// Represents interface for all level cells
class Cell : public Entity
{
protected:
sf::Color cell_color;
public:
2020-03-15 17:57:39 -04:00
Cell(coordinate cell_row = 0,
coordinate cell_col = 0,
2020-03-15 11:02:37 -04:00
const sf::Color &color = palette::White);
2020-03-02 17:22:37 -05:00
virtual ~Cell() override;
2020-03-02 17:22:37 -05:00
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:
2020-03-15 17:57:39 -04:00
PassableCell(coordinate cell_row = 0,
2020-03-16 10:30:30 -04:00
coordinate cell_col = 0,
2020-03-15 11:02:37 -04:00
const sf::Color &color = palette::Brown);
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:
2020-03-15 17:57:39 -04:00
WaterCell(coordinate cell_row = 0,
coordinate cell_col = 0,
2020-03-15 11:02:37 -04:00
const sf::Color &color = palette::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:
2020-03-15 17:57:39 -04:00
WallCell(coordinate cell_row = 0,
2020-03-16 10:30:30 -04:00
coordinate cell_col = 0,
2020-03-15 17:57:39 -04:00
const sf::Color &color = palette::Gray);
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:
2020-03-15 17:57:39 -04:00
ChargeCell(coordinate cell_row = 0,
coordinate cell_col = 0,
int has_charges = 1,
2020-03-16 10:30:30 -04:00
const sf::Color &color = palette::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:
2020-03-15 17:57:39 -04:00
ExitCell(coordinate cell_row = 0,
coordinate cell_col = 0,
2020-03-16 10:30:30 -04:00
const sf::Color &color = palette::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:
2020-03-15 17:57:39 -04:00
TeleportCell(coordinate cell_row = 0,
coordinate cell_col = 0,
coordinate new_cell_row = 0,
2020-03-16 10:30:30 -04:00
coordinate new_cell_col = 0,
const sf::Color &color = palette::Purple);
virtual ~TeleportCell() override;
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
};
2020-03-03 11:11:04 -05:00
///////////////////////////////////////
/// A cell which replaces and changes other map cells when activated
class TriggerCell : public Cell
{
private:
// Vector of cells to place on map
2020-03-16 10:30:30 -04:00
std::vector<CellPtr> cells;
2020-03-03 11:11:04 -05:00
public:
2020-03-15 17:57:39 -04:00
TriggerCell(//std::vector<CellPtr> &&cells_to_change,
coordinate cell_row = 0,
2020-03-16 10:30:30 -04:00
coordinate cell_col = 0,
const sf::Color &color = palette::Pink);
2020-03-03 11:11:04 -05:00
virtual ~TriggerCell() override;
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
};
#endif // CELL_H