-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.py
More file actions
54 lines (38 loc) · 1.48 KB
/
Map.py
File metadata and controls
54 lines (38 loc) · 1.48 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
import pyglet
import random
import MapGenerator
# Atlas containing all of the map markers
map_markers = pyglet.resource.image("resources/map/markers.png")
def getMarker(name):
marker = None
if name == 'marker':
marker = map_markers.get_region(0, 0, 32, 32)
marker.anchor_x = marker.width/2
marker.anchor_y = marker.height/2
return marker
# The map class is higher-order. It only concerns itself with where things are placed on the map, not the drawing of the map
class Map(object):
def __init__(self, width, height, abMap):
# Initialize a map with a specified width and height
self.width = width
self.height = height
# Maps are organised so that one unit in OpenGL terms is one unit on the map.
# At the moment the definition of a unit is left to the imagination
self.elements = abMap.load()
def addObject(self, ob):
self.elements.append(ob)
def getElements(self):
return self.elements
class MapObject(object):
def __init__(self, name, xpos, ypos):
self.name = name
self.x = xpos
self.y = ypos
self.h = (random.random()-0.5)*2
# Random rotation
self.orientation = bool(random.getrandbits(1))
self.img = 'marker'
def getImage(self):
return getMarker(self.img)
def getSprite(self):
return pyglet.sprite.Sprite(img=self.getImage())