GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pythonbirds/atores.py at master · samuelzinho/pythonbirds

Expand file tree

/

atores.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
127 lines (92 loc) · 3.56 KB
/

atores.py

Copy path

File metadata and controls

127 lines (92 loc) · 3.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import math
DESTRUIDO = 'Destruido'
ATIVO = 'Ativo'
class Ator():
_caracter_ativo = 'A'
_caracter_destruido = ' '
def caracter(self, tempo):
if self.status(tempo) == ATIVO:
return self._caracter_ativo
else:
return self._caracter_destruido
def __init__(self, x=0, y=0):
self.y = y
self.x = x
self._tempo_de_colisao = None
def resetar(self):
self._tempo_de_colisao = None
def status(self, tempo):
if self._tempo_de_colisao is None or self._tempo_de_colisao > tempo:
return ATIVO
return DESTRUIDO
def calcular_posicao(self, tempo):
return self.arredondar_posicao()
def arredondar_posicao(self):
self.x, self.y = round(self.x), round(self.y)
return self.x, self.y
def colidir(self, outro_ator, tempo, intervalo=1):
if self.status(tempo) == DESTRUIDO or outro_ator.status(tempo) == DESTRUIDO:
return
x1, y1 = self.arredondar_posicao()
x2, y2 = outro_ator.arredondar_posicao()
def esta_no_intervalo(coordenada1, coordenada2):
coordenadas = sorted([coordenada1, coordenada2])
return coordenadas[1] - intervalo <= coordenadas[0]
if esta_no_intervalo(x1, x2) and esta_no_intervalo(y1, y2):
self._tempo_de_colisao = tempo
outro_ator._tempo_de_colisao = tempo
class Obstaculo(Ator):
_caracter_ativo = 'O'
class Porco(Ator):
_caracter_ativo = '@'
_caracter_destruido = '+'
GRAVIDADE = 10 # m/s^2
class Passaro(Ator):
velocidade_escalar = None
def __init__(self, x=0, y=0):
super().__init__(x, y)
self._x_inicial = x
self._y_inicial = y
self._tempo_de_lancamento = None
self._angulo_de_lancamento = None # radianos
def resetar(self):
super().resetar()
self._tempo_de_lancamento = None
self._angulo_de_lancamento = None
def foi_lancado(self):
return self._tempo_de_lancamento is not None
def colidir_com_chao(self, tempo):
if self.y <= 0:
self._tempo_de_colisao = tempo
def _calcular_posicao_horizontal(self, delta_t):
self.x = self._x_inicial + self.velocidade_escalar * delta_t * math.cos(self._angulo_de_lancamento)
def _calcular_posicao_vertical(self, delta_t):
self.y = (self._y_inicial +
self.velocidade_escalar * delta_t * math.sin(self._angulo_de_lancamento) -
(GRAVIDADE / 2) * delta_t ** 2)
def _calcular_posicao(self, tempo):
delta_t = tempo - self._tempo_de_lancamento
self._calcular_posicao_vertical(delta_t)
self._calcular_posicao_horizontal(delta_t)
def calcular_posicao(self, tempo):
if self._tempo_de_lancamento is None or tempo < self._tempo_de_lancamento:
self.x = self._x_inicial
self.y = self._y_inicial
elif self._tempo_de_colisao is not None and tempo >= self._tempo_de_colisao:
self._calcular_posicao(self._tempo_de_colisao)
else:
self._calcular_posicao(tempo)
return self.arredondar_posicao()
def lancar(self, angulo, tempo):
self._tempo_de_lancamento = tempo
self._angulo_de_lancamento = math.radians(angulo)
class PassaroAmarelo(Passaro):
velocidade_escalar = 30 # m/s
_caracter_ativo = 'A'
_caracter_destruido = 'a'
class PassaroVermelho(Passaro):
velocidade_escalar = 20 # m/s
_caracter_ativo = 'V'
_caracter_destruido = 'v'
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.