-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullets.py
25 lines (24 loc) · 1000 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
import pygame
from pygame.sprite import Sprite
class Bullet(Sprite):
"""class handle bullets"""
def __init__(self,av_settings,screen,ship):
"""creat a bullet object at the top of the ship"""
super(Bullet,self).__init__()
self.screen=screen
#creat a bullet at (0,0)
# set it to the new postion#
self.rect=pygame.Rect(0,0,av_settings.bullet_widith,av_settings.bullet_height)
self.rect.centerx=ship.rect.centerx
self.rect.top=ship.rect.top
# storing bullet postion at decimal value
self.y=float(self.rect.y)
self.colour=av_settings.bullet_colour
self.speed_factor=av_settings.bullet_speed_factor
def update(self):
"""update the bullet position"""
self.y-=self.speed_factor
self.rect.y=self.y
def draw_bullet(self):
# but this related to pygame class rect which i wish to understand some day ?
pygame.draw.rect(self.screen,self.colour,self.rect)