-
Notifications
You must be signed in to change notification settings - Fork 2
/
Muncher.cpp
57 lines (50 loc) · 1.18 KB
/
Muncher.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
#include "Muncher.h"
#include "Sprites.h"
#include "Game.h"
#include "SwitchBlock.h"
Muncher::Muncher(QPoint position) : Enemy()
{
// flags
moving = false;
// textures
texture_animation[0] = Sprites::instance()->get("muncher-0");
texture_animation[1] = Sprites::instance()->get("muncher-1");
texture_animation[2] = Sprites::instance()->get("muncher-2");
// make background color (224, 163, 216) transparent
for (int i = 0; i < 3; i++)
texture_animation[i].setMask(texture_animation[i].createMaskFromColor(QColor(224, 163, 216)));
temp_coin = nullptr;
setPixmap(texture_animation[0]);
setPos(position);
}
void Muncher::animate()
{
//muncher disappear when bottom is pushed,coins appear
if (SwitchBlock::SwitchEffect())
{
if (!temp_coin)
{
collidable = false;
hide();
temp_coin = new Coin(QPoint(pos().toPoint()));
}
if (temp_coin->isDead())
die();
}
else
{
//coins die if not taken by mario
if (!isVisible())
{
collidable = true;
setVisible(true);
temp_coin->die();
}
setPixmap(texture_animation[(animation_counter++ / 8) % 3]);
}
}
void Muncher::die()
{
if (!dead)
dead = true;
}