|
@@ -20,12 +20,12 @@ Engulf is simulation containing:
|
20
|
20
|
"""
|
21
|
21
|
from random import randint
|
22
|
22
|
|
23
|
|
-from sandbox.engulf.subject import Cell
|
|
23
|
+from sandbox.engulf.subject import Cell, Grass
|
24
|
24
|
from synergine2.core import Core
|
25
|
25
|
from synergine2.cycle import CycleManager
|
26
|
26
|
from synergine2.terminals import TerminalManager, Terminal, TerminalPackage
|
27
|
27
|
from synergine2.xyz import Simulation
|
28
|
|
-from synergine2.xyz import XYZSubjects
|
|
28
|
+from sandbox.engulf.simulation import EngulfSubjects
|
29
|
29
|
|
30
|
30
|
|
31
|
31
|
class Engulf(Simulation):
|
|
@@ -50,40 +50,69 @@ class GameTerminal(Terminal):
|
50
|
50
|
self.gui.run()
|
51
|
51
|
|
52
|
52
|
|
53
|
|
-def get_random_subjects(
|
54
|
|
- simulation: Simulation,
|
55
|
|
- count: int,
|
56
|
|
- x_min: int,
|
57
|
|
- y_min: int,
|
58
|
|
- x_max: int,
|
59
|
|
- y_max: int,
|
60
|
|
-) -> [Cell]:
|
61
|
|
- cells = XYZSubjects(simulation=simulation)
|
|
53
|
+def fill_with_random_cells(
|
|
54
|
+ subjects: EngulfSubjects,
|
|
55
|
+ count: int,
|
|
56
|
+ start_position: tuple,
|
|
57
|
+ end_position: tuple,
|
|
58
|
+) -> None:
|
|
59
|
+ cells = []
|
62
|
60
|
|
63
|
61
|
while len(cells) < count:
|
64
|
62
|
position = (
|
65
|
|
- randint(x_min, x_max+1),
|
66
|
|
- randint(y_min, y_max+1),
|
67
|
|
- 0
|
|
63
|
+ randint(start_position[0], end_position[0]+1),
|
|
64
|
+ randint(start_position[1], end_position[1]+1),
|
|
65
|
+ randint(start_position[2], end_position[2]+1),
|
68
|
66
|
)
|
69
|
|
- if position not in cells.xyz:
|
70
|
|
- cells.append(Cell(
|
71
|
|
- simulation=simulation,
|
|
67
|
+ if position not in subjects.cell_xyz:
|
|
68
|
+ cell = Cell(
|
|
69
|
+ simulation=subjects.simulation,
|
72
|
70
|
position=position,
|
73
|
|
- ))
|
|
71
|
+ )
|
|
72
|
+ cells.append(cell)
|
|
73
|
+ subjects.append(cell)
|
74
|
74
|
|
75
|
|
- return cells
|
|
75
|
+
|
|
76
|
+def fill_with_random_grass(
|
|
77
|
+ subjects: EngulfSubjects,
|
|
78
|
+ start_count: int,
|
|
79
|
+ start_position: tuple,
|
|
80
|
+ end_position: tuple,
|
|
81
|
+ density: int=10,
|
|
82
|
+) -> None:
|
|
83
|
+ grasses = []
|
|
84
|
+
|
|
85
|
+ while len(grasses) < start_count:
|
|
86
|
+ position = (
|
|
87
|
+ randint(start_position[0], end_position[0]+1),
|
|
88
|
+ randint(start_position[1], end_position[1]+1),
|
|
89
|
+ randint(start_position[2], end_position[2]+1),
|
|
90
|
+ )
|
|
91
|
+ if position not in subjects.grass_xyz:
|
|
92
|
+ grass = Grass(
|
|
93
|
+ simulation=subjects.simulation,
|
|
94
|
+ position=position,
|
|
95
|
+ )
|
|
96
|
+ grasses.append(grass)
|
|
97
|
+ subjects.append(grass)
|
|
98
|
+
|
|
99
|
+ # TODO: density
|
76
|
100
|
|
77
|
101
|
|
78
|
102
|
def main():
|
79
|
103
|
simulation = Engulf()
|
80
|
|
- subjects = get_random_subjects(
|
81
|
|
- simulation,
|
|
104
|
+ subjects = EngulfSubjects(simulation=simulation)
|
|
105
|
+ fill_with_random_cells(
|
|
106
|
+ subjects,
|
82
|
107
|
30,
|
83
|
|
- -34,
|
84
|
|
- -34,
|
85
|
|
- 34,
|
86
|
|
- 34,
|
|
108
|
+ (-34, -34, 0),
|
|
109
|
+ (34, 34, 0),
|
|
110
|
+ )
|
|
111
|
+ fill_with_random_grass(
|
|
112
|
+ subjects,
|
|
113
|
+ 15,
|
|
114
|
+ (-34, -34, 0),
|
|
115
|
+ (34, 34, 0),
|
87
|
116
|
)
|
88
|
117
|
simulation.subjects = subjects
|
89
|
118
|
|