就飞机大战补给未进入循环(每三十秒投放一次)而提出的问题
#附上补给模块代码import pygame
from random import *
#超级子弹补给
class Bullet_Supply(pygame.sprite.Sprite):
def __init__(self,bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/bullet_supply.png").convert_alpha()
self.rect = self.image.get_rect()
self.width,self.height = bg_size, bg_size
self.rect.left,self.rect.bottom = randint(0,self.width - self.rect.width),-100
self.speed = 5
self.active = False
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self):
self.active = True
self.rect.left, self.rect.bottom = randint(0, self.width - self.rect.width),-100
class Bomb_Supply(pygame.sprite.Sprite):
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/bomb_supply.png").convert_alpha()
self.rect = self.image.get_rect()
self.width, self.height = bg_size, bg_size
self.rect.left,self.rect.bottom = randint(0,self.width - self.rect.width),100
self.speed = 5
self.active = False
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self):
self.rect.left,self.rect.bottom = randint(-36, self.width - self.rect.width), -100
self.active = True # 补给定时器
bomb_supply = supply.Bomb_Supply(bg_size)
bullet_supply = supply.Bullet_Supply(bg_size)
SUPPLY_TIME = USEREVENT
pygame.time.set_timer(SUPPLY_TIME, 30 * 1000)
#补给包响应
elif event.type == SUPPLY_TIME:
supply_sound.play()
if supply.choice():
bullet_supply.reset()
else:
bullet_supply.reset()
页:
[1]