Bonjour a toutes et a tous ,
Je sollicite votre aide , non pas pour la compréhension de l'héritage en lui meme , mais pour cette facon d'ecrire les parametres dans la classe que je n'avais jamais vu auparavant . Dabord le code :
spawn_floating_particle(pos)
1 2 3 4 5 6
| def spawn_floating_particle(pos):
loc = pos[0] + randint(-10, 10), pos[1] + randint(-10, 10)
color = "yellow"
direction = pygame.math.Vector2(0, 0)
speed = randint(50, 100) # 50 100
FloatingParticle(particle_group, loc, color, direction, speed) |
1 2 3 4 5 6 7 8
| class FloatingParticle(Particle):
def __init__(self,
groups: pygame.sprite.Group,
pos: list[int],
color: str,
direction: pygame.math.Vector2,
speed: int):
super().__init__(groups, pos, color, direction, speed) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Particle(pygame.sprite.Sprite):
def __init__(self,
groups: pygame.sprite.Group,
pos: list[int],
color: str,
direction: pygame.math.Vector2,
speed: int):
super().__init__(groups)
self.pos = pos
self.color = color
self.direction = direction
self.speed = speed
self.alpha = 255
self.fade_speed = 400 # 200
self.size = 4 #4
self.create_surf() |
Dans ma classe Particule par exemple , j'ai cette initialisation:
1 2 3 4 5 6
| def __init__(self,
groups: pygame.sprite.Group,
pos: list[int],
color: str,
direction: pygame.math.Vector2,
speed: int): |
Pourquoi a t il complété groups avec pygame.sprite.Group , pos avec list[int], color avec str , direction avec pygame.math.Vector2 , speed avec int . Es ce obligatoire ? Qu'est ce que ca apporte ?
Lorsqu'on donne une valeur par défaut , ne fait on pas :
def __init__(self, color = bleu, speed = 10, ...):
Pourquoi ici utilise t on les " : " ?
Merci
Partager