![]() We use the functions turtle_name.goto() and turtle_name.direction() for it. I want my snakehead’s position to be the center of the window and the direction to be “stop”. We use the functions turtle_name.shape() and turtle_lor().ĭo we need to draw the paths taken by the snake? No! The function turtle_name.penup() makes sure that the path taken by the snake is not drawn. Next, we need to initialize the head shape and color. We use the function turtle_name.speed() for this. Create a turtle with the function turtle.Turtle() and assign it the name head. We set the head speed to 0 as we’re just initializing in this section and the head does not need to move. Snake is basically a turtle(in python language) that moves around. Once you’ve created the window, the next thing we need is a snakehead. We do not need any screen updates other than the scoreboard and hence set to 0. The function acer() turns off the screen updates. Set the window height and width with the function tup(width=X, height=Y). Set the background color for the window with the function window.bgcolor(“Color”). Give this window a name with the function window.title(“Kalgi’s Snake Game”). In this case, our window is win for the game. The function turtle.Screen() is used to create a window. To start using the module, you need to import it like any other module in python. On an obvious note, the player needs to win and hence avoid dying. The snake dies if it touches its own body or the boundaries of the window. The player has to move the snake such that it touches(eats) the food and grows in size. There are two elements in this game – snake and food. Let’s understand this game before we start building. I have used P圜harm with Python version 2.7 for this article. Let’s move ahead and start building the game.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |