Bottom Page

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!
Larz60+ wrote Feb-07-2019, 03:11 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Quote
#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 
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyGame] Game Logic problem with a "The Game of Life" Replication Coda 2 310 Dec-24-2018, 09:26 AM
Last Post: Coda
  [PyGame] Basic Snake game (using OOP) PyAlex 1 560 Sep-10-2018, 09:02 PM
Last Post: Mekire
  [PyGame] Snake not changing directions in Snake Game Bjdamaster 4 524 Aug-13-2018, 05:09 AM
Last Post: Bjdamaster
  [PyGame] Turtle and Pygame together cuevabros 4 779 Jun-27-2018, 03:04 PM
Last Post: cuevabros
  [PyGame] Snake controls not working jakegold98 5 1,058 Dec-12-2017, 01:45 AM
Last Post: Windspar
  Can't make the turtle walk.. Turry 3 1,155 Nov-26-2017, 05:05 PM
Last Post: heiner55

Forum Jump:


Users browsing this thread: 1 Guest(s)