Skip to main content

A cooldown/counter class to wait for stuff in games

Project description

pgcooldown

A cooldown class, checking the delta time between start and now.

cooldown = Cooldown(5)

A trigger class to wait for n seconds.

If started, it saves the current time as t0. On every check, it compares the then current time with t0 and returns as 'cold' if the cooldown time has passed.

The cooldown can be paused, in which case it saves the time left. On restart, it'll set again t0 to the remaining time and continues to compare as normal against the left cooldown time.

At any time, the cooldown can be reset to its initial or a new value.

Parameters:

duration: float - Seconds to cool down

Attributes:

remaining: float        - "temperature" to cool down from
duration: float         - default to initialize the cooldown after each reset()
normalized: float       - property that maps remaining into an interval between 0 and 1
paused: bool = False    - to temporarily disable the cooldown
hot: bool               - there is stil time remaining before cooldown
cold: bool              - time of the cooldown has run out

Methods:

reset()
reset(new_cooldown_time)

set t0 to now, remove pause state, optionally set duration to new
value

start()

Start the cooldown again after a pause.

The cooldown is started at creation time, but can be immediately
paused by chaining.  See pause below.

pause()

remember time left, stop comparing delta time.  This can also be
used to create an cooldown that's not yet running by chaining to
the constructor:

    cooldown = Cooldown(10).pause()

Synopsis:

cooldown = Cooldown(5)

while True:
do_stuff()

if key_pressed
    if key == 'P':
	cooldown.pause()
    elif key == 'ESC':
	cooldown.start()

if cooldown.cold:
    launch_stuff()
    cooldown.reset()

"""

Installation

The project home is https://github.com/dickerdackel/pgcooldown

Getting it from pypi

pip install pgcooldown

Tarball from github

Found at https://github.com/dickerdackel/pgcooldown/releases

Licensing stuff

This lib is under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgcooldown-0.2.3.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

pgcooldown-0.2.3-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page