made items affect stats

This commit is contained in:
2025-12-01 10:59:00 -05:00
parent d6dff2a539
commit 77cb83cfd5
2 changed files with 54 additions and 10 deletions

View File

@@ -3,7 +3,6 @@
#include <print>
#include <random>
#include <raylib.h>
#include <thread>
#include "rng.h"
#include "spawner.h"
@@ -21,7 +20,7 @@ uint32_t score;
Tear tears[100] = {};
float tear_speed = 10;
float tear_range = 500;
float tear_range = 300;
float tear_radius = 10.0f;
double last_fired = 0;
double fire_rate = .5;
@@ -211,6 +210,11 @@ int main() {
std::string lives_text_buffer;
lives_text_buffer.reserve(64);
std::string item_pickup_text_buffer;
item_pickup_text_buffer.reserve(64);
double item_last_picked_up = 0;
double item_pickup_message_duration = 3;
while (!WindowShouldClose()) {
if (IsWindowResized()) {
screen_height = static_cast<float>(GetScreenHeight());
@@ -263,7 +267,7 @@ int main() {
}
}
enemy_spawner.for_each([now](auto &enemy) {
enemy_spawner.for_each([now](Enemy &enemy) {
if (enemy.alive) {
enemy.center = Vector2MoveTowards(enemy.center, player.center(), enemy.speed);
DrawCircleV(enemy.center, enemy.radius, RED);
@@ -281,12 +285,30 @@ int main() {
}
});
item_spawner.for_each([](auto &item) {
item_spawner.for_each([&item_pickup_text_buffer, now, &item_last_picked_up](Item &item) {
if (!item.active) return;
DrawCircleV(item.center, item.radius, item.color());
if (CheckCollisionCircleRec(item.center, item.radius, player.rect())) {
switch (item.type) {
case TEARS_UP:
fire_rate = std::max(fire_rate - 0.1, 0.1);
break;
case TEARS_DOWN:
fire_rate += 0.1;
break;
case RANGE_UP:
tear_range += 100.0f;
break;
case RANGE_DOWN:
tear_range = std::max(tear_range - 100.0f, 100.0f);
break;
case ITEM_TYPE_COUNT:
break;
}
std::format_to(std::back_inserter(item_pickup_text_buffer), "{:t}!", item.type);
item_last_picked_up = now;
item.active = false;
}
});
@@ -296,9 +318,17 @@ int main() {
score_text_buffer.clear();
std::format_to(std::back_inserter(lives_text_buffer), "Lives: {}", player.lives);
DrawText(lives_text_buffer.c_str(), 50, static_cast<int>(screen_height) - 50, 20, BLACK);
DrawText(lives_text_buffer.c_str(), 50, static_cast<int>(screen_height) - 75, 20, BLACK);
lives_text_buffer.clear();
if (now < item_last_picked_up + item_pickup_message_duration && !item_pickup_text_buffer.empty()) {
DrawText(item_pickup_text_buffer.c_str(), 50, static_cast<int>(screen_height) - 50, 20, BLACK);
}
if (item_last_picked_up + item_pickup_message_duration <= now && !item_pickup_text_buffer.empty()) {
item_pickup_text_buffer.clear();
}
EndDrawing();
}
CloseWindow();

24
types.h
View File

@@ -57,23 +57,37 @@ enum ItemType {
template <>
struct std::formatter<ItemType> : std::formatter<string_view> {
bool title_case = false;
constexpr auto parse(std::format_parse_context& ctx) {
auto it = ctx.begin();
if (it == ctx.end()) return it;
if (*it == 't') {
title_case = true;
++it;
}
return it;
}
auto format(const ItemType& item_type, std::format_context& ctx) const {
std::string_view item_type_str;
switch (item_type) {
case TEARS_UP:
item_type_str = "TEARS_UP";
item_type_str = title_case ? "Tears Up" : "TEARS_UP";
break;
case TEARS_DOWN:
item_type_str = "TEARS_DOWN";
item_type_str = title_case ? "Tears Down" : "TEARS_DOWN";
break;
case RANGE_UP:
item_type_str = "RANGE_UP";
item_type_str = title_case ? "Range Up" : "RANGE_UP";
break;
case RANGE_DOWN:
item_type_str = "RANGE_DOWN";
item_type_str = title_case ? "Range Down" : "RANGE_DOWN";
break;
case ITEM_TYPE_COUNT:
item_type_str = "ITEM_TYPE_COUNT";
item_type_str = title_case ? "Item Type Count" : "ITEM_TYPE_COUNT";
break;
}
return std::formatter<string_view>::format(item_type_str, ctx);;