diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-20 13:34:04 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-20 13:34:04 -0500 |
commit | f0eab98e417bf648261a9027bef91fe935af76cb (patch) | |
tree | 7c212cbe8bd549d5a6229c616806095596859a8f | |
parent | ca4935cb65325edbd45d4a3aacc921ea9ed9483b (diff) | |
download | tanetane-f0eab98e417bf648261a9027bef91fe935af76cb.tar.gz tanetane-f0eab98e417bf648261a9027bef91fe935af76cb.tar.bz2 tanetane-f0eab98e417bf648261a9027bef91fe935af76cb.zip |
Added variable movement speed
Ionia now moves at half Lucas's speed, which I think is good for NPCs.
-rw-r--r-- | res/maps/map2.tmx | 1 | ||||
-rw-r--r-- | src/character_system.cpp | 11 | ||||
-rw-r--r-- | src/character_system.h | 2 | ||||
-rw-r--r-- | src/consts.h | 4 | ||||
-rw-r--r-- | src/game.cpp | 8 | ||||
-rw-r--r-- | src/input_system.cpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/map.cpp | 2 | ||||
-rw-r--r-- | src/map.h | 1 | ||||
-rw-r--r-- | src/sprite.h | 1 |
10 files changed, 23 insertions, 12 deletions
diff --git a/res/maps/map2.tmx b/res/maps/map2.tmx index 87dbb1e..af021bf 100644 --- a/res/maps/map2.tmx +++ b/res/maps/map2.tmx | |||
@@ -696,6 +696,7 @@ | |||
696 | <property name="collisionOffsetY" type="int" value="-8"/> | 696 | <property name="collisionOffsetY" type="int" value="-8"/> |
697 | <property name="collisionWidth" type="int" value="12"/> | 697 | <property name="collisionWidth" type="int" value="12"/> |
698 | <property name="enclosureZone" value="ionia_enclosure"/> | 698 | <property name="enclosureZone" value="ionia_enclosure"/> |
699 | <property name="movementSpeed" type="int" value="1"/> | ||
699 | <property name="shadow" type="bool" value="true"/> | 700 | <property name="shadow" type="bool" value="true"/> |
700 | <property name="wander" type="bool" value="true"/> | 701 | <property name="wander" type="bool" value="true"/> |
701 | </properties> | 702 | </properties> |
diff --git a/src/character_system.cpp b/src/character_system.cpp index 7d456f6..e6dddf6 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp | |||
@@ -7,9 +7,10 @@ | |||
7 | #include "animation_system.h" | 7 | #include "animation_system.h" |
8 | #include "script_system.h" | 8 | #include "script_system.h" |
9 | 9 | ||
10 | void CharacterSystem::initSprite(int spriteId) { | 10 | void CharacterSystem::initSprite(int spriteId, int movementSpeed) { |
11 | Sprite& sprite = game_.getSprite(spriteId); | 11 | Sprite& sprite = game_.getSprite(spriteId); |
12 | sprite.orientable = true; | 12 | sprite.orientable = true; |
13 | sprite.movementSpeed = movementSpeed; | ||
13 | } | 14 | } |
14 | 15 | ||
15 | void CharacterSystem::addSpriteToParty(int leaderId, int followerId) { | 16 | void CharacterSystem::addSpriteToParty(int leaderId, int followerId) { |
@@ -29,8 +30,10 @@ void CharacterSystem::addSpriteToParty(int leaderId, int followerId) { | |||
29 | toFace = directionFacingPoint(targetPos - follower.loc); | 30 | toFace = directionFacingPoint(targetPos - follower.loc); |
30 | } | 31 | } |
31 | 32 | ||
32 | for (int i=0; i<PARTY_FRAME_DELAY; i++) { | 33 | int truePartyDelay = PARTY_FRAME_DELAY / leader.movementSpeed; |
33 | vec2i tween = ((follower.loc - targetPos) * i) / static_cast<double>(PARTY_FRAME_DELAY) + targetPos; | 34 | |
35 | for (int i=0; i<truePartyDelay; i++) { | ||
36 | vec2i tween = ((follower.loc - targetPos) * i) / static_cast<double>(truePartyDelay) + targetPos; | ||
34 | follower.trail.push_front({.pos = tween, .dir = toFace}); | 37 | follower.trail.push_front({.pos = tween, .dir = toFace}); |
35 | } | 38 | } |
36 | 39 | ||
@@ -101,7 +104,7 @@ void CharacterSystem::tick(double dt) { | |||
101 | continue; | 104 | continue; |
102 | } | 105 | } |
103 | 106 | ||
104 | int speed = MOVEMENT_SPEED; | 107 | int speed = sprite.movementSpeed; |
105 | if (sprite.characterState == CharacterState::Running) { | 108 | if (sprite.characterState == CharacterState::Running) { |
106 | speed *= 2; | 109 | speed *= 2; |
107 | } | 110 | } |
diff --git a/src/character_system.h b/src/character_system.h index 8c2ea54..79c1710 100644 --- a/src/character_system.h +++ b/src/character_system.h | |||
@@ -17,7 +17,7 @@ public: | |||
17 | 17 | ||
18 | CharacterSystem(Game& game) : game_(game) {} | 18 | CharacterSystem(Game& game) : game_(game) {} |
19 | 19 | ||
20 | void initSprite(int spriteId); | 20 | void initSprite(int spriteId, int movementSpeed); |
21 | 21 | ||
22 | void tick(double dt) override; | 22 | void tick(double dt) override; |
23 | 23 | ||
diff --git a/src/consts.h b/src/consts.h index 38e0ef8..e0af6cd 100644 --- a/src/consts.h +++ b/src/consts.h | |||
@@ -7,8 +7,8 @@ const int GAME_HEIGHT = 480; | |||
7 | const int CANVAS_WIDTH = 240; | 7 | const int CANVAS_WIDTH = 240; |
8 | const int CANVAS_HEIGHT = 160; | 8 | const int CANVAS_HEIGHT = 160; |
9 | 9 | ||
10 | const int MOVEMENT_SPEED = 2; | 10 | const int LUCAS_MOVEMENT_SPEED = 2; |
11 | const int PARTY_FRAME_DELAY = 10;// / MOVEMENT_SPEED; | 11 | const int PARTY_FRAME_DELAY = 20; // true delay is this divided by movement speed (so for Lucas walking it's 10) |
12 | 12 | ||
13 | const int MESSAGE_TEXT_WIDTH = 196; | 13 | const int MESSAGE_TEXT_WIDTH = 196; |
14 | 14 | ||
diff --git a/src/game.cpp b/src/game.cpp index 5c0017d..b5393a8 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -62,9 +62,11 @@ void Game::loadMap(std::string filename) { | |||
62 | getSprite(spriteId).hasShadow = p.shadow; | 62 | getSprite(spriteId).hasShadow = p.shadow; |
63 | } | 63 | } |
64 | getSprite(spriteId).interactionScript = p.interactionScript; | 64 | getSprite(spriteId).interactionScript = p.interactionScript; |
65 | if (p.wander) { | 65 | if (p.movementSpeed != -1) { |
66 | getSystem<CharacterSystem>().initSprite(spriteId); | 66 | getSystem<CharacterSystem>().initSprite(spriteId, p.movementSpeed); |
67 | getSprite(spriteId).wander = true; | 67 | if (p.wander) { |
68 | getSprite(spriteId).wander = true; | ||
69 | } | ||
68 | } | 70 | } |
69 | if (!p.enclosureZone.empty()) { | 71 | if (!p.enclosureZone.empty()) { |
70 | getSprite(spriteId).enclosureZone = p.enclosureZone; | 72 | getSprite(spriteId).enclosureZone = p.enclosureZone; |
diff --git a/src/input_system.cpp b/src/input_system.cpp index 2201907..43c59dd 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp | |||
@@ -40,7 +40,8 @@ void InputSystem::tick(double dt) { | |||
40 | for (int spriteId : game_.getSprites()) { | 40 | for (int spriteId : game_.getSprites()) { |
41 | Sprite& sprite = game_.getSprite(spriteId); | 41 | Sprite& sprite = game_.getSprite(spriteId); |
42 | if (sprite.controllable) { | 42 | if (sprite.controllable) { |
43 | vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * MOVEMENT_SPEED); | 43 | // Interacting with objects always uses Lucas's movement speed. |
44 | vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * LUCAS_MOVEMENT_SPEED); | ||
44 | CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, checkLoc, sprite.dir); | 45 | CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, checkLoc, sprite.dir); |
45 | 46 | ||
46 | if (collision.horiz.blocked || collision.vert.blocked) { | 47 | if (collision.horiz.blocked || collision.vert.blocked) { |
diff --git a/src/main.cpp b/src/main.cpp index 9f503e1..e40b4f4 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -40,7 +40,7 @@ void loop(Renderer& renderer, std::mt19937& rng) { | |||
40 | game.getSprite(lucasSprite).player = true; | 40 | game.getSprite(lucasSprite).player = true; |
41 | game.getSprite(lucasSprite).controllable = true; | 41 | game.getSprite(lucasSprite).controllable = true; |
42 | game.getSprite(lucasSprite).persistent = true; | 42 | game.getSprite(lucasSprite).persistent = true; |
43 | game.getSystem<CharacterSystem>().initSprite(lucasSprite); | 43 | game.getSystem<CharacterSystem>().initSprite(lucasSprite, LUCAS_MOVEMENT_SPEED); |
44 | game.getSystem<CameraSystem>().setFollowingSprite(lucasSprite); | 44 | game.getSystem<CameraSystem>().setFollowingSprite(lucasSprite); |
45 | game.getSystem<CameraSystem>().unlockCamera(); | 45 | game.getSystem<CameraSystem>().unlockCamera(); |
46 | 46 | ||
diff --git a/src/map.cpp b/src/map.cpp index 5845009..d7c1e7e 100644 --- a/src/map.cpp +++ b/src/map.cpp | |||
@@ -80,6 +80,8 @@ Map::Map(std::string_view name) : name_(name) { | |||
80 | p.wander = property.getBoolValue(); | 80 | p.wander = property.getBoolValue(); |
81 | } else if (property.getName() == "enclosureZone") { | 81 | } else if (property.getName() == "enclosureZone") { |
82 | p.enclosureZone = property.getStringValue(); | 82 | p.enclosureZone = property.getStringValue(); |
83 | } else if (property.getName() == "movementSpeed") { | ||
84 | p.movementSpeed = property.getIntValue(); | ||
83 | } | 85 | } |
84 | } | 86 | } |
85 | 87 | ||
diff --git a/src/map.h b/src/map.h index e4096f4..a311be1 100644 --- a/src/map.h +++ b/src/map.h | |||
@@ -25,6 +25,7 @@ struct Prototype { | |||
25 | std::string interactionScript; | 25 | std::string interactionScript; |
26 | bool shadow = false; | 26 | bool shadow = false; |
27 | bool wander = false; | 27 | bool wander = false; |
28 | int movementSpeed = -1; | ||
28 | std::string enclosureZone; | 29 | std::string enclosureZone; |
29 | }; | 30 | }; |
30 | 31 | ||
diff --git a/src/sprite.h b/src/sprite.h index e0cff0c..4e3e490 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
@@ -70,6 +70,7 @@ public: | |||
70 | 70 | ||
71 | // Character | 71 | // Character |
72 | bool orientable = false; | 72 | bool orientable = false; |
73 | int movementSpeed = 0; // 1 is slow (good for NPCs), 2 is Lucas's default walking speed | ||
73 | std::vector<int> followers; | 74 | std::vector<int> followers; |
74 | std::deque<Movement> trail; | 75 | std::deque<Movement> trail; |
75 | CharacterState characterState = CharacterState::Still; | 76 | CharacterState characterState = CharacterState::Still; |