-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.py
More file actions
95 lines (83 loc) · 2.73 KB
/
map.py
File metadata and controls
95 lines (83 loc) · 2.73 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class Map(object):
"""docstring for Map"""
def __init__(self, player_list=None, width=1800, height=500, tileWidth=70, gravity=10):
super(Map, self).__init__()
if player_list:
self.player_list = player_list
else:
self.player_list = []
self.tile_list = None
self.enemies_list = None
self.props_list = None
self.tileWidth = tileWidth
self.width = width
self.height = height
self.gravity = gravity
def genFloor(self):
if self.tile_list is None:
self.tile_list = []
# print("*"*5, "Generating Tiles for the floor","*"*5)
totalTiles = int(self.width / self.tileWidth)
for nTile in range(0, totalTiles):
x = nTile * self.tileWidth
y = self.height - self.tileWidth # plain heigthfloor
self.tile_list.append(Tile(x, y))
else:
print("*" * 5, " Tiles not generated !!!", "*" * 5)
def updateAll(self):
if self.player_list:
for plyr in self.player_list:
plyr.y += self.gravity
plyr.update()
self.checkTileCollitions(plyr)
def checkTileCollitions(self, player):
tileIndx = int(player.x / self.tileWidth)
# print("Check colision...... ", "!!!!!!"*5)
if tileIndx < len(self.tile_list):
if (player.x >= self.tile_list[tileIndx].x and
player.x < (self.tile_list[tileIndx].x + self.tileWidth) and
player.y > self.tile_list[tileIndx].y and
player.y <= (self.tile_list[tileIndx].y + self.tile_list[tileIndx].height)):
player.y = self.tile_list[tileIndx].y
# print("Collisionnnnnnnn!!!! " * 5)
# def addPlayer(self, sid, character, x, y):
def addPlayer(self, player):
self.player_list.append(player)
if len(self.player_list) > 0 and self.tile_list is None:
self.genFloor()
def removePlayer(self, sid):
for plyr in self.player_list:
if plyr.id == sid:
self.player_list.remove(plyr)
# print(f"\nPLAYER {sid} FROM LIST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
# print([x.id for x in self.player_list])
break
# print("\nPLAYER NOT FOUUUUUUHNDDDDDDDDDDDDDDDDDDDD ON LIST**************************!\n")
def findPlayer(self, sid):
for plyr in self.player_list:
if plyr.id == sid:
return plyr
def jsonData(self, data="players"):
if self.tile_list:
if data == "map":
return [x.jsonify() for x in self.tile_list]
if self.player_list:
if data == "players":
return [x.jsonify() for x in self.player_list]
if self.enemies_list:
if data == "enemies":
return [x.jsonify() for x in self.enemies_list]
class Tile(object):
"""Class for Tile of the map"""
def __init__(self, x, y, tileType="grass", height=70, fixed=True):
super(Tile, self).__init__()
self.x = x
self.y = y
self.height = height
self.fixed = fixed
self.tileType = tileType
def jsonify(self):
return {'x': self.x,
'y': self.y,
'tileType': self.tileType
}