From 8713d03831226dcd559c6a1e2b1c7b0d7c660bac Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 16 Mar 2022 11:53:46 -0400 Subject: added signs (which can't be read yet) --- src/game.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 170f584..301447f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "util.h" #include "renderer.h" #include "consts.h" @@ -23,6 +24,12 @@ Game::Game(std::mt19937& rng, Muxer& muxer) : } tick(); + + std::ifstream textFile("../res/childoflight.txt"); + std::string line; + while (std::getline(textFile, line)) { + signTexts.push_back(line); + } } inline bool isTileSetOrNotLit(const Map& map, int x, int y) @@ -119,7 +126,7 @@ void Game::tick(bool onlyDark) bool Game::movePlayer(int x, int y) { - if (map.at(x,y).tile == Tile::Floor) + if (map.at(x,y).tile == Tile::Floor && !map.at(x,y).sign) { if (map.at(player_x, player_y).tile == Tile::Floor) { @@ -258,16 +265,36 @@ void Game::recalculateRender() { map.at(x,y).dirtyRender = false; if (map.at(x,y).tile == Tile::Floor) { - if (std::bernoulli_distribution(0.05)(rng)) { + int renderDesc = 0; + if (isTileSetOrNotLit(map, x-1, y-1)) renderDesc |= (1 << 7); + if (isTileSetOrNotLit(map, x , y-1)) renderDesc |= (1 << 6); + if (isTileSetOrNotLit(map, x+1, y-1)) renderDesc |= (1 << 5); + if (isTileSetOrNotLit(map, x+1, y )) renderDesc |= (1 << 4); + if (isTileSetOrNotLit(map, x+1, y+1)) renderDesc |= (1 << 3); + if (isTileSetOrNotLit(map, x , y+1)) renderDesc |= (1 << 2); + if (isTileSetOrNotLit(map, x-1, y+1)) renderDesc |= (1 << 1); + if (isTileSetOrNotLit(map, x-1, y )) renderDesc |= (1 << 0); + + if (renderDesc == 0 && map.at(x,y).sign) { + map.at(x,y).renderId = TilesetIndex(24, 13); + } else if (std::bernoulli_distribution(0.05)(rng)) { static const std::vector furnishings { TilesetIndex(20, 16), TilesetIndex(21, 2), TilesetIndex(22, 2), TilesetIndex(21, 3), TilesetIndex(22, 3)}; - map.at(x,y).renderId = furnishings.at(std::uniform_int_distribution(0, furnishings.size()-1)(rng)); + + if (renderDesc == 0 && !(x == player_x && y == player_y) && std::bernoulli_distribution(0.2)(rng)) { + map.at(x,y).renderId = TilesetIndex(24, 13); + map.at(x,y).sign = true; + } else { + map.at(x,y).renderId = furnishings.at(std::uniform_int_distribution(0, furnishings.size()-1)(rng)); + map.at(x,y).sign = false; + } } else { map.at(x,y).renderId = -1; + map.at(x,y).sign = false; } } else if (map.at(x,y).tile == Tile::Wall) { static bool initWalls = false; @@ -785,6 +812,43 @@ void Game::update(size_t frameTime) { } } + switch (signInstructionState) { + case SignInstructionState::Hidden: { + auto [lookX, lookY] = coordInDirection(player_x, player_y, playerAnim.getDirection()); + if (map.at(lookX, lookY).sign) { + signInstructionState = SignInstructionState::FadingIn; + signFade.start(1000); + } + + break; + } + case SignInstructionState::FadingIn: { + signFade.tick(frameTime); + if (signFade.isComplete()) { + signInstructionState = SignInstructionState::Visible; + } + + break; + } + case SignInstructionState::Visible: { + auto [lookX, lookY] = coordInDirection(player_x, player_y, playerAnim.getDirection()); + if (!map.at(lookX, lookY).sign || losing != LoseState::None) { + signInstructionState = SignInstructionState::FadingOut; + signFade.start(1000); + } + + break; + } + case SignInstructionState::FadingOut: { + signFade.tick(frameTime); + if (signFade.isComplete()) { + signInstructionState = SignInstructionState::Hidden; + } + + break; + } + } + if (dirtyLighting) { recalculateLighting(); -- cgit 1.4.1