Adding a timer in pygame [duplicate] - python

This question already has answers here:
Countdown timer in Pygame
(8 answers)
Closed 5 years ago.
Would anyone know how you would code a timer to be displayed on screen in pygame, where the time is going up as the user is playing?

This link might be helpful
http://www.pygame.org/docs/ref/time.html#pygame.time.get_ticks
You can do something like this
start_ticks=pygame.time.get_ticks()
while mainloop:
seconds=(pygame.time.get_ticks()-start_ticks)/1000
if seconds>10:
break

Related

timer in python code but like a montlyh subscription [duplicate]

This question already has answers here:
set a Python program to expire after a certain number of days
(1 answer)
Simple license protection for Python app
(1 answer)
Closed 10 months ago.
I'm a new coder.
That's why I have a program that I want to ask, but I need to create a timer and the program should not open when the timer is finished, how can I do this? Can you help me with this?
What should I try in this program and make a similar monthly subscription?
import time
time.sleep(5)
5 being the seconds waiting

Pygame keeps crashing [duplicate]

This question already has answers here:
Pygame unresponsive display
(1 answer)
Pygame window not responding after a few seconds
(3 answers)
Closed 2 years ago.
I just made a pygame when you click the screen it changes the color to a random color stored in a variable called backgroundColor. At the beginning of the while loop it does display.fill(backgroundColor) .
I started clicking the screen really fast. But after about 8,000 cycles the screen turns white and stops doing anything. Does anyone know why the game crashes after so many color changes.

How to use sounds and channels on pygame? [duplicate]

This question already has answers here:
how to play wav file in python?
(5 answers)
How can I play an mp3 with pygame?
(7 answers)
Closed 2 years ago.
I'm trying to add to my game background music with sound effects and I understood that the best way to do it is with channels and sounds, so I tried it but when I play a sound sound_name.play() or play it with a channel channel_name.play(sound_name) it does nothing, and when I add a delay it beeps.
Does anyone know how to figure it out or has a better way to play some sound on my game (when one sound doesn't stop or reset the other sound)?
Thank you :)

How do I clear the output screen in python? [duplicate]

This question already has answers here:
Clear terminal in Python [duplicate]
(27 answers)
Closed 4 years ago.
I am making a text based rpg in python 3 and the output window gets very cluttered cluttered. I was wondering if there was a way to clear the screen automatically from time to time.
import os
os.system('cls')
You can use os.system('clear') if you are on linux.

how to make pygame start sound at a specific point? [duplicate]

This question already has answers here:
how to play wav file in python?
(5 answers)
How can I play an mp3 with pygame?
(7 answers)
Closed 2 years ago.
i have a sound file with a delay in it that plays with pygame.
menu_sound = pygame.mixer.Sound('sounds/Devastation.ogg')
#these lines are not next to each other in my code, i just picked out relevant lines.
menu_sound.play(-1)
there is about a 4 second delay. how can i force pygame to play the music starting at 4 seconds? i have looked at the mixer module documentation and can't find anything.
Python 3.3.3, windows

Categories

Resources