-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtileMap.py
More file actions
50 lines (42 loc) · 1.37 KB
/
tileMap.py
File metadata and controls
50 lines (42 loc) · 1.37 KB
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
import random
class TileMap:
def __init__(self, size):
self._tileMap = self.createMap(size)
self._tiles = []
for row in self._tileMap:
for x in row:
self._tiles.append( { "status": x } )
def loadingMap(self, oldMap):
self._tileMap = oldMap
self._tiles = []
for row in self._tileMap:
for x in row:
self._tiles.append( { "status": x } )
def appendTile(self, polygon, position):
for tile in self._tiles:
if "polygon" not in tile:
tile["polygon"] = polygon
tile["position"] = position
break
def __getitem__(self, index):
return self._tileMap[index]
def updateMap(self, index, status):
newMap = self._tileMap
size = len(newMap)
rowIndex = int(index / size)
realIndex = index - (rowIndex * size)
self._tileMap[rowIndex][realIndex] = status
def getTile(self, index):
return self._tiles[index]
@staticmethod
def createMap(size) -> list:
"""
Create `size` x `size` map
"""
map_data = []
for mapy in range(0, size):
map_row = []
for mapx in range(0, size):
map_row.append(0) # random.randint(0,1)
map_data.append(map_row)
return map_data