Super jank prototype of my idea but I am rendering multiple characters per cell to give the effect of a more complex character. Now to make this a data setup so it's easy to make characters. Also, probably have little add ons to show things like weapons equiped, etc.
This commit is contained in:
parent
31c86fa2b3
commit
9f1e9717a0
3 changed files with 39 additions and 11 deletions
45
gui.cpp
45
gui.cpp
|
@ -123,6 +123,22 @@ bool GUI::handle_events() {
|
||||||
return event_happened;
|
return event_happened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sf::Sprite &GUI::get_text_sprite(wchar_t tile) {
|
||||||
|
if(!$sprites.contains(tile)) {
|
||||||
|
sf::Glyph glyph = $font.getGlyph(tile, MAP_FONT_SIZE, false);
|
||||||
|
// WARNING! we actually have to do this here because SFML caches
|
||||||
|
// the glyphs on the font texture, so this gets loaded each time
|
||||||
|
// we get a new glyph from the font.
|
||||||
|
$font_texture = $font.getTexture(MAP_FONT_SIZE);
|
||||||
|
sf::Sprite sprite($font_texture);
|
||||||
|
sprite.setTextureRect(glyph.textureRect);
|
||||||
|
$sprites[tile] = sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sprites[tile];
|
||||||
|
}
|
||||||
|
|
||||||
void GUI::run_systems() {
|
void GUI::run_systems() {
|
||||||
auto player = $world.get<Player>();
|
auto player = $world.get<Player>();
|
||||||
System::enemy_pathing($world, $game_map, player);
|
System::enemy_pathing($world, $game_map, player);
|
||||||
|
@ -133,33 +149,39 @@ void GUI::run_systems() {
|
||||||
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
|
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
|
||||||
if(clear) $window.clear();
|
if(clear) $window.clear();
|
||||||
std::string screenout = $screen.ToString();
|
std::string screenout = $screen.ToString();
|
||||||
std::string map_screenout = $map_screen.ToString();
|
|
||||||
std::wstring main_screen_utf8 = $converter.from_bytes(screenout);
|
std::wstring main_screen_utf8 = $converter.from_bytes(screenout);
|
||||||
$ui_text.setString(main_screen_utf8);
|
$ui_text.setString(main_screen_utf8);
|
||||||
$window.draw($ui_text);
|
$window.draw($ui_text);
|
||||||
|
|
||||||
|
std::string map_screenout = $map_screen.ToString();
|
||||||
std::wstring map_screen_utf8 = $converter.from_bytes(map_screenout);
|
std::wstring map_screen_utf8 = $converter.from_bytes(map_screenout);
|
||||||
sf::Texture ftext = $font.getTexture(MAP_FONT_SIZE);
|
|
||||||
|
|
||||||
float y = 0.0f;
|
float y = 0.0f;
|
||||||
float x = GAME_MAP_POS;
|
float x = GAME_MAP_POS;
|
||||||
const float line_spacing = $font.getLineSpacing(MAP_FONT_SIZE);
|
const float line_spacing = $font.getLineSpacing(MAP_FONT_SIZE);
|
||||||
|
sf::Glyph base_glyph = $font.getGlyph(L'█', MAP_FONT_SIZE, false);
|
||||||
|
auto bg_sprite = get_text_sprite(L'█');
|
||||||
|
bg_sprite.setColor(sf::Color(20,20,20));
|
||||||
|
auto add_sprite = get_text_sprite(L'!');
|
||||||
|
bool has_add = false;
|
||||||
|
|
||||||
for(size_t i = 0; i < map_screen_utf8.size(); i++) {
|
for(size_t i = 0; i < map_screen_utf8.size(); i++) {
|
||||||
wchar_t tile = map_screen_utf8[i];
|
wchar_t tile = map_screen_utf8[i];
|
||||||
sf::Glyph glyph = $font.getGlyph(tile, MAP_FONT_SIZE, false);
|
sf::Sprite &sprite = get_text_sprite(tile);
|
||||||
sf::Sprite sprite(ftext);
|
|
||||||
sprite.setTextureRect(glyph.textureRect);
|
|
||||||
sprite.setPosition({x, y});
|
sprite.setPosition({x, y});
|
||||||
|
bg_sprite.setPosition({x, y});
|
||||||
|
|
||||||
if(tile == L'█') {
|
if(tile == L'█') {
|
||||||
sprite.setColor(sf::Color(100,100,100));
|
sprite.setColor(sf::Color(80,80,80));
|
||||||
} else if(tile == L'☺') {
|
} else if(tile == L'☺') {
|
||||||
sprite.setColor(sf::Color::Blue);
|
sprite.setColor(sf::Color::Blue);
|
||||||
} else if(tile == L'Ω') {
|
} else if(tile == L'Ω') {
|
||||||
sprite.setColor(sf::Color::Red);
|
sprite.setColor(sf::Color::Red);
|
||||||
} else if(tile == L'·') {
|
add_sprite.setColor(sf::Color::Red);
|
||||||
sprite.setColor(color(Value::DARK_MID));
|
add_sprite.setPosition({x-3,y-3});
|
||||||
|
has_add = true;
|
||||||
|
} else if(tile == L'#') {
|
||||||
|
sprite.setColor(sf::Color(5,5,5));
|
||||||
} else if(tile == L'\r') {
|
} else if(tile == L'\r') {
|
||||||
continue; // skip these, just windows junk
|
continue; // skip these, just windows junk
|
||||||
} else if(tile == L'\n') {
|
} else if(tile == L'\n') {
|
||||||
|
@ -171,8 +193,13 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
|
||||||
sprite.setColor(color(Value::MID));
|
sprite.setColor(color(Value::MID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$window.draw(bg_sprite);
|
||||||
$window.draw(sprite);
|
$window.draw(sprite);
|
||||||
x += glyph.advance;
|
if(has_add) {
|
||||||
|
$window.draw(add_sprite);
|
||||||
|
has_add = false;
|
||||||
|
}
|
||||||
|
x += base_glyph.advance;
|
||||||
}
|
}
|
||||||
|
|
||||||
$window.display();
|
$window.display();
|
||||||
|
|
3
gui.hpp
3
gui.hpp
|
@ -50,6 +50,7 @@ class GUI {
|
||||||
Screen $screen;
|
Screen $screen;
|
||||||
Screen $map_screen;
|
Screen $map_screen;
|
||||||
DinkyECS::World $world;
|
DinkyECS::World $world;
|
||||||
|
sf::Texture $font_texture;
|
||||||
std::unordered_map<wchar_t, sf::Sprite> $sprites;
|
std::unordered_map<wchar_t, sf::Sprite> $sprites;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -66,7 +67,7 @@ public:
|
||||||
void shake();
|
void shake();
|
||||||
void configure_world();
|
void configure_world();
|
||||||
void run_systems();
|
void run_systems();
|
||||||
sf::Sprite get_text_sprite(wchar_t tile);
|
sf::Sprite &get_text_sprite(wchar_t tile);
|
||||||
|
|
||||||
int main();
|
int main();
|
||||||
};
|
};
|
||||||
|
|
2
map.hpp
2
map.hpp
|
@ -11,7 +11,7 @@
|
||||||
#define WALL_VALUE 1
|
#define WALL_VALUE 1
|
||||||
#define SPACE_VALUE 0
|
#define SPACE_VALUE 0
|
||||||
#define WALL_TILE "█"
|
#define WALL_TILE "█"
|
||||||
#define FLOOR_TILE "·"
|
#define FLOOR_TILE "#"
|
||||||
#define PLAYER_TILE "☺"
|
#define PLAYER_TILE "☺"
|
||||||
#define ENEMY_TILE "Ω"
|
#define ENEMY_TILE "Ω"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue