23.9 C
New York
Monday, April 28, 2025

Pygame: Rating rating within the Python recreation assigning factors to each gamers


I’m attempting to study to encode a easy recreation with 2 gamers taking pictures in horizontal enemies from the underside of the display screen.

Every thing works nicely besides this:

  • When participant 1 hits enemy sort A, participant 1 will get +1 rating.

  • When participant 1 hits enemy sort B, participant 1 will get a +3 rating.

  • The identical goes for participant 2.

  • When participant 1 or 2 hit the enemy B 3 occasions, I would love a picture and a sound to be reproduced for five seconds.

My code at the moment makes the sport every rating for each gamers, so every recreation is a draw!

And on no account can I reproduce the picture + sound when hitting the enemy sort B 3 occasions.

The following is a generalized code of what I’m working and I made a small translation of my mom tongue, so I hope it is sensible.

enemy hit = pygame.sprite.spritecollide(self, enemies, True)
    world score_player1, score_player2
    for p in enemy hit:
        pygame.mixer.Sound.play(enemyA_sound if not p.enemyB else enemyB_suono)
        pygame.mixer.Sound.play(hit_sound)
        if p.enemyB:
            score_player1 += 3
        else:
            score_player1 += 1
        if p.is_viola:
            score_player2 += 3
        else:
            score_player2 += 1
        self.kill()
def score_management(participant, is_enemyB):
world score_player1, score_player2, player1_enemyB_hit, player2_enemyB_hit

if participant == "player1":
    if is_enemyB:
        score_player1 += 3
        player1_enemyB_hit += 1
        if player1_enemyB_hit == 3:
            display screen.blit(prize_img, (width // 2 - prize_img.get_width() // 2, peak // 2 - prize_img.get_height() // 2))
            pygame.show.flip()
            pygame.mixer.Sound.play(prize_sound)
            pygame.time.delay(5000)

    else:
        score_player1 += 1
        score_player2 += 0

elif participant == "player2":
    if is_EnemyB:
        score_player2 += 3
        player2_enemyB_hit += 1
        if player2_enemyB_hit == 3:
            display screen.blit(prize_img, (width // 2 - prize_img.get_width() // 2, peak // 2 - prize_img.get_height() // 2))
            pygame.show.flip()
            pygame.mixer.Sound.play(prize_sound)
            pygame.time.delay(5000)
    else:
        score_player2 += 1
        score_player1 += 0

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles