From ed45bbcaa40046f96793fd3f4559d89ab62bc3b7 Mon Sep 17 00:00:00 2001 From: cboissie Date: Mon, 30 May 2011 03:11:26 +0200 Subject: [PATCH] New version whith khamidou's fork included. Now you can play with all the 4 basics turrets You can pause the game (wip) And stop/replay when you lose/win (wip) --- Bug_Attack.pro.user | 372 +++++------------ defenser.cpp | 377 +++++++++++++++--- defenser.h | 109 ++++- enemy.cpp | 38 +- enemy.h | 19 +- enemyfactory.cpp | 22 +- enemyfactory.h | 1 - mainwindow.cpp | 26 +- mainwindow.ui | 39 ++ map.cpp | 43 +- map.h | 1 + .../{moustiquevolant1.png => moustique1.png} | Bin .../{moustiquevolant2.png => moustique2.png} | Bin player.cpp | 38 +- player.h | 7 + projectile.cpp | 182 ++++++++- projectile.h | 87 +++- types.h | 2 +- 18 files changed, 994 insertions(+), 369 deletions(-) rename media/textures/ennemies/{moustiquevolant1.png => moustique1.png} (100%) rename media/textures/ennemies/{moustiquevolant2.png => moustique2.png} (100%) diff --git a/Bug_Attack.pro.user b/Bug_Attack.pro.user index 3e15d28..b89cd7c 100644 --- a/Bug_Attack.pro.user +++ b/Bug_Attack.pro.user @@ -1,297 +1,111 @@ - RunConfiguration0-BaseEnvironmentBase - 2 - - - RunConfiguration0-CommandLineArguments - - - - RunConfiguration0-ProFile - Bug_Attack.pro - - - RunConfiguration0-RunConfiguration.name - Bug_Attack - - - RunConfiguration0-UseDyldImageSuffix - false - - - RunConfiguration0-UseTerminal - false - - - RunConfiguration0-UserEnvironmentChanges - - - - RunConfiguration0-UserSetName - false - - - RunConfiguration0-UserSetWorkingDirectory - false - - - RunConfiguration0-UserWorkingDirectory - - - - RunConfiguration0-type - Qt4ProjectManager.Qt4RunConfiguration - - - activeRunConfiguration + ProjectExplorer.Project.ActiveTarget 0 - activebuildconfiguration - Debug - - - buildConfiguration-Debug - - Debug - 0 - 0 - - 2 - - - - buildConfiguration-Release - - Release - 0 - - 0 - - - - buildconfiguration-Debug-buildstep0 - - Debug - - COLORTERM=gnome-terminal - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-4ATZ8FsiM4,guid=b3b5e8064b425952320809474de0d837 - DEFAULTS_PATH=/usr/share/gconf/wmii.default.path - DESKTOP_SESSION=wmii - DISPLAY=:0.0 - DVDCSS_CACHE=/home/karim/.dvdcss/ - DVDCSS_METHOD=key - DVDCSS_RAW_DEVICE=/dev/rdvd - DVDCSS_VERBOSE=0 - EDITOR=emacs -nw - GDMSESSION=wmii - GDM_KEYBOARD_LAYOUT=fr oss - GDM_LANG=fr_FR.utf8 - GNOME_KEYRING_CONTROL=/tmp/keyring-lbcNed - GNOME_KEYRING_PID=1553 - GROUP=karim - GTK_MODULES=canberra-gtk-module - HOME=/home/karim - HOST=darkstar - HOSTTYPE=i486-linux - LANG=fr_FR.utf8 - LANGUAGE= - LD_LIBRARY_PATH=/usr/lib/qtcreator - LESS=-Q - LOGNAME=karim - MACHTYPE=i486 - MANDATORY_PATH=/usr/share/gconf/wmii.mandatory.path - ORBIT_SOCKETDIR=/tmp/orbit-karim - OSTYPE=linux - PATH=/usr/bin:/home/karim/proglangs/go/bin:/home/karim/usrbin:/home/karim/proglangs/go/bin:/home/karim/usrbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games - PWD=/home/karim/Documents/Cours/LO21/projet/Bug_Attack - QTDIR=/usr/share/qt4 - REMOTEHOST= - SHELL=/bin/tcsh - SHLVL=2 - SPEECHD_PORT=7560 - SSH_AGENT_PID=1606 - SSH_AUTH_SOCK=/tmp/ssh-WHnVlH1571/agent.1571 - TERM=xterm - USER=karim - USERNAME=karim - VENDOR=intel - VISUALWORKS=/home/karim/vw7.7.1nc - WINDOWID=35651588 - WMII_9MENU=wmii9menu -font 'fixed' -nf '#888888' -nb '#222222' -sf '#ffffff' -sb '#285577' -br '#4c7899' - WMII_ADDRESS=unix!/tmp/ns.karim.:0/wmii - WMII_CONFPATH=/home/karim/.wmii-3.5:/etc/X11/wmii-3.5 - WMII_FOCUSCOLORS=#ffffff #285577 #4c7899 - WMII_FONT=fixed - WMII_MENU=dmenu -b -fn 'fixed' -nf '#888888' -nb '#222222' -sf '#ffffff' -sb '#285577' - WMII_NORMCOLORS=#888888 #222222 #333333 - WMII_NS_DIR=/tmp/ns.karim.:0 - WMII_TERM=x-terminal-emulator - XAUTHORITY=/var/run/gdm/auth-for-karim-ZS7TdS/database - XDG_CONFIG_DIRS=/etc/xdg/xdg-wmii:/etc/xdg - XDG_SESSION_COOKIE=8d773db3cd1c3e1862d910494c27a514-1306581046.982572-757318715 - no_proxy=0.0.0.0, 127.0.0.1, localhost - - - /home/karim/Documents/Cours/LO21/projet/Bug_Attack/Bug_Attack.pro - -spec - linux-g++ - -r - CONFIG+=debug - - /usr/bin/qmake-qt4 - false - /home/karim/Documents/Cours/LO21/projet/Bug_Attack - - - - buildconfiguration-Debug-buildstep1 + ProjectExplorer.Project.EditorSettings - Debug - - COLORTERM=gnome-terminal - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-4ATZ8FsiM4,guid=b3b5e8064b425952320809474de0d837 - DEFAULTS_PATH=/usr/share/gconf/wmii.default.path - DESKTOP_SESSION=wmii - DISPLAY=:0.0 - DVDCSS_CACHE=/home/karim/.dvdcss/ - DVDCSS_METHOD=key - DVDCSS_RAW_DEVICE=/dev/rdvd - DVDCSS_VERBOSE=0 - EDITOR=emacs -nw - GDMSESSION=wmii - GDM_KEYBOARD_LAYOUT=fr oss - GDM_LANG=fr_FR.utf8 - GNOME_KEYRING_CONTROL=/tmp/keyring-lbcNed - GNOME_KEYRING_PID=1553 - GROUP=karim - GTK_MODULES=canberra-gtk-module - HOME=/home/karim - HOST=darkstar - HOSTTYPE=i486-linux - LANG=fr_FR.utf8 - LANGUAGE= - LD_LIBRARY_PATH=/usr/lib/qtcreator - LESS=-Q - LOGNAME=karim - MACHTYPE=i486 - MANDATORY_PATH=/usr/share/gconf/wmii.mandatory.path - ORBIT_SOCKETDIR=/tmp/orbit-karim - OSTYPE=linux - PATH=/usr/bin:/home/karim/proglangs/go/bin:/home/karim/usrbin:/home/karim/proglangs/go/bin:/home/karim/usrbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games - PWD=/home/karim/Documents/Cours/LO21/projet/Bug_Attack - QTDIR=/usr/share/qt4 - REMOTEHOST= - SHELL=/bin/tcsh - SHLVL=2 - SPEECHD_PORT=7560 - SSH_AGENT_PID=1606 - SSH_AUTH_SOCK=/tmp/ssh-WHnVlH1571/agent.1571 - TERM=xterm - USER=karim - USERNAME=karim - VENDOR=intel - VISUALWORKS=/home/karim/vw7.7.1nc - WINDOWID=35651588 - WMII_9MENU=wmii9menu -font 'fixed' -nf '#888888' -nb '#222222' -sf '#ffffff' -sb '#285577' -br '#4c7899' - WMII_ADDRESS=unix!/tmp/ns.karim.:0/wmii - WMII_CONFPATH=/home/karim/.wmii-3.5:/etc/X11/wmii-3.5 - WMII_FOCUSCOLORS=#ffffff #285577 #4c7899 - WMII_FONT=fixed - WMII_MENU=dmenu -b -fn 'fixed' -nf '#888888' -nb '#222222' -sf '#ffffff' -sb '#285577' - WMII_NORMCOLORS=#888888 #222222 #333333 - WMII_NS_DIR=/tmp/ns.karim.:0 - WMII_TERM=x-terminal-emulator - XAUTHORITY=/var/run/gdm/auth-for-karim-ZS7TdS/database - XDG_CONFIG_DIRS=/etc/xdg/xdg-wmii:/etc/xdg - XDG_SESSION_COOKIE=8d773db3cd1c3e1862d910494c27a514-1306581046.982572-757318715 - no_proxy=0.0.0.0, 127.0.0.1, localhost - - false - - -w - - /usr/bin/make - true - /home/karim/Documents/Cours/LO21/projet/Bug_Attack + System - buildconfiguration-Debug-cleanstep0 + ProjectExplorer.Project.Target.0 - Debug - true - - clean - + Desktop + Qt4ProjectManager.Target.DesktopTarget + 0 + 0 + + + + QtProjectManager.QMakeBuildStep + + + + + Qt4ProjectManager.MakeStep + false + + + + 2 + + + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/clement/Projects/Bug_Attack-build-desktop + 2 + 0 + true + + + + + QtProjectManager.QMakeBuildStep + + + + + Qt4ProjectManager.MakeStep + false + + + + 2 + + + Qt4ProjectManager.MakeStep + true + + + + 1 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/clement/Projects/Bug_Attack-build-desktop + 2 + 0 + true + + 2 + + Bug_Attack + Qt4ProjectManager.Qt4RunConfiguration + 2 + + Bug_Attack.pro + false + false + + false + false + + + 1 - buildconfiguration-Release-buildstep0 - - Release - - - - buildconfiguration-Release-buildstep1 - - Release - - - - buildconfiguration-Release-cleanstep0 - - Release - - - - buildconfigurations - - Debug - Release - - - - buildstep0 - - - - - - - buildstep1 - - - - - - buildsteps - - trolltech.qt4projectmanager.qmake - trolltech.qt4projectmanager.make - - - - cleanstep0 - - - true - - - - cleansteps - - trolltech.qt4projectmanager.make - - - - defaultFileEncoding - System + ProjectExplorer.Project.TargetCount + 1 - project - + ProjectExplorer.Project.Updater.FileVersion + 4 diff --git a/defenser.cpp b/defenser.cpp index 11fed1d..691d5f8 100644 --- a/defenser.cpp +++ b/defenser.cpp @@ -1,8 +1,7 @@ -#include -#include #include #include "defenser.h" #include "projectile.h" +#include /** * DEFENSER @@ -12,6 +11,9 @@ Defenser::Defenser(int posx,int posy,int level,Map* map) :Entity(posx,posy),_level(level),_map(map) { this->setIsSelected(true); // Appel à la méthode pour rafraichir l'affichage + // Met le compteur interne à 0 et relie le FPS au tir + _shootTimerStep = 0; + // QObject::connect(&map->gameTimer,SIGNAL(timeout()), this,SLOT(shootTarget())); } @@ -28,6 +30,54 @@ void Defenser::increaseLevel(void) { this->updateStats(); } +void Defenser::advance(int phase) { + if(!phase) + return; + + // Détection des ennemis aux alentours + QList enemies = _map->getEnemyList(); + + QList::iterator i; + + // Recherche des ennemis de la map (tire sur tous les types d'ennemis) + for(i = enemies.begin() ; i != enemies.end() ; ++i) { + + float targetX = (*i)->x(); + float targetY = (*i)->y(); + + if( (_targetType | (*i)->getType()) == _targetType && + sqrt(pow(fabs(this->x()-16 - targetX - ((*i)->getSize()-1)*16),2) + +pow(fabs(this->y()-16 - targetY - ((*i)->getSize()-1)*16),2) + ) <= _range) + { + // Si le défenseur ne tirait pas encore + if(!_isShooting) { + this->setIsShooting(true); // Modification via la méthode pour les effets visuels + } + // Actualise la position de la cible + this->setTarget(targetX+(*i)->getSize()*16,targetY+(*i)->getSize()*16); + // Tire + this->shootTarget(); + + return; // On vise la première cible rencontrée + + } // end distanceTest + + } //eof + // Si aucun monstre n'a été rencontré + this->setIsShooting(false); // Modification via la méthode pour les effets visuels + +} // eom + +QRectF Defenser::boundingRect(void) const { + return QRectF(-32,-32,_range,_range); +} + +void Defenser::setTarget(float targetX,float targetY) { + // Sauvegarde la position de la cible courante + _targetX = targetX; + _targetY = targetY; +} void Defenser::setIsShooting(bool state) { @@ -52,6 +102,12 @@ void Defenser::setIsShooting(bool state) { } +bool Defenser::isShooting(void) const { return _isShooting;} + +// On considère que par défaut seules trois améliorations sont possibles +// Cette méthode est néanmoins virtuelle pour cas particulier(s) +bool Defenser::isLevelMax(void) const { return _level==3; } + /** * PISTOLET A EAU **/ @@ -60,13 +116,9 @@ WaterGun::WaterGun(int posx,int posy,int level,Map* map) : Defenser(posx,posy,level,map) { // Type de cible - _target = TYPE::T_RAMPANT & TYPE::T_VOLANT; - _shootTimerStep = 0; - _rate = 4 - _level/2; + _targetType = DEFAULT_TARGET_TYPE; // Caractéristiques this->updateStats(); - - QObject::connect(&map->gameTimer,SIGNAL(timeout()), this,SLOT(shootTarget())); } int WaterGun::getCost(int level) const{ @@ -75,9 +127,9 @@ int WaterGun::getCost(int level) const{ if(level == -1) level = _level; switch(level) { - case 1: return 8; - case 2: return 20; - default: return 45; + case 1: return BASIC_COST; + case 2: return INTERMEDIATE_COST; + default: return HIGHEST_COST; } } @@ -98,9 +150,6 @@ QString WaterGun::getInfos(void) const { return infos; } -bool WaterGun::isShooting(void) const { return _isShooting;} - -bool WaterGun::isLevelMax(void) const { return _level==3; } void WaterGun::updateStats(void) { @@ -110,17 +159,98 @@ void WaterGun::updateStats(void) { } -QRectF WaterGun::boundingRect(void) const { - return QRectF(-32,-32,_range,_range); + +void WaterGun::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + + // Si la tourelle est selectionnée, on dessine un halo autour + if(_isSelected) { + painter->setBrush(QBrush(Qt::yellow)); + painter->drawRect(-2,-2,36,36); + } + + // Dessine la tourelle + painter->setBrush(QBrush(Qt::blue)); + painter->drawRect(0,0,32,32); + + // Dessine la portée de la tourelle + painter->setBrush(QBrush(Qt::blue,Qt::NoBrush)); + painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range); } -void WaterGun::setTarget(float targetX,float targetY) { - // Sauvegarde la position de la cible courante - _targetX = targetX; - _targetY = targetY; +void WaterGun::shootTarget(void) { + if (!isShooting()) + return; + + _shootTimerStep+= 1; + + if (_shootTimerStep < (GAME::FPS / _rate)) + return; + + _shootTimerStep = 0; + + // Créé un nouveau projectile au niveau du centre de la tourelle + Projectile* shot = new ProjectileWater(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map); + _map->addItem(shot); + } -void WaterGun::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + +/** +* LANCE PIERRE +**/ + +Slingshot::Slingshot(int posx,int posy,int level,Map* map) + : Defenser(posx,posy,level,map) +{ + // Type de cible + _targetType = DEFAULT_TARGET_TYPE; + _shootTimerStep = 0; + // Caractéristiques + this->updateStats(); +} + +int Slingshot::getCost(int level) const{ + + // Si aucune valeur en argument, alors on affiche le coût du niveau courant + if(level == -1) level = _level; + + switch(level) { + case 1: return BASIC_COST; + case 2: return INTERMEDIATE_COST; + default: return HIGHEST_COST; + } +} + +QString Slingshot::getInfos(void) const { + + // Infos générales + QString infos = "Lance-pierres de niveau "; + infos+= QString::number(_level); + // Amélioration + if(!this->isLevelMax()) { + infos+= "\n- Amelioration : "; + infos+= QString::number(this->getCost(_level+1)); + } + // Revente + infos+= "\n- Revente : "; + infos+= QString::number(this->getCost(_level)/2); + + return infos; +} + + + +void Slingshot::updateStats(void) { + + _range = (3.0f + _level/2.0f)*32.0f; + _rate = 1; + _power = 10 * _level * sqrt(_level); // level ^ 1.5 + +} + + + +void Slingshot::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { // Si la tourelle est selectionnée, on dessine un halo autour if(_isSelected) { @@ -129,7 +259,7 @@ void WaterGun::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget } // Dessine la tourelle - painter->setBrush(QBrush(Qt::red)); + painter->setBrush(QBrush(Qt::gray)); painter->drawRect(0,0,32,32); // Dessine la portée de la tourelle @@ -137,47 +267,101 @@ void WaterGun::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range); } -void WaterGun::advance(int phase) { - if(!phase) +void Slingshot::shootTarget(void) { + if (!isShooting()) return; - // Détection des ennemis aux alentours - QList enemies = _map->getEnemyList(); + _shootTimerStep+= 1; - QList::iterator i; + if (_shootTimerStep < (GAME::FPS / _rate)) + return; - // Recherche des ennemis de la map (tire sur tous les types d'ennemis) - for(i = enemies.begin() ; i != enemies.end() ; ++i) { + _shootTimerStep = 0; - float targetX = (*i)->x(); - float targetY = (*i)->y(); + // Créé un nouveau projectile au niveau du centre de la tourelle + Projectile* shot = new ProjectileStone(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map); + _map->addItem(shot); - if(sqrt(pow(fabs(this->x()-16 - targetX - ((*i)->getSize()-1)*16),2) - +pow(fabs(this->y()-16 - targetY - ((*i)->getSize()-1)*16),2) - ) <= _range) - { - // Si le défenseur ne tirait pas encore - if(!_isShooting) { - this->setIsShooting(true); // Modification via la méthode pour les effets visuels - } - // Actualise la position de la cible - this->setTarget(targetX+(*i)->getSize()*16,targetY+(*i)->getSize()*16); +} - return; // On vise la première cible rencontrée - } // end distanceTest +/** +* PAINTBALL +**/ - } //eof - // Si aucun monstre n'a été rencontré - this->setIsShooting(false); // Modification via la méthode pour les effets visuels +Paintball::Paintball(int posx,int posy,int level,Map* map) + : Defenser(posx,posy,level,map) +{ + // Type de cible + _targetType = DEFAULT_TARGET_TYPE; + _shootTimerStep = 0; + // Caractéristiques + this->updateStats(); +} -} // eom +int Paintball::getCost(int level) const{ -void WaterGun::shootTarget(void) { + // Si aucune valeur en argument, alors on affiche le coût du niveau courant + if(level == -1) level = _level; + + switch(level) { + case 1: return BASIC_COST; + case 2: return INTERMEDIATE_COST; + default: return HIGHEST_COST; + } +} + +QString Paintball::getInfos(void) const { + + // Infos générales + QString infos = "Paint-ball de niveau "; + infos+= QString::number(_level); + // Amélioration + if(!this->isLevelMax()) { + infos+= "\n- Amelioration : "; + infos+= QString::number(this->getCost(_level+1)); + } + // Revente + infos+= "\n- Revente : "; + infos+= QString::number(this->getCost(_level)/2); + + return infos; +} + + + +void Paintball::updateStats(void) { + + _range = (4.0f + _level/2.0f)*32.0f; + _rate = 2; + _power = 4 * _level * sqrt(_level); // level ^ 1.5 + +} + + + +void Paintball::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + + // Si la tourelle est selectionnée, on dessine un halo autour + if(_isSelected) { + painter->setBrush(QBrush(Qt::yellow)); + painter->drawRect(-2,-2,36,36); + } + + // Dessine la tourelle + painter->setBrush(QBrush(Qt::white)); + painter->drawRect(0,0,32,32); + + // Dessine la portée de la tourelle + painter->setBrush(QBrush(Qt::blue,Qt::NoBrush)); + painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range); +} + +void Paintball::shootTarget(void) { if (!isShooting()) return; - _shootTimerStep+= 1; /* pas très sur de ça */ + _shootTimerStep+= 1; if (_shootTimerStep < (GAME::FPS / _rate)) return; @@ -185,8 +369,103 @@ void WaterGun::shootTarget(void) { _shootTimerStep = 0; // Créé un nouveau projectile au niveau du centre de la tourelle - Projectile* shot = new Projectile(this->x()+14,this->y()+14,_targetX,_targetY,5,_power, _map); + Projectile* shot = new ProjectilePaintball(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map); _map->addItem(shot); } + + +/** +* PAINTBALL +**/ + +Bowling::Bowling(int posx,int posy,int level,Map* map) + : Defenser(posx,posy,level,map) +{ + // Type de cible + _targetType = DEFAULT_TARGET_TYPE; + _shootTimerStep = 0; + // Caractéristiques + this->updateStats(); +} + +int Bowling::getCost(int level) const{ + + // Si aucune valeur en argument, alors on affiche le coût du niveau courant + if(level == -1) level = _level; + + switch(level) { + case 1: return BASIC_COST; + case 2: return INTERMEDIATE_COST; + default: return HIGHEST_COST; + } +} + +QString Bowling::getInfos(void) const { + + // Infos générales + QString infos = "Joueur de petanque de niveau "; + infos+= QString::number(_level); + // Amélioration + if(!this->isLevelMax()) { + infos+= "\n- Amelioration : "; + infos+= QString::number(this->getCost(_level+1)); + } + // Revente + infos+= "\n- Revente : "; + infos+= QString::number(this->getCost(_level)/2); + + return infos; +} + + + +void Bowling::updateStats(void) { + + _range = (3.0f + _level/2.0f)*32.0f; + _rate = 0.5; + _power = 15 * _level * sqrt(_level); // level ^ 1.5 + +} + + + +void Bowling::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + + // Si la tourelle est selectionnée, on dessine un halo autour + if(_isSelected) { + painter->setBrush(QBrush(Qt::yellow)); + painter->drawRect(-2,-2,36,36); + } + + // Dessine la tourelle + painter->setBrush(QBrush(Qt::black)); + painter->drawRect(0,0,32,32); + + // Dessine la portée de la tourelle + painter->setBrush(QBrush(Qt::blue,Qt::NoBrush)); + painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range); +} + +void Bowling::shootTarget(void) { + if (!isShooting()) + return; + + _shootTimerStep+= 1; + + if (_shootTimerStep < (GAME::FPS / _rate)) + return; + + _shootTimerStep = 0; + + // Créé un nouveau projectile au niveau du centre de la tourelle + Projectile* shot = new ProjectileBowling(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map); + _map->addItem(shot); + +} + + + + + diff --git a/defenser.h b/defenser.h index c53ddc8..cc7041c 100644 --- a/defenser.h +++ b/defenser.h @@ -1,7 +1,6 @@ #ifndef DEFENSER_H #define DEFENSER_H -#include #include "map.h" #include "entity.h" @@ -21,16 +20,21 @@ public: virtual int getCost(int level = -1) const = 0; virtual QString getInfos(void) const = 0; void increaseLevel(void); - virtual bool isLevelMax(void) const = 0; bool isSelected(void) const; + virtual bool isLevelMax(void) const; void setIsShooting(bool state); + void setTarget(float targetX,float targetY); + QRectF boundingRect(void) const; + bool isShooting(void) const; protected: virtual void updateStats(void) = 0; + virtual void advance(int phase); + virtual void shootTarget(void) = 0; int _shootTimerStep; int _level; - int _target; // combinaison de TYPE::ENTITY + int _targetType; // combinaison de TYPE::ENTITY float _rate; float _range; int _power; @@ -57,25 +61,108 @@ class WaterGun : public Defenser { Q_OBJECT + void shootTarget(void); + public: + + static const int DEFAULT_TARGET_TYPE = TYPE::T_RAMPANT | TYPE::T_VOLANT; + static const int BASIC_COST = 8; + static const int INTERMEDIATE_COST = 20; + static const int HIGHEST_COST = 45; + WaterGun(int posx,int posy,int level,Map* map); int getCost(int level = -1) const; - QString getInfos(void) const; - bool isShooting(void) const; - bool isLevelMax(void) const; + QString getInfos(void) const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); - void setTarget(float targetX,float targetY); - QRectF boundingRect(void) const; - static int getBasicCost(void) { return 8; } + static int getBasicCost(void) { return BASIC_COST; } + protected: - void advance(int phase); void updateStats(void); +}; + +/** +* LANCE PIERRE +**/ + + +class Slingshot : public Defenser +{ + Q_OBJECT -public slots: void shootTarget(void); +public: + + static const int DEFAULT_TARGET_TYPE = TYPE::T_VOLANT; + static const int BASIC_COST = 12; + static const int INTERMEDIATE_COST = 25; + static const int HIGHEST_COST = 60; + + Slingshot(int posx,int posy,int level,Map* map); + int getCost(int level = -1) const; + QString getInfos(void) const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + static int getBasicCost(void) { return BASIC_COST; } + +protected: + void updateStats(void); }; +/** +* PAINTBALL +**/ + + +class Paintball : public Defenser +{ + Q_OBJECT + + void shootTarget(void); + +public: + + static const int DEFAULT_TARGET_TYPE = TYPE::T_RAMPANT | TYPE::T_VOLANT; + static const int BASIC_COST = 12; + static const int INTERMEDIATE_COST = 25; + static const int HIGHEST_COST = 60; + + Paintball(int posx,int posy,int level,Map* map); + int getCost(int level = -1) const; + QString getInfos(void) const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + static int getBasicCost(void) { return BASIC_COST; } + +protected: + void updateStats(void); +}; + +/** +* PETANQUE +**/ + + +class Bowling : public Defenser +{ + Q_OBJECT + + void shootTarget(void); + +public: + + static const int DEFAULT_TARGET_TYPE = TYPE::T_RAMPANT; + static const int BASIC_COST = 15; + static const int INTERMEDIATE_COST = 40; + static const int HIGHEST_COST = 80; + + Bowling(int posx,int posy,int level,Map* map); + int getCost(int level = -1) const; + QString getInfos(void) const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + static int getBasicCost(void) { return BASIC_COST; } + +protected: + void updateStats(void); +}; #endif // DEFENSER_H diff --git a/enemy.cpp b/enemy.cpp index 42a448f..143c474 100644 --- a/enemy.cpp +++ b/enemy.cpp @@ -9,6 +9,8 @@ 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); + // Désactive tout malus + _malusCounter = 0; // Repertorie cet ennemi depuis la map _map->addEnemy(this); @@ -19,6 +21,15 @@ int Enemy::getHP(void) const { return _hp; } int Enemy::getResistance(void) const { return _resistance; } TYPE::ENTITY Enemy::getType(void) const { return _type; } +void Enemy::setSpeedMalus(float percent, int seconds) { + _malusCounter = GAME::FPS * seconds; + if(percent >= 0 && percent <= 1) + _speedMalus = percent; // Applique un pourcentage réducteur + else + _speedMalus = 0; // Par défaut on arrête l'ennemi +} + + float Enemy::getSize(void) const { return _size; } void Enemy::hurt(int damages){ @@ -27,7 +38,7 @@ void Enemy::hurt(int damages){ // 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 - emit killedByPlayer(this->getResistance()); // TODO choisir le gain + emit killedByPlayer(this->getSize()); // TODO choisir le gain // Retire de l'indexation de la map emit enemyDestroyed(this); return; @@ -82,11 +93,20 @@ void Enemy::advance(int phase) { - // Déplacement normal + /// Déplacement + // Calcul d'éventuels malus + float speedMalus = 1; // Si aucun malus, cette valeur restera à 1, soit aucune modification + if(_malusCounter > 0) { + _malusCounter--; + speedMalus = _speedMalus; + } + + // Recherche de la direction à suivre QPointF dirVect = currentTile.getDirection(); - float new_x = this->x() + _speed*dirVect.x(); - float new_y = this->y() + _speed*dirVect.y(); + // Application de la vitesse + float new_x = this->x() + _speed*dirVect.x()*speedMalus; + float new_y = this->y() + _speed*dirVect.y()*speedMalus; this->setPos(new_x,new_y); @@ -133,7 +153,7 @@ void Enemy::reachGoal(void) { Cafard::Cafard(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) { // Données du cafard - _type = TYPE::T_RAMPANT; + _type = DEFAULT_TYPE; _hp = 10*size*size; _hpMax = _hp; _resistance = 5*size*size; @@ -177,7 +197,7 @@ void Cafard::advance(int phase) { Fourmi::Fourmi(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) { // Données de la fourmi - _type = TYPE::T_RAMPANT; + _type = DEFAULT_TYPE; _hp = 5*size*size; _hpMax = _hp; _resistance = size*size; @@ -233,7 +253,7 @@ void Fourmi::advance(int phase) { Guepe::Guepe(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) { // Données de la guepe - _type = TYPE::T_VOLANT; + _type = DEFAULT_TYPE; _hp = 7*size*size; _hpMax = _hp; _resistance = 4*size*size; @@ -299,7 +319,7 @@ void Guepe::advance(int phase) { Moustique::Moustique(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size) { // Données du moustique - _type = TYPE::T_VOLANT; + _type = DEFAULT_TYPE; _hp = 6*size*size; _hpMax = _hp; @@ -307,7 +327,7 @@ Moustique::Moustique(Map* map,int posx,int posy, float size):Enemy(map,posx,posy // Images et animations for(int i = 0; i < 2; ++i) { - QPixmap* animTemp = new QPixmap("./media/textures/ennemies/guepe" + QString::number(i+1) + ".png"); + QPixmap* animTemp = new QPixmap("./media/textures/ennemies/moustique" + QString::number(i+1) + ".png"); *animTemp = animTemp->scaled(size*32,size*32); _animPixmap.push_back(animTemp); } diff --git a/enemy.h b/enemy.h index ae2c2a4..01eb0c3 100644 --- a/enemy.h +++ b/enemy.h @@ -23,7 +23,7 @@ public: TYPE::ENTITY getType(void) const; float getSize(void) const; virtual void hurt(int damages); - + void setSpeedMalus(float percent,int seconds); void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); QRectF boundingRect(void) const; @@ -34,6 +34,11 @@ protected: int _hpMax; int _resistance; float _speed; + + // Malus + float _speedMalus; + int _malusCounter; + TYPE::ENTITY _type; virtual void advance(int phase); @@ -56,6 +61,9 @@ class Cafard : public Enemy public: + + const static TYPE::ENTITY DEFAULT_TYPE = TYPE::T_RAMPANT; + Cafard(Map* map,int posx,int posy, float size); void hurt(int damages); @@ -73,6 +81,9 @@ class Fourmi : public Enemy public: + + const static TYPE::ENTITY DEFAULT_TYPE = TYPE::T_RAMPANT; + Fourmi(Map* map,int posx,int posy, float size); void hurt(int damages); @@ -94,6 +105,9 @@ class Guepe : public Enemy public: + + const static TYPE::ENTITY DEFAULT_TYPE = TYPE::T_VOLANT; + Guepe(Map* map,int posx,int posy, float size); void hurt(int damages); @@ -115,6 +129,9 @@ class Moustique : public Enemy public: + + const static TYPE::ENTITY DEFAULT_TYPE = TYPE::T_VOLANT; + Moustique(Map* map,int posx,int posy, float size); void hurt(int damages); diff --git a/enemyfactory.cpp b/enemyfactory.cpp index 0136f38..4d751c4 100644 --- a/enemyfactory.cpp +++ b/enemyfactory.cpp @@ -139,7 +139,27 @@ void EnemyFactory::produceWave(void){ _waveTimerStep = 0; // Vérifie s'il reste des vagues à produire - if(_mapWaves.empty()){ + if(_mapWaves.empty()){ + if(_currentMap->getEnemyList().empty()) { + + //!-- BLOC DE FIN DE PARTIE : Victoire + QMessageBox msgBox; + msgBox.setText("Fin de partie"); + msgBox.setInformativeText("Vous avez gagné."); + + QPushButton *restartButton = msgBox.addButton(tr("Rejouer"), QMessageBox::ActionRole); + QPushButton *quitButton = msgBox.addButton(tr("Quitter"), QMessageBox::ActionRole); + msgBox.exec(); + + if (msgBox.clickedButton() == (QAbstractButton *) restartButton) { + + } else if (msgBox.clickedButton() == (QAbstractButton *) quitButton) { + exit(0); + } + // FIN DU BLOC --! + + + } return; } diff --git a/enemyfactory.h b/enemyfactory.h index c38ba03..fabe4cc 100644 --- a/enemyfactory.h +++ b/enemyfactory.h @@ -2,7 +2,6 @@ #define ENEMYFACTORY_H #include -#include #include #include "map.h" diff --git a/mainwindow.cpp b/mainwindow.cpp index af09f33..08f99e3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -12,7 +12,7 @@ MainWindow::MainWindow(QWidget *parent) : /** * Initialisation des données du joueur **/ - _player = new Player(999,10); + _player = new Player(22,10); /** * Création et chargement de la map @@ -47,8 +47,16 @@ MainWindow::MainWindow(QWidget *parent) : /// Boutons de choix de tourelle // . Pistolet à eau QObject::connect(ui->turretButton_PistoletAEau,SIGNAL(pressed()),_player,SLOT(setTurretChoice1())); - QObject::connect(_player,SIGNAL(setTurret1ButtonDisabled(bool)),this->ui->turretButton_PistoletAEau,SLOT(setDisabled(bool))); - + QObject::connect(_player,SIGNAL(setTurret1ButtonDisabled(bool)),ui->turretButton_PistoletAEau,SLOT(setDisabled(bool))); + // . Lance-pierres + QObject::connect(ui->turretButton_LancePierres,SIGNAL(pressed()),_player,SLOT(setTurretChoice2())); + QObject::connect(_player,SIGNAL(setTurret2ButtonDisabled(bool)),ui->turretButton_LancePierres,SLOT(setDisabled(bool))); + // . Paintball + QObject::connect(ui->turretButton_Paintball,SIGNAL(pressed()),_player,SLOT(setTurretChoice3())); + QObject::connect(_player,SIGNAL(setTurret3ButtonDisabled(bool)),ui->turretButton_Paintball,SLOT(setDisabled(bool))); + // . Pétanque + QObject::connect(ui->turretButton_Petanque,SIGNAL(pressed()),_player,SLOT(setTurretChoice4())); + QObject::connect(_player,SIGNAL(setTurret4ButtonDisabled(bool)),ui->turretButton_Petanque,SLOT(setDisabled(bool))); // Demande d'informations sur une tourelle QObject::connect(_sceneMap,SIGNAL(turretInfosRequest(QString)),ui->turretInfoLabel,SLOT(setText(QString))); @@ -91,9 +99,9 @@ void MainWindow::showMapContextMenu(const QPoint& pos) { // Création du menu de choix de la tourelle QMenu myMenu(this); QAction* createTurret1 = myMenu.addAction("Pistolet a eau"); - myMenu.addAction("-- turret 2 --"); - myMenu.addAction("-- turret 3 --"); - myMenu.addAction("-- turret 4 --"); + QAction* createTurret2 = myMenu.addAction("Lance-pierres"); + QAction* createTurret3 = myMenu.addAction("Paintball"); + QAction* createTurret4 = myMenu.addAction("Petanque"); myMenu.addAction("-- turret 5 --"); // On regarde si un choix a été effectué et si la case est libre pour la pose d'une tourelle @@ -103,6 +111,12 @@ void MainWindow::showMapContextMenu(const QPoint& pos) { // TODO CHANGER ADD TURRET if(selectedItem == createTurret1) _sceneMap->addTurretAt(TYPE::PISTOLET_A_EAU,mousePos.x(),mousePos.y()); + else if(selectedItem == createTurret2) + _sceneMap->addTurretAt(TYPE::LANCE_PIERRES,mousePos.x(),mousePos.y()); + else if(selectedItem == createTurret3) + _sceneMap->addTurretAt(TYPE::PAINTBALL,mousePos.x(),mousePos.y()); + else if(selectedItem == createTurret4) + _sceneMap->addTurretAt(TYPE::PETANQUE,mousePos.x(),mousePos.y()); } } diff --git a/mainwindow.ui b/mainwindow.ui index f173063..f6fe652 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -132,6 +132,45 @@ Pistolet à eau + + + + 130 + 30 + 98 + 27 + + + + Lance-pierres + + + + + + 20 + 60 + 98 + 27 + + + + PaintBall + + + + + + 130 + 60 + 98 + 27 + + + + Pétanque + + diff --git a/map.cpp b/map.cpp index 90a1f9e..a1cda00 100644 --- a/map.cpp +++ b/map.cpp @@ -95,7 +95,7 @@ void Map::removeEnemy(Enemy* ptr) { int i; for(i = 0; i < _enemies.length() ; ++i) { - if(_enemies[i] == ptr){ + if(_enemies[i] == ptr) { std::cout << "OMG je suis mort" << std::endl; _enemies.removeAt(i); // QObject::disconnect(ptr); @@ -132,6 +132,42 @@ bool Map::addTurretAt(TYPE::TURRET turretType,float mx,float my) { } break; + // Lance-pierres + case TYPE::LANCE_PIERRES: + if(_player->payMoney(Slingshot::getBasicCost())) + { + enoughMoney = true; + newTurret = new Slingshot(((int)(mx/32))*32, + ((int)(my/32))*32, + 1, + this); + } + break; + + // Paintball + case TYPE::PAINTBALL: + if(_player->payMoney(Paintball::getBasicCost())) + { + enoughMoney = true; + newTurret = new Paintball(((int)(mx/32))*32, + ((int)(my/32))*32, + 1, + this); + } + break; + + // Pétanque + case TYPE::PETANQUE: + if(_player->payMoney(Bowling::getBasicCost())) + { + enoughMoney = true; + newTurret = new Bowling(((int)(mx/32))*32, + ((int)(my/32))*32, + 1, + this); + } + break; + // Type inconnu ~ erreur default: break; @@ -188,6 +224,8 @@ void Map::removeTurret(void) { // Désactive les boutons de tourelle emit disableTurretUpgradeButton(true); emit disableTurretSellButton(true); + // Met à jour l'affichage + this->update(); break; } @@ -218,6 +256,9 @@ void Map::upgradeTurret(void) { // Si l'upgrade est maximale, on désactive le bouton d'upgrade if(_turrets[i]->isLevelMax()) emit disableTurretUpgradeButton(true); + + // Met à jour l'affichage + this->update(); } break; } diff --git a/map.h b/map.h index 3f717c9..9d5daf8 100644 --- a/map.h +++ b/map.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/media/textures/ennemies/moustiquevolant1.png b/media/textures/ennemies/moustique1.png similarity index 100% rename from media/textures/ennemies/moustiquevolant1.png rename to media/textures/ennemies/moustique1.png diff --git a/media/textures/ennemies/moustiquevolant2.png b/media/textures/ennemies/moustique2.png similarity index 100% rename from media/textures/ennemies/moustiquevolant2.png rename to media/textures/ennemies/moustique2.png diff --git a/player.cpp b/player.cpp index ad36ec6..ec142d2 100644 --- a/player.cpp +++ b/player.cpp @@ -33,9 +33,24 @@ void Player::loseLives(int livesLost) { // Fait perdre des vies au joueur // ... et le compteur est notifié _lives-=livesLost; - if(_lives < 0) + if(_lives <= 0){ _lives = 0; + //!-- BLOC DE FIN DE PARTIE : Victoire + QMessageBox msgBox; + msgBox.setText("Fin de partie"); + msgBox.setInformativeText("Vous avez perdu..."); + QPushButton *restartButton = msgBox.addButton(tr("Rejouer"), QMessageBox::ActionRole); + QPushButton *quitButton = msgBox.addButton(tr("Quitter"), QMessageBox::ActionRole); + msgBox.exec(); + if (msgBox.clickedButton() == (QAbstractButton *) restartButton) { + + } + else if (msgBox.clickedButton() == (QAbstractButton *) quitButton) + exit(0); + // FIN DU BLOC --! + } + emit livesValueChanged(_lives); } @@ -58,6 +73,15 @@ void Player::setTurretChoice(TYPE::TURRET choice) { case TYPE::PISTOLET_A_EAU : emit setTurret1ButtonDisabled(false); break; + case TYPE::LANCE_PIERRES : + emit setTurret2ButtonDisabled(false); + break; + case TYPE::PAINTBALL: + emit setTurret3ButtonDisabled(false); + break; + case TYPE::PETANQUE: + emit setTurret4ButtonDisabled(false); + break; default: break; } @@ -72,6 +96,15 @@ void Player::setTurretChoice(TYPE::TURRET choice) { case TYPE::PISTOLET_A_EAU: emit setTurret1ButtonDisabled(true); break; + case TYPE::LANCE_PIERRES: + emit setTurret2ButtonDisabled(true); + break; + case TYPE::PAINTBALL: + emit setTurret3ButtonDisabled(true); + break; + case TYPE::PETANQUE: + emit setTurret4ButtonDisabled(true); + break; default: break; } @@ -79,6 +112,9 @@ void Player::setTurretChoice(TYPE::TURRET choice) { } void Player::setTurretChoice1(){this->setTurretChoice(TYPE::PISTOLET_A_EAU);} +void Player::setTurretChoice2(){this->setTurretChoice(TYPE::LANCE_PIERRES);} +void Player::setTurretChoice3(){this->setTurretChoice(TYPE::PAINTBALL);} +void Player::setTurretChoice4(){this->setTurretChoice(TYPE::PETANQUE);} diff --git a/player.h b/player.h index 4aeb0a7..ca79d1e 100644 --- a/player.h +++ b/player.h @@ -1,6 +1,7 @@ #ifndef PLAYER_H #define PLAYER_H +#include #include #include "types.h" @@ -31,12 +32,18 @@ public slots: void loseLives(int livesLost); void turretSold(int money); void setTurretChoice1(); + void setTurretChoice2(); + void setTurretChoice3(); + void setTurretChoice4(); signals: void moneyValueChanged(int); void livesValueChanged(int); void setTurret1ButtonDisabled(bool); + void setTurret2ButtonDisabled(bool); + void setTurret3ButtonDisabled(bool); + void setTurret4ButtonDisabled(bool); void turretSelected(); }; diff --git a/projectile.cpp b/projectile.cpp index c4d3b11..4e7c17e 100644 --- a/projectile.cpp +++ b/projectile.cpp @@ -3,8 +3,12 @@ #include "map.h" #include "projectile.h" -Projectile::Projectile(float posX, float posY, float targetX, float targetY, float speed, int damages, Map* map) - : Entity(posX,posY),_speed(speed),_damages(damages),_targetX(targetX),_targetY(targetY) +/** +* PROJECTILE +**/ + +Projectile::Projectile(float posX, float posY, float targetX, float targetY, int damages, Map* map) + : Entity(posX,posY),_damages(damages),_targetX(targetX),_targetY(targetY) { // Calcul du vecteur de déplacement du point (posX,posY) vers (targetX,targetY) // .. Nb : on calcule ici le vecteur normalisé pour appliquer ensuite la vitesse propre à l'objet @@ -20,16 +24,94 @@ QRectF Projectile::boundingRect() const { return QRectF(0,0,5,5); } -void Projectile::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { +void Projectile::advance(int phase) { + + if(!phase) + return; + + // Collision avec ennemi + // . Recherche des ennemis de la map + QList entities = _map->getEnemyList(); + QList::iterator i; + for(i = entities.begin(); i < entities.end() ; ++i) { + if(((*i)->getType() | _targetType) == _targetType && + this->collidesWithItem(*i,Qt::IntersectsItemBoundingRect)){ + // On retire le projectile de la scène + this->scene()->removeItem(this); + // Inflige des domages au monstre + Enemy *e = *i; + e->hurt(_damages); + return; + } + } + + + + // Déplacement du projectile selon le vecteur de déplacement et la vitesse + float newx = this->x() + _speed*_movementVect.x(); + float newy = this->y() + _speed*_movementVect.y(); + + // std::cout << "I'm still alive mothafucka" << std::endl; + + // Si le projectile est en dehors de l'écran, on le supprime + if(newx < 0 || newx > 512 || newy < 0 || newy > 512){ + _map->removeItem(this); // TODO VERIFIER Semble faire un appel à delete() de l'objet + return; + } + this->setPos(newx,newy); + +} + +/** +* PROJECTILE WATER +**/ + +ProjectileWater::ProjectileWater(float posX,float posY,float targetX,float targetY,int damages, Map *map) + :Projectile(posX,posY,targetX,targetY,damages,map){ + _targetType = DEFAULT_TARGET_TYPE; + _speed = DEFAULT_SPEED; +} +void ProjectileWater::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + // Dessine le projectile painter->setBrush(QBrush(Qt::cyan)); - // Dessine la tourelle painter->drawRect(0,0,5,5); +} +/** +* PROJECTILE WATER +**/ +ProjectileStone::ProjectileStone(float posX,float posY,float targetX,float targetY,int damages, Map *map) + :Projectile(posX,posY,targetX,targetY,damages,map){ + _targetType = DEFAULT_TARGET_TYPE; + _speed = DEFAULT_SPEED; } -void Projectile::advance(int phase) { +void ProjectileStone::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + // Dessine le projectile + painter->setBrush(QBrush(Qt::gray)); + painter->drawRect(0,0,5,5); +} + + +/** +* PROJECTILE PAINT BALL +**/ + +ProjectilePaintball::ProjectilePaintball(float posX,float posY,float targetX,float targetY,int damages, Map *map) + :Projectile(posX,posY,targetX,targetY,damages,map){ + _targetType = DEFAULT_TARGET_TYPE; + _speed = DEFAULT_SPEED; +} + +void ProjectilePaintball::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + // Dessine le projectile + painter->setBrush(QBrush(Qt::green)); + painter->drawRect(0,0,5,5); +} + +void ProjectilePaintball::advance(int phase) { if(!phase) return; @@ -39,12 +121,98 @@ void Projectile::advance(int phase) { QList entities = _map->getEnemyList(); QList::iterator i; for(i = entities.begin(); i < entities.end() ; ++i) { - if(this->collidesWithItem(*i,Qt::IntersectsItemBoundingRect)){ + if( ((*i)->getType() | _targetType) == _targetType + && this->collidesWithItem(*i,Qt::IntersectsItemBoundingRect)){ // On retire le projectile de la scène this->scene()->removeItem(this); - // Inflige des dommages au monstre + // Inflige des domages au monstre Enemy *e = *i; e->hurt(_damages); + // Ralenti également le monstre pendant 4 secondes + e->setSpeedMalus(0.5f,4); + return; + } + } + + + + // Déplacement du projectile selon le vecteur de déplacement et la vitesse + float newx = this->x() + _speed*_movementVect.x(); + float newy = this->y() + _speed*_movementVect.y(); + + // std::cout << "I'm still alive mothafucka" << std::endl; + + // Si le projectile est en dehors de l'écran, on le supprime + if(newx < 0 || newx > 512 || newy < 0 || newy > 512){ + _map->removeItem(this); // TODO VERIFIER Semble faire un appel à delete() de l'objet + return; + } + this->setPos(newx,newy); + +} + + +/** +* PROJECTILE BOWLING +**/ + +ProjectileBowling::ProjectileBowling(float posX,float posY,float targetX,float targetY,int damages, Map *map) + :Projectile(posX,posY,targetX,targetY,damages,map){ + _targetType = DEFAULT_TARGET_TYPE; + _speed = DEFAULT_SPEED; +} + +void ProjectileBowling::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + // Dessine le projectile + painter->setBrush(QBrush(Qt::black)); + painter->drawRect(0,0,5,5); +} + + + +/** +* Dommages de zone : +* Les dommages de bases sont calculés de la sorte : +* 15 * niveau ^ 1.5 +* Les dommages de zone sont calculés de la sorte : +* 10 * niveau ^ 1.5 +* Afin d'économiser en calculs, on se base sur les dommages de base, multipliés par 10/15. +**/ +void ProjectileBowling::advance(int phase) { + + if(!phase) + return; + + // Collision avec ennemi + // . Recherche des ennemis de la map + QList entities = _map->getEnemyList(); + QList::iterator i; + for(i = entities.begin(); i < entities.end() ; ++i) { + if( ((*i)->getType() | _targetType) == _targetType && + this->collidesWithItem(*i,Qt::IntersectsItemBoundingRect)) { + + + // Inflige des dommages à la cible... + Enemy *e = *i; + e->hurt(_damages); + + // ... puis on recherche des ennemis à une case de distance qui seront également blessés + for(int j = 0 ; j < entities.size() ; ++j) { + + float targetX = entities[j]->x(); + float targetY = entities[j]->y(); + + if(entities[j] != e && sqrt(pow(fabs(this->x()-16 - targetX - ((*i)->getSize()-1)*16),2) + +pow(fabs(this->y()-16 - targetY - ((*i)->getSize()-1)*16),2) + ) <= 32) + { + entities[j]->hurt(_damages*10/15); + } + + } + // On retire le projectile de la scène + this->scene()->removeItem(this); + return; } } diff --git a/projectile.h b/projectile.h index 2ac6730..cb3da38 100644 --- a/projectile.h +++ b/projectile.h @@ -5,26 +5,109 @@ #include "entity.h" #include "map.h" +/** +* PROJECTILE +**/ class Map; class Projectile : public Entity { +protected: + float _speed; int _damages; float _targetX; float _targetY; + int _targetType; // Combinaison de TYPE::ENTITY QPointF _movementVect; Map* _map; virtual void advance(int phase); public: + Projectile(float posX,float posY,float targetX,float targetY,int damages, Map *map); QRectF boundingRect() const; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) = 0; + + + +}; + + +/** +* PROJECTILE WATER +**/ + +class ProjectileWater : public Projectile { + +public: + + // Caractéristiques + static const float DEFAULT_SPEED = 4; + static const int DEFAULT_TARGET_TYPE = TYPE::T_RAMPANT | TYPE::T_VOLANT; + + ProjectileWater(float posX,float posY,float targetX,float targetY,int damages, Map *map); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + +}; + + +/** +* PROJECTILE STONE +**/ + +class ProjectileStone : public Projectile { + +public: + + // Caractéristiques + static const float DEFAULT_SPEED = 2.5; + static const int DEFAULT_TARGET_TYPE = TYPE::T_VOLANT; + + + ProjectileStone(float posX,float posY,float targetX,float targetY,int damages, Map *map); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + +}; + +/** +* PROJECTILE PAINT BALL +**/ +class ProjectilePaintball : public Projectile { + + // Méthode redéfinie pour l'effet spécial + void advance(int phase); + +public: + + // Caractéristiques + static const float DEFAULT_SPEED = 3; + static const int DEFAULT_TARGET_TYPE = TYPE::T_RAMPANT | TYPE::T_VOLANT; + + + ProjectilePaintball(float posX,float posY,float targetX,float targetY,int damages, Map *map); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + +}; + +/** +* PROJECTILE BOWLING +**/ +class ProjectileBowling : public Projectile { + + // Méthode redéfinie pour l'effet spécial + void advance(int phase); + +public: + + // Caractéristiques + static const float DEFAULT_SPEED = 2; + static const int DEFAULT_TARGET_TYPE = TYPE::T_RAMPANT | TYPE::T_VOLANT; - Projectile(float posX,float posY,float targetX,float targetY,float speed,int damages, Map *map); + ProjectileBowling(float posX,float posY,float targetX,float targetY,int damages, Map *map); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); }; diff --git a/types.h b/types.h index 2c3c3b3..7497378 100644 --- a/types.h +++ b/types.h @@ -9,7 +9,7 @@ namespace TYPE { typedef enum { NORTH = 1 , SOUTH = 2 , EAST = 4 , WEST = 8, GOAL = 32, UP = 128 } DIRECTION; typedef enum { T_RAMPANT = 1, T_VOLANT = 2 } ENTITY; typedef enum { CAFARD , FOURMI , GUEPE , MOUSTIQUE } ENEMY; -typedef enum { NONE, PISTOLET_A_EAU } TURRET; +typedef enum { NONE, PISTOLET_A_EAU, LANCE_PIERRES, PAINTBALL, PETANQUE } TURRET; }; -- 2.43.0