When i run my project the snake is already increasing size and my code is: import turtle import time import random delay = 0.1 # set up the screen wn =turtle.Screen() wn.title("Snake game by Aditya Footballer") wn.bgcolor("Blue") wn.setup(width=600, height=600) wn.tracer(0) # Tru to turn 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 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 1 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()
@Manga_Lov42 күн бұрын
When my Snake collabs with an apple only the segment 0 is coming to the snake, the others are spawning in the middle My entire Code: import turtle import time import random delay = 0.1 #set up the screen wn = turtle.Screen() wn.title("Snake Game") 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 = [] #Funktions 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 the end segmentsfirst in reversed order 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) # 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()
@jadeabove2 күн бұрын
I squealed a bit too loud when I got the "Player" to move. :p
@TokyoEdTech2 күн бұрын
@@jadeabove It's a great feeling! Keep on codin'!
@dudewhatthe26323 күн бұрын
my snake not moving
@dudewhatthe26323 күн бұрын
i copied code here it is import turtle import time import random delay = 0.1 #Score score = 0 high_score= 0 # set screen wn = turtle.Screen() wn.title("Snake Game by @Valentino") 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" #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=("Courier", 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) #Keybord 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.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 for segment in segments: segment.goto(1000, 1000) #Clear the segments list segments.clear() #Reset score score = 0 delay = 0.1 pen.clear() pen.write("Score: {} High_Score: {}". format(score, high_score), align="center", font=("Courier", 24, "normal")) # Check for collision with 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) delay -= 0.001 #Increase Score score += 10 if score > high_score: high_score = score pen.clear() pen.write("Score: {} High_Score: {}". format(score, high_score), align="center", font=("Courier", 24, "normal")) #Move 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() wn.mainloop()
@dudewhatthe26323 күн бұрын
don't know what i did wrong pls help me
@dudewhatthe26323 күн бұрын
luv your vids
@TokyoEdTech3 күн бұрын
@@dudewhatthe2632 Hiya - first you are missing the following: move() time.sleep(delay) Plus, there is something else wrong, but I couldn't quite figure it out. Here is a link to the correct code: gist.github.com/wynand1004/ec105fd2f457b10d971c09586ec44900 Note, the order is pretty important for this one. Keep on codin'!
@valhurts4 күн бұрын
That's crazy this vid is 8 years rn
@TokyoEdTech4 күн бұрын
Wow - time flies!
@The-MaliX4 күн бұрын
help me I type pen.hideturtle() but i get Exception has occurred: TypeError TPen.hideturtle() missing 1 required positional argument: 'self'
@TokyoEdTech4 күн бұрын
@@The-MaliX Can you copy and paste all of your code so I can take a look?
@@alomchakma605 If you copy and paste your code, I can take a look
@SohamKapdi-j1d6 күн бұрын
When I tried to add this code to my space war code my turtle was not responding after just adding the splash screen so what should I do
@TokyoEdTech5 күн бұрын
@@SohamKapdi-j1d If you share all the code I can take a look.
@SohamKapdi-j1d3 күн бұрын
@@TokyoEdTech what should i am not able send the link to the code
@TokyoEdTech3 күн бұрын
@@SohamKapdi-j1d You can copy and paste it here
@SohamKapdi-j1d2 күн бұрын
@@TokyoEdTech i tried that to it was giving me error i tried it many times so if have any other way to send the code to you can you tell me please
@Bubble_Kayl366 күн бұрын
it appears but wont follow (do you need the whole code or is this enough?) #add 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 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 head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x , y) move() time.sleep(delay) wn.mainloop()
@TokyoEdTech6 күн бұрын
@Bubble_Kayl36 Hi. Yes, could you provide all the code so I can test it?
@Bubble_Kayl362 күн бұрын
@@TokyoEdTech #snake import turtle import time import random delay = 0.1 #set up screen wn = turtle.Screen() wn.title("Snake Game by Bubble") wn.bgcolor("green") 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("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) #body 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) #key 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 collision with food if head.distance(food) < 20: #move food to random spot X = random.randint(-290,290) Y = random.randint(-290,290) food.goto(X , Y) #add 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 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 head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() time.sleep(delay) wn.mainloop() sorry for the wait, youtube didn't give me a notification
@LarryTheWeirdone7 күн бұрын
So every time I type in while True: the colon is there but when I run it opens terminal which is normal but it says expected : when it’s there?
@TokyoEdTech7 күн бұрын
@@LarryTheWeirdone Can you copy and paste the code and the error message?
@LarryTheWeirdone4 күн бұрын
@TokyoEdTech hey sorry I found out what the error was. I thought there was only one Colon but there was 2. And I forget which line it was since I already deleted that project
@TokyoEdTech4 күн бұрын
@LarryTheWeirdone All good - glad you got it sorted!
@COOLGAMING4167 күн бұрын
Sir can u pls provide source code of this
@TokyoEdTech7 күн бұрын
@COOLGAMING416 Sure - here you go: github.com/wynand1004/Projects/tree/master/SpaceWar
@COOLGAMING4167 күн бұрын
Thnx a lot sir
@SohamKapdi-j1d9 күн бұрын
when trying to use more things such as lives so what happens when i add both on the screen the game is not able to undo the 0 in the score and 3 in the lives and it writes over the old number so what should i do not face that problem
@TokyoEdTech7 күн бұрын
Use .clear on the pen turtle. Then redraw all the text.
@SohamKapdi-j1d7 күн бұрын
@@TokyoEdTech thanks 😊😊
@MelloTheHero10 күн бұрын
turn.listen() doesn't work?
@TokyoEdTech9 күн бұрын
Hi. There is no turn.listen() - it should probably be turtle.listen()
@saturn5tony10 күн бұрын
An fyi, the little indian format is the way the 6502 deals with a 16 bit number. Thanks for sharing !
@TokyoEdTech10 күн бұрын
@@saturn5tony Cheers - thanks for the info!
@ziaulhaiderchowdhury936311 күн бұрын
Thanks a lot . That was a good lesson for the beginners . My high score is 400.
@TokyoEdTech11 күн бұрын
You're welcome. 400 points is impressive! Keep on codin' and please subscribe!
@xyzxyz609516 күн бұрын
Bună ziua. Mulțumesc pentru lecția de Pyth0n. Salutări din Franța.
@konoyaro0917 күн бұрын
1:33 how did you get that list,in my python there is no list by default please help
@TokyoEdTech17 күн бұрын
@@konoyaro09 It depends on which editor or IDE you are using. Check out Geany or VS Code.
@konoyaro0917 күн бұрын
1:32 in my python i dont get that list,how can i fix that
@himankgaming755518 күн бұрын
My actual interest for general programming and logic building started from here and today after working as a software developer, I just came back here to appreciate the efforts that has changed one life, Thank you sir for this great tutorial playlist
@TokyoEdTech18 күн бұрын
@@himankgaming7555 That is amazing! Thank you for letting me know. Congratulations on your new job! Keep on codin'!
@thelegith361919 күн бұрын
sir what IDE are you using beacuse im a beginner and i have jupyter notebook and it isn"t working on it
@TokyoEdTech19 күн бұрын
This won't work in Jupyter Notebook. These days I use Geany - this video will help you get started: kzbin.info/www/bejne/j6aQZ4V6eLRleLs
@Balamayooran20 күн бұрын
Hi sir, can we do this optimization through from scipy.optimize import linprog
@TokyoEdTech20 күн бұрын
@@Balamayooran I believe so - might want to try it and report back!
@Balamayooran19 күн бұрын
@@TokyoEdTech , Hi sir, thanks, when it comes to area, then this will be non-linear type, so I think from scipy.optimiza import linprog is not suited, your one is correct
@TokyoEdTech19 күн бұрын
@Balamayooran Thanks for the update!
@erioluwaalvinolorundare972622 күн бұрын
NameError: name 'random' is not defined. Did you forget to import 'random'? this is what it says the error
@TokyoEdTech18 күн бұрын
So, it tells you the error, and it tells you exactly how to fix it. At the top of the program where you have import turtle, add import random
@erioluwaalvinolorundare972622 күн бұрын
and also if i move the snake and it hit the red ball it will stop automatically and say error
@erioluwaalvinolorundare972622 күн бұрын
if i press a or d for the snake it wont move
@TokyoEdTech22 күн бұрын
@@erioluwaalvinolorundare9726 If you share your code I will take a look.
@erioluwaalvinolorundare972622 күн бұрын
can you help me out
@erioluwaalvinolorundare972622 күн бұрын
hi tokyoedthech
@NamVuongLe22 күн бұрын
Hi
@monkeyedits969424 күн бұрын
I got a problem my sprite doesnt move anymore, import os import random #Import the Turtle module import turtle #Required by MacOSX to show the window turtle.fd(0) #Set the animations speed to the maximum turtle.speed(0) #Change the background color turtle.bgcolor("black") #Hide the default turtle turtle.ht() #This saves memory turtle.setundobuffer(1) #This speeds up drawing turtle.tracer(1) class Sprite(turtle.Turtle): def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape = spriteshape) self.speed(0) self.penup() self.color(color) self.fd(0) self.goto(startx, starty) self.speed = 1 def move(self): self.fd(self.speed) class Player(Sprite): def __init__(self, spriteshape, color, startx, starty): Sprite.__init__(self, spriteshape, color, startx, starty) self.speed = 4 self.lives = 3 def turn_left(self): self.lt(45) def turn_right(self): self.lt(45) def accelerate(self): self.speed += 1 def accelerate (self): self.speed -=1 #Create my sprites player = Player("triangle", "white", 0, 0) #Keyboard bindings turtle.onkey(player.turn_left, "Left") turtle.listen() turtle.onkey(player.turn_right, "Right") turtle.listen() turtle.onkey(player.accelerate_up, "Up") turtle.listen() turtle.onkey(player.decelerate, "Down") turtle.listen() #Main game loop while True: player.move() delay = raw_input("Press enter to finish. > ")
@TokyoEdTech24 күн бұрын
@@monkeyedits9694 Are you getting any error message?
@patientson25 күн бұрын
This is an absolute requirement for data analyst and cyber security
@TokyoEdTech25 күн бұрын
@@patientson Glad you think so!
@user-vp2lg9gu5l26 күн бұрын
I love your videos; I first followed them in 2019 when I got into python but then life got in the way and I hadn't coded in 4 years so i spent hours trying to figure out which youtuber it was who taught me the first time and then I found your Pong playlist finally! I got right back into it with your guidence! I love how you don’t just show us what to do but explain why everything is done and thus allow us to alter the code we write to differ from yours to personalise it for instance with this game I decided when the snake hits the border it should just come back from the other side of the screen and so I tried that, and it may not be perfect coding but I was able to make it work from what you have taught! I have also added sounds and a “GAME OVER” screen , as well as making the high score save between games (code is below for anyone who wants to do the same and can’t figure it out! - you will need to pick some sounds you like I get mine from freesound.org/ and adding sounds is explained here: kzbin.info/www/bejne/j4vOn6KFjKiUoJY&ab_channel=TokyoEdtech for help on how the high score saving works I used this vid: kzbin.info/www/bejne/fXSYYZebrbamiNE&ab_channel=TokyoEdtech) your great explanations also mean that when I make a typo or differ from your code slightly to personalise it and it doesn’t work I'm able to pause your video and try and figure it out myself since you have not just shown but taught, for instance with this code everything worked except after you lose the score would reset to 0 and stay at 0, it took me 10 mins to realise that I had missed an indent on lines 149 and 150 but I got there eventually! Code: import turtle import winsound import time import random import pickle delay = 0.1 # Score score = 0 high_score = 0 high_score = pickle.load(open("score.dat", "rb")) # this reads the high score file and makes the high score save - if you are copying this code remove this and run once without this line then reinsert it # Screen setup wn = turtle.Screen() wn.title("Snake by Lewis") wn.bgcolor("light green") wn.setup(width=600, height=600) wn.tracer(0) # Turns off screen updates to increase running speed # Snake head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("dark green") head.penup() head.goto(0,0) head.direction = "stop" # Mouse (food) food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("red") food.penup() food.goto(0,100) # Body segments segments = [] # Score board pen = turtle.Turtle() pen.speed(0) pen.shape("square") pen.color("black") pen.penup() pen.hideturtle() pen.goto(0, 260) pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 18, "normal")) # "GAME OVER" message gameover_pen = turtle.Turtle() gameover_pen.speed(0) gameover_pen.shape("square") gameover_pen.color("red") gameover_pen.penup() gameover_pen.hideturtle() gameover_pen.goto(0, 0) # 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) gameover_pen.clear() # if you just put this after the gameover message it will instantly vanish even if you use a time delay for some reason, so my solution was to get rid of the message when you click a key to move to start the next game if head.direction == "down": y = head.ycor() head.sety(y - 20) gameover_pen.clear() if head.direction == "left": x = head.xcor() head.setx(x - 20) gameover_pen.clear() if head.direction == "right": x = head.xcor() head.setx(x + 20) gameover_pen.clear() # Key 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() # Collisions with border if head.xcor() > 290: y = head.ycor() head.goto(-290, y) if head.xcor() < -290: y = head.ycor() head.goto(290, y) if head.ycor() > 290: x = head.xcor() head.goto(x, -290) if head.ycor() < -290: x = head.xcor() head.goto(x, 290) # Collision with food if head.distance(food) < 20: winsound.PlaySound("foodsound.wav", winsound.SND_ASYNC) 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) # Shorten delay delay -= 0.001 # Increase score score += 1 if score > high_score: high_score = score pen.clear() pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 18, "normal")) # Move 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 (closest to head) to where head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() # Check for head collision with body segments for segment in segments: if segment.distance(head) < 20: winsound.PlaySound("gameover.wav", winsound.SND_ASYNC) gameover_pen.clear() # idk why this changes things but putting this anywhere else causes the snake to imedietly move left upon respawn regardless of the head.direction = "stop" code head.goto(0, 0) head.direction = "stop" # Hide the segments for segment in segments: segment.goto(1000, 1000) # Clear segments list segments.clear() # reset score, delay, and sound delay = 0.1 score = 0 # update score display + GAMEOVER pen.clear() pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 18, "normal")) gameover_pen.clear() # gameover code has to be here or it just doesnt show up unsure why??? gameover_pen.write("GAME OVER!", align="center", font=("Courier", 32, "bold")) time.sleep(2.527) # this is how long the gameover sound lasts # Saves the high score as a file pickle.dump(high_score, open("score.dat", "wb")) time.sleep(delay) wn.mainloop()
@ChristinaGoddeti27 күн бұрын
Can we run this project in pycharm
@TokyoEdTech27 күн бұрын
@@ChristinaGoddeti Yep!
@HaliamhJaved28 күн бұрын
7:06 my code is the exact same as yours except for colors but it isn’t moving at all
@TokyoEdTech28 күн бұрын
@@HaliamhJaved If you share your code I'll take a look.
@harshitasahu178Ай бұрын
Hii sir My snake is not moving and it doesn't give any error message I use Python 3.8.6
@TokyoEdTechАй бұрын
@@harshitasahu178 Can you paste the code here so I can take a look?
@rayaneachchaq6302Ай бұрын
thank u sooo much man appreciate the efforts
@TokyoEdTechАй бұрын
@@rayaneachchaq6302 You are welcome! Keep on codin' and please subscribe!
@pythonBossАй бұрын
bro you are great super bro can you post more videos like this
@TokyoEdTech29 күн бұрын
Thanks! I have a number of game tutorials - be sure to check them out! Keep on codin' and please subscribe!
@Ripblank87Ай бұрын
#import the module import os import random import turtle turtle.fd(0) turtle.speed(0) turtle.bgcolor("black") turtle.ht() turtle.setundobuffer(1) class Sprite(turtle.Turtle): def __init__(self, spiriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape = spiriteshape) self.speed(0) self.penup() self.color(color) self.fd(0) self.goto(startx, starty) self.speed = 1 def move(self): self.fd(self.speed) class Player(Sprite): def __init__(self, spiriteshape, color, startx, starty): Sprite.__init__(self, shape = spiriteshape) def turn_left(self): self.lf(45) #Sprites player = Sprite("triangle", "white", 0, 0) #keyboard bindings #main game loop while True: player.move() in this code thats close to yours i couldn't use turn.left key binds or any key binds
@TokyoEdTechАй бұрын
@@Ripblank87 You are missing the code that does the keybinding. What did you actually type?
@Ripblank87Ай бұрын
@TokyoEdTech uh i just copied what you did in the second video also i removed self.speed = 4 and self.lives = 3 Because they were making errors
@TokyoEdTechАй бұрын
@@Ripblank87 As I mentioned you don't have the keybinding code - go back, watch the video, and make sure you don't miss that part.
@Ripblank87Ай бұрын
Alright thank you
@eclipse_ctaАй бұрын
Thanks a lot! this tutorial is very easy to follow! would reccomend this a lot. also thank you so much for giving explanations as to (example) why we use penup, etc. :-)
@TokyoEdTechАй бұрын
@@eclipse_cta You're quite welcome. Keep on codin' and please subscribe!
@VanditaTiwari_28Ай бұрын
Hey my code is not running
@TokyoEdTechАй бұрын
@@VanditaTiwari_28 If you share your code and any error messages I can take a look.
@Ripblank87Ай бұрын
How to get self to work
@TokyoEdTechАй бұрын
I'm not sure what you mean - can you share the code and any error messages?
@Ripblank87Ай бұрын
@TokyoEdTech it says self is not defined
@Ripblank87Ай бұрын
@TokyoEdTech by the way you are a legend
@TokyoEdTechАй бұрын
@@Ripblank87 Please share the code - copy and paste it here.
@TokyoEdTechАй бұрын
@@Ripblank87 Thanks - I try!
@outlander6643Ай бұрын
can i use visual studio code to do this ? if so what extension do i need to run the calculator to open as a window?
@TokyoEdTech29 күн бұрын
Hiya - sure, it should be no problem. You don't need any extensions as tkinter usually comes with Python.
@Stories-m6uАй бұрын
1:12 not Pythagoras theorem again ahhhhh
@TokyoEdTechАй бұрын
@@Stories-m6u It pops up when you least expect it!
@afcnft-12Ай бұрын
Your videos help me on tests !
@TokyoEdTechАй бұрын
@@afcnft-12 Awesome - glad I could help. Keep on codin' and please subscribe!
@mohammadahmadzee5060Ай бұрын
can we make the snake realistic
@TokyoEdTechАй бұрын
You can use images for the head and body, but that complicates things a bit.
@xoxo.lxly.26Ай бұрын
hey how did you import the sound? on mac how did u save it on folder and all plesase explain me.
@TokyoEdTech29 күн бұрын
Usually you do "Save as..." and then choose the folder. Alternatively, once it is in the downloads, copy and paste it into the folder.
@rickeymelson1204Ай бұрын
hello sir. i'm getting the AttributeError 'Turtle' object has no attribute 'size. import os import random #Import the Turtle module import turtle turtle.fd(0) #set the animation speed turtle.speed(0) #change the background turtle.bgcolor("black") #hide the default turtle turtle.ht() #this saves memory turtle.setundobuffer(1) #this speeds up the drawing turtle.tracer(1) class Sprite(turtle.Turtle): def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape = spriteshape) self.speed(0) self.penup() self.color(color) self.fd(0) self.goto(startx, starty) self.speed = 4 def move(self): self.fd(self.speed) #Border detection if self.xcor() > 290: self.setx(290) self.rt(60) if self.xcor() < -290: self.setx(290) self.rt(60) if self.ycor() > 290: self.sety(290) self.rt(60) if self.ycor() < - 290: set.sety(290) self.rt(60) class Player(Sprite): def __init__(self, spriteshape, color, startx, starty): Sprite.__init__(self, spriteshape, color, startx, starty) self_speed = 4 self_lives = 3 def turn_left(self): self.lt(45) def turn_right(self): self.rt(45) def accelerate(self): self.speed += 1 def decelerate(self): self.speed -= 1 class Game(): def __init__(self): self.level = 1 self.score = 0 self.state = "playing" self.pen = turtle.Turtle() self.lives = 3 def draw_border(self): #Draw Border self.pen.speed(0) self.pen.color("white") self.pen.size(3) self.pen.penup() self.pen.goto(-300, 300) self.pen.pendown() for side in range(4): self.pen.fd(600) self.pen.rt(60) self.pen.penup() self.pen.ht() #create game object game = Game() #draw the game border game.draw_border() #create my sprites player = Sprite("triangle", "white", 0, 0) #keyboard binding turtle.onkey(player.turn_left, "Left") turtle.onkey(player.turn_right, "Right") turtle.onkey(player.accelerate, "Up") turtle.onkey(player.decelerate, "Down") turtle.listen() #Main game Loop while True: player.move() delay = input("press enter to finish. > ")
@TokyoEdTechАй бұрын
Hiya. Try self.pen.pensize(3)
@houdatahiri4596Ай бұрын
hello every one i dont know why the green screen dont show up in my screen and i have a projet presantation tomorrow please help me guys
@houdatahiri4596Ай бұрын
thats my error guys > & c:/Users/Lenovo/Desktop/exercice/.venv/Scripts/python.exe c:/Users/Lenovo/xDesktop/exercice/preparatin.py/snak.py x Traceback (most recent call last): File "c:\Users\Lenovo\Desktop\exercice\preparatin.py\snak.py", line 3, in <module> wn = turtle.screen() ^^^^^^^^^^^^^ AttributeError: module 'turtle' has no attribute 'screen'. Did you mean: 'Screen'? PS C:\Users\Lenovo\Desktop\exercice>
@TokyoEdTechАй бұрын
@@houdatahiri4596 The error message tells you exactly what the problem is and how to fix it. screen -> Screen
@xoxo.lxly.26Ай бұрын
Umm sorry for troubling u again but when i shoot the missile it passes straight thorough the enemy here is my code: ___________________CODE___________________ import os import random #Import the Turtle module import turtle #Required by MacOSX to show the window turtle.fd(0) #Set the animation speed to the maxiumum turtle.speed(0) #Change the background color turtle.bgcolor("black") #Hide the default turtle turtle.ht() #This saves memory turtle.setundobuffer(1) #This speeds up drawing turtle.tracer(1) class Sprite(turtle.Turtle): def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape = spriteshape) self.speed(0) self.penup() self.color(color) self.fd(0) self.goto(startx, starty) self.speed = 1 def move(self): self.fd(self.speed) #Bounary detection if self.xcor() > 290: self.setx(290) self.rt(60) if self.ycor() < -290: self.setx(-290) self.rt(60) if self.ycor() > 290: self.sety(290) self.rt(60) if self.xcor() < -290: self.sety(-290) self.rt(60) def is_collision(self, other): if (self.xcor() >= (other.xcor() - 20)) and \ (self.xcor() <= (other.xcor() + 20)) and \ (self.ycor() >= (other.ycor() - 20)) and \ (self.ycor() <= (other.ycor() + 20)): return True else: return False class Player(Sprite): def __init__(self, spriteshape, color, startx, starty): Sprite.__init__(self, spriteshape, color, startx, starty) self.speed = 4 self.lives = 3 def turn_left(self): self.lt(45) def turn_right(self): self.rt(45) def accelerate(self): self.speed += 1 def decelerate(self): self.speed -= 1 class Enemy(Sprite): def __init__(self, spriteshape, color, startx, starty): Sprite.__init__(self, spriteshape, color, startx, starty) self.speed = 6 self.setheading(random.randint(0,360)) class Missile(Sprite): def __init__(self, spriteshape, color, startx, starty): Sprite.__init__(self, spriteshape, color, startx, starty) self.shapesize(stretch_wid=0.3, stretch_len=0.4, outline = None) self.speed = 20 self.status = "ready" self.goto(-1000, 1000) def fire(self): if self.status == "ready": self.goto(player.xcor(),player.ycor()) self.setheading(player.heading()) self.status = "firing" def move(self): if self.status == "ready": self.goto(-1000, 1000) if self.status == "firing": self.fd(self.speed) #Border check if self.xcor() < -290 or self.xcor() > 290 or \ self.ycor() < -290 or self.ycor() > 290: self.goto(-1000,1000) self.status = "ready" class Game(): def __init__(self): self.level = 1 self.score = 0 self.state = "playing" self.pen = turtle.Turtle() self.lives = 3 def draw_border(self): #Draw border self.pen.speed(0) self.pen.color("white") self.pen.pensize(3) self.pen.penup() self.pen.goto(-300, 300) self.pen.pendown() for side in range(4): self.pen.fd(600) self.pen.rt(90) self.pen.penup() self.pen.ht() #Create game object game = Game() #Draw the game border game.draw_border() #Create my sprites player = Player("triangle", "white", 0, 0) enemy = Enemy("circle", "red", -100, 0) missile = Missile("circle", "orange", 0, 0) #Keyboard bindings turtle.onkey(player.turn_left, "Left") turtle.onkey(player.turn_right, "Right") turtle.onkey(player.accelerate, "Up") turtle.onkey(player.decelerate, "Down") turtle.onkey(missile.fire, "space") turtle.listen() #Main game loop while True: player.move() enemy.move() missile.move() #Check for a collision with the player if player.is_collision(enemy): x = random.randint(-250, 250) y = random.randint(-250, 250) enemy.goto(x, y) #Check for a collision between the missile and the enemy if player.is_collision(enemy): x = random.randint(-250, 250) y = random.randint(-250, 250) enemy.goto(x, y) missile.status = "ready" delay = raw_input("Press enter to finish. >") FINISH!
@Cr3ckedАй бұрын
TYSM. You helped me explore so many things about turtle. just 1 question, what is the difference between turtle.Turtle() And turtle.Pen()? I've Been Trying To Figure It Out For 3 Years Since I Started Python
@TokyoEdTech29 күн бұрын
You're welcome. turtle.Turtle() creates a new turtle object that can be moved around on the screen. There is no turtle.Pen(), but there is turtle.pen() If you mean: pen = turtle.Turtle() then I am creating a new turtle object that I am (in this case) using to print the text on the screen. Keep on codin' and please subscribe!
@Cr3cked29 күн бұрын
@@TokyoEdTech Strange, Since My Turtle Module Has "t = turtle.Pen()"?
@TokyoEdTech28 күн бұрын
@@Cr3cked Can you copy and paste your code here so I can take a look? There is a turtle.pen() method but it is lowercase.
@@Cr3cked I had to actually go into the turtle code itself. Pen is an alias of Turtle. This is found on line 3884. Link: github.com/python/cpython/blob/main/Lib/turtle.py#L3884 Mystery solved! It would be nice if this were included in the documentation somewhere.
@Cr3ckedАй бұрын
AINT NO WAY YOU ARE FRICKIN CODING A GAME WITH TURTLE. LIKE BRO HOWWWW. I ALWAYS MAKE A CONTROLABBLE ARROW BUT THIS IS NEXT LEVEL
@TokyoEdTechАй бұрын
@@Cr3cked Hahahaha! The turtle module is surprisingly capable - check this one out! kzbin.info/aero/PLlEgNdBJEO-kK78GXDVzytiZlJtCyiFyW&si=2nAI_bZJnnVpVXFw
@VivekPatel-zv8hvАй бұрын
have created the same game but still am getting bigger as i move on the screen?
@TokyoEdTechАй бұрын
@@VivekPatel-zv8hv Can you share the code so I can take a look?