forked from LindseyB/AsciiAsciiRevolution
-
Notifications
You must be signed in to change notification settings - Fork 1
/
selectScreen.d
104 lines (82 loc) · 1.69 KB
/
selectScreen.d
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
module selectScreen;
import tango.io.Stdout;
import tango.io.stream.TextFile;
import tango.util.Convert;
import tango.stdc.stringz;
import ncurses;
import level;
import asciiSprite;
class SelectScreen {
Level[] _levels;
int _selectedLevel = 0;
AsciiSprite _cron;
AsciiSprite _title;
AsciiSprite _selector;
bool _levelSelected = false;
this(char[] levelsPath) {
auto levelsFile = new TextFileInput(levelsPath);
char[] audio;
char[] name;
char[] arrowChart;
int difficulty = -1;
int i = 0;
foreach(line; levelsFile) {
if(i == 0) {
audio = line;
i++;
} else if(i == 1) {
name = line;
i++;
} else if(i == 2) {
difficulty = to!(int)(line);
i++;
} else if(i == 3) {
arrowChart = line;
i = 0;
Level l = new Level(audio, name, difficulty, arrowChart);
_levels ~= l;
} else {
// boo!
}
}
_cron = new AsciiSprite("graphics/cron-mini.txt");
_title = new AsciiSprite("graphics/level-select.txt");
_selector = new AsciiSprite("graphics/cron-selector.txt");
}
void down() {
_selectedLevel++;
if(_selectedLevel > _levels.length-1){
_selectedLevel = 0;
}
}
void up() {
_selectedLevel--;
if(_selectedLevel < 0){
_selectedLevel = _levels.length-1;
}
}
void selectLevel() {
_levelSelected = true;
}
void drawScreen() {
int y = 10;
int x = 0;
_title.drawSprite();
foreach(i,level; _levels){
move(y,x);
if(i == _selectedLevel){
_selector.setXY(0,y-1);
_selector.drawSprite();
}
x = 8;
move(y,x);
addstr(toStringz(level._name));
y++;
for(int j=0; j < level._difficulty; j++){
_cron.setXY(x+(j*4),y);
_cron.drawSprite();
}
y+=5;
}
}
}