def life_and_death(self): if not self.bool_showingSymptoms: super(InfectedCell, self).life_and_death() elif self.typeOfInfection == "on_death_disperse": #self.dispersionCount += self.timeTilSymptoms % 10 if self.energy > self.timeToDie: self.energy -= self.timeToDie else: self.mass -= self.timeToDie if self.mass <= 0.1: environment.add_virus_at_location(self.dispersionCount,self.killer.pos) World.kill_cell(self) passer = self.keyForChildren - (self.keyForChildren % 10) self.killer.keyGen(passer)
def life_and_death(self): if not self.bool_showingSymptoms: super(InfectedCell, self).life_and_death() elif self.typeOfInfection == "on_death_disperse": #self.dispersionCount += self.timeTilSymptoms % 10 if self.energy > self.timeToDie: self.energy -= self.timeToDie else: self.mass -= self.timeToDie if self.mass <= 0.1: environment.add_virus_at_location(self.dispersionCount, self.killer.pos) World.kill_cell(self) passer = self.keyForChildren - (self.keyForChildren % 10) self.killer.keyGen(passer)
def run(self): while True: # make the background white windowSurfaceObj.fill(whiteColor) pygame.draw.rect(windowSurfaceObj, blackColor, (.35 * 3 * world_width, 0, 10, display_height)) # World's food set is changing while the for loop runs, so we must lock it so that we do not iterate over a changing set World.lock.acquire() for food in World.food_set: # convert the food coordinates too coordinates that pygame can understand x, y = convert_to_display_loc(food.pos) # draw the food circles pygame.gfxdraw.filled_circle(windowSurfaceObj, x, y, int(0.01 * display_width), redColor) # draw all the cells for cell in World.cell_list: sys.stderr.write("") if isinstance(cell, Virus): #draw virus self.draw_wrapping_square(cell, 5, pygame.Color(*cell.color)) else: self.draw_wrapping_circle(cell, cell.radius, pygame.Color(*cell.color)) # we're no longer going through the cell list, so now allow other parts of this project to change the cell list World.lock.release() # exit if the user says to for event in pygame.event.get(): if event.type == QUIT: pygame.quit() return () # add food or cell via left/right mouse click elif event.type == MOUSEBUTTONDOWN: # print "mouse button down" if event.button == 1: # print "got position" pos = Position(convert_envi_loc(event.pos)) for button in buttons: if math.sqrt(( (buttons[button].xloc - event.pos[0])**2) + ((buttons[button].yloc - event.pos[1])**2)) < 30: # print "button clicked" buttons[button].click() else: if event.pos[0] < world_width and event.pos[ 1] < world_height: # print "adding food at", event.pos environment.add_food_at_location(pos) elif event.button == 2: # print "adding virus" pos = Position(convert_envi_loc(event.pos)) environment.add_virus_at_location(1, pos) elif event.button == 3: # print "adding cell" pos = Position(convert_envi_loc(event.pos)) environment.add_cell_at_location(pos) # allow user to change resistance # increase resistance if the user hits the U elif event.type == KEYDOWN: if event.key == K_u: World.resistance += 1000 # decrease resistance if the user hits D # prevent them from making resistance negative elif event.key == K_d: new_resistance = World.resistance - 250 if new_resistance >= 0: World.resistance = new_resistance else: pass # update the screen draw_buttons() pygame.display.update()
def run(self): while True: # make the background white windowSurfaceObj.fill(whiteColor) pygame.draw.rect(windowSurfaceObj, blackColor, (.35*3*world_width,0,10,display_height)) # World's food set is changing while the for loop runs, so we must lock it so that we do not iterate over a changing set World.lock.acquire() for food in World.food_set: # convert the food coordinates too coordinates that pygame can understand x, y = convert_to_display_loc(food.pos) # draw the food circles pygame.gfxdraw.filled_circle(windowSurfaceObj, x, y, int(0.01*display_width), redColor) # draw all the cells for cell in World.cell_list: sys.stderr.write("") if isinstance(cell, Virus): #draw virus self.draw_wrapping_square(cell, 5, pygame.Color(*cell.color)) else: self.draw_wrapping_circle(cell, cell.radius, pygame.Color(*cell.color)) # we're no longer going through the cell list, so now allow other parts of this project to change the cell list World.lock.release() # exit if the user says to for event in pygame.event.get(): if event.type ==QUIT: pygame.quit() return () # add food or cell via left/right mouse click elif event.type == MOUSEBUTTONDOWN: # print "mouse button down" if event.button == 1: # print "got position" pos = Position(convert_envi_loc(event.pos)) for button in buttons: if math.sqrt(((buttons[button].xloc-event.pos[0])**2)+((buttons[button].yloc-event.pos[1])**2)) < 30: # print "button clicked" buttons[button].click() else: if event.pos[0]<world_width and event.pos[1]<world_height: # print "adding food at", event.pos environment.add_food_at_location(pos) elif event.button == 2: # print "adding virus" pos = Position(convert_envi_loc(event.pos)) environment.add_virus_at_location(1,pos) elif event.button == 3: # print "adding cell" pos = Position(convert_envi_loc(event.pos)) environment.add_cell_at_location(pos) # allow user to change resistance # increase resistance if the user hits the U elif event.type ==KEYDOWN: if event.key == K_u: World.resistance +=1000 # decrease resistance if the user hits D # prevent them from making resistance negative elif event.key == K_d: new_resistance = World.resistance - 250 if new_resistance >=0: World.resistance = new_resistance else: pass # update the screen draw_buttons() pygame.display.update()