Creating Snake game in Turtle - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: Creating Snake game in Turtle (/thread-15949.html) |
Creating Snake game in Turtle - Shadower - Feb-07-2019 Hello all, I am creating a snake game with Python, in Turtle. For this project, I am using this video: https://www.youtube.com/watch?v=rrOqlfMujqQ&ab_channel=ChristianThompson The code I wrote is: https://pastebin.com/hAJhqu29 And the error I am getting is: raise Terminator turtle.Terminator I tried looking online but I couldn't find help. BTW- I am not using Pygame on purpose, since I am still a beginner and I want to learn the "basics". Thanks in advance for your reply! RE: Creating Snake game in Turtle - woooee - Feb-11-2019 You don't ever move the object. Take a look at the goto() function in the docs. Also, your variables are local to the functions, so x, y, and head.direction are garbage collected when the function exits and so the code calling these functions never has access to any changes, i.e. if the object was moving, it would move to the same place; see this link on passing variable to, and returning them from a function http://www.tutorialspoint.com/python/python_functions.htm A test program from my toolbox that could use some modifications from turtle import * from random import * import time setup(600,500) maxx = 300 maxy = 250 minx= -maxx miny= - maxy title ("shooting ball") bgcolor('grey') ball=Turtle() ball.penup() ball.shape("circle") ball.shapesize(3,3,3) ball.color("blue") bounce_point = 20 x = randint(minx + bounce_point, maxx + bounce_point) y = randint(miny + bounce_point, maxy + bounce_point) ball.goto(x,y) ball.showturtle() dx = 10 dy = 10 ctr = 0 while ctr < 200: ## set a reasonable limit ctr += 1 xx = x + dx ## test for sides of bounding box ## and reverse direction if found if xx < minx+bounce_point: xx = minx + bounce_point dx = -dx if xx > maxx - bounce_point: xx = maxx- bounce_point dx = -dx yy=y+dy if yy < miny + bounce_point: yy= miny + bounce_point dy = -dy if xx > maxx - bounce_point: xx = maxx- bounce_point dx = -dx yy=y+dy if yy < miny + bounce_point: yy= miny + bounce_point dy = -dy if yy > maxy + bounce_point: yy = maxy + bounce_point dy = -dy x = xx y = yy ball.goto(x,y) time.sleep(0.01) ## allow time for a screen update |