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:
parent
b6c1eba1b3
commit
4f090159ab
14 changed files with 524 additions and 58 deletions
64
guecs.cpp
64
guecs.cpp
|
@ -1,6 +1,70 @@
|
|||
#include "guecs.hpp"
|
||||
|
||||
namespace guecs {
|
||||
|
||||
void Textual::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) {
|
||||
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 Textual::update(std::wstring& new_content) {
|
||||
content = new_content;
|
||||
text->setString(content);
|
||||
}
|
||||
|
||||
|
||||
void Sprite::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 bounds = sprite->getGlobalBounds();
|
||||
|
||||
sprite->setScale({
|
||||
float(cell.w - padding * 2) / bounds.size.x,
|
||||
float(cell.h - padding * 2) / bounds.size.y});
|
||||
}
|
||||
|
||||
void Rectangle::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 Meter::init(lel::Cell& cell) {
|
||||
bar.init(cell);
|
||||
}
|
||||
|
||||
|
||||
void Background::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);
|
||||
}
|
||||
|
||||
|
||||
UI::UI() {
|
||||
$font = make_shared<sf::Font>(FONT_FILE_NAME);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue