Implement farming
This commit is contained in:
@@ -88,17 +88,26 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
|
||||
region.rec.height *= sizeY;
|
||||
ecs_set_ptr(ECS, building, TextureRegion, ®ion);
|
||||
|
||||
bzTileMapSetCollisions(&game->map, true, COLL_LAYER_BUILDINGS, posX, posY, sizeX, sizeY);
|
||||
bool hasCollision = true;
|
||||
|
||||
switch (type) {
|
||||
case BUILDING_KEEP:
|
||||
ecs_set(ECS, building, AddPopCapacity, {10});
|
||||
ecs_add_id(ECS, building, Storage);
|
||||
break;
|
||||
case BUILDING_WHEAT_0:
|
||||
case BUILDING_WHEAT_1:
|
||||
hasCollision = false;
|
||||
ecs_add_id(ECS, building, Harvestable);
|
||||
ecs_set(ECS, building, Resource, {RES_FOOD, INFINITY});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasCollision)
|
||||
bzTileMapSetCollisions(&game->map, true, COLL_LAYER_BUILDINGS, posX, posY, sizeX, sizeY);
|
||||
|
||||
return building;
|
||||
|
||||
}
|
||||
@@ -166,12 +175,14 @@ Vector2 getPositionNearBuilding(ecs_entity_t building, Vector2 fromPos) {
|
||||
Vector2 pos = *ecs_get(ECS, building, Position);
|
||||
HitBox hitbox = *ecs_get(ECS, building, HitBox);
|
||||
|
||||
Vector2 center = entityGetCenter(pos, hitbox);
|
||||
|
||||
Vector2 size = {hitbox.width, hitbox.height};
|
||||
size = Vector2SubtractValue(size, 10.0f);
|
||||
|
||||
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, pos));
|
||||
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, center));
|
||||
dir = Vector2Multiply(dir, size);
|
||||
|
||||
pos = Vector2Add(pos, dir);
|
||||
return pos;
|
||||
center = Vector2Add(center, dir);
|
||||
return center;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user