在此代码中,问题出在Check_Health(). 每当我运行游戏时,它都会将生命值减少到极低的数字,这是不希望的。我只希望每个气球在离开屏幕时都能减少我的生命。具体来说,在第一波生命应该减少到95,但是当程序运行时,它减少到-405。有人知道为什么吗?
import pygame
import sys
import os
import random
import time
pygame.init()
WIDTH, HEIGHT = 800,600
win = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()
bg_music = []
#for r,d,f in os.walk("Music"):
#bg_music.append(f)
i = 0
Lives = 100
balloon_sprite = pygame.image.load("Logo.png")
rounds = [[5,50], [6,40], [8,40], [15,30], [15,20]]
FPS = 60
a3 = True
a1 = a2= False
bloons = []
'''def music_play():
global i
if not(pygame.mixer.music.get_busy()):
pygame.mixer.music.load('Music/'+bg_music[0][i])
pygame.mixer.music.play()
i = random.randint(0,len(bg_music)-1)'''
class Button:
def __init__(self, x_center, y_center, text, size, text_col, bg_col):
self.x = x_center
self.y = y_center
self.size = size
self.text_col = text_col
self.bg_col = bg_col
self.hit = False
font = pygame.font.Font('freesansbold.ttf', self.size)
self.text = font.render(text, True, self.text_col, self.bg_col)
self.textRect = self.text.get_rect()
self.textRect.center = (self.x, self.y)
win.blit(self.text, self.textRect)
def Check_Collision(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
pos_mouse = event.pos
if self.textRect.collidepoint(pos_mouse):
self.hit = True
def Start(self):
global run1
if (self.hit):
run1 = False
def Quit(self):
if (self.hit):
sys.exit()
def fast_forward(self):
global a1,a2,a3, FPS
if(self.hit):
不负相思意
相关分类