splashscreen fade

This commit is contained in:
Squishy Bloob 2024-03-31 00:03:04 +00:00
parent aead28db61
commit 55204a5d0a
5 changed files with 42 additions and 8 deletions

View File

@ -16,6 +16,9 @@ enum class upscaler {
int upscaler_scale(upscaler upscaler); int upscaler_scale(upscaler upscaler);
std::tuple<double, double, double, double> color_to_elements(color color);
color elements_to_color(double r, double g, double b, double a);
struct image : resource { struct image : resource {
image(resource_manager& rm, ini_category const* ini, std::string const& path, std::vector<uint8_t> const& data); image(resource_manager& rm, ini_category const* ini, std::string const& path, std::vector<uint8_t> const& data);
image(image const& other); image(image const& other);
@ -32,19 +35,18 @@ struct image : resource {
color get_safe(vec2i pos) const; color get_safe(vec2i pos) const;
void clear(color color); 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);
void draw(image const* image, vec2i pos, recti src_rect); 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);
void draw(image const* image, vec2i pos, color color, recti src_rect); 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, double rot);
void draw_rot(image const* image, vec2i pos, recti src_rect, 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, upscaler upscaler);
void draw_upscaled(image const* image, std::vector<upscaler> upscalers); void draw_upscaled(image const* image, std::vector<upscaler> 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 color);
void draw(std::string const& str, vec2i pos, font const* font, color color1, color color2); void draw(std::string const& str, vec2i pos, font const* font, color color1, color color2);

View File

@ -172,7 +172,7 @@ void image::draw_upscaled(image const* img, vec2i s, upscaler upscaler) {
UPSCALE_3X_END UPSCALE_3X_END
} }
} }
/*
image const* image::upscale_eagle_2x() const { image const* image::upscale_eagle_2x() const {
auto img = new image(size() * 2); auto img = new image(size() * 2);
for(int y = 0; y < size().y; ++y) { for(int y = 0; y < size().y; ++y) {
@ -197,3 +197,4 @@ image const* image::upscale_eagle_2x() const {
} }
return img; return img;
} }
*/

View File

@ -188,8 +188,12 @@ void play_logo(HWND window, image const* logo, image const* logo_slime) {
if(now - last_frame >= frame_duration) { if(now - last_frame >= frame_duration) {
screen.clear(0x242424); 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)); 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(); auto p = screen.raw_pointer();
window_image.draw_upscaled(&screen, upscaler::scale3x); window_image.draw_upscaled(&screen, upscaler::scale3x);

View File

@ -76,5 +76,32 @@ void image::clear(color color) {
std::fill(_data, _data + size().size(), 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<double, double, double, double> 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;
}

View File

@ -21,8 +21,8 @@ void my_game::init(settings& settings) {
time = 0.0; time = 0.0;
settings.scale = 3; settings.scale = 3;
settings.size = vec2i(1920/3, 1080/3); settings.size = vec2i(1920/3, 1080/3);
img = get<image>("test.png"); //img = get<image>("test.png");
slime = get<image>("slime.png"); //slime = get<image>("slime.png");
//slime = slime->upscale_2x(); //slime = slime->upscale_2x();
//slime = slime->upscale_2x(); //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) { 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); 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))); //target.draw(img, vec2i(320, 180) + pos, recti(vec2i(8, 14), vec2i(8 * 4, 14 * 4)));
//for(int i = 0; i < 1; ++i) //for(int i = 0; i < 1; ++i)
// target.draw(img, vec2i::zero); // target.draw(img, vec2i::zero);
//target.draw_rot(slime, vec2i(200, 200), time); //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); //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."; 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); //target.draw(str, vec2i(100, 100) + pos, font, 0xffffff, 0);