My project idea will be a Marble Maze. You will navigate the maze using the Gyro and Accelerometer to control the marble movement. There will be obsticles where the marble can fall in and you will need to avoid it and make it to the finish spot.
For the project, there will be 2 viewable areas. The main page
where the user will touch the start button in order to start
the game. Once it is clicked, the game will start and it will
start getting input from the Gyro and Accelerometer to control
the marble movements.
The first stage will be getting the marble getting the movement
to be controlled by the Gyro and Accelerometer. Second after
that will be to add the start page to make sure the transition
to the game works. Third will to add the finish spot and the
obsticles that you will need to avoid.
A1)The sensors I will be using is the Gyroscope and the Accelerometer. For the Gyroscope I will need to get the rotational data of the phone which will controll the location the marble will move. The Accelerometer will detect the data of how fast the phone moves, this will control the speed the marble will move.
A2)Gyroscope will output three float values, X, Y, and Z. Each value is in radians per seconds.
For anticlockwise rotation along any axis, the values will be positive. For clockwise rotation
along any axis, the values will be negative.
Accelerometer will output three float values, X, Y and Z. The X-axis is the left right movement
of the phone. The Y-axis is the Up and Down movement of the phone. The Z-axis is the forward and backward
movement of the phone. The values i will only be interested in is the X and Y values which can output
+/-16.0.
A3)I will use my One Plus 7 Pro to test the project and the sensors to see if they are working. With my device, I will output the values the sensors to the display to see if it is working correctly.
A4)In order to push the android project to github, I would first create a folder to store the project in. Within that folder, I would git init, then save the android project in that folder. From this I will 'git add .' to add all the files to be commited. Next will be 'git remote add origin -http github project-' in order for it to connect to the project. Save the android project to that file and 'git add .' to add all the files to be commited. The last two commands will be 'git commit -m "Commit"' to describe what was pushed and then 'git push -u origin main' to send all the code to github.
For this project, I went with trying to get a game that requires the user
to tilt there phone to controll the marble on the screen. The goal is to get
to the finish line which is the white square. I was unable to get any obstacles create
since they were not as important as the movement, finish line and main pages.
The above pictures are what the app looks like, the main page is first and the play
area is second.
Above is the sensor code in my project. It constantly checks for any changes in the
Accelerometer and changes the stored value. The if statements control the boundary that
the marble can do so it stays within bounds. This is the area that I would need to use
to create the collision for the obstacles.
While working on developing this project, I ran into alot of interesting bugs.
The goal is the game is to beat the level the fastest and I was having trouble
creating a finish page so instead I decided to have it redirect back to the main page.
This is when the problems started, while trying to debug the issue, I had my application
crash my phone System.UI about 4 times. This all came down to the code above.
The redirect works but if you decided to close the game before the redirect
it would cause this crash to happen. A way to fix, which i have not been able to
get working, is to have it detect when the app is closed or suspended and stop the
redirect from happening.
I did not have a way to show the screen moving so instead I streamed my phone display
to my desktop using SCRCPY and video recorded it then.