hey how did you import the sound? on mac how did u save it on folder and all plesase explain me.
@rickeymelson120420 сағат бұрын
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. > ")
@TokyoEdTech13 сағат бұрын
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!
@xoxo.lxly.26Күн бұрын
Hey can you tell me the code for writing the title i don't know how to write it please answer me.☺
@Chess_Man1002 күн бұрын
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
@Chess_Man1002 күн бұрын
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
@TokyoEdTech2 күн бұрын
@@Chess_Man100 Hahahaha! The turtle module is surprisingly capable - check this one out! kzbin.info/aero/PLlEgNdBJEO-kK78GXDVzytiZlJtCyiFyW&si=2nAI_bZJnnVpVXFw
@VivekPatel-zv8hv2 күн бұрын
have created the same game but still am getting bigger as i move on the screen?
@TokyoEdTech2 күн бұрын
@@VivekPatel-zv8hv Can you share the code so I can take a look?
@ranveersingh15892 күн бұрын
import turtle import time import random delay = 0.1 #Score score = 0 high_score = 0 #setting up the screen window = turtle.Screen() window.title("Snake game by Rv. ") window.bgcolor("Black") window.setup(width=1400 , height=1000) window.tracer(0) #turns off the screen updates #snake Head head = turtle.Turtle() head.speed(0) head.shape("triangle") head.color("#00FFFF") head.penup() head.goto(0,0) head.direction = "stop" #Snake Food food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("#FF69B4") 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, 460) 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) #Keyboard Bindings window.listen() window.onkeypress(go_up, "w") window.onkeypress(go_down, "s") window.onkeypress(go_left, "a") window.onkeypress(go_right, "d") #main game loop while True: window.update() #Check for collision with the border if head.xcor()>690 or head.xcor()<-690 or head.ycor()>490 or head.ycor()<-490: time.sleep(1) head.goto(0, 0) head.direction = "stop" #Hide the segments for segment in segments: segment.goto(1000 , 1000) #Clear the segments segments.clear() #Reset the score score = 0 #reset the delay delay = 0.1 #Update the Score display pen.clear() pen.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("courier", 24, "normal")) #Check for the collision with the food if head.distance(food) < 20: #Move the food to the random spot. x = random.randint(-690, 690) y = random.randint(-490, 490) food.goto(x, y) #Add a segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("triangle") new_segment.color("#39FF14") 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 pen.clear() pen.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("courier", 24, "normal")) #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() #Check for the head collisions with the body for segment in segments: if segment.distance(head) < 20: time.sleep(1) head.goto(0, 0) head.direction = "stop" #Hide the segments for segment in segments: segment.goto(1000 , 1000) #Clear the segments segments.clear() # Reset the score and delay score = 0 delay = 0.1 # Update the Score display pen.clear() pen.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("courier", 24, "normal")) time.sleep(delay) window.mainloop()
@boriskostial23482 күн бұрын
shadows name 'y' from outer scope shadows name 'x' from outer scope shadows name 'y'from outer scope shadows name 'x'from outer scope import turtle import time import random from setuptools.command.egg_info import write_toplevel_names 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) # Snake head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("white") head.penup() 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.color("red") food.penup() food.goto(0, 100) # Functions def go_up(): head.direction = "up" def go_right(): head.direction = "right" def go_left(): head.direction = "left" def go_down(): head.direction = "down" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 20) if head.direction == "right": x: float = head.xcor() head.setx(x + 20) if head.direction == "down": y = head.ycor() head.sety(y - 20) if head.direction == "left": 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(food) < 20: #move the food to a random spot x = random.randint(-290, 290) y = random.randint(-290, 290) move() time.sleep(delay)
@dlbet41104 күн бұрын
The big fail is that you haven't told me how to get to the place where you start to code. It's a pretty important first step for beginners.
@TokyoEdTech4 күн бұрын
@@dlbet4110 Yes, the assumption is that you already know this, or that you know how to search. Try this: kzbin.info/www/bejne/j6aQZ4V6eLRleLssi=v2mgZTED013mi7XL
@xoxo.lxly.265 күн бұрын
hey my code is here and the border is not working i t cant be shown 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) 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.pensize(3) self.penpenup() 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) #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.listen() #Main game loop while True: player.move() delay = raw_input("Press enter to finish. >")
@TokyoEdTech5 күн бұрын
Hi. Don't indent the following code: #Create game object game = Game() #Draw the game border game.draw_border() Note, there are other issues - it's self.pen.penup() as well.
@xoxo.lxly.264 күн бұрын
@@TokyoEdTech Umm i did as you told me but the turtle is not moving and the border is also not showing Here is the code form the border line .... def draw_border(self): #Draw border self.pen.speed(0) self.pen.color("white") self.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()
@xoxo.lxly.264 күн бұрын
@@TokyoEdTech Also if i its not working on IDLE so can i write it on Visual code editor you see i am also on MacBook
@TokyoEdTech4 күн бұрын
@xoxo.lxly.26 Read the error messages. They tell you which lines are wrong. Then fix them one by one.
@xoxo.lxly.264 күн бұрын
@@TokyoEdTech Umm These are the errror messages i am sorry for troubling you a lot but i am a 14 yr old begginer learning programming so here are the errors ................. Traceback (most recent call last): File "/Users/****/Documents/py.eg Spacewar.py", line 99, in <module> game.draw_border() File "/Users/****/Documents/py.eg Spacewar.py", line 83, in draw_border self.pensize(3) AttributeError: 'Game' object has no attribute 'pensize'
@xoxo.lxly.265 күн бұрын
he my border is not showing and when i add the border command so the turtle is moving but the border is not showing , here is my 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) 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.pensize(3) self.penpenup() 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) #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.listen() #Main game loop while True: player.move() delay = raw_input("Press enter to finish. >")
@PranshuAgarwalEncyclopedia5 күн бұрын
Thank You So Much It Helped Me So Much
@TokyoEdTech5 күн бұрын
@@PranshuAgarwalEncyclopedia Glad to hear it - keep on codin' and please subscribe!
@boriskostial23486 күн бұрын
my snake head doesnt want to move no errors nothing import turtle import time from setuptools.command.egg_info import write_toplevel_names 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) # Snake head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("white") head.penup() head.color("Black") head.penup() head.goto(0, 0) head.direction = "stop" # Functions def go_up(): head.direction = "up" def go_right(): head.direction = "right" def go_left(): head.direction = "left" def go_down(): head.direction = "down" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 20) if head.direction == "right": x = head.xcor() head.setx(x + 20) if head.direction == "down": y = head.ycor() head.sety(y - 20) if head.direction == "left": 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, "s") # Main game loop while True: wn.update() move() time.sleep(delay) wn.mainloop()
@TokyoEdTech6 күн бұрын
@@boriskostial2348 Try deleting wn.mainloop(). It should not be indented.
@boriskostial23484 күн бұрын
@@TokyoEdTech yep thankss
@Chess_Man1002 күн бұрын
@@boriskostial2348 Try This Code: import time import turtle 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) # Snake head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("white") head.penup() head.color("Black") head.penup() head.goto(0, 0) head.direction = "stop" # Functions def go_up(): head.direction = "up" def go_right(): head.direction = "right" def go_left(): head.direction = "left" def go_down(): head.direction = "down" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 20) if head.direction == "right": x = head.xcor() head.setx(x + 20) if head.direction == "down": y = head.ycor() head.sety(y - 20) if head.direction == "left": 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() move() time.sleep(delay) wn.mainloop()
@xoxo.lxly.267 күн бұрын
Bro i like your videos very much kep up the good work!!!! Can this work on IDLE?
@TokyoEdTech6 күн бұрын
@@xoxo.lxly.26 Thanks. And yes, it should
@xoxo.lxly.266 күн бұрын
@@TokyoEdTech ok thsnks
@xoxo.lxly.267 күн бұрын
my score is really bad like your first time hwen you didn't add the command "pen.clear" its i cant understand it here is my code import turtle import time import random delay = 0.1 # Score score = 0 high_score = 0 # Set up the Screen wn = turtle.Screen() wn.title("Snake Game by @Rayan_Uddin") 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 = "start" #Snake food food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("yellow") 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) # 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 border 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 segments.clear() # 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) x = head.xcor() # Increase the 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 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() # Check for head collision with the body segments for segment in segments: if segment.distance(head) < 20: time.sleep(1) head.goto(0,0) head.direction = "stop" # Hide the segments for segment in segments: segment.goto(1000,1000) # Clear the segments segments.clear() time.sleep(delay) wn.mainloop()
@TokyoEdTech7 күн бұрын
@@xoxo.lxly.26 Same problem : pen clear()
@xoxo.lxly.267 күн бұрын
@@TokyoEdTech so what do i do?
@xoxo.lxly.268 күн бұрын
my snake can't move right or left it just resatrts here is my code. import turtle import time delay = 0.1 # Set up the Screen wn = turtle.Screen() wn.title("Snake Game by @Unknown_User") 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" # 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.sety(x - 20) if head.direction == "right": x = head.xcor() head.sety(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() move() time.sleep(delay) wn.mainloop()
@TokyoEdTech8 күн бұрын
@@xoxo.lxly.26 In the left and right sections you have sety. It should be setx.
@xoxo.lxly.267 күн бұрын
@@TokyoEdTech thnks bro very much!!!!!!!
@TokyoEdTech7 күн бұрын
@xoxo.lxly.26 You're welcome. Keep on codin' and please subscribe!
@yoshihome10 күн бұрын
help, when I try to add the cookie sprite, it says "couldn't open "cookie.gif": no such file or directory"
@yoshihome10 күн бұрын
here's my code: import turtle wn = turtle.Screen() wn.title("Cookie Clicker by @yoshihome") wn.bgcolor("black") wn.register_shape("cookie.gif") cookie = turtle.Turtle() cookie.shape("cookie.gif") cookie.speed(0) wn.mainloop()
@TokyoEdTech10 күн бұрын
@@yoshihome You have to make sure the image file is in the same folder as the .py file.
@yoshihome10 күн бұрын
@@TokyoEdTech thank you, I'll try
@yoshihome10 күн бұрын
@@TokyoEdTech Thank you soo much, it worked!! :D
@TokyoEdTech10 күн бұрын
@yoshihome You're welcome. Keep on codin' and please subscribe!
@99vikram9910 күн бұрын
hey bro, I want the full coding bro.Because I'm interested fully in python, as well as I am teenager
@TokyoEdTech10 күн бұрын
@@99vikram99 You're gonna have to do it the hard way - follow the tutorial and get it working. There are no shortcuts.
@mishra___vaibhav11 күн бұрын
why you used xstart = 2
@TokyoEdTech11 күн бұрын
As I said in the video it's a guess.
@-Tr41l-11 күн бұрын
when i try use direction it says "AttributeError: 'Turtle' object has no attribute 'direction'"
@TokyoEdTech11 күн бұрын
@@-Tr41l- If you share the code I can take a look.
@-Tr41l-11 күн бұрын
no way bros still replying
@TokyoEdTech11 күн бұрын
@@-Tr41l- I try!
@Cherry_Blossom45312 күн бұрын
Keep it up brother this was so useful for my school competition. Hats off to you I will water all your tutorial.
@TokyoEdTech12 күн бұрын
Glad to hear it. Keep on codin' and please subscribe!
@darkknight-r4g14 күн бұрын
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()
@TokyoEdTech14 күн бұрын
@@darkknight-r4g The new segment section needs to be indented one more level.
@JR_R56016 күн бұрын
Yea I’m cooked
@mamtakurdia525716 күн бұрын
Heyy When i write segments.clear() My segments are disappearing automatically what to do ??
@TokyoEdTech16 күн бұрын
Hi - can you share all the code? Most likely you have an indentation error.
@Alantom-d4b17 күн бұрын
import turtle import random import time delay = 0.1 wn = turtle.Screen() wn.bgcolor('blue') wn.title('SNAKE GAME') wn.setup(600,800) wn.tracer(0) snake = turtle.Turtle() snake.penup() snake.speed(0) snake.shape('square') snake.color('yellow') snake.goto(0,0) food = turtle.Turtle() food.penup() food.speed(0) food.shape('triangle') food.color('sky blue') food.goto(0, -100) def snake_up(): y = snake.ycor() y += 20 snake.sety(y) def snake_down(): y = snake.ycor() y -= 20 snake.sety(y) def snake_left(): x = snake.xcor() x -= 20 snake.setx(x) def snake_right(): x = snake.xcor() x += 20 snake.setx(x) turtle.listen() turtle.onkey(snake_up, 'Up') turtle.onkey(snake_down, 'Down') turtle.onkey(snake_left, 'Left') turtle.onkey(snake_right, 'Right') while True: wn.update() if snake.distance(food) < 20: x = random.randint(-290,290) y = random.randint(-290,290) food.goto(x,y) segment = [] new_segment = turtle.Turtle() new_segment.penup() new_segment.speed(0) new_segment.shape('square') new_segment.color('green') segment.append(new_segment) for index in range(len(segment)-1,0,-1): x = segment[index-1].xcor() y = segment[index-1].ycor() segment[index].goto(x,y) if len(segment) > 0: x = snake.xcor() y = snake.ycor() segment[0].goto(x,y) time.sleep(delay) how to make it grow?
@TokyoEdTech17 күн бұрын
@@Alantom-d4b You have several problems. segment = [] Should be segments = [] Also that line is in the wrong spot. And the indentation is wrong. Watch the video again and pay closet attention.
I've been having a problem with the missile not firing, it will show up in front of the player for a fraction of a second then disappear. here is the full code, any help is greatly appreciated as I need to do this for a school project (yes, we are supposed to be fallowing a tutorial, I'm not cheating) #Mid Term Project (Space Shooter) #------------importing and set up------------- import turtle, os, random window = turtle.Screen() turtle.title("Space Shooter") turtle.speed(0) turtle.bgcolor('black') turtle.ht() #hide default turtle turtle.setundobuffer(1) #saves memory turtle.tracer(1) #this will be used later to speed up drawing #-----------------makeing classes-------------- class Sprite(turtle.Turtle): #pre: #post: create a class for sprites def __init__(self, sSpritShape, sColor, iStartX, iStartY): turtle.Turtle.__init__(self, shape = sSpritShape) self.speed(0) self.penup() self.color(sColor) self.fd(0) self.goto(iStartX, iStartY) self.speed = 1 def Move(self): #pre: a object on screen #post: the abiliy to move forward a set speed + the border of the world self.fd(self.speed) #boundry detection if self.xcor()> 290: self.setx(290) self.right(60) if self.xcor()<-290: self.setx(-290) self.right(60) if self.ycor()> 290: self.sety(290) self.right(60) if self.ycor()< -290: self.sety(-290) self.right(60) #collion detection def 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): #pre: the Sprite class #post: a child of the Sprite class used for the player def __init__(self, sSpritShape, sColor, iStartX, iStartY): Sprite.__init__(self, sSpritShape, sColor, iStartX, iStartY) self.speed = 4 self.lives = 3 #movement def TurnL(self): self.left(45) def TurnR(self): self.right(45) def Accelerate(self): if self.speed < 10: self.speed += 1 def Decelerate(self): if self.speed > 0: self.speed -=1 class Enemy(Sprite): #pre: the Sprite class #post: a class used to control enemies def __init__(self, sSpritShape, sColor, iStartX, iStartY): Sprite.__init__(self, sSpritShape, sColor, iStartX, iStartY) self.speed = 6 self.setheading(random.randint(0,360)) class Missile(Sprite): #pre: the Sprite class #post: a class used to control enemies def __init__(self, sSpritShape, sColor, iStartX, iStartY): Sprite.__init__(self, sSpritShape, sColor, iStartX, iStartY) self.shapesize(stretch_wid = 0.3, stretch_len=0.4, outline = None) self.speed = 20 self.status = 'ready' #fire the missle def Fire_Missile(self): #pre:a missle object at the ready #post:the ability to fire said missile if self.status == 'ready': self.goto(Player.xcor(),Player.ycor()) self.setheading(Player.heading()) self.status = 'firing' #missle movement def Move(self): if self.status == 'ready': self.goto(-1000,1000) if self.status == 'firing': self.forward(self.speed) #border check if self.xcor() <= -290 or self.xcor() >= 290 or \ self.ycor() <= -290 or self.ycor() >= 290: 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 Border(self): 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.forward(600) self.pen.right(90) self.pen.penup() self.pen.ht() #-----------------Creating Game--------------------- game = Game() game.Border() #-----------------Creating Sprites------------------ Player = Player('triangle', 'white', 0, 0) Enemy = Enemy('turtle', 'red', -100, 0) Missile = Missile('triangle', 'yellow', 0,0) #-----------------Keybinds-------------------------- turtle.onkey(Player.TurnL, "Left") turtle.onkey(Player.TurnR, "Right") turtle.onkey(Player.Accelerate, "Up") turtle.onkey(Player.Decelerate, "Down") turtle.onkey(Missile.Fire_Missile, 'space') turtle.listen() #-----------------Main Game Loop-------------------- while True: Player.Move() Enemy.Move() Missile.Move() #collision check with player if Player.Collision(Enemy): Enemy.goto(random.randint(-250,250),random.randint(-250,250)) #check missileto enemy collision if Missile.Collision(Enemy): Enemy.goto(random.randint(-250,250),random.randint(-250,250)) Missile.status = 'ready'
@TokyoEdTech18 күн бұрын
Hiya - The last line is not indented correctly. It should be indented one more level. Good luck with your project. Keep on codin' and please subscribe!
@cannolimaster427315 күн бұрын
@@TokyoEdTech Thank you so much. This fixed the problem
@TokyoEdTech15 күн бұрын
You're welcome.
@lobstermooch536519 күн бұрын
I am running on windows 10. I have pygame installed. the turtle window is always unresponsive.
@TokyoEdTech19 күн бұрын
@@lobstermooch5365 Can you share your code and I'll take a look?
@lobstermooch536519 күн бұрын
@@TokyoEdTech import pygame import random #import the Turtle module import turtle turtle.fd(0) turtle.speed(0) turtle.bgcolor('black') turtle.ht() turtle.setundobuffer(1) turtle.tracer(1) class Sprite(turtle.Turtle): def __init__(self, sprite_shape, color, starx, starty): turtle.Turtle.__init__(self, shape = sprite_shape) self.speed(0) self.penup() self.color(color) self.fd(0) self.goto(starx, starty) self.speed = 1 #create my sprites player = Sprite("triangle", "white", 0, 0) delay = input("Press enter to exit. > ")
@TokyoEdTech19 күн бұрын
@@lobstermooch5365 Hiya - I tried it on my computer (Mac) and it is working fine. I did delete import pygame since this uses the turltle module.
@lobstermooch536518 күн бұрын
@@TokyoEdTech im using pycharm. should I use something else for my IDE?
@Chess_Man10019 күн бұрын
I Don't Exactly Get The dy Function. Can You Please Help Me Understand?
@TokyoEdTech18 күн бұрын
dy is an attribute, not a function. dy means change in y. So, if dy is +1, then every time the main loop executes, the y value increases by 1 which will move the ball up. If dy is -1 then every time the main loop executes the y value decreases by 1 which will move the ball down. Keep on codin' and please subscribe!
@Chess_Man10017 күн бұрын
@@TokyoEdTech Is It A Turtle Attribute Or Did You Use It As A Variable Since I Had To Use One. It Said That dy Isn't A Turtle Attribute.
@TokyoEdTech17 күн бұрын
@ServerInFrench It was added by me in the code - you must have missed it.
@Chess_Man10017 күн бұрын
@@TokyoEdTech Ok Thanks!
@Nothern-p2e24 күн бұрын
I tested it but than when it was bouncing it was cutting the circle while going up or down
@TokyoEdTech23 күн бұрын
If you want to paste the code here I can take a look.
@marshall_1038924 күн бұрын
when i run it says unindent does not match any outer indentation level
@marshall_1038924 күн бұрын
and its the line where it says for index in range(len(segments)- 1, 0, -1):
@TokyoEdTech24 күн бұрын
@@marshall_10389 Can you share your code so I can take a look?
@BananaDope24 күн бұрын
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.
@TokyoEdTech24 күн бұрын
@@BananaDope Here you go: kzbin.info/www/bejne/poeZk56hZrqrf5osi=slfzrgDQm7D0jv4V Thanks for the reminder!
@ThisGuy-up9nd25 күн бұрын
My snake doesnt showup after this part. Not sure what i did wrong
@TokyoEdTech25 күн бұрын
@@ThisGuy-up9nd If you share your code and any error messages I'll take a look.
@ThisGuy-up9nd25 күн бұрын
Why cant I go back up to edit a line of code?
@TokyoEdTech25 күн бұрын
@@ThisGuy-up9nd This will help you get started : kzbin.info/www/bejne/j6aQZ4V6eLRleLssi=L5Mk8NURFuTGaVcm
@Unknownperson3385726 күн бұрын
I'm like super new to Python idk what I'm doing I'm just copying the code. Is it a good way to learn?
@Ledy-Official-g4l23 күн бұрын
Try and copy all the code then ask chat gpt to explain it that is how i am learning but I definetely know that just copying the code and not understanding is a really bad way to learn
@theperson4yearsago56520 күн бұрын
Im in comp sci principals right now, and I'll just say keep going bro you'll get there
@TokyoEdTech18 күн бұрын
Copying is a good way to start, but also listen to the explanation. I wouldn't start with this video - it is intermediate. Keep on codin' and please subscribe!
@digitalcode-web9241Ай бұрын
Bro can you do next part of this series ? please
@TokyoEdTech18 күн бұрын
I'm not sure if/when I'll get back to this. If you've gotten this far, you should be able to make changes and add what you want to the game. Good luck, keep on codin' and please subscribe!
@BooyahАй бұрын
If you're still looking up basic commands, You don't have to make a fucking tutorial.
@sholehuddin9769Ай бұрын
what's the text editor do you use??
@TokyoEdTechАй бұрын
I'm not sure in this view, but these days I use Geany. LINK: kzbin.info/www/bejne/p6bInnyditNneZo
@JC-jn8jzАй бұрын
instead of it, is it possible to display use timer in input function, so the input will stop if the time is above a certain condition
@TokyoEdTechАй бұрын
@@JC-jn8jz Sure - everything in coding comes down to "if this, then that". Just gotta find the right condition.
@hinowitchАй бұрын
the game closes when i hit the food here is my code: import turtle import time import random delay = 0.1 # Set uo the screen wn = turtle.Screen() wn.title("Snake game by hinowitch") 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) # 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() if head.distance(food) < 20: # Move the food to a random spot x = random.randind(-290, 290) y = random.randint(-290, 290) food.goto(x,y) move() time.sleep(delay) wn.mainloop() i would realy apriciate it if you could help me
@hinowitchАй бұрын
if already fixed it with a ai tool it was just a wrong letter
@TokyoEdTechАй бұрын
@@hinowitch Glad you got it sorted. But, there is no need to use AI for this. You need to learn to read the error message. It literally tells you exactly where and what the problem is, and how to fix it. For example: Traceback (most recent call last): File "/Users/teacher/Desktop/help.py", line 151, in <module> x = random.randind(-290, 290) ^^^^^^^^^^^^^^ AttributeError: module 'random' has no attribute 'randind'. Did you mean: 'randint'? Keep on codin' - and please subscribe!
@hinowitchАй бұрын
hello when i press a the game closes but wsd work here is my code: import turtle import time delay = 0.1 # Set uo the screen wn = turtle.Screen() wn.title("Snake game by hinowitch") 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" # 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(y - 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() move() time.sleep(delay) wn.mainloop()
@hinowitchАй бұрын
already figured it out
@TokyoEdTechАй бұрын
Glad to hear it!
@rsb7613Ай бұрын
Please, help me! I did the same code in the same api and all fields come in my calls only the "summary" that not, comes: Star Trek premiered on 1966-09-08. ['summary'] For any movie In time: I am using python 3.12 and VSCode
@TokyoEdTechАй бұрын
@@rsb7613 Can you share the code so I can take a look?
@lordcasper3357Ай бұрын
instead of using turtle just use pygame bro, f*ck turtle
@BabyQuasarXАй бұрын
Second year computer science student and I'm going back to this video because it is helpful. Thanks!
@TokyoEdTechАй бұрын
@@BabyQuasarX I have a master's in comp sci and I have to review my own videos from time to time! Never hurts to review the fundamentals! Keep on codin' and please subscribe!
@BabyQuasarXАй бұрын
@@TokyoEdTech Congrats on the master's degree! It's good to go back to these videos because I'm not coding that much in my spare time. I try to but I just lose motivation.
@TokyoEdTechАй бұрын
@@BabyQuasarX Thanks...and good luck with your studies!
@TokyoEdTechАй бұрын
@@BabyQuasarX Thanks! I feel you on the motivation... It comes and goes!
@sebastianmackay5657Ай бұрын
2 minutes in and it already doesn't work, python doesn't like that raw_input, not defined. Does turtle come preinstalled or do we have to install it first?
@TokyoEdTechАй бұрын
@@sebastianmackay5657 Change raw_input to input
@sebastianmackay5657Ай бұрын
@@TokyoEdTech thanks
@TokyoEdTechАй бұрын
@@sebastianmackay5657 Sure thing. Keep on codin' and please subscribe!
@GoopygoopsАй бұрын
can you please gimme the code so i can past it? :)
@TokyoEdTechАй бұрын
Sorry - you'll have to do it yourself.
@EpicsdafanimationsАй бұрын
How do you run?
@TokyoEdTechАй бұрын
@@Epicsdafanimations Hi! Watch this - it will help you get started. kzbin.info/www/bejne/j6aQZ4V6eLRleLssi=eHwn0I4UiyXwGvlp
@EpicsdafanimationsАй бұрын
Thanks your the goat
@TokyoEdTechАй бұрын
@@Epicsdafanimations Thanks! Keep on codin' and please subscribe! :)