6.3.5 Cmu Cs Academy -
This is where the actual movement happens.
def onStep(app): # If the flag is true, move the shape by a small amount if app.movingRight == True: app.player.centerX += 5if app.movingLeft == True: app.player.centerX -= 5
A common prompt (reconstructed from typical CMU CS Academy content):
"Write a program where a blue circle moves right across the screen. It should stop when its center reaches
x = 300. Use awhileloop insideonStepor a custom function. Ensure the loop doesn't freeze the program." 6.3.5 Cmu Cs Academy
Constraints:
If you only use onKeyPress, your shape will move once, pause, and then move again (because of the computer's key-repeat delay). This feels "jerky."
The Solution: You need a helper variable (Boolean) to track if the key is held down. This is where the actual movement happens
Error: Using range(rows-1) or range(1, rows).
Result: Missing the first or last row/column.
Fix: Always use range(rows) and range(cols) for full coverage.
In the real world, the pattern you learn in 6.3.5 is everywhere: A common prompt (reconstructed from typical CMU CS
Understanding onKeyPress and global state is your first step toward building a playable game in CMU CS Academy—like a simple maze or a "catch the falling objects" game.