summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/scripts/common.lua5
-rw-r--r--src/consts.h2
-rw-r--r--src/game.cpp2
-rw-r--r--src/map.cpp10
-rw-r--r--src/map.h4
-rw-r--r--src/renderer.cpp30
-rw-r--r--src/sprite.h4
-rw-r--r--src/transform_system.h2
8 files changed, 52 insertions, 7 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index b0e555b..2a2ce35 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -26,8 +26,9 @@ CharacterState = {
26} 26}
27 27
28SpriteLayer = { 28SpriteLayer = {
29 NORMAL = 0, 29 MASK = 0,
30 ABOVE = 1 30 NORMAL = 1,
31 ABOVE = 2
31} 32}
32 33
33BehaviourType = { 34BehaviourType = {
diff --git a/src/consts.h b/src/consts.h index e0af6cd..65e4558 100644 --- a/src/consts.h +++ b/src/consts.h
@@ -12,6 +12,4 @@ const int PARTY_FRAME_DELAY = 20; // true delay is this divided by movement spee
12 12
13const int MESSAGE_TEXT_WIDTH = 196; 13const int MESSAGE_TEXT_WIDTH = 196;
14 14
15const int NUM_SPRITE_LAYERS = 2;
16
17#endif /* end of include guard: CONSTS_H_9561E49C */ 15#endif /* end of include guard: CONSTS_H_9561E49C */
diff --git a/src/game.cpp b/src/game.cpp index 5b5c506..7e3c88f 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -56,7 +56,7 @@ void Game::loadMap(std::string filename) {
56 if (spritesByAlias_.count(p.name)) continue; 56 if (spritesByAlias_.count(p.name)) continue;
57 57
58 int spriteId = emplaceSprite(p.name); 58 int spriteId = emplaceSprite(p.name);
59 getSystem<TransformSystem>().initSprite(spriteId, p.pos); 59 getSystem<TransformSystem>().initSprite(spriteId, p.pos, p.masked ? SpriteLayer::Mask : SpriteLayer::Normal);
60 getSystem<TransformSystem>().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true); 60 getSystem<TransformSystem>().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true);
61 if (!p.animationFilename.empty()) { 61 if (!p.animationFilename.empty()) {
62 getSystem<AnimationSystem>().initSprite(spriteId, p.animationFilename); 62 getSystem<AnimationSystem>().initSprite(spriteId, p.animationFilename);
diff --git a/src/map.cpp b/src/map.cpp index c3ac828..8d0ada6 100644 --- a/src/map.cpp +++ b/src/map.cpp
@@ -71,12 +71,20 @@ Map::Map(std::string_view name) : name_(name) {
71 } else if (layer->getType() == tmx::Layer::Type::Object) { 71 } else if (layer->getType() == tmx::Layer::Type::Object) {
72 const auto& objectLayer = layer->getLayerAs<tmx::ObjectGroup>(); 72 const auto& objectLayer = layer->getLayerAs<tmx::ObjectGroup>();
73 73
74 bool masked = false;
75 for (const tmx::Property& property : objectLayer.getProperties()) {
76 if (property.getName() == "masked" && property.getBoolValue()) {
77 masked = true;
78 }
79 }
80
74 for (const tmx::Object& object : objectLayer.getObjects()) { 81 for (const tmx::Object& object : objectLayer.getObjects()) {
75 if (object.getType() == "sprite") { 82 if (object.getType() == "sprite") {
76 Prototype p; 83 Prototype p;
77 p.name = object.getName(); 84 p.name = object.getName();
78 p.pos.x() = object.getPosition().x; 85 p.pos.x() = object.getPosition().x;
79 p.pos.y() = object.getPosition().y; 86 p.pos.y() = object.getPosition().y;
87 p.masked = masked;
80 88
81 for (const tmx::Property& property : object.getProperties()) { 89 for (const tmx::Property& property : object.getProperties()) {
82 if (property.getName() == "collisionOffsetX") { 90 if (property.getName() == "collisionOffsetX") {
@@ -159,6 +167,8 @@ Map::Map(std::string_view name) : name_(name) {
159 for (const tmx::Property& property : mapfile.getProperties()) { 167 for (const tmx::Property& property : mapfile.getProperties()) {
160 if (property.getName() == "music") { 168 if (property.getName() == "music") {
161 music_ = property.getStringValue(); 169 music_ = property.getStringValue();
170 } else if (property.getName() == "maskZone") {
171 maskZone_ = property.getStringValue();
162 } 172 }
163 } 173 }
164} 174}
diff --git a/src/map.h b/src/map.h index a125082..1167290 100644 --- a/src/map.h +++ b/src/map.h
@@ -31,6 +31,7 @@ struct Prototype {
31 bool wander = false; 31 bool wander = false;
32 int movementSpeed = -1; 32 int movementSpeed = -1;
33 std::string enclosureZone; 33 std::string enclosureZone;
34 bool masked = false;
34}; 35};
35 36
36struct Trigger { 37struct Trigger {
@@ -82,6 +83,8 @@ public:
82 83
83 const std::string& getMusic() const { return music_; } 84 const std::string& getMusic() const { return music_; }
84 85
86 const std::string& getMaskZone() const { return maskZone_; }
87
85private: 88private:
86 89
87 std::string name_; 90 std::string name_;
@@ -96,6 +99,7 @@ private:
96 std::vector<Trigger> triggers_; 99 std::vector<Trigger> triggers_;
97 std::map<std::string, Zone> zones_; 100 std::map<std::string, Zone> zones_;
98 std::string music_; 101 std::string music_;
102 std::string maskZone_;
99}; 103};
100 104
101#endif /* end of include guard: MAP_H_D95D6D47 */ 105#endif /* end of include guard: MAP_H_D95D6D47 */
diff --git a/src/renderer.cpp b/src/renderer.cpp index 5ab623a..ea8a2ac 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -178,6 +178,36 @@ void Renderer::render(Game& game) {
178 SDL_RenderCopy(ren_.get(), mapSwapTex_.get(), nullptr, nullptr); 178 SDL_RenderCopy(ren_.get(), mapSwapTex_.get(), nullptr, nullptr);
179 } 179 }
180 180
181 // Render mask sprite layer
182 if (!game.getMap().getMaskZone().empty()) {
183 texture_ptr spritesTex(
184 SDL_CreateTexture(
185 ren_.get(),
186 SDL_PIXELFORMAT_RGBA8888,
187 SDL_TEXTUREACCESS_TARGET,
188 mapBounds.w(),
189 mapBounds.h()));
190
191 if (!spritesTex) {
192 throw sdl_error();
193 }
194
195 SDL_SetRenderTarget(ren_.get(), spritesTex.get());
196 SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 0);
197 SDL_RenderClear(ren_.get());
198
199 for (const Sprite& sprite : game.getSystem<TransformSystem>().getSpritesByY(SpriteLayer::Mask) | game.spriteView()) {
200 renderSprite(sprite);
201 }
202
203 const Zone& zone = game.getMap().getZone(game.getMap().getMaskZone());
204 SDL_Rect zoneArea { zone.ul.x(), zone.ul.y(), zone.dr.x() - zone.ul.x(), zone.dr.y() - zone.ul.y() };
205
206 SDL_SetRenderTarget(ren_.get(), canvas.get());
207 SDL_SetTextureBlendMode(spritesTex.get(), SDL_BLENDMODE_BLEND);
208 SDL_RenderCopy(ren_.get(), spritesTex.get(), &zoneArea, &zoneArea);
209 }
210
181 // Render normal sprite layer 211 // Render normal sprite layer
182 for (const Sprite& sprite : game.getSystem<TransformSystem>().getSpritesByY(SpriteLayer::Normal) | game.spriteView()) { 212 for (const Sprite& sprite : game.getSystem<TransformSystem>().getSpritesByY(SpriteLayer::Normal) | game.spriteView()) {
183 renderSprite(sprite); 213 renderSprite(sprite);
diff --git a/src/sprite.h b/src/sprite.h index 13d0383..6538c1d 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -11,8 +11,10 @@
11#include "step_type.h" 11#include "step_type.h"
12 12
13enum class SpriteLayer { 13enum class SpriteLayer {
14 Mask,
14 Normal, 15 Normal,
15 Above 16 Above,
17 NUM_SPRITE_LAYERS // do not use
16}; 18};
17 19
18struct SpriteFrame { 20struct SpriteFrame {
diff --git a/src/transform_system.h b/src/transform_system.h index 6707347..7fa3423 100644 --- a/src/transform_system.h +++ b/src/transform_system.h
@@ -54,7 +54,7 @@ public:
54private: 54private:
55 55
56 Game& game_; 56 Game& game_;
57 std::set<std::tuple<int, int>> spritesByY_[NUM_SPRITE_LAYERS]; 57 std::set<std::tuple<int, int>> spritesByY_[static_cast<int>(SpriteLayer::NUM_SPRITE_LAYERS)];
58 58
59 struct Collidable { 59 struct Collidable {
60 int lower; 60 int lower;