进度
- 调整数值,使游戏流畅
只能是让子弹飞得更快、僵尸生成更慢,避免大量精灵滞留在屏幕上,至于深层的循环判断检测代码是否能简化不是很清楚,毕竟我算法实在没有天赋。。 - 制作种子银行
class SeedBank:
pos = (50, 0)
money = 100000
def __init__(self):
self.image_surf = pygame.image.load('assets/SeedBank.png').convert_alpha()
self.Cards = []
self.import_assets()
def import_assets(self):
for image in os.listdir('assets/SeedBank_Cards'):
full_path = 'assets/SeedBank_Cards/' + image
image_surf = pygame.image.load(full_path).convert_alpha()
self.Cards.append(image_surf)
def show_sun(self, screen):
(x, y) = self.pos
text_money = DrawText('{}'.format(self.money), 15, 'black')
text_halfw = text_money.get_width() / 2
screen.blit(text_money, (x+(45-text_halfw), y+75))
def show_card(self, screen):
screen.blit(self.image_surf, self.pos)
(x, y) = self.pos
for i in range(len(self.Cards)):
screen.blit(self.Cards[i], (x+95+i*50, y+15))
def update(self, screen):
self.show_card(screen)
self.show_sun(screen)
- 实现太阳花生产阳光逻辑
def produce(self, seedbank):
if self.t == self.produce_interval:
seedbank.money += 25
self.t -= 1
if self.t < 0:
self.t = self.produce_interval
- 实现僵尸到达最左端游戏失败
class GameManager:
def __init__(self):
self.gameover_surf = pygame.image.load('assets/gameover.png')
def gameover(self, screen):
screen.blit(self.gameover_surf, (50, 50))
for i in range(5):
if not self.all_ZBQs[i].isEmpty() and \
self.all_ZBQs[i].head().pos.x < Benchmark[0]:
return True