parent
a93a084095
commit
d1020a4468
@ -0,0 +1,50 @@
|
||||
import pygame
|
||||
import pygame.freetype
|
||||
|
||||
|
||||
class Stats: # 统计
|
||||
def __init__(self, ai_game):
|
||||
# 获取屏幕设置
|
||||
self.screen = ai_game.screen
|
||||
self.screen_rect = ai_game.screen.get_rect()
|
||||
self.settings = ai_game.settings
|
||||
|
||||
# 分数
|
||||
self.score = 0
|
||||
self.font = pygame.font.Font("resource/Bonus/kenvector_future.ttf", 30)
|
||||
self.score_font = None
|
||||
self.score_font_rect = None
|
||||
|
||||
# 飞船的护盾值
|
||||
self.ship = ai_game.ship
|
||||
|
||||
# 飞船的生命条数
|
||||
# self.ship_lives = pygame.image.load("")
|
||||
# boss的生命值
|
||||
self.boss = ai_game.boss
|
||||
|
||||
def update(self):
|
||||
self.show_score()
|
||||
self.show_ship_hp()
|
||||
self.show_boss_hp()
|
||||
|
||||
def show_score(self):
|
||||
self.score_font = self.font.render("score:" + str(self.score), True, self.settings.WHITE) # 渲染成图片
|
||||
self.score_font_rect = self.score_font.get_rect()
|
||||
self.score_font_rect.centerx = self.settings.screen_width / 2
|
||||
self.score_font_rect.centery = 20
|
||||
self.screen.blit(self.score_font, self.score_font_rect)
|
||||
|
||||
def show_ship_hp(self):
|
||||
pygame.draw.rect(self.screen, self.settings.WHITE, (10, 10, self.ship.hp, 15))
|
||||
pygame.draw.rect(self.screen, self.settings.YELLOW, (10, 10, 100, 15), 2)
|
||||
|
||||
def show_boss_hp(self):
|
||||
rect1 = pygame.Rect(0, 0, self.boss.hp, 15)
|
||||
rect2 = pygame.Rect(0, 0, 200, 15)
|
||||
rect2.midbottom = self.boss.rect.midtop
|
||||
rect1.midbottom = rect2.midbottom
|
||||
rect1.left = rect2.left
|
||||
if self.boss.hp >= 0:
|
||||
pygame.draw.rect(self.screen, self.settings.RED, rect1)
|
||||
pygame.draw.rect(self.screen, self.settings.YELLOW, rect2, 2)
|
Loading…
Reference in new issue