import pygame import enum import math import random import utils behaviours=enum.Enum('behaviours',['Cursor','Average']) class Worker(): def __init__(self,x,y,behaviour,grid): self.x,self.y,self.behaviour,self.grid=x,y,behaviour,grid self.direction=0 def target(self): if self.behaviour==behaviours.Cursor: return pygame.mouse.get_pos() if self.behaviour==behaviours.Average: return self.grid.mx,self.grid.my def draw(self,screen): pygame.draw.circle(screen,'grey',(self.x,self.y),8) pygame.draw.circle(screen,'black',(self.x+math.cos(self.dir)*5,self.y+math.sin(self.dir)*5),3) def update(self,events): mx,my=self.target() self.dir=utils.get_direction(self.x,self.y,mx,my) speed=min(5,((mx-self.x)**2+(my-self.y)**2)**0.5*0.1) self.x+=math.cos(self.dir)*speed self.y+=math.sin(self.dir)*speed