Skip to content

Commit 655de4a

Browse files
Update README.md
1 parent ae730ec commit 655de4a

File tree

1 file changed

+1
-77
lines changed

1 file changed

+1
-77
lines changed

README.md

+1-77
Original file line numberDiff line numberDiff line change
@@ -210,83 +210,7 @@ beginStateMachine()
210210
.endStateMachine();
211211
```
212212

213-
## Example 4: Flappy-Bird game controller
214-
215-
A slightly more complex example is the game controller of my [Flappy Bird](https://github.com/armin-reichert/birdy) game implementation.
216-
217-
```java
218-
beginStateMachine()
219-
.description("[Play Scene]")
220-
.initialState(PLAYING)
221-
222-
.states()
223-
224-
.state(PLAYING)
225-
.onEntry(() -> {
226-
points = 0;
227-
start();
228-
})
229-
230-
.state(GAME_OVER)
231-
.onEntry(() -> stop())
232-
233-
.transitions()
234-
235-
.stay(PLAYING)
236-
.on(TOUCHED_PIPE)
237-
.condition(() -> points > 3)
238-
.act(e -> {
239-
points -= 3;
240-
sound("sfx/hit.mp3").play();
241-
Bird bird = ent.named("bird");
242-
bird.tf.x += app().settings().getAsInt("obstacle-width") + bird.tf.width;
243-
bird.dispatch(TOUCHED_PIPE);
244-
})
245-
246-
.stay(PLAYING)
247-
.on(PASSED_OBSTACLE)
248-
.act(e -> {
249-
points++;
250-
sound("sfx/point.mp3").play();
251-
})
252-
253-
.when(PLAYING).then(GAME_OVER)
254-
.on(TOUCHED_PIPE)
255-
.condition(() -> points <= 3)
256-
.act(t -> {
257-
sound("sfx/hit.mp3").play();
258-
Bird bird = ent.named("bird");
259-
bird.dispatch(CRASHED);
260-
})
261-
262-
.when(PLAYING).then(GAME_OVER)
263-
.on(TOUCHED_GROUND)
264-
.act(e -> {
265-
sound("music/bgmusic.mp3").stop();
266-
Bird bird = ent.named("bird");
267-
bird.dispatch(TOUCHED_GROUND);
268-
})
269-
270-
.when(PLAYING).then(GAME_OVER)
271-
.on(LEFT_WORLD)
272-
.act(e -> {
273-
sound("music/bgmusic.mp3").stop();
274-
Bird bird = ent.named("bird");
275-
bird.dispatch(LEFT_WORLD);
276-
})
277-
278-
.stay(GAME_OVER)
279-
.condition(() -> Keyboard.keyPressedOnce(KeyEvent.VK_SPACE))
280-
.act(() -> BirdyGameApp.setScene(START_SCENE))
281-
282-
.stay(GAME_OVER)
283-
.on(TOUCHED_GROUND)
284-
.act(() -> sound("music/bgmusic.mp3").stop())
285-
286-
.endStateMachine();
287-
```
288-
289-
## Example 5: Pac-Man ghost "AI"
213+
## Example 4: Pac-Man ghost "AI"
290214

291215
I used this state machine library extensively in my [Pac-Man game implementation](https://github.com/armin-reichert/pacman), which in fact was the main motivation for creating this library at all. In that implementation, state machines are used all over the place: for the central game control, for Pac-Man and the ghosts, for their movement, for controlling the animations in the intro view and more.
292216

0 commit comments

Comments
 (0)