def achievement(self): killed = self.hud.visitors_killed if killed >= 1000 and 1000 not in self.achievements_done:#not killed == self.last_rendered_achievement: #self.last_rendered_achievement = killed self.achievements_done.append(1000) self.achievement_image = image_util.load_image("achievement_1000.png") self.achievement_countdown = 200 elif killed >= 500 and 500 not in self.achievements_done:## and not killed == self.last_rendered_achievement: self.achievements_done.append(500) #self.last_rendered_achievement = killed self.achievement_image = image_util.load_image("achievement_500.png") self.achievement_countdown = 200 elif killed >= 100 and 100 not in self.achievements_done:## and not killed == self.last_rendered_achievement: self.achievements_done.append(100) #self.last_rendered_achievement = killed self.achievement_image = image_util.load_image("achievement_100.png") self.achievement_countdown = 200 elif killed >= 10 and 10 not in self.achievements_done:## and not killed == self.last_rendered_achievement: self.achievements_done.append(10) #self.last_rendered_achievement = killed self.achievement_image = image_util.load_image("achievement_10.png") self.achievement_countdown = 200 if self.achievement_countdown > 0: self.screen.blit(self.achievement_image, (250,100)) self.achievement_countdown -= 1
def __init__(self): super().__init__() self.max_score = 12 self.level_name = 'level1' self.stone = "{}/stone.png".format(IMAGES_FOLDER) self.stone_image = iu.load_image(self.stone) self.portal = "{}/portal.png".format(IMAGES_FOLDER) self.portal_image = iu.load_image(self.portal) self.wall_image = iu.load_image(self.wall) self.ground_image = iu.load_image(self.ground) self.rock_positions = [ (150, 150), (350, 350), (150, 250), (550, 50), (250, 90), (150, 110), ] self.portal1 = None self.portal2 = None self.construct() self.next_level = Level3() self.song = "{}/level2.ogg".format(SOUND_FOLDER)
def __init__(self): super().__init__() self.wall_image = iu.load_image(self.wall) self.ground_image = iu.load_image(self.ground) self.construct()
def __init__(self, image, x, y, game): self.name = "Tasmanian Devil" self.init_image = image_util.load_image("tasmanian.png") self.init_x = x self.init_y = y image = image_util.load_image("tasmanian.png") attack_image = image_util.load_image("tasmanian_attack.png") unselected_images = image_util.load_sliced_sprites(32, 32, "tasmanian_unselected.png") rect = image.get_rect() rect.left = 5 rect.top = 5 rect.width = rect.width-10 rect.height = rect.height-10 speed = 3 attack_length = 250 attack_delay = 200 Player.__init__(self, game, x, y, image, attack_image, unselected_images, rect, speed, attack_length, attack_delay) self.canDriveCar = False
def __init__(self, image, x, y, game): self.name = "Kangaroo" image = image_util.load_image("kangaroo.png") self.init_image = image self.init_x = x self.init_y = y attack_image = image_util.load_image("taz_attack.png") unselected_images = image_util.load_sliced_sprites(32, 32, "kangaroo_unselected.png") rect = image.get_rect() rect.left = 5 rect.top = 5 rect.width = rect.width-10 rect.height = rect.height-10 speed = 3 attack_length = 250 attack_delay = 200 Player.__init__(self, game, x, y, image, attack_image, unselected_images, rect, speed, attack_length, attack_delay) self.attack_sprite = Sprite() self.attack_sprite.rect = image.get_rect() self.canDriveCar = True # jump self.jump_images = image_util.load_sliced_sprites(32, 32, "kangaroo_jump.png") self.jump_init_time = 50 self.jump_time = 500 self.is_jumping = False self.last_jump = -self.jump_time
def __init__(self, image, x, y, game): self.name = "Dingo" self.init_image = image_util.load_image("dingo.png") self.init_x = x self.init_y = y image = image_util.load_image("dingo.png") attack_image = image_util.load_image("dingo_attack.png") unselected_images = image_util.load_sliced_sprites(32, 32, "dingo_unselected.png") rect = image.get_rect() rect.left = 5 rect.top = 5 rect.width = rect.width-10 rect.height = rect.height-10 speed = 3 attack_length = 250 attack_delay = 200 Player.__init__(self, game, x, y, image, attack_image, unselected_images, rect, speed, attack_length, attack_delay) self.left_offset = 5 self.top_offset = 5 self.rect.width = 32 - self.left_offset * 2 self.rect.height = self.rect.width self.attack_sprite = Sprite() self.attack_sprite.rect = image.get_rect() #self.attack_sprite.rect.width += 10 #self.attack_sprite.rect.height += 10 self.canDriveCar = False
def __init__(self, image, x, y, game): self.name = "Brown Snake" self.init_image = image_util.load_image("snake.png") self.init_x = x self.init_y = y image = image_util.load_image("snake.png") attack_image = image_util.load_image("snake_attack.png") unselected_images = image_util.load_sliced_sprites( 32, 32, "snake_unselected.png") rect = image.get_rect() rect.left = 5 rect.top = 5 rect.width = rect.width - 10 rect.height = rect.height - 10 speed = 3 attack_length = 250 attack_delay = 200 Player.__init__(self, game, x, y, image, attack_image, unselected_images, rect, speed, attack_length, attack_delay) self.canDriveCar = False
def free_animal(self, animal_name): animals_freed[animal_name] = image_util.load_image(animal_info.info[animal_name][3]) self.hud.draw() if len(animals_freed) is 5 and self.animalsFreed is False: cutscene = Cutscene(self, "escape the zoo", \ [image_util.load_image(os.path.join("cutscenes","escape_the_zoo.png"))], \ image_util.load_sliced_sprites(210, 80, os.path.join("cutscenes","press_enter.png"))); cutscene.fire(self.player) self.animalsFreed = True
def __init__(self, image, x, y, game): self.name = "Koala" self.init_image = image self.init_x = x self.init_y = y attack_image = image_util.load_image("koala_attack.png") unselected_images = image_util.load_sliced_sprites(32, 32, "koala_unselected.png") rect = image.get_rect() rect.left = 5 rect.top = 5 rect.width = rect.width-10 rect.height = rect.height-10 speed = 3 attack_length = 250 attack_delay = 200 Player.__init__(self, game, x, y, image, attack_image, unselected_images, rect, speed, attack_length, attack_delay) self.normal_rect = self.rect self.normal_left_offset = self.left_offset self.normal_top_offset = self.top_offset self.climbing_rect = pygame.Rect(15,15,rect.width - 30, rect.height - 30) self.climbing_left_offset = 15 self.climbing_top_offset = 15 self.attack_sprite = Sprite() self.attack_sprite.rect = image.get_rect() self.canDriveCar = False self.isInTree = False
def ranOver(self, source): self.kill() if "Koala" not in animals_freed: self.game.free_animal("Koala") cutscene = Cutscene(self.game, "freed_koalas", \ [image_util.load_image(os.path.join("cutscenes","koala_intro.png"))], \ image_util.load_sliced_sprites(210, 80, os.path.join("cutscenes","press_enter.png"))); cutscene.fire(self.game.player)
def __init__(self): self.max_score = None self.level_name = 'NONE' self.wall = "{}/brick.png".format(IMAGES_FOLDER) self.ground = "{}/grass.png".format(IMAGES_FOLDER) self.wall_image = iu.load_image(self.wall) self.ground_image = iu.load_image(self.ground) self.all_sprites = pygame.sprite.OrderedUpdates() self.obstacles = pygame.sprite.Group() self.portals = pygame.sprite.Group() self.bg_surface = pygame.Surface((SCREEN_W, SCREEN_H)) self.bg_surface = self.bg_surface.convert() self.next_level = None
def __init__(self, x, y, image=None, image_path=None): super().__init__() self.image = iu.load_image("{}/{}".format( IMAGES_FOLDER, image_path)) if image is None else image self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y
def ranOver(self, source): self.kill() if "Koala" not in animals_freed: self.game.free_animal("Koala") cutscene = Cutscene(self.game, "freed_koalas", \ [image_util.load_image(os.path.join("cutscenes","koala_intro.png"))], \ image_util.load_sliced_sprites(210, 80, os.path.join("cutscenes","press_enter.png"))) cutscene.fire(self.game.player)
def __init__(self): super().__init__() self.stone = "{}/stone.png".format(IMAGES_FOLDER) self.stone_image = iu.load_image(self.stone) self.portal = "{}/portal.png".format(IMAGES_FOLDER) self.portal_image = iu.load_image(self.portal) self.wall_image = iu.load_image(self.wall) self.ground_image = iu.load_image(self.ground) self.construct() self.level_name = 'endless' self.song = "{}/level3.ogg".format(SOUND_FOLDER) self.portal1 = None self.portal2 = None
def __init__(self, game): self.visitors_killed = 0 self.zookeepers_killed = 0 self.game = game self.screen = self.game.screen self.background = image_util.load_image("hud.png") self.name = "" self.portrait = image_util.load_image("blank_portrait.png") self.ability = "" self.canDrive = "" self.key_image = image_util.load_image("key.png") self.x = 0 self.y = MAP_HEIGHT self.draw()
def __init__(self, game): self.game = game self.screen = self.game.screen self.image = image_util.load_image("credits.png") self.back_rect = Rect(656,540,131,55) self.pressed = [] for key in pygame.key.get_pressed(): self.pressed.append( True ) self.go_back = False
def __init__(self, x, y, head=False, name=None): super().__init__() self.ported = 0 self.name = name self.direction = 'R' self.next_direction = 'R' self.is_head = head self.following = None if self.is_head: self.image = iu.load_image( "{}/snake_head.png".format(IMAGES_FOLDER)) else: self.image = iu.load_image( "{}/snake_body.png".format(IMAGES_FOLDER)) self.original_image = self.image self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.moved = 0
def __init__(self, image, x, y, game): self.name = "Kangaroo" image = image_util.load_image("kangaroo.png") self.init_image = image self.init_x = x self.init_y = y attack_image = image_util.load_image("taz_attack.png") unselected_images = image_util.load_sliced_sprites( 32, 32, "kangaroo_unselected.png") rect = image.get_rect() rect.left = 5 rect.top = 5 rect.width = rect.width - 10 rect.height = rect.height - 10 speed = 3 attack_length = 250 attack_delay = 200 Player.__init__(self, game, x, y, image, attack_image, unselected_images, rect, speed, attack_length, attack_delay) self.attack_sprite = Sprite() self.attack_sprite.rect = image.get_rect() self.canDriveCar = True # jump self.jump_images = image_util.load_sliced_sprites( 32, 32, "kangaroo_jump.png") self.jump_init_time = 50 self.jump_time = 500 self.is_jumping = False self.last_jump = -self.jump_time
def __init__(self, game): self.game = game self.screen = self.game.screen self.image = image_util.load_image("pause_screen.png") self.index = 0 self.continue_rect = Rect(275, 200, 245, 70) self.controls_rect = Rect(275, 290, 245, 70) self.mainmenu_rect = Rect(275, 380, 245, 70) self.pressed = [] for key in pygame.key.get_pressed(): self.pressed.append(True) self.unpause = False self.control_screen = ControlScreen(self.game)
def __init__(self, screen): self.screen = screen self.map_screen = self.screen.subsurface(0, 0, MAP_WIDTH, MAP_HEIGHT) #pygame.display.set_icon(pygame.image.load(os.path.join("images", "ui","icon.png"))) self.loaded_maps = {} self.current_map = None pygame.mouse.set_visible(1); self.hasKey = False self.animalsFreed = False self.soundUtil = SoundUtil() self.soundUtil.sound_on = True self.pauseMenu = PauseScreen(self) self.cursor = Sprite() self.cursor.rect = Rect(0,0,1,1) self.hud = Hud(self) self.player_group = Group() self.player = Taz(image_util.load_image("tasmanian.png"), 1, 1, self) self.player.inUse = True self.player.current_image = self.player.image self.hud.set_player(self.player) self.last_rendered_achievement = 0 self.achievement_countdown = 0 self.clock = pygame.time.Clock() self.achievements_done = [] self.pressed = [] for key in pygame.key.get_pressed(): self.pressed.append( True ) self.loadLevel("jail.txt") self.isGameOver = False self.returnToMainMenu = False
def __init__(self, screen): self.game = Game(screen) self.screen = screen self.image = image_util.load_image("mainmenu.png") self.index = 0 self.play_rect = Rect(275,200,245,70) self.controls_rect = Rect(275,290,245,70) self.quit_rect = Rect(275,380,245,70) self.credits_rect = Rect(610, 530, 180, 60) self.controlScreen = ControlScreen(self.game) self.creditsScreen = CreditsScreen(self.game) self.pressed = [] for key in pygame.key.get_pressed(): self.pressed.append( True )
def __init__(self, image, x, y, game): self.name = "Koala" self.init_image = image self.init_x = x self.init_y = y attack_image = image_util.load_image("koala_attack.png") unselected_images = image_util.load_sliced_sprites( 32, 32, "koala_unselected.png") rect = image.get_rect() rect.left = 5 rect.top = 5 rect.width = rect.width - 10 rect.height = rect.height - 10 speed = 3 attack_length = 250 attack_delay = 200 Player.__init__(self, game, x, y, image, attack_image, unselected_images, rect, speed, attack_length, attack_delay) self.normal_rect = self.rect self.normal_left_offset = self.left_offset self.normal_top_offset = self.top_offset self.climbing_rect = pygame.Rect(15, 15, rect.width - 30, rect.height - 30) self.climbing_left_offset = 15 self.climbing_top_offset = 15 self.attack_sprite = Sprite() self.attack_sprite.rect = image.get_rect() self.canDriveCar = False self.isInTree = False
def load_map(self, file): lines = file.readlines() # Load the tile map for idx in xrange(len(lines)): line = lines[idx] if line == " \n": self.tiles_high = idx self.height = self.tiles_high * self.tile_size for y in xrange(0, self.tiles_high): line = lines[y] parsed_comments = line.split('#'); line_tiles = parsed_comments[0].replace(' ','').replace('\n','').split(',') self.tiles_wide = len(line_tiles) self.width = self.tiles_wide * self.tile_size self.num_tiles = self.tiles_wide * self.tiles_high x = 0 for key in line_tiles: tile = TileFactory.generateTile(key,x,y,self.game) self.tiles.append(tile) if not tile.walkable: self.unwalkable_tiles.add(tile) if not tile.visible: self.unjumpable_tiles.add(tile) if not tile.swimmable and not tile.walkable: self.unswimmable_and_unwalkable_tiles.add(tile) x += 1 index = self.tiles_high while lines[index] is "\n": index += 1 index += 1 # Load the sprite map for y in xrange(index, self.tiles_high + index): line = lines[y] parsed_comments = line.split('#'); line_tiles = parsed_comments[0].replace(' ','').replace('\n','').split(',') x = 0 for key in line_tiles: if key is not None and key is not '': object = TileFactory.generateSprite(key,x,y - index,self.game) if not isinstance(object, Player): self.not_player.add( object ) self.game_objects.add( object ) x += 1 # special commands index = self.tiles_high + index while index < len(lines): if lines[index] is "\n": index += 1 continue command = lines[index].split(' ') if command[0] == 'link': start_coords = command[1].split(',') end_map = command[2] end_coords = command[3].replace('\n','').split(',') self.events[int(start_coords[1])*self.tiles_wide+int(start_coords[0])] = LinkEvent(start_coords, end_coords, end_map, self.game) elif command[0] == 'dialog': start_coords = command[1].split(',') text = " ".join(command[2:]) self.events[int(start_coords[1])*self.tiles_wide+int(start_coords[0])] = DialogEvent(text, self.game) elif command[0] == 'cutscene': slides = [] for image in [os.path.join("cutscenes",image).replace('\n','') for image in command[3:]]: if(self.loaded_cutscenes.has_key(image)): slides.append(self.loaded_cutscenes.get(image)) else: loaded_image = image_util.load_image(image) slides.append(loaded_image) self.loaded_cutscenes[image] = loaded_image cutscene = Cutscene(self.game, command[2], slides, self.press_enter) self.played_cutscenes[cutscene.name] = False if command[1] == "start": self.start_cutscenes.append(cutscene) else: coords = command[1].split(',') self.events[int(coords[1])*self.tiles_wide+int(coords[0])] = cutscene elif command[0] == 'koaladoor': coords = command[1].split(',') self.events[int(coords[1])*self.tiles_wide+int(coords[0])] = KoalaDoorEvent(int(coords[0]), int(coords[1]), self.game) elif command[0] == 'dingodoor': coords = command[1].split(',') self.events[int(coords[1])*self.tiles_wide+int(coords[0])] = DingoDoorEvent(int(coords[0]), int(coords[1]), self.game) elif command[0] == 'snakedoor': start_coords = command[1].split(',') end_map = command[2] end_coords = command[3].replace('\n','').split(',') self.events[int(start_coords[1])*self.tiles_wide+int(start_coords[0])] = SnakeLinkEvent(start_coords, end_coords, end_map, self.game) elif command[0] == 'pushbacklink': start_coords = command[1].split(',') end_map = command[2] end_coords = command[3].split(',') self.events[int(start_coords[1])*self.tiles_wide+int(start_coords[0])] = PushbackLinkEvent(start_coords, end_coords, end_map, self.game) elif command[0] == 'visitors\n': self.shouldCreateVisitors = True elif command[0] == 'zookeepers\n': self.shouldCreateZookeepers = True elif command[0] == 'animals\n': self.shouldCreateAnimals = True elif command[0] == 'gameover': start_coords = command[1].split(',') self.events[int(start_coords[1])*self.tiles_wide+int(start_coords[0])] = GameOverEvent(self.game) index += 1
def __init__(self, x, y, game): self.game = game self.door = DingoDoor(image_util.load_image("dingofence_lock.png"), x, y + 1, game)
def __init__(self, image, x, y, game): super(DingoDoor, self).__init__(image, (x*TILE_SIZE, y*TILE_SIZE), game) self.cutscene = Cutscene(self.game, "freed dingos", \ [image_util.load_image(os.path.join("cutscenes","dingo_free.png"))], \ image_util.load_sliced_sprites(210, 80, os.path.join("cutscenes","press_enter.png"))); self.game.current_map.game_objects.add(self)
def __init__(self, x, y, game): image = image_util.load_image("splat.png") super(Splat, self).__init__(image, (x,y), game)
def set_player(self, player): self.name = player.name (self.portrait, self.ability, self.canDrive, animal_image) = info[player.name] self.portrait = image_util.load_image(self.portrait) self.draw()
def __init__(self, x, y, game): image = image_util.load_image("splat.png") super(Splat, self).__init__(image, (x, y), game)
def __init__(self, x, y, game): self.game = game self.door = KoalaDoor(image_util.load_image("snake_door.png"), x, y - 1, game)
def __init__(self, image, x, y, game): image = image_util.load_image("zookeeper.png") super(Zookeeper, self).__init__(image, (x*tile_size,y*tile_size), game) self.speed = 1 self.game.current_map.num_zookeepers += 1 self.tracking_player = False
def load_image(self, path: str, target_shape=(256, 256, 1)): mode = iu.get_color_mode(target_shape[2]) image = iu.load_image(path, mode) resized = iu.resize_image(image, target_shape[1], target_shape[0]) resized = iu.normalize(resized, target_shape) return resized
def __init__(self, fruit="apple"): super().__init__() self.image = iu.load_image("{}/{}.png".format(IMAGES_FOLDER, fruit)) self.rect = self.image.get_rect() self.iterations = 0
def load_map(self, file): lines = file.readlines() # Load the tile map for idx in xrange(len(lines)): line = lines[idx] if line == " \n": self.tiles_high = idx self.height = self.tiles_high * self.tile_size for y in xrange(0, self.tiles_high): line = lines[y] parsed_comments = line.split('#') line_tiles = parsed_comments[0].replace(' ', '').replace('\n', '').split(',') self.tiles_wide = len(line_tiles) self.width = self.tiles_wide * self.tile_size self.num_tiles = self.tiles_wide * self.tiles_high x = 0 for key in line_tiles: tile = TileFactory.generateTile(key, x, y, self.game) self.tiles.append(tile) if not tile.walkable: self.unwalkable_tiles.add(tile) if not tile.visible: self.unjumpable_tiles.add(tile) if not tile.swimmable and not tile.walkable: self.unswimmable_and_unwalkable_tiles.add(tile) x += 1 index = self.tiles_high while lines[index] is "\n": index += 1 index += 1 # Load the sprite map for y in xrange(index, self.tiles_high + index): line = lines[y] parsed_comments = line.split('#') line_tiles = parsed_comments[0].replace(' ', '').replace('\n', '').split(',') x = 0 for key in line_tiles: if key is not None and key is not '': object = TileFactory.generateSprite( key, x, y - index, self.game) if not isinstance(object, Player): self.not_player.add(object) self.game_objects.add(object) x += 1 # special commands index = self.tiles_high + index while index < len(lines): if lines[index] is "\n": index += 1 continue command = lines[index].split(' ') if command[0] == 'link': start_coords = command[1].split(',') end_map = command[2] end_coords = command[3].replace('\n', '').split(',') self.events[int(start_coords[1]) * self.tiles_wide + int(start_coords[0])] = LinkEvent( start_coords, end_coords, end_map, self.game) elif command[0] == 'dialog': start_coords = command[1].split(',') text = " ".join(command[2:]) self.events[int(start_coords[1]) * self.tiles_wide + int(start_coords[0])] = DialogEvent( text, self.game) elif command[0] == 'cutscene': slides = [] for image in [ os.path.join("cutscenes", image).replace('\n', '') for image in command[3:] ]: if (self.loaded_cutscenes.has_key(image)): slides.append(self.loaded_cutscenes.get(image)) else: loaded_image = image_util.load_image(image) slides.append(loaded_image) self.loaded_cutscenes[image] = loaded_image cutscene = Cutscene(self.game, command[2], slides, self.press_enter) self.played_cutscenes[cutscene.name] = False if command[1] == "start": self.start_cutscenes.append(cutscene) else: coords = command[1].split(',') self.events[int(coords[1]) * self.tiles_wide + int(coords[0])] = cutscene elif command[0] == 'koaladoor': coords = command[1].split(',') self.events[int(coords[1]) * self.tiles_wide + int(coords[0])] = KoalaDoorEvent( int(coords[0]), int(coords[1]), self.game) elif command[0] == 'dingodoor': coords = command[1].split(',') self.events[int(coords[1]) * self.tiles_wide + int(coords[0])] = DingoDoorEvent( int(coords[0]), int(coords[1]), self.game) elif command[0] == 'snakedoor': start_coords = command[1].split(',') end_map = command[2] end_coords = command[3].replace('\n', '').split(',') self.events[int(start_coords[1]) * self.tiles_wide + int(start_coords[0])] = SnakeLinkEvent( start_coords, end_coords, end_map, self.game) elif command[0] == 'pushbacklink': start_coords = command[1].split(',') end_map = command[2] end_coords = command[3].split(',') self.events[int(start_coords[1]) * self.tiles_wide + int(start_coords[0])] = PushbackLinkEvent( start_coords, end_coords, end_map, self.game) elif command[0] == 'visitors\n': self.shouldCreateVisitors = True elif command[0] == 'zookeepers\n': self.shouldCreateZookeepers = True elif command[0] == 'animals\n': self.shouldCreateAnimals = True elif command[0] == 'gameover': start_coords = command[1].split(',') self.events[int(start_coords[1]) * self.tiles_wide + int(start_coords[0])] = GameOverEvent(self.game) index += 1