From aac3b1bc1ba48b6e50f661b97326ef191cce3e6c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 9 Mar 2021 13:49:03 -0500 Subject: switch_claus starts talking when he gets ya Kumatora, Duster, and Boney had to be given hitboxes, but they are not considered solid. #10 --- res/maps/hallucination_interior.tmx | 1 + res/scripts/hallucination_interior.lua | 7 ++++++- src/character_system.cpp | 17 +++++++++++++++++ src/game.cpp | 3 +++ src/main.cpp | 3 +++ src/map.cpp | 2 ++ src/map.h | 1 + src/sprite.h | 2 ++ 8 files changed, 35 insertions(+), 1 deletion(-) diff --git a/res/maps/hallucination_interior.tmx b/res/maps/hallucination_interior.tmx index 7e012eb..1077cf5 100644 --- a/res/maps/hallucination_interior.tmx +++ b/res/maps/hallucination_interior.tmx @@ -159,6 +159,7 @@ + diff --git a/res/scripts/hallucination_interior.lua b/res/scripts/hallucination_interior.lua index 96b90a6..c265a46 100644 --- a/res/scripts/hallucination_interior.lua +++ b/res/scripts/hallucination_interior.lua @@ -270,6 +270,7 @@ end function hallucination_interior.lets_switch_places() StartCutscene() + FaceTowardSprite("switch_claus", "lucas") FacePartyTowardSprite("lucas", "switch_claus") Halt("switch_claus") SetAnimation("switch_claus", "talk") @@ -280,9 +281,13 @@ function hallucination_interior.lets_switch_places() if GetChoiceSelection() == 0 then DisplayMessage("* You'd like that, wouldn't you?\n\f* ...no. That's too easy.\n\fI'm not letting you off that easy.\n\f* It should've been you, right?\nYou feel guilty, right?\n\f* Well guess what, Lucas?\n\fYou're going to live with that for the rest of your life.\n\f* You know why?\n\f* Because you're going to live, Lucas!\n\fYOU'RE. GOING. TO. LIVE!", "Claus", SpeakerType.MAN) - SetAnimation("switch_claus", "still") HideCutsceneBars() + + SetAnimation("switch_claus", "still") else -- TODO: let's switch places end + + -- Just so we can get away, for now. + hallucination_interior.switch_claus_lose_interest() end diff --git a/src/character_system.cpp b/src/character_system.cpp index 48d2a33..548bd9d 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp @@ -18,6 +18,7 @@ void CharacterSystem::addSpriteToParty(int leaderId, int followerId) { Sprite& leader = game_.getSprite(leaderId); Sprite& follower = game_.getSprite(followerId); follower.orientable = false; + follower.leaderId = leaderId; vec2i targetPos = leader.loc; @@ -83,6 +84,7 @@ void CharacterSystem::breakUpParty(int leaderId) { for (int followerId : followers) { Sprite& follower = game_.getSprite(followerId); follower.trail.clear(); + follower.leaderId = -1; } } @@ -153,6 +155,7 @@ void CharacterSystem::tick(double dt) { // Check collision. CollisionResult collision = game_.getSystem().checkCollision(spriteId, sprite.loc, pLoc, sprite.movementDir); bool blocked = collision.horiz.blocked || collision.vert.blocked; + int colliderSpriteId = (collision.horiz.colliderSprite == -1) ? collision.vert.colliderSprite : collision.horiz.colliderSprite; if (collision.horiz.blocked && !sprite.clipping) { pLoc.x() = sprite.loc.x();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1; @@ -179,6 +182,20 @@ void CharacterSystem::tick(double dt) { game_.getMixer().playSound("../res/sfx/bump.wav"); } + if (colliderSpriteId != -1 && !sprite.bumpPlayerScript.empty()) { + Sprite& collider = game_.getSprite(colliderSpriteId); + bool bumpedPlayer = collider.player; + + if (!bumpedPlayer && collider.leaderId != -1) { + Sprite& colliderLeader = game_.getSprite(collider.leaderId); + bumpedPlayer = colliderLeader.player; + } + + if (bumpedPlayer) { + game_.getSystem().runScript(game_.getMap().getName(), sprite.bumpPlayerScript); + } + } + // Move everything if (pLoc != sprite.loc) { game_.getSystem().moveSprite(spriteId, pLoc); diff --git a/src/game.cpp b/src/game.cpp index bedd934..80ff506 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -72,6 +72,9 @@ void Game::loadMap(std::string filename) { if (p.wander) { getSprite(spriteId).behaviourType = BehaviourType::Wander; } + if (!p.bumpPlayerScript.empty()) { + getSprite(spriteId).bumpPlayerScript = p.bumpPlayerScript; + } } if (!p.enclosureZone.empty()) { getSprite(spriteId).enclosureZone = p.enclosureZone; diff --git a/src/main.cpp b/src/main.cpp index 9cc25bb..051c4d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,7 @@ void loop(Renderer& renderer, std::mt19937& rng) { int kumaSprite = game.emplaceSprite("kuma"); game.getSystem().initSprite(kumaSprite, warpLoc); + game.getSystem().setUpCollision(kumaSprite, {-8, -8}, {12, 8}, false); game.getSystem().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt"); game.getSystem().setSpriteDirection(kumaSprite, Direction::down); game.getSprite(kumaSprite).normallyHasShadow = true; @@ -56,6 +57,7 @@ void loop(Renderer& renderer, std::mt19937& rng) { int dusterSprite = game.emplaceSprite("duster"); game.getSystem().initSprite(dusterSprite, warpLoc); + game.getSystem().setUpCollision(dusterSprite, {-8, -8}, {12, 8}, false); game.getSystem().initSprite(dusterSprite, "../res/sprites/duster_anim.txt"); game.getSystem().setSpriteDirection(dusterSprite, Direction::down); game.getSprite(dusterSprite).normallyHasShadow = true; @@ -64,6 +66,7 @@ void loop(Renderer& renderer, std::mt19937& rng) { int boneySprite = game.emplaceSprite("boney"); game.getSystem().initSprite(boneySprite, warpLoc); + game.getSystem().setUpCollision(boneySprite, {-8, -8}, {12, 8}, false); game.getSystem().initSprite(boneySprite, "../res/sprites/boney_anim.txt"); game.getSystem().setSpriteDirection(boneySprite, Direction::down); game.getSprite(boneySprite).normallyHasShadow = true; diff --git a/src/map.cpp b/src/map.cpp index 32203e5..a170288 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -119,6 +119,8 @@ Map::Map(std::string_view name) : name_(name) { p.mirrorAxis = property.getIntValue(); } else if (property.getName() == "mirrorSprite") { p.spriteToMirror = property.getStringValue(); + } else if (property.getName() == "bumpPlayerScript") { + p.bumpPlayerScript = property.getStringValue(); } } diff --git a/src/map.h b/src/map.h index eb926c7..9418aad 100644 --- a/src/map.h +++ b/src/map.h @@ -27,6 +27,7 @@ struct Prototype { std::string animName; Direction dir = Direction::down; std::string interactionScript; + std::string bumpPlayerScript; bool shadow = false; bool wander = false; int movementSpeed = -1; diff --git a/src/sprite.h b/src/sprite.h index 10dd3a8..f631652 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -81,6 +81,7 @@ public: vec2i collisionSize; std::string interactionScript; std::string walkthroughScript; + std::string bumpPlayerScript; std::string enclosureZone; // Animation (internals) @@ -109,6 +110,7 @@ public: bool orientable = false; int movementSpeed = 0; // 1 is slow (good for NPCs), 2 is Lucas's default walking speed std::vector followers; + int leaderId = -1; std::deque trail; bool trailsAreHalved = false; CharacterState characterState = CharacterState::Still; -- cgit 1.4.1