basic maze problem with turtle
Hi everyone, I'm trying to create a simple maze program. When the user finishes the maze, I want to print in big letters "You Win!" and when the user hits a wall, I want the user to go back to the beginning of the maze. The problem is "collision detection" which is an advanced topic and I'm only in a beginning programming class. Is there anyway I can force the user back to the starting point when the turtle hits the wall? Thank you in advance. -- https://mail.python.org/mailman/listinfo/python-list
basic maze problem with turtle
Hi everyone, I'm trying to create a simple maze program. When the user finishes the maze, I want to print in big letters "You Win!" and when the user hits a wall, I want the user to go back to the beginning of the maze. The problem is "collision detection" which is an advanced topic and I'm only in a beginning programming class. Is there anyway I can force the user back to the starting point when the turtle hits the wall? Thank you in advance. -- https://mail.python.org/mailman/listinfo/python-list
Re: basic maze problem with turtle
On Sunday, October 13, 2013 2:52:50 PM UTC-7, [email protected] wrote: > Hi everyone, I'm trying to create a simple maze program. When the user > finishes the maze, I want to print in big letters "You Win!" and when the > user hits a wall, I want the user to go back to the beginning of the maze. > The problem is "collision detection" which is an advanced topic and I'm only > in a beginning programming class. Is there anyway I can force the user back > to the starting point when the turtle hits the wall? Thank you in advance. Sorry about that, I realized I forgot to include the code. So basically I have one turtle that draws the maze at the beginning and then another turtle(userTurtle) that completes the maze. When the userTurtle hits any point on the wall, I want to force userTurtle back to the start of the maze. Here it is: import turtle userTurtle = turtle.Turtle() draw = turtle.Turtle() scr = turtle.Screen() def drawMaze(): draw.pencolor("gold") draw.pensize(3) draw.penup() draw.goto(0,-180) draw.pendown() draw.speed(10) draw.setheading(180) draw.fd(180) draw.setheading(90) draw.fd(60) draw.setheading(0) draw.fd(120) draw.backward(120) draw.setheading(90) draw.fd(300) draw.setheading(0) draw.fd(120) draw.setheading(-90) draw.fd(120) draw.setheading(180) draw.fd(60) draw.setheading(90) draw.fd(60) draw.setheading(-90) draw.fd(120) draw.setheading(90) draw.fd(60) draw.setheading(0) draw.fd(120) draw.setheading(-90) draw.fd(60) draw.setheading(0) draw.fd(60) draw.setheading(-90) draw.fd(60) draw.backward(60) draw.setheading(0) draw.fd(60) draw.setheading(90) draw.fd(60) draw.penup() draw.setheading(180) draw.fd(60) draw.pendown() draw.setheading(90) draw.fd(60) draw.setheading(180) draw.fd(60) draw.setheading(90) draw.fd(60) draw.setheading(0) draw.fd(120) draw.setheading(-90) draw.fd(60) draw.backward(60) draw.setheading(0) draw.fd(60) draw.setheading(-90) draw.fd(240) draw.setheading(180) draw.fd(60) draw.setheading(-90) draw.fd(60) draw.setheading(180) draw.fd(120) draw.setheading(90) draw.fd(60) draw.setheading(180) draw.fd(60) draw.setheading(90) draw.fd(60) draw.backward(60) draw.setheading(180) draw.fd(60) draw.penup() draw.setheading(0) draw.fd(300) draw.pendown() draw.setheading(-90) draw.fd(120) draw.setheading(180) draw.fd(120) draw.ht() userTurtle.penup() userTurtle.goto(-30,180) userTurtle.setheading(-90) def mazeGame(): scr.bgcolor("#0070ff") def m1(): userTurtle.setheading(90) userTurtle.fd(30) userTurtle.pos() print(userTurtle.pos()) def m2(): userTurtle.setheading(180) userTurtle.fd(30) userTurtle.pos() print(userTurtle.pos()) def m3(): userTurtle.setheading(360) userTurtle.fd(30) userTurtle.pos() print(userTurtle.pos()) def m4(): userTurtle.setheading(-90) userTurtle.fd(30) userTurtle.pos() print(userTurtle.pos()) scr.onkeypress(m1, "Up") scr.onkeypress(m2, "Left") scr.onkeypress(m3, "Right") scr.onkeypress(m4, "Down") scr.listen() drawMaze() mazeGame() -- https://mail.python.org/mailman/listinfo/python-list
Trying to force turtle back to beginning of maze after collides with wall
Hi everyone, I'm trying to create a simple maze program. When the user finishes
the maze, I want to print in big letters "You Win!" and when the user hits a
wall, I want the user to go back to the beginning of the maze. The problem is
"collision detection" which is an advanced topic and I'm only in a beginning
programming class. Is there anyway I can force the user back to the starting
point when the turtle hits the wall? Thank you in advance.
I've tried writing:
if userTurtle.xcor(-30) and userTurtle.ycor(60):
userTurtle.goto(-30,180)
userTurtle.setheading(-90)
and
if userTurtle.pos(-30,60):
userTurtle.goto(-30,180)
userTurtle.setheading(-90)
So basically I have one turtle that draws the maze at the beginning and then
another turtle(userTurtle) that completes the maze. When the userTurtle hits
any point on the wall, I want to force userTurtle back to the start of the
maze.
Here it is:
import turtle
userTurtle = turtle.Turtle()
draw = turtle.Turtle()
scr = turtle.Screen()
def drawMaze():
draw.pencolor("gold")
draw.pensize(3)
draw.penup()
draw.goto(0,-180)
draw.pendown()
draw.speed(10)
draw.setheading(180)
draw.fd(180)
draw.setheading(90)
draw.fd(60)
draw.setheading(0)
draw.fd(120)
draw.backward(120)
draw.setheading(90)
draw.fd(300)
draw.setheading(0)
draw.fd(120)
draw.setheading(-90)
draw.fd(120)
draw.setheading(180)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.setheading(-90)
draw.fd(120)
draw.setheading(90)
draw.fd(60)
draw.setheading(0)
draw.fd(120)
draw.setheading(-90)
draw.fd(60)
draw.setheading(0)
draw.fd(60)
draw.setheading(-90)
draw.fd(60)
draw.backward(60)
draw.setheading(0)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.penup()
draw.setheading(180)
draw.fd(60)
draw.pendown()
draw.setheading(90)
draw.fd(60)
draw.setheading(180)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.setheading(0)
draw.fd(120)
draw.setheading(-90)
draw.fd(60)
draw.backward(60)
draw.setheading(0)
draw.fd(60)
draw.setheading(-90)
draw.fd(240)
draw.setheading(180)
draw.fd(60)
draw.setheading(-90)
draw.fd(60)
draw.setheading(180)
draw.fd(120)
draw.setheading(90)
draw.fd(60)
draw.setheading(180)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.backward(60)
draw.setheading(180)
draw.fd(60)
draw.penup()
draw.setheading(0)
draw.fd(300)
draw.pendown()
draw.setheading(-90)
draw.fd(120)
draw.setheading(180)
draw.fd(120)
draw.ht()
userTurtle.penup()
userTurtle.goto(-30,180)
userTurtle.setheading(-90)
def mazeGame():
scr.bgcolor("#0070ff")
def m1():
userTurtle.setheading(90)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())
def m2():
userTurtle.setheading(180)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())
def m3():
userTurtle.setheading(360)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())
def m4():
userTurtle.setheading(-90)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())
scr.onkeypress(m1, "Up")
scr.onkeypress(m2, "Left")
scr.onkeypress(m3, "Right")
scr.onkeypress(m4, "Down")
scr.listen()
drawMaze()
mazeGame()
--
https://mail.python.org/mailman/listinfo/python-list
On click functions with turtle?
Hi everyone, I have this program that writes out the name "John" in block
letters. I was just messing around because we were just introduced to turtle a
few weeks ago in class and I'm just getting the hang of it. Before I was using
"goto" a certain angle, but now I'm using "seth" and it's so much easier.
Here is my question:
I want to click on a certain letter ("J" or "O" or "H" or "N") and have the
turtle hover above that letter as in when the turtle is above the letter "N" at
the end of my program. Do I need to set the letters up as objects so when I
click inside them, I can set the turtles x and y coordinate to hover above that
letter?
Or do I need to define each letter as a function and make some "if" statements
like "if user clicks inside letter (J,O,H, or N), go to specific x, y
coordinate?"
Thanks for any help in advance. Drawing is frustrating with python, but I'm
starting to understand how it works. I think it's just the angles that trip me
up.
Here is my code:
import turtle
rectangle = turtle.Turtle()
def makeRec():
rectangle.shape("turtle")
rectangle.pensize(2)
rectangle.pencolor("red")
rectangle.speed(5)
#Draws the letter O
rectangle.penup()
rectangle.seth(180)
rectangle.fd(50)
rectangle.seth(90)
rectangle.pendown()
rectangle.pencolor("black")
rectangle.circle(30)
rectangle.penup()
rectangle.seth(180)
rectangle.fd(10)
rectangle.seth(90)
rectangle.pendown()
rectangle.circle(20)
rectangle.penup()
rectangle.seth(180)
rectangle.fd(70)
rectangle.seth(90)
rectangle.fd(30)
rectangle.seth(-90)
#Draws the letter J
rectangle.pendown()
rectangle.fd(40)
rectangle.circle(-20,180)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(-90)
rectangle.circle(10,180)
rectangle.fd(40)
rectangle.seth(0)
rectangle.fd(10)
#Draws the letter H
rectangle.penup()
rectangle.fd(100)
rectangle.seth(-90)
rectangle.pendown()
rectangle.fd(60)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(90)
rectangle.fd(20)
rectangle.seth(0)
rectangle.fd(20)
rectangle.seth(-90)
rectangle.fd(20)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(90)
rectangle.fd(60)
rectangle.seth(180)
rectangle.fd(10)
rectangle.seth(-90)
rectangle.fd(30)
rectangle.seth(180)
rectangle.fd(20)
rectangle.seth(90)
rectangle.fd(30)
rectangle.seth(180)
rectangle.fd(10)
#Draws the letter N
rectangle.penup()
rectangle.seth(0)
rectangle.fd(60)
rectangle.seth(-90)
rectangle.fd(60)
rectangle.seth(90)
rectangle.pendown()
rectangle.fd(60)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(-60)
rectangle.fd(50)
rectangle.seth(90)
rectangle.fd(45)
rectangle.seth(0)
rectangle.fd(13)
rectangle.seth(-90)
rectangle.fd(65)
rectangle.seth(180)
rectangle.fd(15)
rectangle.seth(120)
rectangle.fd(40)
rectangle.seth(-90)
rectangle.fd(35)
rectangle.seth(180)
rectangle.fd(13)
rectangle.seth(90)
rectangle.fd(5)
#Sets the turtle to the position above letter N
rectangle.penup()
rectangle.seth(90)
rectangle.fd(100)
rectangle.seth(180)
rectangle.fd(80)
rectangle.seth(-90)
print(rectangle.pos())
rectangle.setx(54)
rectangle.sety(70)
makeRec()
--
https://mail.python.org/mailman/listinfo/python-list
