-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldBackEarth.cpp
executable file
·91 lines (76 loc) · 1.77 KB
/
FieldBackEarth.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
#include "FieldBackEarth.h"
#include "main.h"
#include "FieldBackGrass.h"
#include "InventoryEarth.h"
FieldBackEarth::FieldBackEarth(void)
{
}
FieldBackEarth::~FieldBackEarth(void)
{
}
void FieldBackEarth::init(const int32_t &x, const int32_t &y)
{
FieldBack::init(x, y);
updateCounter = 0;
switch (myRand(x ^ (y<<2)) % 6)
{
case 0:
image = load_image("Background/Erze/Erde/Erde01.png");
break;
case 1:
image = load_image("Background/Erze/Erde/Erde02.png");
break;
case 2:
image = load_image("Background/Erze/Erde/Erde03.png");
break;
case 3:
image = load_image("Background/Erze/Erde/Erde04.png");
break;
case 4:
image = load_image("Background/Erze/Erde/Erde05.png");
break;
case 5:
image = load_image("Background/Erze/Erde/Erde06.png");
break;
}
}
void FieldBackEarth::myUpdate()
{
if (updateCounter > 2) {
unordered_map<int64_t, FieldBack*>::iterator backIt = world.mapBack.find(world.int64FromXY(xGridded, yGridded-1));
if (backIt != world.mapBack.end())
{
if (backIt->second == NULL)
{
removeFromMap();
FieldBackGrass* fieldBackGrass = new FieldBackGrass();
fieldBackGrass->init(xGridded*GRID_SIZE, yGridded*GRID_SIZE);
fieldBackGrass->health = health;
delete this;
return;
}
}
updateCounter = 0;
} else {
updateCounter += deltaTime;
}
}
void FieldBackEarth::onUsed(const ToolTypes &toolType, const int32_t &toolLevel)
{
if (toolType == appropriateTool)
{
health -= 2*toolLevel*deltaTime;
}
else
{
health -= toolLevel*deltaTime;
}
if (health <= 0)
{
InventoryObject* inventoryObject = new InventoryEarth(1);
world.player.inventory.add(inventoryObject);
removeFromMap();
delete this;
return;
}
}