diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-18 15:25:52 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-18 15:25:52 -0500 |
commit | e4e2f2d2a7b6a282b9618aa0004d9453936f43c6 (patch) | |
tree | de1653dc8b5992420147f28d9fb4de052ea1845f /src | |
parent | e16fb5be90c889c371cbb0ca2444735c2e12073c (diff) | |
download | therapy-e4e2f2d2a7b6a282b9618aa0004d9453936f43c6.tar.gz therapy-e4e2f2d2a7b6a282b9618aa0004d9453936f43c6.tar.bz2 therapy-e4e2f2d2a7b6a282b9618aa0004d9453936f43c6.zip |
Added player death and event scheduling
Also added ability to make sprites flicker, to freeze physics for an entity, and to freeze progression of a sprite's animation loop.
Diffstat (limited to 'src')
-rw-r--r-- | src/components/animatable.h | 33 | ||||
-rw-r--r-- | src/components/playable.h | 9 | ||||
-rw-r--r-- | src/components/ponderable.h | 22 | ||||
-rw-r--r-- | src/components/schedulable.h | 21 | ||||
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | src/systems/animating.cpp | 19 | ||||
-rw-r--r-- | src/systems/controlling.cpp | 29 | ||||
-rw-r--r-- | src/systems/controlling.h | 5 | ||||
-rw-r--r-- | src/systems/mapping.cpp | 21 | ||||
-rw-r--r-- | src/systems/orienting.cpp | 18 | ||||
-rw-r--r-- | src/systems/playing.cpp | 85 | ||||
-rw-r--r-- | src/systems/playing.h | 9 | ||||
-rw-r--r-- | src/systems/pondering.cpp | 16 | ||||
-rw-r--r-- | src/systems/scheduling.cpp | 54 | ||||
-rw-r--r-- | src/systems/scheduling.h | 22 |
15 files changed, 346 insertions, 19 deletions
diff --git a/src/components/animatable.h b/src/components/animatable.h index ed0133e..ec72be0 100644 --- a/src/components/animatable.h +++ b/src/components/animatable.h | |||
@@ -51,12 +51,45 @@ public: | |||
51 | animation_ = std::move(animation); | 51 | animation_ = std::move(animation); |
52 | } | 52 | } |
53 | 53 | ||
54 | inline bool isFlickering() const | ||
55 | { | ||
56 | return flickering_; | ||
57 | } | ||
58 | |||
59 | inline void setFlickering(bool v) | ||
60 | { | ||
61 | flickering_ = v; | ||
62 | } | ||
63 | |||
64 | inline size_t getFlickerTimer() const | ||
65 | { | ||
66 | return flickerTimer_; | ||
67 | } | ||
68 | |||
69 | inline void setFlickerTimer(size_t v) | ||
70 | { | ||
71 | flickerTimer_ = v; | ||
72 | } | ||
73 | |||
74 | inline bool isFrozen() const | ||
75 | { | ||
76 | return frozen_; | ||
77 | } | ||
78 | |||
79 | inline void setFrozen(bool v) | ||
80 | { | ||
81 | frozen_ = v; | ||
82 | } | ||
83 | |||
54 | private: | 84 | private: |
55 | 85 | ||
56 | AnimationSet animationSet_; | 86 | AnimationSet animationSet_; |
57 | std::string animation_; | 87 | std::string animation_; |
58 | size_t frame_ = 0; | 88 | size_t frame_ = 0; |
59 | size_t countdown_ = 0; | 89 | size_t countdown_ = 0; |
90 | bool flickering_ = false; | ||
91 | size_t flickerTimer_ = 0; | ||
92 | bool frozen_ = false; | ||
60 | }; | 93 | }; |
61 | 94 | ||
62 | #endif /* end of include guard: SPRITE_RENDERABLE_H_D3AACBBF */ | 95 | #endif /* end of include guard: SPRITE_RENDERABLE_H_D3AACBBF */ |
diff --git a/src/components/playable.h b/src/components/playable.h index a6e71b0..86a7ee7 100644 --- a/src/components/playable.h +++ b/src/components/playable.h | |||
@@ -2,14 +2,23 @@ | |||
2 | #define PLAYABLE_H_DDC566C3 | 2 | #define PLAYABLE_H_DDC566C3 |
3 | 3 | ||
4 | #include "component.h" | 4 | #include "component.h" |
5 | #include <functional> | ||
5 | 6 | ||
6 | class PlayableComponent : public Component { | 7 | class PlayableComponent : public Component { |
7 | public: | 8 | public: |
8 | 9 | ||
10 | using MapChangeCallback = std::function<void()>; | ||
11 | |||
9 | bool changingMap = false; | 12 | bool changingMap = false; |
10 | int newMapId = -1; | 13 | int newMapId = -1; |
11 | double newMapX = 0; | 14 | double newMapX = 0; |
12 | double newMapY = 0; | 15 | double newMapY = 0; |
16 | MapChangeCallback newMapCallback; | ||
17 | |||
18 | int checkpointMapId = -1; | ||
19 | double checkpointX = 0; | ||
20 | double checkpointY = 0; | ||
21 | |||
13 | }; | 22 | }; |
14 | 23 | ||
15 | #endif /* end of include guard: PLAYABLE_H_DDC566C3 */ | 24 | #endif /* end of include guard: PLAYABLE_H_DDC566C3 */ |
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index e21cbab..78af25f 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h | |||
@@ -70,6 +70,26 @@ public: | |||
70 | grounded_ = v; | 70 | grounded_ = v; |
71 | } | 71 | } |
72 | 72 | ||
73 | inline bool isFrozen() const | ||
74 | { | ||
75 | return frozen_; | ||
76 | } | ||
77 | |||
78 | inline void setFrozen(bool v) | ||
79 | { | ||
80 | frozen_ = v; | ||
81 | } | ||
82 | |||
83 | inline bool isCollidable() const | ||
84 | { | ||
85 | return collidable_; | ||
86 | } | ||
87 | |||
88 | inline void setCollidable(bool v) | ||
89 | { | ||
90 | collidable_ = v; | ||
91 | } | ||
92 | |||
73 | private: | 93 | private: |
74 | 94 | ||
75 | double velX_ = 0.0; | 95 | double velX_ = 0.0; |
@@ -78,6 +98,8 @@ private: | |||
78 | double accelY_ = 0.0; | 98 | double accelY_ = 0.0; |
79 | Type type_ = Type::vacuumed; | 99 | Type type_ = Type::vacuumed; |
80 | bool grounded_ = false; | 100 | bool grounded_ = false; |
101 | bool frozen_ = false; | ||
102 | bool collidable_ = true; | ||
81 | }; | 103 | }; |
82 | 104 | ||
83 | #endif /* end of include guard: TANGIBLE_H_746DB3EE */ | 105 | #endif /* end of include guard: TANGIBLE_H_746DB3EE */ |
diff --git a/src/components/schedulable.h b/src/components/schedulable.h new file mode 100644 index 0000000..a92bbba --- /dev/null +++ b/src/components/schedulable.h | |||
@@ -0,0 +1,21 @@ | |||
1 | #ifndef SCHEDULABLE_H_1DA3FA2A | ||
2 | #define SCHEDULABLE_H_1DA3FA2A | ||
3 | |||
4 | #include "component.h" | ||
5 | #include <tuple> | ||
6 | #include <list> | ||
7 | #include <functional> | ||
8 | #include "entity_manager.h" | ||
9 | |||
10 | class SchedulableComponent : public Component { | ||
11 | public: | ||
12 | |||
13 | using id_type = EntityManager::id_type; | ||
14 | |||
15 | using Callback = std::function<void(id_type)>; | ||
16 | using Action = std::tuple<double, Callback>; | ||
17 | |||
18 | std::list<Action> actions; | ||
19 | }; | ||
20 | |||
21 | #endif /* end of include guard: SCHEDULABLE_H_1DA3FA2A */ | ||
diff --git a/src/game.cpp b/src/game.cpp index f245e7c..3da23a3 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "systems/mapping.h" | 10 | #include "systems/mapping.h" |
11 | #include "systems/orienting.h" | 11 | #include "systems/orienting.h" |
12 | #include "systems/playing.h" | 12 | #include "systems/playing.h" |
13 | #include "systems/scheduling.h" | ||
13 | #include "animation.h" | 14 | #include "animation.h" |
14 | #include "consts.h" | 15 | #include "consts.h" |
15 | 16 | ||
@@ -30,6 +31,7 @@ void key_callback(GLFWwindow* window, int key, int, int action, int) | |||
30 | Game::Game() : world_("res/maps.xml") | 31 | Game::Game() : world_("res/maps.xml") |
31 | { | 32 | { |
32 | systemManager_.emplaceSystem<PlayingSystem>(*this); | 33 | systemManager_.emplaceSystem<PlayingSystem>(*this); |
34 | systemManager_.emplaceSystem<SchedulingSystem>(*this); | ||
33 | systemManager_.emplaceSystem<ControllingSystem>(*this); | 35 | systemManager_.emplaceSystem<ControllingSystem>(*this); |
34 | systemManager_.emplaceSystem<OrientingSystem>(*this); | 36 | systemManager_.emplaceSystem<OrientingSystem>(*this); |
35 | systemManager_.emplaceSystem<PonderingSystem>(*this); | 37 | systemManager_.emplaceSystem<PonderingSystem>(*this); |
diff --git a/src/systems/animating.cpp b/src/systems/animating.cpp index 22224c9..634af67 100644 --- a/src/systems/animating.cpp +++ b/src/systems/animating.cpp | |||
@@ -13,7 +13,10 @@ void AnimatingSystem::tick(double) | |||
13 | auto& sprite = game_.getEntityManager(). | 13 | auto& sprite = game_.getEntityManager(). |
14 | getComponent<AnimatableComponent>(entity); | 14 | getComponent<AnimatableComponent>(entity); |
15 | 15 | ||
16 | sprite.setCountdown(sprite.getCountdown() + 1); | 16 | if (!sprite.isFrozen()) |
17 | { | ||
18 | sprite.setCountdown(sprite.getCountdown() + 1); | ||
19 | } | ||
17 | 20 | ||
18 | const Animation& anim = sprite.getAnimation(); | 21 | const Animation& anim = sprite.getAnimation(); |
19 | if (sprite.getCountdown() >= anim.getDelay()) | 22 | if (sprite.getCountdown() >= anim.getDelay()) |
@@ -26,6 +29,11 @@ void AnimatingSystem::tick(double) | |||
26 | sprite.setFrame(anim.getFirstFrame()); | 29 | sprite.setFrame(anim.getFirstFrame()); |
27 | } | 30 | } |
28 | } | 31 | } |
32 | |||
33 | if (sprite.isFlickering()) | ||
34 | { | ||
35 | sprite.setFlickerTimer((sprite.getFlickerTimer() + 1) % 6); | ||
36 | } | ||
29 | } | 37 | } |
30 | } | 38 | } |
31 | 39 | ||
@@ -44,6 +52,12 @@ void AnimatingSystem::render(Texture& texture) | |||
44 | auto& transform = game_.getEntityManager(). | 52 | auto& transform = game_.getEntityManager(). |
45 | getComponent<TransformableComponent>(entity); | 53 | getComponent<TransformableComponent>(entity); |
46 | 54 | ||
55 | double alpha = 1.0; | ||
56 | if (sprite.isFlickering() && (sprite.getFlickerTimer() < 3)) | ||
57 | { | ||
58 | alpha = 0.0; | ||
59 | } | ||
60 | |||
47 | Rectangle dstrect { | 61 | Rectangle dstrect { |
48 | static_cast<int>(transform.getX()), | 62 | static_cast<int>(transform.getX()), |
49 | static_cast<int>(transform.getY()), | 63 | static_cast<int>(transform.getY()), |
@@ -55,7 +69,8 @@ void AnimatingSystem::render(Texture& texture) | |||
55 | aset.getTexture(), | 69 | aset.getTexture(), |
56 | texture, | 70 | texture, |
57 | aset.getFrameRect(sprite.getFrame()), | 71 | aset.getFrameRect(sprite.getFrame()), |
58 | dstrect); | 72 | dstrect, |
73 | alpha); | ||
59 | } | 74 | } |
60 | } | 75 | } |
61 | 76 | ||
diff --git a/src/systems/controlling.cpp b/src/systems/controlling.cpp index e1609bd..e65c09a 100644 --- a/src/systems/controlling.cpp +++ b/src/systems/controlling.cpp | |||
@@ -105,3 +105,32 @@ void ControllingSystem::input(int key, int action) | |||
105 | { | 105 | { |
106 | actions_.push(std::make_pair(key, action)); | 106 | actions_.push(std::make_pair(key, action)); |
107 | } | 107 | } |
108 | |||
109 | void ControllingSystem::freeze(id_type entity) | ||
110 | { | ||
111 | auto& controllable = game_.getEntityManager(). | ||
112 | getComponent<ControllableComponent>(entity); | ||
113 | |||
114 | controllable.setFrozen(true); | ||
115 | } | ||
116 | |||
117 | void ControllingSystem::unfreeze(id_type entity) | ||
118 | { | ||
119 | auto& controllable = game_.getEntityManager(). | ||
120 | getComponent<ControllableComponent>(entity); | ||
121 | |||
122 | if (controllable.isFrozen()) | ||
123 | { | ||
124 | controllable.setFrozen(false); | ||
125 | |||
126 | auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>(); | ||
127 | |||
128 | if (controllable.isHoldingLeft()) | ||
129 | { | ||
130 | orienting.moveLeft(entity); | ||
131 | } else if (controllable.isHoldingRight()) | ||
132 | { | ||
133 | orienting.moveRight(entity); | ||
134 | } | ||
135 | } | ||
136 | } | ||
diff --git a/src/systems/controlling.h b/src/systems/controlling.h index 01ed7a0..d6f0789 100644 --- a/src/systems/controlling.h +++ b/src/systems/controlling.h | |||
@@ -12,8 +12,13 @@ public: | |||
12 | } | 12 | } |
13 | 13 | ||
14 | void tick(double dt); | 14 | void tick(double dt); |
15 | |||
15 | void input(int key, int action); | 16 | void input(int key, int action); |
16 | 17 | ||
18 | void freeze(id_type entity); | ||
19 | |||
20 | void unfreeze(id_type entity); | ||
21 | |||
17 | private: | 22 | private: |
18 | 23 | ||
19 | std::queue<std::pair<int,int>> actions_; | 24 | std::queue<std::pair<int,int>> actions_; |
diff --git a/src/systems/mapping.cpp b/src/systems/mapping.cpp index 05167c1..a3a17ec 100644 --- a/src/systems/mapping.cpp +++ b/src/systems/mapping.cpp | |||
@@ -167,11 +167,32 @@ void MappingSystem::loadMap(size_t mapId) | |||
167 | } else if (tile == 42) | 167 | } else if (tile == 42) |
168 | { | 168 | { |
169 | addBoundary( | 169 | addBoundary( |
170 | mappable.getRightBoundaries(), | ||
171 | x * TILE_WIDTH, | ||
172 | y * TILE_HEIGHT, | ||
173 | (y+1) * TILE_HEIGHT, | ||
174 | MappableComponent::Boundary::Type::danger); | ||
175 | |||
176 | addBoundary( | ||
177 | mappable.getLeftBoundaries(), | ||
178 | (x+1) * TILE_WIDTH, | ||
179 | y * TILE_HEIGHT, | ||
180 | (y+1) * TILE_HEIGHT, | ||
181 | MappableComponent::Boundary::Type::danger); | ||
182 | |||
183 | addBoundary( | ||
170 | mappable.getDownBoundaries(), | 184 | mappable.getDownBoundaries(), |
171 | y * TILE_HEIGHT, | 185 | y * TILE_HEIGHT, |
172 | x * TILE_WIDTH, | 186 | x * TILE_WIDTH, |
173 | (x+1) * TILE_WIDTH, | 187 | (x+1) * TILE_WIDTH, |
174 | MappableComponent::Boundary::Type::danger); | 188 | MappableComponent::Boundary::Type::danger); |
189 | |||
190 | addBoundary( | ||
191 | mappable.getUpBoundaries(), | ||
192 | (y+1) * TILE_HEIGHT, | ||
193 | x * TILE_WIDTH, | ||
194 | (x+1) * TILE_WIDTH, | ||
195 | MappableComponent::Boundary::Type::danger); | ||
175 | } | 196 | } |
176 | } | 197 | } |
177 | } | 198 | } |
diff --git a/src/systems/orienting.cpp b/src/systems/orienting.cpp index 187bebc..2df8f87 100644 --- a/src/systems/orienting.cpp +++ b/src/systems/orienting.cpp | |||
@@ -93,24 +93,18 @@ void OrientingSystem::moveRight(id_type entity) | |||
93 | 93 | ||
94 | void OrientingSystem::stopWalking(id_type entity) | 94 | void OrientingSystem::stopWalking(id_type entity) |
95 | { | 95 | { |
96 | auto& ponderable = game_.getEntityManager(). | ||
97 | getComponent<PonderableComponent>(entity); | ||
98 | |||
99 | auto& orientable = game_.getEntityManager(). | 96 | auto& orientable = game_.getEntityManager(). |
100 | getComponent<OrientableComponent>(entity); | 97 | getComponent<OrientableComponent>(entity); |
101 | 98 | ||
102 | orientable.setWalkState(OrientableComponent::WalkState::still); | 99 | orientable.setWalkState(OrientableComponent::WalkState::still); |
103 | 100 | ||
104 | if (ponderable.isGrounded()) | 101 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); |
105 | { | ||
106 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
107 | 102 | ||
108 | if (orientable.isFacingRight()) | 103 | if (orientable.isFacingRight()) |
109 | { | 104 | { |
110 | animating.startAnimation(entity, "stillRight"); | 105 | animating.startAnimation(entity, "stillRight"); |
111 | } else { | 106 | } else { |
112 | animating.startAnimation(entity, "stillLeft"); | 107 | animating.startAnimation(entity, "stillLeft"); |
113 | } | ||
114 | } | 108 | } |
115 | } | 109 | } |
116 | 110 | ||
diff --git a/src/systems/playing.cpp b/src/systems/playing.cpp index 2c6a419..40d9706 100644 --- a/src/systems/playing.cpp +++ b/src/systems/playing.cpp | |||
@@ -7,13 +7,18 @@ | |||
7 | #include "components/orientable.h" | 7 | #include "components/orientable.h" |
8 | #include "systems/mapping.h" | 8 | #include "systems/mapping.h" |
9 | #include "systems/pondering.h" | 9 | #include "systems/pondering.h" |
10 | #include "systems/orienting.h" | ||
11 | #include "systems/scheduling.h" | ||
12 | #include "systems/controlling.h" | ||
10 | #include "animation.h" | 13 | #include "animation.h" |
14 | #include "muxer.h" | ||
11 | 15 | ||
12 | void PlayingSystem::tick(double) | 16 | void PlayingSystem::tick(double) |
13 | { | 17 | { |
14 | // Check if we need to change the map | 18 | // Check if we need to change the map |
15 | auto players = game_.getEntityManager().getEntitiesWithComponents< | 19 | auto players = game_.getEntityManager().getEntitiesWithComponents< |
16 | PlayableComponent>(); | 20 | PlayableComponent, |
21 | TransformableComponent>(); | ||
17 | 22 | ||
18 | for (id_type player : players) | 23 | for (id_type player : players) |
19 | { | 24 | { |
@@ -44,6 +49,12 @@ void PlayingSystem::tick(double) | |||
44 | 49 | ||
45 | playable.changingMap = false; | 50 | playable.changingMap = false; |
46 | 51 | ||
52 | if (playable.newMapCallback) | ||
53 | { | ||
54 | playable.newMapCallback(); | ||
55 | playable.newMapCallback = nullptr; | ||
56 | } | ||
57 | |||
47 | break; | 58 | break; |
48 | } | 59 | } |
49 | } | 60 | } |
@@ -66,7 +77,10 @@ void PlayingSystem::initPlayer() | |||
66 | 77 | ||
67 | game_.getEntityManager().emplaceComponent<TransformableComponent>( | 78 | game_.getEntityManager().emplaceComponent<TransformableComponent>( |
68 | player, | 79 | player, |
69 | 203, 44, 10, 12); | 80 | game_.getWorld().getStartingX(), |
81 | game_.getWorld().getStartingY(), | ||
82 | 10, | ||
83 | 12); | ||
70 | 84 | ||
71 | game_.getSystemManager().getSystem<PonderingSystem>().initializeBody( | 85 | game_.getSystemManager().getSystem<PonderingSystem>().initializeBody( |
72 | player, | 86 | player, |
@@ -74,13 +88,20 @@ void PlayingSystem::initPlayer() | |||
74 | 88 | ||
75 | game_.getEntityManager().emplaceComponent<ControllableComponent>(player); | 89 | game_.getEntityManager().emplaceComponent<ControllableComponent>(player); |
76 | game_.getEntityManager().emplaceComponent<OrientableComponent>(player); | 90 | game_.getEntityManager().emplaceComponent<OrientableComponent>(player); |
77 | game_.getEntityManager().emplaceComponent<PlayableComponent>(player); | 91 | |
92 | auto& playable = game_.getEntityManager(). | ||
93 | emplaceComponent<PlayableComponent>(player); | ||
94 | |||
95 | playable.checkpointMapId = game_.getWorld().getStartingMapId(); | ||
96 | playable.checkpointX = game_.getWorld().getStartingX(); | ||
97 | playable.checkpointY = game_.getWorld().getStartingY(); | ||
78 | } | 98 | } |
79 | 99 | ||
80 | void PlayingSystem::changeMap( | 100 | void PlayingSystem::changeMap( |
81 | size_t mapId, | 101 | size_t mapId, |
82 | double x, | 102 | double x, |
83 | double y) | 103 | double y, |
104 | PlayableComponent::MapChangeCallback callback) | ||
84 | { | 105 | { |
85 | auto players = game_.getEntityManager().getEntitiesWithComponents< | 106 | auto players = game_.getEntityManager().getEntitiesWithComponents< |
86 | PlayableComponent>(); | 107 | PlayableComponent>(); |
@@ -94,5 +115,61 @@ void PlayingSystem::changeMap( | |||
94 | playable.newMapId = mapId; | 115 | playable.newMapId = mapId; |
95 | playable.newMapX = x; | 116 | playable.newMapX = x; |
96 | playable.newMapY = y; | 117 | playable.newMapY = y; |
118 | playable.newMapCallback = std::move(callback); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | void PlayingSystem::die() | ||
123 | { | ||
124 | playSound("res/Hit_Hurt5.wav", 0.25); | ||
125 | |||
126 | auto players = game_.getEntityManager().getEntitiesWithComponents< | ||
127 | OrientableComponent, | ||
128 | ControllableComponent, | ||
129 | AnimatableComponent, | ||
130 | PonderableComponent, | ||
131 | PlayableComponent>(); | ||
132 | |||
133 | for (id_type player : players) | ||
134 | { | ||
135 | auto& animatable = game_.getEntityManager(). | ||
136 | getComponent<AnimatableComponent>(player); | ||
137 | |||
138 | auto& ponderable = game_.getEntityManager(). | ||
139 | getComponent<PonderableComponent>(player); | ||
140 | |||
141 | auto& controlling = game_.getSystemManager().getSystem<ControllingSystem>(); | ||
142 | controlling.freeze(player); | ||
143 | |||
144 | animatable.setFrozen(true); | ||
145 | animatable.setFlickering(true); | ||
146 | ponderable.setFrozen(true); | ||
147 | ponderable.setCollidable(false); | ||
148 | |||
149 | auto& scheduling = game_.getSystemManager().getSystem<SchedulingSystem>(); | ||
150 | |||
151 | scheduling.schedule(player, 0.75, [&] (id_type player) { | ||
152 | auto& playable = game_.getEntityManager(). | ||
153 | getComponent<PlayableComponent>(player); | ||
154 | |||
155 | changeMap( | ||
156 | playable.checkpointMapId, | ||
157 | playable.checkpointX, | ||
158 | playable.checkpointY, | ||
159 | [&, player] () { | ||
160 | animatable.setFrozen(false); | ||
161 | animatable.setFlickering(false); | ||
162 | ponderable.setFrozen(false); | ||
163 | ponderable.setCollidable(true); | ||
164 | |||
165 | // Reset the walk state, and then potentially let the | ||
166 | // ControllingSystem set it again. | ||
167 | auto& orienting = game_.getSystemManager(). | ||
168 | getSystem<OrientingSystem>(); | ||
169 | orienting.stopWalking(player); | ||
170 | |||
171 | controlling.unfreeze(player); | ||
172 | }); | ||
173 | }); | ||
97 | } | 174 | } |
98 | } | 175 | } |
diff --git a/src/systems/playing.h b/src/systems/playing.h index c98a464..ff16808 100644 --- a/src/systems/playing.h +++ b/src/systems/playing.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define PLAYING_H_70A54F7D | 2 | #define PLAYING_H_70A54F7D |
3 | 3 | ||
4 | #include "system.h" | 4 | #include "system.h" |
5 | #include "components/playable.h" | ||
5 | 6 | ||
6 | class PlayingSystem : public System { | 7 | class PlayingSystem : public System { |
7 | public: | 8 | public: |
@@ -14,7 +15,13 @@ public: | |||
14 | 15 | ||
15 | void initPlayer(); | 16 | void initPlayer(); |
16 | 17 | ||
17 | void changeMap(size_t mapId, double x, double y); | 18 | void changeMap( |
19 | size_t mapId, | ||
20 | double x, | ||
21 | double y, | ||
22 | PlayableComponent::MapChangeCallback callback = nullptr); | ||
23 | |||
24 | void die(); | ||
18 | 25 | ||
19 | }; | 26 | }; |
20 | 27 | ||
diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 2490dc9..d3601ac 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp | |||
@@ -27,6 +27,11 @@ void PonderingSystem::tick(double dt) | |||
27 | auto& ponderable = game_.getEntityManager(). | 27 | auto& ponderable = game_.getEntityManager(). |
28 | getComponent<PonderableComponent>(entity); | 28 | getComponent<PonderableComponent>(entity); |
29 | 29 | ||
30 | if (ponderable.isFrozen()) | ||
31 | { | ||
32 | continue; | ||
33 | } | ||
34 | |||
30 | // Accelerate | 35 | // Accelerate |
31 | ponderable.setVelocityX( | 36 | ponderable.setVelocityX( |
32 | ponderable.getVelocityX() + ponderable.getAccelX() * dt); | 37 | ponderable.getVelocityX() + ponderable.getAccelX() * dt); |
@@ -289,6 +294,17 @@ void PonderingSystem::tick(double dt) | |||
289 | break; | 294 | break; |
290 | } | 295 | } |
291 | } | 296 | } |
297 | |||
298 | break; | ||
299 | } | ||
300 | |||
301 | case Collision::Type::danger: | ||
302 | { | ||
303 | game_.getSystemManager().getSystem<PlayingSystem>().die(); | ||
304 | |||
305 | stopProcessing = true; | ||
306 | |||
307 | break; | ||
292 | } | 308 | } |
293 | 309 | ||
294 | default: | 310 | default: |
diff --git a/src/systems/scheduling.cpp b/src/systems/scheduling.cpp new file mode 100644 index 0000000..220efae --- /dev/null +++ b/src/systems/scheduling.cpp | |||
@@ -0,0 +1,54 @@ | |||
1 | #include "scheduling.h" | ||
2 | #include "game.h" | ||
3 | #include "components/schedulable.h" | ||
4 | #include "util.h" | ||
5 | |||
6 | void SchedulingSystem::tick(double dt) | ||
7 | { | ||
8 | auto entities = game_.getEntityManager().getEntitiesWithComponents< | ||
9 | SchedulableComponent>(); | ||
10 | |||
11 | for (id_type entity : entities) | ||
12 | { | ||
13 | auto& schedulable = game_.getEntityManager(). | ||
14 | getComponent<SchedulableComponent>(entity); | ||
15 | |||
16 | for (auto& action : schedulable.actions) | ||
17 | { | ||
18 | std::get<0>(action) -= dt; | ||
19 | |||
20 | if (std::get<0>(action) < 0) | ||
21 | { | ||
22 | std::get<1>(action)(entity); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | erase_if(schedulable.actions, | ||
27 | [] (const SchedulableComponent::Action& action) { | ||
28 | return (std::get<0>(action) < 0); | ||
29 | }); | ||
30 | |||
31 | if (schedulable.actions.empty()) | ||
32 | { | ||
33 | game_.getEntityManager().removeComponent<SchedulableComponent>(entity); | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | void SchedulingSystem::schedule( | ||
39 | id_type entity, | ||
40 | double length, | ||
41 | std::function<void(id_type)> action) | ||
42 | { | ||
43 | if (!game_.getEntityManager().hasComponent<SchedulableComponent>(entity)) | ||
44 | { | ||
45 | game_.getEntityManager().emplaceComponent<SchedulableComponent>(entity); | ||
46 | } | ||
47 | |||
48 | auto& schedulable = game_.getEntityManager(). | ||
49 | getComponent<SchedulableComponent>(entity); | ||
50 | |||
51 | schedulable.actions.emplace_back( | ||
52 | length, | ||
53 | std::move(action)); | ||
54 | } | ||
diff --git a/src/systems/scheduling.h b/src/systems/scheduling.h new file mode 100644 index 0000000..7950d62 --- /dev/null +++ b/src/systems/scheduling.h | |||
@@ -0,0 +1,22 @@ | |||
1 | #ifndef SCHEDULING_H_7B02E3E3 | ||
2 | #define SCHEDULING_H_7B02E3E3 | ||
3 | |||
4 | #include "system.h" | ||
5 | |||
6 | class SchedulingSystem : public System { | ||
7 | public: | ||
8 | |||
9 | SchedulingSystem(Game& game) : System(game) | ||
10 | { | ||
11 | } | ||
12 | |||
13 | void tick(double dt); | ||
14 | |||
15 | void schedule( | ||
16 | id_type entity, | ||
17 | double length, | ||
18 | std::function<void(id_type)> action); | ||
19 | |||
20 | }; | ||
21 | |||
22 | #endif /* end of include guard: SCHEDULING_H_7B02E3E3 */ | ||