segf
This commit is contained in:
parent
efcbf48299
commit
63e458ca68
5 changed files with 36 additions and 2 deletions
|
|
@ -15,6 +15,10 @@ class Entity{
|
||||||
virtual void process() {}
|
virtual void process() {}
|
||||||
virtual void draw() const {}
|
virtual void draw() const {}
|
||||||
virtual void tick() {}
|
virtual void tick() {}
|
||||||
|
virtual void collision(Entity* with) {}
|
||||||
|
void queue_free();
|
||||||
|
private:
|
||||||
|
bool free_queued;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,6 +40,7 @@ class Pacman : public Entity{
|
||||||
void process() override;
|
void process() override;
|
||||||
void animation_tick();
|
void animation_tick();
|
||||||
void draw() const override;
|
void draw() const override;
|
||||||
|
void collision(Entity* with) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Wall : public Entity {
|
class Wall : public Entity {
|
||||||
|
|
|
||||||
17
src/entity.cpp
Normal file
17
src/entity.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "components.h"
|
||||||
|
#include "world.h"
|
||||||
|
|
||||||
|
void Entity::queue_free() {
|
||||||
|
if (this->free_queued)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->free_queued = true;
|
||||||
|
World& world = get_world();
|
||||||
|
|
||||||
|
for(int i = 0; i < world.entities.size(); i++)
|
||||||
|
if(world.entities[i] == this) {
|
||||||
|
delete world.entities[i];
|
||||||
|
world.entities.erase(world.entities.begin()+i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -73,5 +73,12 @@ void Pacman::draw() const {
|
||||||
DrawTextureRec(this->texture.get_texture(), this->getTextureRect(), this->position, WHITE);
|
DrawTextureRec(this->texture.get_texture(), this->getTextureRect(), this->position, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Pacman::collision(Entity* with){
|
||||||
|
Scorepoint* score = dynamic_cast<Scorepoint*>(with);
|
||||||
|
if (score != nullptr) {
|
||||||
|
score->queue_free();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
#include "components.h"
|
#include "components.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include <iostream>
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
Wall::Wall() {
|
Wall::Wall() {
|
||||||
std::cout << get_world().get_atlas() <<'\n';
|
|
||||||
this->texture = TextureAtlas(get_world().get_atlas(),0,64,16,16);
|
this->texture = TextureAtlas(get_world().get_atlas(),0,64,16,16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,13 @@ void World::update_grid() {
|
||||||
int indexified_position = indexify_position(this->entities[i]->position);
|
int indexified_position = indexify_position(this->entities[i]->position);
|
||||||
if (indexified_position < 0 || indexified_position >= GRID_CAPACITY)
|
if (indexified_position < 0 || indexified_position >= GRID_CAPACITY)
|
||||||
continue;
|
continue;
|
||||||
|
if(grid[indexified_position] != nullptr){
|
||||||
|
Entity* entity = this->entities[i];
|
||||||
|
grid[indexified_position]->collision(entity);
|
||||||
|
if(entity != nullptr && grid[indexified_position] != nullptr && grid[indexified_position] != entity){
|
||||||
|
entity->collision(grid[indexified_position]);
|
||||||
|
}
|
||||||
|
}
|
||||||
grid[indexified_position] = this->entities[i];
|
grid[indexified_position] = this->entities[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue