| Filename | Latest commit message | Latest commit date |
|---|---|---|
| README.md | ||
🟢 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:
- Hardware Sensors: Using the
sensors_pluspackage to read the phone's tilt. - Streams: Handling a constant flow of data (the phone's position changes 60 times a second!).
- Advanced Layouts: Using
StackandPositionedto 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_pluspackage. - Link the
xandycoordinates of the ball to theaccelerometerEventsstream. - 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
- Dependencies: Add
sensors_plus: ^6.1.1(or the latest version) to yourpubspec.yaml. - The UI: Create a
Scaffoldwith aStackwidget. TheStackallows you to put the ball "on top" of the background. - 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.
- Hint: You’ll need to use
- 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
audioplayerspackage 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.