forked from hotchk155/AVRGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.h
More file actions
117 lines (115 loc) · 3.13 KB
/
Menu.h
File metadata and controls
117 lines (115 loc) · 3.13 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
116
117
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////
/////////
///////// M E N U
/////////
/////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class CMenu : public CGame
{
char sel;
char offset;
char count;
public:
static void getGameIcon(byte *dst, byte count)
{
if(!isSoundOn())
{
dst[ 0] = 0b00000000;
dst[ 1] = 0b00000010;
dst[ 2] = 0b00000100;
dst[ 3] = 0b00001000;
dst[ 4] = 0b00010000;
dst[ 5] = 0b00100000;
dst[ 6] = 0b01000000;
dst[ 7] = 0b00000000;
}
dst[ 8] = 0b00000000;
dst[ 9] = 0b00000010;
dst[10] = 0b01110110;
dst[11] = 0b01011010;
dst[12] = 0b01011010;
dst[13] = 0b01110110;
dst[14] = 0b00000010;
dst[15] = 0b00000000;
}
void init()
{
sel = EEPROM.read(EEPROM_GAMESELECTED);
if(sel <= 0 || sel >= numGameFactories)
sel = 1;
offset = 0;
showIcon(0, 0);
Timer3Period = 100;
}
void showIcon(int ofs, byte count)
{
byte left[16];
byte right[16];
getMenuIcon(sel,left,count);
if(sel < numGameFactories-1)
getMenuIcon(sel+1, right, count);
else
getMenuIcon(0, right, count);
for(int i=0;i<8;++i)
{
Disp8x8.red[i] = (left[i]<<ofs) | right[i]>>(8-ofs);
Disp8x8.green[i] = (left[i+8]<<ofs) | right[i+8]>>(8-ofs);
}
}
void handleEvent(char event)
{
switch(event)
{
case EV_PRESS_C: // toggle
if(sel == 0)
{
setSoundOn(!isSoundOn());
}
else
{
setNextGame(sel);
}
break;
case EV_PRESS_B: // previous item
if(!Timer1Period && !Timer2Period)
{
if(--sel < 0) sel = numGameFactories - 1;
offset = 7;
Timer1Period = 50;
}
break;
case EV_PRESS_D: // next item
if(!Timer1Period && !Timer2Period)
{
offset = 0;
Timer2Period = 50;
}
break;
case EV_TIMER_1:
if(--offset <= 0)
{
Timer1Period = 0;
}
break;
case EV_TIMER_2:
if(++offset > 7)
{
if(++sel > numGameFactories-1)
sel = 0;
offset =0;
Timer2Period = 0;
}
break;
case EV_TIMER_3:
count++;
break;
}
showIcon(offset, count);
}
};
CGameFactoryImpl<CMenu> Menu;