-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWalls.cpp
More file actions
115 lines (100 loc) · 2.8 KB
/
Walls.cpp
File metadata and controls
115 lines (100 loc) · 2.8 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "Walls.h"
#include <stdlib.h>
#include "Door.h"
#include "SGF/Color565.h"
namespace Walls {
namespace {
constexpr Definition WALLS[] = {
{1, "wall_red"},
{2, "wall_green"},
{3, "wall_skull"},
{4, "wall_gold"},
{5, "wall_purple"},
{6, "wall_cyan"},
{7, "wall_brown"},
{8, "wall_pink"},
{9, "wall_white"},
};
uint16_t fallbackColor(uint8_t tile) {
switch (tile) {
case 1: return Color565::rgb(220, 78, 52);
case 2: return Color565::rgb(72, 208, 92);
case 3: return Color565::rgb(126, 126, 138);
case 4: return Color565::rgb(236, 192, 52);
case 5: return Color565::rgb(204, 72, 216);
case 6: return Color565::rgb(48, 212, 224);
case 7: return Color565::rgb(216, 116, 44);
case 8: return Color565::rgb(248, 52, 136);
case 9: return Color565::rgb(248, 248, 248);
default: return Color565::rgb(255, 255, 255);
}
}
uint16_t fallbackTexel(uint8_t tile, int texX, int texY) {
uint16_t base = fallbackColor(tile);
uint16_t dark = Color565::darken(base);
uint16_t light = Color565::lighten(base);
bool edge = (texX == 0 || texY == 0 || texX == TEX_SIZE - 1 || texY == TEX_SIZE - 1);
bool mortar = ((texX % 8) == 0) || ((texY % 8) == 0);
bool stripe = ((texX / 3) % 2) == 0;
bool checker = (((texX / 4) + (texY / 4)) % 2) == 0;
bool diamond = abs(texX - 8) + abs(texY - 8) < 5;
bool slit = (texX > 5 && texX < 10 && texY > 2 && texY < 13);
switch (tile) {
case 1:
return (edge || mortar) ? dark : base;
case 2:
if (edge) {
return dark;
}
return stripe ? light : base;
case 3:
return edge ? dark : base;
case 4:
if (edge || ((texY % 5) == 0)) {
return dark;
}
return ((texX % 5) == 0) ? light : base;
case 5:
return edge ? dark : (diamond ? light : base);
case 6:
if (edge || slit) {
return dark;
}
return (texY < 3 || texY > 12) ? light : base;
case 7:
if (edge) {
return dark;
}
return ((texX + texY) % 6) < 3 ? base : light;
case 8:
if (edge) {
return dark;
}
return ((texX - texY + TEX_SIZE) % 6) < 3 ? light : base;
case 9:
return (edge || checker) ? dark : light;
default:
return base;
}
}
}
const Definition* definition(uint8_t tile) {
for (unsigned i = 0; i < (sizeof(WALLS) / sizeof(WALLS[0])); i++) {
if (WALLS[i].tile == tile) {
return &WALLS[i];
}
}
return 0;
}
const char* textureName(uint8_t tile) {
const Definition* def = definition(tile);
return def ? def->textureName : 0;
}
uint16_t texel(uint8_t tile, int texX, int texY) {
if (Door::isTile(tile)) {
return Door::texel(tile, texX, texY);
}
uint16_t fallback565 = fallbackTexel(tile, texX, texY);
return Textures::texel(textureName(tile), texX, texY, fallback565);
}
}