drop tree on car collision

isolation_bkp/dynres
Dominik Madarász 2022-09-14 13:12:12 +00:00 committed by GitHub
parent cd9a746a61
commit 8ca11b3ec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View File

@ -6,6 +6,7 @@ typedef enum {
BLOCK_FLAG_COLLISION = (1 << 1),
BLOCK_FLAG_HAZARD = (1 << 2),
BLOCK_FLAG_ESSENTIAL = (1 << 3),
BLOCK_FLAG_DESTROY_ON_COLLISION = (1 << 4),
} block_flags;
typedef uint16_t block_id;

View File

@ -16,7 +16,7 @@ static block blocks[] = {
BLOCK(ASSET_LAVA, BLOCK_FLAG_HAZARD, '!', .drag = 6.2f , .friction = 4.0f),
BLOCK(ASSET_FENCE, BLOCK_FLAG_COLLISION, '#', .drag = 1.0f , .friction = 1.0f, .bounce = 1.0f),
BLOCK(ASSET_WOOD, BLOCK_FLAG_COLLISION, '#', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f),
BLOCK(ASSET_TREE, BLOCK_FLAG_COLLISION, '@', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f),
BLOCK(ASSET_TREE, BLOCK_FLAG_COLLISION|BLOCK_FLAG_DESTROY_ON_COLLISION, '@', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f),
BLOCK(ASSET_BELT_LEFT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = -150.0f),
BLOCK(ASSET_BELT_RIGHT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = 150.0f),

View File

@ -508,6 +508,7 @@ void world_chunk_destroy_block(float x, float y, bool drop_item) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = x;
dest->y = y;
entity_set_position(e, dest->x, dest->y);
}
}

View File

@ -143,11 +143,18 @@ void VehicleHandling(ecs_iter_t *it) {
v[i].y += ((fr_y + bk_y) / 2.0f - p[i].y);
car->heading = zpl_arctan2(fr_y - bk_y, fr_x - bk_x);
world_block_lookup lookahead = world_block_from_realpos(p[i].x+PHY_LOOKAHEAD(v[i].x), p[i].y+PHY_LOOKAHEAD(v[i].y));
float check_x = p[i].x+PHY_LOOKAHEAD(v[i].x);
float check_y = p[i].y+PHY_LOOKAHEAD(v[i].y);
world_block_lookup lookahead = world_block_from_realpos(check_x, check_y);
uint32_t flags = blocks_get_flags(lookahead.bid);
if (flags & BLOCK_FLAG_COLLISION) {
if (flags & BLOCK_FLAG_DESTROY_ON_COLLISION) {
world_chunk_destroy_block(check_x, check_y, true);
car->force *= 0.8f;
} else {
car->force = 0.0f;
}
}
for (int j = 0; j < 4; j++) {
if (!world_entity_valid(veh[i].seats[j])) continue;