Skip to content

Commit

Permalink
Add camera
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Jul 5, 2024
1 parent 83f57c1 commit d22d45a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Code
[code](https://github.com/richelbilderbeek/bevy_tdd_book_hello_world) |[![codecov](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_hello_world/graph/badge.svg?token=XAVFZYDQKZ)](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_hello_world) |[hello_world.md](hello_world.md) |Hello world |A minimal `App`
[code](https://github.com/richelbilderbeek/bevy_tdd_book_add_player) |[![codecov](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_add_player/graph/badge.svg?token=XAVFZYDQKZ)](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_add_player) |[add_player.md](add_player.md) |Adding a player |Using `Components`
[code](https://github.com/richelbilderbeek/bevy_tdd_book_add_player_sprite) |[![codecov](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_add_player_sprite/graph/badge.svg?token=XAVFZYDQKZ)](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_add_player_sprite) |[add_player_sprite.md](add_player_sprite.md) |Adding a player sprite |Using closures and `SpriteBundles`
[code](https://github.com/richelbilderbeek/bevy_tdd_book_add_camera) |[![codecov](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_add_camera/graph/badge.svg?token=XAVFZYDQKZ)](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_add_camera) |[add_camera.md](add_camera.md) |Adding a camera |Minimal example, using the `Camera` `Component`
[code](https://github.com/richelbilderbeek/bevy_tdd_book_move_player) |[![codecov](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_move_player/graph/badge.svg?token=XAVFZYDQKZ)](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_move_player) |[move_player.md](move_player.md) |Move a player |Extending a structure, using a `Query`
[code](https://github.com/richelbilderbeek/bevy_tdd_book_move_player_with_keyboard) |[![codecov](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_move_player_with_keyboard/graph/badge.svg?token=XAVFZYDQKZ)](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_move_player_with_keyboard) |[move_player_with_keyboard.md](move_player_with_keyboard.md) |Respond to keyboard |.
[code](https://github.com/richelbilderbeek/bevy_tdd_book_respond_to_keypress) |[![codecov](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_respond_to_keypress/graph/badge.svg?token=XAVFZYDQKZ)](https://codecov.io/gh/richelbilderbeek/bevy_tdd_book_respond_to_keypress) |[respond_to_keypress.md](respond_to_keypress.md) |Respond to keyboard, minimal example |Minimal example, key press
Expand All @@ -24,6 +25,7 @@ flowchart TD
hello_world[hello_world\nGet started]
add_player[add_player\nAdd a player]
add_player_sprite[add_player_sprite\nAdd a player sprite]
add_camera[add_camera\nAdd a camara]
move_player[move_player\nMove a player]
move_player_keyboard[move_player_keyboard\nMove a player\nusing keyboard]
move_player_mouse[move_player_mouse\nMove a player\nusing mouse]
Expand All @@ -40,6 +42,8 @@ flowchart TD
add_player --> add_player_sprite
add_player_sprite --> move_player
add_player_sprite --> add_camera
move_player --> move_player_keyboard
move_player --> move_player_mouse
```
Expand Down
66 changes: 66 additions & 0 deletions add_camera.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Add camera

## First test

```rust
#[test]
fn test_empty_app_has_no_camera() {
let mut app = App::new();
app.update();
assert!(!has_camera(&app));
}
```

## Second test

```rust
#[test]
fn test_app_has_a_camera() {
let mut app = create_app(create_default_game_parameters());
app.update();
assert!(has_camera(&app));
}
```

## Third test

```rust
#[test]
fn test_get_camera_scale() {
let mut app = create_app(create_default_game_parameters());
app.update();
assert_eq!(get_camera_scale(&mut app), 1.0);
}
```

## Fourth test

```rust
#[test]
fn test_initial_camera_scale() {
assert_eq!(create_default_game_parameters().initial_camera_scale, 1.0);
}
```

## Fifth test


Check failure on line 47 in add_camera.md

View workflow job for this annotation

GitHub Actions / check_markdown

Multiple consecutive blank lines [Expected: 1; Actual: 2]
```rust
#[test]
fn test_game_parameters_use_camera_scale() {
let custom_camera_scale: f32 = 5.0;
let mut params = create_default_game_parameters();
params.initial_camera_scale = custom_camera_scale;
let mut app = create_app(params);
app.update();
assert_eq!(get_camera_scale(&mut app), custom_camera_scale);
}
```

## Conclusion

We can now create an `App` with a camera.
When running the `App`, a rectangle is displayed.
However, we do have tested everything that the App does!

Full code can be found at [https://github.com/richelbilderbeek/bevy_tdd_book_add_camera](https://github.com/richelbilderbeek/bevy_tdd_book_add_camera).
Binary file added add_camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d22d45a

Please sign in to comment.