34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import pygame
|
|
import math
|
|
thpi=math.pi/3
|
|
import utils
|
|
|
|
colours=[(196,0,0),(0,196,0),(0,0,196)]
|
|
|
|
class Ring():
|
|
def __init__(self,x,y,size,actions,grid):
|
|
self.x,self.y,self.size,self.grid=x,y,size,grid
|
|
self.init=0
|
|
self.selected=-1
|
|
self.actions=actions
|
|
self.width=2*math.pi/len(self.actions)
|
|
|
|
def draw(self,screen):
|
|
offset=self.size*self.init*0.5
|
|
l=len(self.actions)
|
|
for i in range(l,0,-1):
|
|
i-=1
|
|
colour=colours[i%len(colours)]
|
|
if i==len(colours) and 0==utils.sign((l-1)%3): colour=colours[1]
|
|
if i==self.selected: colour=tuple(n/2 for n in colour)
|
|
pygame.draw.arc(screen,colour,(self.x-offset,self.y-offset,offset*2,offset*2),-(i+1)*self.width,-i*self.width,int(offset*2/3))
|
|
|
|
def update(self,events):
|
|
if self.init<1: self.init+=0.05
|
|
else: self.init=1
|
|
self.selected=int(utils.get_direction(self.x,self.y,*pygame.mouse.get_pos())//self.width%len(self.actions))
|
|
mx,my=pygame.mouse.get_pos()
|
|
if ((self.y-my)**2+(self.x-mx)**2)**0.5<self.size/6: self.selected=-1
|
|
|
|
def __del__(self):
|
|
if self.selected>-1: self.actions[self.selected](self.x,self.y) |