diff options
Diffstat (limited to 'src/systems/playing.cpp')
-rw-r--r-- | src/systems/playing.cpp | 85 |
1 files changed, 81 insertions, 4 deletions
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 | } |