Make a Snake Game in Python | Turtle | Python Project - playproduction.de

Make a Snake Game in Python | Turtle | Python Project

Coding With Evan
Views: 44373
Like: 970
How to make a snake game using python. Here we will make the classic snake game with python.

Source Code :

Join our Facebook Group :

Our Instagram :

Our Facebook :
——————————————
Music Credit: Lakeyinspired
Soundcloud:
——————————————

105 Comments

  1. My snake is stuck and is moving very far distances and i cannot do anything after i eat the first red dot my score remains ten and nothing works

  2. whenever i try to make the snake move it does not move and whenever close the game it gives me errors please tell why it is doing this i really want to learn programming

  3. My everything is perfect and my snake is also moving but when touching food it's shape is not increasing so plz any one can help me.

  4. Could somebody explain these lines, please?:
    for i in range(len(segments) – 1, 0, -1):

    x = segments[i – 1].xcor()

    y = segments[i- 1].ycor()

    segments[i].goto(x, y)

    if len(segments) > 0:

    x = head.xcor()

    y = head.ycor()

    segments[0].goto(x, y)

  5. I used THIS code in android 🥲 pydroid i used external keyboard for keys but snake is not moving pls help🤗😭😭

  6. bro my 49 line def is not working because of it .
    what's the solution

  7. It is not working bgcolor screen is only coming

  8. all perfet but my snake is not movig i am pressing W A S D Keywords but no change please help

  9. Bro it is not working with W S A D can you help me

  10. Can you please tell me what should I do it says "AttributeError: 'int' object has no attribute ' speed'

  11. i am very upset that the snake did not move after all this hard work, I needed 4 hours to understand and do the program 🙁

  12. I got a syntax error help!
    x = segments[index-1].xcor()

    ^

  13. I writen all and i will give this code to all plz comment

    #imports

    import turtle

    import time

    import random

    deley = 0.1

    #scores

    score = 0

    high_score = 0

    #set up screen

    wn = turtle.Screen()

    wn.title("Snake Game")

    wn.bgcolor('yellow')

    wn.setup(width=600, height=600)

    wn.tracer=(0)

    #snake head

    head = turtle.Turtle()

    head.speed(0)

    head.shape("square")

    head.color("black")

    head.penup()

    head.goto(0,0)

    head.direction = ("stop")

    #snake food

    food = turtle.Turtle()

    food.speed(0)

    food.shape("square")

    food.color("red")

    food.penup()

    food.goto(0,100)

    segments = []

    #scoreboards

    sc = turtle.Turtle()

    sc.speed(0)

    sc.shape("square")

    sc.color("black")

    sc.penup()

    sc.hideturtle()

    sc.goto(0,260)

    sc.write("score: 0 High score: 0", align = "center", font =("ds-digital", 24, "normal"))

    #Function

    def go_up():

    if head.direction != "down":

    head.direction = "up"

    def go_down():

    if head.direction != "up":

    head.direction = "down"

    def go_left():

    if head.direction != "right":

    head.direction = "left"

    def go_right():

    if head.direction != "left":

    head.direction = "right"

    def move():

    if head.direction == "up":

    y=head.ycor()

    head.sety(y+20)

    if head.direction == "down":

    y=head.ycor()

    head.sety(y-20)

    if head.direction == "left":

    x = head.xcor()

    head.setx(x-20)

    if head.direction == "right":

    x = head.xcor()

    head.setx(x+20)

    #keyboard bindings

    wn.listen()

    wn.onkeypress(go_up, "w")

    wn.onkeypress(go_down, "s")

    wn.onkeypress(go_left, "a")

    wn.onkeypress(go_right, "d")

    #MainLoop

    while True:

    wn.update()

    #check collision with border area

    if head.xcor()>290 or head.xcor()<-290 or head.ycor()>290 or head.ycor()<-290:

    time.sleep(1)

    head.goto(0,0)

    head.direction ="stop"

    #hide the segments of body

    for segment in segments:

    segments.goto(1000,1000) #out of range

    #clear the segments

    segments.clear()

    #reset score

    score=0

    #reset delay

    delay=0.1

    sc.clear()

    sc.write("score: {} High score: {} ".format(score, high_score), align="center",font=("ds-digital", 24, "normal"))

    #cheak collision with food

    if head.distance(food) <20:

    # move the food to random place

    x = random.randint(-290,290)

    y = random.randint(-290,290)

    food.goto(x,y)

    #add a new segment to the head

    new_segment = turtle.Turtle()

    new_segment.speed(0)

    new_segment.shapes("square")

    new_segment.color("black")

    new_segment.penup()

    segments.append(new_segment)

    #shorten the delay

    delay -=0.001

    #increase the score

    score += 10

    if score > high_score:

    high_score = score

    sc.clear()

    sc.write("score: {} High score: {} ".format(score, high_score), align="center",font=("ds-digital", 24, "normal"))

    #move the segments in reverse order

    for index in range(len(segments)-1,0,-1):

    x = segments[index-1].xcor()

    y = segments[index-1].ycor()

    segments[index].goto(x,y)

    #move segments 0 to head

    if len(segments)>0:

    x = head.xcor()

    y = head.ycor()

    segments[0].goto(x,y)

    move()

    #check for collision with body

    for segment in segments:

    if segment.distance(head)<20:

    time.sleep(1)

    head.goto(0,0)

    head.direction = "stop"

    #head segments

    for segment in segments:

    segment.goto(1000,1000)

    segments.clear()

    score = 0

    delay = 0.1

    #update the score

    sc.clear()

    sc.write("score: {} High score: {} ".format(score, high_score), align="center",font=("ds-digital", 24, "normal"))

    time.sleep(delay)

    wn.mainloop()

  14. bruh you put the code in the desription and we can copy it bruh

  15. Bro I need help with line 134 on the code the x has a squiggly red line under it and don’t know how to fix

  16. Hello im having a problem in the line wn.update() it says exception has occurred: terminator X

  17. #imports

    import turtle

    import time

    import random

    delay = 0.1

    #scores

    score = 0

    high_score = 0

    #setup screen

    wn = turtle.screen()

    wn.title("Snake Game")

    wn.bgcolor('yellow')

    wn.setup(width=600, height=600)

    wn.tracer(0)

    #snake head

    head = turtle.turtle()

    head . speed (0)

    head . shape ("square")

    head . color ("blue")

    head . penup()

    head . goto (0,0)

    head . direction = "stop"

    #snake food

    food = turtle.turtle()

    food.speed (0)

    food.shape ("circle")

    food.color ("red")

    food.penup()

    food.goto(0,100)

    segments = []

    #scoreboards

    sc = turtle.turtle()

    sc.speed(0)

    sc.shape = ("square")

    sc.color("black")

    sc.penup()

    sc.hideturtle()

    sc.goto(0,260)

    sc.write("score: 0 High score: 0", align = "center", font=("ds-digital", 24, "normal"))

    #Functions

    def go_up():

    if head.direction != "down":

    head.direction = "up"

    def go_down():

    if head.direction != "up":

    head.direction = "down"

    def go_left():

    if head.direction != "right":

    head.direction = "left"

    def go_right():

    if head.direction != "left":

    head.direction = "right"

    def move():

    if head.direction == "up":

    y = head.ycor()

    head.sety(y+20)

    if head.direction == "down":

    y = head.ycor()

    head.sety(y-20)

    if head.direction == "left":

    x = head.xcor()

    head.setx(x-20)

    if head.direction == "right":

    x = head.xcor()

    head.setx(x+20)

    #keyboard bindings

    wn.listen()

    wn.onkeypress(go_up, "w")

    wn.onkeypress(go_down, "s")

    wn.onkeypress(go_left, "a")

    wn.onkeypress(go_right, "d")

    #MainLoop

    while True:

    wn.update()

    #check collision with border area

    if head.xcor()>290 or head.xcor()<-290 or head.ycor()>290 or head.ycor()<-290:

    time.sleep(1)

    head.goto(0,0)

    head.direction = "stop"

    #hide the segments of body

    for segment in segments:

    segment.goto(1000,1000) #out of range

    #clear the segments

    segments.clear()

    #reset score

    score = 0

    #reset delay

    delay = 0.1

    sc.clear()

    sc.write("score: {} High score: {}".format(score, high_score), align="center", font=("ds-digital", 24, "normal"))

    #check collision with food

    if head.distance(food) <20:

    # move the food to random place

    x = random.randint(-290,290)

    y = random.randint(-290,290)

    food.goto(x,y)

    #add a new segment to the head

    new_segment = turtle.Turtle()

    new_segment.speed(0)

    new_segment.shape("square")

    new_segment.color("black")

    new_segment.penup()

    segments.append(new_segment)

    #shorten the delay

    delay -= 0.001

    #increase the score

    score += 10

    if score > high_score:

    high_score = score

    sc.clear()

    sc.write("score: {} High score: {}".format(score,high_score), align="center", font=("ds-digital", 24, "normal"))

    #move the segments in reverse order

    for index in range(len(segments)-1,0,-1):

    x = segments[index-1].xcor()

    y = segments[index-1].ycor()

    segments[index].goto(x,y)

    #move segment 0 to head

    if len(segments)>0:

    x = head.xcor()

    y = head.ycor()

    segments[0].goto(x,y)

    move()

    #check for collision with body

    for segment in segments:

    if segment.distance(head)<20:

    time.sleep(1)

    head.goto(0,0)

    head.direction = "stop"

    #hide segments

    for segment in segments:

    segment.goto(1000,1000)

    segments.clear()

    score = 0

    delay = 0.1

    #update the score

    sc.clear()

    sc.write("score: {} High score: {}".format(score,high_score), align="center", font=("ds-digital", 24, "normal"))

    time.sleep(delay)

    wn.mainloop()

  18. ☆࿐ཽ༵ⒹⒺⒺⓅⒶⓀ࿐ཽ༵☆

  19. i love this channel .this channel deserves more subs

  20. when i try running th game in vscode the game opens for a split second and then closes. it says "TypeError: turtle.Vec2D() argument after * must be an iterable, not float" can someone help pls

  21. I have some advice that would help the viewers, can u pls run the code after every line so if u see an error, like the snake not moving, u can fix it and we can also learn from it

  22. NO NEED TO RUN THE PROGRAMME IN VS CODE JUST PUT THE CODE IN PTHON 64-BIT THEN THE GAME WILL START AUTOMATICALLY. BY THE WAY THANKS FOR THE CODE BRO.

  23. Hello Evan!!!
    I run the program but snake is not moving…
    Can you figure out this problem?

  24. wn.mainloop() code isn't running even though I aligned it with the while (True): statement
    Pls help!

  25. Also, when my program ends when the head hits the food

  26. everything work find but one thing that I feel almost give up why can't I start to move? I follow ever single code you write and double check it and nothing wring but I just can't move how to fix it

  27. The yellow screen is just visible for a second but i have written the code as it is then why it's not working?

  28. Hello Evan? The snake isn't moving at all. I cross checked the code more
    than three times.

  29. Hello I made this game in pydriod in my android phone and the bug is that the Snake is not moving could you tell me hove to solve this ??

  30. damn its working if fun ….. but there's a problem when i try to go up , it just suddenly close n when i try to go left it's just stop :[ ……. any suggestion ??? wht shoul i do now :[

Leave a Reply

Your email address will not be published.