Matrix Wipe Effect on Splash

This commit is contained in:
2024-10-01 01:47:09 -04:00
parent b5f54831b2
commit 74a3bb7816
3 changed files with 67 additions and 39 deletions

View File

@@ -27,6 +27,13 @@ namespace CaveGame::Client
JGL::Texture splash;
JGL::Font font;
Vector2 window_size;
float increment = 0;
std::vector<float> scroll_offsets;
std::vector<std::vector<char>> matrix;
void DrawMatrix();
void DrawProgressBar();
};
}

View File

@@ -4,6 +4,55 @@
CaveGame::Client::Splash::Splash() : Scene()
{
font = JGL::Font();
J3ML::Algorithm::RNG rng;
for (int i = 0; i < 100; i++)
{
scroll_offsets.push_back(rng.Float(0, 300.5));
matrix.push_back(std::vector<char>());
for (int j = 0; j < 100; j++)
{
if (rng.FloatNeg1_1() > 0)
matrix[i].push_back('1');
else
matrix[i].push_back('0');
}
}
}
void CaveGame::Client::Splash::DrawMatrix()
{
for (int col = 0; col < 100; col++)
{
float scroll = (scroll_offsets[col] * load_percent);
for (int row = 0; row < 80; row++)
{
char elem = matrix[col][row];
Color4 text_col = Color4(32, 192, 92, 255 - (row*5));
JGL::J2D::DrawString(text_col, std::string(1, elem), (col*16), (row*16) + scroll, 1, 16, font);
}
}
}
void CaveGame::Client::Splash::DrawProgressBar()
{
auto screen_dimensions = window_size;
float bar_length = screen_dimensions.x-20;
float bar_height = 20;
float bar_pos_x = 10;
float bar_pos_y = (screen_dimensions.y-bar_height)-10;
Vector2 bar_pos = {bar_pos_x, bar_pos_y};
JGL::J2D::FillRect(Colors::Gray, bar_pos, {bar_length, bar_height});
float progress_bar_length = bar_length * load_percent;
JGL::J2D::FillRect(Colors::White, bar_pos, {progress_bar_length, bar_height});
}
void CaveGame::Client::Splash::Draw()
@@ -22,28 +71,13 @@ void CaveGame::Client::Splash::Draw()
// TODO: Implement draw-point offset to maintain sensible aspect ratio on the image.
JGL::J2D::Begin();
DrawMatrix();
JGL::J2D::DrawSprite(splash, {0, 0}, 0.f, {0, 0}, aspect);
DrawProgressBar();
Color4 text_col = {32, 192, 92};
for (int cols = 0; cols < (screen_dimensions.x / 16); cols++)
{
JGL::J2D::DrawString(text_col, "0", cols*16, 0, 1, 16, font);
}
float bar_length = screen_dimensions.x-20;
float bar_height = 20;
float bar_pos_x = 10;
float bar_pos_y = (screen_dimensions.y-bar_height)-10;
Vector2 bar_pos = {bar_pos_x, bar_pos_y};
JGL::J2D::FillRect(Colors::Gray, bar_pos, {bar_length, bar_height});
float progress_bar_length = bar_length * load_percent;
JGL::J2D::FillRect(Colors::White, bar_pos, {progress_bar_length, bar_height});
JGL::J2D::End();
}

View File

@@ -33,7 +33,7 @@ JGL::Font Jupiteroid;
float z = 0;
//Vector2 CaveGame::Client::Splash::window_size = {0, 0};
CaveGame::Client::Splash* splash;
class CaveGameWindow : public ReWindow::RWindow
{
@@ -151,6 +151,9 @@ public:
if (current_scene != nullptr)
current_scene->Update(elapsed);
// Ugly temporary hack.
splash->PassWindowSize(getSize());
if (generate_grid) {
//if (frame_count % 2 == 0)
// procgen();
@@ -161,8 +164,6 @@ public:
std::this_thread::sleep_for(1ms);
}
//CaveGame::Client::Splash::window_size = getSize();
}
void display()
@@ -173,8 +174,6 @@ public:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//if (render_grid)
//draw_grid();
if (current_scene != nullptr)
current_scene->Draw();
@@ -213,7 +212,6 @@ public:
void OnRefresh(float elapsed) override
{
//auto begin_frame = std::chrono::high_resolution_clock::now();
update(elapsed);
display();
@@ -222,17 +220,6 @@ public:
std::cout << glError << std::endl;
glSwapBuffers();
//auto end_frame = std::chrono::high_resolution_clock::now();
//auto frame_time = end_frame - begin_frame;
//int frame_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(frame_time).count();
//float frame_time_s = frame_time_ms / 1000.f;
//delta_time = frame_time_s;
//frame_rate = 1.f / delta_time;
//frame_count++;
}
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent &ev) override
@@ -273,10 +260,10 @@ int main() {
window->setResizable(true);
window->setVsyncEnabled(false);
//auto* splash = new CaveGame::Client::Splash();
//splash->PassFont(Jupiteroid);
splash = new CaveGame::Client::Splash();
splash->PassFont(Jupiteroid);
window->ChangeScene(new CaveGame::Client::Splash());
window->ChangeScene(splash);
while (window->isAlive()) {
window->pollEvents();