def __init__(self, world): self.grid = [] self.images = map(lambda f: loadImage("images/" + f), [ "tree1.png", "tree2.png", "tree3.png", "tree4.png", "tree5.png", "tree6.png", "tree8.png", "tree9.png", "tree10.png"]) print self.images for line_num in xrange(WORLD_SIZE[1]): line = [] y = line_num * BLOCK_SIZE for cell in xrange(WORLD_SIZE[0]): on_edge = False if cell==0 or cell==WORLD_SIZE[0]-1: on_edge = True if line_num==0 or line_num==WORLD_SIZE[1]-1: on_edge = True if on_edge or randint(0, 99) < 5: x = cell * BLOCK_SIZE block = Block(world, choice(self.images)) image_size = block.image.get_size() block.location = Vector2(x+image_size[0]/2, y+BLOCK_SIZE) line.append(block) else: line.append(None) self.grid.append(line)
def process(self, time_passed): self.hunger -= time_passed*2.5 self.thirst -= time_passed*2.5 self.heat -= time_passed*2.5 self.age += time_passed pressed = pygame.key.get_pressed() move_vector = (0, 0) if(self.joycontrol == -1): for m in (self.key_map[key] for key in self.key_map if pressed[key]): move_vector = map(sum, zip(move_vector, m)) else: x = self.joystick.get_axis(0) y = self.joystick.get_axis(1) if math.fabs(x) < 0.1: x = 0. if math.fabs(y) < 0.1: y = 0. move_vector = Vector2(x,y) self.heading = Vector2(move_vector) if move_vector[0] < 0.0: self.left_facing = True elif move_vector[0] > 0.0: self.left_facing = False if self.heading.get_length() > 0.0: self.frame_timer -= time_passed if self.frame_timer < 0.0: self.frame_timer = FRAME_TIME self.current_frame += 1 if self.current_frame >= len(self.images_rf): self.current_frame = 0 GameEntity.process(self, time_passed) hare = self.world.get_close_entity("hare", self.location, 80) if hare: self.hunger = min(self.hunger+20.0, 120.0) self.world.remove_entity(hare) self.world.hare_count -= 1 self.sounds["eat"].play() fire = self.world.get_close_entity("fire", self.location, 80) if fire: self.heat = min(self.heat+time_passed*20.0, 120) water = self.world.get_close_entity("water", self.location, 80) if water: self.thirst = min(self.thirst+time_passed*20.0, 120) if self.hunger < 0.0 or self.heat < 0.0 or self.thirst < 0.0: self.world.remove_entity(self) self.world.human_count -= 1 tomb_stone = Block(self.world, loadImage("images/tomb.png")) tomb_stone.location = self.location self.world.add_entity(tomb_stone) self.hunger_image_index = min(5,int(6.0*self.hunger/120.0)) self.thirst_image_index = min(5,int(6.0*self.thirst/120.0)) self.heat_image_index = min(5,int(6.0*self.heat/120.0))