Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
.qtcreator/
Binary file added Grazy Dave.wav
Binary file not shown.
9 changes: 9 additions & 0 deletions PVZ.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ CONFIG += c++11

SOURCES += \
main.cpp \
sound.cpp \
sunflower.cpp \
threepeater.cpp \
utils.cpp \
zombie.cpp \
plant.cpp \
wallnut.cpp \
Expand All @@ -52,7 +55,10 @@ SOURCES += \
screenzombie.cpp

HEADERS += \
sound.h \
sunflower.h \
threepeater.h \
utils.h \
zombie.h \
plant.h \
wallnut.h \
Expand Down Expand Up @@ -88,3 +94,6 @@ RESOURCES += \

RC_ICONS += \
PVZ.ico

DISTFILES += \
Grazy Dave.mp3
591 changes: 181 additions & 410 deletions PVZ.pro.user

Large diffs are not rendered by default.

579 changes: 579 additions & 0 deletions PVZ.pro.user.503846c.4.9-pre1

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,4 @@ void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
2. 在不支持可视化编程的框架下如何高效开发?

必须对`Qt`有较深入了解,并且对每个物体的坐标心中有数,反复调试。

Binary file added audios/bomb.wav
Binary file not shown.
Binary file added audios/bucket.wav
Binary file not shown.
Binary file added audios/car.wav
Binary file not shown.
Binary file added audios/sunclick.wav
Binary file not shown.
29 changes: 16 additions & 13 deletions basiczombie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

BasicZombie::BasicZombie()
{

hp = 270;
atk = 100 * 33 / 1000;
speed = 80.0 * 33 / 1000 / 4.7;
state=Zombie::move;

zomImg[attack]=":/images/ZombieAttack.gif";
if (qrand() % 2)
setMovie(":/images/ZombieWalk1.gif");
zomImg[state]=":/images/ZombieWalk1.gif";
else
setMovie(":/images/ZombieWalk2.gif");
zomImg[state]=":/images/ZombieWalk2.gif";

setMovie(zomImg[state]);
}

void BasicZombie::advance(int phase)
Expand All @@ -18,9 +24,9 @@ void BasicZombie::advance(int phase)
update();
if (hp <= 0)
{
if (state < 2)
if (state!=Zombie::die)
{
state = 2;
state = Zombie::die;
setMovie(":/images/ZombieDie.gif");
setHead(":/images/ZombieHead.gif");
}
Expand All @@ -33,20 +39,17 @@ void BasicZombie::advance(int phase)
{
Plant *plant = qgraphicsitem_cast<Plant *>(items[0]);
plant->hp -= atk;
if (state != 1)
if (state != Zombie::attack)
{
state = 1;
setMovie(":/images/ZombieAttack.gif");
state = Zombie::attack;
setMovie(zomImg[state]);
}
return;
}
if (state)
if (state!=Zombie::move)
{
state = 0;
if (qrand() % 2)
setMovie(":/images/ZombieWalk1.gif");
else
setMovie(":/images/ZombieWalk2.gif");
state = Zombie::move;
setMovie(zomImg[state]);
}
setX(x() - speed);
}
1 change: 1 addition & 0 deletions basiczombie.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class BasicZombie : public Zombie
{
public:
const static int blood=270;
BasicZombie();
void advance(int phase) override;
};
Expand Down
28 changes: 19 additions & 9 deletions bucketzombie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ BucketZombie::BucketZombie()
hp = 1370;
atk = 100 * 33 / 1000;
speed = 80.0 * 33 / 1000 / 4.7;
setMovie(":/images/BucketZombieWalk.gif");
state=Zombie::move;
zomImg[move]=":/images/BucketZombieWalk.gif";
zomImg[attack]=":/images/BucketZombieAttack.gif";
name="bucket";
setMovie(zomImg[move]);
}

void BucketZombie::advance(int phase)
Expand All @@ -15,32 +19,38 @@ void BucketZombie::advance(int phase)
update();
if (hp <= 0)
{
if (state < 2)
if (state!=Zombie::die)
{
state = 2;
state=Zombie::die;
setMovie(":/images/ZombieDie.gif");
setHead(":/images/ZombieHead.gif");
}
else if (movie->currentFrameNumber() == movie->frameCount() - 1)
delete this;
return;
}
//变成普通僵尸
if(hp<=BasicZombie::blood){
Utils::turnNormalZoombie(this);
}

QList<QGraphicsItem *> items = collidingItems();
if (!items.isEmpty())
{
Plant *plant = qgraphicsitem_cast<Plant *>(items[0]);
plant->hp -= atk;
if (state != 1)
if (state!=Zombie::attack)
{
state = 1;
setMovie(":/images/BucketZombieAttack.gif");
state=Zombie::attack;
setMovie(zomImg[state]);

}
return;
}
if (state)
if (state!=Zombie::move)
{
state = 0;
setMovie(":/images/BucketZombieWalk.gif");
state = Zombie::move;
setMovie(zomImg[state]);
}
setX(x() - speed);
}
8 changes: 7 additions & 1 deletion bucketzombie.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@

#include "zombie.h"
#include "plant.h"

#include "basiczombie.h"
#include "utils.h"
#include <QList>
class BucketZombie : public Zombie
{
public:
BucketZombie();
void advance(int phase) override;

;


};

