Can now pan and move the camera to focus on bosses, player, and their actions.
This commit is contained in:
parent
51bb74e2d7
commit
22db12f5e4
6 changed files with 38 additions and 28 deletions
|
|
@ -110,8 +110,10 @@ namespace boss {
|
||||||
if(amount > 0) {
|
if(amount > 0) {
|
||||||
$arena.attach_text(target, fmt::format("{}", amount));
|
$arena.attach_text(target, fmt::format("{}", amount));
|
||||||
$arena.apply_effect(actor, "flame");
|
$arena.apply_effect(actor, "flame");
|
||||||
fmt::println("CAMERA zooming by 0.7 to {}", target);
|
|
||||||
$arena.zoom(target, 0.8f);
|
// USING SCALE
|
||||||
|
float scale = 0.8f;
|
||||||
|
$arena.zoom(target, scale);
|
||||||
} else {
|
} else {
|
||||||
$arena.attach_text(actor, "MISSED");
|
$arena.attach_text(actor, "MISSED");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
camera.cpp
22
camera.cpp
|
|
@ -29,9 +29,13 @@ namespace cinematic {
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera::Camera(sf::Vector2f size) :
|
Camera::Camera(sf::Vector2f size) :
|
||||||
anim(MGR.animations.at("shake")),
|
anim(MGR.animations.at("dolly")),
|
||||||
|
size(size),
|
||||||
base_size(size),
|
base_size(size),
|
||||||
size(size)
|
aimed_at{size.x/2, size.y/2},
|
||||||
|
going_to{size.x/2, size.y/2},
|
||||||
|
camera_bounds{{0,0}, size},
|
||||||
|
view{aimed_at, size}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,10 +46,6 @@ namespace cinematic {
|
||||||
{size.x / 2.0f, size.y / 2.0f},
|
{size.x / 2.0f, size.y / 2.0f},
|
||||||
{base_size.x - size.x / 2.0f, base_size.y - size.y / 2.0f}
|
{base_size.x - size.x / 2.0f, base_size.y - size.y / 2.0f}
|
||||||
};
|
};
|
||||||
|
|
||||||
fmt::println("!!!!! CAMERA BOUNDS camera_bounds={},{},{},{}",
|
|
||||||
camera_bounds.position.x, camera_bounds.position.y,
|
|
||||||
camera_bounds.size.x, camera_bounds.size.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::scale(float ratio) {
|
void Camera::scale(float ratio) {
|
||||||
|
|
@ -69,22 +69,12 @@ namespace cinematic {
|
||||||
void Camera::position(float x, float y) {
|
void Camera::position(float x, float y) {
|
||||||
aimed_at.x = clamp(x, camera_bounds.position.x, camera_bounds.size.x);
|
aimed_at.x = clamp(x, camera_bounds.position.x, camera_bounds.size.x);
|
||||||
aimed_at.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y);
|
aimed_at.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y);
|
||||||
|
|
||||||
fmt::println("!!! CAMERA POSITION aimed_at={},{}; x/y={},{}; camera_bounds={},{},{},{}",
|
|
||||||
aimed_at.x, aimed_at.y, x, y,
|
|
||||||
camera_bounds.position.x, camera_bounds.position.y,
|
|
||||||
camera_bounds.size.x, camera_bounds.size.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::move(float x, float y) {
|
void Camera::move(float x, float y) {
|
||||||
going_to.x = clamp(x, camera_bounds.position.x, camera_bounds.size.x);
|
going_to.x = clamp(x, camera_bounds.position.x, camera_bounds.size.x);
|
||||||
going_to.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y);
|
going_to.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y);
|
||||||
|
|
||||||
fmt::println("!!!! CAMERA MOVE going_to={},{}; x/y={},{}; camera_bounds={},{},{},{}",
|
|
||||||
going_to.x, going_to.y, x, y,
|
|
||||||
camera_bounds.position.x, camera_bounds.position.y,
|
|
||||||
camera_bounds.size.x, camera_bounds.size.y);
|
|
||||||
|
|
||||||
// BUG: annoying special case
|
// BUG: annoying special case
|
||||||
if(anim.motion == ease::SLIDE) {
|
if(anim.motion == ease::SLIDE) {
|
||||||
anim.min_x = aimed_at.x;
|
anim.min_x = aimed_at.x;
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@
|
||||||
namespace cinematic {
|
namespace cinematic {
|
||||||
struct Camera {
|
struct Camera {
|
||||||
components::Animation anim;
|
components::Animation anim;
|
||||||
sf::View view;
|
|
||||||
sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
|
||||||
sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
sf::FloatRect camera_bounds{{0,0},{SCREEN_WIDTH, SCREEN_HEIGHT}};
|
sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
sf::Vector2f aimed_at{0,0};
|
sf::Vector2f aimed_at{0,0};
|
||||||
sf::Vector2f going_to{0,0};
|
sf::Vector2f going_to{0,0};
|
||||||
|
sf::FloatRect camera_bounds{{0,0},{SCREEN_WIDTH, SCREEN_HEIGHT}};
|
||||||
|
sf::View view;
|
||||||
|
|
||||||
Camera(sf::Vector2f base_size);
|
Camera(sf::Vector2f base_size);
|
||||||
|
|
||||||
|
|
|
||||||
29
scene.cpp
29
scene.cpp
|
|
@ -36,8 +36,6 @@ namespace scene {
|
||||||
Engine::Engine(components::AnimatedScene& scene) :
|
Engine::Engine(components::AnimatedScene& scene) :
|
||||||
$scene(scene)
|
$scene(scene)
|
||||||
{
|
{
|
||||||
$camera.style("dolly");
|
|
||||||
|
|
||||||
for(auto& config : $scene.actors) {
|
for(auto& config : $scene.actors) {
|
||||||
auto element = config_scene_element(config, false, false);
|
auto element = config_scene_element(config, false, false);
|
||||||
dbc::check(!$actor_name_ids.contains(element.name),
|
dbc::check(!$actor_name_ids.contains(element.name),
|
||||||
|
|
@ -167,16 +165,35 @@ namespace scene {
|
||||||
$camera.play();
|
$camera.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<Element&, Element&> Engine::left_right(const std::string &actor, const std::string &target) {
|
||||||
|
auto& first = actor_config(actor);
|
||||||
|
auto& second = actor_config(target);
|
||||||
|
|
||||||
|
if(first.pos.x < second.pos.x) {
|
||||||
|
// first is left
|
||||||
|
return {first, second};
|
||||||
|
} else if(first.pos.x == second.pos.x) {
|
||||||
|
auto fb = first.st.sprite->getGlobalBounds();
|
||||||
|
auto sb = second.st.sprite->getGlobalBounds();
|
||||||
|
|
||||||
|
// use the widest one as right
|
||||||
|
if(fb.size.x >= sb.size.x) {
|
||||||
|
return {first, second};
|
||||||
|
} else {
|
||||||
|
return {second, first};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// second is left
|
||||||
|
return {second, first};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::zoom(const std::string &actor, float scale) {
|
void Engine::zoom(const std::string &actor, float scale) {
|
||||||
auto& config = actor_config(actor);
|
auto& config = actor_config(actor);
|
||||||
auto bounds = config.st.sprite->getGlobalBounds();
|
auto bounds = config.st.sprite->getGlobalBounds();
|
||||||
float mid_x = config.pos.x + bounds.size.x / 2.0f;
|
float mid_x = config.pos.x + bounds.size.x / 2.0f;
|
||||||
float mid_y = config.pos.y + bounds.size.y / 2.0f;
|
float mid_y = config.pos.y + bounds.size.y / 2.0f;
|
||||||
|
|
||||||
fmt::println("CAMERA in scene::Engine I'm zooming {} by {} @ {},{} size {},{}; going_to mid={},{}",
|
|
||||||
actor, scale, config.pos.x, config.pos.y,
|
|
||||||
bounds.size.x, bounds.size.y, mid_x, mid_y);
|
|
||||||
|
|
||||||
zoom(mid_x, mid_y, scale);
|
zoom(mid_x, mid_y, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,5 +54,6 @@ namespace scene {
|
||||||
void zoom(const std::string& actor, float scale=0.9f);
|
void zoom(const std::string& actor, float scale=0.9f);
|
||||||
void zoom(float mid_x, float mid_y, float scale);
|
void zoom(float mid_x, float mid_y, float scale);
|
||||||
void reset(sf::RenderTexture& view);
|
void reset(sf::RenderTexture& view);
|
||||||
|
std::pair<Element&, Element&> left_right(const std::string &actor, const std::string &target);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue