about summary refs log tree commit diff stats
path: root/vendor/quadtree/Box.h
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-06-08 11:24:13 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-06-08 11:24:13 -0400
commit21883d1004bde99f03cdbc82307207d5dd681a8a (patch)
tree8240f8710e519cafde163932a5bd862547393691 /vendor/quadtree/Box.h
parent5f458fdee31b06a0fbebdd2542188fc5afec9245 (diff)
downloadlingo-ap-tracker-21883d1004bde99f03cdbc82307207d5dd681a8a.tar.gz
lingo-ap-tracker-21883d1004bde99f03cdbc82307207d5dd681a8a.tar.bz2
lingo-ap-tracker-21883d1004bde99f03cdbc82307207d5dd681a8a.zip
Fixed broken paintings and window repainting
Diffstat (limited to 'vendor/quadtree/Box.h')
0 files changed, 0 insertions, 0 deletions
rd.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "camera_system.h"
#include "sprite.h"
#include "game.h"
#include "map.h"

void CameraSystem::tick(double dt) {
  if (game_.isGameplayPaused()) return;

  if (!locked_ && followingSprite_ != -1) {
    const Sprite& follow = game_.getSprite(followingSprite_);

    pos_ = calculatePosWithCenter(follow.loc - vec2i{0, 16});
  }

  if (panning_) {
    panThus_ += dt;

    if (panThus_ >= panLength_) {
      panning_ = false;
      pos_ = panEnd_;
    } else {
      pos_.x() = static_cast<double>((panEnd_ - panStart_).x()) / panLength_ * panThus_ + panStart_.x();
      pos_.y() = static_cast<double>((panEnd_ - panStart_).y()) / panLength_ * panThus_ + panStart_.y();
    }
  }
}

void CameraSystem::panToSprite(int targetId, int length) {
  locked_ = true;

  const Sprite& target = game_.getSprite(targetId);

  if (length > 0) {
    panning_ = true;
    panStart_ = pos_;
    panEnd_ = calculatePosWithCenter(target.loc - vec2i{0, 16});
    panLength_ = length;
    panThus_ = 0.0;
  } else {
    pos_ = calculatePosWithCenter(target.loc - vec2i{0, 16});
  }
}

void CameraSystem::destroySprite(int spriteId) {
  if (followingSprite_ == spriteId) {
    followingSprite_ = -1;
  }
}

vec2i CameraSystem::calculatePosWithCenter(vec2i center) const {
  const Map& map = game_.getMap();
  vec2i mapBounds = map.getMapSize() * map.getTileSize();

  vec2i result = center - (fov_ / 2);

  if (result.x() < 0) {
    result.x() = 0;
  }
  if (result.y() < 0) {
    result.y() = 0;
  }
  if (result.x() + fov_.w() >= mapBounds.w()) {
    result.x() = mapBounds.w() - fov_.w() - 1;
  }
  if (result.y() + fov_.h() >= mapBounds.h()) {
    result.y() = mapBounds.h() - fov_.h() - 1;
  }

  return result;
}