-
Notifications
You must be signed in to change notification settings - Fork 0
/
generators.py
53 lines (43 loc) · 1.48 KB
/
generators.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
import random
from SerpBonus import SerpBonus
from citizen import Citizen
from enemy import Enemy
from shooting_enemy import ShootingEnemy
class Generator:
def __init__(self, delay):
self.delay = delay
self.generate_after = delay
class SerpGenerator(Generator):
def __init__(self, delay):
super().__init__(delay)
def try_generate(self, game):
if self.generate_after == 0:
x = random.randrange(game.width)
y = random.randrange(game.height)
self.generate_after = self.delay
return SerpBonus(x, y, game)
self.generate_after -= 1
class CitizenGenerator(Generator):
def __init__(self, delay):
super().__init__(delay)
def try_generate(self, game):
if self.generate_after == 0:
x = random.randrange(game.width)
y = random.randrange(game.height)
self.generate_after = self.delay
return Citizen(x, y, game)
self.generate_after -= 1
class EnemiesGenerator(Generator):
def __init__(self, delay):
super().__init__(delay)
def try_generate(self, game):
if self.generate_after == 0:
x = random.randrange(game.width)
y = random.randrange(game.height)
self.generate_after = self.delay
r = random.randrange(0, 2)
if r == 0:
return Enemy(x, y, game)
else:
return ShootingEnemy(x, y, game)
self.generate_after -= 1