-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaircraftspawnevent.py
96 lines (85 loc) · 3.43 KB
/
aircraftspawnevent.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
# File: aircraftspawnevent.py
from config import *;
import random;
class AircraftSpawnEvent:
def __init__(self, spawnpoint, destination):
self.spawnpoint = spawnpoint
self.destination = destination
def getSpawnPoint(self):
return self.spawnpoint
def getDestination(self):
return self.destination
def __str__(self):
return "<" + str(self.spawnpoint) + ", " + str(self.destination.getLocation()) + ">"
@staticmethod
def valid_destinations(destinations,test1,test2):
#d = filter(test1,destinations)
d = [item for item in destinations if test1(item)]
if (len(d) == 0):
return destinations
else:
return d
@staticmethod
def generateGameSpawnEvents(screen_w, screen_h, destinations, n_spawn_points):
randtime = [1]
randspawnevent = []
randspawnpoints = []
for i in range(n_spawn_points):
if i % 4 == 0:
randspawnpoints.append((random.randint(0, screen_w), 0))
elif i % 4 == 1:
randspawnpoints.append((screen_w, random.randint(0, screen_h)))
elif i % 4 == 2:
randspawnpoints.append((random.randint(0, screen_w), screen_h))
elif i % 4 == 3:
randspawnpoints.append((0, random.randint(0,screen_h)))
for x in range(1, Config.NUMBEROFAIRCRAFT):
randtime.append(random.randint(1, Config.GAMETIME))
randtime.sort()
for x in randtime:
# randspawn, side = AircraftSpawnEvent.__generateRandomSpawnPoint(screen_w, screen_h)
randspawn, side = AircraftSpawnEvent.__generateRandomSpawnPoint(screen_w, screen_h, randspawnpoints)
if (side == 1):
def t1(d):
l = d.getLocation()
return l[1] > screen_h/2
def t2(p1,p2):
return 1
elif (side == 2):
def t1(d):
l = d.getLocation()
return l[0] < screen_w/2
def t2(p1,p2):
return 1
elif (side == 3):
def t1(d):
l = d.getLocation()
return l[1] < screen_h/2
def t2(p1,p2):
return 1
elif (side == 4):
def t1(d):
l = d.getLocation()
return l[0] > screen_w/2
def t2(p1,p2):
return 1
d = AircraftSpawnEvent.valid_destinations(destinations,t1,t2)
randdest = random.choice(d)
randspawnevent.append(AircraftSpawnEvent(randspawn, randdest))
return (randtime, randspawnevent)
@staticmethod
def __generateRandomSpawnPoint(screen_w, screen_h, randspawnpoints):
# side = random.randint(1, 4)
# previous = 7
# if side == 1 and side != previous:
# loc = (random.randint(0, screen_w), 0)
# elif side == 2 and side != previous:
# loc = (screen_w, random.randint(0, screen_h))
# elif side == 3 and side != previous:
# loc = (random.randint(0, screen_w), screen_h)
# elif side == 4 and side != previous:
# loc = (0, random.randint(0, screen_h))
index = random.randint(0, len(randspawnpoints) -1)
loc = randspawnpoints[index]
side = index % 4 +1
return (loc), side