diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 5 | ||||
-rw-r--r-- | src/map.cpp | 2 | ||||
-rw-r--r-- | src/map.h | 1 | ||||
-rw-r--r-- | src/renderer.cpp | 6 | ||||
-rw-r--r-- | src/sprite.h | 1 |
5 files changed, 15 insertions, 0 deletions
diff --git a/src/game.cpp b/src/game.cpp index fcd5f44..d1e5b8e 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -34,6 +34,7 @@ void Game::loadMap(std::string filename, std::string warpPoint, Direction dir) { | |||
34 | getSystem<TransformSystem>().setUpCollision(lucasSprite, {-8, -8}, {12, 8}, true); | 34 | getSystem<TransformSystem>().setUpCollision(lucasSprite, {-8, -8}, {12, 8}, true); |
35 | getSystem<AnimationSystem>().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt"); | 35 | getSystem<AnimationSystem>().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt"); |
36 | getSystem<AnimationSystem>().setSpriteDirection(lucasSprite, dir); | 36 | getSystem<AnimationSystem>().setSpriteDirection(lucasSprite, dir); |
37 | getSprite(lucasSprite).hasShadow = true; | ||
37 | getSprite(lucasSprite).player = true; | 38 | getSprite(lucasSprite).player = true; |
38 | getSystem<CharacterSystem>().initSprite(lucasSprite); | 39 | getSystem<CharacterSystem>().initSprite(lucasSprite); |
39 | 40 | ||
@@ -41,18 +42,21 @@ void Game::loadMap(std::string filename, std::string warpPoint, Direction dir) { | |||
41 | getSystem<TransformSystem>().initSprite(kumaSprite, warpLoc); | 42 | getSystem<TransformSystem>().initSprite(kumaSprite, warpLoc); |
42 | getSystem<AnimationSystem>().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt"); | 43 | getSystem<AnimationSystem>().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt"); |
43 | getSystem<AnimationSystem>().setSpriteDirection(kumaSprite, dir); | 44 | getSystem<AnimationSystem>().setSpriteDirection(kumaSprite, dir); |
45 | getSprite(kumaSprite).hasShadow = true; | ||
44 | getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, kumaSprite); | 46 | getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, kumaSprite); |
45 | 47 | ||
46 | int dusterSprite = emplaceSprite("duster"); | 48 | int dusterSprite = emplaceSprite("duster"); |
47 | getSystem<TransformSystem>().initSprite(dusterSprite, warpLoc); | 49 | getSystem<TransformSystem>().initSprite(dusterSprite, warpLoc); |
48 | getSystem<AnimationSystem>().initSprite(dusterSprite, "../res/sprites/duster_anim.txt"); | 50 | getSystem<AnimationSystem>().initSprite(dusterSprite, "../res/sprites/duster_anim.txt"); |
49 | getSystem<AnimationSystem>().setSpriteDirection(dusterSprite, dir); | 51 | getSystem<AnimationSystem>().setSpriteDirection(dusterSprite, dir); |
52 | getSprite(dusterSprite).hasShadow = true; | ||
50 | getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, dusterSprite); | 53 | getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, dusterSprite); |
51 | 54 | ||
52 | int boneySprite = emplaceSprite("boney"); | 55 | int boneySprite = emplaceSprite("boney"); |
53 | getSystem<TransformSystem>().initSprite(boneySprite, warpLoc); | 56 | getSystem<TransformSystem>().initSprite(boneySprite, warpLoc); |
54 | getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt"); | 57 | getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt"); |
55 | getSystem<AnimationSystem>().setSpriteDirection(boneySprite, dir); | 58 | getSystem<AnimationSystem>().setSpriteDirection(boneySprite, dir); |
59 | getSprite(boneySprite).hasShadow = true; | ||
56 | getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, boneySprite); | 60 | getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, boneySprite); |
57 | 61 | ||
58 | for (const Prototype& p : map_->getPrototypes()) { | 62 | for (const Prototype& p : map_->getPrototypes()) { |
@@ -61,6 +65,7 @@ void Game::loadMap(std::string filename, std::string warpPoint, Direction dir) { | |||
61 | getSystem<TransformSystem>().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true); | 65 | getSystem<TransformSystem>().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true); |
62 | if (!p.animationFilename.empty()) { | 66 | if (!p.animationFilename.empty()) { |
63 | getSystem<AnimationSystem>().initSprite(spriteId, p.animationFilename); | 67 | getSystem<AnimationSystem>().initSprite(spriteId, p.animationFilename); |
68 | getSprite(spriteId).hasShadow = p.shadow; | ||
64 | } | 69 | } |
65 | getSprite(spriteId).interactionScript = p.interactionScript; | 70 | getSprite(spriteId).interactionScript = p.interactionScript; |
66 | } | 71 | } |
diff --git a/src/map.cpp b/src/map.cpp index da382fd..3686bbd 100644 --- a/src/map.cpp +++ b/src/map.cpp | |||
@@ -74,6 +74,8 @@ Map::Map(std::string_view name) : name_(name) { | |||
74 | p.animationFilename = property.getStringValue(); | 74 | p.animationFilename = property.getStringValue(); |
75 | } else if (property.getName() == "interactionScript") { | 75 | } else if (property.getName() == "interactionScript") { |
76 | p.interactionScript = property.getStringValue(); | 76 | p.interactionScript = property.getStringValue(); |
77 | } else if (property.getName() == "shadow") { | ||
78 | p.shadow = property.getBoolValue(); | ||
77 | } | 79 | } |
78 | } | 80 | } |
79 | 81 | ||
diff --git a/src/map.h b/src/map.h index 2d448e4..7dbe613 100644 --- a/src/map.h +++ b/src/map.h | |||
@@ -23,6 +23,7 @@ struct Prototype { | |||
23 | vec2i collisionSize; | 23 | vec2i collisionSize; |
24 | std::string animationFilename; | 24 | std::string animationFilename; |
25 | std::string interactionScript; | 25 | std::string interactionScript; |
26 | bool shadow = false; | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | struct Trigger { | 29 | struct Trigger { |
diff --git a/src/renderer.cpp b/src/renderer.cpp index 246b7fb..f07931b 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -122,8 +122,14 @@ void Renderer::render(Game& game) { | |||
122 | 122 | ||
123 | SDL_RenderCopy(ren_.get(), renLay1_.get(), nullptr, nullptr); | 123 | SDL_RenderCopy(ren_.get(), renLay1_.get(), nullptr, nullptr); |
124 | 124 | ||
125 | int shadowTexId = loadImageFromFile("../res/shadow.png"); | ||
125 | for (const Sprite& sprite : game.getSystem<TransformSystem>().getSpritesByY() | game.spriteView()) { | 126 | for (const Sprite& sprite : game.getSystem<TransformSystem>().getSpritesByY() | game.spriteView()) { |
126 | if (sprite.isAnimated) { | 127 | if (sprite.isAnimated) { |
128 | if (sprite.hasShadow) { | ||
129 | const SDL_Rect shadowDest { sprite.loc.x() - 8, sprite.loc.y() - 8, 16, 8 }; | ||
130 | SDL_RenderCopy(ren_.get(), textures_.at(shadowTexId).get(), nullptr, &shadowDest); | ||
131 | } | ||
132 | |||
127 | const SpriteFrame& frame = sprite.frames.at(sprite.animations.at(sprite.animationId).at(sprite.animationFrame)); | 133 | const SpriteFrame& frame = sprite.frames.at(sprite.animations.at(sprite.animationId).at(sprite.animationFrame)); |
128 | const SDL_Rect& src = frame.srcRect; | 134 | const SDL_Rect& src = frame.srcRect; |
129 | SDL_Rect dest { sprite.loc.x() - frame.center.x(), sprite.loc.y() - frame.center.y(), frame.size.w(), frame.size.h() }; | 135 | SDL_Rect dest { sprite.loc.x() - frame.center.x(), sprite.loc.y() - frame.center.y(), frame.size.w(), frame.size.h() }; |
diff --git a/src/sprite.h b/src/sprite.h index 6ef2f57..84a7b03 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
@@ -50,6 +50,7 @@ public: | |||
50 | std::vector<SpriteFrame> frames; | 50 | std::vector<SpriteFrame> frames; |
51 | std::vector<std::vector<int>> animations; | 51 | std::vector<std::vector<int>> animations; |
52 | std::map<std::string, std::map<Direction, int>> nameDirToAnim; | 52 | std::map<std::string, std::map<Direction, int>> nameDirToAnim; |
53 | bool hasShadow = false; | ||
53 | 54 | ||
54 | // Character | 55 | // Character |
55 | bool orientable = false; | 56 | bool orientable = false; |