-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.py
96 lines (81 loc) · 3.06 KB
/
score.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Invasores
# Escrito por: Nilo Menezes (nilo at nilo dot pro dot br)
# This file is part of Invasores.
#
# Invasores is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Invasores is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invasores; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# import pygame
import tradução
from objeto_do_jogo import ObjetoDoJogo
from video import Video
class Score(ObjetoDoJogo):
"""
Utilizada para exibir o score do jogo.
Implementada como um objeto normal, podendo inclusive suportar
animação.
"""
def __init__(self, nome, pos=[0, 0]):
super().__init__(nome, pos)
self.fonte = Video.cria_fonte(["calibri", "arial", "mono"], 30)
# self.fonte.set_bold(True)
self.jogador = None
def respire(self, dt: float):
self.imagem = self.fonte.render(
tradução.pega("score")
% (self.universo.score, self.jogador.resistência, self.jogador.misseis),
True,
(255, 255, 0, 0),
)
class Texto(ObjetoDoJogo):
"""
Utilizada para exibir o score do jogo.
Implementada como um objeto normal, podendo inclusive suportar
animação.
"""
def __init__(self, nome, pos, texto, tamanho, tempo, universo, cor):
super().__init__(nome, pos)
self.fonte = Video.cria_fonte(["calibri", "arial", "mono"], tamanho)
self.fonte.set_bold(True)
self.jogador = None
self.resistência = tempo
self.universo = universo
self.texto = texto
self.cor = cor
self.imagem = self.fonte.render(tradução.pega(self.texto), True, self.cor)
if self.pos == [-1, -1]:
self.pos = [
(self.universo.largura - self.imagem.get_width()) // 2,
(self.universo.altura - self.imagem.get_height()) // 2,
]
def respire(self, dt: float = 1.0):
"""Decrementa a resistência a cada frame.
Com objetivo de fazer o texto sumir após x frames"""
self.resistência -= dt
super().respire()
class ScoreComFPS(Score):
def __init__(self, nome, pos, universo):
super().__init__(nome, pos)
self.universo = universo
def respire(self, dt: float = 0.0):
self.imagem = self.fonte.render(
tradução.pega("scorefps")
% (
self.universo.score,
self.jogador.resistência,
self.jogador.misseis,
self.universo.clock.get_fps(),
),
True,
(255, 255, 0, 0),
)