about summary refs log tree commit diff stats
path: root/data/maps/the_bearer/rooms/Purple Planet (View).txtpb
Commit message (Collapse)AuthorAgeFilesLines
* Changed how door location names are formattedStar Rauchenberger2025-08-301-1/+0
| | | | | | | | | | | | | | | | | | STANDARD type doors with at most four panels in the same map area and no other trigger objects will have their location names generated from the names of the panels used to open the door, similar to Lingo 1. Other door types will use the door's name. In either case, the name can be overridden using the new location_name field. Rooms can also set a panel_display_name field, which will be used in location names for doors, and is used to group panels into areas. Panels themselves can set display names, which differentiates their locations from other panels in the same area. Many maps were updated for this, but note that the_symbolic and the_unyielding have validator failures because of duplicate panel names. This won't matter until panelsanity is implemented.
* Converted puzzle symbols to an enumStar Rauchenberger2025-08-201-1/+1
|
* Added the_bearerStar Rauchenberger2025-08-081-0/+9
='#n150'>150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
#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;
          debugHistory_.pop_front();
          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;
          debugHistorySelection_ = 0;
          debugHistory_.push_front("");
          game_.pauseGameplay();
          SDL_StartTextInput();
          debugText_.clear();
        }
#endif
      } else if (debugConsole_ && e.key.keysym.sym == SDLK_RETURN) {
        game_.getSystem<ScriptSystem>().runDebugScript(debugText_);
        debugHistory_[0] = debugText_;
        debugText_.clear();
        debugHistorySelection_ = 0;
        debugHistory_.push_front("");
      } 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 (debugConsole_ && debugHistorySelection_ < (debugHistory_.size() - 1)) {
          debugHistory_[debugHistorySelection_] = debugText_;
          debugHistorySelection_++;
          debugText_ = debugHistory_[debugHistorySelection_];
        }
        if (game_.getSystem<MenuSystem>().isMenuOpen()) {
          game_.getSystem<MenuSystem>().pressedUp();
        }
      } else if (e.key.keysym.sym == SDLK_DOWN) {
        if (debugConsole_ && debugHistorySelection_ > 0) {
          debugHistory_[debugHistorySelection_] = debugText_;
          debugHistorySelection_--;
          debugText_ = debugHistory_[debugHistorySelection_];
        }
        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);
      }
    }
  }
}