add cancel parameter for Spawner::for_each
This commit is contained in:
7
main.cpp
7
main.cpp
@@ -164,10 +164,11 @@ void update_tears() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enemy_spawner.for_each([¢er, &active](auto &enemy) {
|
enemy_spawner.for_each([¢er, &active](auto &enemy, auto& cancel) {
|
||||||
if (enemy.alive() && CheckCollisionCircles(center, player.tear_radius, enemy.center, enemy.radius)) {
|
if (enemy.alive() && CheckCollisionCircles(center, player.tear_radius, enemy.center, enemy.radius)) {
|
||||||
active = false;
|
active = false;
|
||||||
if (--enemy.hp == 0) score++;
|
if (--enemy.hp == 0) score++;
|
||||||
|
cancel = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -265,7 +266,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enemy_spawner.for_each([now](Enemy &enemy) {
|
enemy_spawner.for_each([now](Enemy &enemy, auto& cancel) {
|
||||||
if (enemy.alive()) {
|
if (enemy.alive()) {
|
||||||
enemy.center = Vector2MoveTowards(enemy.center, player.center(), enemy.speed);
|
enemy.center = Vector2MoveTowards(enemy.center, player.center(), enemy.speed);
|
||||||
const Color enemy_color = enemy.hp == 1 ? PINK : enemy.hp == 2 ? ORANGE : RED;
|
const Color enemy_color = enemy.hp == 1 ? PINK : enemy.hp == 2 ? ORANGE : RED;
|
||||||
@@ -285,7 +286,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
item_spawner.for_each([&item_pickup_text_buffer, now, &item_last_picked_up](Item &item) {
|
item_spawner.for_each([&item_pickup_text_buffer, now, &item_last_picked_up](Item &item, auto& cancel) {
|
||||||
if (!item.active) return;
|
if (!item.active) return;
|
||||||
|
|
||||||
DrawCircleV(item.center, item.radius, item.color());
|
DrawCircleV(item.center, item.radius, item.color());
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ struct Spawner {
|
|||||||
void for_each(F&& func) {
|
void for_each(F&& func) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
for (auto& value : values) {
|
for (auto& value : values) {
|
||||||
func(value);
|
bool cancel = false;
|
||||||
|
func(value, cancel);
|
||||||
|
if (cancel) break;;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user