Python Game Programming Tutorial: Snake Game Part 4

  Рет қаралды 85,138

TokyoEdtech

TokyoEdtech

Күн бұрын

Пікірлер: 691
@aafiyamemon9535
@aafiyamemon9535 4 жыл бұрын
you deserve more subscribers, the way you explain is really awesome!
@robertlouis5721
@robertlouis5721 4 жыл бұрын
Your videos are simply phenomenal as they offer the viewer the opportunity to learn complex systems that could improve an understanding of coding. Thank you for taking the time to make these tutorials.
@cyndinorwood7841
@cyndinorwood7841 5 жыл бұрын
Just an FYI for the #Move the end segments first in reverse order. I changed the 0 to a -1 to get rid of the grey segment that was appearing after I ran the program each time. So if you see this, the way to fix it is to change this line here for index in range(len(segments)-1, 0, -1) .....change the 0 to a -1 This is an excellent tutorial Christian Thompson.
@Ajajqiqjaa
@Ajajqiqjaa 3 жыл бұрын
So so so detailed and I love the way you break a game into bite-size chunks so it's easier for ADHD-affected people like me!!!!!!!!!!!!!
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Thanks - keep on codin'!
@BananaDope
@BananaDope 2 ай бұрын
Hey, I'm a little late but at 6:45 you said you will post in the comments the link of your video about loops and that we should remind you if you forgot.
@TokyoEdTech
@TokyoEdTech 2 ай бұрын
@@BananaDope Here you go: kzbin.info/www/bejne/poeZk56hZrqrf5osi=slfzrgDQm7D0jv4V Thanks for the reminder!
@Ajajqiqjaa
@Ajajqiqjaa 3 жыл бұрын
the parts are divided so incredibly insightful - different part of the games and it is explain with so much details!
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Thanks - I try. :)
@idkhow9603
@idkhow9603 5 жыл бұрын
this is the best tutorial i have seen so far. Thanks so much
@cartoonpage9696
@cartoonpage9696 4 жыл бұрын
This is the best tutorial in KZbin I ever seen..
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Thanks!
@SenseiEli
@SenseiEli 4 жыл бұрын
Wrote all till now works perfect! Next I will build my own game! Thank you!
@thelolgamer612
@thelolgamer612 4 жыл бұрын
I think it is better to use: if head.distance(food) < 20: x = random.randrange(-280, 280, 20) y = random.randrange(-280, 280, 20) food.goto(x, y) this way the food spawn in the path of the snake
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Great tip - thanks!
@arin2442
@arin2442 4 жыл бұрын
I have a slight problem at 3:00.. When I typed in the code new_segment.speed(0), python tells me that it is an attribute error. When ever my black square touches the red circle, the game just stops and it shows me Attribute error. What should I do?
@beetal3850
@beetal3850 4 жыл бұрын
this is awesome! Im thinking about adding other things to it like new fruits that are harder to eat and so on! Im actually pretty good with python.
@vaishalirawal9140
@vaishalirawal9140 4 жыл бұрын
You are a very good teacher... Love from India🇮🇳🇮🇳
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Thank you!
@Ph34dz
@Ph34dz 6 жыл бұрын
There is no good talkthrough like this in any other language, i looked up in every language to find out how it works, and there is none that explains as well as this guy. Im doing this in c++, but the thought process is same as in Python :D
@darkknight-r4g
@darkknight-r4g Ай бұрын
the snake grow bigger everytime it moves .it is not forming a single single segment .here is the code import turtle import time import random delay = 0.1 wn = turtle.Screen() wn.title("Snake game by @Aryan") wn.bgcolor("grey") wn.setup(width = 600 , height = 600) wn.tracer(0) head = turtle.Turtle() head.speed(0) head.shape("square") head.color("black") head.penup() head.goto(0,0) head.direction = "stop" food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("blue") food.penup() food.goto(0,100) segments = [] def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_right(): head.direction = "right" def go_left(): head.direction = "left" 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 == "right": x = head.xcor() head.setx(x + 20) if head.direction == "left": x = head.xcor() head.setx(x - 20) wn.listen() wn.onkeypress(go_up,"w") wn.onkeypress(go_down,"s") wn.onkeypress(go_right,"d") wn.onkeypress(go_left,"a") while True: wn.update() if head.distance(food) < 20: x = random.randint(-290,290) y = random.randint(-290,290) food.goto(x,y) new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("brown") new_segment.penup() segments.append(new_segment) for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycor() segments[index].goto(x, y) if len(segments)>0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() time.sleep(delay) wn.mainloop()
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@darkknight-r4g The new segment section needs to be indented one more level.
@leonmeister8037
@leonmeister8037 6 жыл бұрын
Just a reminder that you wanted to link your Python 3 basics in the comments!
@KabeerSehgal01
@KabeerSehgal01 6 жыл бұрын
You can explain super good! :)
@JanMarsalekWirecard
@JanMarsalekWirecard 5 жыл бұрын
9:33 it is not runking for me, the grey part is still in the middle, help me please
@ethanreed2672
@ethanreed2672 5 жыл бұрын
# Simple Snake Game in Python 3 for Beginners # By @TokyoEdTech import turtle import time import random delay = 0.1 # Set up the screen wn = turtle.Screen() wn.title("Snake Game by @TokyoEdTech") wn.bgcolor("green") wn.setup(width=600, height=600) wn.tracer(0) # Turns off the screen updates # Snake head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("black") head.penup() head.goto(0,0) head.direction = "stop" # Food food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("red") food.penup() food.goto(0,100) segments = [] # 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") # Main game loop while True: wn.update() # Check for a collision with the food if head.distance(food) < 20: # Move the food to a random spot x = random.randint(-290,290) y = random.randint(-290, 290) food.goto(x, y) # Add a segments new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment) # Move the end segments first 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 where the head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() time.sleep(delay) wn.mainloop() I hope this can help! Just copy and paste the parts of your code that MIGHT be broken
@mobzblizzard797
@mobzblizzard797 5 жыл бұрын
you mentioned there was an alternative method to create the segments by using a temp variable, is that method easier than this? And if so, could u explain how to do that method?
@harikalatheeswaran9206
@harikalatheeswaran9206 4 жыл бұрын
Amazing tutorial ! Tried pendown() for every turtle object and the patterns created were very mesmerising ! This tutorial gives me new ideas to create different games. Thanks a lot for this tutorial !
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Glad it helped!
4 жыл бұрын
next step add snake in neural network to teach play by it self ! please make tutoral
@00wx
@00wx 4 жыл бұрын
Please help, when my snake eats, the food just doesnt connect with snake
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
There is a link in the description labeled “NEED HELP?” Check that out and get back to me. Keep on codin’!
@manaser02
@manaser02 4 жыл бұрын
This is a clear tutorial. But my segments draw on the screen as you mentioned it does not draw on the screen 2:12 if put in the command new_segment.penup() . Please help me with this
@manaser02
@manaser02 4 жыл бұрын
@@TokyoEdTech Thanks
@rexpetrie9659
@rexpetrie9659 5 жыл бұрын
after 8:20 seconds of the video when i run my code, I cant move the snake anymore? Heres my code: import turtle import time import random delay = 0.1 #screen setup wn = turtle.Screen() wn.title("Snake") wn.bgcolor("green") 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" #Apple apple = turtle.Turtle() apple.speed(0) apple.shape("circle") apple.color("red") apple.penup() apple.goto(0, 100) segments = [] #functions def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_left(): head.direction = "left" def go_right(): 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") #main game loop while True: wn.update() if head.distance(apple) < 20: x = random.randint(-290,290) y = random.randint(-290, 290) apple.goto(x,y) new_segment=turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("black") new_segment.penup() segments.append(new_segment) for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycor() segments[index].goto(x, y) if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x, y) move() time.sleep(delay) wn.mainloop()
@rexpetrie9659
@rexpetrie9659 5 жыл бұрын
@@TokyoEdTech Here you go pastebin.com/hnX6Z38u
@minonakura8858
@minonakura8858 6 жыл бұрын
Do you mind explaining to me why the body parts don't just stack on top of the head? doesn't setting X and Y to the head.x/ycor() mean that the body parts are at the same coordinates as the head?
@genericgraphix7229
@genericgraphix7229 5 жыл бұрын
Mine doesn't stick at all
@葉孟韋-u1c
@葉孟韋-u1c 5 жыл бұрын
I am confused about line 85.Knowing that while loop will repeat again and again , why dont the statement "new_segment =turtle.Turtle "defined again and again .
@葉孟韋-u1c
@葉孟韋-u1c 5 жыл бұрын
@@TokyoEdTechI learn c++ before ,and find that there is a little difference between two languges.In my opinion i thought that new_segment is 'local variable' ."new_segment =turtle .Turtle( )" is included in the if statement. Once the program jump out of the if statement, if new_segment still be valid?
@reeddhimansaha2782
@reeddhimansaha2782 4 жыл бұрын
I followed the tutorial exactly. Whenever the snake hits the food, the segment does not get appended to the snake head. It remains there itself and food changes its color to grey. Can you please help out with that?
@bernardbeinhauer9528
@bernardbeinhauer9528 6 жыл бұрын
Hello, I have a trouble understanding this piece of code, how it actually works : for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycor() segments[index-1].goto(x, y) could you please explain it in details so I get what's going on? Thanks in advance! :)
@bernardbeinhauer9528
@bernardbeinhauer9528 6 жыл бұрын
@@TokyoEdTech Oh, got it. Thank you!
@adlifiruz808
@adlifiruz808 3 жыл бұрын
hmmm, same here. Do you know how it works?
@Pancakeplanet
@Pancakeplanet 6 жыл бұрын
Hey! So how would i go about changing the snake's head/body/food with a jpeg? Would this be too complicated to a beginner or?
@LaMalo17
@LaMalo17 2 күн бұрын
I'm trying to move the head for 2 pixels instead of 20, but the tail is then only adding up behind the head by only 2 pixels instead of the size of the head (20 pixels). Can u tell me what should I change?
@kidskpadonou894
@kidskpadonou894 4 жыл бұрын
Thanks for the vids, Christian! Okay now here's my problem. Whenever my worm(what i called my snake) touches his food, the program just closes. I would really appreciate if you told me why that could happen. Please make it simple.
@HELLFIRE0239
@HELLFIRE0239 3 жыл бұрын
Hello, thanks for this helpful tutorial but I really didn't understand the code after 3:40, you explained it very fast :/ Why did you put a "-1, 0, -1"? is the x/y coordinate just (amount of segments -1)?
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
It is the index of the given segment. Here's how it works. The head moves AFTER the body segments move - this is key. Let's say you have a snake and it is moving right. It has a head and two body segments: S - S - H We move from the end to the front like so (Note there is overlap so I'm showing the moving segment on top): S - H
@mohamedirsathabdulazeez3610
@mohamedirsathabdulazeez3610 6 жыл бұрын
Hey I have a doubt.when the head take the first food, segments [0] is replacing the head.Can you explain on this.The code says to move the firs segment to where the head positioned.Iam confused
@mohamedirsathabdulazeez3610
@mohamedirsathabdulazeez3610 6 жыл бұрын
Christian Thompson thanks
@jimmyyyy235
@jimmyyyy235 5 жыл бұрын
@@TokyoEdTech can you tell me how to do this pls
@marshall_10389
@marshall_10389 2 ай бұрын
when i run it says unindent does not match any outer indentation level
@marshall_10389
@marshall_10389 2 ай бұрын
and its the line where it says for index in range(len(segments)- 1, 0, -1):
@TokyoEdTech
@TokyoEdTech 2 ай бұрын
@@marshall_10389 Can you share your code so I can take a look?
@minyminnos5518
@minyminnos5518 4 жыл бұрын
SIR I AM SO THANKFUL FOR THIS VIDEO. IT HELPS MY SCHOOL PROJECT. LOVE YA
@ofpqo3951
@ofpqo3951 4 жыл бұрын
Hi Christian! I'm an absolute beginner in Python and I've been loving your videos. Though, I'm afraid there's a teeny weeny problem. While writing one of the codes, I got what you programmers call an unprintable characters, and despite of all the solutions I've read I still can't seem to remove it and it's holding me down. Please respond ASAP! Thanks!
@ghosttm3823
@ghosttm3823 6 ай бұрын
I wanted to ask you how I can configure the same element that is food but it takes away your body, it does nothing for the score and you can continue playing until you play it again with your head without having a body, any idea on how to configure it, I am very new to this
@TokyoEdTech
@TokyoEdTech 6 ай бұрын
It's not super complicated - you need to add the item; basically do the same thing you did with the food. When you collide you need to move the last segment off the screen and remove it from the body. It would be something like: segments[-1].goto(1000, 1000) del segments[-1] Hopefully that will point you in the right direction.
@rayhanali1078
@rayhanali1078 3 жыл бұрын
Hi, my problem is that it keeps on popping up with a message saying 'unindent does not match any outer indentation level'. I'm not sure what's wrong with it.
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Here’s a video on indentation errors which you may find helpful. kzbin.info/www/bejne/Y2fNhHygfZaYaa8
@rayhanali1078
@rayhanali1078 3 жыл бұрын
@@TokyoEdTech Thank you so much
@yephoppler
@yephoppler 3 жыл бұрын
when the snake eats the food there will be a new segment but there's a trail following it for some reason pls help idk if i missed something edit: nevermind i found the problem, i forgot the penup lol, thanks
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Glad you got it sorted - keep on codin'!
@major268
@major268 3 жыл бұрын
the game crashes everytime there snake collides with the food and my body does not grow import turtle import time import random delay = 0.1 #Score score = 0 high_score = 0 #setup screen wn = turtle.Screen() wn.title("Snake game by Hloho") wn.bgcolor("black") wn.setup(width=600, height=600) wn.tracer(0) #turns off screen update #snake head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("white") 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 = [] #Pen pen = turtle.Turtle() pen.speed(0) pen.shape("square") pen.color("white") pen.penup() pen.hideturtle() pen.goto(0, 260) pen.write("Score :0 High Score :0",align="center",font=("Arial", 24,"normal")) 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" #function def move(): if head.direction == "up": y = head.ycor() #current turtle cordinate head.sety(y + 20) if head.direction == "down": y = head.ycor() #current turtle cordinate head.sety(y - 20) if head.direction == "left": x = head.xcor() #current turtle cordinate head.setx(x - 20) if head.direction == "right": x = head.xcor() #current turtle cordinate head.setx(x + 20) #keyboard bindings wn.listen() #listen for key press wn.onkeypress(go_up, "Up") wn.onkeypress(go_down, "Down") wn.onkeypress(go_left, "Left") wn.onkeypress(go_right, "Right") #main game loop while True: wn.update() #check for collision with the board if head.xcor()>290 or head.xcor()290 or head.ycor() high_score: high_score = score pen.clear() pen.write("Score :{} High Score :{}".format(score,high_score),align="center",font=("Courier", 24,"normal")) #move the end segments first with 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) #segments 0 moves with the head if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) #check for collision with the snake body for segment in segments: if segment.distance(head) < 20: time.sleep(1) head.goto(0,0) head.direction = "stop" for segment in segments: segment.goto(1000,1000) #clear segments list segments.clear() #reset score score = 0 #reset delay delay = 0.1 #update score reset pen.clear() pen.write("Score :{} High Score :{}".format(score,high_score),align="center",font=("Courier", 24,"normal")) move() time.sleep(d
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Hiya - move() Must go before the section that says "#check for collision with snake body"
@major268
@major268 3 жыл бұрын
It's working thanks
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
@@major268 You're welcome - keep on codin'!
@darksoulcreeper7954
@darksoulcreeper7954 4 жыл бұрын
When the snake eats the 1st food the segment is left at the centre , but after eating the 2nd food the segments joins! Why??? I checked the codes, but they were fine!
@danielgalamas2057
@danielgalamas2057 4 жыл бұрын
I NEED HELP i did all the coding correctly but when i test it my snake only eats one piece of food then when he eats his 2nd one everything just freezes
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
If you did everything correctly, it would probably work as expected - coding is very touchy and small errors matter greatly. There is a link in the description labeled “NEED HELP?” Check that out and get back to me. Keep on codin’!
@EthanJbleethan
@EthanJbleethan 4 жыл бұрын
I am getting this error Line 111, in for index in range(Len(segments)-1, 0, -1): TypeError: object of type 'Turtle' has no Len() Plz help
@EthanJbleethan
@EthanJbleethan 4 жыл бұрын
@@TokyoEdTech do I have to write all of the code in postbin or can I just write the part that I think messes up the code? And btw thank you a lot
@EthanJbleethan
@EthanJbleethan 4 жыл бұрын
Oops, found out the error. In the hide segments part of the next video, instead of putting for segment in segments, I put for segments in segments. I am still very greatful of you giving me advice and for that I gave you a sub, like and I put notifs on. Love you
@questionmarkquestionmarkques
@questionmarkquestionmarkques 3 жыл бұрын
you are a fantastic teacher, thanks so much for this series
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Thanks - keep on codin'!
@ethanreed2672
@ethanreed2672 5 жыл бұрын
I've noticed that the food isn't always snapped to the grid because, it's on a random coordinate and not something like "25, 25" it's can end up on random coordinate like "348, 321" so, I was wondering if there was/is a way to change this? Maybe use an "if" statement? I'm not sure.
@ethanreed2672
@ethanreed2672 5 жыл бұрын
@@TokyoEdTech Thanks!
@jedicubing4771
@jedicubing4771 3 жыл бұрын
9:49 says "Hope you join me for "Part 4" Problem, this is part 4 XD
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Oops! Glad you were paying close attention!
@ThoughtfulSummit
@ThoughtfulSummit 4 жыл бұрын
Please tell me, are you looking at written down code on a notebook or document or something, or do you just know all of this code from memory. Because I'm thinking of becoming a programmer, but i have a shit memory.
@pallepuaruna6970
@pallepuaruna6970 4 жыл бұрын
This is the best thing I have ever seen
@kurawtw
@kurawtw 4 жыл бұрын
@TokyoEdTech , Its actually working now. it was a indentation problem. anyway, your the only youtube that actually answers comments. thanks man! keep up this miracle work.
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Glad you got it sorted. I try to answer as many comments as possible, but I do miss some here and there. Keep on codin'!
@ohful
@ohful 5 жыл бұрын
When the game starts my snake already has an extra segment and when I run into the food the new segments go to the middle. I don't know what I'm doing wrong so it would be great if you could help me.
@sivasurya4149
@sivasurya4149 4 жыл бұрын
Could u please explain why u red that 9 in 5:34. segment has zero
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
???
@sivasurya4149
@sivasurya4149 4 жыл бұрын
I try to hard but to difficult to understand reverse process....
@quynhnhupham7180
@quynhnhupham7180 5 жыл бұрын
why we need to move the end segment to the first segment ??? i do not understand. And Why we it is the index-1 instead of the index?
@rohaannz6606
@rohaannz6606 4 жыл бұрын
hi, Christian, your tutorials are the best but I don't know why when I eat the food the segment appears in the middle then when i eat the second one it joins my body can you please explain
@cevinsamuel
@cevinsamuel 6 жыл бұрын
Mine, when the head once touch the food, the program immediately stops. Why ?
@frankiemilson1540
@frankiemilson1540 5 жыл бұрын
There is no error message for me and I did the same code in the same order as you but when my snake eats the food the the extra segment for the snake spawns in the middle of the screen, please help.
@karls4934
@karls4934 3 жыл бұрын
how do i add another food object that make the body segment loose 1 segment when consumed.
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Which part do you need help with? Adding another food object, or removing a segment?
@karls4934
@karls4934 3 жыл бұрын
@@TokyoEdTech removing a segment
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
@@karls4934 Thanks - that was an important detail to have left out. Try this: # Move the last segment off the screen segments[-1].goto(1000, 1000) # Remove it from the list segments.remove(segments[-1]) That should do it - I wrote that from memory, so if it doesn't work, let me know.
@ssayorr
@ssayorr 3 жыл бұрын
@@TokyoEdTech what if he wants to do both like make a new 'posionus' food that makes you lose a segment i guess just make a new turtle and then when it collisions with head you the line you gave? i do not know the code but id guess it is like food
@im_dalton_297
@im_dalton_297 4 жыл бұрын
when i get one apple and i go to get the other one as soon as it hits it the programs closes
@im_dalton_297
@im_dalton_297 4 жыл бұрын
import os import turtle import time import random delay = 0.1 # Set up screen wn = turtle.Screen() wn.title("Snake game") wn.bgcolor("green") wn.setup(width=600, height=600) wn.tracer(0) #turns off sceen updates # 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("circle") food.color("red") food.penup() food.goto(0,100) segments = [] # Functions def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_left(): head.direction = "left" def go_right(): 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") # Main game loop while True: wn.update() # check for a collision with the food if head.distance(food) < 20: # Move food to random spot on screen x = random.randint(-290,290) y = random.randint(-290, 290) food.goto(x,y) # Add a segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment) # Move the end segments first in reverse order for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycore() segments[index].goto(x, y) # Move segment 0 to where the head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() time.sleep(delay) wn.mainloop()
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Read the error message - the problem is obvious: Traceback (most recent call last): File "snake.py", line 189, in y = segments[index-1].ycore() AttributeError: 'Turtle' object has no attribute 'ycore' It tells you the EXACT problem and the EXACT line where the problem is.
@im_dalton_297
@im_dalton_297 4 жыл бұрын
@@TokyoEdTech i figured it out
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
@@im_dalton_297 Good to hear! And, you're welcome.
@ha3la982
@ha3la982 4 жыл бұрын
The segments appear on the head once the snake eats the food...Please help
@Jiggly12
@Jiggly12 4 жыл бұрын
my game doesnt add the segment when i touch the food but adds it when i spawn in and this is the code (i know i havent completed it yet but im trying to work this out first.) import turtle import time import random delay = 0.07 #Screen wn = turtle.Screen() wn.title("Snake Game By Basel Waiel") wn.bgcolor("blue") 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("circle") food.color("white") food.penup() food.goto(0, 100) segments = [] #functions def go_up (): head.direction = "up" def go_down (): head.direction = "down" def go_right (): head.direction = "right" def go_left (): head.direction = "left" 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 == "right": x = head.xcor() head.setx(x + 20) if head.direction == "left": x = head.xcor() head.setx(x - 20) #binds wn.listen() wn.onkeypress(go_up, "w") wn.onkeypress(go_down, "s") wn.onkeypress(go_left, "a") wn.onkeypress(go_right, "d") # Main Game Loop while True: wn.update() if head.distance(food) < 20: x = random.randint (-290, 290) y = random.randint (-290, 290) food.goto(x, y) #segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") segments.append(new_segment) move() time.sleep(delay) wn.mainloop()
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Check your indentation.
@catsonair9432
@catsonair9432 6 жыл бұрын
Hey could you exsplain a little more the line, for element in range(len(segments) -1, 0, -1): and what the whole line means with the numbers at the end a little more in-depth thanks
@AbdullahKhalil-k5v
@AbdullahKhalil-k5v 3 ай бұрын
hi my snake is leaving a line behinde it after adding segments
@TokyoEdTech
@TokyoEdTech 3 ай бұрын
@@AbdullahKhalil-k5v Can you share the code and I'll take a look?
@samimsheikh962
@samimsheikh962 4 жыл бұрын
Hey Chris ! I am having no issues so far.... just want to know how to reduce the size of my food by 10 pixels( you mentioed about shape pixels earlier )
@potto1488
@potto1488 5 жыл бұрын
At xcor I keep getting syntax errors?
@stnldvs
@stnldvs 5 жыл бұрын
on the line if len(segments) > 0: it says i have a syntax error and highlights the colon
@SaazGamingChannel
@SaazGamingChannel 4 жыл бұрын
Grey segment appears on top of the head segment and is leaving grey trails even when I coded the pen to be up...any fixes?? Would appreciate if you looked through the code :) Snake Game (First Ever Game!) import turtle import time import random delay = 0.125 win = turtle.Screen() win.title("Snake Game by Max Sarris") win.bgcolor("green") win.setup(width=600, height=600) win.tracer(0) #turns off screen updates :( # 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 (points) food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("red") food.penup() food.goto(0,100) segments = [] # Functions def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_left(): head.direction = "left" def go_right(): 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 win.listen() win.onkeypress(go_up, "w") win.onkeypress(go_down, "s") win.onkeypress(go_left, "a") win.onkeypress(go_right, "d") # Main Game Loop while True: win.update() # Check for collision with food if head.distance(food) < 20: x = random.randint(-290,290) y = random.randint(-290,290) food.goto(x,y) # Add a new segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment) # Move the end segments first 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 where the head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() time.sleep(delay) win.mainloop()
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
This section needs to be indented one more level: # Add a new segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment)
@SaazGamingChannel
@SaazGamingChannel 4 жыл бұрын
@@TokyoEdTech thanks bro, I also added a separate multiplayer scoring system for the second player...was just wondering how you can set an icon for the game
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
@@SaazGamingChannel Cool! I think that is OS dependent. If you want to make a standalone program check out pyfreeze or py2exe, or py2app.
@logandukes5984
@logandukes5984 4 жыл бұрын
anyone else having a problem with the body just making more turtles as soon as you spawn in and youre essentially just drawing a line with your snake. I checked the code and I really have no idea what is wrong I have my penup on the segment turtle and I am really confused
@logandukes5984
@logandukes5984 4 жыл бұрын
@@TokyoEdTech finally figured it out after a long long time of staring at code. my #add segment line of code wasnt indented to only happen if the if statement is true so it was just adding segments every time it moved which resulted in basically a non stop drawing pen
@VAMSIKRISHNA-fs3ff
@VAMSIKRISHNA-fs3ff 4 жыл бұрын
@Logan May be u r missing pen up for the new segment u r creating
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Yeah, indentation will kill you!
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Glad you figured it out!
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Could be lots of things!
@wzards3529
@wzards3529 6 жыл бұрын
Are you using sublime text? How do you set it up to run python code? I've never been able to run game programs through it.
@ryuujianselmoong6753
@ryuujianselmoong6753 2 жыл бұрын
hi @TokyoEdtech the segmentspart is not working its just in the middle when i press play not when i collect food idk why here is the code: import turtle import time import random delay = 0.1 wn = turtle.Screen() wn.setup(width=600, height=600) wn.bgcolor("black") wn.tracer(0) head = turtle.Turtle() head.speed(0) head.shape("square") head.color("green") head.penup() head.goto(0, 0) head.direction = "stop" food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("red") food.penup() segments = [] def go_up(): head.direction = "up" def go_down(): head.direction = "down" def right(): head.direction = "right" def left(): head.direction = "left" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 8) if head.direction == "down": y = head.ycor() head.sety(y - 8) if head.direction == "right": x = head.xcor() head.setx(x + 8) if head.direction == "left": x = head.xcor() head.setx(x - 8) wn.listen() wn.onkeypress(go_up, "Up") wn.onkeypress(go_down, "Down") wn.onkeypress(right, "Right") wn.onkeypress(left, "Left") while True: wn.update() if head.distance(food) < 20: x = random.randint(-290, 290) y = random.randint(-290,290) food.goto(x, y) new_segments = turtle.Turtle() new_segments.speed(0) new_segments.shape("triangle") new_segments.color("green") new_segments.penup() segments.append(new_segments) move() time.sleep(delay) wn.mainloop()
@VedicGemstoneTherapy1027
@VedicGemstoneTherapy1027 5 жыл бұрын
The body of the snake keeps growing even when it doesn't touch the food..plz help....it just keeps on growning long and long rapidly...plz help
@blueskull5529
@blueskull5529 5 жыл бұрын
Same
@fieerce9803
@fieerce9803 4 жыл бұрын
Hi when i do this code the segment is laready there before i intersect the food.
@SquidWRLD
@SquidWRLD 4 жыл бұрын
Hello so it all worked fine but once the head started moving it constantly grew without stopping so i would have a long line from the beginning to the end. How can i fix this and if i need to show you the code how do i do that ( btw great video your like the only python tutorial maker who can explain stuff with out making my brain run at max capacity)
@TauseefKhan-or2yr
@TauseefKhan-or2yr 5 жыл бұрын
no error showing, running perfectly, but i think the penup() function not working , whenever i run the segment drow all over my screen .. please help me.
@TauseefKhan-or2yr
@TauseefKhan-or2yr 5 жыл бұрын
the gray part of the game are drown all over the screen, wherever the head moving ..
@c14aryanpatyal93
@c14aryanpatyal93 6 жыл бұрын
if we reduce the speed then the segments[0] takes the place of head please help me on resolving this issue
@maxbleakley3241
@maxbleakley3241 5 жыл бұрын
Hi, i don't get an error but whenever i get the food the first time it doesn't add it, but the second time i get the food it adds it on
@darshilchitranshi592
@darshilchitranshi592 4 жыл бұрын
I am getting:- on the line new_segment = turtle.Turtle() ^ TabError : incosistent use of tabs and spaces in indentation PLEASE HELP ME !!!
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Chill. You are mixing tabs and spaces. You can only use one or the other.
@darshilchitranshi592
@darshilchitranshi592 4 жыл бұрын
@@TokyoEdTech Thanks for the reply..... Can you please elaborate and rewrite the error... I am a beginner with very less knowledge about python...
@mayursanghvi5480
@mayursanghvi5480 4 жыл бұрын
@@darshilchitranshi592 Try and align that line with the others
@darshilchitranshi592
@darshilchitranshi592 4 жыл бұрын
@@mayursanghvi5480 Thanks..
@mayursanghvi5480
@mayursanghvi5480 4 жыл бұрын
@@darshilchitranshi592 you can watch his video on indentation error
@halladaas9915
@halladaas9915 4 жыл бұрын
thank you soo much, that was really cool. I don't understand how the body moves when we set the segments to go to the x and y coordinates of the other segments. I mean, won't all the segments and the head be on the same place??
@halladaas9915
@halladaas9915 4 жыл бұрын
@@TokyoEdTech oooh makes sense. So if we start all the way from the head to the tail and we set the coordinates of a segment to be that of segment + 1 rather than segment - 1, would the game work properly and function the same way?
@merolekenola2122
@merolekenola2122 4 жыл бұрын
Hi, thanks for the great tutorial! I was wondering why do you move every single segment instead of only moving the last element to the position of the head when you wanna move the snake forward? Thanks in advance for your explanation :)
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Hiya - that's a great idea - I wish I had thought of it! But, I think for my students, the way I've done it easier to understand.
@tormodsolemslupphaug1043
@tormodsolemslupphaug1043 3 жыл бұрын
Intiuitively one might think you could just move only the tail element up front, without doing any code looping. But after adding more than one segment, the last element goes up and stays in second place in tow with the head, thus leaving the segment before behind. This process repeats itself for every new segment added, leaving all the previous ones behind. Hope it makes sense...
@diededeur6139
@diededeur6139 3 жыл бұрын
is there a function to say if snake goes left the snake body has img... if snake goed right the snake body has img....?
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Something like this will do it - assuming you have a shape named "left.gif" in the same folder. wn.register_shape("left.gif") if head.direction == "left": head.shape("left.gif")
@ravegames1003
@ravegames1003 4 жыл бұрын
why does my window close every time i eat the food it works but closes out every time i eat the food
@TheMursk
@TheMursk 6 жыл бұрын
Another implementation would perhaps be creating individual segments every time the snake moves and having a counter go down for each segment until it's on the tip of the tail and dies next
@gg_lukeee2019
@gg_lukeee2019 3 жыл бұрын
it always crashes instead of the snake getting longer please help
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
What is the error message? Copy and paste it here along with the code and I'll take a look.
@timeextreme5161
@timeextreme5161 3 жыл бұрын
@@TokyoEdTech same promblem
@timeextreme5161
@timeextreme5161 3 жыл бұрын
import turtle import time import random delay = 0.1 # set up the screen wn = turtle.Screen() wn.title("Snake game by @AirZn") wn.bgcolor("black") wn.setup (width=600, height=600) wn.tracer(0) # Turns off screen updates # Snake Head head = turtle.Turtle() head.speed (0) head.shape("square") head.color("red") head.penup() head.goto(0,0) head.direction = "stop" # Snake food food = turtle.Turtle() food.speed (0) food.shape("circle") food.color("orange") food.penup() food.goto(0,100) segments = [] # Functions def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_left(): head.direction = "left" def go_right(): 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": pass else: x = head.xcor() head.setx(x - 20) if head.direction == "right": x = head.xcor() head.setx(x + 20) # keyboard binding wn.listen() wn.onkeypress(go_up, "w") wn.onkeypress(go_down, "s") wn.onkeypress(go_left, "a") wn.onkeypress(go_right, "d") # Main game loop while True: wn.update() # Check for a collision with the food if head.distance(food) < 20: # Move the food to a random spot x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(x,y) # Add a segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("green") new_segment.penup() segments.append(new_segment) # Move the end segments first 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 where the head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() time.sleep(delay) wn.mainloop()
@nigelngai3288
@nigelngai3288 5 жыл бұрын
Hi @Christian Thompson ! I'm really enjoying your videos! I am currently on part 4 of the series and unfortunately I ran into a little bit of a problem. When I try to run, this shows up: Traceback (most recent call last): File "snake_game1.py", line 83, in new_segment.speed(0) File "C:\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 2167, in speed return self._speed AttributeError: 'int' object has no attribute '_speed' What should I do? My code: From line 82-86 new_segment = turtle.Turtle new_segment.speed(0) new_segment.color("grey") new_segment.penup() segments.append(new_segment) Thanks again for the videos :)
@nigelngai3288
@nigelngai3288 5 жыл бұрын
@@TokyoEdTech OMG!!! I swear I was constantly comparing your code with mine and yet I still missed this. I am blind 🤣 !! Thanks it works now! You've just earned yourself a subscriber
@qwretyredty4549
@qwretyredty4549 5 жыл бұрын
why my body of my snake is not following the head its stay on the spot where the food eaten
@alvitocabral
@alvitocabral 4 жыл бұрын
Hi Christian - the code all works fine & the snake grows loner on consumption of the food. But the speed gets progressively slower. While inthe beginning its 0.1 delay and it moves really fast, the speed of the snake moving is super slow after like 10-15 additions to the body.. Does that happen to you as well.
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
It does slow a bit, but it shouldn't be that much.
@karismanabil
@karismanabil 4 жыл бұрын
hello, good explanation you have. But I keep have trouble here in x = random.randint(-290,290) y = random.randint(-290,290) and the errors says undefined variabel 'random' . can you help me?
@karismanabil
@karismanabil 4 жыл бұрын
oof, sorry, i just figure it out that i forgot to type import random
@karismanabil
@karismanabil 4 жыл бұрын
@@TokyoEdTech thank you. btw, how to add a border on the screen? since when i maximize my window screen the bg color is goes all of the screen and i can't see the wn.setup border. so i want to add a color at the border.
@mcreallyfunky
@mcreallyfunky 3 жыл бұрын
Hello! Great tutorial. I was wondering if there is a way to make another food item (maybe something like a grape along with the red apple) that would add more segments than the apple would (ex: apple adds 1 segment onto the snake but grape adds 2 segments)? Any help at all would be appreciated! (also having them both be on screen simultaneously)
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Adding the grape is pretty trivial - just copy the apple code and rename it (but a loop would work better). Adding two segments is a bit tricky as you have to add a segment, move, then add the next segment.
@mcreallyfunky
@mcreallyfunky 3 жыл бұрын
@@TokyoEdTech Thanks for the quick reply! The advice is greatly appreciated.
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
No problem - keep on codin'!
@shashankk_tyagi
@shashankk_tyagi 6 жыл бұрын
thank you so much buddy! helped a lot :)
@baha4535
@baha4535 2 жыл бұрын
I have an error its this : unident does not match any outer indentation level Code: import turtle import time import random delay = 0.1 #Set up the screen wn = turtle.Screen() wn.title("Snake Game by Baha") wn.bgcolor("green") wn.setup(width=600, height= 600) wn.tracer(0)#Turns off the screen updates #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("circle") food.color("red") food.penup() food.goto(0,100) segments = [] #Functions def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_left(): head.direction = "left" def go_right(): 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") #Main Game Loop while True: wn.update() #Check for a collision with the food if head.distance(food) < 20: #Move the Food to a random spot x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(x, y) #Add a segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment) move() time.sleep(delay) wn.mainloop()
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
The error message tells you everything ... Make sure you have the same number of spaces for your indentation levels.
@biancaandreeas
@biancaandreeas 2 жыл бұрын
Hi ! My code is working just fine but the only problem I have is that the snake starts from the beginning with a segment, is not starting only with the head. So the snake always has a segment more than it should... But the code starts from an empty list, I don't understand why this is happening...
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
Hi. If you share your code I can take a look.
@tylercantrell7795
@tylercantrell7795 5 жыл бұрын
I made the game smoother by making the delay 0.0075 and doing this: if head.direction == "up": y = head.ycor() head.sety(y + 1(instead of 20)) if head.direction == "down": y = head.ycor() head.sety(y - 1(instead of 20)) if head.direction == "right": x = head.xcor() head.setx(x + 1(instead of 20)) if head.direction == "left": x = head.xcor() head.setx(x - 1(instead of 20)) If I set everything back to normal delay and change the 1 to 20, it works fine, but with this code the new sections of the snake appear at the position of the head, not behind it. Any help is appreciated! Or is there a way to make it smoother without changing those values?
@tylercantrell7795
@tylercantrell7795 5 жыл бұрын
@@TokyoEdTech Thank you! I'll try it
@Anniecao0430
@Anniecao0430 5 жыл бұрын
I know im late but my grey part is super long like the longer it moves the longer it bevomes
@mea664618
@mea664618 6 жыл бұрын
Nice work man, keep up i tried a shorter code to move body segment and it works first i added 'head' to 'segments' list as a first item # Snake body segments = [ ] segments.append(head) then in while loop i added the following code # move the segments for i in range(len(segments)-1, 0, -1): x = segments[i-1].xcor() y = segments[i-1].ycor() segments[i].goto(x, y)
@Gladionuh
@Gladionuh 3 жыл бұрын
When I eat the first apple the application crashes
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
There is a link in the description labeled “NEED HELP?” Check that out and get back to me. Keep on codin’!
@apurvapragya553
@apurvapragya553 4 жыл бұрын
I program in IDLE In it the attachment overlaps to the head everytime I run it Please give solution to it
@shivangsingh3856
@shivangsingh3856 4 жыл бұрын
Which algorithm you are using ?
@penultimania4295
@penultimania4295 3 жыл бұрын
I really like your tutorials. However, while I sort of understand whats going on with the snake body, i probably wouldnt be able to apply this logic in another project if needed. I am not sure if im stupid or just still inexperienced cause i dont see myself coming up with this at all at the moment. Makes me want to abandon this tutorial as I have not understood everything fully and feel im just copying the code. i dont think its your fault though. I just dont get the logic behind the snake body (yes ive read the explanation youve given somewhere else in the comments)
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Yeah. It takes a lot of time and experimentation. I've been coding off and on for decades and it took time to come up with this.
@mariajreijiri3216
@mariajreijiri3216 3 жыл бұрын
Did you remember to put the functions video in the description ?
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
I just did - thanks!
@Donplays_11
@Donplays_11 4 жыл бұрын
I'm at 3:05 pastebin.com/Nn7Afqwe Traceback (most recent call last): File "/Volumes/LUIGI/Snakeee.py", line 96, in segments.append(new_segment) NameError: name 'segments' is not defined
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Watch carefully. You are missing : segments = []
@Donplays_11
@Donplays_11 4 жыл бұрын
@@TokyoEdTech omg thank you so much! I can't believe I did not see that!
@TokyoEdTech
@TokyoEdTech 4 жыл бұрын
Happens to the best of us!
@ariharbas6795
@ariharbas6795 4 жыл бұрын
@@TokyoEdTech is it segments = [] append (new_segment) or segment = [append] (new_segment)
@victorbrorson6605
@victorbrorson6605 5 жыл бұрын
Great tutorial! The code works, and i get no error message. Still, when i run the program, a grey line appears between where the snake head collided with the food and the new segment. This results in many grey lines around the screen after having picked up a few pieces of food. What to do ? :))
@victorbrorson6605
@victorbrorson6605 5 жыл бұрын
@@TokyoEdTech Ahh, perfect, that solved it. Forgot parenthesis after .penup in the new segment code :))) Thx!
@gitanshkumar4113
@gitanshkumar4113 5 жыл бұрын
great explaining!! But when I was trying it to add segment to head the first part is going on top of the head, please explain, i wrote the same cod as u did
@haridaspm8574
@haridaspm8574 5 жыл бұрын
Name segment is not defining
@bronder1092
@bronder1092 4 жыл бұрын
I ran into the same issue. All I did was move the "move()" function to the bottom of the code, including using (window.tracer(0) at the top of the code, including (time.sleep(0.1) you pick the number), that should fix your problem, fixed mine at least. Have a great day!
Python Game Programming Tutorial: Snake Game Part 5
5:32
TokyoEdtech
Рет қаралды 59 М.
Python Game Programming Tutorial: Snake Game Part 3
5:05
TokyoEdtech
Рет қаралды 81 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Let's code a SNAKE GAME in python! 🐍
33:06
Bro Code
Рет қаралды 682 М.
Python Game Programming Tutorial: Snake Game Part 6
5:30
TokyoEdtech
Рет қаралды 50 М.
Creating a Snake game with Python in under 5 minutes
5:40
Engineer Man
Рет қаралды 3,1 МЛН
Python Game Programming: Simple Cookie Clicker
11:44
TokyoEdtech
Рет қаралды 126 М.
Snake Game Python Tutorial
49:40
freeCodeCamp.org
Рет қаралды 527 М.
Python Game Programming Tutorial: Snake Game Part 2
14:19
TokyoEdtech
Рет қаралды 161 М.
15 Python Projects in Under 15 Minutes (Code Included)
12:37
Tech With Tim
Рет қаралды 2 МЛН
Hardy's Integral
13:47
Michael Penn
Рет қаралды 19 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19