Repository navigation
Expand file tree
/
Copy pathenemy.py
More file actions
executable file
·125 lines (107 loc) · 4.51 KB
/
Copy pathenemy.py
File metadata and controls
executable file
·125 lines (107 loc) · 4.51 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
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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pygame
from random import *
class SmallEnemy(pygame.sprite.Sprite):
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/1.0.png").convert_alpha()
self.destroy_images = []
self.destroy_images.extend([
pygame.image.load("images/1.png").convert_alpha(),
pygame.image.load("images/2.png").convert_alpha(),
pygame.image.load("images/3.png").convert_alpha(),
pygame.image.load("images/4.png").convert_alpha()
])
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.speed = 2
self.active = True
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-5 * self.height, 0)
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.active = True
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-5 * self.height, 0)
class MidEnemy(pygame.sprite.Sprite):
energy = 8
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/2-1.png").convert_alpha()
self.image_hit = pygame.image.load(
"images/2-2.png").convert_alpha()
self.destroy_images = []
self.destroy_images.extend([
pygame.image.load("images/2-2.png").convert_alpha(),
pygame.image.load("images/2-3.png").convert_alpha(),
pygame.image.load("images/2-4.png").convert_alpha(),
pygame.image.load("images/2-5.png").convert_alpha(),
pygame.image.load("images/2-6.png").convert_alpha(),
pygame.image.load("images/2-7.png").convert_alpha()
])
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.speed = 2
self.active = True
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-10 * self.height, -self.height)
self.mask = pygame.mask.from_surface(self.image)
self.energy = MidEnemy.energy
self.hit = False
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.active = True
self.energy = MidEnemy.energy
self.rect.left, self.rect.top = randint(0, self.width - self.rect.width),\
randint(-10 * self.height, -self.height)
class BigEnemy(pygame.sprite.Sprite):
energy = 20
def __init__(self, bg_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/3-0.png").convert_alpha()
self.image1 = pygame.image.load("images/3-0.png").convert_alpha()
self.image_hit = pygame.image.load(
"images/3-1.png").convert_alpha()
self.destroy_images = []
self.destroy_images.extend([
pygame.image.load("images/3-1.png").convert_alpha(),
pygame.image.load("images/3-2.png").convert_alpha(),
pygame.image.load("images/3-3.png").convert_alpha(),
pygame.image.load("images/3-4.png").convert_alpha(),
pygame.image.load("images/3-5.png").convert_alpha(),
pygame.image.load("images/3-6.png").convert_alpha()
])
self.rect = self.image1.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.speed = 2
self.active = True
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-15 * self.height, -5 * self.height)
self.mask = pygame.mask.from_surface(self.image1)
self.energy = BigEnemy.energy
self.hit = False
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.active = True
self.energy = BigEnemy.energy
self.rect.left, self.rect.top = \
randint(0, self.width - self.rect.width), \
randint(-15 * self.height, -5 * self.height)