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
Add sound effect to the game
# To do: - Dasagne - Better rules
This commit is contained in:
@@ -7,7 +7,7 @@ set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC 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)
|
||||
|
||||
@@ -16,4 +16,4 @@ qt_standard_project_setup()
|
||||
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)
|
||||
|
||||
@@ -40,6 +40,7 @@ Les règles sont simples:
|
||||
|
||||
- CMake
|
||||
- QT6
|
||||
- QT6 Multimedia
|
||||
|
||||
### Compilation
|
||||
|
||||
|
||||
@@ -17,5 +17,8 @@
|
||||
<file>ressources/tower.png</file>
|
||||
<file>ressources/zeus.png</file>
|
||||
<file>ressources/Orbitron-VariableFont_wght.ttf</file>
|
||||
<file>ressources/explosion.wav</file>
|
||||
<file>ressources/warp.wav</file>
|
||||
<file>ressources/GameOver.wav</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
BIN
ressources/GameOver.wav
Normal file
BIN
ressources/GameOver.wav
Normal file
Binary file not shown.
BIN
ressources/explosion.wav
Normal file
BIN
ressources/explosion.wav
Normal file
Binary file not shown.
BIN
ressources/warp.wav
Normal file
BIN
ressources/warp.wav
Normal file
Binary file not shown.
@@ -117,12 +117,13 @@ void Enemy::moveEnemy() {
|
||||
// Check if the enemy is on the end tile and deal damage
|
||||
if (getCurrentTile() == gameMap.getEndTile()) {
|
||||
game.player->takeDamage(getDamage());
|
||||
game.playWarpSound();
|
||||
game.removeEnemy(this);
|
||||
}
|
||||
// Check if the player is on the same tile as the enemy and deal damage
|
||||
if (game.player->getX() == x && game.player->getY() == y) {
|
||||
game.player->takeDamage(getDamage());
|
||||
game.userGold += coinDrop;
|
||||
dropGold();
|
||||
game.removeEnemy(this);
|
||||
}
|
||||
}
|
||||
@@ -159,11 +160,13 @@ void Enemy::takeDamage(int damage) {
|
||||
healthText->setPlainText(QString::number(health));
|
||||
if (health <= 0) {
|
||||
dropGold();
|
||||
|
||||
game.removeEnemy(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Enemy::dropGold() {
|
||||
game.playDeathSound();
|
||||
game.userGold += coinDrop;
|
||||
game.updateDisplay();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QTimer>
|
||||
#include <QPointF>
|
||||
#include <QSoundEffect>
|
||||
#include "Mob.h"
|
||||
#include "Map.h"
|
||||
#include "Game.h"
|
||||
|
||||
17
src/Game.cpp
17
src/Game.cpp
@@ -53,6 +53,13 @@ Game::Game(Menu* menu) : menu(menu)
|
||||
this->setScene(gameMap);
|
||||
|
||||
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() {
|
||||
@@ -264,6 +271,8 @@ void Game::gameOver() {
|
||||
|
||||
clearTowers();
|
||||
|
||||
gameOverSound.play();
|
||||
|
||||
auto* gameOver = new Gameover(this);
|
||||
connect(gameOver, &Gameover::restartGameSignal, this, &Game::start);
|
||||
gameOver->setFixedSize(200, 100);
|
||||
@@ -484,3 +493,11 @@ void Game::wheelEvent(QWheelEvent* event) {
|
||||
this->setTransform(this->transform().scale(0.9, 0.9));
|
||||
}
|
||||
}
|
||||
|
||||
void Game::playDeathSound() {
|
||||
deathSound.play();
|
||||
}
|
||||
|
||||
void Game::playWarpSound() {
|
||||
warpSound.play();
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <QSqlQuery>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QMenu>
|
||||
#include <QSoundEffect>
|
||||
#include "Map.h"
|
||||
#include "Player.h"
|
||||
#include "Enemy.h"
|
||||
@@ -53,6 +54,8 @@ public:
|
||||
void upgradeTower(Tower* tower, QMouseEvent* event);
|
||||
void placeTower(int gridX, int gridY, QMouseEvent* event);
|
||||
void handleTileClick(int gridX, int gridY, QMouseEvent* event);
|
||||
void playDeathSound();
|
||||
void playWarpSound();
|
||||
|
||||
private:
|
||||
QTimer gameTimer;
|
||||
@@ -69,6 +72,9 @@ private:
|
||||
QVector<Tower*> towers;
|
||||
bool isWaveSpawning;
|
||||
QMenu towerMenu;
|
||||
QSoundEffect gameOverSound;
|
||||
QSoundEffect deathSound;
|
||||
QSoundEffect warpSound;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
|
||||
Reference in New Issue
Block a user