-
Notifications
You must be signed in to change notification settings - Fork 0
/
bullets.py
42 lines (33 loc) · 1.06 KB
/
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
40
41
42
#! /usr/bin/python3
import pygame
from colors import Colors
class InvaderBullet(pygame.sprite.Sprite):
def __init__(self, pos, screen_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([4, 15])
self.image.fill(Colors.WHITE)
self.rect = self.image.get_rect()
self.screen_h = screen_size[1]
self.rect.x = pos[0]
self.rect.y = pos[1]
self.speed = 9
def update(self):
if self.rect.y < self.screen_h:
self.rect.y += self.speed
else:
self.kill()
class PlayerBullet(pygame.sprite.Sprite):
def __init__(self, pos, screen_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([4, 15])
self.image.fill(Colors.GREEN)
self.rect = self.image.get_rect()
self.screen_h = screen_size
self.rect.x = pos[0]
self.rect.y = pos[1]
self.speed = 9
def update(self):
if self.rect.y > 0:
self.rect.y -= self.speed
else:
self.kill()