movimiento sobre serpiente en python turtle
Publicado por R (1 intervención) el 03/01/2023 18:16:20
mi código es:
import turtle
import time
delay = 0,1
#background cof
Wn = turtle.Screen()
#title
Wn.title("SnakeGame")
#setup
Wn.setup(width= 800, height= 800)
Wn.bgcolor("white")
Head = turtle.Turtle()
Head.shape("triangle")
Head.color("red")
Head.speed(1)
Head.penup()
Head.goto(0, 0)
Head.direction = "mov"
def mov():
#almacenar el valor actual de la coor Y:
if Head.direction == "up":
Y = Head.ycor()
Head.sety(Y + 10)
#almacenar el valor actual de la coor y:
if Head.direction == "Down":
Y = Head.ycor()
Head.sety(Y - 10)
#almacenar el valor actual de la coor X:
if Head.direction == "Right":
X = Head.xcor()
Head.setx(X + 10)
#almacenar el valor actual de la coor X:
if Head.direction == "Left":
X = Head.xcor()
Head.setx(X - 10)
def dirUP():
Head.direction = "up"
def dirDown():
Head.direction = "Down"
def dirRight():
Head.direction = "Right"
def dirLeft():
Head.direction = "left"
Wn.listen()
Wn.onkeypress(dirUP, "Up")
Wn.onkeypress(dirDown, "Down")
while True:
Wn.update
import turtle
import time
delay = 0,1
#background cof
Wn = turtle.Screen()
#title
Wn.title("SnakeGame")
#setup
Wn.setup(width= 800, height= 800)
Wn.bgcolor("white")
Head = turtle.Turtle()
Head.shape("triangle")
Head.color("red")
Head.speed(1)
Head.penup()
Head.goto(0, 0)
Head.direction = "mov"
def mov():
#almacenar el valor actual de la coor Y:
if Head.direction == "up":
Y = Head.ycor()
Head.sety(Y + 10)
#almacenar el valor actual de la coor y:
if Head.direction == "Down":
Y = Head.ycor()
Head.sety(Y - 10)
#almacenar el valor actual de la coor X:
if Head.direction == "Right":
X = Head.xcor()
Head.setx(X + 10)
#almacenar el valor actual de la coor X:
if Head.direction == "Left":
X = Head.xcor()
Head.setx(X - 10)
def dirUP():
Head.direction = "up"
def dirDown():
Head.direction = "Down"
def dirRight():
Head.direction = "Right"
def dirLeft():
Head.direction = "left"
Wn.listen()
Wn.onkeypress(dirUP, "Up")
Wn.onkeypress(dirDown, "Down")
while True:
Wn.update
Valora esta pregunta


0