I'm trying to add a countdown timer to the top right of my python game

I do not want to have to import anything other than pygame...>>My game is at 50 fps my screen is 640x480

I'm trying to add a timer to the top right of the screen. The timer needs to count down from 10... I've tried tons of things and can't get it to work. So far this is what I have:

class Timer(games.Sprite):
    """ countdown timer """
    def __init__(self):
       timer_message = games.Text(
       value = 10,
       size = 50,
       color = color.black,
       x = games.screen.width - 30,
       y = games.screen.height - 420)
    timer_delay = 50

Answers


I don't see any code for actually causing the timer to count down. Without any knowledge of the rest of your code, I would suggest using

class Timer(games.Sprite):
    def __init__(self):
        ....
        self.start()

    def start(self):
        while self.timer_message.value != 0:
            time.sleep(1)
            self.timer_message.value -= 1

And don't bother with assigning timer_delay.


Need Your Help

Debugging link error with lib.a file

c++ build compilation linker linker-error

The project I'm working with, uses the VTK (ver 5.8.0), c++ 4.6.3, buntu 12.04

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.