-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.py
70 lines (54 loc) · 2.44 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pygame
import os
import sys
from random import *
# how to add subclass to a sprite group in pygame
class SmallEnemy(pygame.sprite.Sprite):
speed = 2
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("resource/images/enemy1.png").convert_alpha()
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.speed = 2
self.rect.left, self.rect.top = randint(0, self.width), randint(-5 * self.height, 0)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.rect.left, self.rect.top = randint(0, self.width), randint(-5 * self.height, 0)
class MidEnemy(pygame.sprite.Sprite):
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("resource/images/enemy2.png").convert_alpha()
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.speed = 1
self.rect.left, self.rect.top = randint(0, self.width), randint(-10 * self.height,
-self.height) # unless wait a screen before arrive
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.rect.left, self.rect.top = randint(0, self.width), randint(-5 * self.height, 0)
class BigEnemy(pygame.sprite.Sprite):
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image1 = pygame.image.load("resource/images/enemy3_n1.png.png").convert_alpha()
self.image2 = pygame.image.load("resource/images/enemy3_n2.png.png").convert_alpha()
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.speed = 1
self.rect.left, self.rect.top = randint(0, self.width), randint(-15 * self.height,
-5 * self.height) # unless wait lot of screens before arrive
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.rect.left, self.rect.top = randint(0, self.width), randint(-5 * self.height, 0)