#endif // BUCKETZOMBIE_H
5 changes: 5 additions & 0 deletions cherrybomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ CherryBomb::CherryBomb()
{
atk = 1800;
hp = 300;

setMovie(":/images/CherryBomb.gif");
sound=new Sound(":/audios/bomb.wav");
}

QRectF CherryBomb::boundingRect() const
Expand All @@ -17,12 +19,15 @@ void CherryBomb::advance(int phase)
if (!phase)
return;
update();

if (hp <= 0)
delete this;
else if (state == 0 && movie->currentFrameNumber() == movie->frameCount() - 1)
{
state = 1;

setMovie(":/images/Boom.gif");
sound->playOnlyOne();
QList<QGraphicsItem *> items = collidingItems();
foreach (QGraphicsItem *item, items)
{
Expand Down
3 changes: 2 additions & 1 deletion cherrybomb.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "plant.h"
#include "zombie.h"

#include<utils.h>
#include "sound.h"
class CherryBomb : public Plant
{
public:
Expand Down
28 changes: 20 additions & 8 deletions conezombie.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#include "conezombie.h"

#include "utils.h"

ConeZombie::ConeZombie()
{
hp = 640;
atk = 100 * 33 / 1000;
speed = 80.0 * 33 / 1000 / 4.7;

zomImg[move]=":/images/ConeZombieWalk.gif";
zomImg[attack]=":/images/ConeZombieAttack.gif";
setMovie(":/images/ConeZombieWalk.gif");
}

Expand All @@ -15,32 +20,39 @@ void ConeZombie::advance(int phase)
update();
if (hp <= 0)
{
if (state < 2)
if (state!=die)
{
state = 2;
state = die;
setMovie(":/images/ZombieDie.gif");
setHead(":/images/ZombieHead.gif");
}
else if (movie->currentFrameNumber() == movie->frameCount() - 1)
delete this;
return;
}

if(hp<=BasicZombie::blood){
Utils::turnNormalZoombie(this);
}



QList<QGraphicsItem *> items = collidingItems();
if (!items.isEmpty())
{
Plant *plant = qgraphicsitem_cast<Plant *>(items[0]);
plant->hp -= atk;
if (state != 1)
if (state != attack)
{
state = 1;
setMovie(":/images/ConeZombieAttack.gif");
state = attack;
setMovie(zomImg[attack]);
}
return;
}
if (state)
if (state!=move)
{
state = 0;
setMovie(":/images/ConeZombieWalk.gif");
state = move;
setMovie(zomImg[move]);
}
setX(x() - speed);
}
2 changes: 1 addition & 1 deletion conezombie.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "zombie.h"
#include "plant.h"

#include "basiczombie.h"
class ConeZombie : public Zombie
{
public:
Expand Down
30 changes: 21 additions & 9 deletions footballzombie.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include "footballzombie.h"

#include "utils.h"

FootballZombie::FootballZombie()
{
hp = 1670;
atk = 100 * 33 / 1000;
speed = 80.0 * 33 / 1000 / 2.5;


zomImg[move]=":/images/FootballZombieWalk.gif";
zomImg[attack]=":/images/FootballZombieAttack.gif";
zomImg[die]=":/images/FootballZombieDie.gif";
setMovie(":/images/FootballZombieWalk.gif");
}

Expand All @@ -15,33 +22,38 @@ void FootballZombie::advance(int phase)
update();
if (hp <= 0)
{
if (state < 2)
if (state !=die)
{
state = 2;
setMovie(":/images/FootballZombieDie.gif");
state = die;
setMovie(zomImg[die]);
setHead(":/images/ZombieHead.gif");

}
else if (movie->currentFrameNumber() == movie->frameCount() - 1)
delete this;
return;
}

if(hp<=BasicZombie::blood){
Utils::turnNormalZoombie(this);
}

QList<QGraphicsItem *> items = collidingItems();
if (!items.isEmpty())
{
Plant *plant = qgraphicsitem_cast<Plant *>(items[0]);
plant->hp -= atk;
if (state != 1)
if (state !=attack)
{
state = 1;
setMovie(":/images/FootballZombieAttack.gif");
state = attack;
setMovie(zomImg[state]);
}
return;
}
if (state)
if (state!=move)
{
state = 0;
setMovie(":/images/FootballZombieWalk.gif");
state = move;
setMovie(zomImg[state]);
}
setX(x() - speed);
}
2 changes: 1 addition & 1 deletion footballzombie.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "zombie.h"
#include "plant.h"

#include "basiczombie.h"
class FootballZombie : public Zombie
{
public:
Expand Down
5 changes: 5 additions & 0 deletions images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@
<file>images/ScreenZombieAttack.gif</file>
<file>images/ScreenZombieWalk.gif</file>
<file>images/ZombiesWon.png</file>
<file>images/Threepeater.gif</file>
<file>audios/bomb.wav</file>
<file>audios/bucket.wav</file>
<file>audios/car.wav</file>
<file>audios/sunclick.wav</file>
</qresource>
</RCC>
Binary file added images/Threepeater.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ int main(int argc, char *argv[])
w.setFixedSize(900, 600);
w.setWindowTitle("植物大战僵尸");
w.show();

return a.exec();
}
Loading