summary refs log tree commit diff stats
path: root/src/input_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-06 13:24:35 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-06 13:24:35 -0500
commit6d6e03b95b197d3a16b629131d463263b46c1e42 (patch)
tree6e730293c3bbeadb3fe3ebfc3f64016a7e885bff /src/input_system.cpp
parent1abc8894c2378596542e5772cd7594492eeecb27 (diff)
downloadtanetane-6d6e03b95b197d3a16b629131d463263b46c1e42.tar.gz
tanetane-6d6e03b95b197d3a16b629131d463263b46c1e42.tar.bz2
tanetane-6d6e03b95b197d3a16b629131d463263b46c1e42.zip
Added sprite interaction
Diffstat (limited to 'src/input_system.cpp')
-rw-r--r--src/input_system.cpp46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/input_system.cpp b/src/input_system.cpp index 6ddb59e..5133e27 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -3,6 +3,8 @@
3#include "character_system.h" 3#include "character_system.h"
4#include "message_system.h" 4#include "message_system.h"
5#include "script_system.h" 5#include "script_system.h"
6#include "transform_system.h"
7#include "animation_system.h"
6 8
7struct Input { 9struct Input {
8 bool left = false; 10 bool left = false;
@@ -26,20 +28,38 @@ void InputSystem::tick(double dt) {
26 game_.getSystem<CharacterSystem>().beginCrouch(spriteId); 28 game_.getSystem<CharacterSystem>().beginCrouch(spriteId);
27 } 29 }
28 } 30 }
29 } else if (e.key.keysym.sym == SDLK_a) { 31 } else if (e.key.keysym.sym == SDLK_SPACE) {
30 // TODO: Remove this, it's just for testing. 32 // If there is text on screen, try to advance it.
31 /*if (game_.getSystem<MessageSystem>().getCutsceneBarsProgress() == 1.0) { 33 if (game_.getSystem<MessageSystem>().getCutsceneBarsProgress() != 0.0) {
32 game_.getSystem<MessageSystem>().hideCutsceneBars(); 34 game_.getSystem<MessageSystem>().advanceText();
33 } else { 35 } else {
34 game_.getSystem<MessageSystem>().displayCutsceneBars(); 36 // Otherwise, check if there is a sprite in front of the player.
35 }*/ 37 for (int spriteId : game_.getSprites()) {
36 //game_.getSystem<MessageSystem>().displayMessage("Some people always try to avoid fighting when there are enemies around. You know the type, right? They use the dash ability to zoom right by. I guess you could say they're followers of \"peace at any price\".", "Sparrow", SpeakerType::Woman); 38 Sprite& sprite = game_.getSprite(spriteId);
37 //game_.getSystem<MessageSystem>().displayMessage("Lucas. You're awful at hide-and-seek, you know that? Try harder.", "Kumatora", SpeakerType::Woman); 39 if (sprite.controllable) {
38 //game_.getSystem<MessageSystem>().displayMessage("Hi Tooth! I hope you're having a good day.", "Lucas", SpeakerType::Boy); 40 vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * MOVEMENT_SPEED);
39 game_.getSystem<ScriptSystem>().runScript("script0001"); 41 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, checkLoc, sprite.dir);
40 } else if (e.key.keysym.sym == SDLK_b) { 42
41 // TODO: Remove this, it's just for testing. 43 // If there is a sprite to be interacted with, rotate that sprite so it is facing the player.
42 game_.getSystem<MessageSystem>().advanceText(); 44 // Then, run its interaction script if present.
45 if (collision.horiz.colliderSprite != -1) {
46 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.horiz.colliderSprite, oppositeDirection(sprite.dir));
47
48 Sprite& collider = game_.getSprite(collision.horiz.colliderSprite);
49 if (collider.interactionScript != "") {
50 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript);
51 }
52 } else if (collision.vert.colliderSprite != -1) {
53 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.vert.colliderSprite, oppositeDirection(sprite.dir));
54
55 Sprite& collider = game_.getSprite(collision.vert.colliderSprite);
56 if (collider.interactionScript != "") {
57 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript);
58 }
59 }
60 }
61 }
62 }
43 } 63 }
44 } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) { 64 } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) {
45 for (int spriteId : game_.getSprites()) { 65 for (int spriteId : game_.getSprites()) {