1 #include <Entities/Board.hpp> 2 #include <Entities/Player.hpp> 3 #include <Engine/EngineGlobals.hpp> 4 #include <Engine/Helpers/Utils.hpp> 6 int Board::small_width = 40;
7 int Board::small_height = 10;
9 int Board::medium_width = 55;
10 int Board::medium_height = 14;
12 int Board::large_width = 78;
13 int Board::large_height = 21;
17 start_x(BOARD_DEFAULT_PLAYER_X),
18 start_y(BOARD_DEFAULT_PLAYER_Y)
20 this->board =
new Array2D<bool>(width, height);
28 bool Board::isBorder(
int x,
int y)
30 if ((x == 0) || (x == (
int)this->board->width() - 1) ||
31 (y == 0) || (y == (int)this->board->height() - 1))
42 return (this->
style == Board::SOLID);
45 return (this->board->at(x, y));
49 return this->board->width();
53 return this->board->height();
55 void Board::draw(Window* win)
57 int teleport_appearance =
'\'';
58 int solid_appearance = ((EngineGlobals::Screen::fancy_borders) ?
62 for (
size_t i = 0; i < (this->board->width()); i++)
64 for (
size_t j = 0; j < (this->board->height()); j++)
66 if (this->isBorder(i, j))
68 win->printChar(((this->
style == Board::TELEPORT) ?
74 else if (this->
isWall(i, j))
75 win->printChar(solid_appearance,
82 for (
size_t i = 0; i < (this->board->width()); i++) {
83 for (
size_t j = 0; j < (this->board->height()); j++) {
86 if (Utils::Random::booleanWithChance(0.031415923))
87 this->board->set(i, j,
true);
92 for (
int i = -2; i != 7; i++)
93 this->board->set(x + i, y,
false);
99 int newx = player->
getX();
100 int newy = player->
getY();
104 int right = this->board->width() - 2;
106 if (player->
getX() < left)
110 else if (player->
getX() > right)
116 int bottom = this->board->height() - 2;
118 if (player->
getY() < top)
122 else if (player->
getY() > bottom)
127 player->moveTo(newx, newy);
132 for (
size_t i = 0; i < this->board->width(); i++)
133 for (
size_t j = 0; j < this->board->height(); j++)
134 this->board->set(i, j,
false);
139 for (
size_t i = 0; i < this->board->width(); i++)
140 for (
size_t j = 0; j < this->board->height(); j++)
141 this->board->set(i, j, newBoard[j][i]);
144 int Board::getStartX()
146 return this->start_x;
148 int Board::getStartY()
150 return this->start_y;
153 void Board::setStartX(
int x)
157 void Board::setStartY(
int y)
164 this->metadata[name] = value;
171 return this->metadata[name];
175 return (this->metadata.find(name) != this->metadata.end());
177 void Board::scrollLeft()
180 for (
size_t j = 0; j < this->board->height() - 1; j++)
183 bool tmp = this->board->at(1, j);
186 for (
size_t i = 0; i < (this->board->width() - 1); i++)
187 this->board->set(i, j, this->board->at(i + 1, j));
190 this->board->set(this->board->width() - 2, j, tmp);
193 void Board::scrollRight()
196 for (
size_t j = 0; j < this->board->height() - 1; j++)
199 bool tmp = this->board->at(this->board->width() - 2, j);
202 for (
size_t i = (this->board->width() - 1); i > 0; i--)
203 this->board->set(i, j, this->board->at(i - 1, j));
206 this->board->set(1, j, tmp);
209 void Board::scrollUp()
212 for (
size_t j = 0; j < this->board->width() - 1; j++)
215 bool tmp = this->board->at(j, 1);
218 for (
size_t i = 0; i < (this->board->height() - 1); i++)
219 this->board->set(j, i, this->board->at(j, i + 1));
222 this->board->set(j, this->board->height() - 2, tmp);
225 void Board::scrollDown()
228 for (
size_t j = 0; j < this->board->width() - 1; j++)
231 bool tmp = this->board->at(j, this->board->height() - 2);
234 for (
size_t i = this->board->height() - 2; i > 0; i--)
235 this->board->set(j, i, this->board->at(j, i - 1));
238 this->board->set(j, 1, tmp);
void randomlyFillExceptBy(int x, int y)
Places random walls all over the Board except by #x and #y, allowing the Player to move a little bit ...
bool hasMetadata(std::string name)
Tells if this level has a specific information attached.
std::string getMetadata(std::string name)
Gets a meta information from this level.
Style
If the player will teleport when reaching the Board's limits or not.
Style style
Tells if the player will teleport when reaching the Board's limits or not.
Board(int width, int height, Style style)
Creates a new Board.
void setMetadata(std::string name, std::string value)
Sets a meta information from this level.
bool isWall(int x, int y)
Tells if there's a wall at #x #y.
void setBoard(std::vector< std::vector< bool > > &newBoard)
Sets the whole level content.
void teleport(Player *player)
Makes the Player teleport if it's on a border.
void clear()
Makes the whole level empty.
int getX()
Returns the head's x position.
int getY()
Returns the head's y position.