Grid base
This commit is contained in:
parent
76284d80b9
commit
0432d6932c
11 changed files with 81 additions and 14 deletions
|
|
@ -21,6 +21,8 @@ void World::setup(){
|
|||
void World::process(){
|
||||
this->clock += GetFrameTime();
|
||||
|
||||
this->update_grid();
|
||||
|
||||
for(int i = 0; i < this->entities.size(); i++) {
|
||||
this->entities[i]->process();
|
||||
if (this->clock>=this->seconds_per_tick) {
|
||||
|
|
@ -33,12 +35,31 @@ void World::process(){
|
|||
}
|
||||
}
|
||||
|
||||
void World::draw() {
|
||||
void World::draw() const {
|
||||
for(int i = 0; i < this->entities.size(); i++) {
|
||||
this->entities[i]->draw();
|
||||
}
|
||||
}
|
||||
|
||||
int indexify_position(Vector2 vector){
|
||||
return (int)(vector.x / 16.0) + GRID_COLUMNS * (int)(vector.y / 16.0);
|
||||
}
|
||||
|
||||
void World::update_grid() {
|
||||
for(int i = 0; i < GRID_CAPACITY; i++)
|
||||
this->grid[i] = nullptr;
|
||||
|
||||
for(int i = 0; i < this->entities.size(); i++)
|
||||
{
|
||||
int indexified_position = indexify_position(this->entities[i]->position);
|
||||
if (indexified_position < 0 || indexified_position >= GRID_CAPACITY)
|
||||
continue;
|
||||
grid[indexified_position] = this->entities[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
World create_world_with(float seconds_per_tick){
|
||||
World result = World();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue