From 6c1813ceca9043a96da1fc8b03e8f8034944b3ab Mon Sep 17 00:00:00 2001 From: cboissie Date: Thu, 2 Jun 2011 16:42:16 +0200 Subject: [PATCH] Correcting bugs. --- Doxyfile | 10 +++---- enemy.cpp | 80 +++++++++++++++++++++++++++++++++++++++++--------- enemy.h | 30 ++++++++++++------- mainwindow.cpp | 12 +++++++- map.cpp | 26 ++++++++++------ map.h | 2 +- types.h | 9 +++++- 7 files changed, 128 insertions(+), 41 deletions(-) diff --git a/Doxyfile b/Doxyfile index a3c1f3d..857341d 100644 --- a/Doxyfile +++ b/Doxyfile @@ -137,7 +137,7 @@ SHORT_NAMES = NO # comments will behave just like regular Qt-style comments # (thus requiring an explicit @brief command for a brief description.) -JAVADOC_AUTOBRIEF = NO +JAVADOC_AUTOBRIEF = YES # If the QT_AUTOBRIEF tag is set to YES then Doxygen will # interpret the first line (until the first dot) of a Qt-style @@ -791,7 +791,7 @@ HTML_HEADER = # each generated HTML page. If it is left blank doxygen will generate a # standard footer. -HTML_FOOTER = +HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to @@ -1017,7 +1017,7 @@ SERVER_BASED_SEARCH = NO # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. -GENERATE_LATEX = YES +GENERATE_LATEX = NO # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be @@ -1389,7 +1389,7 @@ HIDE_UNDOC_RELATIONS = YES # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) -HAVE_DOT = NO +HAVE_DOT = YES # By default doxygen will write a font called FreeSans.ttf to the output # directory and reference it in all dot files that doxygen generates. This @@ -1442,7 +1442,7 @@ UML_LOOK = NO # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. -TEMPLATE_RELATIONS = NO +TEMPLATE_RELATIONS = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT # tags are set to YES then doxygen will generate a graph for each documented diff --git a/enemy.cpp b/enemy.cpp index d3d7fc0..2f627f5 100644 --- a/enemy.cpp +++ b/enemy.cpp @@ -2,10 +2,18 @@ #include #include "enemy.h" -/** +/************************************************************************************************************ * ENEMY -**/ +************************************************************************************************************/ + +/** +* @brief Constructeur +* @param map Pointeur sur la map contenant l'ennemi. +* @param posx Position x de l'ennemi. +* @param posy Position y de l'ennemi. +* @param size Taille de l'ennemi (détermine sa taille effective ainsi que ses caractéristiques). +*/ Enemy::Enemy(Map* map,int posx,int posy, float size):Entity(posx,posy),_map(map),_size(size){ // Positionne l'ennemi bien au centre du chemin this->setPos(this->x() - (_size-1)*16,this->y() - (_size-1)*16); @@ -16,11 +24,38 @@ Enemy::Enemy(Map* map,int posx,int posy, float size):Entity(posx,posy),_map(map) } - +/** +* @brief Retourne le nombre actuel de points de vie. +* @return _hp Nombre de points de vie actuel. +*/ int Enemy::getHP(void) const { return _hp; } + + +/** +* @brief Renvoie la résistance (défense) de l'ennemi. +* @return _resistance Résistance de l'ennemi. +*/ int Enemy::getResistance(void) const { return _resistance; } + +/** +* @brief Renvoie le type de l'ennemi (volant ou rampant). +* @return _type Type de l'ennemi. +*/ TYPE::ENTITY Enemy::getType(void) const { return _type; } + +/** +* @brief Renvoie la taille de l'ennemi. +* @return _size Taille de l'ennemi. +*/ +float Enemy::getSize(void) const { return _size; } + + +/** +* @brief Applique un malus de vitesse à l'ennemi pendant un temps déterminé. +* @param percent Pourcentage du malus (<=1). +* @param seconds Durée en secondes du malus. +*/ void Enemy::setSpeedMalus(float percent, int seconds) { _malusCounter = GAME::FPS * seconds; if(percent >= 0 && percent <= 1) @@ -29,12 +64,20 @@ void Enemy::setSpeedMalus(float percent, int seconds) { _speedMalus = 0; // Par défaut on arrête l'ennemi } - -float Enemy::getSize(void) const { return _size; } +/** +* @brief Infliges des dommages directs à l'ennemi. +* Si la résistance est trop importante, les dommages sont réduits à zéro. +* @param damages Dommages directs infligés par une source externe. +*/ void Enemy::hurt(int damages){ + // Applique la résistance de l'ennemi aux dommages + int effectiveDamages = damages - _resistance; + if(effectiveDamages < 0) effectiveDamages = 0; + // Inflige 'damages' dégats à l'ennemi - _hp-=damages; + _hp-=effectiveDamages; + // Si ses HP sont tombés à zéro, on le détruit if(_hp <= 0) { // Indique que la mort est provoquée par le joueur @@ -145,9 +188,12 @@ void Enemy::reachGoal(void) { } -/** + + +/************************************************************************************************************ * CAFARD -**/ +************************************************************************************************************/ + Cafard::Cafard(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) @@ -190,9 +236,11 @@ void Cafard::advance(int phase) { -/** +/************************************************************************************************************ * FOURMI -**/ +************************************************************************************************************/ + + Fourmi::Fourmi(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) { @@ -247,9 +295,10 @@ void Fourmi::advance(int phase) { -/** +/************************************************************************************************************ * GUEPE -**/ +************************************************************************************************************/ + Guepe::Guepe(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) { @@ -313,9 +362,12 @@ void Guepe::advance(int phase) { } -/** + + +/************************************************************************************************************ * MOUSTIQUE -**/ +************************************************************************************************************/ + Moustique::Moustique(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) { diff --git a/enemy.h b/enemy.h index fb8eaef..680291b 100644 --- a/enemy.h +++ b/enemy.h @@ -15,9 +15,10 @@ class Map; -/** +/************************************************************************************************************ * ENEMY -**/ +************************************************************************************************************/ + class Enemy : public Entity { @@ -59,9 +60,11 @@ signals: }; -/** + +/************************************************************************************************************ * CAFARD -**/ +************************************************************************************************************/ + class Cafard : public Enemy { @@ -79,9 +82,11 @@ protected: }; -/** + +/************************************************************************************************************ * FOURMI -**/ +************************************************************************************************************/ + class Fourmi : public Enemy { @@ -103,9 +108,12 @@ protected: }; -/** + + +/************************************************************************************************************ * GUEPE -**/ +************************************************************************************************************/ + class Guepe : public Enemy { @@ -127,9 +135,11 @@ protected: }; -/** + +/************************************************************************************************************ * MOUSTIQUE -**/ +************************************************************************************************************/ + class Moustique : public Enemy { diff --git a/mainwindow.cpp b/mainwindow.cpp index 1e29b2c..93e8121 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -29,7 +29,7 @@ void MainWindow::launchGame(QWidget *parent) { /** * Initialisation des données du joueur **/ - _player = new Player(22,10,_gameDifficulty); // 22 - 10 + _player = new Player(9999,10,_gameDifficulty); // 22 - 10 /** @@ -73,18 +73,23 @@ void MainWindow::launchGame(QWidget *parent) { /// Boutons de choix de tourelle // . Pistolet à eau + ui->turretButton_PistoletAEau->setDisabled(false); QObject::connect(ui->turretButton_PistoletAEau,SIGNAL(pressed()),_player,SLOT(setTurretChoice1())); QObject::connect(_player,SIGNAL(setTurret1ButtonDisabled(bool)),ui->turretButton_PistoletAEau,SLOT(setDisabled(bool))); // . Lance-pierres + ui->turretButton_LancePierres->setDisabled(false); QObject::connect(ui->turretButton_LancePierres,SIGNAL(pressed()),_player,SLOT(setTurretChoice2())); QObject::connect(_player,SIGNAL(setTurret2ButtonDisabled(bool)),ui->turretButton_LancePierres,SLOT(setDisabled(bool))); // . Paintball + ui->turretButton_Paintball->setDisabled(false); QObject::connect(ui->turretButton_Paintball,SIGNAL(pressed()),_player,SLOT(setTurretChoice3())); QObject::connect(_player,SIGNAL(setTurret3ButtonDisabled(bool)),ui->turretButton_Paintball,SLOT(setDisabled(bool))); // . Pétanque + ui->turretButton_Petanque->setDisabled(false); QObject::connect(ui->turretButton_Petanque,SIGNAL(pressed()),_player,SLOT(setTurretChoice4())); QObject::connect(_player,SIGNAL(setTurret4ButtonDisabled(bool)),ui->turretButton_Petanque,SLOT(setDisabled(bool))); // . Musicien + ui->turretButton_Musicien->setDisabled(false); QObject::connect(ui->turretButton_Musicien,SIGNAL(pressed()),_player,SLOT(setTurretChoice5())); QObject::connect(_player,SIGNAL(setTurret5ButtonDisabled(bool)),ui->turretButton_Musicien,SLOT(setDisabled(bool))); @@ -198,6 +203,11 @@ void MainWindow::reloadGame(void) { _view->disconnect(); this->disconnect(); + // Libère la mémoire + delete _player; + delete _sceneMap->getWaveGenerator(); + delete _sceneMap; // Détruira tous les éléments de la scène + // Relance le jeu (nb: les éléments de l'ancienne partie seront automatiquement supprimés par l'appel au new) this->launchGame(this->parentWidget()); } diff --git a/map.cpp b/map.cpp index 643a599..901937d 100644 --- a/map.cpp +++ b/map.cpp @@ -32,7 +32,9 @@ Map::Map(QWidget *parent,Player* player):QGraphicsScene(parent),_player(player) // Générateur de vagues _waveGenerator = new EnemyFactory(this,_player); + // Lancement du timer (boucle principale du jeu) + _isPaused = false; QObject::connect(&gameTimer, SIGNAL(timeout()), this, SLOT(advance())); gameTimer.start(1000 / GAME::FPS); } @@ -99,10 +101,10 @@ void Map::removeEnemy(Enemy* ptr) { for(i = 0; i < _enemies.length() ; ++i) { if(_enemies[i] == ptr) { - std::cout << "OMG je suis mort" << std::endl; _enemies.removeAt(i); - // QObject::disconnect(ptr); this->removeItem(ptr); + ptr->deleteLater(); + break; } } @@ -200,7 +202,10 @@ bool Map::addTurretAt(TYPE::TURRET turretType,float mx,float my) { // Gestion des clics sur la tourelle QObject::connect(this,SIGNAL(setTurretsSelected(bool)),newTurret,SLOT(setIsSelected(bool))); - // On remet à zéro le choix du joueur + // Mise à jour des bonus + emit updateBonuses(); + + // On remet à zéro le choix du joueur _player->setTurretChoice(TYPE::NONE); // Affichage des infos + activation des boutons @@ -248,7 +253,6 @@ void Map::removeTurret(void) { dynamic_cast(_turrets[i])->removeBonuses(); // Retire l'objet de la map et de la liste - //this->removeItem(_turrets[i]); delete(_turrets[i]); _turrets.removeAt(i); @@ -306,11 +310,15 @@ Tile& Map::getTileAt(int grid_x, int grid_y) const { return *_mapTiles[grid_x][g EnemyFactory* Map::getWaveGenerator(void) const { return _waveGenerator; } void Map::setPause(void) { - if (_isPause) { - _isPause = false; - gameTimer.stop(); - } else { - _isPause = true; + + // Relance le jeu + if (_isPaused) { + _isPaused = false; gameTimer.start(1000 / GAME::FPS); } + // Stoppe le jeu + else { + _isPaused = true; + gameTimer.stop(); + } } diff --git a/map.h b/map.h index 7815b23..7d8a315 100644 --- a/map.h +++ b/map.h @@ -32,7 +32,7 @@ class Map : public QGraphicsScene QGraphicsScene* _scene; QPoint _startPos; Player* _player; - bool _isPause; + bool _isPaused; void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/types.h b/types.h index 93109a5..800b0e3 100644 --- a/types.h +++ b/types.h @@ -1,3 +1,10 @@ +/** +* @file types.h +* @brief Ce fichier contient les constantes et types prédéfinis du jeu, utilisés +* à des fins de simplification du code. On notera que les valeurs de type DIRECTION +* utilisent chacune un bit différent, utile pour les tests à base de masques de bits. +*/ + #ifndef TYPES_H #define TYPES_H @@ -17,7 +24,7 @@ typedef enum { NONE, PISTOLET_A_EAU, LANCE_PIERRES, PAINTBALL, PETANQUE, MUSICIE namespace GAME { typedef enum { EASY = 1, HARD = 2 } DIFFICULTY; -static const short FPS = 60; +static const short FPS = 30; } -- 2.43.0