From 55204a5d0a990ff3375203c2ecdd62014f22c504 Mon Sep 17 00:00:00 2001 From: squishy Date: Sun, 31 Mar 2024 00:03:04 +0000 Subject: [PATCH] splashscreen fade --- blooblib/include/image.h | 6 ++++-- blooblib/src/draw/upscale.cpp | 3 ++- blooblib/src/game.cpp | 6 +++++- blooblib/src/image.cpp | 27 +++++++++++++++++++++++++++ test/test.cpp | 8 ++++---- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/blooblib/include/image.h b/blooblib/include/image.h index 1eb96b2..ca0961c 100644 --- a/blooblib/include/image.h +++ b/blooblib/include/image.h @@ -16,6 +16,9 @@ enum class upscaler { int upscaler_scale(upscaler upscaler); +std::tuple color_to_elements(color color); +color elements_to_color(double r, double g, double b, double a); + struct image : resource { image(resource_manager& rm, ini_category const* ini, std::string const& path, std::vector const& data); image(image const& other); @@ -32,19 +35,18 @@ struct image : resource { color get_safe(vec2i pos) const; void clear(color color); + void blend_to(color color, double amount); void draw(image const* image, vec2i pos); void draw(image const* image, vec2i pos, recti src_rect); void draw(image const* image, vec2i pos, color color); void draw(image const* image, vec2i pos, color color, recti src_rect); - //void draw_upscaled(image const* image); void draw_rot(image const* image, vec2i pos, double rot); void draw_rot(image const* image, vec2i pos, recti src_rect, double rot); void draw_upscaled(image const* image, upscaler upscaler); void draw_upscaled(image const* image, std::vector upscalers); - image const* upscale_eagle_2x() const; void draw(std::string const& str, vec2i pos, font const* font, color color); void draw(std::string const& str, vec2i pos, font const* font, color color1, color color2); diff --git a/blooblib/src/draw/upscale.cpp b/blooblib/src/draw/upscale.cpp index 53cab33..b8e4477 100644 --- a/blooblib/src/draw/upscale.cpp +++ b/blooblib/src/draw/upscale.cpp @@ -172,7 +172,7 @@ void image::draw_upscaled(image const* img, vec2i s, upscaler upscaler) { UPSCALE_3X_END } } - +/* image const* image::upscale_eagle_2x() const { auto img = new image(size() * 2); for(int y = 0; y < size().y; ++y) { @@ -197,3 +197,4 @@ image const* image::upscale_eagle_2x() const { } return img; } +*/ \ No newline at end of file diff --git a/blooblib/src/game.cpp b/blooblib/src/game.cpp index 13a3ffa..7e5ed14 100644 --- a/blooblib/src/game.cpp +++ b/blooblib/src/game.cpp @@ -188,8 +188,12 @@ void play_logo(HWND window, image const* logo, image const* logo_slime) { if(now - last_frame >= frame_duration) { screen.clear(0x242424); - screen.draw(logo, vec2i(0, min(-frames*16 + 2500, 0))); + screen.draw(logo, vec2i(0, min(-frames*12 + 1600, 0))); screen.draw(logo_slime, screen.size() - vec2i(34, 28)); + if(frames < 60 && frames >= 30) + screen.blend_to(0x0, 2.0 - (frames / 30.0)); + if(frames < 30) + screen.clear(0); auto p = screen.raw_pointer(); window_image.draw_upscaled(&screen, upscaler::scale3x); diff --git a/blooblib/src/image.cpp b/blooblib/src/image.cpp index 7a8c9e9..a7c3559 100644 --- a/blooblib/src/image.cpp +++ b/blooblib/src/image.cpp @@ -76,5 +76,32 @@ void image::clear(color color) { std::fill(_data, _data + size().size(), color); } +void image::blend_to(color color, double amount) { + auto bc = color_to_elements(color); + auto inv_amount = 1.0 - amount; + for(int i = 0; i < _bounds.size.size(); ++i) { + auto c = color_to_elements(_data[i]); + double r = inv_amount * std::get<0>(c) + amount * std::get<0>(bc); + double g = inv_amount * std::get<1>(c) + amount * std::get<1>(bc); + double b = inv_amount * std::get<2>(c) + amount * std::get<2>(bc); + double a = inv_amount * std::get<3>(c) + amount * std::get<3>(bc); + _data[i] = elements_to_color(r, g, b, a); + } +} +std::tuple color_to_elements(color color) { + double r = (color & 0x00ff0000) >> 16; + double g = (color & 0x0000ff00) >> 8; + double b = color & 0x000000ff; + double a = (color & 0xff000000) >> 24; + return std::make_tuple(r / 255.0, g / 255.0, b / 255.0, a / 255.0); +} + +color elements_to_color(double r, double g, double b, double a) { + int ri = r * 255; + int gi = g * 255; + int bi = b * 255; + int ai = a * 255; + return ai << 24 | ri << 16 | gi << 8 | bi; +} diff --git a/test/test.cpp b/test/test.cpp index b0c48af..daf280c 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -21,8 +21,8 @@ void my_game::init(settings& settings) { time = 0.0; settings.scale = 3; settings.size = vec2i(1920/3, 1080/3); - img = get("test.png"); - slime = get("slime.png"); + //img = get("test.png"); + //slime = get("slime.png"); //slime = slime->upscale_2x(); //slime = slime->upscale_2x(); //slime = slime->upscale_2x(); @@ -36,14 +36,14 @@ void my_game::update() { } void my_game::render(image& target) { - target.clear(0xffdddd); + target.clear(0x123456); auto pos = vec2i(std::sin(time * TAU / 4) * 100, std::cos(time * TAU / 4) * 100); //target.draw(img, vec2i(320, 180) + pos, recti(vec2i(8, 14), vec2i(8 * 4, 14 * 4))); //for(int i = 0; i < 1; ++i) // target.draw(img, vec2i::zero); //target.draw_rot(slime, vec2i(200, 200), time); - target.draw(slime, vec2i(40, 40)); + //target.draw(slime, vec2i(40, 40)); //target.draw(tileset[0xda], vec2i(320, 180) + pos, 0xff00ff); auto str = "Can only be played if\nthere are no card in\nyour draw pile.\nDeal 50 damage to ALL\nenemies."; //target.draw(str, vec2i(100, 100) + pos, font, 0xffffff, 0);