lundi 1 février 2021

How do I make it so that if a turtle is close to a turtle, it will increase a variable

So i am trying to make a more interactive game, basically, i want to make it so that if a turtle is close to another one, it will increase a variable(in this case, the variable is score). The code is over here

import turtle
import random
import time
screen = turtle.Screen()


mapmaker = turtle.Turtle()
turtler = turtle.Turtle()
mapmaker.shape('classic')
turtler.shape('turtle')
turtler.penup()
turtler.forward(10)
colours = ["red", "orange", "yellow", "green", "blue", "violet", "indigo"]
for i in range(360):
  mapmaker.color(colours[i % 7])
  mapmaker.width(i / 100 + 1)
  mapmaker.forward(i + 10)
  mapmaker.right(270)
  mapmaker.speed(100000000000000000000000000000000000000)
  
move_speed = 10
turn_speed = 10

def forward():
  turtler.forward(move_speed)
  
def backward():
  turtler.backward(move_speed)
  
def right():
  turtler.right(turn_speed)
  
def left():
  turtler.left(turn_speed)
  
screen.onkey(forward, "up")
screen.onkey(backward, "down")
screen.onkey(left, "left")
screen.onkey(right, "right")
screen.listen()
screen.onkey(forward, "w")
screen.onkey(backward, "s")
screen.onkey(left, "a")
screen.onkey(right, "d")

fruit = turtle.Turtle()
fruit.shape('square')

x = random.randint(-175,175)
y = random.randint(-175,175)
score = 0

random_time = random.randint(2,5)
while score < 10:
  if turtler.distance(fruit) < 15:
    score + 1
    fruit.penup()
    fruit.goto(x,y)
    

if score > 10:
  print("Congratulations, you have won!")
  screen.bye()

Does anyone know how to make it so that if the turtle is distanced close to it, it will do what make the other one go to a random position and increase the score?




Aucun commentaire:

Enregistrer un commentaire