about summary refs log tree commit diff stats
path: root/data/maps/the_double_sided/rooms/Flipped Blue Area.txtpb
blob: f650be9cb3d9d513ab10cec88553869664725307 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
name: "Flipped Blue Area"
panels {
  name: "SKY"
  path: "Panels/Maze/panel_5"
  clue: "sky"
  answer: "ground"
  symbols: SUN
}
panels {
  name: "HEAD"
  path: "Panels/Maze/panel_10"
  clue: "head"
  answer: "feet"
  symbols: SUN
}
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 "controlling.h"
#include "game.h"
#include "components/controllable.h"
#include "components/orientable.h"
#include "systems/orienting.h"

void ControllingSystem::tick(double)
{
  while (!actions_.empty())
  {
    int key = actions_.front().first;
    int action = actions_.front().second;

    auto entities = game_.getEntityManager().getEntitiesWithComponents<
      ControllableComponent,
      OrientableComponent>();

    for (auto entity : entities)
    {
      auto& controllable = game_.getEntityManager().
        getComponent<ControllableComponent>(entity);

      auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>();

      if (action == GLFW_PRESS)
      {
        if (key == controllable.getLeftKey())
        {
          controllable.setHoldingLeft(true);

          if (!controllable.isFrozen())
          {
            orienting.moveLeft(entity);
          }
        } else if (key == controllable.getRightKey())
        {
          controllable.setHoldingRight(true);

          if (!controllable.isFrozen())
          {
            orienting.moveRight(entity);
          }
        } else if (key == controllable.getJumpKey())
        {
          if (!controllable.isFrozen())
          {
            orienting.jump(entity);
          }
        } else if (key == controllable.getDropKey())
        {
          if (!controllable.isFrozen())
          {
            orienting.drop(entity);
          }
        }
      } else if (action == GLFW_RELEASE)
      {
        if (key == controllable.getLeftKey())
        {
          controllable.setHoldingLeft(false);

          if (!controllable.isFrozen())
          {
            if (controllable.isHoldingRight())
            {
              orienting.moveRight(entity);
            } else {
              orienting.stopWalking(entity);
            }
          }
        } else if (key == controllable.getRightKey())
        {
          controllable.setHoldingRight(false);

          if (!controllable.isFrozen())
          {
            if (controllable.isHoldingLeft())
            {
              orienting.moveLeft(entity);
            } else {
              orienting.stopWalking(entity);
            }
          }
        } else if (key == controllable.getDropKey())
        {
          if (!controllable.isFrozen())
          {
            orienting.stopDropping(entity);
          }
        } else if (key == controllable.getJumpKey())
        {
          if (!controllable.isFrozen())
          {
            orienting.stopJumping(entity);
          }
        }
      }
    }

    actions_.pop();
  }
}

void ControllingSystem::input(int key, int action)
{
  actions_.push(std::make_pair(key, action));
}

void ControllingSystem::freeze(id_type entity)
{
  auto& controllable = game_.getEntityManager().
    getComponent<ControllableComponent>(entity);

  controllable.setFrozen(true);
}

void ControllingSystem::unfreeze(id_type entity)
{
  auto& controllable = game_.getEntityManager().
    getComponent<ControllableComponent>(entity);

  if (controllable.isFrozen())
  {
    controllable.setFrozen(false);

    auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>();

    if (controllable.isHoldingLeft())
    {
      orienting.moveLeft(entity);
    } else if (controllable.isHoldingRight())
    {
      orienting.moveRight(entity);
    }
  }
}