Skip to content

Commit 4fb28b8

Browse files
committed
Create anim namespace and implement print_splash_screen
1 parent 79aefc2 commit 4fb28b8

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/anim.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#include <algorithm>
22
#include <filesystem>
33
#include <iostream>
4+
#include <numeric>
45
#include <string>
56
#include <vector>
7+
8+
#include <str_format/str_format.hpp>
9+
610
#include "models.hpp"
711
#include "utils.hpp"
8-
#include <str_format/str_format.hpp>
912

10-
std::vector<std::string> gen_healthbar(Pokemon& pkmn)
13+
namespace anim
14+
{
15+
std::vector<std::string> gen_healthbar(models::Pokemon& pkmn)
1116
{
1217
/*
1318
* bulbasaur :L30 // label
@@ -24,7 +29,7 @@ std::vector<std::string> gen_healthbar(Pokemon& pkmn)
2429

2530
std::string stars = std::string(hp_scaled, '*');
2631
stars = stars.append(std::string(10 - hp_scaled, ' '));
27-
Color star_color = (hp_scaled >= 5) ? Color::GREEN : (3 < hp_scaled && hp_scaled < 5) ? Color::YELLOW : Color::RED;
32+
utils::Color star_color = (hp_scaled >= 5) ? utils::Color::GREEN : (3 < hp_scaled && hp_scaled < 5) ? utils::Color::YELLOW : utils::Color::RED;
2833
std::string progressbar = kt::format_str("HP [{}]", style(stars, star_color));
2934
progressbar = std::string(max_width - 15, ' ').append(progressbar);
3035

@@ -34,7 +39,21 @@ std::vector<std::string> gen_healthbar(Pokemon& pkmn)
3439
return {label, progressbar, hitpoints};
3540
}
3641

37-
void print_frame(Pokemon& pkmn1, Pokemon& pkmn2)
42+
void print_splash_screen(const std::filesystem::path& assets_dir)
43+
{
44+
auto logo = utils::read_file(assets_dir / std::filesystem::path("splashscreen.txt"));
45+
std::cout << utils::style(std::accumulate(logo.begin(), logo.end(), std::string("")), utils::Color::YELLOW) << '\n';
46+
47+
std::cout << '\n' << std::string(19, ' ');
48+
49+
for (const char& c : "copyright (c) 2021 cpp-gamedev")
50+
{
51+
std::cout << c;
52+
utils::sleep(100);
53+
}
54+
}
55+
56+
void print_frame(models::Pokemon& pkmn1, models::Pokemon& pkmn2)
3857
{
3958
std::string healthbars{};
4059
std::string sprites{};
@@ -63,3 +82,4 @@ void print_frame(Pokemon& pkmn1, Pokemon& pkmn2)
6382

6483
return;
6584
}
85+
} // namespace anim

src/anim.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
#include<string>
44
#include<vector>
5+
56
#include "models.hpp"
67

7-
std::vector<std::string> gen_healthbar(Pokemon& pkmn);
8+
namespace anim
9+
{
10+
std::vector<std::string> gen_healthbar(models::Pokemon& pkmn);
11+
12+
void print_splash_screen(const std::filesystem::path& assets_dir);
813

9-
void print_frame(Pokemon& pkmn1, Pokemon& pkmn2);
14+
void print_frame(models::Pokemon& pkmn1, models::Pokemon& pkmn2);
15+
} // namespace anim

0 commit comments

Comments
 (0)