-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyTextures.cpp
More file actions
72 lines (62 loc) · 2.2 KB
/
EnemyTextures.cpp
File metadata and controls
72 lines (62 loc) · 2.2 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
#include "EnemyTextures.h"
#include <string.h>
#include "SGF/Color565.h"
#include "SGF/Math.h"
#include "Textures.h"
#include "Enemy.h"
namespace {
uint16_t applyAttackTint(uint16_t color565) {
uint8_t r5 = (color565 >> 11) & 0x1F;
uint8_t g6 = (color565 >> 5) & 0x3F;
uint8_t b5 = color565 & 0x1F;
uint8_t r = (r5 * 255) / 31;
uint8_t g = (g6 * 255) / 63;
uint8_t b = (b5 * 255) / 31;
r = Math::clamp(r + 56, 0, 255);
g = (g * 3) / 4;
b = (b * 3) / 4;
return Color565::rgb(r, g, b);
}
} // namespace
namespace EnemyTextures {
void build(const Enemy& enemy, uint16_t* outTexture, uint32_t nowMs) {
const char* textureName = enemy.isAlive()
? enemy.aliveTextureName
: enemy.deadTextureName;
const uint16_t* bmpTexture = Textures::pixels(textureName);
if (bmpTexture != nullptr) {
memcpy(outTexture, bmpTexture, Enemy::TEX_SIZE * Enemy::TEX_SIZE * sizeof(uint16_t));
if (enemy.isAlive() && enemy.isAttacking(nowMs)) {
for (int i = 0; i < Enemy::TEX_SIZE * Enemy::TEX_SIZE; i++) {
if (outTexture[i] != 0) {
outTexture[i] = applyAttackTint(outTexture[i]);
}
}
}
return;
}
for (int texY = 0; texY < Enemy::TEX_SIZE; texY++) {
for (int texX = 0; texX < Enemy::TEX_SIZE; texX++) {
if (!enemy.isAlive()) {
bool body =
(texY >= 8 && texY <= 11 && texX >= 2 && texX <= 13) ||
(texY >= 11 && texY <= 13 && texX >= 4 && texX <= 11) ||
(texY == 7 && texX >= 4 && texX <= 6);
bool head = (texY >= 6 && texY <= 8 && texX >= 11 && texX <= 13);
bool blood = (texY == 12 && texX >= 11 && texX <= 13);
if (blood) {
outTexture[texY * Enemy::TEX_SIZE + texX] = Color565::rgb(132, 28, 20);
} else if (head) {
outTexture[texY * Enemy::TEX_SIZE + texX] = Color565::rgb(118, 152, 98);
} else if (body) {
outTexture[texY * Enemy::TEX_SIZE + texX] = Color565::rgb(74, 92, 122);
} else {
outTexture[texY * Enemy::TEX_SIZE + texX] = 0;
}
} else {
outTexture[texY * Enemy::TEX_SIZE + texX] = enemy.texel(texX, texY, nowMs);
}
}
}
}
} // namespace EnemyTextures