summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/direction.h13
-rw-r--r--src/input_system.cpp46
-rw-r--r--src/main.cpp1
-rw-r--r--src/sprite.h3
4 files changed, 49 insertions, 14 deletions
diff --git a/src/direction.h b/src/direction.h index a83a6f8..e11b1f3 100644 --- a/src/direction.h +++ b/src/direction.h
@@ -51,4 +51,17 @@ inline bool dirHasDir(Direction value, Direction inner) {
51 } 51 }
52} 52}
53 53
54inline Direction oppositeDirection(Direction value) {
55 switch (value) {
56 case Direction::up: return Direction::down;
57 case Direction::up_right: return Direction::down_left;
58 case Direction::right: return Direction::left;
59 case Direction::down_right: return Direction::up_left;
60 case Direction::down: return Direction::up;
61 case Direction::down_left: return Direction::up_right;
62 case Direction::left: return Direction::right;
63 case Direction::up_left: return Direction::down_right;
64 }
65}
66
54#endif /* end of include guard: DIRECTION_H_AB66A90E */ 67#endif /* end of include guard: DIRECTION_H_AB66A90E */
diff --git a/src/input_system.cpp b/src/input_system.cpp index 6ddb59e..5133e27 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -3,6 +3,8 @@
3#include "character_system.h" 3#include "character_system.h"
4#include "message_system.h" 4#include "message_system.h"
5#include "script_system.h" 5#include "script_system.h"
6#include "transform_system.h"
7#include "animation_system.h"
6 8
7struct Input { 9struct Input {
8 bool left = false; 10 bool left = false;
@@ -26,20 +28,38 @@ void InputSystem::tick(double dt) {
26 game_.getSystem<CharacterSystem>().beginCrouch(spriteId); 28 game_.getSystem<CharacterSystem>().beginCrouch(spriteId);
27 } 29 }
28 } 30 }
29 } else if (e.key.keysym.sym == SDLK_a) { 31 } else if (e.key.keysym.sym == SDLK_SPACE) {
30 // TODO: Remove this, it's just for testing. 32 // If there is text on screen, try to advance it.
31 /*if (game_.getSystem<MessageSystem>().getCutsceneBarsProgress() == 1.0) { 33 if (game_.getSystem<MessageSystem>().getCutsceneBarsProgress() != 0.0) {
32 game_.getSystem<MessageSystem>().hideCutsceneBars(); 34 game_.getSystem<MessageSystem>().advanceText();
33 } else { 35 } else {
34 game_.getSystem<MessageSystem>().displayCutsceneBars(); 36 // Otherwise, check if there is a sprite in front of the player.
35 }*/ 37 for (int spriteId : game_.getSprites()) {
36 //game_.getSystem<MessageSystem>().displayMessage("Some people always try to avoid fighting when there are enemies around. You know the type, right? They use the dash ability to zoom right by. I guess you could say they're followers of \"peace at any price\".", "Sparrow", SpeakerType::Woman); 38 Sprite& sprite = game_.getSprite(spriteId);
37 //game_.getSystem<MessageSystem>().displayMessage("Lucas. You're awful at hide-and-seek, you know that? Try harder.", "Kumatora", SpeakerType::Woman); 39 if (sprite.controllable) {
38 //game_.getSystem<MessageSystem>().displayMessage("Hi Tooth! I hope you're having a good day.", "Lucas", SpeakerType::Boy); 40 vec2i checkLoc = sprite.loc + (unitVecInDirection(sprite.dir) * MOVEMENT_SPEED);
39 game_.getSystem<ScriptSystem>().runScript("script0001"); 41 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, checkLoc, sprite.dir);
40 } else if (e.key.keysym.sym == SDLK_b) { 42
41 // TODO: Remove this, it's just for testing. 43 // If there is a sprite to be interacted with, rotate that sprite so it is facing the player.
42 game_.getSystem<MessageSystem>().advanceText(); 44 // Then, run its interaction script if present.
45 if (collision.horiz.colliderSprite != -1) {
46 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.horiz.colliderSprite, oppositeDirection(sprite.dir));
47
48 Sprite& collider = game_.getSprite(collision.horiz.colliderSprite);
49 if (collider.interactionScript != "") {
50 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript);
51 }
52 } else if (collision.vert.colliderSprite != -1) {
53 game_.getSystem<AnimationSystem>().setSpriteDirection(collision.vert.colliderSprite, oppositeDirection(sprite.dir));
54
55 Sprite& collider = game_.getSprite(collision.vert.colliderSprite);
56 if (collider.interactionScript != "") {
57 game_.getSystem<ScriptSystem>().runScript(collider.interactionScript);
58 }
59 }
60 }
61 }
62 }
43 } 63 }
44 } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) { 64 } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) {
45 for (int spriteId : game_.getSprites()) { 65 for (int spriteId : game_.getSprites()) {
diff --git a/src/main.cpp b/src/main.cpp index 8363995..3ea92ae 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -51,6 +51,7 @@ void loop(Renderer& renderer) {
51 game.getSystem<TransformSystem>().initSprite(flintSprite, {35*16, 19*16}); 51 game.getSystem<TransformSystem>().initSprite(flintSprite, {35*16, 19*16});
52 game.getSystem<TransformSystem>().setUpCollision(flintSprite, {-8, -8}, {12, 8}); 52 game.getSystem<TransformSystem>().setUpCollision(flintSprite, {-8, -8}, {12, 8});
53 game.getSystem<AnimationSystem>().initSprite(flintSprite, "../res/sprites/flint_anim.txt", renderer); 53 game.getSystem<AnimationSystem>().initSprite(flintSprite, "../res/sprites/flint_anim.txt", renderer);
54 game.getSprite(flintSprite).interactionScript = "script0001";
54 55
55 game.getSystem<CameraSystem>().setFollowingSprite(lucasSprite); 56 game.getSystem<CameraSystem>().setFollowingSprite(lucasSprite);
56 game.getSystem<CameraSystem>().unlockCamera(); 57 game.getSystem<CameraSystem>().unlockCamera();
diff --git a/src/sprite.h b/src/sprite.h index e9c6fd0..b2cca87 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -36,12 +36,13 @@ public:
36 bool collidable = false; 36 bool collidable = false;
37 vec2i collisionOffset; 37 vec2i collisionOffset;
38 vec2i collisionSize; 38 vec2i collisionSize;
39 std::string interactionScript;
39 40
40 // Animation 41 // Animation
41 bool isAnimated = false; 42 bool isAnimated = false;
42 int textureId; 43 int textureId;
43 Direction dir = Direction::down; 44 Direction dir = Direction::down;
44 std::string animationName; 45 std::string animationName = "still";
45 int animationId = 0; 46 int animationId = 0;
46 int animationFrame = 0; 47 int animationFrame = 0;
47 std::vector<SpriteFrame> frames; 48 std::vector<SpriteFrame> frames;