-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenemy.py
140 lines (121 loc) · 5.45 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import pygame
from random import *
miss = [0, 0, 0]
create = [2, 6, 15]
class SmallEnemy(pygame.sprite.Sprite):
energy = 1
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(r'images\enemy1.png').convert_alpha()
self.destroy_images = []
self.destroy_images.extend([pygame.image.load(r'images\enemy1_down1.png').convert_alpha(),
pygame.image.load(r'images\enemy1_down2.png').convert_alpha(),
pygame.image.load(r'images\enemy1_down3.png').convert_alpha(),
pygame.image.load(r'images\enemy1_down4.png').convert_alpha()
])
self.initpos1 = 5
self.initpos2 = 0
self.speed = 2
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.active = True
self.mask = pygame.mask.from_surface(self.image)
self.maxenergy = SmallEnemy.energy
self.energy = SmallEnemy.energy
self.hit = False
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-self.initpos1 * self.height, -self.initpos2 * self.height)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
miss[2] += 1
self.reset()
def reset(self):
create[2] += 1
self.active = True
self.energy = self.maxenergy
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-self.initpos1 * self.height, -self.initpos2 * self.height)
class MidEnemy(pygame.sprite.Sprite):
energy = 8
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(r'images\enemy2.png').convert_alpha()
self.image_hit = pygame.image.load(r'images\enemy2_hit.png').convert_alpha()
self.destroy_images = []
self.destroy_images.extend([pygame.image.load(r'images\enemy2_down1.png').convert_alpha(),
pygame.image.load(r'images\enemy2_down2.png').convert_alpha(),
pygame.image.load(r'images\enemy2_down3.png').convert_alpha(),
pygame.image.load(r'images\enemy2_down4.png').convert_alpha()
])
self.initpos1 = 10
self.initpos2 = 5
self.speed = 1
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.active = True
self.mask = pygame.mask.from_surface(self.image)
self.maxenergy = MidEnemy.energy
self.energy = MidEnemy.energy
self.hit = False
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-self.initpos1 * self.height, -self.initpos2 * self.height)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
miss[1] += 1
self.reset()
def reset(self):
create[1] += 1
self.active = True
self.energy = self.maxenergy
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-self.initpos1 * self.height, -self.initpos2 * self.height)
class BigEnemy(pygame.sprite.Sprite):
energy = 20
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image1 = pygame.image.load(r'images\enemy3_n1.png').convert_alpha()
self.image = self.image1
self.image2 = pygame.image.load(r'images\enemy3_n2.png').convert_alpha()
self.image_hit = pygame.image.load(r'images\enemy3_hit.png').convert_alpha()
self.destroy_images = []
self.destroy_images.extend([pygame.image.load(r'images\enemy3_down1.png').convert_alpha(),
pygame.image.load(r'images\enemy3_down2.png').convert_alpha(),
pygame.image.load(r'images\enemy3_down3.png').convert_alpha(),
pygame.image.load(r'images\enemy3_down4.png').convert_alpha(),
pygame.image.load(r'images\enemy3_down5.png').convert_alpha(),
pygame.image.load(r'images\enemy3_down6.png').convert_alpha()
])
self.initpos1 = 15
self.initpos2 = 5
self.speed = 1
self.rect = self.image1.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.active = True
self.mask = pygame.mask.from_surface(self.image1)
self.maxenergy = BigEnemy.energy
self.energy = BigEnemy.energy
self.hit = False
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-self.initpos1 * self.height, -self.initpos2 * self.height)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
miss[0] += 1
self.reset()
def reset(self):
create[0] += 1
self.active = True
self.energy = self.maxenergy
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-self.initpos1 * self.height, -self.initpos2 * self.height)