You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.6 KiB

6 months ago
# 文字
import pygame
from .. import constants as C
from . import coin
from .. import setup, tools
pygame.font.init()
class Info:
6 months ago
def __init__(self,state,game_info):
6 months ago
self.state = state
6 months ago
self.game_info = game_info
6 months ago
self.create_state_labels() # 创造某个阶段特有文字
self.create_info_labels() # 通用信息
self.flash_coin = coin.FlashingCoin()
def create_state_labels(self):
self.state_labels = []
if self.state == 'main_menu':
6 months ago
self.state_labels.append((self.create_label('1 PLAYER '),(272,360)))
self.state_labels.append((self.create_label('2 PLAYER'), (272, 405)))
6 months ago
self.state_labels.append((self.create_label('TOP - '), (290, 465)))
self.state_labels.append((self.create_label('00000'), (400, 465)))
elif self.state == 'load_screen':
self.state_labels.append((self.create_label('WORLD'), (280, 200)))
self.state_labels.append((self.create_label('1 - 1'), (430, 200)))
6 months ago
self.state_labels.append((self.create_label('X {}'.format(self.game_info['lives'])), (380, 280)))
6 months ago
self.player_image = tools.get_image(setup.GRAPHICS['mario_bros'],178,32,12,16,(0,0,0), C.BG_MULTI)
6 months ago
elif self.state == 'game.over':
self.state_labels.append((self.create_label('GAME OVER'), (280, 300)))
6 months ago
def create_info_labels(self):
self.info_labels = []
self.info_labels.append((self.create_label('MARIO'), (75, 30)))
self.info_labels.append((self.create_label('WORLD'), (450, 30)))
self.info_labels.append((self.create_label('TIME'), (625, 30)))
self.info_labels.append((self.create_label('00000'), (75, 55)))
self.info_labels.append((self.create_label('x00'), (300, 55)))
self.info_labels.append((self.create_label('1 - 1'), (480, 55)))
def create_label(self,label,size=40,width_scale=1.25,height_scale=1):
font = pygame.font.SysFont('FixedSys.ttf',size)
label_image = font.render(label,1,(255,255,255)) # 文字渲染图片
rect = label_image.get_rect()
label_image = pygame.transform.scale(label_image,(int(rect.width*width_scale),int(rect.height*height_scale)))
return label_image
def update(self):
self.flash_coin.update()
def draw(self,surface):
for label in self.state_labels:
surface.blit(label[0],label[1])
for label in self.info_labels:
surface.blit(label[0],label[1])
surface.blit(self.flash_coin.image, self.flash_coin.rect)
if self.state == 'load_screen':
surface.blit(self.player_image,(300,270))