forked from kn0w0n3/Super_Mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmushroom.cpp
103 lines (78 loc) · 2.34 KB
/
mushroom.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Author: equati0n
* Date: December 2016
*/
#include "mushroom.h"
#include "player.h"
#include "smallmario.h"
#include <QPainter>
#include <QDebug>
Mushroom::Mushroom(QRectF platformRect, int direction,QGraphicsItem *parent): QGraphicsItem(parent),mCurrentFrame(),mPlatform(platformRect), mDirection(direction)
{
setFlag(ItemClipsToShape);
mPixmap = QPixmap(":images/m40.png");
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(nextFrame()));
timer->start(100);
up= true;
down = true;
right = true;
right2 = false;
}
Mushroom::~Mushroom(){
}
void Mushroom::nextFrame(){
if(up) {
if(this->pos().y() > mPlatform.y()-40) {
setPos(this->pos().x(), this->pos().y() - (mDirection *5));
}
}
if(right){
if(this->pos().y() == mPlatform.y() -42) {
up = false;
setPos(this->pos().x() + (mDirection *5), this->pos().y());
}
}
if(down) {
if(this->pos().x() > mPlatform.x() + mPlatform.width()+20) {
right = false;
setPos(this->pos().x() , this->pos().y() + (mDirection *25));
}
}
if(this->pos().y() > 619) {
down =false;
setPos(this->pos().x() + (mDirection *5), 620);
}
//Collision Detection
QList<QGraphicsItem *> colliding_items = collidingItems();
for (int i = 0, n = colliding_items.size(); i < n; ++i){
if (typeid(*(colliding_items[i])) == typeid(Player)){
scene()->removeItem(this);
emit marioSizeStatus(3);
delete this;
return;
}
}
for (int i = 0, n = colliding_items.size(); i < n; ++i){
if (typeid(*(colliding_items[i])) == typeid(SmallMario)){
scene()->removeItem(colliding_items[i]);
scene()->removeItem(this);
emit marioSizeStatus(2);
delete colliding_items[i];
delete this;
return;
}
}
}
QRectF Mushroom::boundingRect() const {
return QRectF(0,0,70,50);
}
void Mushroom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->drawPixmap(0,0, mPixmap, mCurrentFrame, 0,70, 50);
setTransformOriginPoint(boundingRect().center());
Q_UNUSED(widget);
Q_UNUSED(option);
}
int Mushroom::type() const {
return Type;
}