Some jank test visual effects are working.

main
Zed A. Shaw 3 months ago
parent 243d15c123
commit f9bf8f06ea
  1. 52
      gui.cpp
  2. 7
      gui.hpp
  3. 23
      map.cpp
  4. 2
      meson.build

@ -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() {

@ -30,7 +30,6 @@ enum class Value {
};
class GUI {
sf::Color color(Value val);
Map $game_map;
sf::SoundBuffer $hit_buf;
sf::Sound $hit_sound;
@ -44,6 +43,8 @@ class GUI {
Canvas $canvas;
sf::Font $font;
sf::Text $text;
bool $shake_it = false;
bool $burn_baby_burn = false;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
sf::RenderWindow $window;
Screen $screen;
@ -53,9 +54,13 @@ public:
// disable copying
GUI(GUI &gui) = delete;
sf::Color color(Value val);
sf::Color color(int val);
void create_renderer();
void render_scene();
void handle_events();
void shake();
void burn();
int main();
};

@ -2,11 +2,9 @@
#include "dbc.hpp"
#include <vector>
#include <fmt/core.h>
#include <random>
#include "rand.hpp"
#include <utility>
std::random_device $RNG;
std::mt19937 $GENERATOR($RNG());
using std::vector, std::pair;
using namespace fmt;
@ -116,8 +114,8 @@ inline int make_split(Room &cur, bool horiz) {
size_t dimension = horiz ? cur.height : cur.width;
int min = dimension / 4;
int max = dimension - min;
std::uniform_int_distribution<int> rand_dim(min, max);
return rand_dim($GENERATOR);
return Random::rand_int(min, max);
}
void Map::partition_map(Room &cur, int depth) {
@ -212,26 +210,25 @@ void Map::set_door(Room &room, int value) {
}
void rand_side(Room &room, Point &door) {
std::uniform_int_distribution<int> rand_side(0, 3);
std::uniform_int_distribution<int> rand_x(0, room.width - 1);
std::uniform_int_distribution<int> rand_y(0, room.height - 1);
int rand_x = Random::rand_int(0, room.width - 1);
int rand_y = Random::rand_int(0, room.height - 1);
switch(rand_side($GENERATOR)) {
switch(Random::rand_int(0,3)) {
case 0: // north
door.x = room.x + rand_x($GENERATOR);
door.x = room.x + rand_x;
door.y = room.y-1;
break;
case 1: // south
door.x = room.x + rand_x($GENERATOR);
door.x = room.x + rand_x;
door.y = room.y + room.height;
break;
case 2: // east
door.x = room.x + room.width;
door.y = room.y + rand_y($GENERATOR);
door.y = room.y + rand_y;
break;
case 3: // west
door.x = room.x - 1;
door.y = room.y + rand_y($GENERATOR);
door.y = room.y + rand_y;
break;
default:
dbc::sentinel("impossible side");

@ -17,6 +17,7 @@ runtests = executable('runtests', [
'dbc.cpp',
'map.cpp',
'entity.cpp',
'rand.cpp',
'tests/fsm.cpp',
'tests/dbc.cpp',
'tests/map.cpp',
@ -28,6 +29,7 @@ roguish = executable('roguish', [
'main.cpp',
'map.cpp',
'gui.cpp',
'rand.cpp',
'entity.cpp',
],
dependencies: dependencies)

Loading…
Cancel
Save