Started working on this 'arena tester' tool that would let me load an enemy and test them, but then realized I could just make it so I can spawn enemies in the game. I'm keeping the arena around as it will be useful later as a scriptable testing tool, but for now just spawn and test.

This commit is contained in:
Zed A. Shaw 2025-04-04 12:45:55 -04:00
parent b6c1eba1b3
commit 4f090159ab
14 changed files with 524 additions and 58 deletions

View file

@ -24,33 +24,11 @@ namespace guecs {
shared_ptr<sf::Font> font = nullptr;
shared_ptr<sf::Text> text = nullptr;
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText");
if(font == nullptr) font = font_ptr;
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size);
text->setFillColor(color);
if(centered) {
dbc::log("TEXTUAL IS CENTERED");
auto bounds = text->getLocalBounds();
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell);
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
text->setPosition({float(text_cell.x), float(text_cell.y) - text_cell.h / 2});
} else {
text->setPosition({float(cell.x + padding * 2), float(cell.y + padding * 2)});
}
text->setCharacterSize(size);
}
void update(std::wstring& new_content) {
content = new_content;
text->setString(content);
}
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr);
void update(std::wstring& new_content);
};
struct Label : public Textual {
template<typename... Args>
Label(Args... args) : Textual(args...)
{
@ -75,19 +53,7 @@ namespace guecs {
std::shared_ptr<sf::Sprite> sprite = nullptr;
std::shared_ptr<sf::Texture> texture = nullptr;
void init(lel::Cell &cell) {
auto sprite_texture = textures::get(name);
texture = sprite_texture.texture;
sprite = make_shared<sf::Sprite>(*texture);
sprite->setPosition({
float(cell.x + padding),
float(cell.y + padding)});
auto size = texture->getSize();
sprite->setScale({
float(cell.w - padding * 2) / size.x,
float(cell.h - padding * 2) / size.y});
}
void init(lel::Cell &cell);
};
struct Rectangle {
@ -97,23 +63,14 @@ namespace guecs {
int border_px = GUECS_BORDER_PX;
shared_ptr<sf::RectangleShape> shape = nullptr;
void init(lel::Cell& cell) {
sf::Vector2f size{float(cell.w) - padding * 2, float(cell.h) - padding * 2};
if(shape == nullptr) shape = make_shared<sf::RectangleShape>(size);
shape->setPosition({float(cell.x + padding), float(cell.y + padding)});
shape->setFillColor(color);
shape->setOutlineColor(border_color);
shape->setOutlineThickness(border_px);
}
void init(lel::Cell& cell);
};
struct Meter {
float percent = 1.0f;
Rectangle bar;
void init(lel::Cell& cell) {
bar.init(cell);
}
void init(lel::Cell& cell);
};
struct ActionData {
@ -130,7 +87,6 @@ namespace guecs {
float w = 0.0f;
float h = 0.0f;
sf::Color color = GUECS_BG_COLOR;
shared_ptr<sf::RectangleShape> shape = nullptr;
Background(lel::Parser& parser, sf::Color bg_color=GUECS_BG_COLOR) :
@ -143,12 +99,7 @@ namespace guecs {
Background() {}
void init() {
sf::Vector2f size{float(w), float(h)};
if(shape == nullptr) shape = make_shared<sf::RectangleShape>(size);
shape->setPosition({float(x), float(y)});
shape->setFillColor(color);
}
void init();
};
class UI {