Add hitboxes

This commit is contained in:
2024-01-28 11:00:32 +01:00
parent 0a4c1fd154
commit a61768e912
15 changed files with 494 additions and 200 deletions

File diff suppressed because one or more lines are too long

View File

@@ -28,7 +28,7 @@ bool canPlaceBuilding(Game *game, BuildingType type, BzTile tileX, BzTile tileY)
BzSpatialGridIter it = bzSpatialGridIter(game->entityGrid, buildArea.x, buildArea.y, buildArea.width, buildArea.height);
while (bzSpatialGridQueryNext(&it)) { ecs_entity_t entity = *(ecs_entity_t *) it.data;
Rectangle bounds;
if (!getEntityBounds(entity, NULL, NULL, &bounds)) continue;
if (!getEntityHitBox(entity, NULL, &bounds)) continue;
if (CheckCollisionRecs(buildArea, bounds))
return false;
@@ -55,21 +55,26 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
.size = (Vec2i) { sizeX, sizeY }
});
Position pos = {
.x = posX * tileWidth + sizeX * tileWidth * 0.5f,
.y = posY * tileHeight + sizeY * tileHeight * 0.5f
.x = posX * tileWidth,
.y = posY * tileHeight
};
Size size = {
.x = sizeX * tileWidth,
.y = sizeY * tileHeight
.y = sizeY * tileHeight,
};
HitBox hitbox = {
.x = 0.0f, .y = 0.0f,
.width = size.x,
.height = size.y
};
ecs_set_ptr(ECS, building, Position, &pos);
ecs_set_ptr(ECS, building, Size, &size);
ecs_set_ptr(ECS, building, HitBox, &hitbox);
ecs_set(ECS, building, Rotation, {0});
SpatialGridID gridID = bzSpatialGridInsert(game->entityGrid, &building,
pos.x - size.x * 0.5f, pos.y - size.y * 0.5f,
size.x, size.y);
pos.x, pos.y, hitbox.width, hitbox.height);
ecs_set_ptr(ECS, building, SpatialGridID, &gridID);
ecs_set(ECS, building, Owner, {player});
BzTileset *tileset = &game->tileset;
@@ -154,11 +159,12 @@ bool canAffordBuilding(BuildingType type, PlayerResources res) {
Vector2 getPositionNearBuilding(ecs_entity_t building, Vector2 fromPos) {
BZ_ASSERT(ecs_is_alive(ECS, building));
BZ_ASSERT(ecs_has(ECS, building, Position));
BZ_ASSERT(ecs_has(ECS, building, Size));
BZ_ASSERT(ecs_has(ECS, building, HitBox));
Vector2 pos = *ecs_get(ECS, building, Position);
Vector2 size = *ecs_get(ECS, building, Size);
HitBox hitbox = *ecs_get(ECS, building, HitBox);
Vector2 size = {hitbox.width, hitbox.height};
size = Vector2SubtractValue(size, 10.0f);
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, pos));

View File

