add item spawner
This commit is contained in:
62
types.h
62
types.h
@@ -4,14 +4,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "raymath.h"
|
||||
#include "raylib.h"
|
||||
|
||||
struct Player : Rectangle {
|
||||
uint8_t lives;
|
||||
double last_hit;
|
||||
|
||||
[[nodiscard]] Vector2 center() const noexcept;
|
||||
|
||||
[[nodiscard]] Rectangle rect() const noexcept;
|
||||
|
||||
[[nodiscard]] bool is_invulnerable(double now) const noexcept;
|
||||
|
||||
void move(float delta_x, float delta_y);
|
||||
@@ -41,3 +46,60 @@ struct Enemy {
|
||||
float speed;
|
||||
bool alive;
|
||||
};
|
||||
|
||||
enum ItemType {
|
||||
TEARS_UP,
|
||||
TEARS_DOWN,
|
||||
RANGE_UP,
|
||||
RANGE_DOWN,
|
||||
ITEM_TYPE_COUNT
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<ItemType> : std::formatter<string_view> {
|
||||
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";
|
||||
break;
|
||||
case TEARS_DOWN:
|
||||
item_type_str = "TEARS_DOWN";
|
||||
break;
|
||||
case RANGE_UP:
|
||||
item_type_str = "RANGE_UP";
|
||||
break;
|
||||
case RANGE_DOWN:
|
||||
item_type_str = "RANGE_DOWN";
|
||||
break;
|
||||
case ITEM_TYPE_COUNT:
|
||||
item_type_str = "ITEM_TYPE_COUNT";
|
||||
break;
|
||||
}
|
||||
return std::formatter<string_view>::format(item_type_str, ctx);;
|
||||
}
|
||||
};
|
||||
|
||||
struct Item {
|
||||
Vector2 center;
|
||||
float radius;
|
||||
ItemType type;
|
||||
bool active;
|
||||
|
||||
[[nodiscard]] Color color() const noexcept {
|
||||
switch (type) {
|
||||
case TEARS_UP:
|
||||
return BLUE;
|
||||
case TEARS_DOWN:
|
||||
return GREEN;
|
||||
case RANGE_UP:
|
||||
return RED;
|
||||
case RANGE_DOWN:
|
||||
return ORANGE;
|
||||
case ITEM_TYPE_COUNT:
|
||||
assert(0 && "ITEM_TYPE_COUNT should not be instantiated.");
|
||||
}
|
||||
|
||||
assert(0 && "Unreachable.");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user