Stop letting scores go negative

This commit is contained in:
Neale Pickett 2014-02-02 10:05:50 -07:00
parent ce4c886008
commit 97a5c2cebe
1 changed files with 6 additions and 4 deletions

10
main.c
View File

@ -23,8 +23,8 @@ volatile bool tick = false; // Set high when jiffy clock ticks
// Clocks are in deciseconds // Clocks are in deciseconds
uint16_t score_a = 0; int16_t score_a = 0;
uint16_t score_b = 0; int16_t score_b = 0;
int16_t period_clock = -(30 * 60 * 10); int16_t period_clock = -(30 * 60 * 10);
int16_t jam_duration = -(2 * 60 * 10); int16_t jam_duration = -(2 * 60 * 10);
int16_t lineup_duration = (-30 * 10); int16_t lineup_duration = (-30 * 10);
@ -76,6 +76,8 @@ const uint8_t indicator[] = {
0x00, 0x63, 0x0b, 0x0f, 0x04 0x00, 0x63, 0x0b, 0x0f, 0x04
}; };
#define max(a, b) ((a)>(b)?(a):(b))
void void
latch() latch()
{ {
@ -301,11 +303,11 @@ update_controller()
} }
if (pressed & BTN_LEFT) { if (pressed & BTN_LEFT) {
score_a += inc; score_a = max(score_a + inc, 0);
} }
if (pressed & BTN_RIGHT) { if (pressed & BTN_RIGHT) {
score_b += inc; score_b = max(score_b + inc, 0);
} }
} }