Add texture orientation, WIP on turn

# To do:
- Dasagne
This commit is contained in:
2024-05-26 12:45:35 +02:00
parent 831e643268
commit 6ed6fb8d4f
16 changed files with 50 additions and 1 deletions

View File

@@ -22,5 +22,6 @@
<file>ressources/Sound/GameOver.wav</file>
<file>ressources/Sound/Menu.wav</file>
<file>ressources/Sound/Game.mp3</file>
<file>ressources/Tile/turn.png</file>
</qresource>
</RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 591 B

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 595 B

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 595 B

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 595 B

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
ressources/Tile/turn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -78,6 +78,23 @@ 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++) {
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);
}
}
}
}
this->width = width;
this->height = height;

View File

@@ -66,4 +66,31 @@ QGraphicsPixmapItem* Tile::getGraphics() const {
void Tile::mousePressEvent(QMouseEvent* event) {
emit tileClicked(gridX(), gridY(), event);
}
}
void Tile::setOrientation(Direction previousDirection, Direction nextDirection) {
QPixmap pixmap = this->icon().pixmap(this->iconSize());
if ((previousDirection == Down && nextDirection == Right) || (previousDirection == Left && nextDirection == Up)) {
pixmap = QPixmap(QString::fromStdString(":/ressources/Tile/turn.png"));
if (previousDirection == Left && nextDirection == Up) {
pixmap = pixmap.transformed(QTransform().rotate(180));
}
}
else{
switch (previousDirection) {
case Up:
case Down:
// Rotate 90 degrees
pixmap = pixmap.transformed(QTransform().rotate(90));
break;
case Left:
case Right:
// Do nothing
break;
}
}
// Update the graphics
if(!pixmap.isNull()) {
this->setIcon(QIcon(pixmap));
}
}

View File

@@ -14,6 +14,7 @@ class Tile : public QPushButton
Q_OBJECT
public:
enum Type { Road, Start, End, Tower, Other, Null };
enum Direction { Up, Down, Left, Right, NullDir };
Tile(Type type, QWidget* parent = nullptr);
Type getType() const;
int gridX();
@@ -22,6 +23,7 @@ public:
void setType(Type type);
QGraphicsPixmapItem* getGraphics() const;
void mousePressEvent(QMouseEvent* event) override;
void setOrientation(Direction previousDirection, Direction nextDirection = Direction::NullDir);
private:
Type type;

View File

@@ -20,6 +20,7 @@ Tower::Tower(int damage, double fireRate, int range, int level, int cost, QPoint
fireTimer->start(fireRate * 1000);
int xTile = position.x() * 50;
int yTile = position.y() * 50;
/*
rangeIndicator = new QGraphicsEllipseItem(xTile - range * 10, yTile - range * 10, range * 25, range * 25, this);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
@@ -30,6 +31,7 @@ Tower::Tower(int damage, double fireRate, int range, int level, int cost, QPoint
if(scene != nullptr) {
scene->addItem(rangeIndicator);
}
*/
}
void Tower::fireAtClosest(Enemy* target) const {