drop tree on car collision
parent
cd9a746a61
commit
8ca11b3ec7
|
@ -6,6 +6,7 @@ typedef enum {
|
||||||
BLOCK_FLAG_COLLISION = (1 << 1),
|
BLOCK_FLAG_COLLISION = (1 << 1),
|
||||||
BLOCK_FLAG_HAZARD = (1 << 2),
|
BLOCK_FLAG_HAZARD = (1 << 2),
|
||||||
BLOCK_FLAG_ESSENTIAL = (1 << 3),
|
BLOCK_FLAG_ESSENTIAL = (1 << 3),
|
||||||
|
BLOCK_FLAG_DESTROY_ON_COLLISION = (1 << 4),
|
||||||
} block_flags;
|
} block_flags;
|
||||||
|
|
||||||
typedef uint16_t block_id;
|
typedef uint16_t block_id;
|
||||||
|
@ -29,4 +30,4 @@ void *blocks_get_img(block_id id);
|
||||||
|
|
||||||
void blocks_build_chunk_tex(uint64_t id, block_id *blocks, void *view);
|
void blocks_build_chunk_tex(uint64_t id, block_id *blocks, void *view);
|
||||||
void *blocks_get_chunk_tex(uint64_t id);
|
void *blocks_get_chunk_tex(uint64_t id);
|
||||||
void blocks_remove_chunk_tex(uint64_t id);
|
void blocks_remove_chunk_tex(uint64_t id);
|
||||||
|
|
|
@ -16,12 +16,12 @@ static block blocks[] = {
|
||||||
BLOCK(ASSET_LAVA, BLOCK_FLAG_HAZARD, '!', .drag = 6.2f , .friction = 4.0f),
|
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_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_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_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),
|
BLOCK(ASSET_BELT_RIGHT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = 150.0f),
|
||||||
BLOCK(ASSET_BELT_UP, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = -150.0f),
|
BLOCK(ASSET_BELT_UP, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = -150.0f),
|
||||||
BLOCK(ASSET_BELT_DOWN, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = 150.0f),
|
BLOCK(ASSET_BELT_DOWN, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = 150.0f),
|
||||||
};
|
};
|
||||||
|
|
||||||
ZPL_STATIC_ASSERT(sizeof(blocks)/sizeof(block) < ZPL_U16_MAX, "too many registered blocks! (max. 65536)");
|
ZPL_STATIC_ASSERT(sizeof(blocks)/sizeof(block) < ZPL_U16_MAX, "too many registered blocks! (max. 65536)");
|
||||||
|
|
|
@ -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);
|
Position *dest = ecs_get_mut(world_ecs(), e, Position);
|
||||||
dest->x = x;
|
dest->x = x;
|
||||||
dest->y = y;
|
dest->y = y;
|
||||||
|
entity_set_position(e, dest->x, dest->y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,10 +143,17 @@ void VehicleHandling(ecs_iter_t *it) {
|
||||||
v[i].y += ((fr_y + bk_y) / 2.0f - p[i].y);
|
v[i].y += ((fr_y + bk_y) / 2.0f - p[i].y);
|
||||||
car->heading = zpl_arctan2(fr_y - bk_y, fr_x - bk_x);
|
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);
|
uint32_t flags = blocks_get_flags(lookahead.bid);
|
||||||
if (flags & BLOCK_FLAG_COLLISION) {
|
if (flags & BLOCK_FLAG_COLLISION) {
|
||||||
car->force = 0.0f;
|
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++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
|
|
Loading…
Reference in New Issue