-
Notifications
You must be signed in to change notification settings - Fork 0
/
bullets.py
39 lines (26 loc) · 998 Bytes
/
bullets.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
35
36
37
38
39
import pygame
from pygame.sprite import Sprite
class Bullets(Sprite):
'''a class thats manage bullets fired by ship'''
def __init__(self, aa_settings, screen,ship):
'''this creates the bullet object'''
super(Bullets, self).__init__()
self.screen = screen
#create a bullet at initial position (0,0)
self.rect = pygame.Rect(0,0,aa_settings.bullet_width,
aa_settings.bullet_height)
self.rect.centerx = ship.rect.centerx
self.rect.top = ship.rect.top
#store the bullets position as a decimal value:
self.y = float(self.rect.y)
self.speed_factor = aa_settings.bullets_speed_factor
self.color = aa_settings.bullet_color
def update(self):
'''moves and update the bullet'''
#position the bullet
self.y -= self.speed_factor
#updatethe rect position:
self.rect.y = self.y
def draw_bullet(self):
'''draws the bullet to screen'''
pygame.draw.rect(self.screen, self.color,self.rect)