Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added built in game_times including methods to get game elapsed time a… #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pgzero/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from .keyboard import keyboard
from .animation import animate
from .rect import Rect, ZRect
from .game_times import get_game_time_secs, get_game_timer, \
convert_secs_to_time_format

from .loaders import images, sounds

Expand Down
31 changes: 31 additions & 0 deletions pgzero/game_times.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pygame
import datetime


def get_game_time_secs():
"""
Total runtime of the game
:return: time elapsed in seconds
"""
return pygame.time.get_ticks() / 1000.0


def convert_secs_to_time_format(time_secs):
"""
It converts a time in seconds to a readable format
:param time_secs:
:return: string
"""
return str(datetime.timedelta(seconds=time_secs))


def get_game_timer():
"""
It converts the Total Game Time from seconds to a readable format
hh:mm:s:ms
:return: string
"""
return convert_secs_to_time_format(get_game_time_secs())