Add rest of assets, add blue player
BIN
assets/game.png
|
Before Width: | Height: | Size: 399 KiB After Width: | Height: | Size: 440 KiB |
@@ -242,9 +242,9 @@
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5893, 5894, 5895, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5655, 5656, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6149, 6150, 6151, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void igResource(ecs_world_t *ecs,
|
|||||||
void igOwner(ecs_world_t *ecs,
|
void igOwner(ecs_world_t *ecs,
|
||||||
ecs_entity_t entity, ecs_entity_t comp) {
|
ecs_entity_t entity, ecs_entity_t comp) {
|
||||||
Owner *owner = ecs_get_mut_id(ecs, entity, comp);
|
Owner *owner = ecs_get_mut_id(ecs, entity, comp);
|
||||||
igInputInt("PlayerID", &owner->playerID, 0, 0, 0);
|
igInputInt("PlayerID", &owner->player, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void igSpatialGridID(ecs_world_t *ecs,
|
void igSpatialGridID(ecs_world_t *ecs,
|
||||||
|
|||||||
@@ -33,8 +33,14 @@ typedef struct Resource {
|
|||||||
} Resource;
|
} Resource;
|
||||||
extern ECS_COMPONENT_DECLARE(Resource);
|
extern ECS_COMPONENT_DECLARE(Resource);
|
||||||
|
|
||||||
|
typedef enum Player {
|
||||||
|
PLAYER_RED = 0,
|
||||||
|
PLAYER_BLUE = 1,
|
||||||
|
PLAYER_COUNT
|
||||||
|
} Player;
|
||||||
|
|
||||||
typedef struct Owner {
|
typedef struct Owner {
|
||||||
int32_t playerID;
|
Player player;
|
||||||
} Owner;
|
} Owner;
|
||||||
extern ECS_COMPONENT_DECLARE(Owner);
|
extern ECS_COMPONENT_DECLARE(Owner);
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ ecs_entity_t entityCreateWorker(const Position position, Game *game) {
|
|||||||
Arms arms = {.primary = right};
|
Arms arms = {.primary = right};
|
||||||
ecs_set_ptr(ECS, e, Arms, &arms);
|
ecs_set_ptr(ECS, e, Arms, &arms);
|
||||||
ecs_set(ECS, right, Arm, {.offset = 45.0f, 4.5f});
|
ecs_set(ECS, right, Arm, {.offset = 45.0f, 4.5f});
|
||||||
|
ecs_set(ECS, e, Owner, {PLAYER_RED});
|
||||||
|
|
||||||
ecs_set(ECS, right, Size, {8, 8});
|
ecs_set(ECS, right, Size, {8, 8});
|
||||||
ecs_set(ECS, right, Rotation, { 0.0f });
|
ecs_set(ECS, right, Rotation, { 0.0f });
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ typedef struct DrawData {
|
|||||||
Rectangle dst;
|
Rectangle dst;
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
f32 rotation;
|
f32 rotation;
|
||||||
|
u8 layer;
|
||||||
bool canHaveAlpha;
|
bool canHaveAlpha;
|
||||||
} DrawData;
|
} DrawData;
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ void updateAnimationState(ecs_iter_t *it) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void updateAnimation(ecs_iter_t *it) {
|
void updateAnimation(ecs_iter_t *it) {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
|
||||||
Animation *anim = ecs_field(it, Animation, 1);
|
Animation *anim = ecs_field(it, Animation, 1);
|
||||||
TextureRegion *texture = ecs_field(it, TextureRegion, 2);
|
TextureRegion *texture = ecs_field(it, TextureRegion, 2);
|
||||||
|
|
||||||
float dt = GetFrameTime();
|
float dt = GetFrameTime();
|
||||||
|
|
||||||
for (i32 i = 0; i < it->count; i++) {
|
for (i32 i = 0; i < it->count; i++) {
|
||||||
|
ecs_entity_t entity = it->entities[i];
|
||||||
AnimationFrame frame = anim[i].frame;
|
AnimationFrame frame = anim[i].frame;
|
||||||
AnimationSequence seq = anim[i].sequence;
|
AnimationSequence seq = anim[i].sequence;
|
||||||
|
|
||||||
@@ -46,7 +46,14 @@ void updateAnimation(ecs_iter_t *it) {
|
|||||||
anim[i].frame = entityGetAnimationFrame(anim[i].entityType, anim[i].animType, nextFrame);
|
anim[i].frame = entityGetAnimationFrame(anim[i].entityType, anim[i].animType, nextFrame);
|
||||||
anim[i].elapsed = 0.0f;
|
anim[i].elapsed = 0.0f;
|
||||||
|
|
||||||
texture[i].rec = bzTilesetGetTileRegion(anim[i].tileset, anim[i].frame.frame);
|
texture[i].rec = getTextureRect(anim[i].frame.frame);
|
||||||
|
if (ecs_has(ECS, entity, Owner)) {
|
||||||
|
Owner owner = *ecs_get(ECS, entity, Owner);
|
||||||
|
BzTileID base = anim[i].frame.frame;
|
||||||
|
Vector2 offset = getTileOffset(base, owner.player);
|
||||||
|
texture[i].rec.x += offset.x;
|
||||||
|
texture[i].rec.y += offset.y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,10 +45,23 @@ void entityPathRemove(ecs_iter_t *it) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateTextureOwnerTile(ecs_iter_t *it) {
|
||||||
|
TextureRegion *tex = ecs_field(it, TextureRegion, 1);
|
||||||
|
Owner *owner = ecs_field(it, Owner, 2);
|
||||||
|
|
||||||
|
for (i32 i = 0; i < it->count; i++) {
|
||||||
|
Rectangle rec = tex[i].rec;
|
||||||
|
BzTileID base = ((int)rec.y / 16) * 256 + ((int) rec.x / 16);
|
||||||
|
Vector2 offset = getTileOffset(base, owner[i].player);
|
||||||
|
tex[i].rec.x += offset.x;
|
||||||
|
tex[i].rec.y += offset.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void entityUpdateSpatialID(ecs_iter_t *it) {
|
void entityUpdateSpatialID(ecs_iter_t *it) {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
Position *position = ecs_field(it, Position, 1);
|
Position *position = ecs_field(it, Position, 1);
|
||||||
Position *size = ecs_field(it, Position, 2);
|
Position *size = ecs_field(it, Size, 2);
|
||||||
//Velocity *velocity = ecs_field(it, Velocity, 3);
|
//Velocity *velocity = ecs_field(it, Velocity, 3);
|
||||||
SpatialGridID *id = ecs_field(it, SpatialGridID, 4);
|
SpatialGridID *id = ecs_field(it, SpatialGridID, 4);
|
||||||
|
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ void updatePlayerInput() {
|
|||||||
getBuildingSize(input->building, &sizeX, &sizeY);
|
getBuildingSize(input->building, &sizeX, &sizeY);
|
||||||
bool canPlace = canPlaceBuilding(game, input->building, tileX, tileY);
|
bool canPlace = canPlaceBuilding(game, input->building, tileX, tileY);
|
||||||
if (canPlace && isInputBtnDown(input, primaryBtn)) {
|
if (canPlace && isInputBtnDown(input, primaryBtn)) {
|
||||||
placeBuilding(game, input->building, tileX, tileY, (Owner) {-1});
|
placeBuilding(game, input->building, tileX, tileY, (Owner) {PLAYER_BLUE});
|
||||||
}
|
}
|
||||||
input->buildingCanPlace = canPlace;
|
input->buildingCanPlace = canPlace;
|
||||||
input->buildingPos = (Vec2i) {tileX, tileY};
|
input->buildingPos = (Vec2i) {tileX, tileY};
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void drawGameUI(Game *game, f32 dt) {
|
|||||||
BUILDING_MARKET,
|
BUILDING_MARKET,
|
||||||
BUILDING_MILL,
|
BUILDING_MILL,
|
||||||
BUILDING_HOUSE_02, // placeholder for farm
|
BUILDING_HOUSE_02, // placeholder for farm
|
||||||
BUILDING_BARRACS,
|
BUILDING_BARRACKS,
|
||||||
BUILDING_ARCHERY_RANGE
|
BUILDING_ARCHERY_RANGE
|
||||||
};
|
};
|
||||||
const char *buildingNames[] = {
|
const char *buildingNames[] = {
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ void setupSystems() {
|
|||||||
|
|
||||||
ECS_OBSERVER(ECS, entityPathRemove, EcsOnRemove, Path);
|
ECS_OBSERVER(ECS, entityPathRemove, EcsOnRemove, Path);
|
||||||
|
|
||||||
|
ECS_OBSERVER(ECS, updateTextureOwnerTile, EcsOnSet, TextureRegion, Owner);
|
||||||
|
|
||||||
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, Size, Velocity, SpatialGridID);
|
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, Size, Velocity, SpatialGridID);
|
||||||
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
|
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ void updateEasingSystem(ecs_iter_t *it);
|
|||||||
*/
|
*/
|
||||||
void entityPathRemove(ecs_iter_t *it);
|
void entityPathRemove(ecs_iter_t *it);
|
||||||
|
|
||||||
|
void updateTextureOwnerTile(ecs_iter_t *it);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 0: Game (singleton) for entity map
|
* 0: Game (singleton) for entity map
|
||||||
* 1: Position
|
* 1: Position
|
||||||
|
|||||||
BIN
rawAssets/Puny-Characters/Archer-Green.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
rawAssets/Puny-Characters/Archer-Purple.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
rawAssets/Puny-Characters/Character-Base.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
rawAssets/Puny-Characters/Environment/Dirt.png
Normal file
|
After Width: | Height: | Size: 651 B |
BIN
rawAssets/Puny-Characters/Environment/Grass1.png
Normal file
|
After Width: | Height: | Size: 581 B |
BIN
rawAssets/Puny-Characters/Environment/Grass2.png
Normal file
|
After Width: | Height: | Size: 581 B |
BIN
rawAssets/Puny-Characters/Environment/Tree.png
Normal file
|
After Width: | Height: | Size: 812 B |
BIN
rawAssets/Puny-Characters/Human-Soldier-Cyan.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
rawAssets/Puny-Characters/Human-Soldier-Red.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
rawAssets/Puny-Characters/Human-Worker-Cyan.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
rawAssets/Puny-Characters/Human-Worker-Red.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
rawAssets/Puny-Characters/Mage-Cyan.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
rawAssets/Puny-Characters/Mage-Red.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
rawAssets/Puny-Characters/Orc-Grunt.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
rawAssets/Puny-Characters/Orc-Peon-Cyan.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
rawAssets/Puny-Characters/Orc-Peon-Red.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
rawAssets/Puny-Characters/Orc-Soldier-Cyan.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
rawAssets/Puny-Characters/Orc-Soldier-Red.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
rawAssets/Puny-Characters/Slime.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
rawAssets/Puny-Characters/Soldier-Blue.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
rawAssets/Puny-Characters/Soldier-Red.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
rawAssets/Puny-Characters/Soldier-Yellow.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
rawAssets/Puny-Characters/Warrior-Blue.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
rawAssets/Puny-Characters/Warrior-Red.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 399 KiB After Width: | Height: | Size: 440 KiB |
3840
rawAssets/game.tsj
1669
rawAssets/game.tsx
4
rawAssets/test.tsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<tileset version="1.10" tiledversion="1.10.2" name="test" tilewidth="16" tileheight="16" tilecount="768" columns="48">
|
||||||
|
<image source="Puny-Characters/Human-Worker-Red.png" width="768" height="256"/>
|
||||||
|
</tileset>
|
||||||
@@ -442,3 +442,143 @@ class EnumWriter:
|
|||||||
writer.output("return (AnimationFrame) {-1, -1.0f};\n")
|
writer.output("return (AnimationFrame) {-1, -1.0f};\n")
|
||||||
writer.block_end()
|
writer.block_end()
|
||||||
writer.empty_line()
|
writer.empty_line()
|
||||||
|
|
||||||
|
def filter_by_props(self, tiles, prop_names):
|
||||||
|
filtered = []
|
||||||
|
for tile in tiles:
|
||||||
|
if 'properties' not in tile:
|
||||||
|
continue
|
||||||
|
props = tile['properties']
|
||||||
|
names = prop_names[:]
|
||||||
|
for prop in props:
|
||||||
|
if prop['name'] in names:
|
||||||
|
names.remove(prop['name'])
|
||||||
|
if len(names) == 0:
|
||||||
|
filtered.append(tile)
|
||||||
|
return filtered
|
||||||
|
|
||||||
|
def get_property(self, tile, prop_name):
|
||||||
|
if 'properties' not in tile:
|
||||||
|
return None
|
||||||
|
props = tile['properties']
|
||||||
|
for prop in props:
|
||||||
|
if prop['name'] == prop_name:
|
||||||
|
return prop
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def output_get_text_rect(self, func_name, width, tile_width, tile_height):
|
||||||
|
writer = self.writer
|
||||||
|
writer.output(
|
||||||
|
f"static Rectangle {func_name}(BzTileID tile) ")
|
||||||
|
writer.block_start()
|
||||||
|
|
||||||
|
writer.output(f"Rectangle base = {{ (tile % {width}) * {tile_width}, "
|
||||||
|
f"(tile / {width}) * {tile_height}, {tile_width}, {tile_height} }};\n")
|
||||||
|
|
||||||
|
sized_tiles = {}
|
||||||
|
for tile in self.all_tiles:
|
||||||
|
if 'properties' not in tile:
|
||||||
|
continue
|
||||||
|
props = tile['properties']
|
||||||
|
size_x = 1
|
||||||
|
size_y = 1
|
||||||
|
for prop in props:
|
||||||
|
if prop['name'] == 'size_x':
|
||||||
|
size_x = int(prop['value'])
|
||||||
|
if prop['name'] == 'size_y':
|
||||||
|
size_y = int(prop['value'])
|
||||||
|
|
||||||
|
if size_x == 1 and size_y == 1:
|
||||||
|
continue
|
||||||
|
sized_tiles[tile['id']] = (size_x, size_y)
|
||||||
|
sized_map = defaultdict(list)
|
||||||
|
for k, v in sized_tiles.items():
|
||||||
|
sized_map[v].append(k)
|
||||||
|
|
||||||
|
if sized_map:
|
||||||
|
writer.output("switch (tile) ")
|
||||||
|
writer.block_start()
|
||||||
|
for k, v in sized_map.items():
|
||||||
|
for id in v:
|
||||||
|
writer.output(f"case {id}:\n")
|
||||||
|
writer.indent()
|
||||||
|
x, y = k
|
||||||
|
writer.output(f"base.width *= {x};\n")
|
||||||
|
writer.output(f"base.height *= {y};\n")
|
||||||
|
writer.output("break;\n")
|
||||||
|
writer.unindent()
|
||||||
|
writer.output("default: break;\n")
|
||||||
|
writer.block_end()
|
||||||
|
|
||||||
|
writer.output("return base;\n")
|
||||||
|
|
||||||
|
writer.block_end()
|
||||||
|
writer.empty_line()
|
||||||
|
|
||||||
|
def output_base_index(self, func_name, field):
|
||||||
|
writer = self.writer
|
||||||
|
tiles = self.filter_by_props(self.all_tiles, [field])
|
||||||
|
field_map = defaultdict(list)
|
||||||
|
for tile in tiles:
|
||||||
|
index = self.get_property(tile, field)['value']
|
||||||
|
field_map[index].append(tile['id'])
|
||||||
|
sizes = list(map(lambda x: len(x), field_map.values()))
|
||||||
|
assert len(set(sizes)) == 1
|
||||||
|
indices = list(zip(*field_map.values()))
|
||||||
|
writer.output(
|
||||||
|
f"static BzTileID {func_name}(BzTileID tile) ")
|
||||||
|
writer.block_start()
|
||||||
|
|
||||||
|
writer.output("switch (tile) ")
|
||||||
|
writer.block_start()
|
||||||
|
|
||||||
|
for index in indices:
|
||||||
|
for idx in index:
|
||||||
|
writer.output(f"case {idx}:\n")
|
||||||
|
writer.indent()
|
||||||
|
writer.output(f"return {index[0]};\n")
|
||||||
|
writer.unindent()
|
||||||
|
writer.output("default: return tile;\n")
|
||||||
|
writer.block_end()
|
||||||
|
|
||||||
|
writer.block_end()
|
||||||
|
writer.empty_line()
|
||||||
|
|
||||||
|
def output_index_tile_offset(self, func_name, field, width, tile_width, tile_height):
|
||||||
|
writer = self.writer
|
||||||
|
tiles = self.filter_by_props(self.all_tiles, [field])
|
||||||
|
field_map = defaultdict(list)
|
||||||
|
for tile in tiles:
|
||||||
|
index = self.get_property(tile, field)['value']
|
||||||
|
field_map[index].append(tile['id'])
|
||||||
|
sizes = list(map(lambda x: len(x), field_map.values()))
|
||||||
|
assert len(set(sizes)) == 1
|
||||||
|
indices = list(zip(*field_map.values()))
|
||||||
|
writer.output(
|
||||||
|
f"static Vector2 {func_name}(BzTileID tile, i32 idx) ")
|
||||||
|
writer.block_start()
|
||||||
|
size = sizes[0]
|
||||||
|
writer.output(f"if (idx < 0 || idx >= {size}) return (Vector2) {{0, 0}};\n")
|
||||||
|
|
||||||
|
writer.output("switch (tile) ")
|
||||||
|
writer.block_start()
|
||||||
|
|
||||||
|
def calc_pos(tile):
|
||||||
|
return (tile % width) * tile_width, (tile // width) * tile_height
|
||||||
|
|
||||||
|
for index in indices:
|
||||||
|
base_idx = index[0]
|
||||||
|
base_pos = calc_pos(base_idx)
|
||||||
|
positions = [(0, 0)]
|
||||||
|
for idx in index[1:]:
|
||||||
|
pos = calc_pos(idx)
|
||||||
|
positions.append((pos[0] - base_pos[0], pos[1] - base_pos[1]))
|
||||||
|
str_positions = list(map(lambda x: f"{{{x[0]}, {x[1]}}}", positions))
|
||||||
|
ret = f"((Vector2 []) {{{', '.join(str_positions)}}})[idx]"
|
||||||
|
writer.output(f"case {base_idx}: return {ret};\n")
|
||||||
|
writer.output("default: return (Vector2) {0, 0};\n")
|
||||||
|
writer.block_end()
|
||||||
|
|
||||||
|
writer.block_end()
|
||||||
|
writer.empty_line()
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ def remove_properties(data, dst_file):
|
|||||||
|
|
||||||
|
|
||||||
content = open("../rawAssets/game.tsj").read()
|
content = open("../rawAssets/game.tsj").read()
|
||||||
tiles = json.loads(content)["tiles"]
|
all_tiles = json.loads(content)["tiles"]
|
||||||
remove_properties(content, "../assets/game.tsj")
|
remove_properties(content, "../assets/game.tsj")
|
||||||
terrain_tiles = extract_by_property(tiles, "terrain")
|
terrain_tiles = extract_by_property(all_tiles, "terrain")
|
||||||
building_tiles = extract_by_property(tiles, "building")
|
building_tiles = extract_by_property(all_tiles, "building")
|
||||||
entity_tiles = extract_by_property(tiles, "entity")
|
entity_tiles = extract_by_property(all_tiles, "entity")
|
||||||
item_tiles = extract_by_property(tiles, "item")
|
item_tiles = extract_by_property(all_tiles, "item")
|
||||||
|
|
||||||
writer.header_guard_start()
|
writer.header_guard_start()
|
||||||
script_name = os.path.basename(__file__)
|
script_name = os.path.basename(__file__)
|
||||||
@@ -88,6 +88,12 @@ item_writer.output_enum_to_tile("getItemTile")
|
|||||||
#item_writer.output_has_handle("itemHasHandle")
|
#item_writer.output_has_handle("itemHasHandle")
|
||||||
#item_writer.output_handle("itemGetHandle")
|
#item_writer.output_handle("itemGetHandle")
|
||||||
|
|
||||||
|
tile_writer = EnumWriter(writer, all_tiles, "", "")
|
||||||
|
|
||||||
|
tile_writer.output_get_text_rect("getTextureRect", 256, 16, 16)
|
||||||
|
tile_writer.output_base_index("getTileBase", "player")
|
||||||
|
tile_writer.output_index_tile_offset("getTileOffset", "player", 256, 16, 16)
|
||||||
|
|
||||||
|
|
||||||
writer.header_guard_stop()
|
writer.header_guard_stop()
|
||||||
|
|
||||||
|
|||||||