-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprite.cpp
77 lines (62 loc) · 2.56 KB
/
Sprite.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
/*
* Circles implementation for the GauntletII project.
*/
#include "Effect.h"
#define SPRITE_WIDTH 9
#define SPRITE_HEIGHT 9
static uint8_t heartData[SPRITE_WIDTH * SPRITE_HEIGHT] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static uint8_t ghostData[SPRITE_WIDTH * SPRITE_HEIGHT] = {
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF,
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
};
class Sprite : public Effect {
private:
int spriteWidth, spriteHeight;
public:
Sprite(CRGB *leds, int width, int height) : Effect(leds, width, height), spriteWidth(SPRITE_WIDTH), spriteHeight(SPRITE_HEIGHT) {
}
void start() {
for (int i = 0; i < 400; i++) {
if (random(100) > 98) {
blit(ghostData, 178, random(0, width - spriteWidth), random(0, height - spriteHeight));
} else {
blit(heartData, 0, random(0, width - spriteWidth), random(0, height - spriteHeight));
}
LEDS.show();
delay(100);
for (int i = 0; i < width * height; i++) {
leds[i].fadeToBlackBy(64);
}
}
}
void blit(uint8_t *sprite, uint8_t hue, int x, int y) {
uint8_t saturation = random(8, 16) * 16;
for (int spx = 0; spx < spriteWidth; spx++) {
for (int spy = 0; spy < spriteHeight; spy++) {
if (inXRange(spx + x) && inYRange(spy + y)) {
uint8_t spritePixel = sprite[spy * spriteHeight + spx];
if (spritePixel) {
pixel(spx + x, spy + y) = CHSV(hue, saturation, spritePixel);
}
}
}
}
}
};