Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ assets/textures/*.txt
assets/data/*.json
manifest.json

# VS
CMakeSettings.json

# VSCode, clangd etc
.vscode/
.cache/
Expand Down
28 changes: 28 additions & 0 deletions EasyInstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Write-Host -ForegroundColor Yellow "+++ PKMN Asset Builder +++"

Write-Host "`nAccording to the National Pok\u00e9mon Index, the first 151 entries served in Generation I."
Write-Host "You may use any of these numbers to create new asset files to play this game.`n"

$ID1 = Read-Host "Pokemon ID #1"
$ID2 = Read-Host "Pokemon ID #2"

if ( -not (Test-Path -Path "venv" -PathType Container) )
{
Write-Host -ForegroundColor Yellow "Creating a new virtual environment . . ."
python -m venv venv/
.\venv\Scripts\Activate.ps1
Write-Host "Installing dependencies . . ."
python -m pip install --upgrade pip
python -m pip install -r requirements.txt --only-binary all
}
else
{
.\venv\Scripts\Activate.ps1
}

python gen_data.py --verbose make --id $ID1 $ID2
python gen_data.py manifest

Write-Host -ForegroundColor Yellow "Done!"

deactivate # virtual environment
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@
</a>
</p>

## Build & Debug
## For Users: Playing the Game

Go to [Releases](https://github.com/cpp-gamedev/pkmn/releases) and download the
latest version of `pkmn-x64-linux-windows-v1.0.0-*.zip`. Unzip this directory, then

- run `easy_install.sh` (Linux)
- run `EasyInstall.ps1` (Windows)

to configure the game. This process may take a minute or two depending on your
internet connection. After that, run the `pkmn` binary (`pkmn.exe` on Windows)
to start the game. The game takes up quite a bit of vertical space, so you may
want to adjust the size of your terminal.

## For Developers: Build & Debug the Game

Initialize and update all submodules after you have cloned this repository:

Expand All @@ -34,12 +47,6 @@ environments on Linux.

### Generating new Pokemon

---

*Note: You can also use the `./easy_install.sh` script to skip this section.*

---

If this is your first time using a python script, use

```bash
Expand Down
5 changes: 2 additions & 3 deletions easy_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fi
python3 gen_data.py --verbose make --id $id1 $id2
python3 gen_data.py manifest

echo "Updating submodules . . ."
git submodule update --init --recursive

echo "Done!"

deactivate # virtual environment
2 changes: 1 addition & 1 deletion src/anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void print_splash_screen(const std::filesystem::path& assets_dir)

std::cout << '\n' << std::setfill(' ') << std::setw(19);

utils::slow_print("copyright (c) 2021 cpp-gamedev", std::chrono::milliseconds{50});
utils::delayed_print("copyright (c) 2021 cpp-gamedev", std::chrono::milliseconds{50});
}

void print_move_table(const models::Pokemon& pkmn)
Expand Down
7 changes: 3 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ int main()

auto pkmns = load_main_menu(manifest);
auto& [player, ai] = pkmns;
clear_screen();

while (player.hp > 0 && ai.hp > 0)
{
clear_screen();
player.make_move(ai, print_frame(player, ai));

if (ai.hp > 0)
{
sleep(1000ms);
ai.make_move(player, random_range<std::size_t>(1, 4));
clear_screen();
}
}

clear_screen();
slow_print((ai.hp == 0) ? "You Won :)" : "You Lost :(", 50ms);
std::cout << '\n';
delayed_print((ai.hp == 0) ? "You Won :)" : "You Lost :(", 50ms);

return EXIT_SUCCESS;
}
Expand Down
13 changes: 7 additions & 6 deletions src/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void Pokemon::configure_move_set()
if (move.power > 0 && move.accuracy > 0)
{
move.type = MoveType::ATTACK;
move.accuracy = utils::random_range<int>(this->difficulty == Difficulty::EASY ? 5 : (this->difficulty == Difficulty::MODERATE) ? 6 : 7, 10) * 10;
move.power += this->difficulty == Difficulty::EASY ? -20 : (this->difficulty == Difficulty::MODERATE) ? 0 : 20;
move.power = abs(move.power);
move.flavor_text = kt::format_str("{} deals {} points in damage.", move.name, move.power);
Expand Down Expand Up @@ -107,30 +108,30 @@ void Pokemon::make_move(Pokemon& pkmn, std::size_t index)
int damage = std::ceil(move.power * (this->atk * 100) / (100 * pkmn.def));
pkmn.hp -= damage;
pkmn.hp = (pkmn.hp < 0) ? 0 : pkmn.hp;
msg = kt::format_str("{} used {} and inflicts {} points in damage!", this->name, move.name, damage);
msg = kt::format_str("{} uses {}! and inflicts {} points in damage!", this->name, move.name, damage);
}
else
{
msg = kt::format_str("{} missed his target!", this->name);
msg = kt::format_str("{} uses {}! The ATTACK missed its target!", this->name, move.name);
}
break;
case MoveType::HEAL:
this->hp += move.power;
this->hp = (this->hp > this->max_hp) ? this->max_hp : this->hp;
msg = kt::format_str("{} increased his HP by {} points", this->name, move.power);
msg = kt::format_str("{} increased its HP by {} points", this->name, move.power);
break;
case MoveType::BOOST_ATK:
this->atk += move.power;
msg = kt::format_str("{} increased his ATTACK by {}%!", this->name, move.power);
msg = kt::format_str("{} increased its ATTACK by {}%!", this->name, move.power);
break;
case MoveType::BOOST_DEF:
this->def += move.power;
msg = kt::format_str("{} increased his DEFENSE by {}%!", this->name, move.power);
msg = kt::format_str("{} increased its DEFENSE by {}%!", this->name, move.power);
break;
default:
break;
}

utils::slow_print(msg, std::chrono::milliseconds{50});
utils::delayed_print(msg, std::chrono::milliseconds{25});
}
} // namespace models
6 changes: 3 additions & 3 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ void sleep(std::chrono::milliseconds ms)
std::this_thread::sleep_for(ms);
}

void slow_print(const std::string& str, std::chrono::milliseconds ms)
void delayed_print(std::string_view msg, std::chrono::milliseconds ms)
{
for (char c : str)
for (char c : msg)
{
std::cout << c;
std::cout << c << std::flush;
sleep(ms);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void clear_screen();

void sleep(std::chrono::milliseconds ms);

void slow_print(const std::string& str, std::chrono::milliseconds ms);
void delayed_print(std::string_view msg, std::chrono::milliseconds ms);

enum class Color
{
Expand Down