-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFireBall.cpp
129 lines (106 loc) · 2.87 KB
/
FireBall.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "FireBall.h"
#include "Sprites.h"
#include <iostream>
#include "Iceberg.h"
#include "BlooberBaby.h"
FireBall::FireBall(QPoint position, Direction direction) {
//set default flags
script_move = false;
moving = true;
dir = direction;
moving_speed = 2;
// set durations
death_duration = 15;
// textures
texture[0] = Sprites::instance()->get("fire-ball-left-0");
texture[1] = Sprites::instance()->get("fire-ball-left-1");
texture[2] = Sprites::instance()->get("fire-ball-left-2");
texture[3] = Sprites::instance()->get("fire-ball-left-3");
texture_dying[0] = Sprites::instance()->get("boom-0");
texture_dying[1] = Sprites::instance()->get("boom-1");
texture_dying[2] = Sprites::instance()->get("boom-2");
setPixmap(texture[0]);
setPos(position - QPoint(0, pixmap().height()));
setZValue(2);
}
void FireBall::animate()
{
Entity::animate();
if (!dying)
{
if (dir == LEFT)
setPixmap(texture[(animation_counter / 10) % 4]);
else if (dir == RIGHT)
setPixmap(texture[(animation_counter / 10) % 4].transformed(QTransform().scale(-1, 1)));
}
else
setPixmap(texture_dying[(death_counter / 5) % 3]);
}
void FireBall::advance()
{
//fire ball shoot by mario
//don't advance when dying or freezed
if (freezed || dying)
return;
//start jumping when hit with walkable_object
if (walkable_object)
{
jumping = true;
walkable_object = nullptr;
}
//different physic parameter between horizontal walkable_object
//and uphill or downhill walkable_object
if (script_move)
{
jumping_duration = 80;
moving_speed = 2;
}
else
{
jumping_duration = 20;
moving_speed = 3;
}
//set the proper speed during the jumping
if (jumping)
{
if (jump_counter <= jumping_duration / 2)
jumping_speed = 3;
else if (jump_counter > jumping_duration / 2 && jump_counter < jumping_duration - 4)
jumping_speed = 2;
else
jumping_speed = 1;
}
//set the proper falling_speed during the falling
if (falling)
{
if (falling_counter < 2)
falling_speed = 1;
else if (falling_counter >= 2 && falling_counter < 6)
falling_speed = 2;
else
falling_speed = 3;
}
Entity::advance();
}
void FireBall::hit(Object* what, Direction fromDir)
{
//dying when hit with other fireball
if (dynamic_cast<FireBall*>(what))
dying = true;
//hurt enemy when hitted and die
Enemy* enemy = dynamic_cast<Enemy*>(what);
if (dynamic_cast<Enemy*>(what) )
{
dying = true;
enemy->hurt();
return;
}
//when hit from right or left, then die
if ((dynamic_cast<Inert*>(what) && (fromDir != DOWN && fromDir != UNDETERMINED && fromDir != UP && fromDir !=UNKNOWN)) || dynamic_cast<Enemy*>(what))
dying = true;
//when hit with downhill or uphill, paramenters will change
if (dynamic_cast<Iceberg*>(what) && ((dynamic_cast<Iceberg*>(what)->type() == "downhill") || dynamic_cast<Iceberg*>(what)->type() == "uphill"))
script_move = true;
else
script_move = false;
}