@@ -23,6 +23,7 @@ ECS_COMPONENT_DECLARE(TextureRegion);
ECS_COMPONENT_DECLARE(Animation);
ECS_COMPONENT_DECLARE(Easing);
ECS_COMPONENT_DECLARE(HitBox);
ECS_COMPONENT_DECLARE(Arms);
ECS_COMPONENT_DECLARE(Arm);
ECS_COMPONENT_DECLARE(BzBTState);
@@ -64,6 +65,7 @@ void initComponentIDs(ecs_world_t *ecs) {
ECS_COMPONENT_DEFINE(ecs, Animation);
ECS_COMPONENT_DEFINE(ecs, Easing);
ECS_COMPONENT_DEFINE(ecs, HitBox);
ECS_COMPONENT_DEFINE(ecs, Arms);
ECS_COMPONENT_DEFINE(ecs, Arm);
ECS_COMPONENT_DEFINE(ecs, BzBTState);

View File

@@ -136,6 +136,9 @@ extern ECS_COMPONENT_DECLARE(Easing);
* Gameplay components
*********************************************************/
typedef Rectangle HitBox;
extern ECS_COMPONENT_DECLARE(HitBox);
typedef struct WeaponMelee {
ecs_entity_t weapon;
f32 reach;

View File

@@ -11,17 +11,18 @@ ecs_entity_t entityCreateEmpty() {
ecs_entity_t entityCreateBaseUnit(const Position position, Player player,
EntityType type, AnimType startAnim, Game *game) {
BzTileset *tileset = &game->tileset;
BzTileID tileID = getEntityTile(type);
TextureRegion region = {
tileset->tiles,
getTextureRect(getEntityTile(type))
getTextureRect(tileID)
};
const Size size = {10.0f * region.rec.width / 16.0f, 10.0f * region.rec.height / 16.0f};
HitBox hitbox = getEntityHitBoxRec(tileID);
ecs_entity_t e = entityCreateEmpty();
ecs_set_ptr(ECS, e, Position, &position);
ecs_set_ptr(ECS, e, Size, &size);
//ecs_set_ptr(ECS, e, HitBox, &hitbox);
BzSpatialGridID spatialID = bzSpatialGridInsert(game->entityGrid, &e,
position.x - size.x * 0.5f, position.y - size.y * 0.5f,
size.x, size.y);
position.x + hitbox.x, position.y + hitbox.y,
hitbox.width, hitbox.height);
ecs_set(ECS, e, SpatialGridID, { spatialID });
ecs_set(ECS, e, Rotation, { 0.0f });
ecs_set(ECS, e, Orientation, {0.0f});
@@ -78,7 +79,6 @@ ecs_entity_t entityCreateWorker(const Position position, Player player, Game *ga
ecs_set_ptr(ECS, e, Arms, &arms);
ecs_set(ECS, right, Arm, {.offset = 45.0f, 4.5f});
ecs_set(ECS, right, Size, {8, 8});
ecs_set(ECS, right, Rotation, { 0.0f });
TextureRegion daggerRegion = {
tileset->tiles,

View File

@@ -1686,7 +1686,56 @@ static Vector2 getItemHandlePoint(BzTile tile) {
case 8199: return (Vector2) {5, 11};
case 8200: return (Vector2) {4, 12};
case 8201: return (Vector2) {4, 12};
default: return (Vector2) {0, 0};
default: return (Vector2) {0.0f, 0.0f};
}
}
static bool hasEntityHitBoxRec(BzTile tile) {
switch (tile) {
case 27:
case 539:
case 1051:
case 1563:
case 2075:
case 2587:
case 5888:
case 5889:
case 5890:
case 5891:
case 6146:
case 6147:
case 6402:
case 6403:
case 6656:
case 6912:
case 7170:
case 7171:
case 7172:
return true;
default: return false;
}
}
static Rectangle getEntityHitBoxRec(BzTile tile) {
switch (tile) {
case 27: return (Rectangle) {4, 2, 8, 12};
case 539: return (Rectangle) {4, 0, 8, 14};
case 1051: return (Rectangle) {4, 0, 8, 14};
case 1563: return (Rectangle) {4, 0, 8, 14};
case 2075: return (Rectangle) {4, 1, 8, 13};
case 2587: return (Rectangle) {4, 3, 8, 11};
case 5888: return (Rectangle) {4, 4, 8, 9};
case 5889: return (Rectangle) {3, 7, 10, 7};
case 5890: return (Rectangle) {6, 4, 4, 10};
case 5891: return (Rectangle) {6, 4, 4, 10};
case 6146: return (Rectangle) {6, 4, 4, 10};
case 6147: return (Rectangle) {6, 4, 4, 10};
case 6402: return (Rectangle) {6, 4, 4, 10};
case 6403: return (Rectangle) {6, 4, 4, 10};
case 6656: return (Rectangle) {6, 4, 4, 10};
case 6912: return (Rectangle) {6, 4, 4, 10};
case 7170: return (Rectangle) {3, 3, 10, 10};
case 7171: return (Rectangle) {3, 4, 10, 9};
case 7172: return (Rectangle) {1, 3, 14, 10};
default: return (Rectangle) { 0.0f, 0.0f, 0.0f, 0.0f};
}
}
#endif // GAME_TILESET_H

View File

@@ -128,7 +128,7 @@ bool init(void *userData) {
input->queries.selected = ecs_query(ECS, {
.filter.terms = {
{ecs_id(Position)},
{ecs_id(Size)},
{ecs_id(HitBox)},
{ecs_id(Selected)}
}
});
@@ -386,17 +386,14 @@ static void renderGame(Game *game, float dt) {
Rotation *r = ecs_field(&it, Rotation, 3);
TextureRegion *t = ecs_field(&it, TextureRegion, 4);
for (i32 i = 0; i < it.count; i++) {
Rectangle dst = {p[i].x, p[i].y, s[i].x, s[i].y};
Vector2 origin = {dst.width * 0.5f, dst.height};
dst.x += origin.x - dst.width * 0.5f;
dst.y += origin.y - dst.height * 0.5f;
Rectangle collider = {
p[i].x - s[i].x * 0.5f,
p[i].y - s[i].y * 0.5f,
.width = s[i].x,
.height = s[i].y
};
if (!CheckCollisionRecs(camBounds, collider))
f32 sclX = s[i].x / t[i].rec.width;
f32 sclY = s[i].y / t[i].rec.height;
Rectangle dst = {p[i].x, p[i].y,
t[i].rec.width * sclX, t[i].rec.height * sclY};
Vector2 origin = {0.0f, 0.0f};
//dst.x += origin.x - dst.width * 0.5f;
//dst.y += origin.y - dst.height * 0.5f;
if (!CheckCollisionRecs(camBounds, dst))
continue;
Rectangle src = t[i].rec;
// Fixes texture bleeding issue
@@ -432,7 +429,7 @@ static void renderGame(Game *game, float dt) {
DrawData draw = drawData[i];
Vector2 pos = {
draw.dst.x,
draw.dst.y - draw.dst.height * 0.5f,
draw.dst.y,
};
Color c = WHITE;
if (draw.canHaveAlpha) {
@@ -572,7 +569,7 @@ void igInspectWindow(ecs_entity_t entity, bool *open) {
igInspectComp("Owner", entity, ecs_id(Owner), igOwner);
igInspectComp("SpatialGridID", entity, ecs_id(SpatialGridID), igSpatialGridID);
igInspectComp("Position", entity, ecs_id(Position), igVec2Comp);
igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
//igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
igInspectComp("Velocity", entity, ecs_id(Velocity), igVec2Comp);
igInspectComp("TargetPosition", entity, ecs_id(TargetPosition), igVec2Comp);
igInspectComp("Steering", entity, ecs_id(Steering), igVec2Comp);

View File

@@ -130,7 +130,7 @@ bool initRocksLayer(BzTileMap *map, BzTileLayer *layer) {
posX += sizeX * 0.5f;
posY += sizeY * 0.5f;
ecs_set(ECS, e, Position, {posX, posY});
ecs_set(ECS, e, Size, {sizeX, sizeY});
ecs_set(ECS, e, HitBox, {sizeX, sizeY});
ecs_set(ECS, e, Rotation, {0});
BzTile tileID = bzTilesetGetTileID(tileset, layerTile);
ecs_set(ECS, e, TextureRegion, {tileset->tiles, bzTilesetGetTileRegion(tileset, tileID)});
@@ -155,20 +155,24 @@ bool initTreesLayer(BzTileMap *map, BzTileLayer *layer) {
tile = bzTilesetGetTileID(tileset, tile);
if (tile == -1) continue; // Not a tree
BzTile tileID = bzTilesetGetTileID(tileset, layerTile);
BZ_ASSERT(hasEntityHitBoxRec(tileID));
HitBox hb = getEntityHitBoxRec(tileID);
f32 sizeX = tileset->tileWidth;
f32 sizeY = tileset->tileHeight;
f32 posX = layer->offsetX + x * sizeX;
f32 posY = layer->offsetY + y * sizeY;
ecs_entity_t e = entityCreateEmpty();
SpatialGridID gridID = bzSpatialGridInsert(game->entityGrid, &e, posX, posY, sizeX, sizeY);
SpatialGridID gridID = bzSpatialGridInsert(game->entityGrid, &e,
posX + hb.x, posY + hb.y,
hb.width, hb.height);
ecs_set(ECS, e, SpatialGridID, {gridID});
posX += sizeX * 0.5f;
posY += sizeY * 0.5f;
ecs_set(ECS, e, Position, {posX, posY});
ecs_set(ECS, e, Size, {sizeX, sizeY});
ecs_set_ptr(ECS, e, HitBox, &hb);
ecs_set(ECS, e, Rotation, {0});
BzTile tileID = bzTilesetGetTileID(tileset, layerTile);
ecs_set(ECS, e, TextureRegion, {tileset->tiles, bzTilesetGetTileRegion(tileset, tileID)});
ecs_set(ECS, e, TextureRegion, {tileset->tiles, getTextureRect(tileID)});
ecs_set(ECS, e, Resource, {RES_WOOD, 20});
ecs_add_id(ECS, e, Selectable);
ecs_add_id(ECS, e, Harvestable);

View File

@@ -31,12 +31,6 @@ bool entitySetPath(const ecs_entity_t entity, const Vector2 target, Game *game)
}
static Position getBottomLeftPos(Position pos, Size size) {
return (Position) {pos.x - size.x * 0.5f, pos.y - size.y * 0.5f};
}
void entityPathRemove(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
for (i32 i = 0; i < it->count; i++) {
@@ -101,13 +95,18 @@ void entityUnConsumePopCapacity(ecs_iter_t *it) {
void entityUpdateSpatialID(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
Position *position = ecs_field(it, Position, 1);
Position *size = ecs_field(it, Size, 2);
//Velocity *velocity = ecs_field(it, Velocity, 3);
HitBox *hitbox = ecs_field(it, HitBox, 2);
Velocity *velocity = ecs_field(it, Velocity, 3);
SpatialGridID *id = ecs_field(it, SpatialGridID, 4);
BZ_UNUSED(velocity);
for (i32 i = 0; i < it->count; i++) {
Position pos = getBottomLeftPos(position[i], size[i]);
bzSpatialGridUpdate(game->entityGrid, id[i], pos.x, pos.y, size[i].x, size[i].y);
Rectangle rec = {
position[i].x + hitbox[i].x,
position[i].y + hitbox[i].y,
hitbox[i].width, hitbox[i].height
};
bzSpatialGridUpdate(game->entityGrid, id[i], rec.x, rec.y, rec.width, rec.height);
}
}
@@ -225,12 +224,13 @@ void entityUpdateArms(ecs_iter_t *it) {
void renderColliders(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1);
Size *size = ecs_field(it, Size, 2);
HitBox *hitbox = ecs_field(it, HitBox , 2);
for (i32 i = 0; i < it->count; i++) {
f32 posX = pos[i].x - size[i].x * 0.5f;
f32 posY = pos[i].y - size[i].y * 0.5f;
DrawRectangleLines(posX, posY, size[i].x, size[i].y, RED);
HitBox hb = hitbox[i];
hb.x += pos[i].x;
hb.y += pos[i].y;
DrawRectangleLinesEx(hb, 1.0f, RED);
}
}

View File

@@ -16,8 +16,8 @@ void selectUnits(BzSpatialGrid *entityGrid, Rectangle area, Player player);
void addEntityToInspected(ecs_entity_t entity, Game *game);
static void iterateSelectedUnits(ecs_query_t *query, void (*fn)(ecs_entity_t entity, Position *pos, Size *size));
static void iterRemovePaths(ecs_entity_t entity, Position *pos, Size *size);
static void iterateSelectedUnits(ecs_query_t *query, void (*fn)(ecs_entity_t entity, Position *pos));
static void iterRemovePaths(ecs_entity_t entity, Position *pos);
void placeUnits(i32 numUnits, f32 unitSpacing, Vector2 start, Vector2 end, BzTileMap *map, Vector2 **outPlaces);
@@ -305,23 +305,27 @@ void drawPlayerInputUIGround() {
rlSetLineWidth(2.0f);
while (ecs_query_next(&it)) {
Position *pos = ecs_field(&it, Position, 1);
Size *size = ecs_field(&it, Size, 2);
HitBox *hitbox = ecs_field(&it, HitBox , 2);
for (i32 i = 0; i < it.count; i++) {
ecs_entity_t entity = it.entities[i];
f32 radius = BZ_MIN(size[i].x, size[i].y);
radius *= 0.5f;
f32 radius = BZ_MAX(hitbox[i].width, hitbox[i].height);
radius *= 0.8f;
const f32 lineThickness = 1.0f;
if (ecs_has(ECS, entity, Building)) {
const f32 padding = 2.0f;
Rectangle bounds = {
pos[i].x - size[i].x * 0.5f - padding,
pos[i].y - size[i].y * 0.5f - padding,
size[i].x + padding * 2,
size[i].y + padding * 2,
pos[i].x + hitbox[i].x - padding,
pos[i].y - hitbox[i].y - padding,
hitbox[i].width + padding * 2,
hitbox[i].height + padding * 2,
};
DrawRectangleLinesEx(bounds, lineThickness, GREEN);
} else {
DrawRing(pos[i], radius, radius + lineThickness, 0, 360, 12, GREEN);
Position center = {
pos[i].x + hitbox[i].x + hitbox[i].width * 0.5f,
pos[i].y + hitbox[i].y + hitbox[i].height * 0.5f,
};
DrawRing(center, radius, radius + lineThickness, 0, 360, 12, GREEN);
}
}
}
@@ -367,10 +371,10 @@ ecs_entity_t queryEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t
if (!ecs_has_id(ECS, entity, Selectable)) continue;
if (!ecs_has_id(ECS, entity, tag)) continue;
Vector2 pos;
Rectangle bounds;
if (!getEntityBounds(entity, &pos, NULL, &bounds)) continue;
Rectangle hitbox;
if (!getEntityHitBox(entity, &pos, &hitbox)) continue;
if (!CheckCollisionPointRec(point, bounds)) continue;
if (!CheckCollisionPointRec(point, hitbox)) continue;
f32 curDst = Vector2Distance(point, pos);
if (closestDst > curDst) {
@@ -405,10 +409,10 @@ void selectUnits(BzSpatialGrid *entityGrid, Rectangle area, Player player) {
if (owner.player != player) continue;
}
if (!ecs_has_id(ECS, entity, ecs_id(Unit))) continue;
Rectangle bounds;
if (!getEntityBounds(entity, NULL, NULL, &bounds)) continue;
Rectangle hitbox;
if (!getEntityHitBox(entity, NULL, &hitbox)) continue;
if (!CheckCollisionRecs(area, bounds)) continue;
if (!CheckCollisionRecs(area, hitbox)) continue;
ecs_add(ECS, entity, Selected);
}
}
@@ -463,20 +467,19 @@ void placeUnits(i32 numUnits, f32 unitSpacing, Vector2 start, Vector2 end, BzTil
}
}
static void iterateSelectedUnits(ecs_query_t *query, void (*fn)(ecs_entity_t entity, Position *pos, Size *size)) {
static void iterateSelectedUnits(ecs_query_t *query, void (*fn)(ecs_entity_t entity, Position *pos)) {
ecs_iter_t it = ecs_query_iter(ECS, query);
while (ecs_iter_next(&it)) {
Position *pos = ecs_field(&it, Position, 1);
Size *size = ecs_field(&it, Size, 2);
for (i32 i = 0; i < it.count; i++) {
ecs_entity_t entity = it.entities[i];
fn(entity, pos + i, size + i);
fn(entity, pos + i);
}
}
}
static void iterRemovePaths(ecs_entity_t entity, Position *pos, Size *size) {
static void iterRemovePaths(ecs_entity_t entity, Position *pos) {
ecs_remove(ECS, entity, Path);
}

View File

@@ -2,37 +2,25 @@
#include "../game_state.h"
Rectangle calculateEntityBounds(Position pos, Size size) {
return (Rectangle) {
pos.x - size.x * 0.5f,
pos.y - size.x * 0.5f,
size.x, size.y
};
}
bool getEntityBounds(ecs_entity_t entity, Position *outPos, Size *outSize, Rectangle *outBounds) {
bool getEntityHitBox(ecs_entity_t entity, Position *outPos, Rectangle *outHitBox) {
if (!ecs_is_alive(ECS, entity))
return false;
const Position *pos = ecs_get(ECS, entity, Position);
if (!pos)
return false;
const Size *size = ecs_get(ECS, entity, Size);
if (!size)
return false;
if (outPos) {
if (outPos)
*outPos = *pos;
const HitBox *hitbox = ecs_get(ECS, entity, HitBox);
if (!hitbox)
return false;
if (outHitBox) {
*outHitBox = *hitbox;
outHitBox->x += pos->x;
outHitBox->y += pos->y;
}
if (outSize) {
*outSize = *size;
}
if (outBounds) {
*outBounds = (Rectangle) {
pos->x - size->x * 0.5f,
pos->y - size->y * 0.5f,
size->x, size->y
};
}
return true;
}
@@ -115,7 +103,7 @@ void setupSystems() {
ECS_OBSERVER(ECS, entityConsumePopCapacity, EcsOnSet, ConsumePopCapacity, Owner);
ECS_OBSERVER(ECS, entityUnConsumePopCapacity, EcsOnRemove, ConsumePopCapacity, Owner);
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, Size, Velocity, SpatialGridID);
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, HitBox, Velocity, SpatialGridID);
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Velocity, TargetPosition, Steering);
@@ -126,11 +114,11 @@ void setupSystems() {
ECS_SYSTEM(ECS, updateAnimationState, EcsOnUpdate, Animation, TextureRegion);
ECS_SYSTEM(ECS, updateAnimation, EcsOnUpdate, Animation, TextureRegion);
ECS_SYSTEM(ECS, updateEasingSystem, EcsOnUpdate, Easing, Position, Size, Rotation);
ECS_SYSTEM(ECS, updateEasingSystem, EcsOnUpdate, Easing, Position, HitBox, Rotation);
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, Size);
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, HitBox);
ECS_SYSTEM(ECS, renderOrientationDirection, EcsOnUpdate, Position, Orientation);
ECS_SYSTEM(ECS, renderArmPosition, EcsOnUpdate, Position, Arm);

View File

@@ -91,7 +91,7 @@ void entityUnConsumePopCapacity(ecs_iter_t *it);
/*
* 0: Game (singleton) for entity map
* 1: Position
* 2: Size
* 2: HitBox
* 3: Velocity (only entities with velocity change position)
* 4: SpatialGridID
*/
@@ -132,7 +132,7 @@ void entityUpdateArms(ecs_iter_t *it);
/*
* 1: Position
* 2: Size
* 2: HitBox
*/
void renderColliders(ecs_iter_t *it);
@@ -199,8 +199,7 @@ void drawSettingsUI(Game *game, f32 dt);
* Utils
**********************************/
Rectangle calculateEntityBounds(Position pos, Size size);
bool getEntityBounds(ecs_entity_t entity, Position *outPos, Size *outSize, Rectangle *outBounds);
bool getEntityHitBox(ecs_entity_t entity, Position *outPos, Rectangle *outHitBox);
/**********************************
* MISC

View File

@@ -227,6 +227,29 @@
"tileid":28
}],
"id":27,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":12,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":2
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"animation",
@@ -997,6 +1020,29 @@
"tileid":540
}],
"id":539,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":14,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"animation",
@@ -1639,6 +1685,29 @@
"tileid":1052
}],
"id":1051,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":14,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"animation",
@@ -2353,6 +2422,29 @@
"tileid":1564
}],
"id":1563,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":14,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"animation",
@@ -5053,6 +5145,29 @@
"tileid":2076
}],
"id":2075,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":13,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":1
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"animation",
@@ -6243,6 +6358,29 @@
"tileid":2588
}],
"id":2587,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":11,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":3
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"animation",
@@ -6845,16 +6983,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":11,
"id":1,
"name":"",
"height":9,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":10,
"x":3,
"y":3
"width":8,
"x":4,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -6871,6 +7008,29 @@
},
{
"id":5889,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":7,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":10,
"x":3,
"y":7
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"terrain",
@@ -6887,16 +7047,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -6920,16 +7079,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -7378,16 +7536,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -7411,16 +7568,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -7728,16 +7884,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -7761,16 +7916,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -8189,16 +8343,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -8490,16 +8643,15 @@
"name":"",
"objects":[
{
"ellipse":true,
"height":8,
"id":1,
"name":"",
"height":10,
"id":2,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":6
"width":4,
"x":6,
"y":4
}],
"opacity":1,
"type":"objectgroup",
@@ -8808,6 +8960,29 @@
},
{
"id":7170,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":10,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":10,
"x":3,
"y":3
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"terrain",
@@ -8818,6 +8993,29 @@
},
{
"id":7171,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":9,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":10,
"x":3,
"y":4
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"terrain",
@@ -8828,6 +9026,29 @@
},
{
"id":7172,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":10,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":14,
"x":1,
"y":3
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"terrain",

View File

@@ -125,6 +125,9 @@
<property name="entity" value=""/>
<property name="player" type="int" value="0"/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="2" width="8" height="12"/>
</objectgroup>
<animation>
<frame tileid="27" duration="200"/>
<frame tileid="28" duration="200"/>
@@ -512,6 +515,9 @@
<property name="player" type="int" value="0"/>
<property name="size_y" type="int" value="2"/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="0" width="8" height="14"/>
</objectgroup>
<animation>
<frame tileid="539" duration="200"/>
<frame tileid="540" duration="200"/>
@@ -789,6 +795,9 @@
<property name="player" type="int" value="0"/>
<property name="size_y" type="int" value="2"/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="0" width="8" height="14"/>
</objectgroup>
<animation>
<frame tileid="1051" duration="200"/>
<frame tileid="1052" duration="200"/>
@@ -1106,6 +1115,9 @@
<property name="player" type="int" value="0"/>
<property name="size_y" type="int" value="2"/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="0" width="8" height="14"/>
</objectgroup>
<animation>
<frame tileid="1563" duration="200"/>
<frame tileid="1564" duration="200"/>
@@ -1935,6 +1947,9 @@
<property name="entity" value=""/>
<property name="size_y" type="int" value="2"/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="1" width="8" height="13"/>
</objectgroup>
<animation>
<frame tileid="2075" duration="200"/>
<frame tileid="2076" duration="200"/>
@@ -2306,6 +2321,9 @@
<property name="entity" value=""/>
<property name="size_y" type="int" value="2"/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="3" width="8" height="11"/>
</objectgroup>
<animation>
<frame tileid="2587" duration="200"/>
<frame tileid="2588" duration="200"/>
@@ -2559,24 +2577,23 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="3" y="3" width="10" height="11">
<ellipse/>
</object>
<object id="2" name="hitbox" x="4" y="4" width="8" height="9"/>
</objectgroup>
</tile>
<tile id="5889">
<properties>
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="3" y="7" width="10" height="7"/>
</objectgroup>
</tile>
<tile id="5890">
<properties>
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="5891">
@@ -2584,9 +2601,7 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="5892">
@@ -2765,9 +2780,7 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="6147">
@@ -2775,9 +2788,7 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="6148">
@@ -2896,9 +2907,7 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="6403">
@@ -2906,9 +2915,7 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="6404">
@@ -3071,9 +3078,7 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="6657">
@@ -3197,9 +3202,7 @@
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" x="4" y="6" width="8" height="8">
<ellipse/>
</object>
<object id="2" name="hitbox" x="6" y="4" width="4" height="10"/>
</objectgroup>
</tile>
<tile id="6913">
@@ -3331,16 +3334,25 @@
<properties>
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="3" y="3" width="10" height="10"/>
</objectgroup>
</tile>
<tile id="7171" type="gold_ore">
<properties>
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="3" y="4" width="10" height="9"/>
</objectgroup>
</tile>
<tile id="7172" type="gold_ore">
<properties>
<property name="terrain" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="1" y="3" width="14" height="10"/>
</objectgroup>
</tile>
<tile id="7173">
<properties>

View File

@@ -96,13 +96,23 @@ item_writer.output_enum_to_tile("getItemTile")
tile_writer = EnumWriter(writer, all_tiles, "", "")
tile_writer.output_get_text_rect("getTextureRect", 256, 16, 16)
TILE_WIDTH = 16
TILE_HEIGHT = 16
tile_writer.output_get_text_rect("getTextureRect", 256, TILE_WIDTH, TILE_HEIGHT)
tile_writer.output_base_index("getTileBase", "player")
tile_writer.output_index_tile_offset("getTileOffset", "player", 256, 16, 16)
tile_writer.output_index_tile_offset("getTileOffset", "player", 256, TILE_WIDTH, TILE_HEIGHT)
vec2_transform = ["Vector2", "(Vector2) {0.0f, 0.0f}",
lambda x: f"(Vector2) {{{x['x']}, {x['y']}}}"]
rec_transform = ["Rectangle", "(Rectangle) { 0.0f, 0.0f, 0.0f, 0.0f}",
lambda x: f"(Rectangle) {{{x['x']}, {x['y']}, {x['width']}, {x['height']}}}"]
tile_writer.output_has_object("hasItemHandlePoint", "handle")
tile_writer.output_get_object("getItemHandlePoint", "handle", "Vector2", "(Vector2) {0, 0}", lambda x: f"(Vector2) {{{x['x']}, {x['y']}}}")
tile_writer.output_get_object("getItemHandlePoint", "handle", *vec2_transform)
tile_writer.output_has_object("hasEntityHitBoxRec", "hitbox")
tile_writer.output_get_object("getEntityHitBoxRec", "hitbox", *rec_transform)
writer.header_guard_stop()