summary refs log tree commit diff stats
path: root/src/input_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-03-11 16:06:19 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2021-03-11 17:33:15 -0500
commiteb9fa5020317a44f17cc4906c4c1c6fe55700d3e (patch)
treee4cb67d97818e06d974d0fca987dd76f25affdf9 /src/input_system.cpp
parent4c29543e44deb7a327b21b0af6a85a92e83ff103 (diff)
downloadtanetane-eb9fa5020317a44f17cc4906c4c1c6fe55700d3e.tar.gz
tanetane-eb9fa5020317a44f17cc4906c4c1c6fe55700d3e.tar.bz2
tanetane-eb9fa5020317a44f17cc4906c4c1c6fe55700d3e.zip
Simplified collision detection output
It is no longer split into horizontal and vertical results. Also, the collision detection routine now does the work of calculating an adjusted position, instead of the caller (CharacterSystem) having to do it. This will be useful for #3.
Diffstat (limited to 'src/input_system.cpp')
-rw-r--r--src/input_system.cpp18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/input_system.cpp b/src/input_system.cpp index 38423a2..c399e91 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -87,25 +87,17 @@ void InputSystem::tick(double dt) {
87 vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * LUCAS_MOVEMENT_SPEED); 87 vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * LUCAS_MOVEMENT_SPEED);
88 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, sprite.loc, checkLoc, sprite.dir); 88 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, sprite.loc, checkLoc, sprite.dir);
89 89
90 if (collision.horiz.blocked || collision.vert.blocked) { 90 if (collision.blocked) {
91 inFrontOfSomething = true; 91 inFrontOfSomething = true;
92 } 92 }
93 93
94 // If there is a sprite to be interacted with, rotate that sprite so it is facing the player. 94 // If there is a sprite to be interacted with, rotate that sprite so it is facing the player.
95 // Then, run its interaction script if present. 95 // Then, run its interaction script if present.
96 if (collision.horiz.colliderSprite != -1) { 96 for (int colliderSpriteId : collision.colliders) {
97 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.horiz.colliderSprite, oppositeDirection(sprite.dir)); 97 game_.getSystem<AnimationSystem>().setSpriteDirection(colliderSpriteId, oppositeDirection(sprite.dir));
98 98
99 Sprite& collider = game_.getSprite(collision.horiz.colliderSprite); 99 Sprite& collider = game_.getSprite(colliderSpriteId);
100 if (collider.interactionScript != "") { 100 if (!collider.interactionScript.empty()) {
101 game_.getSystem<ScriptSystem>().runScript(game_.getMap().getName(), collider.interactionScript);
102 activated = true;
103 }
104 } else if (collision.vert.colliderSprite != -1) {
105 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.vert.colliderSprite, oppositeDirection(sprite.dir));
106
107 Sprite& collider = game_.getSprite(collision.vert.colliderSprite);
108 if (collider.interactionScript != "") {
109 game_.getSystem<ScriptSystem>().runScript(game_.getMap().getName(), collider.interactionScript); 101 game_.getSystem<ScriptSystem>().runScript(game_.getMap().getName(), collider.interactionScript);
110 activated = true; 102 activated = true;
111 } 103 }