-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.py
34 lines (26 loc) · 1.16 KB
/
bullet.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
import pygame
from pygame.sprite import Sprite
class Bullet(Sprite):
"""Uma classe que administra projéteis disparados pela nave"""
def __init__(self, ai_settings, screen, ship):
"""Cria um objeto para o projétil na posição atual da nave."""
super(Bullet, self).__init__()
self.screen = screen
# Cria um retângulo para o projétil em (0,0) e em seguida, define a
# posição correta
self.rect = pygame.Rect(0,0, ai_settings.bullet_width, ai_settings.bullet_height)
self.rect.centerx = ship.rect.centerx
self.rect.top = ship.rect.top
# Armazena a posição do projétil como um valor decimal
self.y = float(self.rect.y)
self.color = ai_settings.bullet_color
self.speed_factor = ai_settings.bullet_speed_factor
def update(self):
"""Move o projétil para cima na tela."""
# Atualiza a posição decimal do projétil
self.y -= self.speed_factor
#Atualiza a posição de rect
self.rect.y = self.y
def draw_bullet(self):
"""Desenha o projétil na tela."""
pygame.draw.rect(self.screen, self.color, self.rect)