summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input_system.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/input_system.cpp b/src/input_system.cpp index 5133e27..5158724 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -34,12 +34,19 @@ void InputSystem::tick(double dt) {
34 game_.getSystem<MessageSystem>().advanceText(); 34 game_.getSystem<MessageSystem>().advanceText();
35 } else { 35 } else {
36 // Otherwise, check if there is a sprite in front of the player. 36 // Otherwise, check if there is a sprite in front of the player.
37 bool inFrontOfSomething = false;
38 bool activated = false;
39
37 for (int spriteId : game_.getSprites()) { 40 for (int spriteId : game_.getSprites()) {
38 Sprite& sprite = game_.getSprite(spriteId); 41 Sprite& sprite = game_.getSprite(spriteId);
39 if (sprite.controllable) { 42 if (sprite.controllable) {
40 vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * MOVEMENT_SPEED); 43 vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * MOVEMENT_SPEED);
41 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, checkLoc, sprite.dir); 44 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, checkLoc, sprite.dir);
42 45
46 if (collision.horiz.blocked || collision.vert.blocked) {
47 inFrontOfSomething = true;
48 }
49
43 // If there is a sprite to be interacted with, rotate that sprite so it is facing the player. 50 // If there is a sprite to be interacted with, rotate that sprite so it is facing the player.
44 // Then, run its interaction script if present. 51 // Then, run its interaction script if present.
45 if (collision.horiz.colliderSprite != -1) { 52 if (collision.horiz.colliderSprite != -1) {
@@ -48,6 +55,7 @@ void InputSystem::tick(double dt) {
48 Sprite& collider = game_.getSprite(collision.horiz.colliderSprite); 55 Sprite& collider = game_.getSprite(collision.horiz.colliderSprite);
49 if (collider.interactionScript != "") { 56 if (collider.interactionScript != "") {
50 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript); 57 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript);
58 activated = true;
51 } 59 }
52 } else if (collision.vert.colliderSprite != -1) { 60 } else if (collision.vert.colliderSprite != -1) {
53 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.vert.colliderSprite, oppositeDirection(sprite.dir)); 61 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.vert.colliderSprite, oppositeDirection(sprite.dir));
@@ -55,10 +63,15 @@ void InputSystem::tick(double dt) {
55 Sprite& collider = game_.getSprite(collision.vert.colliderSprite); 63 Sprite& collider = game_.getSprite(collision.vert.colliderSprite);
56 if (collider.interactionScript != "") { 64 if (collider.interactionScript != "") {
57 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript); 65 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript);
66 activated = true;
58 } 67 }
59 } 68 }
60 } 69 }
61 } 70 }
71
72 if (inFrontOfSomething && !activated) {
73 game_.getSystem<ScriptSystem>().runScript("default");
74 }
62 } 75 }
63 } 76 }
64 } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) { 77 } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) {