Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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());
- }
- protected:
- virtual bool OnUserCreate()
- {
- for (int n = 0; n < nMaxStreamers; n++)
- {
- sStreamer s;
- PrepareStreamer(&s);
- listStreamers.push_back(s);
- }
- return true;
- }
- virtual bool OnUserUpdate(float fElapsedTime)
- {
- 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++)
- {
- 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);
- if (rand() % 1000 < 5)
- s.sText[i] = RandomCharacter();
- }
- if (s.fPosition - s.sText.size() >= ScreenHeight())
- PrepareStreamer(&s);
- }
- return true;
- }
- };
- int main()
- {
- OneLoneCoder_Matrix game;
- game.ConstructConsole(128, 80, 12, 12);
- game.Start();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement