-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPiranhaFire.cpp
111 lines (85 loc) · 2.36 KB
/
PiranhaFire.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
102
103
104
105
106
107
108
109
110
111
#include "PiranhaFire.h"
#include "Mario.h"
#include "Sprites.h"
#include "Sounds.h"
#include "Game.h"
#include <iostream>
PiranhaFire::PiranhaFire(QPoint position, Direction direction) : Plant()
{
in_counter = 0;
out_counter = 0;
in = true;
falling_counter = 0;
jump_counter = 0;
angle = 30;
pos_in = position;
dir = direction;
// textures
texture_crunch_up[0] = Sprites::instance()->get("plant-fire-up-0");
texture_crunch_up[1] = Sprites::instance()->get("plant-fire-up-1");
texture_crunch_down[0] = Sprites::instance()->get("plant-fire-down-0");
texture_crunch_down[1] = Sprites::instance()->get("plant-fire-down-1");
setPixmap(texture_crunch_up[0]);
setPos(position - QPoint(0, pixmap().height()));
setZValue(2);
}
void PiranhaFire::advance()
{
if(dying)
return;
Plant::advance();
if(mario !=nullptr)
{
//depending from mario's position, plant shoots fireballs with different angles and directions
if (mario->pos().y() <= pos().y() - 10)
angle = 30;
else if (mario->pos().y() <= pos().y() + 10)
angle = -30;
else
angle = -45;
if (mario->pos().x() >= pos().x() + boundingRect().width() / 2)
dir = RIGHT;
else
dir = LEFT;
}
//shooting fireballs at regular intervals
if (in_counter == 66)
fire = new FireBallPiranha(pos().toPoint() + QPoint(0, 12), dir, angle);
if (in_counter == 133)
fire = new FireBallPiranha(pos().toPoint() + QPoint(0, 12), dir, angle);
}
void PiranhaFire::animate()
{
Entity::animate();
if(dying)
{
Plant::animate();
return;
}
//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();
//set the proper texture
if(angle==30)
{
setPixmap(texture_crunch_up[(animation_counter / 20) % 2]);
}
else
setPixmap(texture_crunch_down[(animation_counter / 20) % 2]);
//mirror texture when dir is RIGHT
if(dir==RIGHT)
setPixmap(pixmap().transformed(QTransform().scale(-1, 1)));
}
void PiranhaFire::hit(Object* what, Direction fromDir)
{
Object::hit(what, fromDir);
}
void PiranhaFire::hurt()
{
Sounds::instance()->play("stomp");
//update score of mario and begins to die
mario->updateScore(100, pos().toPoint());
dying = true;
moving = false;
}