def releaseAnklebiters(): global spawned if not 'dynamite3' in savedata.__dict__.keys() and not spawned: indeces = ((6,6), (9,6), (12,6), (4, 8), (14, 8), (2, 10), (6, 10), (12, 10), (16, 10), (4,11), (14, 11)) for i in indeces: system.engine.addEntity(Carnivore(ika.Entity(i[0]*16+8, i[1]*16, 1, "carnivore.ika-sprite"))) spawned = 1
def roarState(self): # spawn one to five Carnivores to irritate the shit out of the player self.anim = 'roar' s = False sound.serpentRoar.Play() for wait in range(200): n = self._animator.curFrame - 12 # Yet another hack. ika.Map.xwin += ika.Random(-n, n + 1) ika.Map.ywin += ika.Random(-n, n + 1) yield None # need to destroy old corpses (a first!) for e in system.engine.entities: if e.stats.hp == 0 and isinstance(e, Enemy): system.engine.destroyEntity(e) for q in range(ika.Random(1, 4)): x, y = 320 + (q * 60), 588 n = ika.EntitiesAt(x, y, x + 16, y + 16, self.layer) if not n: if self.stats.hp > self.stats.maxhp / 2: #normal if ika.Random(0, 2): e = Carnivore( ika.Entity(x, y, self.layer, 'carnivore.ika-sprite')) else: e = AnkleBiter( ika.Entity(x, y, self.layer, 'anklebiter.ika-sprite')) else: #half dead, stronger spawns if ika.Random(0, 2): e = Devourer( ika.Entity(x, y, self.layer, 'devourer.ika-sprite')) else: e = Carnivore( ika.Entity(x, y, self.layer, 'carnivore.ika-sprite')) system.engine.addEntity(e) e.mood = e.attackMood
def __init__(self): trees = list() caves = list() ponds = list() herbivores = list() carnivores = list() spaces = list() shared_queue = queue.Queue(maxsize=1) rows = [n for n in range(0, 17, 1)] cols = [n for n in range(0, 31, 1)] pygame.init() surface = pygame.display.set_mode((1280, 720)) pygame.display.set_caption('Rumiany Wschód') surface.fill(Board.GREEN) self.redraw_lines(rows, cols, surface) for row in rows: for col in cols: spaces.append((col, row)) coords = random.sample(spaces, Board.TREE_NUMBER+Board.CAVE_NUMBER+Board.POND_NUMBER) for i in range(Board.TREE_NUMBER): a, b = coords[i] trees.append(Tree(a, b)) for i in range(Board.TREE_NUMBER, Board.CAVE_NUMBER + Board.TREE_NUMBER): a, b = coords[i] caves.append(Cave(a, b)) for i in range(Board.CAVE_NUMBER + Board.TREE_NUMBER, Board.POND_NUMBER + Board.CAVE_NUMBER + Board.TREE_NUMBER): a, b = coords[i] ponds.append(Pond(a, b)) self.redraw_resources(surface, coords) #Occupancy map occupancy_map = self.init_map(rows, cols, spaces, coords) shared_queue.put(occupancy_map) #Creating the herbivore threads herbivores = [Herbivore(i, i, shared_queue, ponds, trees, caves) for i in range(8)] #Creating the carnivore threads carnivores = [Carnivore(i+6, i+6, shared_queue, ponds, herbivores, carnivores) for i in range(2)] for i in herbivores: i.herbivores = herbivores for i in carnivores: i.carnivores = carnivores for i in herbivores: i.start() for i in carnivores: i.start() while True: #herbivore reproduction for i in herbivores: if i.alive: a, b = i.get_position() if i.ready_to_reproduce: new_herbivore = Herbivore(a, b, shared_queue, ponds, trees, caves) i.ready_to_reproduce = False herbivores.append(new_herbivore) new_herbivore.start() else: herbivores.remove(i) for i in herbivores: i.herbivores = herbivores for i in carnivores: if i.alive: a, b = i.get_position() if i.ready_to_reproduce: new_carnivore = Carnivore(a, b, shared_queue, ponds, herbivores, carnivores) i.ready_to_reproduce = False carnivores.append(new_carnivore) new_carnivore.start() else: carnivores.remove(i) for i in carnivores: i.carnivores = carnivores # occupancy_map = shared_queue.get(True) # occupancy_map = self.init_map(rows, cols, spaces, coords) # shared_queue.put(occupancy_map) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() #Killing animals before exit for i in herbivores: i.alive = False for i in carnivores: i.alive = False sys.exit() #Redrawing everything surface.fill(Board.GREEN) self.redraw_lines(rows, cols, surface) self.redraw_resources(surface, coords) self.redraw_herbivores(surface, herbivores) self.redraw_carnivores(surface, carnivores) pygame.display.update()
def test_it_eats_anything(self): carnivore = Carnivore() carnivore.eat(1) carnivore.eat(map) carnivore.eat({'i am': 'uneatable'}) carnivore.eat(object) carnivore.eat(range(100)) carnivore.eat(carnivore) carnivore.stomach |should| equal_to([ 1, map, {'i am': 'uneatable'}, object, range(100), carnivore])
def it_ignores_digestion_at_an_empty_stomach(self): carnivore = Carnivore() carnivore.stomach |should| be_empty carnivore.digest() carnivore.stomach |should| be_empty
def test_it_digests_oldest_eaten_thing(self): carnivore = Carnivore() carnivore.eat(1) carnivore.eat(2) carnivore.eat(3) carnivore.digest() carnivore.stomach |should| equal_to([2, 3]) carnivore.digest() carnivore.stomach |should| equal_to([3]) carnivore.eat(4) carnivore.digest() carnivore.stomach |should| equal_to([4])