about summary refs log tree commit diff stats
path: root/data/maps/daedalus/rooms/Red Smiley.txtpb
blob: 28f2a036a6d4edebd7ea58c8192d233b6a0601ac (plain) (blame)
1
2
3
4
5
6
7
8
9
name: "Red Smiley"
panel_display_name: "Northwest Area"
panels {
  name: "SMILE"
  path: "Panels/Smiley Rooms/red"
  clue: "smile"
  answer: "red"
  symbols: QUESTION
}
olor: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.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 "input_system.h"
#include "game.h"
#include "character_system.h"
#include "message_system.h"
#include "script_system.h"
#include "transform_system.h"
#include "animation_system.h"
#include "menu_system.h"

struct Input {
  bool left = false;
  bool right = false;
  bool up = false;
  bool down = false;
};

void InputSystem::tick(double dt) {
  SDL_Event e;
  while (SDL_PollEvent(&e)) {
    if (e.type == SDL_QUIT) {
      game_.quit();

      return;
    } else if (e.type == SDL_TEXTINPUT) {
      debugText_.append(e.text.text);
    } else if (e.type == SDL_KEYDOWN) {
      if (e.key.keysym.sym == SDLK_ESCAPE) {
        if (debugConsole_) {
          debugConsole_ = false;
          game_.unpauseGameplay();
          SDL_StopTextInput();
          debugText_.clear();
        } else {
          if (game_.getSystem<MenuSystem>().isMenuOpen()) {
            game_.getSystem<MenuSystem>().closePauseMenu();
          } else if (!game_.isGameplayPaused()) {
            game_.getSystem<MenuSystem>().openPauseMenu();
          }
        }
      } else if (e.key.keysym.sym == SDLK_BACKQUOTE) {
#ifdef TANETANE_DEBUG
        if (!debugConsole_ && !game_.isGameplayPaused()) {
          debugConsole_ = true;
          game_.pauseGameplay();
          SDL_StartTextInput();
          debugText_.clear();
        }
#endif
      } else if (debugConsole_ && e.key.keysym.sym == SDLK_RETURN) {
        game_.getSystem<ScriptSystem>().runDebugScript(debugText_);
        debugText_.clear();
      } else if (debugConsole_ && e.key.keysym.sym == SDLK_BACKSPACE) {
        // Make sure to keep the backtick/heart.
        if (!debugText_.empty()) {
          debugText_.pop_back();
        }
      } else if (debugConsole_ && e.key.keysym.sym == SDLK_v && SDL_GetModState() & (KMOD_CTRL | KMOD_GUI)) {
        // CTRL-V or CMD-V bc I have a Mac thanks
        char* clipboardText = SDL_GetClipboardText();
        debugText_.append(clipboardText);
        SDL_free(clipboardText);
      } else if (e.key.keysym.sym == SDLK_m) {
        if (!debugConsole_ && !game_.getSystem<MenuSystem>().isMenuOpen()) {
          if (game_.getMixer().isMusicMuted()) {
            game_.getMixer().unmuteMusic();
          } else {
            game_.getMixer().muteMusic();
          }
        }
      } else if (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT) {
        if (game_.isGameplayPaused()) continue;

        for (int spriteId : game_.getSprites()) {
          Sprite& sprite = game_.getSprite(spriteId);
          if (sprite.controllable) {
            game_.getSystem<CharacterSystem>().beginCrouch(spriteId);
          }
        }
      } else if (e.key.keysym.sym == SDLK_SPACE) {
        if (game_.getSystem<MenuSystem>().isMenuOpen()) {
          game_.getSystem<MenuSystem>().activateOption();
        }

        if (game_.isGameplayPaused()) continue;

        // If there is text on screen, try to advance it.
        if (game_.getSystem<MessageSystem>().getCutsceneBarsProgress() != 0.0) {
          game_.getSystem<MessageSystem>().advanceText();
        } else {
          // Otherwise, check if there is a sprite in front of the player.
          bool inFrontOfSomething = false;
          bool activated = false;

          for (int spriteId : game_.getSprites()) {
            Sprite& sprite = game_.getSprite(spriteId);
            if (sprite.controllable) {
              // Interacting with objects always uses Lucas's movement speed.
              vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * LUCAS_MOVEMENT_SPEED);
              CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, sprite.loc, checkLoc, sprite.dir);

              if (collision.blocked) {
                inFrontOfSomething = true;
              }

              // If there is a sprite to be interacted with, rotate that sprite so it is facing the player.
              // Then, run its interaction script if present.
              for (int colliderSpriteId : collision.colliders) {
                game_.getSystem<AnimationSystem>().setSpriteDirection(colliderSpriteId, oppositeDirection(sprite.dir));

                Sprite& collider = game_.getSprite(colliderSpriteId);
                if (!collider.interactionScript.empty()) {
                  game_.getSystem<ScriptSystem>().runScript(game_.getMap().getName(), collider.interactionScript);
                  activated = true;
                }
              }
            }
          }

          if (inFrontOfSomething && !activated) {
            game_.getSystem<ScriptSystem>().runScript("global", "no_problem_here");
          }
        }
      } else if (e.key.keysym.sym == SDLK_LEFT) {
        if (game_.getSystem<MenuSystem>().isMenuOpen()) {
          game_.getSystem<MenuSystem>().pressedLeft();
        }

        if (game_.isGameplayPaused()) continue;

        if (game_.getSystem<MessageSystem>().isChoiceActive()) {
          game_.getSystem<MessageSystem>().selectFirstChoice();
        }
      } else if (e.key.keysym.sym == SDLK_RIGHT) {
        if (game_.getSystem<MenuSystem>().isMenuOpen()) {
          game_.getSystem<MenuSystem>().pressedRight();
        }

        if (game_.isGameplayPaused()) continue;

        if (game_.getSystem<MessageSystem>().isChoiceActive()) {
          game_.getSystem<MessageSystem>().selectSecondChoice();
        }
      } else if (e.key.keysym.sym == SDLK_UP) {
        if (game_.getSystem<MenuSystem>().isMenuOpen()) {
          game_.getSystem<MenuSystem>().pressedUp();
        }
      } else if (e.key.keysym.sym == SDLK_DOWN) {
        if (game_.getSystem<MenuSystem>().isMenuOpen()) {
          game_.getSystem<MenuSystem>().pressedDown();
        }
      }
    } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) {
      if (game_.isGameplayPaused()) continue;

      for (int spriteId : game_.getSprites()) {
        Sprite& sprite = game_.getSprite(spriteId);
        if (sprite.controllable) {
          game_.getSystem<CharacterSystem>().endCrouch(spriteId);
        }
      }
    }
  }

  if (game_.isGameplayPaused()) return;

  Input keystate;
  const Uint8* state = SDL_GetKeyboardState(NULL);
  keystate.left = state[SDL_SCANCODE_LEFT];
  keystate.right = state[SDL_SCANCODE_RIGHT];
  keystate.up = state[SDL_SCANCODE_UP];
  keystate.down = state[SDL_SCANCODE_DOWN];

  for (int spriteId : game_.getSprites()) {
    Sprite& sprite = game_.getSprite(spriteId);

    if (sprite.controllable) {
      bool directed = false;
      Direction dir = Direction::left;

      if (keystate.up)
      {
        directed = true;
        dir = Direction::up;
      } else if (keystate.down)
      {
        directed = true;
        dir = Direction::down;
      }

      if (keystate.left)
      {
        directed = true;
        if (dir == Direction::up) {
          dir = Direction::up_left;
        } else if (dir == Direction::down) {
          dir = Direction::down_left;
        } else {
          dir = Direction::left;
        }
      } else if (keystate.right)
      {
        directed = true;
        if (dir == Direction::up) {
          dir = Direction::up_right;
        } else if (dir == Direction::down) {
          dir = Direction::down_right;
        } else {
          dir = Direction::right;
        }
      }

      if (directed) {
        game_.getSystem<CharacterSystem>().moveInDirection(spriteId, dir);
      } else {
        game_.getSystem<CharacterSystem>().stopDirecting(spriteId);
      }
    }
  }
}