-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhutrie.cpp
99 lines (82 loc) · 2.34 KB
/
hutrie.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
#include <string>
#include <sstream>
#include "hutrie.h"
#include "unit.h"
#include "sound.h"
#include "textures.h"
#include "gamebalance.h"
///////////////////////////CONSTRUCTOR/////////////////////////////////////////////////////////////////////////////////////
Hutrie::Hutrie(sf::RenderWindow* hutrieApplication, std::vector<Unit*> unitsFromGame, std::string pathName)
: MapObject(hutrieApplication, unitsFromGame, pathName),
hutrieThread(&Hutrie::moveHutrie, this)
{
title.text.setString("Hutrie:");
sprite.setPosition(6 * 64, 7 * 64);
sprite.setScale(0.64, 0.64);
transparentTexture.loadFromFile(Textures::transparent);
sound.openFromFile(Sound::hutrie);
sound.setVolume(GameBalance::sfxVolume);
busy = false;
pauseThread = false;
frameCounter = 0;
animationCounter = 0;
}
///////////////////////////MOVING TO SPECIFIC MOUSE DIRECTION/////////////////////////////////////////////////////////////////////////////////////
void Hutrie::toDirection(float targetX, float targetY)
{
while (sprite.getPosition().y < targetY)
{
if (pauseThread)
{
sf::sleep(sf::seconds(2));
};
sprite.move(0, 1);
animateTextureDown();
sf::sleep(sf::milliseconds(5));
};
animationCounter = 0;
while (sprite.getPosition().x < targetX)
{
if (pauseThread)
{
sf::sleep(sf::seconds(2));
};
animateTextureRight();
sprite.move(1, 0);
sf::sleep(sf::milliseconds(5));
};
animationCounter = 0;
while (sprite.getPosition().y > targetY)
{
if (pauseThread)
{
sf::sleep(sf::seconds(2));
};
animateTextureUp();
sprite.move(0, -1);
sf::sleep(sf::milliseconds(5));
};
animationCounter = 0;
while (sprite.getPosition().x > targetX)
{
if (pauseThread)
{
sf::sleep(sf::seconds(2));
};
animateTextureLeft();
sprite.move(-1, 0);
sf::sleep(sf::milliseconds(5));
};
animationCounter = 0;
}
void Hutrie::updateStatus()
{
std::ostringstream desc;
desc << "I'm ready for\n\taction!";
description.text.setString(desc.str());
}
void Hutrie::changeTexture(std::string path)
{
currentTexture.loadFromFile(path);
sprite.setTexture(currentTexture);
}