Add sound effect to the game

# To do:
- Dasagne
- Better rules
This commit is contained in:
2024-05-23 14:35:15 +02:00
parent fd169ae769
commit 93f1a2bc0d
10 changed files with 34 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
find_package(Qt6 REQUIRED COMPONENTS Widgets Sql Gui Core) find_package(Qt6 REQUIRED COMPONENTS Widgets Sql Gui Core Multimedia)
file(GLOB_RECURSE sourceCode src/*.cpp src/*.h) file(GLOB_RECURSE sourceCode src/*.cpp src/*.h)
@@ -16,4 +16,4 @@ qt_standard_project_setup()
add_executable(Poulpes_de_l_espace_La_derniere_ligne_de_defense ressources.qrc ${sourceCode} add_executable(Poulpes_de_l_espace_La_derniere_ligne_de_defense ressources.qrc ${sourceCode}
) )
target_link_libraries(Poulpes_de_l_espace_La_derniere_ligne_de_defense PRIVATE Qt6::Widgets Qt6::Sql) target_link_libraries(Poulpes_de_l_espace_La_derniere_ligne_de_defense PRIVATE Qt6::Widgets Qt6::Sql Qt6::Gui Qt6::Core Qt6::Multimedia)

View File

@@ -40,6 +40,7 @@ Les règles sont simples:
- CMake - CMake
- QT6 - QT6
- QT6 Multimedia
### Compilation ### Compilation

View File

@@ -17,5 +17,8 @@
<file>ressources/tower.png</file> <file>ressources/tower.png</file>
<file>ressources/zeus.png</file> <file>ressources/zeus.png</file>
<file>ressources/Orbitron-VariableFont_wght.ttf</file> <file>ressources/Orbitron-VariableFont_wght.ttf</file>
<file>ressources/explosion.wav</file>
<file>ressources/warp.wav</file>
<file>ressources/GameOver.wav</file>
</qresource> </qresource>
</RCC> </RCC>

BIN
ressources/GameOver.wav Normal file

Binary file not shown.

BIN
ressources/explosion.wav Normal file

Binary file not shown.

BIN
ressources/warp.wav Normal file

Binary file not shown.

View File

@@ -117,12 +117,13 @@ void Enemy::moveEnemy() {
// Check if the enemy is on the end tile and deal damage // Check if the enemy is on the end tile and deal damage
if (getCurrentTile() == gameMap.getEndTile()) { if (getCurrentTile() == gameMap.getEndTile()) {
game.player->takeDamage(getDamage()); game.player->takeDamage(getDamage());
game.playWarpSound();
game.removeEnemy(this); game.removeEnemy(this);
} }
// Check if the player is on the same tile as the enemy and deal damage // Check if the player is on the same tile as the enemy and deal damage
if (game.player->getX() == x && game.player->getY() == y) { if (game.player->getX() == x && game.player->getY() == y) {
game.player->takeDamage(getDamage()); game.player->takeDamage(getDamage());
game.userGold += coinDrop; dropGold();
game.removeEnemy(this); game.removeEnemy(this);
} }
} }
@@ -159,11 +160,13 @@ void Enemy::takeDamage(int damage) {
healthText->setPlainText(QString::number(health)); healthText->setPlainText(QString::number(health));
if (health <= 0) { if (health <= 0) {
dropGold(); dropGold();
game.removeEnemy(this); game.removeEnemy(this);
} }
} }
void Enemy::dropGold() { void Enemy::dropGold() {
game.playDeathSound();
game.userGold += coinDrop; game.userGold += coinDrop;
game.updateDisplay(); game.updateDisplay();
} }

View File

@@ -7,6 +7,7 @@
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include <QTimer> #include <QTimer>
#include <QPointF> #include <QPointF>
#include <QSoundEffect>
#include "Mob.h" #include "Mob.h"
#include "Map.h" #include "Map.h"
#include "Game.h" #include "Game.h"

View File

@@ -53,6 +53,13 @@ Game::Game(Menu* menu) : menu(menu)
this->setScene(gameMap); this->setScene(gameMap);
player->updatePreviousHealth(); player->updatePreviousHealth();
this->gameOverSound.setSource(QUrl::fromLocalFile(":/ressources/GameOver.wav"));
this->gameOverSound.setVolume(0.5f);
this->deathSound.setSource(QUrl::fromLocalFile(":/ressources/explosion.wav"));
this->deathSound.setVolume(0.5f);
this->warpSound.setSource(QUrl::fromLocalFile(":/ressources/warp.wav"));
this->warpSound.setVolume(0.5f);
} }
void Game::start() { void Game::start() {
@@ -264,6 +271,8 @@ void Game::gameOver() {
clearTowers(); clearTowers();
gameOverSound.play();
auto* gameOver = new Gameover(this); auto* gameOver = new Gameover(this);
connect(gameOver, &Gameover::restartGameSignal, this, &Game::start); connect(gameOver, &Gameover::restartGameSignal, this, &Game::start);
gameOver->setFixedSize(200, 100); gameOver->setFixedSize(200, 100);
@@ -484,3 +493,11 @@ void Game::wheelEvent(QWheelEvent* event) {
this->setTransform(this->transform().scale(0.9, 0.9)); this->setTransform(this->transform().scale(0.9, 0.9));
} }
} }
void Game::playDeathSound() {
deathSound.play();
}
void Game::playWarpSound() {
warpSound.play();
}

View File

@@ -13,6 +13,7 @@
#include <QSqlQuery> #include <QSqlQuery>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QMenu> #include <QMenu>
#include <QSoundEffect>
#include "Map.h" #include "Map.h"
#include "Player.h" #include "Player.h"
#include "Enemy.h" #include "Enemy.h"
@@ -53,6 +54,8 @@ public:
void upgradeTower(Tower* tower, QMouseEvent* event); void upgradeTower(Tower* tower, QMouseEvent* event);
void placeTower(int gridX, int gridY, QMouseEvent* event); void placeTower(int gridX, int gridY, QMouseEvent* event);
void handleTileClick(int gridX, int gridY, QMouseEvent* event); void handleTileClick(int gridX, int gridY, QMouseEvent* event);
void playDeathSound();
void playWarpSound();
private: private:
QTimer gameTimer; QTimer gameTimer;
@@ -69,6 +72,9 @@ private:
QVector<Tower*> towers; QVector<Tower*> towers;
bool isWaveSpawning; bool isWaveSpawning;
QMenu towerMenu; QMenu towerMenu;
QSoundEffect gameOverSound;
QSoundEffect deathSound;
QSoundEffect warpSound;
protected: protected:
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;