diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-10-09 22:51:50 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-10-09 22:51:50 +0200 |
commit | ff4929c650e6ed446b6faff9f6b0f078d0a3644c (patch) | |
tree | 932671a8f9e06d0add2fb2ae9c0f542bd3980304 /src/world.cpp | |
parent | 8d6cb03cd83b9f6576909058601af54f16c8acfe (diff) |
Initial work on entities.
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/world.cpp b/src/world.cpp index dc25f66..9d9b97d 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -83,9 +83,30 @@ tile_t *world_t::get_tile(ssize_t x, ssize_t y) return sector->tiles + ty * SECTOR_SIZE + tx; } +static sector_index_t get_index(float x, float y) +{ + return sector_index_t(floor(x), floor(y)); +} + +void entity_t::link_to_sector(sector_t *sector) +{ + parents.push_back(sector); + sector->ents.insert(this); +} + void entity_t::link(world_t *world) { - // TODO + sector_index_t base; + sector_t *sector; + ssize_t dx, dy; + + // An entity gets linked to at least one sector. + base = get_index(bounds.left, bounds.top); + sector = world->get_sector(base); + link_to_sector(sector); + + // There might be more, though. + //for (dy = 0; dy < } void entity_t::unlink(void) |