diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 12 | ||||
-rw-r--r-- | src/map.cpp | 29 | ||||
-rw-r--r-- | src/map.h | 13 |
3 files changed, 49 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp index c23897b..b1fc373 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -47,11 +47,13 @@ void loop(Renderer& renderer) { | |||
47 | game.getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt", renderer); | 47 | game.getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt", renderer); |
48 | game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, boneySprite); | 48 | game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, boneySprite); |
49 | 49 | ||
50 | int flintSprite = game.emplaceSprite("flint"); | 50 | for (const Prototype& p : game.getMap().getPrototypes()) { |
51 | game.getSystem<TransformSystem>().initSprite(flintSprite, {35*16, 19*16}); | 51 | int spriteId = game.emplaceSprite(p.name); |
52 | game.getSystem<TransformSystem>().setUpCollision(flintSprite, {-8, -8}, {12, 8}); | 52 | game.getSystem<TransformSystem>().initSprite(spriteId, p.pos); |
53 | game.getSystem<AnimationSystem>().initSprite(flintSprite, "../res/sprites/flint_anim.txt", renderer); | 53 | game.getSystem<TransformSystem>().setUpCollision(spriteId, p.collisionOffset, p.collisionSize); |
54 | game.getSprite(flintSprite).interactionScript = "script0001"; | 54 | game.getSystem<AnimationSystem>().initSprite(spriteId, p.animationFilename, renderer); |
55 | game.getSprite(spriteId).interactionScript = p.interactionScript; | ||
56 | } | ||
55 | 57 | ||
56 | game.getSystem<CameraSystem>().setFollowingSprite(lucasSprite); | 58 | game.getSystem<CameraSystem>().setFollowingSprite(lucasSprite); |
57 | game.getSystem<CameraSystem>().unlockCamera(); | 59 | game.getSystem<CameraSystem>().unlockCamera(); |
diff --git a/src/map.cpp b/src/map.cpp index 0c4f9d6..1a2a250 100644 --- a/src/map.cpp +++ b/src/map.cpp | |||
@@ -51,6 +51,35 @@ Map::Map(std::string_view filename, Renderer& renderer) { | |||
51 | } | 51 | } |
52 | 52 | ||
53 | layers_.push_back(std::move(tilesToStore)); | 53 | layers_.push_back(std::move(tilesToStore)); |
54 | } else if (layer->getType() == tmx::Layer::Type::Object) { | ||
55 | const auto& objectLayer = layer->getLayerAs<tmx::ObjectGroup>(); | ||
56 | |||
57 | for (const tmx::Object& object : objectLayer.getObjects()) { | ||
58 | if (object.getType() == "sprite") { | ||
59 | Prototype p; | ||
60 | p.name = object.getName(); | ||
61 | p.pos.x() = object.getPosition().x; | ||
62 | p.pos.y() = object.getPosition().y; | ||
63 | |||
64 | for (const tmx::Property& property : object.getProperties()) { | ||
65 | if (property.getName() == "collisionOffsetX") { | ||
66 | p.collisionOffset.x() = property.getIntValue(); | ||
67 | } else if (property.getName() == "collisionOffsetY") { | ||
68 | p.collisionOffset.y() = property.getIntValue(); | ||
69 | } else if (property.getName() == "collisionWidth") { | ||
70 | p.collisionSize.w() = property.getIntValue(); | ||
71 | } else if (property.getName() == "collisionHeight") { | ||
72 | p.collisionSize.h() = property.getIntValue(); | ||
73 | } else if (property.getName() == "animation") { | ||
74 | p.animationFilename = property.getStringValue(); | ||
75 | } else if (property.getName() == "interactionScript") { | ||
76 | p.interactionScript = property.getStringValue(); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | prototypes_.push_back(std::move(p)); | ||
81 | } | ||
82 | } | ||
54 | } | 83 | } |
55 | } | 84 | } |
56 | } | 85 | } |
diff --git a/src/map.h b/src/map.h index de18e68..a896b00 100644 --- a/src/map.h +++ b/src/map.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef MAP_H_D95D6D47 | 1 | #ifndef MAP_H_D95D6D47 |
2 | #define MAP_H_D95D6D47 | 2 | #define MAP_H_D95D6D47 |
3 | 3 | ||
4 | #include <string> | ||
4 | #include <string_view> | 5 | #include <string_view> |
5 | #include <vector> | 6 | #include <vector> |
6 | #include "renderer.h" | 7 | #include "renderer.h" |
@@ -17,6 +18,15 @@ struct Tile { | |||
17 | StepType step = StepType::none; | 18 | StepType step = StepType::none; |
18 | }; | 19 | }; |
19 | 20 | ||
21 | struct Prototype { | ||
22 | std::string name; | ||
23 | vec2i pos; | ||
24 | vec2i collisionOffset; | ||
25 | vec2i collisionSize; | ||
26 | std::string animationFilename; | ||
27 | std::string interactionScript; | ||
28 | }; | ||
29 | |||
20 | class Map { | 30 | class Map { |
21 | public: | 31 | public: |
22 | 32 | ||
@@ -36,6 +46,8 @@ public: | |||
36 | 46 | ||
37 | StepType getStepType(int x, int y) const; | 47 | StepType getStepType(int x, int y) const; |
38 | 48 | ||
49 | const std::vector<Prototype>& getPrototypes() const { return prototypes_; } | ||
50 | |||
39 | private: | 51 | private: |
40 | 52 | ||
41 | vec2i mapSize_; | 53 | vec2i mapSize_; |
@@ -43,6 +55,7 @@ private: | |||
43 | std::vector<std::vector<Tile>> layers_; | 55 | std::vector<std::vector<Tile>> layers_; |
44 | int tilesetTextureId_; | 56 | int tilesetTextureId_; |
45 | int tilesetColumns_; | 57 | int tilesetColumns_; |
58 | std::vector<Prototype> prototypes_; | ||
46 | }; | 59 | }; |
47 | 60 | ||
48 | #endif /* end of include guard: MAP_H_D95D6D47 */ | 61 | #endif /* end of include guard: MAP_H_D95D6D47 */ |