added pause functionality to snake

This commit is contained in:
2014-12-30 00:52:56 +01:00
parent d96c76f054
commit 36fd117508
10 changed files with 24 additions and 7 deletions
+3 -1
View File
@@ -289,7 +289,9 @@ void _lcd_write_byte(uint8_t bb)
/** Wait until the device is ready */
void _lcd_wait_bf()
{
while(lcd_read_bf_addr() & _BV(7));
uint8_t d = 0;
while(d++ < 120 && lcd_read_bf_addr() & _BV(7))
_delay_us(1);
}
View File
View File
+3 -1
View File
@@ -289,7 +289,9 @@ void _lcd_write_byte(uint8_t bb)
/** Wait until the device is ready */
void _lcd_wait_bf()
{
while(lcd_read_bf_addr() & _BV(7));
uint8_t d = 0;
while(d++ < 120 && lcd_read_bf_addr() & _BV(7))
_delay_us(1);
}
+18 -5
View File
@@ -28,7 +28,7 @@
#define BTN_RIGHT D3
#define BTN_UP D4
#define BTN_DOWN D5
#define BTN_SELECT D6
#define BTN_PAUSE D6
#define BTN_RESTART D7
// Debouncer channels for buttons
@@ -37,7 +37,7 @@
#define D_RIGHT 1
#define D_UP 2
#define D_DOWN 3
#define D_SELECT 4
#define D_PAUSE 4
#define D_RESTART 5
#define DEBO_CHANNELS 6
@@ -75,7 +75,7 @@ void SECTION(".init8") init()
as_input_pu(BTN_RIGHT);
as_input_pu(BTN_UP);
as_input_pu(BTN_DOWN);
as_input_pu(BTN_SELECT);
as_input_pu(BTN_PAUSE);
as_input_pu(BTN_RESTART);
// add buttons to debouncer
@@ -83,7 +83,7 @@ void SECTION(".init8") init()
debo_add_rev(BTN_RIGHT);
debo_add_rev(BTN_UP);
debo_add_rev(BTN_DOWN);
debo_add_rev(BTN_SELECT);
debo_add_rev(BTN_PAUSE);
debo_add_rev(BTN_RESTART);
// setup timer
@@ -256,6 +256,8 @@ void init_gameboard()
uint8_t presc = 0;
bool restart_held;
bool pause_held;
bool paused;
void update()
{
if (debo_get_pin(D_RESTART)) {
@@ -271,7 +273,18 @@ void update()
restart_held = false;
}
if(!crashed) {
if (debo_get_pin(D_PAUSE)) {
if (!pause_held) {
paused ^= true;
pause_held = true;
}
} else {
pause_held = false;
}
if(!crashed && !paused) {
// resolve movement direction
if (debo_get_pin(D_LEFT))