-
Notifications
You must be signed in to change notification settings - Fork 0
/
bullets.py
38 lines (24 loc) · 978 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
import pygame
from pygame.sprite import Sprite
class Bullet(Sprite):
#a class for the bullets
def __init__(self,setting,screen ,iron):
"""Create a bullet object at ships position"""
super().__init__()
self.screen=screen
#create a bullet rect at (0,0) and then set current position
self.rect=pygame.Rect(0,0,setting.bull_width,setting.bull_height)
self.rect.centerx=iron.rect.centerx
self.rect.top=iron.rect.top
#storimg the bullets position
self.y=float(self.rect.y)
self.color=setting.bull_color
self.speed=setting.bull_speed
def update(self):
#updating the bullets position
self.y-=self.speed
#update the rect position
self.rect.y=self.y
def draw_bull(self):
"""drawing the bullet"""
pygame.draw.rect(self.screen,self.color,self.rect)