Тёмный
TokyoEdtech
TokyoEdtech
TokyoEdtech
Подписаться
Welcome to TokyoEdtech's RU-vid channel! I am a middle and high school computer science teacher and I make computer programming tutorials, mostly in Python (and sometimes Java). My tutorials are mostly beginner-friendly and focus on making simple games, simple apps, and computer science principles.

Become a channel member and support more great coding content by clicking here: ru-vid.com/show-UC2vm-0XX5RkWCXWwtBZGOXgjoin

JavaScript Quiz for Beginners
24:53
5 месяцев назад
Simple Java Game Library (Intro)
20:38
5 месяцев назад
Intro to JavaScript Playing Sound Files
18:41
7 месяцев назад
Intro To JavaScript for Absolute Beginners
13:53
8 месяцев назад
Intro to AI: Measuring Euclidean Distance
25:30
8 месяцев назад
Intro to AI: Constraint Satisfaction Problems
26:12
8 месяцев назад
AP CS A Teacher Training - Arrays
12:00
Год назад
Комментарии
@Epicsdafanimations
@Epicsdafanimations 7 часов назад
How do you run?
@AbdullahKhalil-k5v
@AbdullahKhalil-k5v 17 часов назад
hi my snake is leaving a line behinde it after adding segments
@TokyoEdTech
@TokyoEdTech 17 часов назад
@@AbdullahKhalil-k5v Can you share the code and I'll take a look?
@somethingoofty5660
@somethingoofty5660 18 часов назад
for anyone who needs to delete the segments for segment in segments: segment.hideturtle() segments.clear()
@TokyoEdTech
@TokyoEdTech 18 часов назад
@@somethingoofty5660 thanks! Make sure the indentation is correct.
@somethingoofty5660
@somethingoofty5660 14 часов назад
@@TokyoEdTech no problem :)
@AhmedMemon-s1u
@AhmedMemon-s1u 3 дня назад
Absolutely love you, sir! ❤ So glad to see you back after such a long time! 🎉
@TokyoEdTech
@TokyoEdTech 3 дня назад
@@AhmedMemon-s1u Thanks - glad to be back!
@4sQuizzes
@4sQuizzes 4 дня назад
i attempted this in python shell and it manually went through and showed me all the tries and then crashed. 💀 Thank you for the video though
@TokyoEdTech
@TokyoEdTech 3 дня назад
@@4sQuizzes If you share your code and any error messages here I can take a look.
@4sQuizzes
@4sQuizzes 3 дня назад
@@TokyoEdTech import random print ("Cryptarithmetic Puzzle") while True: # Choose random values S= random.randint (0,9) E= random.randint (0,9) N= random.randint (0,9) D= random.randint (0,9) M= random.randint (0,9) O= random.randint (0,9) R= random.randint (0,9) Y= random.randint (0,9) #Did we find a solution SEND = S * 1000 + E * 100 + N * 10 + D MORE = M * 1000 + O * 100 + R * 10 + E MONEY = M * 10000 + O * 1000 + N * 100 + E * 10 + Y if SEND + MORE == MONEY: break print(f" {S} {E} {N} {D}") print(f"+ {M} {O} {R} {E}") print(f"---------------------") print(f" {M} {O} {N} {E} {Y}")
@TokyoEdTech
@TokyoEdTech 3 дня назад
@@4sQuizzes Hi. The print statements should not be indented at all.
@4sQuizzes
@4sQuizzes 3 дня назад
@@TokyoEdTech ahh thank you
@TokyoEdTech
@TokyoEdTech 3 дня назад
@@4sQuizzes You are welcome.
@yingtang-s6q
@yingtang-s6q 5 дней назад
I don not know how to reduce the speed of the ball
@TokyoEdTech
@TokyoEdTech 5 дней назад
Hiya. Change dx and dy to smaller values such as 0.01
@Komradenter
@Komradenter 5 дней назад
I came around as python beginner which already did some small project in pygame. This is actually great stuff to help me better practice arrays and understand logic of python. Thank you even after 9 years your YT video is helping dum dums like me.
@TokyoEdTech
@TokyoEdTech 5 дней назад
@@Komradenter Thanks - very nice of you to say. Glad to hear the video helped. Keep on codin' and please subscribe!
@otbwtf17
@otbwtf17 6 дней назад
Hey Tokyo! I was waiting for a new video. I enjoy these! Good video!
@TokyoEdTech
@TokyoEdTech 6 дней назад
@@otbwtf17 Thanks - much appreciated! Keep on codin' and please subscribe!
@sangeetaanand1
@sangeetaanand1 6 дней назад
My player is not showing up on the screen,only rarely it does import os import random import turtle turtle.fd(0) turtle.speed(0) turtle.bgcolor("black") turtle.ht() turtle.setundobuffer(1) turtle.tracer(1) delay = input('entter a key to end') 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,shape= spriteshape,color=color,startx=startx,starty=starty) self.speed = 4 self.lives = 3 player = Player( spriteshape="triangle", color="white", startx= 0, starty= 0 ) while True: player.move()
@sangeetaanand1
@sangeetaanand1 6 дней назад
i use vs code,hence there is no 'raw_input" but it was working perfectly till now
@TokyoEdTech
@TokyoEdTech 6 дней назад
@@sangeetaanand1 Hi! You don't need the delay line - delete it. Also, you've copied the class Player code wrong. See the correct code here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-_tnYXAJGIvU.htmlsi=eOThfZg4sOMjcnxd&t=305
@gtr_xt
@gtr_xt 7 дней назад
very nice guide
@TokyoEdTech
@TokyoEdTech 7 дней назад
@@gtr_xt Thanks - keep on codin' and please subscribe!
@carloscuebas1306
@carloscuebas1306 8 дней назад
need a how to keep hight score after game over
@TokyoEdTech
@TokyoEdTech 8 дней назад
@@carloscuebas1306 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GC50dexQsRo.html
@SadidKingYT
@SadidKingYT 13 дней назад
Love you man really helped
@TokyoEdTech
@TokyoEdTech 13 дней назад
@@SadidKingYT Great to hear! Keep on codin' and please subscribe!
@laayad1
@laayad1 13 дней назад
i made it corectlly
@TokyoEdTech
@TokyoEdTech 13 дней назад
@@laayad1 Awesome! Keep on codin' and please subscribe!
@NutcasePodcast77
@NutcasePodcast77 16 дней назад
Do you still live in Tokyo?
@TokyoEdTech
@TokyoEdTech 16 дней назад
@@NutcasePodcast77 Yep. I am at the metro station now waiting for my train.
@doodlemelon_animator
@doodlemelon_animator 18 дней назад
Hi! I dont know if you are still replying to comments on this video, but when I type Head.direction “Direction” Isnt a thing, I would appreciate if you could help me, thank you!
@TokyoEdTech
@TokyoEdTech 18 дней назад
@@doodlemelon_animator Sure thing. Can you paste in all of the code so I can take a look?
@LearncodeObaid
@LearncodeObaid 18 дней назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-MIaEVIGR5NY.htmlsi=-JfrmPeDhLcUJ02M
@LearncodeObaid
@LearncodeObaid 18 дней назад
Python Project free source code on my youtube channel
@LearncodeObaid
@LearncodeObaid 18 дней назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-MIaEVIGR5NY.htmlsi=-JfrmPeDhLcUJ02M
@LearncodeObaid
@LearncodeObaid 18 дней назад
Python Project free source code on my youtube channel
@goofyworld5410
@goofyworld5410 19 дней назад
you are one of the best python tubers you explained clearlyu and went straight to the point subbed! :D
@TokyoEdTech
@TokyoEdTech 19 дней назад
@@goofyworld5410 Cheers - keep on codin'!
@goofyworld5410
@goofyworld5410 19 дней назад
also somehow it moves up and down just fine but when i press a or d it just teleports about like 30-40 pixels away in that direction reply pls
@goofyworld5410
@goofyworld5410 19 дней назад
There was two d's in the keyboard bindings
@mikayelalikhanyan1587
@mikayelalikhanyan1587 21 день назад
I'm not able to go into replit, and I didn't go anywhere as the signup feature took me to a blank page, I did go to your : Download the code here and I'm not sure what to do there man
@TokyoEdTech
@TokyoEdTech 21 день назад
@@mikayelalikhanyan1587 Sorry, I can't help with repl.it. You can try a different browser to see if they helps. Otherwise contact their customer support. The link takes you to s page with the programs I wrote in the video. You can read them or download them or copy and paste into repl once you get out working.
@mikayelalikhanyan1587
@mikayelalikhanyan1587 17 дней назад
@@TokyoEdTech ok, honestly i think text editor could work as a basic ide to run your code
@TokyoEdTech
@TokyoEdTech 17 дней назад
@@mikayelalikhanyan1587 You can edit the code there, but running it is a different story.
@matthayes8257
@matthayes8257 22 дня назад
Do you have any idea why the missile is not firing? i think "self.goto(-1000, 1000) is where its going wrong but not 100%, heres the full code. import os import random #import 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, 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) #boundary 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: 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)) #missile 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 == "firing": self.fd(self.speed) 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 sprite player = Player("triangle", "white", 0, 0) enemy = Enemy ("circle", "red", -100,0) missile = missile ("triangle","yellow", 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 player if player.is_collision(enemy): x = random.randint(-250, 250) y = random.randint(-250, 250) enemy.goto(x, y) #check for missile collison with enemy if player.is_collision(enemy): x = random.randint(-250, 250) y = random.randint(-250, 250) enemy.goto(x, y) delay = raw_input("Press enter to finish")
@TokyoEdTech
@TokyoEdTech 22 дня назад
@@matthayes8257 Hiya. You have: self.status = "ready" And: self.status = "Ready" They should both be "ready" Keep on codin'...and please subscribe.
@nut4935
@nut4935 23 дня назад
I will like to speak to your manager I have type 1 one autism and did not understand😇🥰🥰🥰😇
@TokyoEdTech
@TokyoEdTech 23 дня назад
@@nut4935 Sorry, the manager is on vacation...
@edwinquaihoi8503
@edwinquaihoi8503 23 дня назад
syntax casing isn't a language feature, you could use camel case in Python if you wanted
@TokyoEdTech
@TokyoEdTech 23 дня назад
You are correct - you can use whatever casing you want to use; the compiler/interpreter does not care. However, each language has its own casing convention that you should follow - especially when working with others or when planning to share your code. In the case of Python it is found in PEP8: peps.python.org/pep-0008/#prescriptive-naming-conventions In the case of Java it is found here: www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
@edwinquaihoi8503
@edwinquaihoi8503 23 дня назад
@@TokyoEdTech standards are nice, thanks for the series
@TokyoEdTech
@TokyoEdTech 23 дня назад
@@edwinquaihoi8503 Sure thing - keep on codin'!
@colebuzz
@colebuzz 25 дней назад
hello i tried to put some of my own twists and change the game abit for a more of a challange so i didnt copy the exact code,but i have a problem with the scoring system it doesnt go up for me import turtle import time import random delay = 0.1 score = 0 high_score = 0 wn = turtle.Screen() wn.title("square annihilation") wn.bgcolor("black") wn.setup(width=600, height=600) wn.tracer(0) # character head = turtle.Turtle() head.shape("circle") head.color("blue") head.penup() head.goto(0,0) head.direction = "stop" 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) if head.direction == "upright": x=head.xcor() head.setx(x + 12) y=head.ycor() head.sety(y + 12) def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_left(): head.direction = "left" def go_right(): head.direction = "right" robot = turtle.Turtle() robot.shape("triangle") robot.color("green") robot.penup() robot.goto(0,0) 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=("courier", 24, "normal")) bomb = turtle.Turtle() bomb.shape("square") bomb.color("red") bomb.penup() bomb.goto(0,0) 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.xcor()>290 or head.xcor()<-290 or head.ycor() > 290 or head.ycor() < -290: head.goto(0,0) head.direction="stop" if head.distance(bomb) < 20: head.goto(0,0) head.direction= "stop" if head.distance(robot) < 20: a= random.randint(-290,290) b= random.randint(-290,290) robot.goto(a,b) x= random.randint(-290,290) y= random.randint(-290,290) bomb.goto(x,y) score = score + 1 if score > high_score: score = high_score pen.clear() pen.write("score: {} high score: {}".format(score, high_score), align="center", font=("courier", 24, "normal")) if x==a and y==b: x= random.randint(-290,290) y= random.randint(-290,290) bomb.goto(x,y) score pen.clear() pen.write("Score: {} High Score: {}".format(score, high_score), align = "center", font =("Courier", 24, "normal")) move() time.sleep(delay) wn.mainloop()
@TokyoEdTech
@TokyoEdTech 24 дня назад
Hiya - This is great - I love seeing people take an idea and add their own personal touch. You have two problems. 1. You have score sitting there by itself. This isn't a real problem, but I'd get rid of it. 2. You have: if score > high_score: score = high_score It should be: if score > high_score: high_score = score If you think about it a bit it should make sense. Keep on codin'!
@eillieel8870
@eillieel8870 29 дней назад
I have been in part 6 but I touch the food three times and at the three times, it stopped. What should I do?
@eillieel8870
@eillieel8870 29 дней назад
Here is my code import turtle import time import random delay = 0.1 # Set up the screen wn = turtle.Screen() wn.title("Snake Game by @tokyoEdtech ") wn.bgcolor("green") wn.setup(width=600, height=600) wn.tracer(0) # Turns off the screen updates # Snake head head = turtle.Turtle() head.speed(0.2) head.shape("square") head.color("black") head.penup() head.goto(0,0) head.direction = "stop" # Snake food food = turtle.Turtle() food.speed(0.2) 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 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 = () # 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 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 = () time.sleep(delay) wn.mainloop()
@TokyoEdTech
@TokyoEdTech 27 дней назад
@@eillieel8870 Hiya, At two parts of your program, you have segments = () It should be: segments = [] There are also some indentation errors you'll need to fix.
@SonaliRamsumar
@SonaliRamsumar Месяц назад
not sure if you'll still read this but can you post the code for us in the comments?
@TokyoEdTech
@TokyoEdTech Месяц назад
Hiya - the link is in the comments. Enjoy!
@rashidibby
@rashidibby Месяц назад
does this still work on turtle 2024?
@TokyoEdTech
@TokyoEdTech Месяц назад
Mostly. Change delay = raw_input() to wn.mainloop() Also, left -> Left or Left -> left in the keyboard section. Other than that, you should be fine.
@sarcasticstartrek7719
@sarcasticstartrek7719 Месяц назад
27:45 that close parenthesis automatically being typed made me snort :D I bet you pressed delete just as you were about to write a semi colon :D
@TokyoEdTech
@TokyoEdTech Месяц назад
@@sarcasticstartrek7719 All the time!
@ratedfrog476
@ratedfrog476 Месяц назад
I did the whole thing and this came up Traceback (most recent call last): File import.pxi, line 20, in java.chaquopy.import_override
@TokyoEdTech
@TokyoEdTech Месяц назад
@@ratedfrog476 I'm not sure why it says java here. How are you running this?
@ratedfrog476
@ratedfrog476 Месяц назад
@TokyoEdTech I'm using python
@TokyoEdTech
@TokyoEdTech Месяц назад
@@ratedfrog476 What program are you using to write the code? What operating system?
@ratedfrog476
@ratedfrog476 Месяц назад
@@TokyoEdTech pycharm
@AshleyBrown-d9y
@AshleyBrown-d9y Месяц назад
import turtle import time delay = 0.1 wn = turtle.Screen() wn.title("Snake Game by @TokyoEdTech") 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 = "stop" 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) 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() move() time.sleep(delay) wn.mainloop() but im dont run
@TokyoEdTech
@TokyoEdTech Месяц назад
Hiya. There is a difference between = and == You have: def go_up(): head.direction == "up" It should be: def go_up(): head.direction = "up" When comparing you use ==, but when assigning you use =
@yashkr4137
@yashkr4137 Месяц назад
excuse me Mr. TokyoEdtech well that border that you are talking about does not appear to be working on my PC because I'm using Python 3.12.5? or something else?
@TokyoEdTech
@TokyoEdTech Месяц назад
@@yashkr4137 Can you share the code and I'll take a look.
@Miabukk
@Miabukk 18 дней назад
@@TokyoEdTech i have the same problem: 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) #Boundary detection if self.xcor() > 290: self.setx(290) self.rt(60) if self.xcor() < -290: self.setx(-290) self.lt(60) if self.ycor() > 290: self.sety(290) self.rt(60) if self.ycor() < -290: self.sety(-290) self.rt(60) class Player(Sprite): def __init__(self, spriteshape, color, startx, starty): Sprite.__init__(self, shape = spriteshape) 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(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, 'a') turtle.onkey(player.turn_right, 'd') turtle.onkey(player.turn_accelerate, 'w') turtle.onkey(player.turn_deccelerate, 's') turtle.listen() #Main game loop while True: player.move() delay = raw_input('Press Enter to finish. >')
@TokyoEdTech
@TokyoEdTech 18 дней назад
@@Miabukk You have to explain a little better - the program is not working at all, not just the border. I got the following error: Traceback (most recent call last): File "/Users/teacher/Desktop/help.py", line 195, in <module> game. draw_border() ^^^^^^^^^^^^^^^^^ AttributeError: 'Game' object has no attribute 'draw_border' ANyhoo, I tried fixing it, but there were too many mistakes - some were incorrect indentation, others you just copied wrong. If you follow along with the video, you should be testing each part as you add it so you don't end up with so many problems at once. There is a link in the description to the correct code, I'd suggest starting there and moving forward carefully.
@Miabukk
@Miabukk 17 дней назад
@@TokyoEdTech ty i got it working now. Its crazy you still respond to comments even when the video is 8 years old, thank you
@TokyoEdTech
@TokyoEdTech 17 дней назад
@@Miabukk Glad to hear it! Keep on codin'..and please subscribe!
@shripalmehta
@shripalmehta Месяц назад
multi line comments can be done using """ and """.
@TokyoEdTech
@TokyoEdTech Месяц назад
@@shripalmehta Technically speaking, they are doc strings. For comments, each line begins with a hashtag. REF: peps.python.org/pep-0008/#comments
@Ben-tj3vp
@Ben-tj3vp Месяц назад
File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 33 move( ) ^ IndentationError: unindent does not match any outer indentation level
@TokyoEdTech
@TokyoEdTech Месяц назад
@@Ben-tj3vp The error message is pretty clear. Check your indentation - could be off by a space.
@g1dalmatia
@g1dalmatia Месяц назад
For anyone who may have had trouble getting set up I figured I might just write what happened to me and how I fixed it for reference. I am using Mac OS Sonoma with an intel processor. I already had homebrew installed on my laptop along with python 3.9.6. When I first ran the code in IDE, VS Code that is displayed at 2:38 I was only seeing a small grey box. It took a while but I trouble shot this by using homebrew to uninstall python and then reinstall. (I did not uninstall the Mac OS default Python file). Then I did the same with VS code. I also installed pyenv and tcl-tk with homebrew(honestly not sure if this helped with anything.) After doing this I made an alias in my ~/.zshrc file to have the command python point to python3 in my usr/local/bin so that whenever I use python in the terminal it now points to the newer version (3.12.5) instead of the system default I found that solution on stackoverlfow.com Lastly in VS Code I had to choose the version of python I wanted to use which is done down at the bottom right hand corner next to the interpreter selector. Using 3.9.6 was still an option but this version didn't work at all and threw an error message about a deprecating package and didn't even let me hit enter to exit, I did change delay = raw_input() to just input() and so using 3.12 works perfectly so far no problems. I hope this is clear enough to help someone (:
@sergeyvolkov2209
@sergeyvolkov2209 Месяц назад
If your code doesn't work see if there are 2 _ besides the init because it needs 2 _ instead of 1
@TokyoEdTech
@TokyoEdTech Месяц назад
@@sergeyvolkov2209 Good advice!
@duygukaratas8339
@duygukaratas8339 Месяц назад
I will seriously pray for your health. I found this code in geeksforgeeks but i didn't get it. I scaned phyton books for 2 days but it didn't work for me. I appreciate a lot. You have a detailed and descriptive explanation. I will definetely follow your videos.💝💝💝🥰
@DOGPERSON4
@DOGPERSON4 Месяц назад
doestnt work. too many bugs in code. guess thast what i get for using a videoe from 8 years ago
@TokyoEdTech
@TokyoEdTech Месяц назад
@@DOGPERSON4 I think the code is probably fine - this tutorial is still surprisingly popular. However, compared to my other videos, it is not as beginner friendly. If you want to share your code and error messages, I can take a look and point you in the right direction.
@YashwanthG666
@YashwanthG666 Месяц назад
Sir i am not able to add images in the code can u guide me wth the steps
@TokyoEdTech
@TokyoEdTech Месяц назад
@@YashwanthG666 Make sure the images are in the same folder as the game file. I am assuming you are using a laptop or desktop.
@UlsterHVF
@UlsterHVF Месяц назад
🐕
@UlsterHVF
@UlsterHVF Месяц назад
Ђгђ дкшсксђјфп.
@RioKhandual
@RioKhandual Месяц назад
Sorry, but when I hit the border, there is an error, my code import turtle import time import random delay = 0.1 #Set up the screen windows = turtle.Screen() windows.title("If your score is 1,000 ") windows.bgcolor("green") windows.setup(width=600, height=600) windows.tracer(0) #Snake Head Head = turtle.Turtle() Head.speed(0) Head.shape("square") Head.color("yellow") 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 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) def go_up(): Head.direction = "up" def go_down(): Head.direction = "down" def go_right(): Head.direction = "right" def go_left(): Head.direction = "left" #Keyboard Bindings windows.listen() windows.onkeypress(go_up, "Up") windows.onkeypress(go_down, "Down") windows.onkeypress(go_left, "Left") windows.onkeypress(go_right, "Right") #Main Game Loop while True: windows.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 segments in segments: segments.goto(1000, 1000) #Clear the segments list segments.clear() 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) #make a new segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("dark grey") new_segment.penup() segments.append(new_segment) #Move the end segments first in reverse order for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycor() segments[index].goto(x, y) #Move segment 0 to where the head is if len(segments) > 0: x = Head.xcor() y = Head.ycor() segments[0].goto(x, y) move() time.sleep(delay) windows.mainloop()
@RioKhandual
@RioKhandual Месяц назад
Can you please help me
@RioKhandual
@RioKhandual Месяц назад
It says the turtle has no len
@TokyoEdTech
@TokyoEdTech Месяц назад
@@RioKhandual Hiya. Change: for segments in segments: To: for segment in segments: Keep on codin'!
@RioKhandual
@RioKhandual Месяц назад
@@TokyoEdTech Thanks, it is working now!
@TokyoEdTech
@TokyoEdTech Месяц назад
@@RioKhandual You're welcome!
@jonipynnonen4942
@jonipynnonen4942 Месяц назад
It says Player.turn_left() missing 1 required positional afrument: ”self” turtle.onkey(Player.turn_left, ”Left”) is the line
@TokyoEdTech
@TokyoEdTech Месяц назад
@@jonipynnonen4942 Can you share all of th code so I can take a look?
@heinzandberg2716
@heinzandberg2716 Месяц назад
I'm getting started in teaching myself to code. At the moment I'm using Python. Could you guys maybe help me out in figuring out what you call the program that he is using to code and if it's free to use. It might come off as a stupid question for some of you experienced coders, but I am just starting out and I am very much interested in giving this a go. Thank you very much!
@TokyoEdTech
@TokyoEdTech Месяц назад
@@heinzandberg2716 Everybody has to start somewhere. Try this video first : ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Yu-6RDCO2BY.htmlsi=tk4pMOmLvUJPo7lm
@faloudealekk
@faloudealekk Месяц назад
i loved it thank you
@TokyoEdTech
@TokyoEdTech 23 дня назад
You're welcome - keep on codin"!
@funfill1985
@funfill1985 16 дней назад
​@@TokyoEdTech Wow ur still replying omg
@TokyoEdTech
@TokyoEdTech 16 дней назад
@@funfill1985 Yep, I try! Keep on codin' and please subscribe!
@simonechannel4148
@simonechannel4148 Месяц назад
File "c:\Users\simon\Desktop\Games\SpaceArena.py", line 276, in <module> game.start_level() File "c:\Users\simon\Desktop\Games\SpaceArena.py", line 39, in start_level x = random.randint(-self.width/2, self.width/2) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\simon\AppData\Local\Programs\Python\Python312\Lib andom.py", line 336, in randint return self.randrange(a, b+1) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\simon\AppData\Local\Programs\Python\Python312\Lib andom.py", line 301, in randrange istart = _index(start) ^^^^^^^^^^^^^ TypeError: 'float' object cannot be interpreted as an integer. Thats the error code. Code: import turtle import math import random SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 wn = turtle.Screen() wn.setup(SCREEN_WIDTH, SCREEN_HEIGHT) wn.title("Space Arena by Simon Alfonzo") wn.bgcolor("black") wn.tracer(0) pen = turtle.Turtle() pen.speed(0) pen.shape("square") pen.color("white") pen.penup() pen.hideturtle() class Game(): def __init__(self, width, height): self.width = width self.height = height self.level = 1 def start_level(self): sprites.clear() # Add player sprites.append(player) # Add missile sprites.append(missile) # Add enemies for _ in range(self.level): x = random.randint(-self.width/2, self.width/2) y = random.randint(-self.height/2, self.height/2) dx = random.randint(-2, 2) dy = random.randint(-2, -2) sprites.append(Enemy(x, y, "square", "red")) sprites[-1].dx = dx sprites[-1].dy = dy def render_border(self, pen): pen.color("white") pen.width(3) pen.penup() left = -self.width/2.0 right = self.width/2.0 top = self.height/2.0 bottom = -self.height/2.0 pen.goto(left, top) pen.pendown() pen.goto(right, top) pen.goto(right, bottom) pen.goto(left, bottom) pen.goto(left, top) pen.penup() class Sprite(): # Constructor def __init__(self, x, y, shape, color): self.x = x self.y = y self.shape = shape self.color = color self.dx = 0 self.dy = 0 self.heading = 0 self.da = 0 self.thrust = 0.0 self.acceleration = 0.001 self.health = 100 self.max_health = 100 self.width = 20 self.height = 20 def is_collision(self, other): if self.x < other.x + other.width and\ self.x + self.width > other.x and\ self.y < other.y + other.height and\ self.y + self.height > other.y: return True else: return False def update(self): self.heading += self.da self.heading %= 360 self.dx += math.cos(math.radians(self.heading)) * self.thrust self.dy += math.sin(math.radians(self.heading)) * self.thrust self.x += self.dx self.y += self.dy self.border_check() def border_check(self): if self.x > game.width/2.0 - 10: self.x = game.width/2.0 - 10 self.dx *= -1 elif self.x < -game.width/2.0 + 10: self.x = -game.width/2.0 + 10 self.dx *= -1 if self.y > game.height/2.0 - 10: self.y = game.height/2.0 - 10 self.dy *= -1 elif self.y < -game.height/2.0 + 10: self.y = -game.height/2.0 + 10 self.dy *= -1 def render(self, pen): pen.goto(self.x, self.y) pen.setheading(self.heading) pen.shape(self.shape) pen.color(self.color) pen.stamp() self.render_health_meter(pen) def render_health_meter(self, pen): # Draw health meter pen.goto(self.x - 10, self.y + 20) pen.width(3) pen.pendown() pen.setheading(0) if self.health/self.max_health < 0.3: pen.color("red") elif self.health/self.max_health < 0.7: pen.color("yellow") else: pen.color("green") pen.fd(20 * (self.health/self.max_health)) if self.health != self.max_health: pen.color("grey") pen.fd(20 * ((self.max_health-self.health)/self.max_health)) pen.penup() class Player(Sprite): def _init_ (self, x, y, shape, color): Sprite.__init__(self, 0, 0, shape, color) self.Lives = 3 self.score = 0 self.heading = 90 self.da = 0 def rotate_left(self): self.da = 0.35 def rotate_right(self): self.da = -0.35 def stop_rotation(self): self.da = 0 def accelerate(self): self.thrust += self.acceleration def decelerate(self): self.thrust = 0.0 def fire(self): missile.fire(self.x, self.y, self.heading, self.dx, self.dy) def render(self, pen): pen.shapesize(0.5, 1.0, None) pen.goto(self.x, self.y) pen.setheading(self.heading) pen.shape(self.shape) pen.color(self.color) pen.stamp() pen.shapesize(1.0, 1.0, None) self.render_health_meter(pen) class Enemy(Sprite): def _init_ (self, x, y, shape, color): Sprite.__init__(self, x, y, shape, color) class Powerup(Sprite): def _init_ (self, x, y, shape, color): Sprite.__init__(self, x, y, shape, color) class Missile(Sprite): def _init_ (self, x, y, shape, color): Sprite.__init__(self, x, y, shape, color) self.state = "ready" self.fuel = 100 self.thrust = 1.0 self.max_fuel = 200 self.fuel = self.max_fuel self.height = 4 self.width = 4 def fire(self, x, y, heading, dx, dy): if self.state == "ready": self.state = "active" self.x = x self.y = y self.heading = heading self.dx = dx self.dy = dy self.dx += math.cos(math.radians(self.heading)) * self.thrust self.dy += math.sin(math.radians(self.heading)) * self.thrust def update(self): if self.state == "active": self.fuel -= self.thrust if self.fuel <= 0: self.reset() self.heading += self.da self.heading %= 360 self.x += self.dx self.y += self.dy self.border_check() def reset (self): self.fuel = self.max_fuel self.dx = 0 self.dy = 0 self.state = "ready" def render(self, pen): if self.state == "active": pen.shapesize(0.2, 0.2, None) pen.goto(self.x, self.y) pen.setheading(self.heading) pen.shape(self.shape) pen.color(self.color) pen.stamp() pen.shapesize(1.0, 1.0, None) # Create game object game = Game(1000, 300) # Create player sprite player = Player(0, 0, "triangle", "white") # Create missile object missile = Missile(0, 100, "circle", "yellow") powerup = Powerup(0, -100, "circle", "blue") powerup.dy = 0.1 powerup.dx = 0.01 powerup2 = Powerup(-0, -100, "circle", "blue") powerup2.dy = -0.1 powerup2.dx = -0.01 # Sprites list sprites = [] # Setup the level game.start_level() # Keyoard Bindings wn.listen() wn.onkeypress(player.rotate_left, "Left") wn.onkeypress(player.rotate_right, "Right") wn.onkeyrelease(player.stop_rotation, "Left") wn.onkeyrelease(player.stop_rotation, "Right") wn.onkeypress(player.accelerate, "Up") wn.onkeyrelease(player.decelerate, "Up") wn.onkeypress(player.fire, "space") # Main Loop while True: # Clear screen pen.clear() # Do game stuff # Update sprites for sprite in sprites: sprite.update() # Check for collisions for sprite in sprites: if isinstance(sprite, Enemy): if player.is_collision(sprite): player.x = 0 player.y = 0 if missile.state == "active" and missile.is_collision(sprite): sprite.x = -100 sprite.y = -100 missile.reset() if missile.is_collision(sprite): sprite.x = +100 sprite.y = -100 if isinstance(sprite, Powerup): if player.is_collision(sprite): sprite.x = 100 sprite.y = 100 if missile.state == "active" and missile.is_collision(sprite): sprite.x = 100 sprite.y = -100 missile.reset() # Render sprites for sprite in sprites: sprite.render(pen) game.render_border(pen) # Update the screen wn.update()
@Seth_Stewart
@Seth_Stewart Месяц назад
Idk why, but I love the idea of numbering lines of code by tens
@TokyoEdTech
@TokyoEdTech Месяц назад
@@Seth_Stewart It has a nostalgic appeal for sure!
@passportbro904
@passportbro904 Месяц назад
3rd
@TokyoEdTech
@TokyoEdTech Месяц назад
@@passportbro904 4th