forked from kn0w0n3/Super_Mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflower.cpp
84 lines (64 loc) · 1.86 KB
/
flower.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
/*
* Author: equati0n
* Date: December 2016
*/
#include "flower.h"
#include "firemario.h"
#include "player.h"
#include "smallmario.h"
#include <QPainter>
#include <QDebug>
Flower::Flower(QRectF platformRect, int direction,QGraphicsItem *parent): QGraphicsItem(parent),mCurrentFrame(),mPlatform(platformRect), mDirection(direction)
{
setFlag(ItemClipsToShape);
mPixmap = QPixmap(":images/flower.png");
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(nextFrame()));
timer->start(100);
up= true;
down = true;
right = true;
right2 = false;
}
void Flower::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;
}
}
//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)){
emit marioSizeStatusf(4);
delete colliding_items[i];
delete this;
return;
}
}
for (int i = 0, n = colliding_items.size(); i < n; ++i){
if (typeid(*(colliding_items[i])) == typeid(FireMario)){
emit marioSizeStatusf(5);
//delete colliding_items[i];
delete this;
return;
}
}
}
QRectF Flower::boundingRect() const {
return QRectF(0,0,70,50);
}
void Flower::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 Flower::type() const {
return Type;
}