-
Notifications
You must be signed in to change notification settings - Fork 0
/
formation.py
64 lines (55 loc) · 2.08 KB
/
formation.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
class Formation(object):
def __init__(self, general):
self.general = general
def place_minions(self): pass
def mirror(self, x, y):
return (self.general.bg.width - x - 1, self.general.bg.height - y - 1) if self.general.side else (x, y)
class FlyingWedge(Formation):
def __init__(self, general, increment=1):
super(FlyingWedge, self).__init__(general)
self.increment = increment
def place_minions(self):
n = self.general.minions_alive
for i in range(14, 3, -1):
offset_y = 0
for x in range(i, 3, -1):
for j in range(0, self.increment + 1):
if n <= 0: return
minion_placed = self.general.minion.clone(*self.mirror(x, self.general.y + offset_y))
if minion_placed is not None:
self.general.bg.minions.append(minion_placed)
n -= 1
offset_y = abs(offset_y)+1 if j%2 else -offset_y
class InvertedWedge(Formation):
def __init__(self, general, increment=1):
super(InvertedWedge, self).__init__(general)
self.increment = increment
def place_minions(self):
n = self.general.minions_alive
for i in range(4, 15):
offset_y = 0
for x in range(i, 15):
for j in range(0, self.increment + 1):
if n <= 0: return
minion_placed = self.general.minion.clone(*self.mirror(x, self.general.y + offset_y))
if minion_placed is not None:
self.general.bg.minions.append(minion_placed)
n -= 1
offset_y = abs(offset_y)+1 if j%2 else -offset_y
class Rows(Formation):
def __init__(self, general, rows=21):
super(Rows, self).__init__(general)
self.rows = rows
def place_minions(self):
n = self.general.minions_alive
for x in range(5, 15):
offset_y = 0
r = self.rows
while r > 0:
if n <= 0: return
minion_placed = self.general.minion.clone(*self.mirror(x, self.general.y + offset_y))
if minion_placed is not None:
self.general.bg.minions.append(minion_placed)
n -= 1
offset_y = abs(offset_y)+1 if r%2 or not self.rows%2 else -offset_y
r -= 1