Got some new sounds and camera shake came back but has a bug.

This commit is contained in:
Zed A. Shaw 2024-11-08 13:18:43 -05:00
parent ed9d0de8e0
commit 113811bc84
10 changed files with 30 additions and 9 deletions

24
gui.cpp
View file

@ -39,7 +39,11 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
$renderer($canvas, $map_screen, $screen)
{
// this needs a config file soon
$sounds.load("hit", "hit.wav");
$sounds.load("ambient", "ambient_sound.mp3");
$sounds.load("loot_gold", "loot_gold.mp3");
$sounds.load("combat_player_hit", "combat_player_hit.mp3");
$sounds.load("combat_enemy_hit", "combat_enemy_hit.mp3");
$sounds.load("combat_miss", "combat_miss.flac");
resize_map(BASE_MAP_FONT_SIZE);
}
@ -114,21 +118,24 @@ void GUI::handle_world_events() {
if(damage.enemy_did > 0) {
$log.log(format("Enemy HIT YOU for {} damage!", damage.enemy_did));
$log.log(format("-- Enemy has {} HP left.", enemy_combat.hp));
$sounds.play("hit");
$sounds.play("combat_enemy_hit");
shake();
} else {
$log.log("Enemy MISSED YOU.");
}
if(damage.player_did > 0) {
$log.log(format("You HIT enemy for {} damage!", damage.player_did));
$sounds.play("hit");
$sounds.play("combat_player_hit");
} else {
$sounds.play("combat_miss");
$log.log("You MISSED the enemy.");
}
} break;
case eGUI::LOOT: {
auto &loot = std::any_cast<Loot&>(data);
auto inventory = $world.get<Inventory>(player.entity);
$sounds.play("loot_gold");
$log.log(format("You found {} gold. You have {} now.",
loot.amount, inventory.gold));
}
@ -185,6 +192,16 @@ void GUI::run_systems() {
System::death($world);
}
void GUI::shake() {
for(int i = 0; i < 10; ++i) {
int x = Random::uniform<int>(-10,10);
int y = Random::uniform<int>(-10,10);
// add x/y back to draw screen
$renderer.draw_screen(true, x, y);
std::this_thread::sleep_for(1ms);
}
}
void GUI::render_scene() {
$screen.Clear();
$map_screen.Clear();
@ -194,6 +211,7 @@ void GUI::render_scene() {
}
int GUI::main() {
// $sounds.play("ambient");
create_renderer();
run_systems();