-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvader.py
More file actions
45 lines (37 loc) · 1.36 KB
/
invader.py
File metadata and controls
45 lines (37 loc) · 1.36 KB
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
43
44
45
import pygame
from shooter_bullet import Shooter_bullet
import random
class Invader(pygame.sprite.Sprite):
def __init__(self, screen, number = 1, shooter_bullets = None):
super(Invader, self).__init__()
self.screen = screen
self.shooter_bullets = shooter_bullets
invader_path = f"icons/saucer{number}b.ico"
self.image = pygame.image.load(invader_path)
self.rect = self.image.get_rect()
self.rect.x = self.rect.width
self.rect.y = self.rect.height
self.x = float(self.rect.x)
self.y = float(self.rect.y)
self.count_move = 150
self.move_x = 0.4
self.number = number
self.is_shooter = (number == 3)
def print(self):
self.screen.blit(self.image, self.rect)
def update(self, shift=50):
rnd = random.randint
if self.count_move < 400:
self.count_move += 1
self.x += self.move_x
else:
self.count_move = 0
self.y += 4
self.move_x = -self.move_x
if self.is_shooter and rnd(0, 500) == 0:
shooter_bullet = Shooter_bullet(self.screen, self)
self.shooter_bullets.add(shooter_bullet)
if self.is_shooter:
shift.shift = self.y
self.rect.x = self.x
self.rect.y = self.y