forked from kn0w0n3/Super_Mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoomba.cpp
89 lines (71 loc) · 2.58 KB
/
goomba.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Author: equati0n
* Date: December 2016
*/
#include "goomba.h"
#include "player.h"
#include "smallmario.h"
#include "firemario.h"
#include <QPainter>
#include <QDebug>
Goomba::Goomba(QRectF platformRect, int direction, QGraphicsItem *parent) : QGraphicsItem(parent), mCurrentFrame3(), mPlatform(platformRect), mDirection(direction)
{
setFlag(ItemClipsToShape);
mPixmap3 = QPixmap(":images/goombas.png");
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(nextFrame()));
timer->start(100);
}
void Goomba::nextFrame() {
mCurrentFrame3 += 54;
if (mCurrentFrame3 >= 862 ) {
mCurrentFrame3 = 0;
}
if(this->pos().x() < mPlatform.x() || this->pos().x() > mPlatform.x()+ mPlatform.width()) {
mDirection = -mDirection;
setTransform(QTransform(-mDirection, 0, 0, 1, boundingRect().width(), 0));
}
setPos(this->pos().x() + (mDirection*7), this->pos().y());
//Collision Detection
QList<QGraphicsItem *> colliding_items = collidingItems();
//If one of the colliding items is an Enemy, destroy both the bullet and the enemy
for (int i = 0, n = colliding_items.size(); i < n; ++i){
if (typeid(*(colliding_items[i])) == typeid(Player)){
emit marioSizeStatus(0);
delete colliding_items[i];
qDebug()<<"Mario deleted small mario added";
delete this;
return;
}
}
for (int i = 0, n = colliding_items.size(); i < n; ++i){
if (typeid(*(colliding_items[i])) == typeid(SmallMario)){
emit marioSizeStatus(1);
delete colliding_items[i];
qDebug()<<"small mario dead";
delete this;
return;
}
}
for (int i = 0, n = colliding_items.size(); i < n; ++i){
if (typeid(*(colliding_items[i])) == typeid(FireMario)){
emit marioSizeStatus(6);
delete colliding_items[i];
qDebug()<<"Fire mario deleted small mario added";
delete this;
return;
}
}
}
QRectF Goomba::boundingRect() const {
return QRectF(0,0,52,50);
}
void Goomba::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->drawPixmap(0,0, mPixmap3, mCurrentFrame3, 0,52, 50);
setTransformOriginPoint(boundingRect().center());
Q_UNUSED(widget);
Q_UNUSED(option);
}
int Goomba::type() const {
return Type;
}