-
Notifications
You must be signed in to change notification settings - Fork 0
/
MasterZombie.cpp
56 lines (46 loc) · 1.7 KB
/
MasterZombie.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "MasterZombie.h"
#include "Plant.h"
#include "Oak.h"
#include <QGraphicsScene>
MasterZombie::MasterZombie(const int &pixPer50MiliSec, QTimer *timer, const int &lives, QGraphicsItem *parent)
: Zombie(pixPer50MiliSec , timer , lives , parent)
{
// set picture
setPixmap(QPixmap(":images/mZombie1.png"));
// connect timer to moveToLeft()
connect( timer , SIGNAL(timeout()) , this , SLOT( moveToLeft() ) );
}
void MasterZombie::moveToLeft() {
// change picture
if(miliSec % 500 == 0){
setPixmap(QPixmap(":images/mZombie4.png"));
}
else if(miliSec % 400 == 0){
setPixmap(QPixmap(":images/mZombie3.png"));
}
else if(miliSec % 200 == 0){
setPixmap(QPixmap(":images/mZombie2.png"));
}
else if(miliSec % 100 == 0){
setPixmap(QPixmap(":images/mZombie1.png"));
}
// ** following codes are running in the Zombie class' moveToLeft() because
// we connected Zombie class' moveToLeft() to timer in Zombie class' constructor
// so we don't need to run these codes again.
// collect colliding items in a list
// QList <QGraphicsItem *> collidingObjects = collidingItems();
// remove and delete colliding plants
// for (size_t i = 0 ; i < collidingObjects.size() ; ++i){
// Plant * plant = dynamic_cast<Plant*>(collidingObjects[i]);
// if( plant ){
// if(typeid(*(collidingObjects[i])) != typeid(Oak)){ // zombie destroy every plant except Oak
// scene()->removeItem(collidingObjects[i]);
// delete collidingObjects[i];
// }
// }
// }
//setPos(x() - pixPer50MiliSec , y());
// if ( x() == 0 ){
// exit(1); // TO DO
// }
}