Add texture orientation, WIP on turn
# To do: - Dasagne
@@ -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>
|
||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 591 B After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 594 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 595 B After Width: | Height: | Size: 304 B |
|
Before Width: | Height: | Size: 595 B After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 595 B After Width: | Height: | Size: 1.1 KiB |
BIN
ressources/Tile/turn.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||