snake: Add D-pad support
Change-Id: I0edecc390acdcd4424d2fba567f0dc326e59ac0e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/kudzu/+/228652
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Carlos Chinchilla <cachinchilla@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Taylor Cramer <cramertj@google.com>
diff --git a/applications/snake/main.cc b/applications/snake/main.cc
index d49ce6e..e0657b0 100644
--- a/applications/snake/main.cc
+++ b/applications/snake/main.cc
@@ -74,6 +74,8 @@
display.ReleaseFramebuffer(std::move(framebuffer));
snake::Game game(display_width, display_height);
+
+ kudzu::Buttons& kudzu_buttons = Common::GetButtons();
PollingTouchButtonsThread touch_buttons_thread{
Common::GetTouchscreen(), game, display_width, display_height};
pw::thread::DetachedThread(Common::TouchscreenThreadOptions(),
@@ -86,6 +88,20 @@
while (true) {
frame_counter.StartFrame();
+ kudzu_buttons.Update();
+ if (kudzu_buttons.Pressed(kudzu::button::up)) {
+ game.OnButtonUp(true);
+ }
+ if (kudzu_buttons.Pressed(kudzu::button::down)) {
+ game.OnButtonDown(true);
+ }
+ if (kudzu_buttons.Pressed(kudzu::button::left)) {
+ game.OnButtonLeft(true);
+ }
+ if (kudzu_buttons.Pressed(kudzu::button::right)) {
+ game.OnButtonRight(true);
+ }
+
// Get frame buffer.
framebuffer = display.GetFramebuffer();
PW_CHECK(framebuffer.is_valid());