-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstages.py
More file actions
61 lines (51 loc) · 2.62 KB
/
Copy pathstages.py
File metadata and controls
61 lines (51 loc) · 2.62 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
from fruit.envs.games.food_collector.constants import GlobalConstants
from fruit.envs.games.food_collector.manager import ResourceManager
from fruit.envs.games.food_collector.sprites import TreeSprite, LandSprite
class StageMap(object):
def __init__(self, num_of_tiles, tile_size, current_path, sprites, trees, lands, resources_manager):
self.num_of_stages = 1
self.num_of_tiles = num_of_tiles
self.map = [None] * self.num_of_stages
self.current_path = current_path
self.sprites = sprites
self.trees = trees
self.tile_size = tile_size
self.rc = resources_manager
self.lands = lands
self.__build_map()
def __build_map(self):
#########################################################################
#########################################################################
# STAGE 1
# We can make a static or dynamic map
# This is a static map (it is better to use dynamic when num_of_tiles is
# unknown). However, static map is easier to create a stage.
self.map[0] = [[-1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1],
[ 1, -1, 1, -1, -1, -1],
[-1, -1, -1, 1, -1, -1],
[-1, 0, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1]]
#########################################################################
#########################################################################
def load_map(self, stage):
if stage >= self.num_of_stages:
raise ValueError("Stage out of range !!!")
# This is for static map
for row in range(len(self.map[stage])):
for col in range(len(self.map[stage][row])):
land_bg = self.rc.get_image(ResourceManager.LAND_TILE)
land = LandSprite(self.tile_size, col, row, land_bg)
self.lands.add(land)
if self.map[stage][row][col] == GlobalConstants.TREE_TILE:
tree_bg = self.rc.get_image(ResourceManager.TREE_TILE)
tree = TreeSprite(self.tile_size, col, row, tree_bg)
self.sprites.add(tree)
self.trees.add(tree)
if self.map[stage][row][col] == GlobalConstants.PLANT_TILE:
plant_bg = self.rc.get_image(ResourceManager.PLANT_TILE)
plant = TreeSprite(self.tile_size, col, row, plant_bg)
self.sprites.add(plant)
self.trees.add(plant)
def number_of_stages(self):
return self.num_of_stages