Python Forum
Creating Snake game in Turtle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Snake game in Turtle
#1
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=rrOqlfMu...anThompson

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!
Reply
#2
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/pyt...ctions.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 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to add segments to the snake body blacklight 1 2,869 Sep-13-2023, 07:33 AM
Last Post: angelabarrios
  [PyGame] Snake game: how to get an instance for my snake's body multiple times? hajebazil 2 2,139 Jan-30-2022, 04:58 AM
Last Post: hajebazil
  Dugeon maze game with turtle module. Newbie1114 3 3,332 Jun-15-2021, 03:11 AM
Last Post: stephen645
  Creating a “Player” class, and then importing it into game onizuka 4 3,037 Sep-01-2020, 06:06 PM
Last Post: onizuka
  help with snake game blacklight 3 2,594 Jul-30-2020, 01:13 AM
Last Post: nilamo
  Snake Game - obstacle problem Samira 3 5,597 Oct-31-2019, 02:58 PM
Last Post: Samira
  [PyGame] Creating "saves" for the game subject71 2 2,174 Oct-29-2019, 11:31 AM
Last Post: Zman350x
  [PyGame] Made my first Python program: Snake. Please help me improve it andrerocha1998 7 6,134 Feb-19-2019, 07:08 PM
Last Post: Windspar
  [PyGame] Basic Snake game (using OOP) PyAlex 1 12,529 Sep-10-2018, 09:02 PM
Last Post: Mekire
  [PyGame] Snake not changing directions in Snake Game Bjdamaster 4 4,928 Aug-13-2018, 05:09 AM
Last Post: Bjdamaster

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020