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) --- res/childoflight.txt | 26 ++++++++++++++++++ res/read_instruction.png | Bin 0 -> 10146 bytes src/animation.h | 2 ++ src/direction.h | 12 ++++++++ src/game.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++-- src/game.h | 14 +++++++++- src/map.h | 5 ++-- src/renderer.cpp | 22 ++++++++++++--- src/renderer.h | 1 + 9 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 res/childoflight.txt create mode 100644 res/read_instruction.png diff --git a/res/childoflight.txt b/res/childoflight.txt new file mode 100644 index 0000000..d65796d --- /dev/null +++ b/res/childoflight.txt @@ -0,0 +1,26 @@ +"Your life, and the lives of those who believe in you. Are you willing to put it all on the line?" +Those words echoed in the child's head more than any other as he put his hands on the lamp. Through it, he could feel the sun's enormous presence far below him. Its power was palpable; a gentle thrumming that tickled his fingers. It was strong -- stronger and nearer than it had been with the other temples. Up close, it felt like all there was. +The lamp was light in his hands. Without a word he pulled, and light poured out. He closed his eyes and all he saw was light. +The child was nowhere when he awoke. Bright, white emptiness stretched out in all directions. He gulped as he looked around -- felt that emptiness resonate in his chest. +"Hello?" he called out. No one answered. +Trembling, he pushed himself to his feet. He'd been through countless battles, been spat on by people he used to trust, and even took down the immortal ruler of the world. He told himself he could handle whatever this was. +He hadn't had to do those things by himself, though. +The child took a step. His bare foot thudded against an invisible ground. When nothing further happened, he kept going. Choose a direction and just walk, he thought. There was nothing else to do. +"Is anyone out there?" +His steps turned inside out. The ground flipped over and curved in on itself. He saw figures in the distance but when he approached he realized it was himself he was seeing. He felt a headache start to come on, and it only grew when something finally did appear. +A black spiral, twisting out from beneath him. He climbed and climbed, and his feet hurt and his chest ached and his arms twisted but it wasn't enough to take him down. Somehow he felt like nothing would ever be able to stop him again. One foot after another he climbed and watched the matter splay out before him. This thing he'd found, it was immense. It was infinite. +It was the Sun. +"Pure hearted one," it said without saying, not a roaring voice but a subtle understanding planted in the child's mind. "We meet at last." +The child gulped. Throughout all that time searching for and sanctifying the lamps, he hadn't considered what would actually happen if he won. But now here he was, facing infinity itself, and it dawned on him the Sun had probably been sealed away for a good reason. +Would saving the world be worth the consequences? +"H-hello?" he stammered. It came out as nothing more than a squeak, but a shift in the Sun's surface -- starry as the night sky -- told him that it heard. +"For thousands of years I have slept here, ever since the world grew past the need for my power." +An eye -- incomprehensibly large -- regarded the boy who'd raised it from its slumber. An eye which had seen countless things: births, deaths, loves, wars. A being who'd caused so many of them, and had to be shut away to contain its limitless power. A power that was once again free. +The child took a deep breath. "I'm sorry I woke you up," he said, voice wobbling like a teeter totter. "I had to light the lamps to stop someone else from doing it. He wanted to end the world. But I want to save it." +"I've seen visions in my dreams of your world crumbling. I've felt your despair. I've heard your cries for help. I've seen your strength, clear as day, in the pieces of your heart that you shared." +The child saw himself reflected in that eye. Saw his feet lift off the ground, pulled by some invisible force. Saw the sparks of magic flying around his hands, felt his being churning out of control as something dark, something horrible, something unfathomably ancient poured into his mind, squeezing and pulling it like taffy, tearing it apart and putting it back together. +"Now my power is needed once again. As you have shared with me, I will share it in return." +"Wh-" he tried to ask, but his throat squeezed tight and choked the words to death. Sweat poured from his brow as the worst fever he'd ever felt took hold. His head was being thrust beneath the surface of the water, his torso was being struck by lightning from a machine. +The Sun watched him float there, writhing and sweating and sparking with violent electricity. It closed its eye. +"I promise you that I will not miss it." +The thrumming from before was inside of him now. The Sun's heartbeat was gone -- it was his own. The child opened his mouth to scream, and what came out was light. \ No newline at end of file diff --git a/res/read_instruction.png b/res/read_instruction.png new file mode 100644 index 0000000..6e924e6 Binary files /dev/null and b/res/read_instruction.png differ diff --git a/src/animation.h b/src/animation.h index 0108c12..f1eddb6 100644 --- a/src/animation.h +++ b/src/animation.h @@ -20,6 +20,8 @@ public: return frames_.at(animations_.at(animationId_).at(animationFrame_)); } + Direction getDirection() const { return dir_; } + void update(int dt); private: diff --git a/src/direction.h b/src/direction.h index 0fe3e5a..14ea0a5 100644 --- a/src/direction.h +++ b/src/direction.h @@ -3,6 +3,9 @@ #include #include +#include + +using coord = std::tuple; enum class Direction { up, @@ -19,4 +22,13 @@ inline Direction directionFromString(std::string_view str) { throw std::invalid_argument("Invalid direction: " + std::string(str)); } +inline coord coordInDirection(int x, int y, Direction dir) { + switch (dir) { + case Direction::up: return {x, y-1}; + case Direction::down: return {x, y+1}; + case Direction::left: return {x-1, y}; + case Direction::right: return {x+1, y}; + } +} + #endif /* end of include guard: DIRECTION_H_42BDAFB9 */ 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(); diff --git a/src/game.h b/src/game.h index f307156..71685e6 100644 --- a/src/game.h +++ b/src/game.h @@ -13,7 +13,7 @@ #include "consts.h" constexpr int TilesetIndex(int x, int y) { - return x + y * 24; + return x + y * 25; } enum class LoseState { @@ -23,6 +23,13 @@ enum class LoseState { Outro }; +enum class SignInstructionState { + Hidden, + FadingIn, + Visible, + FadingOut +}; + struct Input { bool left = false; bool right = false; @@ -100,6 +107,11 @@ public: Timer losePopPlayerTimer = {3000}; //Timer zoomTimer = {62}; + std::vector signTexts; + int nextSignIndex = 0; + SignInstructionState signInstructionState = SignInstructionState::Hidden; + Interpolation signFade; + private: void tick( diff --git a/src/map.h b/src/map.h index 2faac85..de74b14 100644 --- a/src/map.h +++ b/src/map.h @@ -8,8 +8,7 @@ #include #include #include "consts.h" - -using coord = std::tuple; +#include "direction.h" enum class Tile { Floor, @@ -35,6 +34,8 @@ struct MapData { std::set litTiles; int renderId = -1; bool dirtyRender = true; + bool sign = false; + std::string text; }; struct Chunk { diff --git a/src/renderer.cpp b/src/renderer.cpp index befad8a..2be36ae 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -109,6 +109,7 @@ Renderer::Renderer() loadTextureFromFile("../res/player.png", playerSheet_); loadTextureFromFile("../res/runninbloods.png", tileset_); loadTextureFromFile("../res/lamp.png", lamp_); + loadTextureFromFile("../res/read_instruction.png", readInstruction_); loadTextureFromFile("../res/title0.png", titles_[0]); SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); @@ -171,14 +172,14 @@ void Renderer::renderGame( SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); if (game.map.at(x,y).renderId != -1) { - tileRect.x = game.map.at(x,y).renderId % 24 * 16; - tileRect.y = game.map.at(x,y).renderId / 24 * 16; + tileRect.x = game.map.at(x,y).renderId % 25 * 16; + tileRect.y = game.map.at(x,y).renderId / 25 * 16; SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); } } else { SDL_Rect tileRect { - game.map.at(x,y).renderId % 24 * 16, - game.map.at(x,y).renderId / 24 * 16, + game.map.at(x,y).renderId % 25 * 16, + game.map.at(x,y).renderId / 25 * 16, 16, 16}; @@ -375,6 +376,19 @@ void Renderer::renderGame( } SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); + + if (game.signInstructionState != SignInstructionState::Hidden) { + int instOpacity = 255; + if (game.signInstructionState == SignInstructionState::FadingIn) { + instOpacity = game.signFade.getProgress(0, 255); + } else if (game.signInstructionState == SignInstructionState::FadingOut) { + instOpacity = game.signFade.getProgress(255, 0); + } + + SDL_SetTextureAlphaMod(readInstruction_.get(), instOpacity); + SDL_RenderCopy(ren_.get(), readInstruction_.get(), nullptr, nullptr); + } + SDL_RenderPresent(ren_.get()); } diff --git a/src/renderer.h b/src/renderer.h index 1364550..de1e125 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -137,6 +137,7 @@ private: texture_ptr playerSheet_; texture_ptr tileset_; texture_ptr lamp_; + texture_ptr readInstruction_; std::array titles_; std::array titleWidths_; -- cgit 1.4.1