So i'm trying to build a "horse race" game and i want to randomly pick out 5 players from a list of 10 players and 5 of them all have different randomly picked y coordinates from a list. I tried my code but the y's sometimes are the same. I'm kinda stuck and i really appreciate if you guys can help me.
class Player1(pygame.sprite.Sprite): #Player1 class ( 2-10 are the same)
def __init__(self, pos_x, pos_y):
super().__init__()
self.sprites = []
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/1.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/2.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/3.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/4.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/5.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/6.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/7.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/8.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/9.png").convert_alpha(), (80, 60)))
self.sprites.append(pygame.transform.scale(pygame.image.load("image/pig/non/10.png").convert_alpha(), (80, 60)))
self.current_sprite = 0
self.image = self.sprites[self.current_sprite]
self.rect = self.image.get_rect(center = (pos_x, pos_y))
def update(self):
self.current_sprite += 0.1
if self.current_sprite >= len(self.sprites):
self.current_sprite = 0
self.image = self.sprites[int(self.current_sprite)]
random_y = [sf_height-200, sf_height - 290,sf_height-345,sf_height - 420,sf_height - 470]
player1 = Player1(player_x,random.choice(random_y))
player2 = Player2(player_x,random.choice(random_y))
player3 = Player3(player_x,random.choice(random_y))
player4 = Player4(player_x,random.choice(random_y))
player5 = Player5(player_x,random.choice(random_y))
player6 = Player6(player_x,random.choice(random_y))
player7 = Player7(player_x,random.choice(random_y))
player8 = Player8(player_x,random.choice(random_y))
player9 = Player9(player_x,random.choice(random_y))
player10 = Player10(player_x,random.choice(random_y))
player_list = [player1, player2, player3, player4, player5, player6, player7, player8, player9, player10]
player_group = pygame.sprite.Group()
player_group.add(random.sample(player_list, 5))
Aucun commentaire:
Enregistrer un commentaire