forked from LindseyB/AsciiAsciiRevolution
-
Notifications
You must be signed in to change notification settings - Fork 1
/
animatedAsciiSprite.d
63 lines (49 loc) · 1.11 KB
/
animatedAsciiSprite.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
module animatedAsciiSprite;
import tango.io.Stdout;
import tango.io.stream.TextFile;
import tango.text.Util;
import asciiSprite;
class AnimatedAsciiSprite : AsciiSprite {
char[][][] _animation;
int _frame;
bool _loop;
bool _animate;
this(char[] filePath, WINDOW* win, bool transparent, bool loop, int x=0, int y=0){
_frame = 0;
auto _spriteFile = new TextFileInput(filePath);
super._x = x;
super._y = y;
super._win = win;
super._transparent = transparent;
_animate = true;
_loop = loop;
bool firstLine = true;
char[][] newFrame;
foreach(line; _spriteFile){
if(contains(line, '%')){
firstLine = true;
} else {
if(firstLine){
if(newFrame !is null){
_animation ~= newFrame;
}
firstLine = false;
newFrame = null;
}
newFrame ~= line;
}
}
_animation ~= newFrame;
super._sprite = _animation[0];
}
void nextFrame() {
if(_animate){
int before = ++_frame;
_frame %= _animation.length;
if(!_loop && before == _animation.length && _frame == 0){
_animate = false;
}
super._sprite = _animation[_frame];
}
}
}