-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalien.py
More file actions
46 lines (39 loc) · 1.5 KB
/
Copy pathalien.py
File metadata and controls
46 lines (39 loc) · 1.5 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
46
import pygame
from pygame.sprite import Sprite
import random
class Alien(Sprite):
"""Класс, представляющий одного пришельца"""
def __init__(self, screen, settings, rocket):
super().__init__()
self.screen = screen
self.settings = settings
self.rocket = rocket
self.image = pygame.image.load('image/pixil-frame-1.png')
self.rect = self.image.get_rect()
self.x = float(self.rect.x)
self.y = float(self.rect.y)
self.spawn_alien()
def spawn_alien(self):
"""Появление пришельцев"""
self.one = random.randint(1000, 1800)
self.two = random.randint(0, 1800)
self.one1 = random.randint(500, 1000)
self.two1 = random.randint(0, 1800)
self.list = [self.one, self.two]
self.list1 = [self.one1, self.two1]
self.rect.x = random.choice(self.list)
self.rect.y = random.choice(self.list1)
self.x = float(self.rect.x)
self.y = float(self.rect.y)
def update(self):
"""Искусственный интеллект пришельца"""
if self.x < self.rocket.x:
self.x += float(self.settings.alien_speed)
else:
self.x -= float(self.settings.alien_speed)
if self.y < self.rocket.rect.y:
self.y += float(self.settings.alien_speed)
else:
self.y -= float(self.settings.alien_speed)
self.rect.x = self.x
self.rect.y = self.y