diff options
Diffstat (limited to 'src/systems/playing.cpp')
-rw-r--r-- | src/systems/playing.cpp | 220 |
1 files changed, 102 insertions, 118 deletions
diff --git a/src/systems/playing.cpp b/src/systems/playing.cpp index 40d9706..b04f0cb 100644 --- a/src/systems/playing.cpp +++ b/src/systems/playing.cpp | |||
@@ -5,61 +5,17 @@ | |||
5 | #include "components/playable.h" | 5 | #include "components/playable.h" |
6 | #include "components/controllable.h" | 6 | #include "components/controllable.h" |
7 | #include "components/orientable.h" | 7 | #include "components/orientable.h" |
8 | #include "components/realizable.h" | ||
8 | #include "systems/mapping.h" | 9 | #include "systems/mapping.h" |
9 | #include "systems/pondering.h" | 10 | #include "systems/pondering.h" |
10 | #include "systems/orienting.h" | 11 | #include "systems/orienting.h" |
11 | #include "systems/scheduling.h" | 12 | #include "systems/scheduling.h" |
12 | #include "systems/controlling.h" | 13 | #include "systems/controlling.h" |
14 | #include "systems/animating.h" | ||
15 | #include "systems/realizing.h" | ||
13 | #include "animation.h" | 16 | #include "animation.h" |
14 | #include "muxer.h" | 17 | #include "muxer.h" |
15 | 18 | ||
16 | void PlayingSystem::tick(double) | ||
17 | { | ||
18 | // Check if we need to change the map | ||
19 | auto players = game_.getEntityManager().getEntitiesWithComponents< | ||
20 | PlayableComponent, | ||
21 | TransformableComponent>(); | ||
22 | |||
23 | for (id_type player : players) | ||
24 | { | ||
25 | auto& playable = game_.getEntityManager(). | ||
26 | getComponent<PlayableComponent>(player); | ||
27 | |||
28 | if (playable.changingMap) | ||
29 | { | ||
30 | // Change the map! | ||
31 | auto entities = game_.getEntityManager().getEntities(); | ||
32 | |||
33 | for (id_type entity : entities) | ||
34 | { | ||
35 | if (entity != player) | ||
36 | { | ||
37 | game_.getEntityManager().deleteEntity(entity); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | game_.getSystemManager().getSystem<MappingSystem>(). | ||
42 | loadMap(playable.newMapId); | ||
43 | |||
44 | auto& transformable = game_.getEntityManager(). | ||
45 | getComponent<TransformableComponent>(player); | ||
46 | |||
47 | transformable.setX(playable.newMapX); | ||
48 | transformable.setY(playable.newMapY); | ||
49 | |||
50 | playable.changingMap = false; | ||
51 | |||
52 | if (playable.newMapCallback) | ||
53 | { | ||
54 | playable.newMapCallback(); | ||
55 | playable.newMapCallback = nullptr; | ||
56 | } | ||
57 | |||
58 | break; | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void PlayingSystem::initPlayer() | 19 | void PlayingSystem::initPlayer() |
64 | { | 20 | { |
65 | id_type player = game_.getEntityManager().emplaceEntity(); | 21 | id_type player = game_.getEntityManager().emplaceEntity(); |
@@ -72,15 +28,24 @@ void PlayingSystem::initPlayer() | |||
72 | 28 | ||
73 | game_.getEntityManager().emplaceComponent<AnimatableComponent>( | 29 | game_.getEntityManager().emplaceComponent<AnimatableComponent>( |
74 | player, | 30 | player, |
75 | std::move(playerGraphics), | 31 | std::move(playerGraphics)); |
76 | "stillLeft"); | ||
77 | 32 | ||
78 | game_.getEntityManager().emplaceComponent<TransformableComponent>( | 33 | game_.getSystemManager().getSystem<AnimatingSystem>().startAnimation( |
79 | player, | 34 | player, |
80 | game_.getWorld().getStartingX(), | 35 | "stillLeft"); |
81 | game_.getWorld().getStartingY(), | 36 | |
82 | 10, | 37 | auto& realizing = game_.getSystemManager().getSystem<RealizingSystem>(); |
83 | 12); | 38 | |
39 | auto& realizable = game_.getEntityManager(). | ||
40 | getComponent<RealizableComponent>(realizing.getSingleton()); | ||
41 | |||
42 | auto& transformable = game_.getEntityManager(). | ||
43 | emplaceComponent<TransformableComponent>(player); | ||
44 | |||
45 | transformable.x = realizable.startingX; | ||
46 | transformable.y = realizable.startingY; | ||
47 | transformable.w = 10; | ||
48 | transformable.h = 12; | ||
84 | 49 | ||
85 | game_.getSystemManager().getSystem<PonderingSystem>().initializeBody( | 50 | game_.getSystemManager().getSystem<PonderingSystem>().initializeBody( |
86 | player, | 51 | player, |
@@ -92,84 +57,103 @@ void PlayingSystem::initPlayer() | |||
92 | auto& playable = game_.getEntityManager(). | 57 | auto& playable = game_.getEntityManager(). |
93 | emplaceComponent<PlayableComponent>(player); | 58 | emplaceComponent<PlayableComponent>(player); |
94 | 59 | ||
95 | playable.checkpointMapId = game_.getWorld().getStartingMapId(); | 60 | playable.mapId = realizable.activeMap; |
96 | playable.checkpointX = game_.getWorld().getStartingX(); | 61 | playable.checkpointMapId = realizable.startingMapId; |
97 | playable.checkpointY = game_.getWorld().getStartingY(); | 62 | playable.checkpointX = realizable.startingX; |
63 | playable.checkpointY = realizable.startingY; | ||
64 | |||
65 | realizing.enterActiveMap(player); | ||
66 | |||
67 | realizable.activePlayer = player; | ||
98 | } | 68 | } |
99 | 69 | ||
100 | void PlayingSystem::changeMap( | 70 | void PlayingSystem::changeMap( |
71 | id_type player, | ||
101 | size_t mapId, | 72 | size_t mapId, |
102 | double x, | 73 | double x, |
103 | double y, | 74 | double y) |
104 | PlayableComponent::MapChangeCallback callback) | ||
105 | { | 75 | { |
106 | auto players = game_.getEntityManager().getEntitiesWithComponents< | 76 | auto& playable = game_.getEntityManager(). |
107 | PlayableComponent>(); | 77 | getComponent<PlayableComponent>(player); |
108 | 78 | ||
109 | for (id_type player : players) | 79 | auto& transformable = game_.getEntityManager(). |
80 | getComponent<TransformableComponent>(player); | ||
81 | |||
82 | auto& animatable = game_.getEntityManager(). | ||
83 | getComponent<AnimatableComponent>(player); | ||
84 | |||
85 | auto& ponderable = game_.getEntityManager(). | ||
86 | getComponent<PonderableComponent>(player); | ||
87 | |||
88 | auto& realizing = game_.getSystemManager().getSystem<RealizingSystem>(); | ||
89 | |||
90 | auto& realizable = game_.getEntityManager(). | ||
91 | getComponent<RealizableComponent>(realizing.getSingleton()); | ||
92 | |||
93 | id_type newMapEntity = realizable.entityByMapId[mapId]; | ||
94 | |||
95 | if (playable.mapId != newMapEntity) | ||
110 | { | 96 | { |
111 | auto& playable = game_.getEntityManager(). | 97 | if (playable.mapId == realizable.activeMap) |
112 | getComponent<PlayableComponent>(player); | 98 | { |
99 | realizing.leaveActiveMap(player); | ||
100 | } else if (newMapEntity == realizable.activeMap) | ||
101 | { | ||
102 | realizing.enterActiveMap(player); | ||
103 | } | ||
113 | 104 | ||
114 | playable.changingMap = true; | 105 | playable.mapId = newMapEntity; |
115 | playable.newMapId = mapId; | 106 | } |
116 | playable.newMapX = x; | 107 | |
117 | playable.newMapY = y; | 108 | transformable.x = x; |
118 | playable.newMapCallback = std::move(callback); | 109 | transformable.y = y; |
110 | |||
111 | if (realizable.activePlayer == player) | ||
112 | { | ||
113 | realizing.loadMap(newMapEntity); | ||
119 | } | 114 | } |
120 | } | 115 | } |
121 | 116 | ||
122 | void PlayingSystem::die() | 117 | void PlayingSystem::die(id_type player) |
123 | { | 118 | { |
124 | playSound("res/Hit_Hurt5.wav", 0.25); | 119 | playSound("res/Hit_Hurt5.wav", 0.25); |
125 | 120 | ||
126 | auto players = game_.getEntityManager().getEntitiesWithComponents< | 121 | auto& animatable = game_.getEntityManager(). |
127 | OrientableComponent, | 122 | getComponent<AnimatableComponent>(player); |
128 | ControllableComponent, | ||
129 | AnimatableComponent, | ||
130 | PonderableComponent, | ||
131 | PlayableComponent>(); | ||
132 | 123 | ||
133 | for (id_type player : players) | 124 | auto& ponderable = game_.getEntityManager(). |
134 | { | 125 | getComponent<PonderableComponent>(player); |
135 | auto& animatable = game_.getEntityManager(). | 126 | |
136 | getComponent<AnimatableComponent>(player); | 127 | auto& controlling = game_.getSystemManager().getSystem<ControllingSystem>(); |
137 | 128 | controlling.freeze(player); | |
138 | auto& ponderable = game_.getEntityManager(). | 129 | |
139 | getComponent<PonderableComponent>(player); | 130 | animatable.frozen = true; |
140 | 131 | animatable.flickering = true; | |
141 | auto& controlling = game_.getSystemManager().getSystem<ControllingSystem>(); | 132 | ponderable.frozen = true; |
142 | controlling.freeze(player); | 133 | ponderable.collidable = false; |
143 | 134 | ||
144 | animatable.setFrozen(true); | 135 | auto& scheduling = game_.getSystemManager().getSystem<SchedulingSystem>(); |
145 | animatable.setFlickering(true); | 136 | |
146 | ponderable.setFrozen(true); | 137 | scheduling.schedule(player, 0.75, [&] (id_type player) { |
147 | ponderable.setCollidable(false); | 138 | auto& playable = game_.getEntityManager(). |
148 | 139 | getComponent<PlayableComponent>(player); | |
149 | auto& scheduling = game_.getSystemManager().getSystem<SchedulingSystem>(); | 140 | |
150 | 141 | changeMap( | |
151 | scheduling.schedule(player, 0.75, [&] (id_type player) { | 142 | player, |
152 | auto& playable = game_.getEntityManager(). | 143 | playable.checkpointMapId, |
153 | getComponent<PlayableComponent>(player); | 144 | playable.checkpointX, |
154 | 145 | playable.checkpointY); | |
155 | changeMap( | 146 | |
156 | playable.checkpointMapId, | 147 | animatable.frozen = false; |
157 | playable.checkpointX, | 148 | animatable.flickering = false; |
158 | playable.checkpointY, | 149 | ponderable.frozen = false; |
159 | [&, player] () { | 150 | ponderable.collidable = true; |
160 | animatable.setFrozen(false); | 151 | |
161 | animatable.setFlickering(false); | 152 | // Reset the walk state, and then potentially let the |
162 | ponderable.setFrozen(false); | 153 | // ControllingSystem set it again. |
163 | ponderable.setCollidable(true); | 154 | auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>(); |
164 | 155 | orienting.stopWalking(player); | |
165 | // Reset the walk state, and then potentially let the | 156 | |
166 | // ControllingSystem set it again. | 157 | controlling.unfreeze(player); |
167 | auto& orienting = game_.getSystemManager(). | 158 | }); |
168 | getSystem<OrientingSystem>(); | ||
169 | orienting.stopWalking(player); | ||
170 | |||
171 | controlling.unfreeze(player); | ||
172 | }); | ||
173 | }); | ||
174 | } | ||
175 | } | 159 | } |