Add rendering for all tiles and entities
parent
b51d505814
commit
ee43a87f8a
|
@ -44,39 +44,66 @@ ENUMIDS_TILETYPE_MAPPING = {
|
|||
'Urchin': 25,
|
||||
}
|
||||
|
||||
DANGER_COLOUR = (239,79,81,255)
|
||||
WCRATE_COLOUR = (160,117,48,255)
|
||||
MCRATE_COLOUR = (110,110,110,255)
|
||||
|
||||
REC_DRAW_FUNCTION = lambda ctx,x,y,s,c : ctx.rectangle(((x,y), (x+s-1, y+s-1)), c)
|
||||
UPHALFREC_DRAW_FUNCTION = lambda ctx,x,y,s,c : ctx.rectangle(((x,y), (x+s-1, y+s//2-1)), c)
|
||||
DOWNHALFREC_DRAW_FUNCTION = lambda ctx,x,y,s,c : ctx.rectangle(((x, y+s//2), (x+s-1,y+s-1)), c)
|
||||
LEFTHALFREC_DRAW_FUNCTION = lambda ctx,x,y,s,c : ctx.rectangle(((x,y), (x+s//2-1, y+s-1)), c)
|
||||
RIGHTHALFREC_DRAW_FUNCTION = lambda ctx,x,y,s,c : ctx.rectangle(((x+s//2,y), (x+s-1, y+s-1)), c)
|
||||
CIRCLE_DRAW_FUNCTION = lambda ctx,x,y,s,c : ctx.circle((x+s//2, y+s//2), s//2, c)
|
||||
TRIANGLE_DRAW_FUNCTION = lambda ctx,x,y,s,c : ctx.regular_polygon(((x+s//2, y+s//2), s//2), 3, 0, c)
|
||||
|
||||
def draw_bomb_tile(ctx, x, y, s, c):
|
||||
REC_DRAW_FUNCTION(ctx, x, y, s, c)
|
||||
ctx.line((x,y,x+s-1,y+s-1), DANGER_COLOUR, 1)
|
||||
ctx.line((x,y+s-1,x+s-1,y), DANGER_COLOUR, 1)
|
||||
|
||||
def draw_arrow_tile(ctx, x, y, s, c, d):
|
||||
REC_DRAW_FUNCTION(ctx, x, y, s, c)
|
||||
if d == 0:
|
||||
ctx.line((x+s//2,y+s//2,x+s//2,y), DANGER_COLOUR, 1)
|
||||
elif d == 1:
|
||||
ctx.line((x+s//2,y+s//2,x+s-1,y+s//2), DANGER_COLOUR, 1)
|
||||
elif d == 2:
|
||||
ctx.line((x+s//2,y+s//2,x+s//2,y+s-1), DANGER_COLOUR, 1)
|
||||
elif d == 3:
|
||||
ctx.line((x+s//2,y+s//2,x,y+s//2), DANGER_COLOUR, 1)
|
||||
|
||||
def draw_urchin_tile(ctx, x, y, s, c):
|
||||
ctx.line((x,y,x+s-1,y+s-1), c, 1)
|
||||
ctx.line((x,y+s-1,x+s-1,y), c, 1)
|
||||
ctx.line((x+(s-1)//2,y,x+(s-1)//2,y+s-1), c, 1)
|
||||
ctx.line((x,y+(s-1)//2,x+s-1,y+(s-1)//2), c, 1)
|
||||
|
||||
TILETYPE_SHAPE_MAP = {
|
||||
'Solid': (REC_DRAW_FUNCTION, (0,0,0,255)),
|
||||
'WoodenPlat': (UPHALFREC_DRAW_FUNCTION, (128,64,0,255)),
|
||||
'Ladder': (REC_DRAW_FUNCTION, (214,141,64,255)),
|
||||
'LSpike': (LEFTHALFREC_DRAW_FUNCTION, (239,79,81,255)),
|
||||
'RSpike': (RIGHTHALFREC_DRAW_FUNCTION, (239,79,81,255)),
|
||||
'USpike': (UPHALFREC_DRAW_FUNCTION, (239,79,81,255)),
|
||||
'DSpike': (DOWNHALFREC_DRAW_FUNCTION, (239,79,81,255)),
|
||||
'EmptyWCrate': (REC_DRAW_FUNCTION, (160,117,48,255)),
|
||||
#'LArrowWCrate': 9,
|
||||
#'RArrowWCrate': 10,
|
||||
#'UArrowWCrate': 11,
|
||||
#'DArrowWCrate': 12,
|
||||
#'BombWCrate': 13,
|
||||
'EmptyMCrate': (REC_DRAW_FUNCTION, (225,225,225,255)),
|
||||
#'LArrowMCrate': 15,
|
||||
#'RArrowMCrate': 16,
|
||||
#'UArrowMCrate': 17,
|
||||
#'DArrowMCrate': 18,
|
||||
#'BombMCrate': 19,
|
||||
'LSpike': (LEFTHALFREC_DRAW_FUNCTION, DANGER_COLOUR),
|
||||
'RSpike': (RIGHTHALFREC_DRAW_FUNCTION, DANGER_COLOUR),
|
||||
'USpike': (UPHALFREC_DRAW_FUNCTION, DANGER_COLOUR),
|
||||
'DSpike': (DOWNHALFREC_DRAW_FUNCTION, DANGER_COLOUR),
|
||||
'EmptyWCrate': (REC_DRAW_FUNCTION, WCRATE_COLOUR),
|
||||
'LArrowWCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,3), WCRATE_COLOUR),
|
||||
'RArrowWCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,1), WCRATE_COLOUR),
|
||||
'UArrowWCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,0), WCRATE_COLOUR),
|
||||
'DArrowWCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,2), WCRATE_COLOUR),
|
||||
'BombWCrate': (draw_bomb_tile, WCRATE_COLOUR),
|
||||
'EmptyMCrate': (REC_DRAW_FUNCTION, MCRATE_COLOUR),
|
||||
'LArrowMCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,3), MCRATE_COLOUR),
|
||||
'RArrowMCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,1), MCRATE_COLOUR),
|
||||
'UArrowMCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,0), MCRATE_COLOUR),
|
||||
'DArrowMCrate': (lambda ctx,x,y,s,c : draw_arrow_tile(ctx,x,y,s,c,2), MCRATE_COLOUR),
|
||||
'BombMCrate': (draw_bomb_tile, MCRATE_COLOUR),
|
||||
'Boulder': (CIRCLE_DRAW_FUNCTION, (45,45,45,255)),
|
||||
#'Runner': 21,
|
||||
'Runner': (TRIANGLE_DRAW_FUNCTION, (0,0,128,255)),
|
||||
'Player': (REC_DRAW_FUNCTION, (255,0,255,255)),
|
||||
'Chest': (REC_DRAW_FUNCTION, (255,255,0,255)),
|
||||
'Exit': (REC_DRAW_FUNCTION, (0,255,0,255)),
|
||||
#'Urchin': 25,
|
||||
'Urchin': (draw_urchin_tile, DANGER_COLOUR),
|
||||
}
|
||||
|
||||
# First go to tilesets and find Simple_tiles identifier, then find enumTags to identifier which tile type is what tileid
|
||||
|
@ -126,7 +153,7 @@ converted_filename = '.'.join(fileparts)
|
|||
TILE_SIZE = 8
|
||||
# Each level should be packed as: [width, 2 bytes][height, 2 bytes][tile_type,entity,water,padding 1,1,1,1 bytes][tile_type,entity,water,padding 1,1,1,1 bytes]...
|
||||
# Then loop the levels. Read the layerIndstances
|
||||
for level in all_levels[17:18]:
|
||||
for level in all_levels[13:15]:
|
||||
n_chests : int = 0
|
||||
# Search for __identifier for the level layout
|
||||
level_name = ""
|
||||
|
@ -176,27 +203,24 @@ for level in all_levels[17:18]:
|
|||
print("Error on tile", x, y)
|
||||
render_ctx.circle((x,y), 2,(255,0,0,255))
|
||||
print(e)
|
||||
lvl_render.show()
|
||||
#for i, water_level in enumerate(water_layout["intGridCsv"]):
|
||||
# tiles_info[i][2] = water_level
|
||||
|
||||
## Subject to change
|
||||
#for ent in entity_layout["entityInstances"]:
|
||||
# x,y = ent["__grid"]
|
||||
# tiles_info[y*width + x][0] = ENUMIDS_TILETYPE_MAPPING[ent["__identifier"]]
|
||||
# if ent["__identifier"] == "Urchin":
|
||||
# spd_encoding = 0
|
||||
# for urchin_data in ent['fieldInstances']:
|
||||
# if urchin_data["__identifier"] == "Direction":
|
||||
# spd_encoding |= urchin_data["__value"] << 2
|
||||
# elif urchin_data["__identifier"] == "SpeedLevel":
|
||||
# spd_encoding |= urchin_data["__value"]
|
||||
|
||||
# tiles_info[y*width + x][0] += spd_encoding
|
||||
|
||||
|
||||
#for y in range(height):
|
||||
# for x in range(width):
|
||||
# print(tiles_info[y*width + x], end=" ")
|
||||
# print()
|
||||
for ent in entity_layout["entityInstances"]:
|
||||
x,y = ent["__grid"]
|
||||
x *= TILE_SIZE
|
||||
y *= TILE_SIZE
|
||||
ent = ent["__identifier"]
|
||||
try:
|
||||
if ent in TILETYPE_SHAPE_MAP:
|
||||
draw_func, colour = TILETYPE_SHAPE_MAP[ent]
|
||||
draw_func(render_ctx, x, y, TILE_SIZE, colour)
|
||||
else:
|
||||
print(ent, "is not mapped");
|
||||
except Exception as e:
|
||||
print("Error on tile", x, y)
|
||||
render_ctx.circle((x,y), 2,(255,0,0,255))
|
||||
print(e)
|
||||
|
||||
lvl_render.show()
|
||||
|
|
Loading…
Reference in New Issue