55
66DESTRUIDO = 'Destruido'
77ATIVO = 'Ativo'
8+ GRAVIDADE = 10 # m/s^2
89
910
1011class Ator ():
@@ -14,35 +15,21 @@ class Ator():
1415 def __init__ (self , x = 0 , y = 0 ):
1516 self .y = y
1617 self .x = x
17- self ._tempo_de_colisao = None
18-
19- def caracter (self , tempo ):
20- return self ._caracter_ativo if self .status (tempo ) == ATIVO else self ._caracter_destruido
21-
22- def resetar (self ):
23- self ._tempo_de_colisao = None
24-
25- def status (self , tempo ):
26- if self ._tempo_de_colisao is None or self ._tempo_de_colisao > tempo :
27- return ATIVO
28- return DESTRUIDO
18+ self .caracter = self ._caracter_ativo
19+ self .status = ATIVO
2920
3021 def calcular_posicao (self , tempo ):
31- return self .arredondar_posicao ()
32-
33- def arredondar_posicao (self ):
34- self .x , self .y = round (self .x ), round (self .y )
3522 return self .x , self .y
3623
37- def colidir (self , outro_ator , tempo , intervalo = 1 ):
38- if self .status ( tempo ) == DESTRUIDO or outro_ator .status ( tempo ) == DESTRUIDO :
24+ def colidir (self , outro_ator , intervalo = 1 ):
25+ if self .status == DESTRUIDO or outro_ator .status == DESTRUIDO :
3926 return
40- x1 , y1 = self .arredondar_posicao ()
41- x2 , y2 = outro_ator .arredondar_posicao ()
4227
43- if x1 - intervalo <= x2 <= x1 + intervalo and y1 - intervalo <= y2 <= y1 + intervalo :
44- self ._tempo_de_colisao = tempo
45- outro_ator ._tempo_de_colisao = tempo
28+ if self .x - intervalo <= outro_ator .x <= self .x + intervalo and self .y - intervalo <= outro_ator .y <= self .y + intervalo :
29+ self .status = DESTRUIDO
30+ self .caracter = self ._caracter_destruido
31+ outro_ator .caracter = outro_ator ._caracter_destruido
32+ outro_ator .status = DESTRUIDO
4633
4734
4835class Obstaculo (Ator ):
@@ -54,9 +41,6 @@ class Porco(Ator):
5441 _caracter_destruido = '+'
5542
5643
57- GRAVIDADE = 10 # m/s^2
58-
59-
6044class Passaro (Ator ):
6145 velocidade_escalar = None
6246
@@ -67,18 +51,12 @@ def __init__(self, x=0, y=0):
6751 self ._tempo_de_lancamento = None
6852 self ._angulo_de_lancamento = None # radianos
6953
70- def resetar (self ):
71- super ().resetar ()
72- self ._tempo_de_lancamento = None
73- self ._angulo_de_lancamento = None
74-
75-
7654 def foi_lancado (self ):
7755 return self ._tempo_de_lancamento is not None
7856
79- def colidir_com_chao (self , tempo ):
57+ def colidir_com_chao (self ):
8058 if self .y <= 0 :
81- self ._tempo_de_colisao = tempo
59+ self .status = DESTRUIDO
8260
8361 def _calcular_posicao_horizontal (self , delta_t ):
8462 self .x = self ._x_inicial + self .velocidade_escalar * delta_t * math .cos (self ._angulo_de_lancamento )
@@ -94,14 +72,12 @@ def _calcular_posicao(self, tempo):
9472 self ._calcular_posicao_horizontal (delta_t )
9573
9674 def calcular_posicao (self , tempo ):
97- if self ._aguardando_lancamento (tempo ):
98- self .x = self ._x_inicial
99- self .y = self ._y_inicial
100- elif self ._ja_colidiu (tempo ):
101- self ._calcular_posicao (self ._tempo_de_colisao )
102- else :
75+ if self ._tempo_de_lancamento is None :
76+ return self ._x_inicial , self ._y_inicial
77+ if self .status == ATIVO :
10378 self ._calcular_posicao (tempo )
104- return self .arredondar_posicao ()
79+ return self .x , self .y
80+
10581
10682 def lancar (self , angulo , tempo ):
10783 self ._tempo_de_lancamento = tempo
0 commit comments