def update(self): actor, goody = self.actor, self.actor.goody if actor.world.outside(actor): actor.kill() goody.pos = actor.world.randomPosition() return if actor.health <= 0: actor.world.killEnemy(actor) goody.pos = vector(goody.pos) return if actor.health < 0.5*ENEMY_HEALTH: actor.stateMachine.ChangeState(RunAway(actor)) goody.pos = vector(goody.pos) return
def __init__(self, pos, world, *groups): pygame.sprite.Sprite.__init__(self, *groups) self.image = GM.makeimage.star(GOODY_SIZE, GOODY_COLOR) self.rect = self.image.get_rect() self.pos = vector(pos) self.rect.center = self.pos self.world = world
def __init__(self, pos, world, *groups): pygame.sprite.Sprite.__init__(self, *groups) self.image = GM.makeimage.star(24, (255,0,0)) self.rect = self.image.get_rect() self.pos = vector(pos) self.rect.center = self.pos self.world = world
def update(self, actor): goody = actor.goody if actor.world.outside(actor): actor.kill() goody.pos = actor.world.randomPosition() return if actor.health <= 0: actor.world.killEnemy(actor) return if actor.health < 0.5 * ENEMY_HEALTH: actor.stateMachine.ChangeState(RunAway()) goody.pos = vector(goody.pos) return
def __init__(self, pos, world, *groups): pygame.sprite.Sprite.__init__(self, *groups) self.images = GM.makeimage.rotating_arrow(ENEMY_SIZE, ENEMY_COLOR) self.frame = 0 self.image = self.images[self.frame] self.rect = self.image.get_rect() self.pos = vector(pos) self.rect.center = self.pos self.world = world self.heading = randomNormalVector() self.speed = ENEMY_SPEED self.stateMachine = StateMachine(self, Sneak()) self.health = ENEMY_HEALTH
def __init__(self, pos, world, *groups): pygame.sprite.Sprite.__init__(self, *groups) self.images = GM.makeimage.rotating_arrow(GATHERER_SIZE,GATHERER_COLOR) self.frame = 0 self.image = self.images[self.frame] self.rect = self.image.get_rect() self.pos = vector(pos) self.rect.center = self.pos self.world = world self.heading = randomNormalVector() self.speed = GATHERER_SPEED self.stateMachine = StateMachine(self, Search()) self.goody = None
def star(size,color): surface = pygame.Surface((size,size)).convert() if color[0] == color[1] == color[2] == 0: backgroundColor = (255,255,255) else: backgroundColor = (0,0,0) surface.fill(backgroundColor) surface.set_colorkey(backgroundColor) radius = size/2.0 center = vector(radius,radius) angles1 = [i*2*N.pi/5.0 - N.pi/2.0 for i in range(5)] p1 = [(radius*N.cos(a), radius*N.sin(a)) for a in angles1] angles2 = [i*2*N.pi/5.0 - N.pi/2.0 + 2*N.pi/10.0 for i in range(5)] p2 = [(0.4*radius*N.cos(a),0.4*radius*N.sin(a)) for a in angles2] points = [] for a,b in zip(p1,p2): points.extend((center+a,center+b)) width=0 pygame.draw.polygon(surface, color, points, width) return surface
def star(size, color): surface = pygame.Surface((size, size)).convert() if color[0] == color[1] == color[2] == 0: backgroundColor = (255, 255, 255) else: backgroundColor = (0, 0, 0) surface.fill(backgroundColor) surface.set_colorkey(backgroundColor) radius = size / 2.0 center = vector(radius, radius) angles1 = [i * 2 * N.pi / 5.0 - N.pi / 2.0 for i in range(5)] p1 = [(radius * N.cos(a), radius * N.sin(a)) for a in angles1] angles2 = [ i * 2 * N.pi / 5.0 - N.pi / 2.0 + 2 * N.pi / 10.0 for i in range(5) ] p2 = [(0.4 * radius * N.cos(a), 0.4 * radius * N.sin(a)) for a in angles2] points = [] for a, b in zip(p1, p2): points.extend((center + a, center + b)) width = 0 pygame.draw.polygon(surface, color, points, width) return surface
def arrow(size, angle, color, fill=True): surface = pygame.Surface((size, size)).convert() if color[0] == color[1] == color[2] == 0: backgroundColor = (255, 255, 255) else: backgroundColor = (0, 0, 0) surface.fill(backgroundColor) surface.set_colorkey(backgroundColor) radius = size / 2.0 angleleft = N.pi * (angle + 150) / 180.0 angleright = N.pi * (angle - 150) / 180.0 angle = N.pi * angle / 180.0 center = vector(radius, radius) p1 = center + (radius * N.cos(angle), radius * N.sin(angle)) p2 = center + (radius * N.cos(angleleft), radius * N.sin(angleleft)) p3 = center + (radius * N.cos(angleright), radius * N.sin(angleright)) if fill: width = 0 else: width = 1 pygame.draw.polygon(surface, color, [p1, p2, p3], width) return surface
def arrow(size, angle, color, fill=True): surface = pygame.Surface((size,size)).convert() if color[0] == color[1] == color[2] == 0: backgroundColor = (255,255,255) else: backgroundColor = (0,0,0) surface.fill(backgroundColor) surface.set_colorkey(backgroundColor) radius = size/2.0 angleleft = N.pi*(angle+150)/180.0 angleright = N.pi*(angle-150)/180.0 angle = N.pi*angle/180.0 center = vector(radius, radius) p1 = center + (radius*N.cos(angle), radius*N.sin(angle)) p2 = center + (radius*N.cos(angleleft), radius*N.sin(angleleft)) p3 = center + (radius*N.cos(angleright), radius*N.sin(angleright)) if fill: width=0 else: width=1 pygame.draw.polygon(surface, color, [p1,p2,p3], width) return surface
def exit(self, actor): goody = actor.goody goody.pos = vector(actor.pos) actor.goody = None
def randomPosition(self): x = random.randint(0,self.screen.get_width()-1) y = random.randint(0,self.screen.get_height()-1) return vector(x,y)
def exit(self): actor, goody = self.actor, self.actor.goody goody.pos = vector(actor.pos) actor.goody = None
def randomPosition(self): x = random.randint(0, self.screen.get_width() - 1) y = random.randint(0, self.screen.get_height() - 1) return vector(x, y)