def initializeAnimals(self, fx=5, rb=10, wl=10, br=10, ea=10): for z in range(rb): x = random.randint(0, self.size[0] - 1) y = random.randint(0, self.size[1] - 1) pos = (x, y) r = rabbit.Rabbit(pos, self) for a in range(fx): b = random.randint(0, self.size[0] - 1) c = random.randint(0, self.size[1] - 1) pos = (b, c) f = fox.Fox(pos, self) for m in range(fx): n = random.randint(0, self.size[0] - 1) o = random.randint(0, self.size[1] - 1) pos = (n, o) w = wolf.Wolf(pos, self) for m in range(br): n = random.randint(0, self.size[0] - 1) o = random.randint(0, self.size[1] - 1) pos = (n, o) b = bear.Bear(pos, self) for m in range(ea): n = random.randint(0, self.size[0] - 1) o = random.randint(0, self.size[1] - 1) pos = (n, o) ea = eagle.Eagle(pos, self)
def __init__(self, file_path): self.starting_blocks = [] self.starting_enemies = [] self.starting_coins = [] self.starting_powerups = [] self.starting_flag = [] self.starting_fires = [] self.blocks = pygame.sprite.Group() self.enemies = pygame.sprite.Group() self.coins = pygame.sprite.Group() self.powerups = pygame.sprite.Group() self.flag = pygame.sprite.Group() self.fires = pygame.sprite.Group() self.active_sprites = pygame.sprite.Group() self.inactive_sprites = pygame.sprite.Group() with open(file_path, 'r') as f: data = f.read() map_data = json.loads(data) self.width = map_data['width'] * game.GRID_SIZE self.height = map_data['height'] * game.GRID_SIZE self.start_x = map_data['start'][0] * game.GRID_SIZE self.start_y = map_data['start'][1] * game.GRID_SIZE for item in map_data['blocks']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE img = game.block_images[item[2]] self.starting_blocks.append(block.Block(x, y, img)) for item in map_data['fires']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_fires.append(fire.Fire(x, y, game.fire_img)) for item in map_data['bears']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_enemies.append(bear.Bear(x, y, game.bear_images)) for item in map_data['monsters']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_enemies.append( monster.Monster(x, y, game.monster_images)) for item in map_data['coins']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_coins.append(coin.Coin(x, y, game.coin_img)) for item in map_data['oneups']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_powerups.append(oneUp.OneUp(x, y, game.oneup_img)) for item in map_data['hearts']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_powerups.append(heart.Heart(x, y, game.heart_img)) for i, item in enumerate(map_data['flag']): x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE if i == 0: img = game.flag_img else: img = game.flagpole_img self.starting_flag.append(flag.Flag(x, y, img)) self.background_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.scenery_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.inactive_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.active_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) if map_data['background-color'] != "": self.background_layer.fill(map_data['background-color']) if map_data['background-img'] != "": background_img = pygame.image.load( map_data['background-img']).convert_alpha() if map_data['background-fill-y']: h = background_img.get_height() w = int(background_img.get_width() * game.HEIGHT / h) background_img = pygame.transform.scale( background_img, (w, game.HEIGHT)) if "top" in map_data['background-position']: start_y = 0 elif "bottom" in map_data['background-position']: start_y = self.height - background_img.get_height() if map_data['background-repeat-x']: for x in range(0, self.width, background_img.get_width()): self.background_layer.blit(background_img, [x, start_y]) else: self.background_layer.blit(background_img, [0, start_y]) if map_data['scenery-img'] != "": scenery_img = pygame.image.load( map_data['scenery-img']).convert_alpha() if map_data['scenery-fill-y']: h = scenery_img.get_height() w = int(scenery_img.get_width() * game.HEIGHT / h) scenery_img = pygame.transform.scale(scenery_img, (w, game.HEIGHT)) if "top" in map_data['scenery-position']: start_y = 0 elif "bottom" in map_data['scenery-position']: start_y = self.height - scenery_img.get_height() if map_data['scenery-repeat-x']: for x in range(0, self.width, scenery_img.get_width()): self.scenery_layer.blit(scenery_img, [x, start_y]) else: self.scenery_layer.blit(scenery_img, [0, start_y]) pygame.mixer.music.load(map_data['music']) self.gravity = map_data['gravity'] self.terminal_velocity = map_data['terminal-velocity'] self.completed = False self.blocks.add(self.starting_blocks) self.enemies.add(self.starting_enemies) self.coins.add(self.starting_coins) self.powerups.add(self.starting_powerups) self.flag.add(self.starting_flag) self.fires.add(self.starting_fires) self.active_sprites.add(self.coins, self.enemies, self.powerups, self.fires) self.inactive_sprites.add(self.blocks, self.flag) # with this speed up blitting on slower computers? for s in self.active_sprites: s.image.convert() for s in self.inactive_sprites: s.image.convert() self.inactive_sprites.draw(self.inactive_layer) # is converting layers helpful at all? self.background_layer.convert() self.scenery_layer.convert() self.inactive_layer.convert() self.active_layer.convert()
parser = argparse.ArgumentParser(description = 'Export Bear posts as Jekyll-compatible markdown') parser.add_argument('output', type = str, help = 'directory to output to') parser.add_argument('--tag', type = str, action='append', help='Tag to export, you can specify multiple times. If no tags are specified all posts will be exported') parser.add_argument('--html', action = "store_true", help = "render as html") args = parser.parse_args() full_path = os.path.join(os.getcwd(), args.output) # Check directory exists if not os.path.isdir(full_path): print("The given output directory {} does not exist".format(full_path)) sys.exit(1) # Open Bear database b = bear.Bear() # Check tags if args.tag: notes = [] for tag in args.tag: t = b.tag_by_title(tag) if not t: print("The given tag '{}' does not exist - note they're case sensitive".format(tag)) sys.exit(1) for note in t.notes(): notes.append(note) else: notes = b.notes() # Iterate through all notes
def main(): #random.seed(0) draw_api = draw.init() arctic = geometry.Arctic(HEXDEPTH) list_of_bears = [] player_bear = bear.Bear((0, 0), 0, BLUE, INVLIGHTBLUE, 'M') player_bear.put_trail(arctic) player_bear.destination = (0, 0) list_of_bears.append(player_bear) another_bear = bear.Bear((1, 0), 1, RED, INVLIGHTRED, 'F') another_bear.put_trail(arctic) list_of_bears.append(another_bear) yet_another_bear = bear.Bear((4, 4), -1, RED, INVLIGHTRED, 'F') yet_another_bear.put_trail(arctic) list_of_bears.append(yet_another_bear) #print(draw.get_hex_distance(player_bear.position,another_bear.position)) #print('{0:.2f}'.format(draw.get_hex_angle(player_bear.position,another_bear.position))+'°') fpsClock = pygame.time.Clock() redraw(draw_api, arctic, list_of_bears) set_purpose(arctic, list_of_bears) while True: for event in pygame.event.get(): if event.type == pg.QUIT: pygame.quit() sys.exit() if event.type == pg.KEYDOWN: if (event.key == pg.K_UP): co = -1 list_of_bears[0].destination = (0, 1) animate(draw_api, arctic, list_of_bears, fpsClock, co=co) arctic.move_forward() for b in list_of_bears: b.shift_forward() move_bears(arctic, list_of_bears) set_purpose(arctic, list_of_bears) redraw(draw_api, arctic, list_of_bears) if (event.key == pg.K_RIGHT): cr = 1 list_of_bears[0].turn_right() animate(draw_api, arctic, list_of_bears, fpsClock, cr=cr) arctic.turn_right() for b in list_of_bears: b.turn_left() b.rotate_right() move_bears(arctic, list_of_bears) set_purpose(arctic, list_of_bears) redraw(draw_api, arctic, list_of_bears) if (event.key == pg.K_LEFT): cr = -1 list_of_bears[0].turn_left() animate(draw_api, arctic, list_of_bears, fpsClock, cr=cr) arctic.turn_left() for b in list_of_bears: b.turn_right() b.rotate_left() move_bears(arctic, list_of_bears) set_purpose(arctic, list_of_bears) redraw(draw_api, arctic, list_of_bears) if (event.key == pg.K_DOWN): animate(draw_api, arctic, list_of_bears, fpsClock) arctic.remain() move_bears(arctic, list_of_bears) set_purpose(arctic, list_of_bears) redraw(draw_api, arctic, list_of_bears) if (event.key == pg.K_ESCAPE): print(sys.getsizeof(draw_api.get_h_lookup)) pygame.display.update()
def main(): parser = argparse.ArgumentParser( description='Export Bear posts as Jekyll-compatible markdown') parser.add_argument('output', type=str, help='directory to output to') parser.add_argument( '--tag', type=str, action='append', help= 'Tag to export, you can specify multiple times. If no tags are specified all posts will be exported' ) args = parser.parse_args() full_path = os.path.join(os.getcwd(), args.output) # Check directory exists if not os.path.isdir(full_path): print("The given output directory {} does not exist".format(full_path)) sys.exit(1) # Open Bear database b = bear.Bear() # Check tags if args.tag: notes = [] for tag in args.tag: t = b.tag_by_title(tag) if not t: print( "The given tag '{}' does not exist - note they're case sensitive" .format(tag)) sys.exit(1) for note in t.notes(): notes.append(note) else: notes = b.notes() css = get_css() # Iterate through all notes for note in notes: # Create a suitable filename filename = title_to_filename(full_path, note.title) + '.html' # Write out the post with open(filename, 'w', encoding='utf8') as f: content = markdown.markdown(note.text, extensions=[ ImageExtension(), 'markdown.extensions.nl2br', 'markdown.extensions.fenced_code' ]) html = """<html> <head> <title>{}</title> </head> <body> <div class="note-wrapper"> {} </div> <style>{}</style> </body> </html> """.format(note.title, content, css) f.write(html) # Images to copy for image in note.images(): if image.exists(): # Figure out target path for image target_path = os.path.join(full_path, image.uri) # Make dir os.makedirs(os.path.dirname(target_path), exist_ok=True) # Copy file shutil.copyfile(image.path, target_path)
def main(): parser = argparse.ArgumentParser( description='Export Bear posts as Jekyll-compatible markdown') parser.add_argument('output', type=str, help='directory to output to') parser.add_argument( '--tag', type=str, action='append', help= 'Tag to export, you can specify multiple times. If no tags are specified all posts will be exported' ) parser.add_argument('--html', action="store_true", help="render as html") args = parser.parse_args() full_path = os.path.join(os.getcwd(), args.output) # Check directory exists if not os.path.isdir(full_path): print("The given output directory {} does not exist".format(full_path)) sys.exit(1) # Open Bear database b = bear.Bear() # Check tags if args.tag: notes = [] for tag in args.tag: t = b.tag_by_title(tag) if not t: print( "The given tag '{}' does not exist - note they're case sensitive" .format(tag)) sys.exit(1) for note in t.notes(): notes.append(note) else: notes = b.notes() # Iterate through all notes for note in notes: # Create a suitable filename filename = title_to_filename(full_path, note.title) + '.md' # Write out the post with open(filename, 'w', encoding='utf8') as f: f.write("""--- title: {} date: {} tags: {} uuid: {} --- {}""".format(note.title, note.created.strftime('%Y-%m-%d %H:%M:%S +0000'), ' '.join([t.title for t in note.tags()]), note.id, note.text)) # Images to copy for image in note.images(): if image.exists(): # Figure out target path for image target_path = os.path.join(full_path, image.uri) # Make dir os.makedirs(os.path.dirname(target_path), exist_ok=True) # Copy file shutil.copyfile(image.path, target_path)