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:
——————————————

119 Comments

  1. Please help me, can someone tell me why the snake game what I made doesn't move? I had press (W A S D) but still can move😭

  2. 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

  3. 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

  4. 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.

  5. 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)

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

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

  8. It is not working bgcolor screen is only coming

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

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

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

  12. 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 🙁

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

    ^

  14. 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()

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

  16. 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

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

  18. #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()

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

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

  21. 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

  22. 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

  23. 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.

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

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

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

  27. 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

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

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

  30. 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 ??

Leave a Reply

Your email address will not be published.