can now click and drag to move dial
This commit is contained in:
parent
36ca8638f6
commit
3e5c5cc896
@ -1,5 +1,4 @@
|
||||
import math
|
||||
|
||||
import pygame
|
||||
import os
|
||||
|
||||
@ -23,24 +22,20 @@ class Dial(pygame.sprite.Sprite):
|
||||
self.test = True
|
||||
|
||||
def update(self):
|
||||
if self.test:
|
||||
if self.test_cw:
|
||||
self.position += 0.01
|
||||
else:
|
||||
self.position -= 0.01
|
||||
if self.position > 1:
|
||||
self.position = 1
|
||||
self.test_cw = not self.test_cw
|
||||
if self.position < 0:
|
||||
self.position = 0
|
||||
self.test_cw = not self.test_cw
|
||||
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.center = (math.sin(math.radians(self.rotation)) * -300 + 360,
|
||||
math.cos(math.radians(self.rotation + 180)) * 300 + 360)
|
||||
def set_test(self, test_value):
|
||||
self.test = test_value
|
||||
|
||||
def move_dial(self, movement_ammount):
|
||||
self.position += movement_ammount
|
||||
|
||||
if self.position > 1:
|
||||
self.position = 1
|
||||
if self.position < 0:
|
||||
self.position = 0
|
||||
|
||||
|
||||
def main(windowed_mode):
|
||||
pygame.init()
|
||||
@ -66,10 +61,15 @@ def main(windowed_mode):
|
||||
pygame.display.flip()
|
||||
|
||||
running = True
|
||||
prev_mouse_pos = (0, 0)
|
||||
mouse_pos = (0, 0)
|
||||
get_mouse_speed = False
|
||||
while running:
|
||||
clock.tick(FPS)
|
||||
|
||||
# pygame.mouse.set_visible(False)
|
||||
prev_mouse_pos = mouse_pos
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
@ -78,13 +78,19 @@ def main(windowed_mode):
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
running = False
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
dial.set_test(True)
|
||||
get_mouse_speed = True
|
||||
if event.type == pygame.MOUSEBUTTONUP:
|
||||
dial.set_test(False)
|
||||
|
||||
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
get_mouse_speed = False
|
||||
|
||||
draw()
|
||||
if get_mouse_speed:
|
||||
mouse_diff = (prev_mouse_pos[0] - mouse_pos[0], prev_mouse_pos[1] - mouse_pos[1])
|
||||
movement_speed = math.sqrt((mouse_diff[0] ** 2) + (mouse_diff[1] ** 2))
|
||||
mouse_angle = math.atan2(mouse_pos[0] - 360, mouse_pos[1] - 360)
|
||||
diff_angle = math.atan2(mouse_diff[0], mouse_diff[1])
|
||||
speed_coeff = math.cos((mouse_angle - (0.5 * PI)) - diff_angle)
|
||||
final_speed = movement_speed * speed_coeff
|
||||
dial.move_dial(final_speed / -5000.0)
|
||||
|
||||
|
||||
pygame.quit()
|
||||
|
Loading…
Reference in New Issue
Block a user