Add victory menu

This commit is contained in:
Nikita Lisitsa 2024-08-20 15:23:45 +03:00
parent 01dfaee33f
commit decf3ba5be

View file

@ -379,6 +379,7 @@ namespace gmtk
int stage = 0;
float stage_animation = 0.f;
bool victory = false;
int resource_count = 0;
@ -419,15 +420,15 @@ namespace gmtk
{{color_type::white, shape_type::circle}, 0, {}, {{color_type::white, shape_type::circle}}},
{{color_type::white, shape_type::circle}, 15, {card_type::mixer}, {{color_type::black, shape_type::circle}}},
{{color_type::gray, shape_type::circle}, 15, {card_type::hue_shifter, card_type::crossing}, {{color_type::red, shape_type::circle}}},
{{color_type::green, shape_type::circle}, 15, {card_type::reshaper, card_type::crossing}, {}},
{{color_type::green, shape_type::square}, 30, {card_type::hue_shifter, card_type::crossing, card_type::zoomer, card_type::zoomer}, {}},
{{color_type::blue, shape_type::square}, 30, {card_type::mixer, card_type::crossing, card_type::zoomer}, {}},
{{color_type::yellow, shape_type::square}, 30, {card_type::zoomer}, {}},
{{color_type::magenta, shape_type::square}, 30, {}, {}},
{{color_type::cyan, shape_type::square}, 30, {card_type::reshaper, card_type::reshaper, card_type::zoomer}, {{color_type::black, shape_type::circle}}},
{{color_type::white, shape_type::square}, 45, {card_type::mixer, card_type::mixer, card_type::mixer, card_type::mixer, card_type::zoomer, card_type::zoomer, card_type::crossing}, {{color_type::white, shape_type::circle}}},
{{color_type::black, shape_type::square}, 45, {card_type::mixer, card_type::mixer, card_type::reshaper, card_type::reshaper, card_type::reshaper, card_type::zoomer, card_type::zoomer, card_type::crossing, card_type::crossing, card_type::crossing}, {{color_type::red, shape_type::circle}}},
{{color_type::gray, shape_type::square}, 60, {}, {}},
// {{color_type::green, shape_type::circle}, 15, {card_type::reshaper, card_type::crossing}, {}},
// {{color_type::green, shape_type::square}, 30, {card_type::hue_shifter, card_type::crossing, card_type::zoomer, card_type::zoomer}, {}},
// {{color_type::blue, shape_type::square}, 30, {card_type::mixer, card_type::crossing, card_type::zoomer}, {}},
// {{color_type::yellow, shape_type::square}, 30, {card_type::zoomer}, {}},
// {{color_type::magenta, shape_type::square}, 30, {}, {}},
// {{color_type::cyan, shape_type::square}, 30, {card_type::reshaper, card_type::reshaper, card_type::zoomer}, {{color_type::black, shape_type::circle}}},
// {{color_type::white, shape_type::square}, 45, {card_type::mixer, card_type::mixer, card_type::mixer, card_type::mixer, card_type::zoomer, card_type::zoomer, card_type::crossing}, {{color_type::white, shape_type::circle}}},
// {{color_type::black, shape_type::square}, 45, {card_type::mixer, card_type::mixer, card_type::reshaper, card_type::reshaper, card_type::reshaper, card_type::zoomer, card_type::zoomer, card_type::crossing, card_type::crossing, card_type::crossing}, {{color_type::red, shape_type::circle}}},
// {{color_type::gray, shape_type::square}, 60, {}, {}},
};
template <typename Component, util::uuid UUID>
@ -1568,49 +1569,58 @@ namespace gmtk
);
}
if (!in_menu() && !is_sandbox_mode_ && map_.stage + 1 < std::size(stages) && map_.resource_count >= stages[map_.stage].count)
if (!in_menu() && !is_sandbox_mode_ && map_.resource_count >= stages[map_.stage].count)
{
for (auto card : stages[map_.stage].cards)
map_.cards[card] += 1;
for (auto type : stages[map_.stage].sources)
if (map_.stage + 1 < std::size(stages))
{
util::hash_set<location, location_hash> spots;
for (auto card : stages[map_.stage].cards)
map_.cards[card] += 1;
auto add = [&](location l)
for (auto type : stages[map_.stage].sources)
{
if (!map_.world->index<index>().find(l))
spots.insert(l);
};
util::hash_set<location, location_hash> spots;
for (int i = 0; i < 3; ++i)
{
add({0, {-1, i}});
add({0, {3, i}});
add({0, {i, 3}});
auto add = [&](location l)
{
if (!map_.world->index<index>().find(l))
spots.insert(l);
};
for (int i = 0; i < 3; ++i)
{
add({0, {-1, i}});
add({0, {3, i}});
add({0, {i, 3}});
}
if (!map_.cards.contains(card_type::zoomer))
{
spots.erase(location{0, {0, 3}});
spots.erase(location{0, {2, 3}});
}
if (!spots.empty())
{
map_.world->create(
vertex{random::uniform_from(map_rng_, spots)},
source{type}
);
}
}
if (!map_.cards.contains(card_type::zoomer))
{
spots.erase(location{0, {0, 3}});
spots.erase(location{0, {2, 3}});
}
map_.stage += 1;
map_.stage_animation += 1.f;
map_.resource_count = 0;
if (!spots.empty())
{
map_.world->create(
vertex{random::uniform_from(map_rng_, spots)},
source{type}
);
}
if (map_.stage > 1 && tutorial_state_ <= 2)
tutorial_state_ = 3;
}
else if (!map_.victory)
{
map_.victory = true;
in_victory_menu_ = true;
set_victory_menu_buttons();
}
map_.stage += 1;
map_.stage_animation += 1.f;
map_.resource_count = 0;
if (map_.stage > 1 && tutorial_state_ <= 2)
tutorial_state_ = 3;
}
map_.world->apply<vertex const, transformer>([&](vertex const & v, transformer & t)
@ -2249,15 +2259,29 @@ namespace gmtk
box[0] = {pen[0], pen[0] + button_width};
box[1] = {pen[1] - button_height, pen[1]};
box = geom::expand(box, menu_buttons_[i].selected_state * 8.f * pixel_size);
bool active = static_cast<bool>(menu_buttons_[i].action);
if (geom::contains(box, mouse_world_))
selected_button_ = i;
gfx::color_rgba bg_color;
gfx::color_rgba text_color;
auto text_color = gfx::lerp(gfx::black.as_color_rgba(), gfx::color_rgba{191, 96, 0, 255}, menu_buttons_[i].selected_state);
if (active)
{
box = geom::expand(box, menu_buttons_[i].selected_state * 8.f * pixel_size);
if (geom::contains(box, mouse_world_))
selected_button_ = i;
bg_color = gfx::lerp(gfx::color_rgba{192, 192, 192, 255}, gfx::white.as_color_rgba(), menu_buttons_[i].selected_state);
text_color = gfx::lerp(gfx::black.as_color_rgba(), gfx::color_rgba{191, 96, 0, 255}, menu_buttons_[i].selected_state);
}
else
{
bg_color = {192, 224, 255, 255};
text_color = {0, 0, 0, 255};
}
painter_.rect(geom::expand(box, pixel_size * 5.f), text_color);
painter_.rect(box, gfx::lerp(gfx::color_rgba{192, 192, 192, 255}, gfx::white.as_color_rgba(), menu_buttons_[i].selected_state));
painter_.rect(box, bg_color);
float s = pixel_size * 4.f;
@ -2276,6 +2300,7 @@ namespace gmtk
bool in_start_menu_ = true;
bool in_escape_menu_ = false;
bool in_victory_menu_ = false;
float menu_transition_ = 1.f;
@ -2291,7 +2316,7 @@ namespace gmtk
bool in_menu() const
{
return in_start_menu_ || in_escape_menu_;
return in_start_menu_ || in_escape_menu_ || in_victory_menu_;
}
std::uint64_t seed_ = 0;
@ -2328,6 +2353,7 @@ namespace gmtk
}
in_start_menu_ = false;
in_escape_menu_ = false;
in_victory_menu_ = false;
reset_state();
}
@ -2345,6 +2371,7 @@ namespace gmtk
{
in_start_menu_ = true;
in_escape_menu_ = false;
in_victory_menu_ = false;
map_ = start_menu_map();
@ -2372,6 +2399,7 @@ namespace gmtk
void set_escape_menu_buttons()
{
menu_buttons_.clear();
menu_buttons_.push_back({"Paused", {}});
menu_buttons_.push_back({"Continue", [this]{ in_escape_menu_ = false; }});
menu_buttons_.push_back({"Restart", [this]{ start_new_game(is_challenge_mode_, is_sandbox_mode_, false); }});
menu_buttons_.push_back({"Main menu", [this]{ set_start_menu(); }});
@ -2379,6 +2407,16 @@ namespace gmtk
menu_buttons_.push_back({"Exit", [this]{ stop(); }});
}
void set_victory_menu_buttons()
{
menu_buttons_.clear();
menu_buttons_.push_back({"You won!", {}});
menu_buttons_.push_back({"One more turn", [this]{ in_victory_menu_ = false; }});
menu_buttons_.push_back({"Play again", [this]{ start_new_game(is_challenge_mode_, is_sandbox_mode_, true); }});
menu_buttons_.push_back({"Main menu", [this]{ set_start_menu(); }});
menu_buttons_.push_back({"Exit", [this]{ stop(); }});
}
context const & context_;
bool is_windowed_ = false;