From 77fad1c341787f11ee3b8aeaa5c58fe6ebbdebb6 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 6 Jul 2021 10:13:33 -0400 Subject: Added the ability to pan camera to a warp point --- res/scripts/common.lua | 4 ++++ src/camera_system.cpp | 16 ++++++++++++++++ src/camera_system.h | 6 ++++++ src/map.h | 4 ++-- 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) camera():panToSprite(spriteId, length) end +function PanToWarpPoint(warpPoint, length) + camera():panToWarpPoint(warpPoint, length) +end + function WaitForPan() while camera():isPanning() do 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) { } } +void CameraSystem::panToWarpPoint(std::string_view warpPoint, int length) { + locked_ = true; + + vec2i center = game_.getMap().getWarpPoint(warpPoint); + + if (length > 0) { + panning_ = true; + panStart_ = pos_; + panEnd_ = calculatePosWithCenter(center); + panLength_ = length; + panThus_ = 0.0; + } else { + pos_ = calculatePosWithCenter(center); + } +} + void CameraSystem::destroySprite(int spriteId) { if (followingSprite_ == spriteId) { 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 @@ #ifndef CAMERA_SYSTEM_H_D52ADAD3 #define CAMERA_SYSTEM_H_D52ADAD3 +#include #include "consts.h" #include "system.h" #include "vector.h" @@ -29,6 +30,11 @@ public: // Automatically locks the camera. void panToSprite(int targetId, int length); + // Pans over to the provided warp point over the provided amount of time. + // - length is in milliseconds + // Automatically locks the camera. + void panToWarpPoint(std::string_view warpPoint, int length); + bool isPanning() const { return panning_; } 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: const std::vector& getPrototypes() const { return prototypes_; } - const vec2i& getWarpPoint(const std::string& name) const { return warpPoints_.at(name); } + const vec2i& getWarpPoint(std::string_view name) const { return warpPoints_.find(name)->second; } const std::vector& getTriggers() const { return triggers_; } @@ -103,7 +103,7 @@ private: std::string tilesetFilename_; int tilesetColumns_; std::vector prototypes_; - std::map warpPoints_; + std::map> warpPoints_; std::vector triggers_; std::map zones_; 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) { engine_.new_usertype( "camera", "panToSprite", &CameraSystem::panToSprite, + "panToWarpPoint", &CameraSystem::panToWarpPoint, "isPanning", &CameraSystem::isPanning, "unlockCamera", &CameraSystem::unlockCamera, "setFollowingSprite", &CameraSystem::setFollowingSprite); -- cgit 1.4.1