diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-16 11:53:46 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-16 11:53:46 -0400 |
commit | 8713d03831226dcd559c6a1e2b1c7b0d7c660bac (patch) | |
tree | fd0c1e7ff253e3c69646d727bc49a112a71f5ca9 /src | |
parent | 4b52f51404aca45a7d5d8e5998649ff67df97bbd (diff) | |
download | ether-8713d03831226dcd559c6a1e2b1c7b0d7c660bac.tar.gz ether-8713d03831226dcd559c6a1e2b1c7b0d7c660bac.tar.bz2 ether-8713d03831226dcd559c6a1e2b1c7b0d7c660bac.zip |
added signs (which can't be read yet)
Diffstat (limited to 'src')
-rw-r--r-- | src/animation.h | 2 | ||||
-rw-r--r-- | src/direction.h | 12 | ||||
-rw-r--r-- | src/game.cpp | 70 | ||||
-rw-r--r-- | src/game.h | 14 | ||||
-rw-r--r-- | src/map.h | 5 | ||||
-rw-r--r-- | src/renderer.cpp | 22 | ||||
-rw-r--r-- | src/renderer.h | 1 |
7 files changed, 116 insertions, 10 deletions
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: | |||
20 | return frames_.at(animations_.at(animationId_).at(animationFrame_)); | 20 | return frames_.at(animations_.at(animationId_).at(animationFrame_)); |
21 | } | 21 | } |
22 | 22 | ||
23 | Direction getDirection() const { return dir_; } | ||
24 | |||
23 | void update(int dt); | 25 | void update(int dt); |
24 | 26 | ||
25 | private: | 27 | 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 @@ | |||
3 | 3 | ||
4 | #include <string_view> | 4 | #include <string_view> |
5 | #include <stdexcept> | 5 | #include <stdexcept> |
6 | #include <tuple> | ||
7 | |||
8 | using coord = std::tuple<int, int>; | ||
6 | 9 | ||
7 | enum class Direction { | 10 | enum class Direction { |
8 | up, | 11 | up, |
@@ -19,4 +22,13 @@ inline Direction directionFromString(std::string_view str) { | |||
19 | throw std::invalid_argument("Invalid direction: " + std::string(str)); | 22 | throw std::invalid_argument("Invalid direction: " + std::string(str)); |
20 | } | 23 | } |
21 | 24 | ||
25 | inline coord coordInDirection(int x, int y, Direction dir) { | ||
26 | switch (dir) { | ||
27 | case Direction::up: return {x, y-1}; | ||
28 | case Direction::down: return {x, y+1}; | ||
29 | case Direction::left: return {x-1, y}; | ||
30 | case Direction::right: return {x+1, y}; | ||
31 | } | ||
32 | } | ||
33 | |||
22 | #endif /* end of include guard: DIRECTION_H_42BDAFB9 */ | 34 | #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 @@ | |||
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(); |
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 @@ | |||
13 | #include "consts.h" | 13 | #include "consts.h" |
14 | 14 | ||
15 | constexpr int TilesetIndex(int x, int y) { | 15 | constexpr int TilesetIndex(int x, int y) { |
16 | return x + y * 24; | 16 | return x + y * 25; |
17 | } | 17 | } |
18 | 18 | ||
19 | enum class LoseState { | 19 | enum class LoseState { |
@@ -23,6 +23,13 @@ enum class LoseState { | |||
23 | Outro | 23 | Outro |
24 | }; | 24 | }; |
25 | 25 | ||
26 | enum class SignInstructionState { | ||
27 | Hidden, | ||
28 | FadingIn, | ||
29 | Visible, | ||
30 | FadingOut | ||
31 | }; | ||
32 | |||
26 | struct Input { | 33 | struct Input { |
27 | bool left = false; | 34 | bool left = false; |
28 | bool right = false; | 35 | bool right = false; |
@@ -100,6 +107,11 @@ public: | |||
100 | Timer losePopPlayerTimer = {3000}; | 107 | Timer losePopPlayerTimer = {3000}; |
101 | //Timer zoomTimer = {62}; | 108 | //Timer zoomTimer = {62}; |
102 | 109 | ||
110 | std::vector<std::string> signTexts; | ||
111 | int nextSignIndex = 0; | ||
112 | SignInstructionState signInstructionState = SignInstructionState::Hidden; | ||
113 | Interpolation signFade; | ||
114 | |||
103 | private: | 115 | private: |
104 | 116 | ||
105 | void tick( | 117 | 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 @@ | |||
8 | #include <map> | 8 | #include <map> |
9 | #include <random> | 9 | #include <random> |
10 | #include "consts.h" | 10 | #include "consts.h" |
11 | 11 | #include "direction.h" | |
12 | using coord = std::tuple<int, int>; | ||
13 | 12 | ||
14 | enum class Tile { | 13 | enum class Tile { |
15 | Floor, | 14 | Floor, |
@@ -35,6 +34,8 @@ struct MapData { | |||
35 | std::set<coord> litTiles; | 34 | std::set<coord> litTiles; |
36 | int renderId = -1; | 35 | int renderId = -1; |
37 | bool dirtyRender = true; | 36 | bool dirtyRender = true; |
37 | bool sign = false; | ||
38 | std::string text; | ||
38 | }; | 39 | }; |
39 | 40 | ||
40 | struct Chunk { | 41 | 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() | |||
109 | loadTextureFromFile("../res/player.png", playerSheet_); | 109 | loadTextureFromFile("../res/player.png", playerSheet_); |
110 | loadTextureFromFile("../res/runninbloods.png", tileset_); | 110 | loadTextureFromFile("../res/runninbloods.png", tileset_); |
111 | loadTextureFromFile("../res/lamp.png", lamp_); | 111 | loadTextureFromFile("../res/lamp.png", lamp_); |
112 | loadTextureFromFile("../res/read_instruction.png", readInstruction_); | ||
112 | 113 | ||
113 | loadTextureFromFile("../res/title0.png", titles_[0]); | 114 | loadTextureFromFile("../res/title0.png", titles_[0]); |
114 | SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); | 115 | SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); |
@@ -171,14 +172,14 @@ void Renderer::renderGame( | |||
171 | SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); | 172 | SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); |
172 | 173 | ||
173 | if (game.map.at(x,y).renderId != -1) { | 174 | if (game.map.at(x,y).renderId != -1) { |
174 | tileRect.x = game.map.at(x,y).renderId % 24 * 16; | 175 | tileRect.x = game.map.at(x,y).renderId % 25 * 16; |
175 | tileRect.y = game.map.at(x,y).renderId / 24 * 16; | 176 | tileRect.y = game.map.at(x,y).renderId / 25 * 16; |
176 | SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); | 177 | SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); |
177 | } | 178 | } |
178 | } else { | 179 | } else { |
179 | SDL_Rect tileRect { | 180 | SDL_Rect tileRect { |
180 | game.map.at(x,y).renderId % 24 * 16, | 181 | game.map.at(x,y).renderId % 25 * 16, |
181 | game.map.at(x,y).renderId / 24 * 16, | 182 | game.map.at(x,y).renderId / 25 * 16, |
182 | 16, | 183 | 16, |
183 | 16}; | 184 | 16}; |
184 | 185 | ||
@@ -375,6 +376,19 @@ void Renderer::renderGame( | |||
375 | } | 376 | } |
376 | 377 | ||
377 | SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); | 378 | SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); |
379 | |||
380 | if (game.signInstructionState != SignInstructionState::Hidden) { | ||
381 | int instOpacity = 255; | ||
382 | if (game.signInstructionState == SignInstructionState::FadingIn) { | ||
383 | instOpacity = game.signFade.getProgress(0, 255); | ||
384 | } else if (game.signInstructionState == SignInstructionState::FadingOut) { | ||
385 | instOpacity = game.signFade.getProgress(255, 0); | ||
386 | } | ||
387 | |||
388 | SDL_SetTextureAlphaMod(readInstruction_.get(), instOpacity); | ||
389 | SDL_RenderCopy(ren_.get(), readInstruction_.get(), nullptr, nullptr); | ||
390 | } | ||
391 | |||
378 | SDL_RenderPresent(ren_.get()); | 392 | SDL_RenderPresent(ren_.get()); |
379 | } | 393 | } |
380 | 394 | ||
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: | |||
137 | texture_ptr playerSheet_; | 137 | texture_ptr playerSheet_; |
138 | texture_ptr tileset_; | 138 | texture_ptr tileset_; |
139 | texture_ptr lamp_; | 139 | texture_ptr lamp_; |
140 | texture_ptr readInstruction_; | ||
140 | 141 | ||
141 | std::array<texture_ptr, NUM_TITLES> titles_; | 142 | std::array<texture_ptr, NUM_TITLES> titles_; |
142 | std::array<int, NUM_TITLES> titleWidths_; | 143 | std::array<int, NUM_TITLES> titleWidths_; |