Как я могу управлять входами с помощью библиотеки черепах?Python

Программы на Python
Ответить
Anonymous
 Как я могу управлять входами с помощью библиотеки черепах?

Сообщение Anonymous »

Я делаю простую игру с луком и стрелами на Python, используя библиотеку черепах, и я хочу иметь возможность стрелять стрелой по команде и изменять ее начальную скорость и угол с помощью ввода с клавиатуры. Однако я не могу запустить стрелу по команде. Мой код такой:

Код: Выделить всё

import math
import turtle
import time
import keyboard
import pygame

wn = turtle.Screen()
wn.title("Tiro al blanco")
wn.bgcolor("black")
wn.setup(width = 800, height = 600)
wn.tracer(0)

#parametros optimos: vi = 14.5, th = 45

vi = 14.5
th = 45

segs = 0
score = 0

fireStatus = 0

#dibujar target
target = turtle.Turtle()
target.speed(0) #Velocidad de animacion, no de movimiento
target.shape("circle")
target.color("white")
target.shapesize(stretch_wid = 3, stretch_len = 3)
target.penup() ##Para que no trace línea de movimiento
target.goto(350,0) ##posición inicial

target2 = turtle.Turtle()
target2.speed(0) #Velocidad de animacion, no de movimiento
target2.shape("circle")
target2.color("red")
target2.shapesize(stretch_wid = 2, stretch_len = 2)
target2.penup() ##Para que no trace línea de movimiento
target2.goto(350,0) ##posición inicial

target3 = turtle.Turtle()
target3.speed(0) #Velocidad de animacion, no de movimiento
target3.shape("circle")
target3.color("white")
target3.shapesize(stretch_wid = 1, stretch_len = 1)
target3.penup() ##Para que no trace línea de movimiento
target3.goto(350,0) ##posición inicial

target4 = turtle.Turtle()
target4.speed(0) #Velocidad de animacion, no de movimiento
target4.shape("circle")
target4.color("red")
target4.shapesize(stretch_wid = 0.5, stretch_len = 0.5)
target4.penup() ##Para que no trace línea de movimiento
target4.goto(350,0) ##posición inicial

#dibujar arco
bow = turtle.Turtle()
bow.speed(0) #Velocidad de animacion, no de movimiento
bow.shape(turtle.circle(20,180))
bow.color("brown")
bow.shapesize(stretch_wid = 5, stretch_len = 1)
bow.penup() ##Para que no trace línea de movimiento
bow.goto(-350,0) ##posición inicial

#dibujar flecha
arrow = turtle.Turtle()
arrow.speed(0) #Velocidad de animacion, no de movimiento
arrow.shape("arrow")
arrow.color("cyan")
arrow.penup() ##Para que no trace línea de movimiento
arrow.goto(-350,0) ##posición inicial

arrow.velx = vi*math.cos(math.radians(th))

arrow.vely = vi*math.sin(math.radians(th))

#scoreboard
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 260)
pen.write("Score: 0", align = "center", font=("Courier", 24, "normal"))

#parametros
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, -260)
pen.write("Velocidad:{}, Inclinacion: {} ".format(vi, th), align = "center", font=("Courier", 24, "normal"))

def fire(): #comando para cambiar el estado de disparo
fireStatus = 1
print(fireStatus)

turtle.onkey(fire, "space")

while True:
fireStatus = 0
wn.update()
time.sleep(0.1)
turtle.listen()
print(fireStatus)
segs +=1
#turtle.exitonclick()

while fireStatus == True:
arrow.vely = vi*math.sin(math.radians(th)) - 0.3*(segs)

if arrow.ycor() < -100:
arrow.vely = 0
arrow.velx = 0

if arrow.ycor() > 275:
arrow.vely = 0
arrow.velx = 0

if arrow.xcor() > 335:
arrow.vely = 0
arrow.velx = 0

if arrow.xcor() >= 330:
if arrow.xcor() = -30:
if arrow.ycor() 

Подробнее здесь: [url]https://stackoverflow.com/questions/75778529/how-can-i-control-inputs-using-turtle-library[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»