summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-07-06 10:13:33 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2021-07-06 10:13:33 -0400
commit77fad1c341787f11ee3b8aeaa5c58fe6ebbdebb6 (patch)
treeaa8addf2f54d3def01edb29944cacdebdcaf981b
parent8aedeaf12c7dbf35f2f75f1b063b76a4fad06f30 (diff)
downloadtanetane-77fad1c341787f11ee3b8aeaa5c58fe6ebbdebb6.tar.gz
tanetane-77fad1c341787f11ee3b8aeaa5c58fe6ebbdebb6.tar.bz2
tanetane-77fad1c341787f11ee3b8aeaa5c58fe6ebbdebb6.zip
Added the ability to pan camera to a warp point
-rw-r--r--res/scripts/common.lua4
-rw-r--r--src/camera_system.cpp16
-rw-r--r--src/camera_system.h6
-rw-r--r--src/map.h4
-rw-r--r--src/script_system.cpp1
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)
248end 248end
249 249
250function PanToWarpPoint(warpPoint, length)
251 camera():panToWarpPoint(warpPoint, length)
252end
253
250function WaitForPan() 254function 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
44void 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
44void CameraSystem::destroySprite(int spriteId) { 60void 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);