-
Notifications
You must be signed in to change notification settings - Fork 1
/
scroller.cpp
90 lines (76 loc) · 2.3 KB
/
scroller.cpp
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
#include "scroller.hpp"
ScrollerData *scrollerData = nullptr;
bool processScrollerInput(GameBuff *gameBuff)
{
return gameBuff->playerKeys.a && gameBuff->playerKeys.b;
}
bool displayScroller(GameBuff *gameBuff)
{
scrollerData->line = scrollerData->firstLine;
for (int textline = 0; textline < textlines; textline++)
{
if (scrollerData->line > -16 && scrollerData->line < gameBuff->HEIGHT + 16)
{
if (scrollerData->line < 80)
{
drawString2x(gameBuff, scrollerData->scrollerText[textline], 0, scrollerData->line, MakeColor((scrollerData->line + 80) / 32, (scrollerData->line + 120) / 32, (scrollerData->line + 80) / 64), 0x00);
}
else
{
drawString2x(gameBuff, scrollerData->scrollerText[textline], 0, scrollerData->line, 0xff, 0x00);
}
}
scrollerData->line += 16;
}
scrollerData->firstLine--;
if (scrollerData->line < 0)
return true;
return false;
}
void scrollerInit(GameBuff *gameBuff)
{
if (scrollerData == nullptr)
{
scrollerData = new ScrollerData();
}
scrollerData->exitscroller = false;
scrollerData->firstLine = gameBuff->HEIGHT;
scrollerData->firstScrollRun = true;
scrollerData->startScrollTime = gameBuff->timeInMillis;
scrollerData->currentScrollTime = gameBuff->timeInMillis;
}
void scrollerSetString(char newlines[textlines][16])
{
for (int line = 0; line < textlines; line++)
{
sprintf(scrollerData->scrollerText[line], "%s", newlines[line]);
}
}
void deInitScroller()
{
if (scrollerData != nullptr)
{
free(scrollerData);
scrollerData = nullptr;
}
}
bool scrollerLoop(GameBuff *gameBuff)
{
displayClear(gameBuff, 0x00);
if (scrollerData == nullptr || scrollerData->firstScrollRun)
{
scrollerInit(gameBuff);
scrollerData->firstScrollRun = false;
}
if (processScrollerInput(gameBuff))
scrollerData->exitscroller = true;
;
if (displayScroller(gameBuff))
scrollerData->exitscroller = true;
if (scrollerData->exitscroller)
{
deInitScroller();
return true;
}
return false; // Not done
}