if you add

print('X:{:.2f} Y:{:.2f} Z:{:0.2f}'.format(*g))

after the g = gravity() line in update, this will print the gravity direction (it will show up at the very bottom line, or will show up in console later when you stop the script)

The gravity vector is the direction if gravity, relative to your phone's physical coordinate system: Z points out of the screen, Y points from home button to camera, and X points right in normal portrait mode.

When you hold your phone up to a wall, so you are looking at the screen in front of you with the home button on the bottom edge like you would normally hold it to make a phone call, gravity should read near -1 in Y, but 0 for the other axes.

If you then rotate it 90 degrees counter clockwise, so the home button is on the right side, but screen still vertical, X should read -1.

if you lay it flat on the table, screen up, Z should be near -1 and the other two are near zero.
If you hold it screen

If you confirm that is the case, i think one of two things happened.

Make sure you are not running in any sort of split screen mode. im not sure how scene behaves when you run split screen.

Also, make sure you have this line

run(Game(), PORTRAIT, show_fps=True)

if you had changed to LANDSCAPE, or nothing at all, then things would be as you described, since the game logic assumes that g.x is left/right. if you are in landscape, g.y increases when you tip left/right, while g.x would change by tipping forward/back.

in case you editing something by accident, the motion logic looks like

if abs(g.x) > 0.05: x = self.player.position.x # The components of the gravity vector are in the range 0.0 to 1.0, so we have to multiply it with some factor to move the player more quickly. 40 works pretty well, but feel free to experiment. max_speed = 40 # We simply add the x component of the gravity vector to the current position, and clamp the value between 0 and the scene's width, so the alien doesn't move outside of the screen boundaries. x = max(0, min(self.size.w, x + g.x * max_speed)) self.player.position = (x, 32)