I'm having an error in which after the borders are drawn the program closes. Here is the error message: File "C:\Users\Nick\Desktop\turtlegame.py", line 51, in if player.xcor() > 300 or player.xcor < -300: TypeError: '
I am making a game and I was going to do the same as exactly like yours, but I get confused about where to put that line of code. Because I had a loop inside the main loop. So how to solve that???? Can you please help me? Anyway, that programming tutorial is really great!!! Thanks!!! : )
Why does my turtle graphics screen crash when I start it after I put the border check? I put the same border check thing and I don't know what the problem is. I think the loop is doing it.
@Christian Thompson I am on 3.5 and trying to make my code compatible but my borders arent working and speed is out of control + mypen is going into middle of the screen, even though I tried typing this: mypen.setpos(0, 0) but this doesnt work!!! uggggghhhhnnn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
James Inman I'm sure your well past this but I feel like answering. 0,0 is the center of the screen... In the x,y plane, there are four quadrants with 0,0 at the center
hey mr.tokyo can u help me with this if player.xcor() > 300 or player.xcor < - 300: player.right(180) and i have this error Traceback (most recent call last): File "C:\Users\Yishin\AppData\Local\Programs\Python\Python38-32\pyhtion.py", line 61, in if player.xcor() > 300 or player.xcor < - 300: TypeError: '
You're welcome - there were some changes to the turtle module between Python 2 and 3 - so the onkeymethod was added and is supposed to be applied to the window object, not the turtle object.
@Christian Thompson i am having trouble with the code the turtle won't move import turtle wn=turtle.Screen() wn.bgcolor("lightgreen") mp=turtle.Turtle() mp.pu() mp.setposition(-300,-300) mp.pd() mp.pensize(3) for side in range(4): mp.fd(600) mp.lt(90) mp.hideturtle() ply=turtle.Turtle() ply.color("grey") ply.shape("triangle") ply.pu() ply.speed(0) speed=1 def turnleft(): ply.lt(30) def turnright(): ply.rt(30) def incrspeed(): global speed speed+=1 wn.listen() wn.onkey(turnleft,"left") wn.onkey(turnright,"right") wn.onkey(incrspeed,"up") while True: ply.fd(speed) if ply.ycord()>300 or ply.ycord()300 or ply.xcord()
I write this if player.xcor() > 300 or player.xcor() < -300: player.right(45) if player.ycor() > 300 or player.ycor() < -300: player.right(45) but the borders not working.I can go trough them plz help :(
import turtle x = turtle.Screen border =turtle.Turtle() border.penup() border.setposition( -300,-300) border.pendown() border.pensize(3) for side in range(4) : border.forward(600) border.left(90)
kalem = turtle.Turtle() kalem.color("Blue") kalem.penup() speed =1 def turnleft(): kalem.left(29) def turnright(): kalem.right(29) def increasespeed(): global speed speed+=1 turtle.listen() turtle.onkey(turnleft, "Left") turtle.onkey(turnright, "Right") turtle.onkey(increasespeed,"Up") while True : kalem.forward(speed) if kalem.xcor() > 300 or kalem.xcor() < -300 : kalem.right(45) if kalem.ycor() > 300 or kalem.ycor() < -300: kalem.right(45)
I live in Turkey and when I want to use pastebin.com, google say this; "The protection measure has been taken for this website (pastebin.com) according to decision nr. 2012/27976 dated 08/03/2012 of "Ankara CBS" has been implemented by the Information Comunication Technologies Authority." so I can send you this only from g-mail.
i figured that out on my own for once! and also be aware it has a turning issue to where your player will keep turning for about 2 seconds or glitch out if anyone has a fix for that!
Thank you for making an AWSOME tutorial T-T this is the best tutorial i have ever seen T-T question, can you make it so it can turn with A/D and Left/Right key as well? *maybe you don't even understand wth im saying ;-;
@@TokyoEdTech I meant like you can use both, left/right and a/d, do you just copy the code for left and right? thanks for answering my question👍this was like uploaded 4 years ago xD
Tysm @@TokyoEdTech edit: yay it works =) I love coding, like my sibling, I started when i was like, 7 xD and entered a competition at...like 9... and won second place 👍Thanks
@Christian Thompson i am working on a project, i used border boundary checking from this video... why is this code not working?? code: # TURTLE GAME TEST LOL import turtle, random, math # player turtle stuff t = turtle.Turtle() t.color("white") t.shape("square") t.up() t.goto(0, -280) # Screen stuff sc = turtle.Screen() sc.bgcolor("black") sc.setup(1000, 680) sc.title("Simple Game v.1.1") # Border b = turtle.Turtle() b.up() b.goto(-450, -300) b.color("red") b.down() b.pensize(7) b.fd(900) print(b.xcor()) b.lt(90) b.fd(625) b.lt(90) b.fd(900) b.lt(90) b.fd(625) b.hideturtle() # Functions def rt(): t.fd(50) def lt(): t.bk(50) # Making functions "rt" and "lt" auctally move you araound sc.onkey(rt, "Right") sc.onkey(lt, "Left") sc.listen() turtle.done() # Checking if turtle is touching border while True: if t.xcor() > 450 or t.xcor() < -450: t.bk(50) just for you to know i want to be able to move right and left only not up and down....
I'm having an error in which after the borders are drawn the program closes.
Here is the error message:
File "C:\Users\Nick\Desktop\turtlegame.py", line 51, in
if player.xcor() > 300 or player.xcor < -300:
TypeError: '
change it to this: if player.xcor() > 300 or player.xcor() < -300:
I am making a game and I was going to do the same as exactly like yours, but I get confused about where to put that line of code. Because I had a loop inside the main loop. So how to solve that???? Can you please help me? Anyway, that programming tutorial is really great!!! Thanks!!! : )
Why does my turtle graphics screen crash when I start it after I put the border check? I put the same border check thing and I don't know what the problem is. I think the loop is doing it.
I get the same
I get the same
bare in mind that the boundery checking should be if and elif, otherwhise the player is just gone :-)), because turn(180) and turn(180) == 360!!
@Christian Thompson
I am on 3.5 and trying to make my code compatible but my borders arent working and speed is out of control + mypen is going into middle of the screen, even though I tried typing this:
mypen.setpos(0, 0)
but this doesnt work!!! uggggghhhhnnn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
James Inman I'm sure your well past this but I feel like answering.
0,0 is the center of the screen... In the x,y plane, there are four quadrants with 0,0 at the center
Christian Thompson my y boundary doesn't work
nvm I fixed it
when i use the while true loop the game hangs and doesn't rsspond
Hey can u help me i cant get it to turn 180 degrees when it hits the border
What have you tried so far?
@@TokyoEdTech i got it thanks for replying 🥰
You're welcome.
@@TokyoEdTech i have a problem can u help me
I can try...
hey mr.tokyo can u help me with this
if player.xcor() > 300 or player.xcor < - 300:
player.right(180)
and i have this error
Traceback (most recent call last):
File "C:\Users\Yishin\AppData\Local\Programs\Python\Python38-32\pyhtion.py", line 61, in
if player.xcor() > 300 or player.xcor < - 300:
TypeError: '
Yep. Change player.xcor to player.xcor()
my turtle stopped moving after the boundary checking. what can i do?
solved it!
How did you solve it? Im having the same problem
Thanks for this tutorial. I don't know why I need to apply the onkey method to wn. Using Repl.it, I can't apply the onkey method to the turtle object.
You're welcome - there were some changes to the turtle module between Python 2 and 3 - so the onkeymethod was added and is supposed to be applied to the window object, not the turtle object.
Hello, when i set my position to draw the border there is a line from the center to what ever position i set the turtle, can you help me??
pen.penup()
pen.goto(###, ###)
pen.pendown()
pen.goto(###, ###)
what's application is that?
Probably at the time I used BBEdit, but nowadays I use Geany.
while True:
wn.update()
wn.mainloop()
#Border Checking
if whalo.xcor()>300 or whalo.xcor()
@@TokyoEdTech thanks:)
@@TokyoEdTech pastebin.com/HSyEpxqT
The window dosent close now, thanks. But the borders arent working:(
@@alexhauser8981 what did he tell u im also having the same problem
I thought, if you get to fast you some times cant control, so I made the back arrow to get slow!
bro you can even go in negative speed
Amazing!
@Christian Thompson pls help i am getting this error:
TypeError: penup() missing 1 required positional argument: 'self
Are you doing "your turtle".penup()
@@Beastpig41 i m not sure what you mean but i have done this
mypen = turtle.Turtle
mypen.penup()
@@lirdib9596 it could be mypen =turtle.Turtle()
@@TokyoEdTech thanks
@@TokyoEdTech and can i ask you one more question why don t you make some tutortials on pygame
my borders are not working i can go right trough them ): plz help me
import turtle
wn = turtle.Screen()
wn.bgcolor("lightgreen")
player = turtle.Turtle()
player.color("blue")
player.shape("triangle")
player.penup()
player.speed(0)
goal = turtle.Turtle()
goal.color("red")
goal.shape("circle")
goal.penup()
goal.speed(0)
goal.setpos
mypen = turtle.Turtle()
mypen.penup()
mypen.setposition(-300,-300)
mypen.pendown()
mypen.pensize(3)
for side in range(4):
mypen.forward(600)
mypen.left(90)
mypen.hideturtle()
speed = 1
def turnleft():
player.left(30)
def turnright():
player.right(30)
def increasespeed():
global speed
speed += 1
turtle.listen()
turtle.onkey(turnleft, "Left")
turtle.onkey(turnright, "Right")
turtle.onkey(increasespeed, "Up")
mypen = turtle.Turtle()
mypen.penup()
mypen.setposition(-300,-300)
if player.xcor() > 300 or player.xcor() < -300:
player.right(180)
if player.ycor() > 300 or player.ycor() < -300:
player.right(180)
while True:
player.forward(speed)
Btw im using python 3.4.0
Oh and i cant use pastebin for some reason
Christian Thompson ok thx
(:
@@TokyoEdTech I have the exact code as him and it is still isn't working
@@TokyoEdTech pastebin.com/HbL0NSYj
amazing vid
@Christian Thompson
i am having trouble with the code the turtle won't move
import turtle
wn=turtle.Screen()
wn.bgcolor("lightgreen")
mp=turtle.Turtle()
mp.pu()
mp.setposition(-300,-300)
mp.pd()
mp.pensize(3)
for side in range(4):
mp.fd(600)
mp.lt(90)
mp.hideturtle()
ply=turtle.Turtle()
ply.color("grey")
ply.shape("triangle")
ply.pu()
ply.speed(0)
speed=1
def turnleft():
ply.lt(30)
def turnright():
ply.rt(30)
def incrspeed():
global speed
speed+=1
wn.listen()
wn.onkey(turnleft,"left")
wn.onkey(turnright,"right")
wn.onkey(incrspeed,"up")
while True:
ply.fd(speed)
if ply.ycord()>300 or ply.ycord()300 or ply.xcord()
sure!
if player hits the corner, its geting out of boundary? why is this?
Long story short - it wasn't coded very well. I made this for 10 year old students so I had to keep it simple.
@@TokyoEdTech ok sir, no problem. I jsut wanted to know the reason why this was happening so I had asked.
No worries - it's a good question!
I write this
if player.xcor() > 300 or player.xcor() < -300:
player.right(45)
if player.ycor() > 300 or player.ycor() < -300:
player.right(45)
but the borders not working.I can go trough them plz help :(
import turtle
x = turtle.Screen
border =turtle.Turtle()
border.penup()
border.setposition( -300,-300)
border.pendown()
border.pensize(3)
for side in range(4) :
border.forward(600)
border.left(90)
kalem = turtle.Turtle()
kalem.color("Blue")
kalem.penup()
speed =1
def turnleft():
kalem.left(29)
def turnright():
kalem.right(29)
def increasespeed():
global speed
speed+=1
turtle.listen()
turtle.onkey(turnleft, "Left")
turtle.onkey(turnright, "Right")
turtle.onkey(increasespeed,"Up")
while True :
kalem.forward(speed)
if kalem.xcor() > 300 or kalem.xcor() < -300 :
kalem.right(45)
if kalem.ycor() > 300 or kalem.ycor() < -300:
kalem.right(45)
I can't speak english very well but ı now little
I live in Turkey and when I want to use pastebin.com, google say this;
"The protection measure has been taken for this website (pastebin.com) according to decision nr. 2012/27976 dated 08/03/2012 of "Ankara CBS" has been implemented by the Information Comunication Technologies Authority." so I can send you this only from g-mail.
make it turtle.onkey --->>> to turtle.onkeypress.. makes it a littlebit better to play
Thanks for the suggestion.
i figured that out on my own for once! and also be aware it has a turning issue to where your player will keep turning for about 2 seconds or glitch out if anyone has a fix for that!
guys can someone help with a border if player.xcor() >= 300 or player.xcor()
if you want a answer make another comment like this:
@Christian Thompson
and paste your entire code
never mind got it now its mypen.setpos(275, -275)
and the square is mypen.forward(525)
@@TokyoEdTech This uses classes too right
you are the best
@@TokyoEdTech okey not problem , i am french ,that is what I make mistakes in comment sorry,but I already signed
My code is pretty much identical to yours but it runs way less smooth, anyone know why? (It’s like my FPS is way lower)
You'll have to share your code so I can take a look.
@@TokyoEdTech here’s my code (it’s a turtle you can control and a ball that bounces around in a squares):
import turtle
import math
wn = turtle.Screen()
wn.bgcolor("lightgreen")
wn.title("Bouncing Balls")
#Ritar banan
mypen = turtle.Turtle()
mypen.penup()
mypen.setposition(-300,-300)
mypen.pendown()
mypen.pensize(3)
mypen.speed(10)
for side in range(4):
mypen.forward(600)
mypen.left(90)
mypen.hideturtle()
#Skapar spelaren
player = turtle.Turtle()
player.color("blue")
player.shape("turtle")
player.penup()
player.speed(0)
speed = 0
#Skapar boll
boll = turtle.Turtle()
boll.color("yellow")
boll.shape("circle")
boll.penup()
boll.speed(0)
boll.shapesize(1,1,1)
boll.goto(250,200)
boll.left(30)
def turnleft():
player.left(30)
def turnright():
player.right(30)
def increasespeed():
global speed
speed += 5
def decreasespeed():
global speed
speed -= 5
turtle.listen()
turtle.onkey(turnleft, "a")
turtle.onkey(increasespeed, "w")
turtle.onkey(turnright, "d")
turtle.onkey(decreasespeed, "s")
while True:
boll.forward(7)
player.forward(speed)
if speed > 5:
speed = 5
if speed < -5:
speed = -5
if player.xcor() > int(300) or player.xcor() < int(-300):
player.right(180)
if player.ycor() > int(300) or player.ycor() < int(-300):
player.right(180)
d = math.sqrt(math.pow(player.xcor()-boll.xcor(),2) + math.pow(player.ycor()-boll.ycor(),2))
if d < 17:
break
if boll.xcor() > int(300) or boll.xcor() < int(-300):
boll.left(80)
if boll.ycor() > int(300) or boll.ycor() < int(-300):
boll.left(80)
@@stigidystacks3747 Try this - I added two lines which should make it much faster:
import turtle
import math
wn = turtle.Screen()
wn.bgcolor("lightgreen")
wn.title("Bouncing Balls")
wn.tracer(0)
#Ritar banan
mypen = turtle.Turtle()
mypen.penup()
mypen.setposition(-300,-300)
mypen.pendown()
mypen.pensize(3)
mypen.speed(10)
for side in range(4):
mypen.forward(600)
mypen.left(90)
mypen.hideturtle()
#Skapar spelaren
player = turtle.Turtle()
player.color("blue")
player.shape("turtle")
player.penup()
player.speed(0)
speed = 0
#Skapar boll
boll = turtle.Turtle()
boll.color("yellow")
boll.shape("circle")
boll.penup()
boll.speed(0)
boll.shapesize(1,1,1)
boll.goto(250,200)
boll.left(30)
def turnleft():
player.left(30)
def turnright():
player.right(30)
def increasespeed():
global speed
speed += 5
def decreasespeed():
global speed
speed -= 5
turtle.listen()
turtle.onkey(turnleft, "a")
turtle.onkey(increasespeed, "w")
turtle.onkey(turnright, "d")
turtle.onkey(decreasespeed, "s")
while True:
wn.update()
boll.forward(7)
player.forward(speed)
if speed > 5:
speed = 5
if speed < -5:
speed = -5
if player.xcor() > int(300) or player.xcor() < int(-300):
player.right(180)
if player.ycor() > int(300) or player.ycor() < int(-300):
player.right(180)
d = math.sqrt(math.pow(player.xcor()-boll.xcor(),2) + math.pow(player.ycor()-boll.ycor(),2))
if d < 17:
break
if boll.xcor() > int(300) or boll.xcor() < int(-300):
boll.left(80)
if boll.ycor() > int(300) or boll.ycor() < int(-300):
boll.left(80)
@@TokyoEdTech Wow what a difference!!! Thank you so much 🙏
why its always turtle.Turtle() to make a new turtle? why the capital T turtle?
pls make this code work in python 3.6.1 pls pls pls
i have done it Python 3.6 and its fine :)
Thank you for making an AWSOME tutorial T-T this is the best tutorial i have ever seen T-T
question, can you make it so it can turn with A/D and Left/Right key as well?
*maybe you don't even understand wth im saying ;-;
Thanks - glad you liked it. To use a and d, just copy the lines with Left/Right and change Left/Right to a/d.
@@TokyoEdTech I meant like you can use both, left/right and a/d, do you just copy the code for left and right?
thanks for answering my question👍this was like uploaded 4 years ago xD
@@アリちゃんねる-v5l Yep - you can use both. Just copy the left/right code and then change it to a/d. You're welcome. Keep on codin'!
Tysm @@TokyoEdTech
edit: yay it works =)
I love coding, like my sibling, I started when i was like, 7 xD and entered a competition at...like 9... and won second place 👍Thanks
christian Thompson, can you please help me with something!?
@Christian Thompson
i am working on a project, i used border boundary checking from this video... why is this code not working??
code:
# TURTLE GAME TEST LOL
import turtle, random, math
# player turtle stuff
t = turtle.Turtle()
t.color("white")
t.shape("square")
t.up()
t.goto(0, -280)
# Screen stuff
sc = turtle.Screen()
sc.bgcolor("black")
sc.setup(1000, 680)
sc.title("Simple Game v.1.1")
# Border
b = turtle.Turtle()
b.up()
b.goto(-450, -300)
b.color("red")
b.down()
b.pensize(7)
b.fd(900)
print(b.xcor())
b.lt(90)
b.fd(625)
b.lt(90)
b.fd(900)
b.lt(90)
b.fd(625)
b.hideturtle()
# Functions
def rt():
t.fd(50)
def lt():
t.bk(50)
# Making functions "rt" and "lt" auctally move you araound
sc.onkey(rt, "Right")
sc.onkey(lt, "Left")
sc.listen()
turtle.done()
# Checking if turtle is touching border
while True:
if t.xcor() > 450 or t.xcor() < -450:
t.bk(50)
just for you to know i want to be able to move right and left only not up and down....
fixed, sorry
here is my code