No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-04-02 17:11:30 +05:00
README.md Update README.md 2026-04-02 17:11:30 +05:00

🟢 Project: Gravity Maze (The Tilt Challenge)

Welcome to your first Hardware-Integrated Game! In the Udemy course, you learned how to make apps that respond to taps. In this project, you are going to turn the entire phone into a controller by using the Accelerometer.

🚀 The Mission

Build a game where a ball sits in a "Maze" (the screen). Instead of swiping, the player must physically tilt the phone to roll the ball into a goal while avoiding "Black Hole" obstacles.


🛠 What You’ll Learn (The "New Stuff")

Since you’ve already mastered the basics, this project will push you into three new areas:

  1. Hardware Sensors: Using the sensors_plus package to read the phone's tilt.
  2. Streams: Handling a constant flow of data (the phone's position changes 60 times a second!).
  3. Advanced Layouts: Using Stack and Positioned to move objects freely on the screen.

📋 The Feature List

Phase 1: The Arena

  • A dark-themed background (Game Mode!).
  • A bright-colored Ball (the Player) starting in the center.
  • A Goal (a star or a circle) in one of the corners.

Phase 2: The Gravity Engine

  • Import the sensors_plus package.
  • Link the x and y coordinates of the ball to the accelerometerEvents stream.
  • The Logic: If the phone tilts left, the ball's X-coordinate should decrease!

Phase 3: Boundaries & Win Logic

  • Stop the ball from disappearing off the edge of the screen (Wall detection).
  • Show a "Level Complete!" alert when the ball touches the Goal.
  • Add a Reset button to put the ball back in the middle.

🗺️ Your Roadmap

  1. Dependencies: Add sensors_plus: ^6.1.1 (or the latest version) to your pubspec.yaml.
  2. The UI: Create a Scaffold with a Stack widget. The Stack allows you to put the ball "on top" of the background.
  3. The Listener: Inside initState(), start listening to the accelerometer.
    • Hint: You’ll need to use setState(() {}) inside the listener to tell Flutter to redraw the ball every time the phone moves.
  4. Math Time: The accelerometer gives values like 9.8 (gravity). You’ll need to multiply or divide these numbers to make the ball move at a speed that feels "fun," not too fast or too slow.

🏆 Level Up Challenges (Bonus)

If you finish the base game, try adding these:

  • 🕳️ The Black Holes: Add red circles on the screen. If the ball touches them, it’s "Game Over" and the ball resets.
  • ⏱️ Speedrun: Add a timer to see how fast the player can reach the goal.
  • 🎵 Sound FX: Use the audioplayers package to play a "Ding!" when the goal is hit or a "Boing!" when the ball hits a wall.

💡 Pro-Tip

You cannot test this on a computer emulator! Since computer monitors don't have accelerometers, you will need to plug in a real physical phone to test your "Gravity Engine."

Good luck, Dev! Time to get rolling.