Compare commits
8 Commits
a12a583444
...
0dc6555499
| Author | SHA1 | Date | |
|---|---|---|---|
| 0dc6555499 | |||
| 8b47026f0e | |||
| 097dd7486a | |||
| 6adb31f466 | |||
| db4f7d05f7 | |||
| dafeb80b77 | |||
| 3e4907f192 | |||
| 1366c10fd7 |
34
game.py
34
game.py
@ -9,9 +9,8 @@ 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: Convert fade in / out time to be random
|
||||
# TODO: Make random finer (to prevent a range of 4-5 only having two possible speeds)
|
||||
|
||||
def translate(value, aMin, aMax, bMin, bMax):
|
||||
@ -64,7 +63,7 @@ class Game(gameUtils.Game):
|
||||
# Don't remove this. It does important things. :3
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.wheelSurf = pygame.Surface([min(self.size)]*2) # Don't ask.
|
||||
self.wheelSurf = pygame.Surface([min(self.size)-100]*2) # Don't ask.
|
||||
self.wheelRotation = 0
|
||||
# How long (in seconds) it takes for the wheel to get to full speed
|
||||
self.WHEEL_SPIN_FADE_IN = 0.25
|
||||
@ -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'))
|
||||
@ -92,9 +91,17 @@ class Game(gameUtils.Game):
|
||||
self.items.append(WheelItem('Get shocked at 100%'))
|
||||
self.items.append(WheelItem('Get slapped by\neveryone in the room'))
|
||||
self.items.append(WheelItem('Respin, wheel hidden'))
|
||||
random.shuffle(self.items)
|
||||
|
||||
# How many pixels away from the outer side of the
|
||||
# circle the text should be
|
||||
textMargin = 5
|
||||
self.textMargin = 10
|
||||
|
||||
|
||||
self.font = pygame.font.SysFont('', 50)
|
||||
self.drawWheel()
|
||||
|
||||
def drawWheel(self):
|
||||
# Calculate circle radius
|
||||
circleR = self.wheelSurf.size[0] / 2
|
||||
|
||||
@ -118,20 +125,19 @@ 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, textSurf.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))
|
||||
#pygame.draw.line(textSurf, (0, 255, 0), (circleR, circleR), (circleR, textSurf.size[1]))
|
||||
#if idx < 1:
|
||||
# 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))
|
||||
# pygame.draw.line(textSurf, (0, 255, 0), (circleR, circleR), (circleR, textSurf.size[1]))
|
||||
# Rotate the text surface
|
||||
textSurf = rotateRad(textSurf, -rad)
|
||||
# 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():
|
||||
@ -159,6 +165,10 @@ class Game(gameUtils.Game):
|
||||
"""
|
||||
self.surf.fill((0, 0, 0))
|
||||
self.surf.blit(rotateDeg(gameUtils.centre(self.wheelSurf, self.size), self.wheelRotation), (0, 0))
|
||||
arrowX = (self.size[0] - self.wheelSurf.size[0]) // 2 + self.wheelSurf.size[0]
|
||||
arrowY = self.size[1] // 2
|
||||
arrowSize = 20
|
||||
pygame.draw.polygon(self.surf, (255, 255, 255), ((arrowX, arrowY), (arrowX+arrowSize, arrowY-arrowSize//2), (arrowX+arrowSize, arrowY+arrowSize//2)))
|
||||
|
||||
animTime = time.perf_counter() - self.wheelAnimStart
|
||||
if animTime < self.WHEEL_SPIN_FADE_IN + self.WHEEL_SPIN_FADE_OUT:
|
||||
|
||||
Reference in New Issue
Block a user