forked from capocattiveria/Super_mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlower.cpp
79 lines (67 loc) · 1.43 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
#include "Mario.h"
#include "Sounds.h"
#include "Flower.h"
#include "Sprites.h"
#include <iostream>
Flower::Flower(QPoint position, Direction _dir) : Collectable(position)
{
// set attributes
dir = _dir;
type = FLOWER;
// set texture and position
setPixmap(Sprites::instance()->get("flower"));
setPos(position);
setZValue(1);
// play mushroom sound
Sounds::instance()->play("spawn");
}
void Flower::animate()
{
Entity::animate();
}
void Flower::hit(Object* what, Direction fromDir)
{
Object::hit(what, fromDir);
// if hit by Mario, Mario eats flower and flower dies
Mario* mario = dynamic_cast<Mario*>(what);
if (mario)
{
mario->powerUp(FLOWER);
mario->updateScore(1000, pos().toPoint());
die();
return;
}
Inert* inert_obj = dynamic_cast<Inert*>(what);
if (inert_obj && fromDir == DOWN)
walkable_object = inert_obj;
}
void Flower::advance()
{
//raising phase from the block
if (dir == UP)
{
collidable = true;
setY(y() - moving_speed);
if (y() == spawned_position.y() - pixmap().height())
{
falling = true;
slow = false;
moving = false;
}
}
//falling phase from the block
if (dir == DOWN)
{
slow = false;
falling = true;
falling_speed = 2;
if (y() >= spawned_position.y() + pixmap().height() + 16) {
collidable = true;
}
if (walkable_object)
{
moving = false;
}
}
Entity::advance();
}