Some jank test visual effects are working.

This commit is contained in:
Zed A. Shaw 2024-10-04 18:23:14 -04:00
parent 243d15c123
commit f9bf8f06ea
4 changed files with 66 additions and 18 deletions

52
gui.cpp
View file

@ -17,6 +17,7 @@
#include <fmt/core.h>
#include "dbc.hpp"
#include "gui.hpp"
#include "rand.hpp"
using std::string;
using namespace fmt;
@ -36,6 +37,10 @@ std::array<sf::Color, 10> VALUES{
sf::Color::Transparent, // white
};
sf::Color GUI::color(int val) {
return VALUES[size_t(val)];
}
sf::Color GUI::color(Value val) {
return VALUES[size_t(val)];
}
@ -128,6 +133,7 @@ void GUI::handle_events() {
$game_map.clear_target($player.location);
$player.move({x, y});
} else {
$shake_it = true;
$hit_sound.play();
}
@ -139,6 +145,7 @@ void GUI::handle_events() {
if($enemy.location.x == $player.location.x && $enemy.location.y == $player.location.y) {
$player.event(EntityEvent::HIT);
$burn_baby_burn = true;
} else if($goal.x == $player.location.x && $goal.y == $player.location.y) {
$status_text = "YOU WIN!";
}
@ -146,16 +153,53 @@ void GUI::handle_events() {
}
}
void GUI::burn() {
for(int i = 0; i < 20; ++i) {
$text.setFillColor(color(i % VALUES.size()));
int x = Random::rand_int(-10,10);
int y = Random::rand_int(-10,10);
$text.setPosition({(float)x,(float)y});
$window.draw($text);
$window.display();
std::this_thread::sleep_for(2ms);
}
$text.setFillColor(color(Value::LIGHT_DARK));
}
inline void draw_screen(sf::RenderWindow &window, sf::Text &text, float x=0, float y=0) {
text.setPosition({x,y});
window.clear();
window.draw(text);
window.display();
}
void GUI::shake() {
for(int i = 0; i < 10; ++i) {
int x = Random::rand_int(-10,10);
int y = Random::rand_int(-10,10);
draw_screen($window, $text, (float)x, (float)y);
std::this_thread::sleep_for(1ms);
}
}
void GUI::render_scene() {
Render($screen, $document->Render());
std::string $screenout = $screen.ToString();
std::wstring utf8 = $converter.from_bytes($screenout);
$text.setString(utf8);
$text.setPosition({0,0});
$window.clear();
$window.draw($text);
$window.display();
if($shake_it) {
shake();
$shake_it = false;
}
if($burn_baby_burn) {
burn();
$burn_baby_burn = false;
}
draw_screen($window, $text, 0, 0);
}
int GUI::main() {