Ver código fonte

Added environment resource data.

master
Bryan Miller 6 anos atrás
pai
commit
35d664469d
2 arquivos alterados com 44 adições e 3 exclusões
  1. +21
    -0
      data/json/environment.json
  2. +23
    -3
      game/nodes.py

+ 21
- 0
data/json/environment.json Ver arquivo

@@ -0,0 +1,21 @@
{
"horizon":{
"src":"maptiles/CeilingsFloors.png",
"day_shade":[0,32,64,32],
"night_shade":[0,0,64,32],
"defs":[
"Night":[0,64,64,32],
"Day":[0,96,64,32],
"C. Wood":[0,128,64,32]
]
},
"ground":{
"src":"maptiles/CeilingsFloors.png"
"day_shade":[0,32,64,32],
"night_shade":[0,0,64,32],
"defs":[
"G. Wood":[128,0,64,32],
"G. Gravel":[128,32,64,32]
]
}
}

+ 23
- 3
game/nodes.py Ver arquivo

@@ -94,21 +94,27 @@ class NodeGameMap(gbe.nodes.Node2D):
if e is not None and e() is not None:
self._res["env_src"] = env_src
self._res["env"] = e
# TODO: Load the images associated with the environments
# NOTE: Making a lot of assumptions to the structural validity of the data file.
isrc1 = e().data["horizon"]["src"]
isrc2 = e().data["ground"]["src"]
if res.is_valid("graphic", isrc1) and res.is_valid("graphic", isrc2):
if not res.has("graphic", isrc1):
res.store("graphic", isrc1)
if not res.has("graphic", isrc2):
res.store("graphic", isrc2)
if wall_src != "" and wall_src != self._res["wall_src"]:
if res.is_valid("json", wall_src):
if not res.has("json", wall_src):
print("Storing resource {}".format(wall_src))
res.store("json", wall_src)
w = res.get("json", wall_src)
print(w)
if w is not None and w() is not None:
self._res["wall_src"] = wall_src
self._res["walls"] = w
# NOTE: I'm making a lot of assumptions to the structural validity of the data file, but...
imgsrc = w().data["src"]
if res.is_valid("graphic", imgsrc):
if res.has("graphic", imgsrc):
if not res.has("graphic", imgsrc):
res.store("graphic", imgsrc)
else:
print("Failed to get JSON instance {}".format(wall_src))
@@ -397,6 +403,20 @@ class NodeMapEditor(gbe.nodes.Node2D):
"w": ((hs,hs),(-hs,0),(hs,-hs))
}

def set_color(self, color):
if isinstance(color, (tuple, list)):
clen = len(color)
if clen == 3 or clen == 4:
iscolor = lambda v : isinstance(v, int) and v >= 0 and v < 256
if iscolor(color[0]) and iscolor(color[1]) and iscolor(color[2]):
if clen == 3:
self._color = pygame.Color(color[0], color[1], color[2])
elif clen == 4 and iscolor(color[3]):
self._color = pygame.Color(color[0], color[1], color[2], color[3])

def get_color(self):
return (self._color.r, self._color.g, self._color.b, self._color.a)

def on_start(self):
self.listen("KEYPRESSED", self.on_keypressed)


Carregando…
Cancelar
Salvar