Moved wheel drawing into its own function
This commit is contained in:
17
game.py
17
game.py
@ -9,7 +9,6 @@ import NoPELib
|
||||
import numpy as np
|
||||
import pygame
|
||||
|
||||
# TODO: Add the ability to re-draw the wheel to hightlight the selected item
|
||||
# TODO: Prevent another animation from starting when the wheel's spinning
|
||||
# TODO: Convery fade in / out time to be random
|
||||
# TODO: Make random finer (to prevent a range of 4-5 only having two possible speeds)
|
||||
@ -83,7 +82,7 @@ class Game(gameUtils.Game):
|
||||
# The last index the ticker ticked on
|
||||
self.lastTickItem = -1
|
||||
|
||||
font = pygame.font.SysFont('', 32)
|
||||
self.wheelFont = pygame.font.SysFont('', 32)
|
||||
|
||||
self.items = []
|
||||
self.items.append(WheelItem('Drink 1 shot'))
|
||||
@ -96,7 +95,13 @@ class Game(gameUtils.Game):
|
||||
|
||||
# How many pixels away from the outer side of the
|
||||
# circle the text should be
|
||||
textMargin = 5
|
||||
self.textMargin = 5
|
||||
|
||||
|
||||
self.font = pygame.font.SysFont('', 50)
|
||||
self.drawWheel()
|
||||
|
||||
def drawWheel(self):
|
||||
# Calculate circle radius
|
||||
circleR = self.wheelSurf.size[0] / 2
|
||||
|
||||
@ -120,9 +125,9 @@ class Game(gameUtils.Game):
|
||||
# Create a surface that our text will be rendered onto
|
||||
textSurf = pygame.Surface(self.wheelSurf.size, pygame.SRCALPHA)
|
||||
# Render the item text
|
||||
text = font.render(item.text, True, (255, 255, 255))
|
||||
text = self.wheelFont.render(item.text, True, (255, 255, 255))
|
||||
# Draw the item text onto the text surface, centred to the right
|
||||
textSurf.blit(text, (textSurf.size[0]-text.get_width()-textMargin, self.size[1]//2 - text.get_height()//2))
|
||||
textSurf.blit(text, (textSurf.size[0]-text.get_width()-self.textMargin, self.size[1]//2 - text.get_height()//2))
|
||||
# Draw debug lines
|
||||
#pygame.draw.rect(textSurf, (0, 128, 255), (0, 0, textSurf.size[0], textSurf.size[1]), 1)
|
||||
#pygame.draw.line(textSurf, (255, 0, 0), (circleR, circleR), (textSurf.size[0], circleR))
|
||||
@ -132,8 +137,6 @@ class Game(gameUtils.Game):
|
||||
# Blit the text surface to the wheel surface
|
||||
self.wheelSurf.blit(textSurf, (0, 0))
|
||||
|
||||
self.font = pygame.font.SysFont('', 50)
|
||||
|
||||
def spinnerTick(self):
|
||||
# If there's a tick already playing
|
||||
if time.perf_counter() - self.lastTickTime < self.tickSfx.get_length():
|
||||
|
||||
Reference in New Issue
Block a user