diff options
-rw-r--r-- | res/scripts/common.lua | 4 | ||||
-rw-r--r-- | src/camera_system.cpp | 16 | ||||
-rw-r--r-- | src/camera_system.h | 6 | ||||
-rw-r--r-- | src/map.h | 4 | ||||
-rw-r--r-- | src/script_system.cpp | 1 |
5 files changed, 29 insertions, 2 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 35eec22..46f2275 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua | |||
@@ -247,6 +247,10 @@ function PanToSprite(spriteName, length) | |||
247 | camera():panToSprite(spriteId, length) | 247 | camera():panToSprite(spriteId, length) |
248 | end | 248 | end |
249 | 249 | ||
250 | function PanToWarpPoint(warpPoint, length) | ||
251 | camera():panToWarpPoint(warpPoint, length) | ||
252 | end | ||
253 | |||
250 | function WaitForPan() | 254 | function WaitForPan() |
251 | while camera():isPanning() do | 255 | while camera():isPanning() do |
252 | coroutine.yield() | 256 | coroutine.yield() |
diff --git a/src/camera_system.cpp b/src/camera_system.cpp index 0ef3c36..ac89a78 100644 --- a/src/camera_system.cpp +++ b/src/camera_system.cpp | |||
@@ -41,6 +41,22 @@ void CameraSystem::panToSprite(int targetId, int length) { | |||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | void CameraSystem::panToWarpPoint(std::string_view warpPoint, int length) { | ||
45 | locked_ = true; | ||
46 | |||
47 | vec2i center = game_.getMap().getWarpPoint(warpPoint); | ||
48 | |||
49 | if (length > 0) { | ||
50 | panning_ = true; | ||
51 | panStart_ = pos_; | ||
52 | panEnd_ = calculatePosWithCenter(center); | ||
53 | panLength_ = length; | ||
54 | panThus_ = 0.0; | ||
55 | } else { | ||
56 | pos_ = calculatePosWithCenter(center); | ||
57 | } | ||
58 | } | ||
59 | |||
44 | void CameraSystem::destroySprite(int spriteId) { | 60 | void CameraSystem::destroySprite(int spriteId) { |
45 | if (followingSprite_ == spriteId) { | 61 | if (followingSprite_ == spriteId) { |
46 | followingSprite_ = -1; | 62 | followingSprite_ = -1; |
diff --git a/src/camera_system.h b/src/camera_system.h index 8c9419c..7ff410d 100644 --- a/src/camera_system.h +++ b/src/camera_system.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef CAMERA_SYSTEM_H_D52ADAD3 | 1 | #ifndef CAMERA_SYSTEM_H_D52ADAD3 |
2 | #define CAMERA_SYSTEM_H_D52ADAD3 | 2 | #define CAMERA_SYSTEM_H_D52ADAD3 |
3 | 3 | ||
4 | #include <string_view> | ||
4 | #include "consts.h" | 5 | #include "consts.h" |
5 | #include "system.h" | 6 | #include "system.h" |
6 | #include "vector.h" | 7 | #include "vector.h" |
@@ -29,6 +30,11 @@ public: | |||
29 | // Automatically locks the camera. | 30 | // Automatically locks the camera. |
30 | void panToSprite(int targetId, int length); | 31 | void panToSprite(int targetId, int length); |
31 | 32 | ||
33 | // Pans over to the provided warp point over the provided amount of time. | ||
34 | // - length is in milliseconds | ||
35 | // Automatically locks the camera. | ||
36 | void panToWarpPoint(std::string_view warpPoint, int length); | ||
37 | |||
32 | bool isPanning() const { return panning_; } | 38 | bool isPanning() const { return panning_; } |
33 | 39 | ||
34 | void tick(double dt) override; | 40 | void tick(double dt) override; |
diff --git a/src/map.h b/src/map.h index 4019428..956e370 100644 --- a/src/map.h +++ b/src/map.h | |||
@@ -79,7 +79,7 @@ public: | |||
79 | 79 | ||
80 | const std::vector<Prototype>& getPrototypes() const { return prototypes_; } | 80 | const std::vector<Prototype>& getPrototypes() const { return prototypes_; } |
81 | 81 | ||
82 | const vec2i& getWarpPoint(const std::string& name) const { return warpPoints_.at(name); } | 82 | const vec2i& getWarpPoint(std::string_view name) const { return warpPoints_.find(name)->second; } |
83 | 83 | ||
84 | const std::vector<Trigger>& getTriggers() const { return triggers_; } | 84 | const std::vector<Trigger>& getTriggers() const { return triggers_; } |
85 | 85 | ||
@@ -103,7 +103,7 @@ private: | |||
103 | std::string tilesetFilename_; | 103 | std::string tilesetFilename_; |
104 | int tilesetColumns_; | 104 | int tilesetColumns_; |
105 | std::vector<Prototype> prototypes_; | 105 | std::vector<Prototype> prototypes_; |
106 | std::map<std::string, vec2i> warpPoints_; | 106 | std::map<std::string, vec2i, std::less<>> warpPoints_; |
107 | std::vector<Trigger> triggers_; | 107 | std::vector<Trigger> triggers_; |
108 | std::map<std::string, Zone> zones_; | 108 | std::map<std::string, Zone> zones_; |
109 | std::string music_; | 109 | std::string music_; |
diff --git a/src/script_system.cpp b/src/script_system.cpp index c820ecb..1a63643 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp | |||
@@ -106,6 +106,7 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
106 | engine_.new_usertype<CameraSystem>( | 106 | engine_.new_usertype<CameraSystem>( |
107 | "camera", | 107 | "camera", |
108 | "panToSprite", &CameraSystem::panToSprite, | 108 | "panToSprite", &CameraSystem::panToSprite, |
109 | "panToWarpPoint", &CameraSystem::panToWarpPoint, | ||
109 | "isPanning", &CameraSystem::isPanning, | 110 | "isPanning", &CameraSystem::isPanning, |
110 | "unlockCamera", &CameraSystem::unlockCamera, | 111 | "unlockCamera", &CameraSystem::unlockCamera, |
111 | "setFollowingSprite", &CameraSystem::setFollowingSprite); | 112 | "setFollowingSprite", &CameraSystem::setFollowingSprite); |