-
Notifications
You must be signed in to change notification settings - Fork 6
/
asciiSprite.d
78 lines (57 loc) · 1.06 KB
/
asciiSprite.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
module asciiSprite;
import tango.stdc.stringz;
public import ncurses;
import tango.io.Stdout;
import tango.io.stream.TextFile;
class AsciiSprite {
int _x, _y;
char[][] _sprite;
bool _transparent;
WINDOW* _win;
this(){}
this(char[] filePath){
auto _spriteFile = new TextFileInput(filePath);
_x = 0;
_y = 0;
_transparent = false;
foreach(line; _spriteFile){
_sprite ~= line;
}
_spriteFile.close();
}
this(char[] filePath, WINDOW* win, bool transparent = false, int x=0, int y=0) {
auto _spriteFile = new TextFileInput(filePath);
_x = x;
_y = y;
_transparent = transparent;
foreach(line; _spriteFile){
_sprite ~= line;
}
_spriteFile.close();
}
void setXY(int x, int y){
_x = x;
_y = y;
}
void setY(int y){
_y = y;
}
void drawSprite() {
int y = _y;
int x = _x;
foreach(line; _sprite){
foreach(wchar chr; line){
move(y,x);
if((chr != ' ' && chr != '$') || !_transparent){
addch(chr);
}
if(chr == '$'){
addch(' ');
}
x++;
}
x = _x;
y++;
}
}
}