-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobs.py
86 lines (61 loc) · 1.71 KB
/
mobs.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
from entity import Entity
from sprites import ship, ship_destroy
from sprites import alien1, alien1_destroy
from sprites import alien2
from sprites import block
import random
from copy import deepcopy
class Alien2(Entity):
def __init__(self, line=0, *args, **kwargs):
self.sprites = deepcopy(alien2)
self.sprites_destroy = deepcopy(alien1_destroy)
Entity.__init__(self, *args, **kwargs)
self.line = line
self.speed = 1
self.life = 2
self.point = 20
def tick(self):
if not random.randint(0, 150):
self.fire(0)
return Entity.tick(self)
class Alien1(Entity):
def __init__(self, line=0, *args, **kwargs):
self.sprites = deepcopy(alien1)
self.sprites_destroy = deepcopy(alien1_destroy)
Entity.__init__(self, *args, **kwargs)
self.line = line
self.speed = 1
self.point = 10
class Ship(Entity):
def __init__(self, *args, **kwargs):
self.sprites = deepcopy(ship)
self.sprites_destroy = deepcopy(ship_destroy)
Entity.__init__(self, *args, **kwargs)
# center
self.y = (self.display.height - 1) - self.height
self.x = int((self.display.width/2) - (self.width/2))
self.speed = 5
self.life = 3
class Block(Entity):
def __init__(self, *args, **kwargs):
self.sprites = deepcopy(block)
self.sprites_destroy = None
Entity.__init__(self, *args, **kwargs)
self.speed = 0
self.life = 5
self.center = (
len(self.sprites[0][0]) / 2,
len(self.sprites[0]) / 2
)
self.print_life()
def print_life(self):
x = self.center[0]
y = self.center[1]
line = self.sprites[0][y]
line = list(line)
line[x] = str(self.life)
self.sprites[0][y] = "".join(line)
def tick(self):
if not self.destroyed and not self.onDestroy:
self.print_life()
return Entity.tick(self)