JavaScript Quiz for Beginners
24:53
Simple Java Game Library (Intro)
20:38
Intro to Java and AP CS A - Arrays
17:07
AP CS A Teacher Training - Arrays
12:00
Пікірлер
@alfredwu9523
@alfredwu9523 5 сағат бұрын
Your tutorial is so good that I want to subscribe you a billion time if available
@TokyoEdTech
@TokyoEdTech 3 сағат бұрын
@@alfredwu9523 You're too kind! I never quite finished this one - there are 3 parts bit then you gotta figure it out from there yourself. Good luck!
@alfredwu9523
@alfredwu9523 3 сағат бұрын
@@TokyoEdTech thanks, make more please
@1withSerenity
@1withSerenity Күн бұрын
This video was awesome, really appreciate you sharing it with everyone!
@TokyoEdTech
@TokyoEdTech Күн бұрын
Thanks so much - glad you liked it! Keep on codin' and please subscribe!
@koko-f2k8o
@koko-f2k8o 2 күн бұрын
I need help😅 I don't know how can I make the "Run in Terminal" button please can you tell us how🙏🙏
@koko-f2k8o
@koko-f2k8o 2 күн бұрын
I need help😅 I don't know how can I make the "Run in Terminal" button please can you tell us how🙏🙏
@TokyoEdTech
@TokyoEdTech 2 күн бұрын
@@koko-f2k8o What editor are you using? It depends on what you are using.
@alfredwu9523
@alfredwu9523 2 күн бұрын
thanks for your book, it is REALLY BOOK. just a few weeks before I learn python, I dont even know what is coding. Now after I found in my pc in youtube, searching for videos that could teach me, that time I know your video, and also, after I read your book yesterday, it really help me a lot
@alfredwu9523
@alfredwu9523 2 күн бұрын
Thanks
@kinoHardStyle
@kinoHardStyle 2 күн бұрын
Traceback (most recent call last): File "C:\Users\Desktop\Game\game.py", line 30, in <module> player.move() ^^^^^^^^^^^ AttributeError: 'Sprite' object has no attribute 'move' what is the solution of this? it appears in the line of While true
@vinhthanh9043
@vinhthanh9043 2 күн бұрын
Maybe you should check if your Sprite class missing an attribute 'move'
@TokyoEdTech
@TokyoEdTech 2 күн бұрын
Hiya - you'll need to provide ALL of the code as the error could have multiple different causes.
@alfredwu9523
@alfredwu9523 3 күн бұрын
PLEASE MAKE MORE TUTORIAL GAMES PLEASEEEEE
@TokyoEdTech
@TokyoEdTech 2 күн бұрын
@@alfredwu9523 Do you have any suggestions? And, you might want to subscribe.
@alfredwu9523
@alfredwu9523 2 күн бұрын
@ I subscribe to you once I know this video, and the space war is funnnn I like to play war game controlling infantry and tanks something like this, do you think you can have a try? Thanks for noticing and reading my comment
@alfredwu9523
@alfredwu9523 2 күн бұрын
@@TokyoEdTech and also what app you use to make the script?
@TokyoEdTech
@TokyoEdTech 2 күн бұрын
@@alfredwu9523 Sure thing. The closest I ever got to something like that was this: kzbin.info/www/bejne/b3-ug5mdrt2EasU. There are three parts. It's not a polished tutorial though - I was figuring it out as I went.
@alfredwu9523
@alfredwu9523 2 күн бұрын
@@TokyoEdTech Can you tell me what app you use to do the code?
@rubyhoseinzadeh3843
@rubyhoseinzadeh3843 3 күн бұрын
where did you get the collision sound effect?
@TokyoEdTech
@TokyoEdTech 3 күн бұрын
To be honest I don't remember. But, you could use this: github.com/wynand1004/Projects/blob/master/Space%20Invaders/explosion.wav
@Lootdyman12
@Lootdyman12 6 күн бұрын
Why is my snake not moving when I press a, s, d, w
@TokyoEdTech
@TokyoEdTech 6 күн бұрын
I don't know. But, if you share your code, I can take a look.
@bananaproductions-i1x
@bananaproductions-i1x 6 күн бұрын
please respond quick i dont have all day (sorry for rudeness) i get the error "Player" object has no attribute "move" import os import random #Installing modules import turtle turtle.speed(0) turtle.bgcolor("black") turtle.ht() turtle.setundobuffer(1) turtle.tracer(1) #Sprite Classing and Movement 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 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): #Draws the 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() def move(self): self.fd(self.speed) #Creation of the Game Object game = Game() #Draw game border game.draw_border() class Player(Sprite): def __init__(self, spriteshape, color, startx, starty): Sprite.__init__(self, spriteshape, color, startx, starty) self.speed = 4 self.lives = 3 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, don't touch. while True: player.move() delay = input("Press enter to finish. >")
@bananaproductions-i1x
@bananaproductions-i1x 6 күн бұрын
Now i just added boundary detection (i still havent fixed the previous error) and it said that "self" is not defined
@sutrishadas3279
@sutrishadas3279 6 күн бұрын
hey, I coded this there is no error but when ever i am running this the picture wont show up it did for like less then 1 sec, i don't know what's happening ......the picture wont be displayed
@TokyoEdTech
@TokyoEdTech 6 күн бұрын
@sutrishadas3279 Can you share your code and any error message@
@bananaproductions-i1x
@bananaproductions-i1x 6 күн бұрын
Says invalid syntax at the : infront of the starty when making the indent code block, and when i remove the : it then unidentifies any indents in the code block. Here's my code (i'm up to 7:55) import os import random 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, 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 player = Sprite("triangle", "white", 0, 0) delay = input("Press enter to finish. >")
@bananaproductions-i1x
@bananaproductions-i1x 6 күн бұрын
BTW, im on windows 11, not MacOSX so it could be because of anything mac exclusive
@bananaproductions-i1x
@bananaproductions-i1x 6 күн бұрын
Nevermind! Self-debugged, i forgot the space when defining parent class. Remember guys, put a space after def when writing def__init__(self, spriteshape, color, startx, starty): .
@bolhacska64
@bolhacska64 7 күн бұрын
hello, I'm in a class doing you'r snake game, but wean I write "direction" in like "head.direction = "up"" the "direction" is no in the turtle, I looked all of the command's but "direction" is not there, and if a write it still, doesn't work
@TokyoEdTech
@TokyoEdTech 7 күн бұрын
@@bolhacska64 Can you share you ur code and your error message?
@bolhacska64
@bolhacska64 7 күн бұрын
for some reason, it's saying, that it's not a real thing, but it's still doing it, wth
@bolhacska64
@bolhacska64 7 күн бұрын
btw, here's my code: screen = turtle.Screen() screen.title("Snake Game") screen.bgcolor("green") screen.setup(width=600, height=600) screen.tracer(0) # Snake Head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("grey") head.penup() head.goto(0,0) head.direction = "up" ## Here def move(): if head.direction == "up": ## Here y = head.ycor() head.sety(y + 20) # Main Loop while True: screen.update() move() time.sleep(wait) screen.mainloop()
@bolhacska64
@bolhacska64 7 күн бұрын
it does what it's suppose to, but it's saying no hummm, interesting
@TokyoEdTech
@TokyoEdTech 7 күн бұрын
@@bolhacska64 It is not part of the turtle module or turtle object, but it doesn't matter - we can add our own.
@brinstussy
@brinstussy 8 күн бұрын
Think you forgot to reset the delay for the body collision, unless I missed that part lol.
@TokyoEdTech
@TokyoEdTech 8 күн бұрын
@@brinstussy Thanks for pointing that out! Keep on codin'!
@AlejandroDuhourq
@AlejandroDuhourq 8 күн бұрын
Code: import turtle import time delay = 0.1 wn = turtle.Screen() wn.title("Snake game") wn.bgcolor ("green") 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 = "up" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 20) while True: wn.update() move() error: --------------------------------------------------------------------------- Terminator Traceback (most recent call last) Cell In[6], line 23 20 head.sety(y + 20) 22 while True: ---> 23 wn.update() 25 move() 27 time.sleep(delay) File ~\anaconda3\Lib\turtle.py:1295, in TurtleScreen.update(self) 1293 self._tracing = True 1294 for t in self.turtles(): -> 1295 t._update_data() 1296 t._drawturtle() 1297 self._tracing = tracing File ~\anaconda3\Lib\turtle.py:2654, in RawTurtle._update_data(self) 2653 def _update_data(self): -> 2654 self.screen._incrementudc() 2655 if self.screen._updatecounter != 0: 2656 return File ~\anaconda3\Lib\turtle.py:1284, in TurtleScreen._incrementudc(self) 1282 if not TurtleScreen._RUNNING: 1283 TurtleScreen._RUNNING = True -> 1284 raise Terminator 1285 if self._tracing > 0: 1286 self._updatecounter += 1 Terminator: Please let me know how to fix it please
@TokyoEdTech
@TokyoEdTech 8 күн бұрын
@@AlejandroDuhourq When does the error happen? Suddenly, or when you close the window?
@AlejandroDuhourq
@AlejandroDuhourq 8 күн бұрын
@@TokyoEdTech Sometimes when I close the window, other times the head of the snake doesn´t appear and it just frez maybe is because I am using Jupiter Notebook. Do you recommend my to used python org?
@5OUNDZWAV333
@5OUNDZWAV333 11 күн бұрын
You're the most awesome youtuber ever No extensive explanation, just going with the follow as you code & make mistakes then corrects it, i love this way of teaching & not those youtubers who did not give explanation at all or overexplaining it & it really helps me to complete my project for school :D I really like this series of videos, congrats for a new subscriber❤
@TokyoEdTech
@TokyoEdTech 11 күн бұрын
@@5OUNDZWAV333 Thanks so much! Welcome to the team. Keep on codin'!
@rainbowrain1042
@rainbowrain1042 14 күн бұрын
I’m currently making a game and I don’t have the patience to watch all of your videos to learn how so I’m going to ask these two simple questions question 1. How do you make a window appear? Question 2. How do you add controls? For reference, I am making a game where you have to click as many times as you can in five seconds and depending on your score it says something different
@mukulsehgal2190
@mukulsehgal2190 16 күн бұрын
cool
@TokyoEdTech
@TokyoEdTech 16 күн бұрын
@@mukulsehgal2190 Thanks!
@MelloTheHero
@MelloTheHero 16 күн бұрын
You are an awesome man. keep up the good work.
@TokyoEdTech
@TokyoEdTech 16 күн бұрын
@@MelloTheHero Thanks! Keep on codin' and please subscribe!
@urosstevanovic6044
@urosstevanovic6044 17 күн бұрын
This is awsome however i have problem when i hit the border high score is 0 and then when i eat the first apple it gets back to high score i had
@TokyoEdTech
@TokyoEdTech 17 күн бұрын
@@urosstevanovic6044 Thanks! Can you share your code so I can take a look?
@rajeevkaur891
@rajeevkaur891 18 күн бұрын
Guys use python IDLE Shell 13.3.1 it works on this version. Free to download. I did it on this only. If on pc or laptop, press f5 to run the module…just save it first.
@rajeevkaur891
@rajeevkaur891 18 күн бұрын
Dude nice work…every else youtubers show some error or cut the main part. You show everything to us and explain it. I appriciate your work, i too am a beginner and learnt this programming from you. Thank you😊😊😊
@rajeevkaur891
@rajeevkaur891 18 күн бұрын
Soo mich
@rajeevkaur891
@rajeevkaur891 18 күн бұрын
Much*
@TokyoEdTech
@TokyoEdTech 17 күн бұрын
@@rajeevkaur891 You are quite welcome. It's important to see that nobody codes perfectly the first time - you gotta learn debugging from Day 1. Keep on codin' and please subscribe.!
@theguyintheiceberg129
@theguyintheiceberg129 20 күн бұрын
the snake wont show up
@TokyoEdTech
@TokyoEdTech 20 күн бұрын
If you share your code, I can take a look.
@sunitabaviskar8964
@sunitabaviskar8964 20 күн бұрын
Bro whats is control key of turtle
@TokyoEdTech
@TokyoEdTech 17 күн бұрын
@@sunitabaviskar8964 I'm not sure what you mean? Do you mean the actual CTRL key code?
@TarekKhader-l8n
@TarekKhader-l8n 21 күн бұрын
You are really brilliant, all my regards to you. I am Egyptian and I really liked following your distinguished content 👍👍
@TokyoEdTech
@TokyoEdTech 21 күн бұрын
@@TarekKhader-l8n Thanks - you're too kind! Keep on codin' and please subscribe!
@Than_rik
@Than_rik 22 күн бұрын
Not me learning this ancient language because I need it to pass an exam🙄
@TokyoEdTech
@TokyoEdTech 22 күн бұрын
@Than_rik Good luck! 🤞🍀🙏
@Than_rik
@Than_rik 22 күн бұрын
@TokyoEdTech thanks
@IARRCSim
@IARRCSim 20 күн бұрын
Was the exam part of an ancient history course?
@TokyoEdTech
@TokyoEdTech 20 күн бұрын
@@IARRCSim Hahahahaha!
@itsjipy1d503
@itsjipy1d503 23 күн бұрын
what are you coding on, what program or appilcation? Maybe you can suggest for me other examples to use but your would be just fine.
@TokyoEdTech
@TokyoEdTech 22 күн бұрын
Hiya. These days I use Geany. I did a video about it here: kzbin.info/www/bejne/p6bInnyditNneZosi=D_K7XohkH-5iP2M5 Enjoy!
@itsjipy1d503
@itsjipy1d503 18 күн бұрын
@ thank you so much, appreciate it.
@TokyoEdTech
@TokyoEdTech 17 күн бұрын
@@itsjipy1d503 You're welcome. Keep on codin' and please subscribe!
@erichanson420
@erichanson420 24 күн бұрын
I'd love to see someone document start to finish like, making games or apps in 6502. Just the whole slog. It would be a great resource.
@TokyoEdTech
@TokyoEdTech 24 күн бұрын
@@erichanson420 This guy does it on the NES: kzbin.info/www/bejne/o5-4iYyiaqdsh9Usi=YlQ95TcZ0y_ZF-eE
@thelavagod
@thelavagod 24 күн бұрын
Code editor name??
@Ishu-b1m
@Ishu-b1m 25 күн бұрын
It shows y is not defined shows error
@TokyoEdTech
@TokyoEdTech 25 күн бұрын
@@Ishu-b1m You need to share your code and the entire error message.
@eitanbil
@eitanbil 27 күн бұрын
a better implementation of the "check if task input box is not blank" is doing: if txt_input.get().strip(): tasks.append(txt_input.get()) update_listbox()
@TokyoEdTech
@TokyoEdTech 27 күн бұрын
@eitanbil Thanks for sharing!
@LaMalo17
@LaMalo17 28 күн бұрын
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?
@99vikram99
@99vikram99 29 күн бұрын
bro see this: # Turtle Graphics Game with Scoring System import turtle import random # Define functions def turnleft(): player.left(30) def turnright(): player.right(30) def increasespeed(): global speed speed += 1 def decreasespeed(): global speed speed -= 1 # Update score on screen def update_score(): score_display.clear() score_display.write(f"Score: {score}", align="center", font=("Arial", 24, "normal")) # Create player turtle player = turtle.Turtle() player.color("Darkblue") player.shape("turtle") player.penup() player.speed(0) # Create goal goal = turtle.Turtle() goal.color("orange") goal.shape("circle") goal.penup() goal.speed(0) goal.setpos(random.randint(-250, 250), random.randint(-250, 250)) # Set up screen jack = turtle.Screen() jack.title("Turtle Graphics Game") jack.bgcolor("lightgreen") jack.tracer(0) # Disable auto-update for smoother animation # Draw border mypen = turtle.Turtle() mypen.penup() mypen.setpos(-300, -300) mypen.pendown() mypen.pensize(3) for side in range(4): mypen.forward(600) mypen.left(90) mypen.hideturtle() # Create score display score_display = turtle.Turtle() score_display.hideturtle() score_display.penup() score_display.goto(0, 260) # Position at the top center score_display.color("black") # Initialize variables speed = 1 score = 0 # Initialize the score variable globally # Display the initial score update_score() # Set keyboard bindings jack.listen() jack.onkey(turnleft, "Left") jack.onkey(turnright, "Right") jack.onkey(increasespeed, "Up") jack.onkey(decreasespeed, "Down") # Main game loop def game_loop(): global speed, score player.forward(speed) # Boundary checking if player.xcor() > 300 or player.xcor() < -300: player.right(180) if player.ycor() > 300 or player.ycor() < -300: player.right(180) # Collision checking with goal if player.distance(goal) < 20: goal.setpos(random.randint(-250, 250), random.randint(-250, 250)) score += 1 # Increment score update_score() # Update score display print(f"Goal Reached! Current Score: {score}") # Update the screen jack.update() # Repeat the game loop jack.ontimer(game_loop, 20) # Start the game loop game_loop() # Keep the window open jack.mainloop()
@karmakazegaming1427
@karmakazegaming1427 Ай бұрын
Trying to get my 12yr old son into coding, your video has been a big help. However we have hit a problem around part 7. Each time we lose, the score resets, the high score displays as intended, but when we eat our 1st piece of food in the next game, the score does not go from 0 to 10. It remains at 0 until reaching the previous high score, where it then continues calculating the score and high score together as normal. Any help with this?
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@karmakazegaming1427 Hiya. Sure thing. Can you copy and paste the code so I can take a look?
@karmakazegaming1427
@karmakazegaming1427 29 күн бұрын
@@TokyoEdTech import turtle import time import random delay = 0.1 # Score score = 0 high_score = 0 # Window setup wn = turtle.Screen() wn.title("Snake Game by KarmaKazE") wn.bgcolor("black") wn.setup(width=600, height=600) wn.tracer(0) # 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("yellow") food.penup() food.goto(0,100) segments = [] # Pen pen = turtle.Turtle() pen.speed(0) pen.shape("square") pen.color("red") pen.penup() pen.hideturtle() pen.goto(0, 260) pen.write("Score: 0 High Score: 0", align="center", font=("Comic sans", 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, "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 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 list segments.clear() # Reset the score score = 0 pen.clear() pen.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("Comic sans", 24, "normal")) # Reset the delay delay = 0.1 #Food Collision if head.distance(food) < 20: # Move the food to a random spot x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(random.randint(-290, 290), random.randint(-290, 290)) # 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 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=("Comic sans", 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 list segments.clear() # Reset the score score = 0 pen.clear() pen.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("Comic sans", 24, "normal")) time.sleep(delay) wn.mainloop()
@TokyoEdTech
@TokyoEdTech 29 күн бұрын
@@karmakazegaming1427 The lines pen.clear and pen.write lines after if score > high_score should be unindented one level.
@karmakazegaming1427
@karmakazegaming1427 29 күн бұрын
@@TokyoEdTech works perfectly thank you
@TokyoEdTech
@TokyoEdTech 29 күн бұрын
@karmakazegaming1427 You're welcome. Keep on codin', and please subscribe!
@abedalnaserqouqa
@abedalnaserqouqa Ай бұрын
here is the working code : import turtle import time import random delay = 0.1 wn = turtle.Screen() wn.title("snake game") wn.bgcolor("green") wn.setup(width=600, height=600) wn.tracer(0) head = turtle.Turtle() head.speed(50) 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("red") food.penup() food.goto(0, 100) 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") while True: wn.update() if head.distance(food) < 20: x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(x, y) move() time.sleep(delay) wn.mainloop()
@Chessguy6969
@Chessguy6969 Ай бұрын
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_Lov4
@Manga_Lov4 Ай бұрын
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()
@jadeabove
@jadeabove Ай бұрын
I squealed a bit too loud when I got the "Player" to move. :p
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@jadeabove It's a great feeling! Keep on codin'!
@dudewhatthe2632
@dudewhatthe2632 Ай бұрын
my snake not moving
@dudewhatthe2632
@dudewhatthe2632 Ай бұрын
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()
@dudewhatthe2632
@dudewhatthe2632 Ай бұрын
don't know what i did wrong pls help me
@dudewhatthe2632
@dudewhatthe2632 Ай бұрын
luv your vids
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@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'!
@valhurts
@valhurts Ай бұрын
That's crazy this vid is 8 years rn
@TokyoEdTech
@TokyoEdTech Ай бұрын
Wow - time flies!
@The-MaliX
@The-MaliX Ай бұрын
help me I type pen.hideturtle() but i get Exception has occurred: TypeError TPen.hideturtle() missing 1 required positional argument: 'self'
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@The-MaliX Can you copy and paste all of your code so I can take a look?
@The-MaliX
@The-MaliX Ай бұрын
@@TokyoEdTech import turtle wn = turtle.Screen() wn.title("Cookie Clicker") wn.bgcolor("black") wn.register_shape("Cookie.gif") cookie = turtle.Turtle() cookie.shape("Cookie.gif") cookie.speed(0) clicks = 0 pen = turtle.Turtle pen.hideturtle() pen.color("white") pen.penup() pen.goto(0, 400) pen.write(f"Clicks: {clicks}", align="center", font=("Courier new", 32, "normal")) def clicked(x, y): global clicks clicks += 1 pen.clear() pen.write(f"Clicks: {clicks}", align="center", font=("Courier new", 32, "normal")) cookie.onclick(clicked) wn.mainloop()
@alomchakma605
@alomchakma605 Ай бұрын
My snake is not moving
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@alomchakma605 If you copy and paste your code, I can take a look
@SohamKapdi-j1d
@SohamKapdi-j1d Ай бұрын
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
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@SohamKapdi-j1d If you share all the code I can take a look.
@SohamKapdi-j1d
@SohamKapdi-j1d Ай бұрын
@@TokyoEdTech what should i am not able send the link to the code
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@SohamKapdi-j1d You can copy and paste it here
@SohamKapdi-j1d
@SohamKapdi-j1d Ай бұрын
@@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_Kayl36
@Bubble_Kayl36 Ай бұрын
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()
@TokyoEdTech
@TokyoEdTech Ай бұрын
@Bubble_Kayl36 Hi. Yes, could you provide all the code so I can test it?
@Bubble_Kayl36
@Bubble_Kayl36 Ай бұрын
@@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
@LarryTheWeirdone
@LarryTheWeirdone Ай бұрын
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?
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@LarryTheWeirdone Can you copy and paste the code and the error message?
@LarryTheWeirdone
@LarryTheWeirdone Ай бұрын
@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
@TokyoEdTech
@TokyoEdTech Ай бұрын
@LarryTheWeirdone All good - glad you got it sorted!
@COOLGAMING416
@COOLGAMING416 Ай бұрын
Sir can u pls provide source code of this
@TokyoEdTech
@TokyoEdTech Ай бұрын
@COOLGAMING416 Sure - here you go: github.com/wynand1004/Projects/tree/master/SpaceWar
@COOLGAMING416
@COOLGAMING416 Ай бұрын
Thnx a lot sir
@SohamKapdi-j1d
@SohamKapdi-j1d Ай бұрын
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
@TokyoEdTech
@TokyoEdTech Ай бұрын
Use .clear on the pen turtle. Then redraw all the text.
@SohamKapdi-j1d
@SohamKapdi-j1d Ай бұрын
@@TokyoEdTech thanks 😊😊
@MelloTheHero
@MelloTheHero Ай бұрын
turn.listen() doesn't work?
@TokyoEdTech
@TokyoEdTech Ай бұрын
Hi. There is no turn.listen() - it should probably be turtle.listen()
@saturn5tony
@saturn5tony Ай бұрын
An fyi, the little indian format is the way the 6502 deals with a 16 bit number. Thanks for sharing !
@TokyoEdTech
@TokyoEdTech Ай бұрын
@@saturn5tony Cheers - thanks for the info!