MCPcopy Create free account
hub / github.com/geekcomputers/Python / __init__

Method __init__

Flappy Bird - created with tkinter/Bird.py:23–81  ·  view source on GitHub ↗
(
        self,
        background,
        gameover_function,
        *screen_geometry,
        fp="bird.png",
        event="<Up>",
        descend_speed=5,
    )

Source from the content-addressed store, hash-verified

21 climbsUp = 0.0911458333
22
23 def __init__(
24 self,
25 background,
26 gameover_function,
27 *screen_geometry,
28 fp="bird.png",
29 event="<Up>",
30 descend_speed=5,
31 ):
32 # Verifica se "background" é uma instância de Background e se o "gamerover_method" é chamável
33
34 if not isinstance(background, Background):
35 raise TypeError(
36 "The background argument must be an instance of Background."
37 )
38 if not callable(gameover_function):
39 raise TypeError("The gameover_method argument must be a callable object.")
40
41 # Instância os parâmetros
42 self.__canvas = background
43 self.image_path = fp
44 self.__descend_speed = descend_speed
45 self.gameover_method = gameover_function
46
47 # Recebe a largura e altura do background
48 self.__width = screen_geometry[0]
49 self.__height = screen_geometry[1]
50
51 # Define a decida e subida do pássaro com base na altura do background
52 self.decends *= self.__height
53 self.decends = int(self.decends + 0.5)
54 self.climbsUp *= self.__height
55 self.climbsUp = int(self.climbsUp + 0.5)
56
57 # Invoca o método construtor de Thread
58 Thread.__init__(self)
59
60 # Calcula o tamanho do pássaro com base na largura e altura da janela
61 self.width = (self.__width // 100) * 6
62 self.height = (self.__height // 100) * 11
63
64 # Carrega e cria a imagem do pássaro no background
65 self.__canvas.bird_image = self.getPhotoImage(
66 image_path=self.image_path,
67 width=self.width,
68 height=self.height,
69 closeAfter=True,
70 )[0]
71 self.__birdID = self.__canvas.create_image(
72 self.__width // 2,
73 self.__height // 2,
74 image=self.__canvas.bird_image,
75 tag=self.__tag,
76 )
77
78 # Define evento para fazer o pássaro subir
79 self.__canvas.focus_force()
80 self.__canvas.bind(event, self.jumps)

Callers

nothing calls this directly

Calls 1

getPhotoImageMethod · 0.95

Tested by

no test coverage detected