Skip to content

Commit

Permalink
'move_camera' is an extra chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Aug 3, 2024
1 parent f187def commit 3c3f6cb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
16 changes: 8 additions & 8 deletions docs/chapters/add_camera.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add camera
# 2.7. Add camera

In this chapter, we add adding a camera to our test suites.

Expand All @@ -7,7 +7,7 @@ This chapter introduces:
- the Bevy `Camera2dBundle` bundle
- a local closure

## First test
## 2.7.1. First test

Similar to earlier chapters, the test starts with
counting the number of cameras:
Expand All @@ -20,7 +20,7 @@ fn test_empty_app_has_no_cameras() {
}
```

## First fix
## 2.7.2. First fix

Similar to a `Text` component, we take a look
at [the Bevy documentation on the Camera2dBundle](https://docs.rs/bevy/latest/bevy/prelude/struct.Camera2dBundle.html)
Expand All @@ -39,7 +39,7 @@ their own `Camera`s. As long as it is the case that our camera is the
only `Camera`, this implementation is good enough and does not need
a marker component.

## Second test
## 2.7.3. Second test

Our game will have a camera with a custom scale.
Instead of repeating the smaller steps as in the earlier chapters,
Expand All @@ -59,7 +59,7 @@ In TDD, one should have many small tests and only add one tests that breaks
at the same time. However, to save book pages, I've combined the three
tests into one.

## Second fix
## 2.7.4. Second fix

To fix all this, we need to:

Expand Down Expand Up @@ -100,14 +100,14 @@ Here, we query for the same `projection` field of a `Camera2dBundle`
of data type `OrthographicProjection` as we've used in the `create_app`
function.

## Third tests
## 2.7.5. Third tests

We do want to be able to see something. Hence, we'll probably want to
add a player with or without a texture. I've picked to add
a player in the same way as chapter [`add_player`](add_player.md)
and re-used the same tests and implementations.

## Running `main`
## 2.7.6. Running `main`

As our `create_app` now also adds a camera, the `main` function
simplifies to:
Expand All @@ -123,7 +123,7 @@ fn main() {

![The camera has zoomed in](add_camera.png)

## Conclusion
## 2.7.7. Conclusion

We can now create an `App` with a camera.
When running the `App`, a rectangle is displayed.
Expand Down
22 changes: 11 additions & 11 deletions docs/chapters/move_player.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Move a player
# 2.8. Move a player

This chapter shows how to move a player.

Expand All @@ -10,7 +10,7 @@ This chapter introduces:
- how to extend our own Bevy component
- adding an `Update` system

## First test: an empty `App` has no players
## 2.8.1. First test: an empty `App` has no players

Similar to all earlier chapters, we open
our test suite with counting the number
Expand All @@ -24,11 +24,11 @@ fn test_empty_app_has_no_players() {
}
```

## First fix
## 2.8.2. First fix

See the [`add_player`](add_player.md) chapter.

## Second test: our `App` stores an initial velocity
## 2.8.3. Second test: our `App` stores an initial velocity

The idea of this app is to give the player a velocity,
so that we can see it move.
Expand All @@ -45,7 +45,7 @@ fn test_can_set_and_get_velocity() {
}
```

## Second fix
## 2.8.4. Second fix

To fix this, we'll need to:

Expand Down Expand Up @@ -120,7 +120,7 @@ fn get_player_velocity(app: &mut App) -> Vec2 {
We can directly query for a `Player` component, as we can be sure
other Bevy plugins will not add it for us.

## Third test: our `App` has a player
## 2.8.5. Third test: our `App` has a player

We've been counting the number of players
since the [`add_player`](add_player.md) chapter:
Expand All @@ -136,7 +136,7 @@ fn test_create_app_has_a_player() {

See the [`add_player`](add_player.md) chapter for its implementation.

## Fourth test: the player starts at the origin
## 2.8.6. Fourth test: the player starts at the origin

We've been getting the position of the player
at the [`add_player_sprite`](add_player_sprite.md) chapter:
Expand All @@ -153,7 +153,7 @@ fn test_player_starts_at_the_origin() {
See the [`add_player_sprite`](add_player_sprite.md) chapter for its
implementation.

## Fifth test: a player moves
## 2.8.7. Fifth test: a player moves

Now we have all the pieces in place to test for movement:

Expand All @@ -174,7 +174,7 @@ The test shown here is enough to force us to add player movement,
hence we'll stick with it. If we need precise movement tests, sure, go
ahead and add these!

## Fifth fix
## 2.8.8. Fifth fix

Making a player move is a (Bevy) system: it is a -typically-
function that works on entities in the world.
Expand Down Expand Up @@ -205,7 +205,7 @@ That function argument is the most interesting of the function:
`query` will contain all `Transforms` marked with a `Player`,
where -for the first time!- we can modify the `Transform`.

## `main.rs`
## 2.8.9. `main.rs`

To see that it works, this is the code we can use:

Expand All @@ -227,7 +227,7 @@ We can indeed see our player move:

![The player moves](move_player.png)

## Conclusion
## 2.8.10. Conclusion

We can now create an `App` with one player sprite that moves.
When running the `App`, we can see the player moves.
Expand Down
6 changes: 5 additions & 1 deletion docs/misc/basic_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ flowchart TD
add_camera[2.6. add_camera\nAdd a camara]
move_player[2.7. move_player\nMove the player]
add_text[2.8. add_text\nAdd text]
move_camera[2.9. move_camera\nMove the camera]
move_camera[move_camera\nMove the camera]
introduction --> hello_world
hello_world --> add_player
Expand All @@ -27,3 +27,7 @@ flowchart TD
add_player_sprite --> move_player
move_player -.-> |optional| move_camera
```

The last chapter `move_camera` is an optional chapter
and part of the appendix,
as it introduces no new concepts.

Check failure on line 33 in docs/misc/basic_introduction.md

View workflow job for this annotation

GitHub Actions / check_markdown

Files should end with a single newline character
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ nav:
- 2.6. Add text: chapters/add_text.md
- 2.7. Add a camera: chapters/add_camera.md
- 2.8. Move the player: chapters/move_player.md
- 2.9. Move the camera: chapters/move_camera.md
- 3. Respond to input:
- 3.1. Introduction: misc/respond_to_input_introduction.md
- 3.x. Respond to a key just being pressed: chapters/respond_to_just_key_pressed.md
Expand All @@ -27,6 +26,7 @@ nav:
- 3.x. Respond to a window resize: chapters/respond_to_window_resize.md
- Example programs:
- Introduction: misc/example_programs_introduction.md
- Move the camera: chapters/move_camera.md
- Move the camera with the keyboard: chapters/move_camera_with_keyboard.md
- Move the camera with the mouse: chapters/move_camera_with_mouse.md
- Move the player with the keyboard: chapters/move_player_with_keyboard.md
Expand Down

0 comments on commit 3c3f6cb

Please sign in to comment.