diff --git a/gameRole.py b/gameRole.py index 2d04a68..7a489be 100644 --- a/gameRole.py +++ b/gameRole.py @@ -39,10 +39,15 @@ def __init__(self, plane_img, player_rect, init_pos): self.bullets = pygame.sprite.Group() # 玩家飞机所发射的子弹的集合 self.img_index = 0 # 玩家精灵图片索引 self.is_hit = False # 玩家是否被击中 + self.is_gun_ready = True def shoot(self, bullet_img): bullet = Bullet(bullet_img, self.rect.midtop) self.bullets.add(bullet) + self.is_gun_ready = False + + def reload(self): + self.is_gun_ready = True def moveUp(self): if self.rect.top <= 0: diff --git a/mainGame.py b/mainGame.py index 91df38f..bbc6e74 100644 --- a/mainGame.py +++ b/mainGame.py @@ -81,9 +81,8 @@ # 控制发射子弹频率,并发射子弹 if not player.is_hit: - if shoot_frequency % 15 == 0: - bullet_sound.play() - player.shoot(bullet_img) + if shoot_frequency % 10 == 0: + player.reload() shoot_frequency += 1 if shoot_frequency >= 15: shoot_frequency = 0 @@ -179,6 +178,10 @@ player.moveLeft() if key_pressed[K_d] or key_pressed[K_RIGHT]: player.moveRight() + if key_pressed[K_SPACE] or key_pressed[K_SPACE]: + if player.is_gun_ready: + bullet_sound.play() + player.shoot(bullet_img) font = pygame.font.Font(None, 48)