Make everything work
This commit is contained in:
parent
9c4914b16b
commit
256db75f37
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
size
|
||||
5 5
|
||||
map
|
||||
0 0 0 0 0
|
||||
0 0 1 0 0
|
||||
0 0 1 1 0
|
||||
1 1 2 2 2
|
||||
0 0 0 0 0
|
59
src/cell.cpp
59
src/cell.cpp
|
@ -19,7 +19,7 @@ sf::Color Cell::color() const noexcept
|
|||
return cell_color;
|
||||
}
|
||||
|
||||
void Cell::setHeight(coordinate shift_by_y)
|
||||
void Cell::setHeightShift(coordinate shift_by_y)
|
||||
{
|
||||
height_shift = shift_by_y;
|
||||
}
|
||||
|
@ -46,6 +46,11 @@ bool PassableCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
|||
return true;
|
||||
}
|
||||
|
||||
CellPtr PassableCell::getDefaultInstance() const
|
||||
{
|
||||
return std::make_unique<PassableCell>();
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
WaterCell::WaterCell(coordinate cell_row, coordinate cell_col, const sf::Color &color) :
|
||||
|
@ -64,12 +69,19 @@ bool WaterCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
|||
return false;
|
||||
}
|
||||
|
||||
CellPtr WaterCell::getDefaultInstance() const
|
||||
{
|
||||
return std::make_unique<WaterCell>();
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
WallCell::WallCell(coordinate cell_row, coordinate cell_col, const sf::Color &color) :
|
||||
Cell(cell_row, cell_col, color),
|
||||
height_shift(10) // walls are a bit higher than ground and water
|
||||
{}
|
||||
Cell(cell_row, cell_col, color)
|
||||
{
|
||||
// walls are a bit higher than ground and water
|
||||
height_shift = 10;
|
||||
}
|
||||
|
||||
WallCell::~WallCell()
|
||||
{}
|
||||
|
@ -82,13 +94,19 @@ bool WallCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
|||
return false;
|
||||
}
|
||||
|
||||
CellPtr WallCell::getDefaultInstance() const
|
||||
{
|
||||
return std::make_unique<WallCell>();
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
ChargeCell::ChargeCell(coordinate cell_row, coordinate cell_col, int has_charges, const sf::Color &color) :
|
||||
Cell(cell_row, cell_col, color),
|
||||
cell_charges(has_charges),
|
||||
height_shift(5) // charges are a bit higher than ground and water, but lower than walls
|
||||
{}
|
||||
cell_charges(has_charges)
|
||||
{
|
||||
height_shift = 5; // charges are a bit higher than ground and water, but lower than walls
|
||||
}
|
||||
|
||||
ChargeCell::~ChargeCell()
|
||||
{}
|
||||
|
@ -102,6 +120,11 @@ bool ChargeCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
|||
return true;
|
||||
}
|
||||
|
||||
CellPtr ChargeCell::getDefaultInstance() const
|
||||
{
|
||||
return std::make_unique<ChargeCell>();
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
ExitCell::ExitCell(coordinate cell_row, coordinate cell_col, const sf::Color &color) :
|
||||
|
@ -120,6 +143,11 @@ bool ExitCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
|||
return true;
|
||||
}
|
||||
|
||||
CellPtr ExitCell::getDefaultInstance() const
|
||||
{
|
||||
return std::make_unique<ExitCell>();
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
TeleportCell::TeleportCell(coordinate cell_row, coordinate cell_col, coordinate new_cell_row, coordinate new_cell_col, const sf::Color &color) :
|
||||
|
@ -146,13 +174,21 @@ void TeleportCell::setDestination(coordinate new_cell_row, coordinate new_cell_c
|
|||
new_col = new_cell_col;
|
||||
}
|
||||
|
||||
CellPtr TeleportCell::getDefaultInstance() const
|
||||
{
|
||||
return std::make_unique<TeleportCell>();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
TriggerCell::TriggerCell(/*std::vector<CellPtr> &&cells_to_change,*/ coordinate cell_row, coordinate cell_col, const sf::Color &color) :
|
||||
Cell(cell_row, cell_col, color),
|
||||
height_shift(5) // triggers are a bit higher than ground and water, but lower than walls
|
||||
Cell(cell_row, cell_col, color)
|
||||
{
|
||||
//cells = std::move(cells_to_change);
|
||||
|
||||
// triggers are a bit higher than ground and water, but lower than walls
|
||||
height_shift = 5;
|
||||
}
|
||||
|
||||
TriggerCell::~TriggerCell()
|
||||
|
@ -177,3 +213,8 @@ bool TriggerCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
|||
// It's an impassable object, so player can't move to here.
|
||||
return false;
|
||||
}
|
||||
|
||||
CellPtr TriggerCell::getDefaultInstance() const
|
||||
{
|
||||
return std::make_unique<TriggerCell>();
|
||||
}
|
||||
|
|
20
src/cell.h
20
src/cell.h
|
@ -18,7 +18,7 @@ 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);
|
||||
|
||||
const sf::Color Black = sf::Color( 0, 0, 0);
|
||||
}
|
||||
|
||||
enum CELL_TYPES {
|
||||
|
@ -41,7 +41,7 @@ class Cell;
|
|||
|
||||
using HeroPtr = std::unique_ptr<Hero>;
|
||||
using LevelPtr = std::unique_ptr<Level>;
|
||||
using CellPtr = std::unique_ptr<Cell>
|
||||
using CellPtr = std::unique_ptr<Cell>;
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
|
@ -68,6 +68,8 @@ public:
|
|||
|
||||
/// Determine if Hero can move onto this cell or not
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) = 0;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const = 0;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
@ -83,6 +85,8 @@ public:
|
|||
virtual ~PassableCell() override;
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const override;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
@ -98,6 +102,8 @@ public:
|
|||
virtual ~WaterCell() override;
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const override;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
@ -113,6 +119,8 @@ public:
|
|||
virtual ~WallCell() override;
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const override;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
@ -132,6 +140,8 @@ public:
|
|||
virtual ~ChargeCell() override;
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const override;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
@ -147,6 +157,8 @@ public:
|
|||
virtual ~ExitCell() override;
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const override;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
@ -169,6 +181,8 @@ public:
|
|||
void setDestination(coordinate new_cell_row, coordinate new_cell_col);
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const override;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
@ -189,6 +203,8 @@ public:
|
|||
virtual ~TriggerCell() override;
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
|
||||
virtual CellPtr getDefaultInstance() const override;
|
||||
};
|
||||
|
||||
#endif // CELL_H
|
||||
|
|
|
@ -150,7 +150,7 @@ void Game::renderMap()
|
|||
vertical_shift = static_cast<float>(map[y][x]->heightShift());
|
||||
|
||||
// If cell has any height value, we should draw walls for it
|
||||
if (vertical_shift > 0)
|
||||
/*if (vertical_shift > 0)
|
||||
{
|
||||
// Brush for vertical walls
|
||||
sf::ConvexShape convex_wall_brush;
|
||||
|
@ -163,13 +163,13 @@ void Game::renderMap()
|
|||
convex_wall_brush.setPoint(5, sf::Vector2f(cell_width, cell_height));
|
||||
convex_wall_brush.setOutlineThickness(0);
|
||||
|
||||
sf::Color wall_color = convex_wall_brush.getFillColor() - sf::Color(50, 50, 50);
|
||||
sf::Color wall_color = map[y][x]->color();
|
||||
convex_wall_brush.setFillColor(wall_color);
|
||||
|
||||
convex_wall_brush.setPosition(painter_x, painter_y);
|
||||
|
||||
main_window.draw(convex_wall_brush);
|
||||
}
|
||||
}*/
|
||||
|
||||
// Draw the top surface of the cell itself
|
||||
|
||||
|
|
|
@ -22,16 +22,16 @@ void Level::readMap(std::ifstream &file)
|
|||
for (coordinate k = 0; k < map[j].size(); ++k)
|
||||
{
|
||||
file >> i;
|
||||
map[j][k].reset(default_cells[i]);
|
||||
map[j][k] = default_cells[i]->getDefaultInstance();
|
||||
map[j][k]->setPosition(j, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename D, typename B> // [D]erived - [B]ase
|
||||
unique_ptr<D> static_unique_pointer_cast (unique_ptr<B>&& old)
|
||||
std::unique_ptr<D> static_unique_pointer_cast (std::unique_ptr<B>&& old)
|
||||
{
|
||||
return unique_ptr<D>{static_cast<D*>(old.release())};
|
||||
return std::unique_ptr<D>{static_cast<D*>(old.release())};
|
||||
}
|
||||
|
||||
Level::Level(const std::string &map_file)
|
||||
|
|
Loading…
Reference in New Issue