forked from capocattiveria/Super_mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrokenBlock.cpp
97 lines (84 loc) · 2.31 KB
/
BrokenBlock.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
#include "BrokenBlock.h"
#include "Sprites.h"
BrokenBlock::BrokenBlock(QPointF _pos, Direction _dir, bool _big_jump) : Entity()
{
setPos(_pos);
dir = _dir;
setZValue(3);
big_jump = _big_jump;
falling = false;
moving_speed_div = 3;
duration = 28;
texture_broken[0] = Sprites::instance()->get("broken-block");
texture_broken[0].setMask(texture_broken[0].createMaskFromColor(QColor(224, 163, 216)));
texture_broken[1] = texture_broken[0].transformed(QTransform().scale(-1, 1));
setPixmap(texture_broken[0]);
collidable = false;
}
void BrokenBlock::animate()
{
Entity::animate();
setPixmap(texture_broken[(animation_counter / 20) % 2]);
}
void BrokenBlock::advance()
{
//each brokenblock describes jump trajectory,
//two of these brokenblock do a small jump, others a big jump
if (dir == RIGHT)
setX(x() + animation_counter % 2);
else
setX(x() - animation_counter % 2);
if (animation_counter <= duration) {
setY(y() - moving_speed);
if (animation_counter < duration / 4)
{
if (!big_jump)
moving_speed = 3;
else
moving_speed = 9;
}
if (animation_counter > duration / 4 && animation_counter < 2 * duration / 4)
{
if (!big_jump)
moving_speed = 2;
else
moving_speed = 6;
}
if (animation_counter > 2 * duration / 4 && animation_counter < 3 * duration / 4)
{
if (!big_jump)
moving_speed = 1;
else
moving_speed = 3;
}
if (animation_counter > 3 * duration / 4 && animation_counter < 4 * duration / 4)
{
if (!big_jump)
moving_speed_div = 2;
else
moving_speed_div = 4;
moving_speed = animation_counter % moving_speed_div == 0;
}
}
else if (animation_counter > duration)
{
setY(y() + moving_speed);
if (animation_counter < duration + duration / 5)
{
moving_speed_div = 2;
moving_speed = animation_counter % moving_speed_div == 0;
}
if (animation_counter > duration + duration / 4 && animation_counter < duration + 2 * duration / 4)
{
moving_speed = 1;
}
if (animation_counter > duration + 2 * duration / 4 && animation_counter < duration + 3 * duration / 4)
{
moving_speed = 2;
}
if (animation_counter > duration + 3 * duration / 4 && animation_counter < duration + 4 * duration / 4)
{
moving_speed = 3;
}
}
}