forked from OneLoneCoder/Javidx9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OneLoneCoder_Matrix.cpp
163 lines (130 loc) · 3.61 KB
/
OneLoneCoder_Matrix.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
OneLoneCoder.com - Programming The Matrix
"Ribbet" - @Javidx9
License
~~~~~~~
Copyright (C) 2018 Javidx9
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; See license for details.
Original works located at:
https://www.github.com/onelonecoder
https://www.onelonecoder.com
https://www.youtube.com/javidx9
GNU GPLv3
https://github.com/OneLoneCoder/videos/blob/master/LICENSE
From Javidx9 :)
~~~~~~~~~~~~~~~
Hello! Ultimately I don't care what you use this for. It's intended to be
educational, and perhaps to the oddly minded - a little bit of fun.
Please hack this, change it and use it in any way you see fit. You acknowledge
that I am not responsible for anything bad that happens as a result of
your actions. However this code is protected by GNU GPLv3, see the license in the
github repo. This means you must attribute me if you use it. You can view this
license here: https://github.com/OneLoneCoder/videos/blob/master/LICENSE
Cheers!
Background
~~~~~~~~~~
I hit 0x1FF subscribers, so celebrated with a live stream!
Controls
~~~~~~~~
None, just spot the blonde, brunette, etc, etc...
Author
~~~~~~
Twitter: @javidx9
Blog: www.onelonecoder.com
Video:
~~~~~~
https://youtu.be/s7EbrvA188A
Last Updated: 17/09/2017
*/
#include <iostream>
#include <string>
using namespace std;
#include "olcConsoleGameEngine.h"
class OneLoneCoder_Matrix : public olcConsoleGameEngine
{
public:
OneLoneCoder_Matrix()
{
m_sAppName = L"Matrix";
}
private:
struct sStreamer
{
int nColumn = 0;
float fPosition = 0;
float fSpeed = 0;
wstring sText;
};
list<sStreamer> listStreamers;
int nMaxStreamers = 300;
wchar_t RandomCharacter()
{
return (wchar_t)(rand() % 0x1EF + 0x00C0);
return (wchar_t)(rand() % 93 + 33); // Random ASCII
}
void PrepareStreamer(sStreamer *s)
{
s->nColumn = rand() % ScreenWidth();
s->fPosition = 0;
s->fSpeed = rand() % 40 + 5;
s->sText.clear();
int nStreamerLength = rand() % 80 + 10;
for (int i = 0; i < nStreamerLength; i++)
s->sText.append(1, RandomCharacter());
//s->sText = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
protected:
// Called by olcConsoleGameEngine
virtual bool OnUserCreate()
{
for (int n = 0; n < nMaxStreamers; n++)
{
sStreamer s;
PrepareStreamer(&s);
listStreamers.push_back(s);
}
return true;
}
// Called by olcConsoleGameEngine
virtual bool OnUserUpdate(float fElapsedTime)
{
// Clear Screen
Fill(0, 0, ScreenWidth(), ScreenHeight(), PIXEL_SOLID, 0);
for (auto &s : listStreamers)
{
s.fPosition += fElapsedTime * s.fSpeed;
for (int i = 0; i < s.sText.size(); i++)
{
// If you hate ternary operators do this
// start ->
short col = s.fSpeed < 15.0f ? FG_DARK_GREEN : FG_GREEN; // ;-)
if (i == 0)
col = FG_WHITE;
else
if (i <= 3)
col = FG_GREY;
int nCharIndex = (i - (int)s.fPosition) % s.sText.size();
Draw(s.nColumn, (int)s.fPosition - i, s.sText[nCharIndex], col);
// <- end
// If you like them, do this!
//Draw(s.nColumn, (int)s.fPosition - i, s.sText[(abs(i - (int)s.fPosition) % s.sText.size())], i == 0 ? FG_WHITE : i<=3 ? FG_GREY: i>=s.sText.size()-2 || s.fSpeed < 15.0f? FG_DARK_GREEN: FG_GREEN);
// Missed this out on live stream, occasionally glitch a character
if (rand() % 1000 < 5)
s.sText[i] = RandomCharacter();
}
if ( s.fPosition - s.sText.size() >= ScreenHeight())
PrepareStreamer(&s);
}
return true;
}
};
int main()
{
// Use olcConsoleGameEngine derived app
OneLoneCoder_Matrix game;
game.ConstructConsole(128, 80, 12, 12);
game.Start();
return 0;
}