From e666ebbd05338aa1d3b4e745a983dfdcc7e20fd5 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 13 Oct 2022 20:52:11 +0100 Subject: [PATCH] Start section on controls --- book/src/SUMMARY.md | 1 + book/src/pong/04_controls.md | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 book/src/pong/04_controls.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index e6699916..41b154d2 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -11,3 +11,4 @@ - [Learn agb part I - pong](./pong/01_introduction.md) - [The Gba struct](./pong/02_the_gba_struct.md) - [Sprites](./pong/03_sprites.md) + - [Controls](./pong/04_controls.md) diff --git a/book/src/pong/04_controls.md b/book/src/pong/04_controls.md new file mode 100644 index 00000000..d4a146c1 --- /dev/null +++ b/book/src/pong/04_controls.md @@ -0,0 +1,23 @@ +# Controls + +In this section, we'll make the ball that we displayed in the last section move by pressing the D-Pad. + +# The GBA controls + +The GBA has 10 buttons we can read the state of, and this is the only way a player can directly control the game. +They are the 4 directions on the D-Pad, A, B, Start, Select, and the L and R triggers. + +# Reading the button state + +There are two ways to capture the button state in **agb**, interrupts and polling. +In most games, you will want to use polling, so that is what we will use now. +Interrupts will be covered in a later chapter. + +To add button control to our game, we will need a [ButtonController](https://docs.rs/agb/latest/agb/input/struct.ButtonController.html). +Add this near the top of your main function: + +```rust + let mut input = agb::input::ButtonController::new(); +``` + +The button controller is not part of the `Gba` struct because it only allows for reading and not writing so does not need to be controlled by the borrow checker. \ No newline at end of file