-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapManager.py
50 lines (36 loc) · 1.21 KB
/
MapManager.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
from QTree import QTree
import pygame
class MapManager:
mapSize = 32768
def __init__(self, screenSize, network = None):
self.position = 0
self.screenSize = screenSize
self.network = network
self.tree = QTree(pygame.Rect(-MapManager.mapSize/2, -MapManager.mapSize/2,
MapManager.mapSize, MapManager.mapSize))
def addNode(self, node):
self.tree.insert(node)
def setNetwork(self, network):
self.network = network
def setPosition(self, position):
self.position = position
def incrementPosition(self, delta):
self.position[0] += delta[0]
self.position[1] += delta[1]
def getPosition(self, position):
return self.position
def getAllNodes(self):
return self.tree.getAllNodes()
def getNodesAndConnectionsOnScreen(self):
relevantNodes = []
screenRect = pyGame.Rect(self.position[0] - self.screenSize[0],
self.position[1] - self.screenSize[1],
self.screenSize[0], self.screenSize[1]);
relevantNodes.extend(self.tree.getChildrenInRegion(screeRect))
for node in relevantNodes:
for connection in node.getConnections():
if not connection in relevantNodes:
relevantNodes.append(connection)
return relevantNodes
def getQTree():
return self.tree