Implement sandbox & campaign modes
This commit is contained in:
parent
cce768e01f
commit
2a3ef0f84b
1 changed files with 103 additions and 24 deletions
|
|
@ -694,7 +694,7 @@ namespace gmtk
|
|||
return result;
|
||||
}
|
||||
|
||||
map capmaign_map()
|
||||
map campaign_map(bool challenge)
|
||||
{
|
||||
map result;
|
||||
|
||||
|
|
@ -708,7 +708,75 @@ namespace gmtk
|
|||
lab{}
|
||||
);
|
||||
|
||||
result.cards[card_type::eraser] = 1;
|
||||
result.cards[card_type::eraser] = 1000000;
|
||||
if (!challenge)
|
||||
for (auto type : card_type_values())
|
||||
result.cards[type] = 1000000;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
map sandbox_map()
|
||||
{
|
||||
map result;
|
||||
|
||||
result.world = std::make_unique<ecs::container>();
|
||||
|
||||
result.world->index<index>();
|
||||
result.world->index<path_index>();
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {-1, 0}}},
|
||||
source{{color_type::red, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {-1, 1}}},
|
||||
source{{color_type::green, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {-1, 2}}},
|
||||
source{{color_type::blue, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {3, 0}}},
|
||||
source{{color_type::cyan, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {3, 1}}},
|
||||
source{{color_type::magenta, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {3, 2}}},
|
||||
source{{color_type::yellow, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {0, 3}}},
|
||||
source{{color_type::black, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {1, 3}}},
|
||||
source{{color_type::gray, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {2, 3}}},
|
||||
source{{color_type::white, shape_type::circle}}
|
||||
);
|
||||
|
||||
result.world->create(
|
||||
vertex{{0, {1, -1}}},
|
||||
lab{}
|
||||
);
|
||||
|
||||
for (auto type : card_type_values())
|
||||
result.cards[type] = 1000000;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1060,7 +1128,7 @@ namespace gmtk
|
|||
});
|
||||
}
|
||||
|
||||
void draw(map & map, gfx::painter & painter, float pixel_size)
|
||||
void draw(map & map, gfx::painter & painter, float pixel_size, bool sandbox)
|
||||
{
|
||||
map.world->apply<vertex const, crossing const>([&](vertex const & v, crossing const & c)
|
||||
{
|
||||
|
|
@ -1143,15 +1211,18 @@ namespace gmtk
|
|||
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);
|
||||
if (!sandbox)
|
||||
{
|
||||
auto pen = v.location.bbox(-0.4f).corner(0.5f, 1.f);
|
||||
|
||||
float vs = 2.f * pixel_size;
|
||||
float vs = 2.f * pixel_size;
|
||||
|
||||
draw_item(stages[map.stage].type, pen, 1.f, painter);
|
||||
draw_item(stages[map.stage].type, pen, 1.f, painter);
|
||||
|
||||
pen[1] -= 24.f * vs;
|
||||
pen[1] -= 24.f * vs;
|
||||
|
||||
painter.text(pen, std::format("{}/{}", map.resource_count, stages[map.stage].count), {.scale = {vs, -vs}, .c = {0, 0, 0, 255}});
|
||||
painter.text(pen, std::format("{}/{}", map.resource_count, stages[map.stage].count), {.scale = {vs, -vs}, .c = {0, 0, 0, 255}});
|
||||
}
|
||||
});
|
||||
|
||||
map.world->apply<item const>([&](item const & i)
|
||||
|
|
@ -1441,7 +1512,7 @@ namespace gmtk
|
|||
{
|
||||
in_escape_menu_ ^= true;
|
||||
if (in_escape_menu_)
|
||||
set_escape_menu();
|
||||
set_escape_menu_buttons();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1487,7 +1558,7 @@ namespace gmtk
|
|||
);
|
||||
}
|
||||
|
||||
if (!in_menu() && map_.stage + 1 < std::size(stages) && map_.resource_count >= stages[map_.stage].count)
|
||||
if (!in_menu() && !is_sandbox_mode_ && map_.stage + 1 < std::size(stages) && map_.resource_count >= stages[map_.stage].count)
|
||||
{
|
||||
for (auto card : stages[map_.stage].cards)
|
||||
map_.cards[card] += 1;
|
||||
|
|
@ -1648,7 +1719,7 @@ namespace gmtk
|
|||
{
|
||||
if (auto l = map_.world->get(*cell).get_if<lab>())
|
||||
{
|
||||
if (i.type == stages[map_.stage].type)
|
||||
if (i.type == stages[map_.stage].type || is_sandbox_mode_)
|
||||
{
|
||||
map_.resource_count += 1;
|
||||
l->animate += 1.f;
|
||||
|
|
@ -1923,7 +1994,7 @@ namespace gmtk
|
|||
draw_selection(belt_start_->bbox(), painter_, {64, 64, 64, 255});
|
||||
}
|
||||
|
||||
draw(map_, painter_, in_start_menu_ ? 0.f : pixel_size);
|
||||
draw(map_, painter_, pixel_size, is_sandbox_mode_);
|
||||
|
||||
if (!in_menu())
|
||||
{
|
||||
|
|
@ -2052,10 +2123,8 @@ namespace gmtk
|
|||
|
||||
draw_card(box, type, painter_);
|
||||
|
||||
if (type != card_type::eraser)
|
||||
{
|
||||
if (map_.cards.at(type) < 1000)
|
||||
painter_.text(box.center() - geom::vector{step, 0.f}, std::to_string(map_.cards.at(type)), {.scale = {vs, -vs}, .c = gfx::black});
|
||||
}
|
||||
|
||||
pen[1] -= step;
|
||||
}
|
||||
|
|
@ -2190,10 +2259,12 @@ namespace gmtk
|
|||
}
|
||||
|
||||
bool is_challenge_mode_ = false;
|
||||
bool is_sandbox_mode_ = false;
|
||||
|
||||
void start_campaign(bool challenge, bool new_seed)
|
||||
void start_new_game(bool challenge, bool sandbox, bool new_seed)
|
||||
{
|
||||
is_challenge_mode_ = challenge;
|
||||
is_sandbox_mode_ = sandbox;
|
||||
|
||||
if (new_seed)
|
||||
{
|
||||
|
|
@ -2203,7 +2274,10 @@ namespace gmtk
|
|||
item_rng_ = {seed, 0xb9fc3979f9860bbdull};
|
||||
}
|
||||
|
||||
map_ = capmaign_map();
|
||||
if (sandbox)
|
||||
map_ = sandbox_map();
|
||||
else
|
||||
map_ = campaign_map(is_challenge_mode_);
|
||||
if (in_start_menu_)
|
||||
{
|
||||
view_transition_ = {view_stack_.back()};
|
||||
|
|
@ -2245,21 +2319,26 @@ namespace gmtk
|
|||
view_stack_.push_back({-1, {0, 0}});
|
||||
view_stack_.push_back({0, {1, 1}});
|
||||
|
||||
set_start_menu_buttons();
|
||||
}
|
||||
|
||||
void set_start_menu_buttons()
|
||||
{
|
||||
menu_buttons_.clear();
|
||||
menu_buttons_.push_back({"Campaign mode", [this]{ start_campaign(false, true); }});
|
||||
menu_buttons_.push_back({"Challenge mode", [this]{ start_campaign(true, true); }});
|
||||
menu_buttons_.push_back({"Sandbox mode", {}});
|
||||
menu_buttons_.push_back({is_windowed_ ? "Windowed" : "Fullscreen", [this]{ is_windowed_ ^= true; context_.windowed(is_windowed_); }});
|
||||
menu_buttons_.push_back({"Campaign mode", [this]{ start_new_game(false, false, true); }});
|
||||
menu_buttons_.push_back({"Challenge mode", [this]{ start_new_game(true, false, true); }});
|
||||
menu_buttons_.push_back({"Sandbox mode", [this]{ start_new_game(true, true, true); }});
|
||||
menu_buttons_.push_back({is_windowed_ ? "Windowed" : "Fullscreen", [this]{ is_windowed_ ^= true; context_.windowed(is_windowed_); set_start_menu_buttons(); }});
|
||||
menu_buttons_.push_back({"Exit", [this]{ stop(); }});
|
||||
}
|
||||
|
||||
void set_escape_menu()
|
||||
void set_escape_menu_buttons()
|
||||
{
|
||||
menu_buttons_.clear();
|
||||
menu_buttons_.push_back({"Continue", [this]{ in_escape_menu_ = false; }});
|
||||
menu_buttons_.push_back({"Restart", [this]{ start_campaign(is_challenge_mode_, 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(); }});
|
||||
menu_buttons_.push_back({is_windowed_ ? "Windowed" : "Fullscreen", [this]{ is_windowed_ ^= true; context_.windowed(is_windowed_); }});
|
||||
menu_buttons_.push_back({is_windowed_ ? "Windowed" : "Fullscreen", [this]{ is_windowed_ ^= true; context_.windowed(is_windowed_); set_escape_menu_buttons(); }});
|
||||
menu_buttons_.push_back({"Exit", [this]{ stop(); }});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue