From 2c81361cc9d61dcf5050268157b3e7e92043b740 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 10 Feb 2021 18:18:47 -0500 Subject: loadMap requires a direction now, so party trails are set up correctly --- res/scripts/common.lua | 4 +--- src/character_system.cpp | 6 +++++- src/game.cpp | 6 +++++- src/game.h | 2 +- src/main.cpp | 2 +- src/script_system.cpp | 4 ++-- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 9674b2c..23c07cc 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -92,11 +92,9 @@ function ChangeMap(map, warp) local oldState = playerSprite.characterState FadeToBlack(150) - loadMap("../res/maps/" .. map .. ".tmx", warp) + loadMap("../res/maps/" .. map .. ".tmx", warp, direction) local newPlayerId = getControllableSprite() - SetPartyDirection(newPlayerId, direction) - if oldState == CharacterState.RUNNING then character():startRunning(newPlayerId) end diff --git a/src/character_system.cpp b/src/character_system.cpp index 94833a8..781b50d 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp @@ -24,7 +24,11 @@ void CharacterSystem::addSpriteToParty(int leaderId, int followerId) { targetPos = backFollower.loc; } - Direction toFace = directionFacingPoint(targetPos - follower.loc); + Direction toFace = leader.dir; + if (targetPos != follower.loc) { + toFace = directionFacingPoint(targetPos - follower.loc); + } + for (int i=0; i(PARTY_FRAME_DELAY) + targetPos; follower.trail.push_front({.pos = tween, .dir = toFace}); diff --git a/src/game.cpp b/src/game.cpp index dc3a5ba..4d44a63 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -22,7 +22,7 @@ void Game::clearSprites() { spritesByAlias_.clear(); } -void Game::loadMap(std::string filename, std::string warpPoint) { +void Game::loadMap(std::string filename, std::string warpPoint, Direction dir) { clearSprites(); map_ = std::make_unique(filename); @@ -33,22 +33,26 @@ void Game::loadMap(std::string filename, std::string warpPoint) { getSystem().initSprite(lucasSprite, warpLoc); getSystem().setUpCollision(lucasSprite, {-8, -8}, {12, 8}, true); getSystem().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt"); + getSystem().setSpriteDirection(lucasSprite, dir); getSprite(lucasSprite).controllable = true; getSystem().initSprite(lucasSprite); int kumaSprite = emplaceSprite("kuma"); getSystem().initSprite(kumaSprite, warpLoc); getSystem().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt"); + getSystem().setSpriteDirection(kumaSprite, dir); getSystem().addSpriteToParty(lucasSprite, kumaSprite); int dusterSprite = emplaceSprite("duster"); getSystem().initSprite(dusterSprite, warpLoc); getSystem().initSprite(dusterSprite, "../res/sprites/duster_anim.txt"); + getSystem().setSpriteDirection(dusterSprite, dir); getSystem().addSpriteToParty(lucasSprite, dusterSprite); int boneySprite = emplaceSprite("boney"); getSystem().initSprite(boneySprite, warpLoc); getSystem().initSprite(boneySprite, "../res/sprites/boney_anim.txt"); + getSystem().setSpriteDirection(boneySprite, dir); getSystem().addSpriteToParty(lucasSprite, boneySprite); for (const Prototype& p : map_->getPrototypes()) { diff --git a/src/game.h b/src/game.h index bb88dec..84114ca 100644 --- a/src/game.h +++ b/src/game.h @@ -73,7 +73,7 @@ public: }); } - void loadMap(std::string filename, std::string warpPoint); + void loadMap(std::string filename, std::string warpPoint, Direction dir); const Map& getMap() const { return *map_; } diff --git a/src/main.cpp b/src/main.cpp index 8487077..ddc8df2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ void loop(Renderer& renderer) { game.emplaceSystem(); game.emplaceSystem(); - game.loadMap("../res/maps/map1.tmx", "spawn"); + game.loadMap("../res/maps/map1.tmx", "spawn", Direction::down); renderer.render(game); diff --git a/src/script_system.cpp b/src/script_system.cpp index d8d93e3..e388c6e 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -88,8 +88,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { engine_.set_function( "loadMap", - [&] (std::string filename, std::string warpPoint) { - game_.loadMap(filename, warpPoint); + [&] (std::string filename, std::string warpPoint, Direction dir) { + game_.loadMap(filename, warpPoint, dir); }); engine_.set_function( -- cgit 1.4.1