| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3bc8f84 commit df7abf8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | DESTRUIDO = 'Destruido' | |
| 7 | 7 | ATIVO = 'Ativo' | |
| 8 | + GRAVIDADE = 10 # m/s^2 | ||
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | 11 | class Ator(): | |
@@ -14,35 +15,21 @@ class Ator(): | |||
| 14 | 15 | def __init__(self, x=0, y=0): | |
| 15 | 16 | self.y = y | |
| 16 | 17 | 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 | ||
| 29 | 20 | ||
| 30 | 21 | 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) | ||
| 35 | 22 | return self.x, self.y | |
| 36 | 23 | ||
| 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: | ||
| 39 | 26 | return | |
| 40 | - x1, y1 = self.arredondar_posicao() | ||
| 41 | - x2, y2 = outro_ator.arredondar_posicao() | ||
| 42 | 27 | ||
| 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 | ||
| 46 | 33 | ||
| 47 | 34 | ||
| 48 | 35 | class Obstaculo(Ator): | |
@@ -54,9 +41,6 @@ class Porco(Ator): | |||
| 54 | 41 | _caracter_destruido = '+' | |
| 55 | 42 | ||
| 56 | 43 | ||
| 57 | - GRAVIDADE = 10 # m/s^2 | ||
| 58 | - | ||
| 59 | - | ||
| 60 | 44 | class Passaro(Ator): | |
| 61 | 45 | velocidade_escalar = None | |
| 62 | 46 | ||
@@ -67,18 +51,12 @@ def __init__(self, x=0, y=0): | |||
| 67 | 51 | self._tempo_de_lancamento = None | |
| 68 | 52 | self._angulo_de_lancamento = None # radianos | |
| 69 | 53 | ||
| 70 | - def resetar(self): | ||
| 71 | - super().resetar() | ||
| 72 | - self._tempo_de_lancamento = None | ||
| 73 | - self._angulo_de_lancamento = None | ||
| 74 | - | ||
| 75 | - | ||
| 76 | 54 | def foi_lancado(self): | |
| 77 | 55 | return self._tempo_de_lancamento is not None | |
| 78 | 56 | ||
| 79 | - def colidir_com_chao(self, tempo): | ||
| 57 | + def colidir_com_chao(self): | ||
| 80 | 58 | if self.y <= 0: | |
| 81 | - self._tempo_de_colisao = tempo | ||
| 59 | + self.status = DESTRUIDO | ||
| 82 | 60 | ||
| 83 | 61 | def _calcular_posicao_horizontal(self, delta_t): | |
| 84 | 62 | 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): | |||
| 94 | 72 | self._calcular_posicao_horizontal(delta_t) | |
| 95 | 73 | ||
| 96 | 74 | 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: | ||
| 103 | 78 | self._calcular_posicao(tempo) | |
| 104 | - return self.arredondar_posicao() | ||
| 79 | + return self.x, self.y | ||
| 80 | + | ||
| 105 | 81 | ||
| 106 | 82 | def lancar(self, angulo, tempo): | |
| 107 | 83 | self._tempo_de_lancamento = tempo | |
| Back | FazBrowse Home | New Git URL |
0 commit comments