I want to write a prompt message at turtle.Screen()
every time the turtle, that generates random color when hitting the border, generates a lime green color (50, 205, 50)
.
import random
import turtle
import math
turtle.colormode(255)
# random color generator
r = random.randint(0, 255)
g = random.randint(0, 255)
b - random.randint(0, 255)
rand_color = turtle.color(r, g, b)
# it will update the rgb values set above everytime a condition is satisfied
def rand_c():
return rand_color
# for the prompt message inside turtle.Screen()
sm = turtle.Turtle()
sm.color("White")
sm.hideturtle()
sm.goto(0, 0)
# game loop
while True:
player.forward(speed)
# boundary checking/ putting effects on the border/ player
if player.xcor() > 275 or player.xcor() < -275:
player.setposition(x=0, y=0) # player positioned to (0, 0) when it hits L and R border
winsound.PlaySound("KABOOM", winsound.SND_ASYNC) # plays sound when border is hit
score *= 0 # multiplies the score to zero if the player hits border
rand_c() # change the player color every time it hits the left and right border
# What should be the code here? (condition statement for when turtle generates a lime green color)
if rand_color == (50, 205, 50):
sm.write("Stealth Mode", align="center", font=("Courirer new", 10, "bold"))
sleep(2)
sm.clear()
else:
pass
The problem is that it writes the prompt message every time it hits the border, instead of just writing the prompt message when the turtle only randomly generates a lime green color (50, 205, 50)