def __post_init__(self): """Randomize self.""" self.img = pygame.image.load(Images.get_path(r'flora.png')) if self.is_home: self.img = pygame.image.load(Images.get_path(r'home.png')) self.looks_like_home = True # Pick which color we are self.img_color = random.choice(range(0, 5)) color_file = Images.color_files[self.img_color] color_img = pygame.image.load(Images.get_path(color_file)) # Apply chosen color if not self.is_home: Images.color_image(self.img, color_img) # Size self.block_size = int(self.size_multiple * 32) self.img_scale = int(self.size / self.block_size) self.size_x = self.block_size * self.img_scale self.size_y = self.block_size * self.img_scale self.img = pygame.transform.scale(self.img, (int( self.size_x * self.img_cols), int(self.size_y * self.img_rows))) # Pick which variety we are. var_x = self.variety % self.img_cols var_y = self.variety % self.img_rows self.draw_area = pygame.Rect(var_x * self.block_size * self.img_scale, var_y * self.block_size * self.img_scale, self.block_size * self.img_scale, self.block_size * self.img_scale) self.logic() # Bootstrap our collision rect.
def add_players(self): """Create the players. Return an array of the players as objects with .draw methods. """ player1 = Player(color=Colors.YELLOW, start_x=self.max_x / 5 * 2, controls=[ControlSet()]) player1.images = PlayerImages(default=Images.get_path(r'seahorse.png'), size_x=self.player_size, size_y=self.player_size) player2 = Player(color=Colors.RED, start_x=self.max_x / 5 * 4, controls=[ ControlSet(up=pygame.K_j, down=pygame.K_k, left=pygame.K_h, right=pygame.K_l), ControlSet(up=pygame.K_w, down=pygame.K_s, left=pygame.K_a, right=pygame.K_d) ]) player2.images = PlayerImages(default=Images.get_path(r'squid.png'), size_x=self.player_size, size_y=self.player_size) player3 = Player(color=Colors.BLUE, start_x=self.max_x / 5, controls=[ ControlSet(up=pygame.K_3, down=pygame.K_2, left=pygame.K_1, right=pygame.K_4) ]) player3.images = PlayerImages(default=Images.get_path(r'flounder.png'), size_x=self.player_size, size_y=self.player_size) player4 = Player(color=Colors.PURPLE, start_x=self.max_x / 5 * 3, controls=[ ControlSet(up=pygame.K_7, down=pygame.K_6, left=pygame.K_5, right=pygame.K_8) ]) player4.images = PlayerImages( default=Images.get_path(r'cuttlefish.png'), size_x=self.player_size, size_y=self.player_size) self.players = [player1, player2, player3, player4] for player in self.players: player.pos_y = self.ground_y - player.size_y / 2 player.ground_y = self.ground_y player.max_x = self.max_x
def __post_init__(self): """Load some images.""" self.images = [] for color in Images.color_files: color_img = pygame.image.load(Images.get_path(color)) horse = pygame.image.load(self.default) Images.color_image(base_image=horse, color_image=color_img) red_horse = pygame.transform.scale(horse, (int(self.size_x), int(self.size_y))) self.images += [red_horse] pygame.display.set_icon(self.images[0])
def __post_init__(self): """Size self.""" self.img = pygame.image.load(Images.get_path(r'firework.png')) # Size self.block_size = int(self.size_multiple * 32) self.img_scale = int(self.size / self.block_size) self.size_x = self.block_size * self.img_scale self.size_y = self.block_size * self.img_scale self.img_color = True color = random.choice(Images.color_files) color_img = pygame.image.load(Images.get_path(color)) self.img = Images.color_image(base_image=self.img, color_image=color_img) self.img = pygame.transform.scale(self.img, (int(self.size_x * self.img_cols), int(self.size_y * self.img_rows)))