You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- PoolTable: Pool table geometrical configuration (table, pockets, etc.)
81
+
- Cue: Implements cue sticks
82
+
- EightBall: 8-ball game logic
81
83
82
-
Game objects such as fruits and score are stored in the context. Gameplay middleware manages game objects and state, and receives events such as drop-next-fruit, move-next-fruit from Terminal, and collide-fruits, collide-top from Physics.
84
+
Game data such as balls and score are stored in the application context, and are used by all middlewares. Middlewares communicate via events, and don't have direct access to each other.
83
85
84
-
Terminal middleware accesses game objects and state from the context. and renders them on screen using SVG. Terminal also collects user pointer input and then sends drop-next-fruit and move-next-fruit, which are used by Gameplay.
85
-
86
-
Physics middleware also accesses game objects and state from the context. Physics adds fruits to physics simulation, updates fruits position, and collect collision events from simulation and sends collide-fruits, collide-fruit-top to gameplay.
87
-
88
-
FrameLoop middleware implements the game loop. It sends frame-loop event to all middlewares in each frame.
89
-
90
-
We will discuss each middleware further in the following sections.
86
+
Here is how our Main class looks like:
91
87
92
88
```ts
93
89
classMainextendsMiddleware {
94
90
constructor() {
95
91
super();
96
-
this.use(newGameplay());
97
-
this.use(newPhysics());
98
-
this.use(newTerminal());
99
92
this.use(newFrameLoop());
93
+
this.use(newEightBall());
94
+
this.use(newPoolTable());
95
+
this.use(newCue());
96
+
this.use(newBilliardsPhysics());
97
+
this.use(newTerminal());
100
98
}
101
99
}
102
-
```
100
+
```
103
101
104
-
### Watermelon: FrameLoop
102
+
We will discuss each middleware further in the following sections. By breaking down the application into loosely-coupled middlewares we can reduce complexity of the application, and make it easier to maintain and extend.
103
+
104
+
Terminal middleware accesses game objects and state from the context. and renders them on screen using SVG. Terminal also collects user pointer input and then sends drop-next-fruit and move-next-fruit, which are used by Gameplay.
105
+
106
+
Physics middleware also accesses game objects and state from the context. Physics adds fruits to physics simulation, updates fruits position, and collect collision events from simulation and sends collide-fruits, collide-fruit-top to gameplay.
107
+
108
+
FrameLoop middleware implements the game loop. It sends frame-loop event to all middlewares in each frame.
109
+
110
+
EightBall middleware manages game state, and receives events such as drop-next-fruit, move-next-fruit from Terminal, and collide-fruits, collide-top from Physics.
111
+
112
+
### FrameLoop Middleware
105
113
106
114
Polymatic does not implement game loop, or any other game specific functions. However, it's very simple to use a middlewares to implement a game loop.
107
115
@@ -137,11 +145,11 @@ class Physics extends Middleware {
137
145
}
138
146
```
139
147
140
-
Please note that here we used a fixed frame loop. In this repository source code we implemented a variable frame loop which is slightly more complicated.
148
+
Please note that here we implemented a fixed frame loop. In this repository source code there is a variable frame loop which is slightly more complicated.
141
149
142
-
### Watermelon: Gameplay
150
+
### EightBall Middleware
143
151
144
-
Next, let's implement the gameplay. In the gameplay we implement the logic for dropping new fruits, merging them, and increasing user score.
152
+
Next, let's implement the 8-ball gameplay. In the EightBall middleware we implement the logic, such as when player pockets a ball.
145
153
146
154
We store all objects in the context so that they can be accessed by all middlewares, and we listen to events from other middlewares.
147
155
@@ -175,11 +183,15 @@ class Gameplay extends Middleware {
175
183
}
176
184
```
177
185
186
+
### Cue Middleware
187
+
Cue middleware implements the cue stick. Cue middleware receives user pointer input events from Terminal, and sends move-cue, and shot-cue events, to BilliardsPhysic middleware.
188
+
189
+
178
190
### Data Driver
179
191
180
-
Middlewares shares game object via context. In some middlewares we need to assign new components to game objects. For example in this project in the Terminal middleware we need to add a new svg element for each fruit, and add new bodies to the physics simulation in the Physics middleware. Data drivers are used by middlewares to dynamically add new components to game objects.
192
+
Middlewares share game objects in context. In some middlewares we need to assign new components to game objects. For example for each ball we need to create an SVG element in the Terminal middleware, and add a new physics simulation body int the Physics middleware. Data drivers are used by middlewares to dynamically add new components to game objects.
181
193
182
-
To use data-drivers we first create a Dataset, and then add Drivers to the dataset.
194
+
To use data-drivers we first create a Dataset to track entities, and then add Drivers to the dataset to manage components.
183
195
184
196
Dataset needs to uniquely identify objects between updates, so it requires a key function. We can create a dataset by extending the Dataset class, or using the `Dataset.create` method:
Physics middleware adds physics simulation to fruits and detects collisions. When two similar fruits collide, physics middleware emits an event to informs gameplay middleware about the collision to merge two fruits.
241
+
Physics middleware adds movement and collision detection to balls and table. When two similar fruits collide, physics middleware emits an event to informs gameplay middleware about the collision to merge two fruits.
@@ -293,7 +305,7 @@ export class Physics extends Middleware<MainContext> {
293
305
294
306
```
295
307
296
-
### Watermelon: Terminal with SVG
308
+
### Terminal with SVG
297
309
298
310
Now we need to implement the game Terminal (i.e. user-interface). Terminal renders game objects and score, and collects user input such as pointer events.
0 commit comments