Added global font & render current item
This commit is contained in:
20
game.py
20
game.py
@ -132,6 +132,8 @@ class Game(gameUtils.Game):
|
|||||||
# Blit the text surface to the wheel surface
|
# Blit the text surface to the wheel surface
|
||||||
self.wheelSurf.blit(textSurf, (0, 0))
|
self.wheelSurf.blit(textSurf, (0, 0))
|
||||||
|
|
||||||
|
self.font = pygame.font.SysFont('', 50)
|
||||||
|
|
||||||
def spinnerTick(self):
|
def spinnerTick(self):
|
||||||
# If there's a tick already playing
|
# If there's a tick already playing
|
||||||
if time.perf_counter() - self.lastTickTime < self.tickSfx.get_length():
|
if time.perf_counter() - self.lastTickTime < self.tickSfx.get_length():
|
||||||
@ -169,15 +171,17 @@ class Game(gameUtils.Game):
|
|||||||
self.wheelRotation += speed * self.timeDelta
|
self.wheelRotation += speed * self.timeDelta
|
||||||
self.wheelRotation %= 360
|
self.wheelRotation %= 360
|
||||||
|
|
||||||
# Calculates the current item index with... I don't know, magic?
|
# Calculates the current item index with... I don't know, magic?
|
||||||
currentItemIdx = round((self.wheelRotation / 360) * len(self.items)) % len(self.items)
|
currentItemIdx = round((self.wheelRotation / 360) * len(self.items)) % len(self.items)
|
||||||
|
|
||||||
# If the last tick was on a different index,
|
# If the last tick was on a different index,
|
||||||
if currentItemIdx != self.lastTickItem:
|
if currentItemIdx != self.lastTickItem:
|
||||||
# Click again
|
# Click again
|
||||||
self.spinnerTick()
|
self.spinnerTick()
|
||||||
# And set the last tick index to the current one
|
# And set the last tick index to the current one
|
||||||
self.lastTickItem = currentItemIdx
|
self.lastTickItem = currentItemIdx
|
||||||
|
|
||||||
|
self.surf.blit(self.font.render(self.items[currentItemIdx].text, True, (255, 255, 255)), (0, 0))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user