Exercise 4 · Chapter: One Moving DotRequired+50 XP
Diagonal
Move sideways and downwards at the same time and you get a diagonal. There is no "diagonal" feature — it falls out of doing both.
updateadds1to bothstate["x"]andstate["y"]drawpaints a gold square atgrid[state["y"]][state["x"]]
The test prints both numbers each frame, separated by a slash, so you'll see
them climb together: 1/1, then 2/2, and so on.
Expected output
1/1 2/2 3/3 4/4 5/5
Need a hint?
3 available · costs 5 XP each
python
def update(state, keys):
state["x"] = state["x"] + 1
# The dot only moves sideways. Make it move down too.
return state
def draw(state):
grid = blank_grid()
grid[state["y"]][state["x"]] = "gold"
return grid