Added 'destroy_children' parameter to game_world_destroy_entity().
This commit is contained in:
@@ -91,21 +91,32 @@ bool game_world_create_entity(Game_World *world, Entity_Type type, uint16_t x, u
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_world_destroy_entity(Game_World *world, Entity_ID entity_id) {
|
void game_world_destroy_entity(Game_World *world, Entity_ID entity_id, bool destroy_children) {
|
||||||
assert(world != NULL);
|
assert(world != NULL);
|
||||||
|
assert(entity_id != INVALID_ENTITY_ID);
|
||||||
|
|
||||||
Entity *entity = game_world_try_get_entity_by_id(
|
Entity_ID id_to_remove = entity_id;
|
||||||
world,
|
|
||||||
entity_id
|
while(id_to_remove != INVALID_ENTITY_ID) {
|
||||||
);
|
Entity *e = game_world_try_get_entity_by_id(
|
||||||
assert(entity != NULL);
|
world,
|
||||||
memset(&entity, 0, sizeof(Entity));
|
id_to_remove
|
||||||
|
);
|
||||||
|
assert(e != NULL);
|
||||||
|
|
||||||
Grid_Cell *cell = grid_get_cell(&world->grid, entity->x, entity->y);
|
Grid_Cell *cell = grid_get_cell(&world->grid, e->x, e->y);
|
||||||
assert(cell != NULL);
|
assert(cell != NULL);
|
||||||
assert(grid_try_remove_entity_from_cell(cell));
|
assert(grid_try_remove_entity_from_cell(cell));
|
||||||
|
|
||||||
squeue_push(&world->entity_id_queue, (void *)&entity_id);
|
squeue_push(&world->entity_id_queue, (void *)&e->id);
|
||||||
|
|
||||||
|
id_to_remove = e->child;
|
||||||
|
memset(e, 0, sizeof(Entity));
|
||||||
|
|
||||||
|
if(!destroy_children) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity *game_world_try_get_entity_by_id(Game_World *world, Entity_ID id) {
|
Entity *game_world_try_get_entity_by_id(Game_World *world, Entity_ID id) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Game_World *game_world_create(uint32_t seed, uint16_t level_width, uint16_t leve
|
|||||||
void game_world_destroy(Game_World *world);
|
void game_world_destroy(Game_World *world);
|
||||||
|
|
||||||
bool game_world_create_entity(Game_World *world, Entity_Type type, uint16_t x, uint16_t y, Entity_ID *out_entity_id);
|
bool game_world_create_entity(Game_World *world, Entity_Type type, uint16_t x, uint16_t y, Entity_ID *out_entity_id);
|
||||||
void game_world_destroy_entity(Game_World *world, Entity_ID entity_id);
|
void game_world_destroy_entity(Game_World *world, Entity_ID entity_id, bool destroy_children);
|
||||||
|
|
||||||
// TODO: SS - "void game_world_spawn_player(Game_World *world, ..)"
|
// TODO: SS - "void game_world_spawn_player(Game_World *world, ..)"
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
|||||||
assert(player->active);
|
assert(player->active);
|
||||||
player->active = false;
|
player->active = false;
|
||||||
|
|
||||||
game_world_destroy_entity(simulation_world->game_world, player->entity_id);
|
game_world_destroy_entity(simulation_world->game_world, player->entity_id, true);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/todo.md
Normal file
18
src/todo.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# TODO
|
||||||
|
- Add player-death.
|
||||||
|
- [ ] Went out of bounds.
|
||||||
|
- [ ] Hit other snake's head.
|
||||||
|
- [ ] Hit yours/other snake's body.
|
||||||
|
- Spawn players at a random position.
|
||||||
|
- [ ] When initially joining.
|
||||||
|
- [ ] When dead and should respawn.
|
||||||
|
- Spawn food every N tick(?)
|
||||||
|
- [ ] Spawn food at a random position every N tick.
|
||||||
|
- Do we want a "max food on the board" value?
|
||||||
|
- Why?
|
||||||
|
- This can easily be implemented later.
|
||||||
|
- If we have that much food on the board, don't spawn new food.
|
||||||
|
- Otherwise, spawn new food at a random position.
|
||||||
|
- [ ] When a player disconnects, all children should recursively be destroyed too. Not just the head.
|
||||||
|
- [ ] Sound effects + music.
|
||||||
|
- [ ] Customize the session.
|
||||||
Reference in New Issue
Block a user