forked from capocattiveria/Super_mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiranha.cpp
100 lines (77 loc) · 2.21 KB
/
Piranha.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
#include "Piranha.h"
#include "Mario.h"
#include "Sprites.h"
#include "Sounds.h"
#include "Game.h"
Piranha::Piranha(QPoint position, Direction direction, bool _red, bool _rotate) :Plant()
{
in_counter = 0;
out_counter = 0;
in = true;
falling_counter = 0;
jump_counter = 0;
// set attribute
rotate = _rotate;
red = _red;
pos_in = position;
dir = direction;
slow = true;
// textures
// there are different plants,green or red, rotated or not
if (!red && !rotate)
{
texture_crunch[0] = Sprites::instance()->get("green-plant-0");
texture_crunch[1] = Sprites::instance()->get("green-plant-1");
}
else if (red && !rotate)
{
texture_crunch[0] = Sprites::instance()->get("red-plant-0");
texture_crunch[1] = Sprites::instance()->get("red-plant-1");
}
else if (!red && rotate)
{
texture_crunch[0] = Sprites::instance()->get("green-plant-0").transformed(QTransform().scale(1, -1));
texture_crunch[1] = Sprites::instance()->get("green-plant-1").transformed(QTransform().scale(1, -1));
}
else if (red && rotate)
{
texture_crunch[0] = Sprites::instance()->get("red-plant-0").transformed(QTransform().scale(1, -1));
texture_crunch[1] = Sprites::instance()->get("red-plant-1").transformed(QTransform().scale(1, -1));
}
// set texture and correct y-coordinate w.r.t. texture height
setPixmap(texture_crunch[0]);
setPos(position - QPoint(0, pixmap().height()));
setZValue(2);
}
void Piranha::advance() {
if (dying)
return;
Plant::advance();
}
void Piranha::animate()
{
Entity::animate();
//after 1 frame plants get mario's address,
//otherwise mario points to null at starting of the game, and crash
if (animation_counter == 1)
mario = Game::instance()->getMario();
if (dying)
{
Plant::animate();
return;
}
setPixmap(texture_crunch[(animation_counter / animation_div) % 2]);
}
void Piranha::hit(Object* what, Direction fromDir)
{
Object::hit(what, fromDir);
}
void Piranha::hurt()
{
Sounds::instance()->play("stomp");
//update score of mario and begins to die
Mario* mario = Game::instance()->getMario();
mario->updateScore(100, pos().toPoint());
dying = true;
moving = false;
}