Ejemplo n.º 1
0
    def __init__(self):
        self.done = False
        self.world = World()

        self.ambient = pygame.mixer.Sound("audio/generic_ambient1.wav")        
        self.ambient.play(-1)
        
        self.fire_images = []
        self.hare_images_rf = []
        self.water_images = []

        self.player = MusicPlayer()       
        self.wait_for_song = 1200
        self.music_playing = False

        self.hare_timer = 1.0
        self.hare_timer_add = 1.0
        
        self.fire_timer = 1.0
        self.fire_timer_add = 1.0

        for i in xrange(3):
            filename = "images/fire%i.png" % (i+1)
            image = pygame.image.load(filename).convert_alpha()
            self.fire_images.append(image)

        for i in xrange(2):
            filename = "images/hare%i.png" % (i+1)
            image = pygame.image.load(filename).convert_alpha()
            self.hare_images_rf.append(image)

        for i in xrange(2):
            filename = "images/water%i.png" % (i+1)
            image = pygame.image.load(filename).convert_alpha()
            self.water_images.append(image)

        self.hare_images_lf = map(lambda i: pygame.transform.flip(i, 1, 0), self.hare_images_rf)

        self.humans = []
        self.viewports = []
        
        loader = ImageStripLoader("images/hunger_strip.png")
        self.world.hunger_images = []
        self.world.hunger_images = loader.images_from_coordinates((
            (0,0,64,64),(64,0,64,64),(128,0,64,64),(192,0,64,64),(256,0,64,64),(320,0,64,64),
        ))
        loader = ImageStripLoader("images/thirst_strip.png")
        self.world.thirst_images = []
        self.world.thirst_images = loader.images_from_coordinates((
            (0,0,64,64),(64,0,64,64),(128,0,64,64),(192,0,64,64),(256,0,64,64),(320,0,64,64),
        ))
        loader = ImageStripLoader("images/warmth_strip.png")
        self.world.warmth_images = []
        self.world.warmth_images = loader.images_from_coordinates((
            (0,0,64,64),(64,0,64,64),(128,0,64,64),(192,0,64,64),(256,0,64,64),(320,0,64,64),
        ))

        for human_count in xrange(2):
            human_red = Human(self.world, human_count+1)
            human_red.location = self.get_safe_spot()
            self.world.add_entity(human_red)
            self.humans.append(human_red)
            offset = human_count*SCREEN_SIZE[0]/2+1
            r = pygame.Rect(offset, 0, SCREEN_SIZE[0]/2-1, SCREEN_SIZE[1])
            viewport = Viewport(r, human_red)
            self.viewports.append(viewport)

        for fire_count in xrange(randint(10,50)):
            fire = Fire(self.world, self.fire_images)
            fire.location = self.get_safe_spot()
            self.world.add_entity(fire)
            self.world.fire_count += 1

        for water_count in xrange(randint(5, 10)):
            water = Water(self.world, self.water_images)
            water.location = self.get_safe_spot()
            self.world.add_entity(water)
            self.world.hare_count += 1