From the course: Building the Classic Snake Game with Python
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Controlling the snake's direction - Python Tutorial
From the course: Building the Classic Snake Game with Python
Controlling the snake's direction
- We're now going to look at how to control the snake's direction. Controlling the snake's direction involves diving into the concept of events and event callback functions. Before getting into that though, we first need to create two new variables. One is a global variable called snake directions. The other is a Python dictionary containing offsets which determine how much the snake moves in each direction. So let's do that now. So let's put our offsets up here at the top along with our constants, even though it's not technically a constant because of the dictionary. Offsets equals a dictionary and it's going to have up. It's going to give us an offset of 0,20, because that's plus twenty in the Y-direction. Down is going to give us an offset of 0 and minus twenty or negative twenty. And left will give us an offset of negative 20,0. Zero for the y, negative twenty for the x. And then right is going to give us an offset of 20,0. Okay, so that's our offsets. Then this snake direction…