mirror of
https://github.com/BreizhHardware/Poulpes-de-l-Espace-La-derniere-ligne-de-Defense.git
synced 2026-01-18 16:27:20 +01:00
WIP on turn
# To do: - Dasagne
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 25 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 25 KiB |
@@ -79,19 +79,27 @@ void Map::generateMap(const int width, const int height, Game* game) {
|
||||
}
|
||||
}
|
||||
// Set the right orientation for each tile
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
for (int i = 0; i < height; i++){
|
||||
for (int j = 0; j < width; j++){
|
||||
Tile* tile = tiles[i][j];
|
||||
if (tile->isPath()) {
|
||||
if (i > 0 && tiles[i - 1][j] != nullptr && tiles[i - 1][j]->isPath()) {
|
||||
tile->setOrientation(Tile::Down);
|
||||
} else if (i < height - 1 && tiles[i + 1][j] != nullptr && tiles[i + 1][j]->isPath()) {
|
||||
tile->setOrientation(Tile::Up);
|
||||
} else if (j > 0 && tiles[i][j - 1] != nullptr && tiles[i][j - 1]->isPath()) {
|
||||
tile->setOrientation(Tile::Right);
|
||||
} else if (j < width - 1 && tiles[i][j + 1] != nullptr && tiles[i][j + 1]->isPath()) {
|
||||
tile->setOrientation(Tile::Left);
|
||||
if (tile->isPath()){
|
||||
// Determine the previous and next direction
|
||||
Tile::Direction nextDirection = Tile::NullDir;
|
||||
if (j < width - 1 && tiles[i][j + 1]->isPath()) {
|
||||
nextDirection = Tile::Right;
|
||||
}
|
||||
if (i < height - 1 && tiles[i + 1][j]->isPath()) {
|
||||
nextDirection = Tile::Up;
|
||||
}
|
||||
if (j > 0 && tiles[i][j - 1]->isPath()) {
|
||||
nextDirection = Tile::Left;
|
||||
}
|
||||
if (i > 0 && tiles[i - 1][j]->isPath()) {
|
||||
nextDirection = Tile::Down;
|
||||
}
|
||||
|
||||
// Set the orientation of the tile
|
||||
tile->setOrientation(nextDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,16 +68,20 @@ void Tile::mousePressEvent(QMouseEvent* event) {
|
||||
emit tileClicked(gridX(), gridY(), event);
|
||||
}
|
||||
|
||||
void Tile::setOrientation(Direction previousDirection, Direction nextDirection) {
|
||||
void Tile::setOrientation(Direction nextDirection) {
|
||||
QPixmap pixmap = this->icon().pixmap(this->iconSize());
|
||||
if ((previousDirection == Down && nextDirection == Right) || (previousDirection == Left && nextDirection == Up)) {
|
||||
|
||||
qDebug() << "Previous direction: " << directionToString(this->previousDirection).c_str();
|
||||
qDebug() << "Next direction: " << directionToString(nextDirection).c_str();
|
||||
if ((this->previousDirection == Down && nextDirection == Right) || (this->previousDirection == Left && nextDirection == Up)) {
|
||||
qDebug() << "Turn";
|
||||
pixmap = QPixmap(QString::fromStdString(":/ressources/Tile/turn.png"));
|
||||
if (previousDirection == Left && nextDirection == Up) {
|
||||
if (this->previousDirection == Left && nextDirection == Up) {
|
||||
pixmap = pixmap.transformed(QTransform().rotate(180));
|
||||
}
|
||||
}
|
||||
else{
|
||||
switch (previousDirection) {
|
||||
switch (this->previousDirection) {
|
||||
case Up:
|
||||
case Down:
|
||||
// Rotate 90 degrees
|
||||
@@ -92,5 +96,38 @@ void Tile::setOrientation(Direction previousDirection, Direction nextDirection)
|
||||
// Update the graphics
|
||||
if(!pixmap.isNull()) {
|
||||
this->setIcon(QIcon(pixmap));
|
||||
this->setIconSize(QSize(50, 50));
|
||||
}
|
||||
switch (nextDirection) {
|
||||
case Up:
|
||||
this->previousDirection = Down;
|
||||
break;
|
||||
case Down:
|
||||
this->previousDirection = Up;
|
||||
break;
|
||||
case Left:
|
||||
this->previousDirection = Right;
|
||||
break;
|
||||
case Right:
|
||||
this->previousDirection = Left;
|
||||
break;
|
||||
default:
|
||||
this->previousDirection = NullDir;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Tile::directionToString(Direction direction) {
|
||||
switch (direction){
|
||||
case Up:
|
||||
return "Up";
|
||||
case Down:
|
||||
return "Down";
|
||||
case Left:
|
||||
return "Left";
|
||||
case Right:
|
||||
return "Right";
|
||||
default:
|
||||
return "NullDir";
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,14 @@ public:
|
||||
void setType(Type type);
|
||||
QGraphicsPixmapItem* getGraphics() const;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void setOrientation(Direction previousDirection, Direction nextDirection = Direction::NullDir);
|
||||
void setOrientation(Direction nextDirection);
|
||||
|
||||
private:
|
||||
Type type;
|
||||
QGraphicsPixmapItem* graphics;
|
||||
std::string directionToString(Direction direction);
|
||||
Direction previousDirection;
|
||||
Direction nextDirection;
|
||||
|
||||
signals:
|
||||
void tileClicked(int gridX, int gridY, QMouseEvent* event);
|
||||
|
||||
Reference in New Issue
Block a user