From 7fa69be4e88f1fcf057871fec7e4503f50578465 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 1 Mar 2021 22:19:46 -0500 Subject: Started writing the Mixolydia scene! Looking pretty good so far. TODO: direction facing functions have inverted Y coordinate. confusion expression doesn't exist yet. rest of scene. --- src/behaviour_system.cpp | 1 + src/character_system.cpp | 1 + src/direction.h | 17 +++++++++++++++++ src/main.cpp | 4 ++-- src/script_system.cpp | 7 ++++++- 5 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/behaviour_system.cpp b/src/behaviour_system.cpp index 4a194f0..a05912c 100644 --- a/src/behaviour_system.cpp +++ b/src/behaviour_system.cpp @@ -59,6 +59,7 @@ void BehaviourSystem::tick(double dt) { void BehaviourSystem::directSpriteToLocation(int spriteId, vec2i pos, PathfindingOptions options) { Sprite& sprite = game_.getSprite(spriteId); + sprite.orientable = true; sprite.behaviourType = BehaviourType::Path; sprite.pathfindingDestination = pos; sprite.cardinalDirectionsOnly = pathfindingOptionsContains(options, PathfindingOptions::CardinalDirectionsOnly); diff --git a/src/character_system.cpp b/src/character_system.cpp index 53debb2..48d2a33 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp @@ -17,6 +17,7 @@ void CharacterSystem::initSprite(int spriteId, int movementSpeed) { void CharacterSystem::addSpriteToParty(int leaderId, int followerId) { Sprite& leader = game_.getSprite(leaderId); Sprite& follower = game_.getSprite(followerId); + follower.orientable = false; vec2i targetPos = leader.loc; diff --git a/src/direction.h b/src/direction.h index 3dd95f9..595693f 100644 --- a/src/direction.h +++ b/src/direction.h @@ -90,4 +90,21 @@ inline Direction directionFacingPoint(vec2i point) { } } +inline Direction cardinalDirectionFacingPoint(vec2i point) { + double theta = atan2(point.y(), point.x()); + theta /= M_PI; + + if (theta < -3.0/4.0) { + return Direction::left; + } else if (theta < -1.0/4.0) { + return Direction::down; + } else if (theta < 1.0/4.0) { + return Direction::right; + } else if (theta < 3.0/4.0) { + return Direction::up; + } else { + return Direction::left; + } +} + #endif /* end of include guard: DIRECTION_H_AB66A90E */ diff --git a/src/main.cpp b/src/main.cpp index b98c8f1..d0220fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,9 +27,9 @@ void loop(Renderer& renderer, std::mt19937& rng) { game.emplaceSystem(); game.emplaceSystem(); - game.loadMap("hallucination_interior"); + game.loadMap("pink_shell"); - vec2i warpLoc = game.getMap().getWarpPoint("debugWarp_rightside"); + vec2i warpLoc = game.getMap().getWarpPoint("fromOutside"); int lucasSprite = game.emplaceSprite("lucas"); game.getSystem().initSprite(lucasSprite, warpLoc); diff --git a/src/script_system.cpp b/src/script_system.cpp index 931759d..a3686b4 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -44,7 +44,10 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { "cantCrouch", &Sprite::cantCrouch, "bobsWhenNormal", &Sprite::bobsWhenNormal, "animSlowdown", &Sprite::animSlowdown, - "enclosureZone", &Sprite::enclosureZone); + "enclosureZone", &Sprite::enclosureZone, + "movementSpeed", &Sprite::movementSpeed, + "solid", &Sprite::solid, + "behaviourType", &Sprite::behaviourType); engine_.new_usertype( "message", @@ -230,6 +233,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { loadMapScripts(filename); }); + engine_.set_function("cardinalDirectionFacingPoint", &cardinalDirectionFacingPoint); + engine_.script_file("../res/scripts/common.lua"); } -- cgit 1.4.1