nodes/level_data.pyΒΆ
Part of Tower Defence.
1"""Level data for the Tower Defence port.
2
3An original level designed for this port (the upstream tutorial's Tiled
4map is not redistributable). `level.png` is baked from Kenney's CC0
5Tower Defense tiles plus a procedurally drawn sand path that follows
6`WAYPOINTS`; see `ATTRIBUTION.md`.
7
8- `WAYPOINTS`: polyline the enemies follow, in world space (px). The
9 ends sit off-screen so enemies enter and leave smoothly.
10- `TILE_MAP`: 15x15 grid; tile id ``7`` is grass and is the only tile a
11 turret can be placed on (``2`` = path, ``5`` = decoration).
12"""
13
14from __future__ import annotations
15
16WAYPOINTS: list[tuple[float, float]] = [
17 (-72.0, 120.0),
18 (552.0, 120.0),
19 (552.0, 264.0),
20 (168.0, 264.0),
21 (168.0, 408.0),
22 (360.0, 408.0),
23 (360.0, 600.0),
24 (792.0, 600.0),
25]
26
27# 15x15 grid; tile id 7 = grass (placeable), 2 = path, 5 = decoration.
28TILE_MAP: list[int] = [
29 7,
30 5,
31 7,
32 7,
33 7,
34 7,
35 7,
36 7,
37 7,
38 5,
39 7,
40 7,
41 7,
42 7,
43 7,
44 7,
45 7,
46 7,
47 7,
48 7,
49 7,
50 7,
51 7,
52 7,
53 7,
54 7,
55 7,
56 7,
57 5,
58 7,
59 2,
60 2,
61 2,
62 2,
63 2,
64 2,
65 2,
66 2,
67 2,
68 2,
69 2,
70 2,
71 7,
72 7,
73 7,
74 7,
75 7,
76 7,
77 7,
78 7,
79 5,
80 7,
81 7,
82 7,
83 7,
84 7,
85 2,
86 7,
87 7,
88 7,
89 7,
90 7,
91 7,
92 7,
93 7,
94 7,
95 7,
96 7,
97 7,
98 7,
99 7,
100 2,
101 7,
102 7,
103 7,
104 7,
105 7,
106 7,
107 2,
108 2,
109 2,
110 2,
111 2,
112 2,
113 2,
114 2,
115 2,
116 7,
117 7,
118 7,
119 7,
120 7,
121 7,
122 2,
123 7,
124 7,
125 7,
126 7,
127 7,
128 7,
129 7,
130 7,
131 7,
132 7,
133 7,
134 7,
135 7,
136 7,
137 2,
138 7,
139 7,
140 7,
141 7,
142 7,
143 7,
144 7,
145 7,
146 7,
147 5,
148 7,
149 7,
150 7,
151 7,
152 2,
153 2,
154 2,
155 2,
156 2,
157 7,
158 7,
159 7,
160 7,
161 7,
162 7,
163 7,
164 7,
165 7,
166 7,
167 7,
168 7,
169 7,
170 7,
171 2,
172 7,
173 7,
174 5,
175 7,
176 7,
177 7,
178 7,
179 7,
180 7,
181 7,
182 7,
183 7,
184 5,
185 7,
186 2,
187 7,
188 7,
189 7,
190 7,
191 7,
192 7,
193 7,
194 7,
195 5,
196 7,
197 7,
198 7,
199 7,
200 7,
201 2,
202 7,
203 7,
204 7,
205 7,
206 7,
207 7,
208 7,
209 7,
210 7,
211 7,
212 7,
213 7,
214 7,
215 7,
216 2,
217 2,
218 2,
219 2,
220 2,
221 2,
222 2,
223 2,
224 7,
225 7,
226 5,
227 7,
228 7,
229 7,
230 7,
231 7,
232 7,
233 7,
234 7,
235 7,
236 7,
237 7,
238 7,
239 7,
240 7,
241 7,
242 7,
243 7,
244 7,
245 7,
246 7,
247 7,
248 7,
249 7,
250 7,
251 5,
252 7,
253 7,
254]
255
256GRASS_TILE = 7
257COLS = 15
258ROWS = 15
259
260
261def is_grass(tx: int, ty: int) -> bool:
262 if not (0 <= tx < COLS and 0 <= ty < ROWS):
263 return False
264 return TILE_MAP[ty * COLS + tx] == GRASS_TILE