"""
This file is part of the Tetris project.

Written 2023 by Maarten Tromp <maarten@geekabit.nl>


Website
-------
https://www.geekabit.nl/projects/tetris-window/


License
-------
CC0 (no copyright, public domain)
The person who associated a work with this deed has dedicated the work to the public domain by
waiving all of his or her rights to the work worldwide under copyright law, including all related
and neighbouring rights, to the extent allowed by law. You can copy, modify, distribute and perform
the work, even for commercial purposes, all without asking permission.
https://creativecommons.org/share-your-work/public-domain/cc0/
This file is part of the Tetris project.
"""


# imports
import logging


class GameOver:
	"""
	Simple game-over animation.
	"""

	# constants
	fade_out_multiplier = 0.8
	max_frames = 30


	def __init__(self, screen):
		"""
		Initialize game-over animation.

		Parameters
		----------
		screen: screen object
		"""

		logging.debug("starting game-over animation")

		# private variables
		self._screen = screen
		self._frame_counter = 0


	def update(self):
		"""
		Update game state. This function is called at a regular interval. Handle timed actions and user
		actions.

		Parameters
		----------
		none

		Returns
		-------
		none
		"""

		# quit when max frames is reached
		if self._frame_counter >= self.max_frames:
			self._screen.clear()
			return False
		self._frame_counter += 1

		# fade out
		self._screen.dim(self.fade_out_multiplier)
		return True
