-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlab.cpp
More file actions
74 lines (49 loc) · 1.44 KB
/
Slab.cpp
File metadata and controls
74 lines (49 loc) · 1.44 KB
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
#include "Definitions.h"
Slab::Slab(TypeSlab type, uint32_t* sprites) {
ts = type;
//asignment of internal pointers from the pointer containing the different sprites
DIAMOND_SPRITE = sprites + (BLOCK_WIDTH * 9); //add (BLOCK_WIDTH * 9) to point to the diamond sprite
CONCRETE_SPRITE_1 = sprites + (BLOCK_WIDTH * 6); //add (BLOCK_WIDTH * 6) to point to the concrete sprite
CONCRETE_SPRITE_2 = CONCRETE_SPRITE_1 + BLOCK_WIDTH;
CONCRETE_SPRITE_3 = CONCRETE_SPRITE_2 + BLOCK_WIDTH;
WOOD_SPRITE_1 = sprites + (BLOCK_WIDTH * 3); //add (BLOCK_WIDTH * 3) to point to the wood sprite
WOOD_SPRITE_2 = WOOD_SPRITE_1 + BLOCK_WIDTH;
//setting the sprite based on type
switch (ts) {
case TypeSlab::DIAMOND:
sprite = DIAMOND_SPRITE;
hitpoints = 1;
break;
case TypeSlab::CONCRETE:
sprite = CONCRETE_SPRITE_1;
hitpoints = 100;
break;
case TypeSlab::WOOD:
sprite = WOOD_SPRITE_1;
hitpoints = 50;
break;
default:
sprite = DIAMOND_SPRITE;
hitpoints = 1;
break;
}
}
void Slab::absorbDamage(int damage) {
if (ts != TypeSlab::DIAMOND) {
//updating the hitpoints
hitpoints = hitpoints - damage;
//updating the sprite
if (ts == TypeSlab::CONCRETE) {
if ((hitpoints <= 75) && (hitpoints > 50))
sprite = CONCRETE_SPRITE_2;
else if (hitpoints <= 50)
sprite = CONCRETE_SPRITE_3;
}
else if (ts == TypeSlab::WOOD) {
if (hitpoints <= 25)
sprite = WOOD_SPRITE_2;
}
}
}
Slab::~Slab() {
}