Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Created April 7, 2020 18:01
Show Gist options
  • Save jbobrow/4ad453c2967db758e9015c3ca70a9ef3 to your computer and use it in GitHub Desktop.
Save jbobrow/4ad453c2967db758e9015c3ca70a9ef3 to your computer and use it in GitHub Desktop.
/*
PIRATES 'N' LASERS
Animation Prototype
Lasers
1. Dim Ships Status (Fade to Black)
2. Instant redline w/ exposure flash (Simultaneous w/ Dimming)
3. Step by step explosions @ 400ms per segment
4. Fade up the status of the ship
5. Fade a single health to black.
by Jonathan Bobrow
03.14.2020
*/
#define MAX_HEALTH 5
enum Mode {
SHIP,
LASER,
NUM_MODES
};
byte mode = SHIP;
byte health = 5;
byte actionFace = 0;
word duration = 400;
Timer attackAniTimer;
byte segment = 0;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
if (buttonLongPressed()) {
mode = (mode + 1) % NUM_MODES;
}
if (buttonSingleClicked()) {
attackAniTimer.set(duration);
segment = 0;
}
if (buttonDoubleClicked()) {
duration -= 50;
if (duration < 200) {
duration = 400;
}
}
if (mode == SHIP) {
setColor(OFF);
if (!attackAniTimer.isExpired()) {
if (segment < 4 ) {
long progress = attackAniTimer.getRemaining();
byte brightness = map(progress, 0, duration, 0, 255);
switch (segment) {
case 0:
setColorOnFace(dim(ORANGE, brightness), 0);
break;
case 1:
setColorOnFace(dim(ORANGE, brightness), 1);
setColorOnFace(dim(ORANGE, brightness), 5);
break;
case 2:
setColorOnFace(dim(ORANGE, brightness), 2);
setColorOnFace(dim(ORANGE, brightness), 4);
break;
case 3:
setColorOnFace(dim(ORANGE, brightness), 3);
break;
default:
setColor(OFF);
break;
}
}
}
else {
segment++;
attackAniTimer.set(duration);
}
}
else if (mode == LASER) {
setColor(RED);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment