-
Notifications
You must be signed in to change notification settings - Fork 1
/
spinner.py
38 lines (31 loc) · 1.17 KB
/
spinner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pygame
class Spinner(pygame.sprite.Sprite):
"""
Class for the spinner sprite.
"""
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('spinner_sprite.png')
self.image.set_colorkey(self.image.get_at((0,0)))
self.orig_image = self.image
self.rotation = 360.0
self.min_rotation = 360.0
self.loc = (120, 459) #correct location on phone
self.next_update_time = 0
#adapted from:
#http://www.pygame.org/docs/ref/transform.html#pygame.transform.rotate
def rotate(self, degrees):
"""
Rotate the image sprite in place
"""
orig_rect = self.orig_image.get_rect()
self.image = pygame.transform.rotate(self.orig_image, degrees)
rot_rect = orig_rect.copy()
rot_rect.center = self.image.get_rect().center
self.image = self.image.subsurface(rot_rect).copy()
def update(self, degrees):
self.rotation += degrees
self.rotation = max(29.4, min(self.rotation, 360.0))
self.min_rotation = min(self.rotation, self.min_rotation)
#print self.rotation
self.rotate(self.rotation)