-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.py
28 lines (25 loc) · 885 Bytes
/
enemy.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
import pygame
from pygame.locals import RLEACCEL
import random
# Define the enemy
class Enemy(pygame.sprite.Sprite):
def __init__(self, width, height):
super(Enemy, self).__init__()
self.width = width
self.height = height
self.sprites = ["images/meteor.png", "images/flaming_meteor.png"]
self.surface = pygame.image.load(
self.sprites[random.randint(0, 1)]).convert()
self.surface.set_colorkey((0, 0, 0), RLEACCEL)
self.rect = self.surface.get_rect(
center=(
random.randint(0, self.width),
# Spawn the enemy off-screen
random.randint(-100, -50))
)
self.speed = random.randint(5, 10)
self._layer = 2
def update(self):
self.rect.move_ip(0, self.speed)
if self.rect.top > self.height:
self.kill()