change dial face to only move small triangle to improve performance

This commit is contained in:
Nicholas Dyer 2023-02-19 19:14:07 -05:00
parent 67a218d8e3
commit 4442bed2c2
No known key found for this signature in database
GPG Key ID: E4E6388793FA2105

View File

@ -1,3 +1,5 @@
import math
import pygame import pygame
import os import os
@ -13,23 +15,28 @@ class Dial(pygame.sprite.Sprite):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._base_image = pygame.image.load(script_dir + '/resources/dial-face.png') self._base_image = pygame.image.load(script_dir + '/resources/dial-face.png')
self.rotation = 0 self.position = 0
self.image = pygame.transform.rotate(self._base_image, 77-(2*77.5*self.rotation)) self.rotation = 77 - (2 * 77.5 * self.position)
self.image = pygame.transform.rotate(self._base_image, self.rotation)
self.rect = self._base_image.get_rect() self.rect = self._base_image.get_rect()
self.test_cw = True self.test_cw = True
def update(self): def update(self):
if self.test_cw: if self.test_cw:
self.rotation += 0.01 self.position += 0.01
else: else:
self.rotation -= 0.01 self.position -= 0.01
if self.rotation > 1: if self.position > 1:
self.rotation = 1 self.position = 1
self.test_cw = not self.test_cw self.test_cw = not self.test_cw
if self.rotation < 0: if self.position < 0:
self.rotation = 0 self.position = 0
self.test_cw = not self.test_cw self.test_cw = not self.test_cw
self.image = pygame.transform.rotate(self._base_image, 77-(2*77.5*self.rotation)) self.rotation = 77 - (2 * 77.5 * self.position)
self.image = pygame.transform.rotate(self._base_image, self.rotation)
self.rect = self.image.get_rect(center=self.rect.center) self.rect = self.image.get_rect(center=self.rect.center)
self.rect.center = (math.sin(math.radians(self.rotation)) * -300 + 360,
math.cos(math.radians(self.rotation + 180)) * 300 + 360)
def main(windowed_mode): def main(windowed_mode):