From f44df139b16d7558c3a2772a250642ed47978800 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 19 Aug 2024 18:05:03 +0300 Subject: [PATCH] Juice! --- source/application.cpp | 82 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index f3659b2..befcec7 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -248,6 +249,7 @@ namespace gmtk psemek_ecs_declare_uuid("source") resource_type type; + float animate = 0.f; }; struct transformer @@ -255,6 +257,7 @@ namespace gmtk psemek_ecs_declare_uuid("transformer") transformer_type type; + float animate = 0.f; }; struct crossing @@ -352,6 +355,9 @@ namespace gmtk struct lab { psemek_ecs_declare_uuid("lab") + + float animate = 0.f; + float animate_error = 0.f; }; struct map @@ -743,6 +749,20 @@ namespace gmtk }); } + float animation_factor(float animate) + { + static geom::gradient const g + { + std::pair{0.5f, 0.f}, + geom::easing_type::cubic, + std::pair{0.875f, 1.f}, + geom::easing_type::cubic, + std::pair{1.f, 0.f}, + }; + + return g(animate); + } + void draw(map & map, gfx::painter & painter, float pixel_size) { map.world.apply([&](vertex const & v, crossing const & c) @@ -796,19 +816,35 @@ namespace gmtk map.world.apply([&](vertex const & v, source const & s) { - painter.rect(v.location.bbox(-0.2f), gfx::black); - painter.rect(v.location.bbox(-0.225f), color_of(s.type)); + geom::vector shift{0.f, 0.f}; + if (v.location.coords[0] < 0) + shift = {1.f, 0.f}; + else if (v.location.coords[0] >= 3) + shift = {-1.f, 0.f}; + else + shift = {0.f, -1.f}; + + shift *= v.location.bbox()[0].length() * animation_factor(s.animate) / 12.f; + painter.rect(shift + v.location.bbox(-0.2f), gfx::black); + painter.rect(shift + v.location.bbox(-0.225f), color_of(s.type)); }); map.world.apply([&](vertex const & v, transformer const & t) { - draw_structure(v.location.bbox(), t, painter); + auto box = v.location.bbox(); + box = geom::expand(box, 0.125f * animation_factor(t.animate)); + draw_structure(box, t, painter); }); - map.world.apply([&](vertex const & v, lab const &) + map.world.apply([&](vertex const & v, lab const & l) { - painter.rect(v.location.bbox(-0.2f), {0, 0, 0, 255}); - painter.rect(v.location.bbox(-0.225f), {192, 192, 192, 255}); + geom::vector shift{1.f, -1.f}; + + shift[0] *= v.location.bbox()[0].length() * geom::sqr(std::sin(l.animate_error * geom::pi)) * std::sin(l.animate_error * geom::pi * 5.f) / 12.f; + shift[1] *= v.location.bbox()[0].length() * animation_factor(l.animate) / 12.f; + + painter.rect(shift + v.location.bbox(-0.2f), {0, 0, 0, 255}); + painter.rect(shift + v.location.bbox(-0.225f), {192, 192, 192, 255}); auto pen = v.location.bbox(-0.4f).corner(0.5f, 1.f); @@ -1099,8 +1135,8 @@ namespace gmtk { map_.spawn_timer -= 1.f; - map_.world.apply( - [&](vertex const & v, source const & s) + map_.world.apply( + [&](vertex const & v, source & s) { auto p = v.location.down(); @@ -1108,6 +1144,9 @@ namespace gmtk if (!map_.world.get(t).contains()) { + if (!map_.world.get(t).get().belts_to.empty()) + s.animate += 1.f; + auto i = map_.world.create( item{s.type, p} ); @@ -1156,7 +1195,7 @@ namespace gmtk tutorial_state_ = 3; } - map_.world.apply([&](vertex const & v, transformer const & t) + map_.world.apply([&](vertex const & v, transformer & t) { boost::container::flat_map has_inputs; @@ -1209,6 +1248,9 @@ namespace gmtk break; } + if (crafted) + t.animate += 1.f; + if (!crafted && !has_inputs.empty()) { return; @@ -1254,16 +1296,18 @@ namespace gmtk if (auto cell = map_.world.index().find(i.start.up())) { - if (map_.world.get(*cell).get_if()) + if (auto l = map_.world.get(*cell).get_if()) { if (i.type == stages[map_.stage].type) { map_.resource_count += 1; + l->animate += 1.f; map_.world.destroy(entity); } else { - map_.world.attach(map_.world.index().get(i.start), occupied{entity}); + l->animate_error += 1.f; + map_.world.destroy(entity); } return; } @@ -1323,6 +1367,22 @@ namespace gmtk map_.world.attach(map_.world.index().get(i.start), occupied{entity}); }); + map_.world.apply([&](source & s) + { + s.animate = std::max(0.f, s.animate - 3.f * dt); + }); + + map_.world.apply([&](transformer & t) + { + t.animate = std::max(0.f, t.animate - 3.f * dt); + }); + + map_.world.apply([&](lab & l) + { + l.animate = std::max(0.f, l.animate - 3.f * dt); + l.animate_error = std::max(0.f, l.animate_error - 3.f * dt); + }); + float aspect_ratio = (screen_size_[0] * 1.f) / screen_size_[1]; if (view_transition_)