diff options
Diffstat (limited to 'src/systems/playing.cpp')
-rw-r--r-- | src/systems/playing.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/systems/playing.cpp b/src/systems/playing.cpp new file mode 100644 index 0000000..6652099 --- /dev/null +++ b/src/systems/playing.cpp | |||
@@ -0,0 +1,144 @@ | |||
1 | #include "playing.h" | ||
2 | #include "game.h" | ||
3 | #include "components/transformable.h" | ||
4 | #include "components/animatable.h" | ||
5 | #include "components/playable.h" | ||
6 | #include "components/controllable.h" | ||
7 | #include "components/orientable.h" | ||
8 | #include "systems/mapping.h" | ||
9 | #include "systems/pondering.h" | ||
10 | #include "systems/orienting.h" | ||
11 | #include "systems/scheduling.h" | ||
12 | #include "systems/controlling.h" | ||
13 | #include "systems/animating.h" | ||
14 | #include "systems/realizing.h" | ||
15 | #include "animation.h" | ||
16 | #include "muxer.h" | ||
17 | |||
18 | void PlayingSystem::initPlayer() | ||
19 | { | ||
20 | id_type player = game_.getEntityManager().emplaceEntity(); | ||
21 | |||
22 | AnimationSet playerGraphics {"res/Starla.png", 10, 12, 6}; | ||
23 | playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1); | ||
24 | playerGraphics.emplaceAnimation("stillRight", 0, 1, 1); | ||
25 | playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10); | ||
26 | playerGraphics.emplaceAnimation("walkingRight", 1, 2, 10); | ||
27 | |||
28 | game_.getEntityManager().emplaceComponent<AnimatableComponent>( | ||
29 | player, | ||
30 | std::move(playerGraphics)); | ||
31 | |||
32 | game_.getSystemManager().getSystem<AnimatingSystem>().startAnimation( | ||
33 | player, | ||
34 | "stillLeft"); | ||
35 | |||
36 | auto& realizing = game_.getSystemManager().getSystem<RealizingSystem>(); | ||
37 | |||
38 | auto& transformable = game_.getEntityManager(). | ||
39 | emplaceComponent<TransformableComponent>(player); | ||
40 | |||
41 | transformable.pos = realizing.getStartingPos(); | ||
42 | transformable.size.w() = 10; | ||
43 | transformable.size.h() = 12; | ||
44 | |||
45 | game_.getSystemManager().getSystem<PonderingSystem>().initializeBody( | ||
46 | player, | ||
47 | PonderableComponent::Type::freefalling); | ||
48 | |||
49 | game_.getEntityManager().emplaceComponent<ControllableComponent>(player); | ||
50 | game_.getEntityManager().emplaceComponent<OrientableComponent>(player); | ||
51 | |||
52 | auto& playable = game_.getEntityManager(). | ||
53 | emplaceComponent<PlayableComponent>(player); | ||
54 | |||
55 | playable.mapId = realizing.getActiveMap(); | ||
56 | playable.checkpointMapId = realizing.getStartingMapId(); | ||
57 | playable.checkpointPos = realizing.getStartingPos(); | ||
58 | |||
59 | realizing.enterActiveMap(player); | ||
60 | |||
61 | realizing.setActivePlayer(player); | ||
62 | } | ||
63 | |||
64 | void PlayingSystem::changeMap( | ||
65 | id_type player, | ||
66 | size_t mapId, | ||
67 | vec2d warpPos) | ||
68 | { | ||
69 | auto& playable = game_.getEntityManager(). | ||
70 | getComponent<PlayableComponent>(player); | ||
71 | |||
72 | auto& transformable = game_.getEntityManager(). | ||
73 | getComponent<TransformableComponent>(player); | ||
74 | |||
75 | auto& pondering = game_.getSystemManager().getSystem<PonderingSystem>(); | ||
76 | auto& realizing = game_.getSystemManager().getSystem<RealizingSystem>(); | ||
77 | |||
78 | id_type newMapEntity = realizing.getEntityByMapId(mapId); | ||
79 | |||
80 | if (playable.mapId != newMapEntity) | ||
81 | { | ||
82 | if (playable.mapId == realizing.getActiveMap()) | ||
83 | { | ||
84 | realizing.leaveActiveMap(player); | ||
85 | } else if (newMapEntity == realizing.getActiveMap()) | ||
86 | { | ||
87 | realizing.enterActiveMap(player); | ||
88 | } | ||
89 | |||
90 | playable.mapId = newMapEntity; | ||
91 | } | ||
92 | |||
93 | pondering.unferry(player); | ||
94 | |||
95 | transformable.pos = warpPos; | ||
96 | |||
97 | if (realizing.getActivePlayer() == player) | ||
98 | { | ||
99 | realizing.loadMap(newMapEntity); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | void PlayingSystem::die(id_type player) | ||
104 | { | ||
105 | playSound("res/Hit_Hurt5.wav", 0.25); | ||
106 | |||
107 | auto& animatable = game_.getEntityManager(). | ||
108 | getComponent<AnimatableComponent>(player); | ||
109 | |||
110 | auto& ponderable = game_.getEntityManager(). | ||
111 | getComponent<PonderableComponent>(player); | ||
112 | |||
113 | auto& controlling = game_.getSystemManager().getSystem<ControllingSystem>(); | ||
114 | controlling.freeze(player); | ||
115 | |||
116 | animatable.frozen = true; | ||
117 | animatable.flickering = true; | ||
118 | ponderable.frozen = true; | ||
119 | ponderable.collidable = false; | ||
120 | |||
121 | auto& scheduling = game_.getSystemManager().getSystem<SchedulingSystem>(); | ||
122 | |||
123 | scheduling.schedule(player, 0.75, [&] (id_type player) { | ||
124 | auto& playable = game_.getEntityManager(). | ||
125 | getComponent<PlayableComponent>(player); | ||
126 | |||
127 | changeMap( | ||
128 | player, | ||
129 | playable.checkpointMapId, | ||
130 | playable.checkpointPos); | ||
131 | |||
132 | animatable.frozen = false; | ||
133 | animatable.flickering = false; | ||
134 | ponderable.frozen = false; | ||
135 | ponderable.collidable = true; | ||
136 | |||
137 | // Reset the walk state, and then potentially let the | ||
138 | // ControllingSystem set it again. | ||
139 | auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>(); | ||
140 | orienting.stopWalking(player); | ||
141 | |||
142 | controlling.unfreeze(player); | ||
143 | }); | ||
144 | } | ||