cirno-puzzle/src/cell.h

217 lines
5.4 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-16 15:27:34 -04:00
const sf::Color Black = sf::Color( 0, 0, 0);
2020-03-15 11:02:37 -04:00
}
enum CELL_TYPE {
2020-03-15 17:57:39 -04:00
PASSABLE_CELL = 0,
WATER_CELL = 1,
WALL_CELL = 2,
CHARGE_CELL = 3,
EXIT_CELL = 4,
TELEPORT_CELL = 5,
TRIGGER_CELL = 6,
2020-03-15 17:57:39 -04:00
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 15:27:34 -04:00
using CellPtr = std::unique_ptr<Cell>;
///////////////////////////////////////
/// Represents interface for all level cells
class Cell : public Entity
{
protected:
sf::Color cell_color;
2020-03-19 17:59:21 -04:00
coordinate height_shift;
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;
2020-03-19 17:59:21 -04:00
/// "shift_by_y" indicates the height of current cell
/// Height is a shift of y coordinate on the scene, relatively to the ground (which is 0)
void setHeightShift(coordinate shift_by_y);
coordinate heightShift() const;
/// Determine if Hero can move onto this cell or not
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) = 0;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const = 0;
};
///////////////////////////////////////
/// Any cell where Hero is free to move
2020-03-16 12:54:42 -04:00
class PassableCell final : 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;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const override;
};
///////////////////////////////////////
/// A cell which requires Hero to spend a charge for bridge to move on
2020-03-16 12:54:42 -04:00
class WaterCell final : 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;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const override;
};
///////////////////////////////////////
/// A cell which is impossible to move on
2020-03-16 12:54:42 -04:00
class WallCell final : 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;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const override;
};
///////////////////////////////////////
/// A cell which gives hero a charge
2020-03-16 12:54:42 -04:00
class ChargeCell final : 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;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const override;
};
///////////////////////////////////////
/// A cell which moves hero to next level
2020-03-16 12:54:42 -04:00
class ExitCell final : 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;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const override;
};
///////////////////////////////////////
/// A cell which teleports hero to following coordinates
2020-03-16 12:54:42 -04:00
class TeleportCell final : public Cell
{
private:
2020-03-16 10:38:04 -04:00
coordinate new_row, new_col;
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;
2020-03-19 17:59:21 -04:00
2020-03-19 11:42:45 -04:00
/// Set the coordinates of this teleport destination
2020-03-19 17:59:21 -04:00
void setDestination(coordinate new_cell_row, coordinate new_cell_col);
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const override;
};
2020-03-03 11:11:04 -05:00
///////////////////////////////////////
/// A cell which replaces and changes other map cells when activated
2020-03-16 12:54:42 -04:00
class TriggerCell final : public Cell
2020-03-03 11:11:04 -05:00
{
private:
// Vector of cells to place on map
2020-03-19 17:59:21 -04:00
std::vector<CellPtr> vector_cells;
2020-03-03 11:11:04 -05:00
public:
2020-03-19 11:42:45 -04:00
/// Vector of cell types you can cast in to
static const std::vector<CELL_TYPE> cells_to_cast;
2020-03-19 11:42:45 -04:00
TriggerCell(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;
2020-03-19 11:42:45 -04:00
/// Add a cell which has to be placed to map when the trigger gets activated
void addTarget(CellPtr &&cell);
2020-03-03 11:11:04 -05:00
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
2020-03-16 15:27:34 -04:00
virtual CellPtr clone() const override;
2020-03-03 11:11:04 -05:00
};
#endif // CELL_H