From 6d6e03b95b197d3a16b629131d463263b46c1e42 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 6 Feb 2021 13:24:35 -0500 Subject: Added sprite interaction --- src/input_system.cpp | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/input_system.cpp') 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 @@ #include "character_system.h" #include "message_system.h" #include "script_system.h" +#include "transform_system.h" +#include "animation_system.h" struct Input { bool left = false; @@ -26,20 +28,38 @@ void InputSystem::tick(double dt) { game_.getSystem().beginCrouch(spriteId); } } - } else if (e.key.keysym.sym == SDLK_a) { - // TODO: Remove this, it's just for testing. - /*if (game_.getSystem().getCutsceneBarsProgress() == 1.0) { - game_.getSystem().hideCutsceneBars(); + } else if (e.key.keysym.sym == SDLK_SPACE) { + // If there is text on screen, try to advance it. + if (game_.getSystem().getCutsceneBarsProgress() != 0.0) { + game_.getSystem().advanceText(); } else { - game_.getSystem().displayCutsceneBars(); - }*/ - //game_.getSystem().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); - //game_.getSystem().displayMessage("Lucas. You're awful at hide-and-seek, you know that? Try harder.", "Kumatora", SpeakerType::Woman); - //game_.getSystem().displayMessage("Hi Tooth! I hope you're having a good day.", "Lucas", SpeakerType::Boy); - game_.getSystem().runScript("script0001"); - } else if (e.key.keysym.sym == SDLK_b) { - // TODO: Remove this, it's just for testing. - game_.getSystem().advanceText(); + // Otherwise, check if there is a sprite in front of the player. + for (int spriteId : game_.getSprites()) { + Sprite& sprite = game_.getSprite(spriteId); + if (sprite.controllable) { + vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * MOVEMENT_SPEED); + CollisionResult collision = game_.getSystem().checkCollision(spriteId, checkLoc, sprite.dir); + + // 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. + if (collision.horiz.colliderSprite != -1) { + game_.getSystem().setSpriteDirection(collision.horiz.colliderSprite, oppositeDirection(sprite.dir)); + + Sprite& collider = game_.getSprite(collision.horiz.colliderSprite); + if (collider.interactionScript != "") { + game_.getSystem().runScript(collider.interactionScript); + } + } else if (collision.vert.colliderSprite != -1) { + game_.getSystem().setSpriteDirection(collision.vert.colliderSprite, oppositeDirection(sprite.dir)); + + Sprite& collider = game_.getSprite(collision.vert.colliderSprite); + if (collider.interactionScript != "") { + game_.getSystem().runScript(collider.interactionScript); + } + } + } + } + } } } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) { for (int spriteId : game_.getSprites()) { -- cgit 1.4.1