diff options
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 70 |
1 files changed, 67 insertions, 3 deletions
| 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 @@ | |||
| 2 | #include <vector> | 2 | #include <vector> |
| 3 | #include <fov.h> | 3 | #include <fov.h> |
| 4 | #include <iostream> | 4 | #include <iostream> |
| 5 | #include <fstream> | ||
| 5 | #include "util.h" | 6 | #include "util.h" |
| 6 | #include "renderer.h" | 7 | #include "renderer.h" |
| 7 | #include "consts.h" | 8 | #include "consts.h" |
| @@ -23,6 +24,12 @@ Game::Game(std::mt19937& rng, Muxer& muxer) : | |||
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | tick(); | 26 | tick(); |
| 27 | |||
| 28 | std::ifstream textFile("../res/childoflight.txt"); | ||
| 29 | std::string line; | ||
| 30 | while (std::getline(textFile, line)) { | ||
| 31 | signTexts.push_back(line); | ||
| 32 | } | ||
| 26 | } | 33 | } |
| 27 | 34 | ||
| 28 | inline bool isTileSetOrNotLit(const Map& map, int x, int y) | 35 | inline bool isTileSetOrNotLit(const Map& map, int x, int y) |
| @@ -119,7 +126,7 @@ void Game::tick(bool onlyDark) | |||
| 119 | 126 | ||
| 120 | bool Game::movePlayer(int x, int y) | 127 | bool Game::movePlayer(int x, int y) |
| 121 | { | 128 | { |
| 122 | if (map.at(x,y).tile == Tile::Floor) | 129 | if (map.at(x,y).tile == Tile::Floor && !map.at(x,y).sign) |
| 123 | { | 130 | { |
| 124 | if (map.at(player_x, player_y).tile == Tile::Floor) | 131 | if (map.at(player_x, player_y).tile == Tile::Floor) |
| 125 | { | 132 | { |
| @@ -258,16 +265,36 @@ void Game::recalculateRender() { | |||
| 258 | map.at(x,y).dirtyRender = false; | 265 | map.at(x,y).dirtyRender = false; |
| 259 | 266 | ||
| 260 | if (map.at(x,y).tile == Tile::Floor) { | 267 | if (map.at(x,y).tile == Tile::Floor) { |
| 261 | if (std::bernoulli_distribution(0.05)(rng)) { | 268 | int renderDesc = 0; |
| 269 | if (isTileSetOrNotLit(map, x-1, y-1)) renderDesc |= (1 << 7); | ||
| 270 | if (isTileSetOrNotLit(map, x , y-1)) renderDesc |= (1 << 6); | ||
| 271 | if (isTileSetOrNotLit(map, x+1, y-1)) renderDesc |= (1 << 5); | ||
| 272 | if (isTileSetOrNotLit(map, x+1, y )) renderDesc |= (1 << 4); | ||
| 273 | if (isTileSetOrNotLit(map, x+1, y+1)) renderDesc |= (1 << 3); | ||
| 274 | if (isTileSetOrNotLit(map, x , y+1)) renderDesc |= (1 << 2); | ||
| 275 | if (isTileSetOrNotLit(map, x-1, y+1)) renderDesc |= (1 << 1); | ||
| 276 | if (isTileSetOrNotLit(map, x-1, y )) renderDesc |= (1 << 0); | ||
| 277 | |||
| 278 | if (renderDesc == 0 && map.at(x,y).sign) { | ||
| 279 | map.at(x,y).renderId = TilesetIndex(24, 13); | ||
| 280 | } else if (std::bernoulli_distribution(0.05)(rng)) { | ||
| 262 | static const std::vector<int> furnishings { | 281 | static const std::vector<int> furnishings { |
| 263 | TilesetIndex(20, 16), | 282 | TilesetIndex(20, 16), |
| 264 | TilesetIndex(21, 2), | 283 | TilesetIndex(21, 2), |
| 265 | TilesetIndex(22, 2), | 284 | TilesetIndex(22, 2), |
| 266 | TilesetIndex(21, 3), | 285 | TilesetIndex(21, 3), |
| 267 | TilesetIndex(22, 3)}; | 286 | TilesetIndex(22, 3)}; |
| 268 | map.at(x,y).renderId = furnishings.at(std::uniform_int_distribution<int>(0, furnishings.size()-1)(rng)); | 287 | |
| 288 | if (renderDesc == 0 && !(x == player_x && y == player_y) && std::bernoulli_distribution(0.2)(rng)) { | ||
| 289 | map.at(x,y).renderId = TilesetIndex(24, 13); | ||
| 290 | map.at(x,y).sign = true; | ||
| 291 | } else { | ||
| 292 | map.at(x,y).renderId = furnishings.at(std::uniform_int_distribution<int>(0, furnishings.size()-1)(rng)); | ||
| 293 | map.at(x,y).sign = false; | ||
| 294 | } | ||
| 269 | } else { | 295 | } else { |
| 270 | map.at(x,y).renderId = -1; | 296 | map.at(x,y).renderId = -1; |
| 297 | map.at(x,y).sign = false; | ||
| 271 | } | 298 | } |
| 272 | } else if (map.at(x,y).tile == Tile::Wall) { | 299 | } else if (map.at(x,y).tile == Tile::Wall) { |
| 273 | static bool initWalls = false; | 300 | static bool initWalls = false; |
| @@ -785,6 +812,43 @@ void Game::update(size_t frameTime) { | |||
| 785 | } | 812 | } |
| 786 | } | 813 | } |
| 787 | 814 | ||
| 815 | switch (signInstructionState) { | ||
| 816 | case SignInstructionState::Hidden: { | ||
| 817 | auto [lookX, lookY] = coordInDirection(player_x, player_y, playerAnim.getDirection()); | ||
| 818 | if (map.at(lookX, lookY).sign) { | ||
| 819 | signInstructionState = SignInstructionState::FadingIn; | ||
| 820 | signFade.start(1000); | ||
| 821 | } | ||
| 822 | |||
| 823 | break; | ||
| 824 | } | ||
| 825 | case SignInstructionState::FadingIn: { | ||
| 826 | signFade.tick(frameTime); | ||
| 827 | if (signFade.isComplete()) { | ||
| 828 | signInstructionState = SignInstructionState::Visible; | ||
| 829 | } | ||
| 830 | |||
| 831 | break; | ||
| 832 | } | ||
| 833 | case SignInstructionState::Visible: { | ||
| 834 | auto [lookX, lookY] = coordInDirection(player_x, player_y, playerAnim.getDirection()); | ||
| 835 | if (!map.at(lookX, lookY).sign || losing != LoseState::None) { | ||
| 836 | signInstructionState = SignInstructionState::FadingOut; | ||
| 837 | signFade.start(1000); | ||
| 838 | } | ||
| 839 | |||
| 840 | break; | ||
| 841 | } | ||
| 842 | case SignInstructionState::FadingOut: { | ||
| 843 | signFade.tick(frameTime); | ||
| 844 | if (signFade.isComplete()) { | ||
| 845 | signInstructionState = SignInstructionState::Hidden; | ||
| 846 | } | ||
| 847 | |||
| 848 | break; | ||
| 849 | } | ||
| 850 | } | ||
| 851 | |||
| 788 | if (dirtyLighting) | 852 | if (dirtyLighting) |
| 789 | { | 853 | { |
| 790 | recalculateLighting(); | 854 | recalculateLighting(); |
