0

My code currently draws the 2 tron bikes and each of the players can move them with the WASD and up down left right keys. Right now if you play the game anyone can start playing at any time they want to, there's no specific "starting" time or a countdown of sorts. There's also no way to end the game but I'll sort that out later, I'm just wondering how to get a countdown to get my game started.

def tron():
    blueplayer = turtle.Turtle()
    redplayer = turtle.Turtle()
    screen = turtle.Screen()
    blueplayer.speed(10)
    redplayer.speed(10)
    screen.setup(600, 600)
    screen.bgpic('TronBg.png')
    screen.bgcolor('black')
    screen.addshape('BlueBike.gif')
    screen.addshape('RedBike.gif')
    blueplayer.shape('BlueBike.gif')
    redplayer.shape('RedBike.gif')
    redplayer.pencolor("red")
    redplayer.pensize(4)
    blueplayer.pencolor("blue")
    blueplayer.pensize(4)
    redplayer.pu()
    blueplayer.pu()
    blueplayer.goto(-200, 50)
    redplayer.goto(200, 50)
    redplayer.pd()
    blueplayer.pd()
  
    def RedUp():
        blueplayer.tilt(90)
        while True:
            blueplayer.setheading(90)
            blueplayer.forward(1)
    def BlueUp():
        redplayer.tilt(90)
        while True:
            redplayer.setheading(90)
            redplayer.forward(100)

    def RedDown():
        blueplayer.tilt(270)
        while True:
            blueplayer.setheading(270)
            blueplayer.forward(1)
    def BlueDown():
        redplayer.tilt(270)
        while True:
            redplayer.setheading(270)
            redplayer.forward(1)

    def RedLeft():
        blueplayer.tilt(180)
        while True:
            blueplayer.setheading(180)
            blueplayer.forward(1)
    def BlueLeft():
        redplayer.tilt(180)
        while True:
            redplayer.setheading(180)
            redplayer.forward(1)

    def RedRight():
        while True:
            blueplayer.setheading(0)
            blueplayer.forward(1)
    def BlueRight():
        while True:
            redplayer.setheading(0)
            redplayer.forward(1)

    screen.listen()

    screen.onkey(RedUp, "w")
    screen.onkey(RedDown, "s")
    screen.onkey(RedLeft, "a")
    screeb.onkey(RedRight, "d")
    
    screen.onkey(BlueUp, "Up")
    screen.onkey(BlueDown, "Down")
    screen.onkey(BlueLeft, "Left")
    screen.onkey(BlueRight, "Right")
    
    screen.mainloop()

tron()
Ian
  • 35
  • 6

2 Answers2

1

Well there are two methods that I know of and both involve the time module

the simplest by far would be time.sleep:

import time

for x in range(10):
     time.sleep(.8) ## can change the parameter to however seconds you want to wait
     print(x)

the other way that I know about would be using time.asctime():

splitting it finding seconds converting it to an integer and checking to see if that Is larger than the last time you found the seconds in time.asctime() this method for me is rated 1/10 unless you don't want to stop the program.

0

You could you time.sleep function, or else you could choose other time modules.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 19 '22 at 08:55