Compare commits
No commits in common. "63e458ca68e9220cbbb70d3729084f8d27a274ac" and "ed0c9eb2215333e0258be8243e5b4fd3f29644bc" have entirely different histories.
63e458ca68
...
ed0c9eb221
5 changed files with 3 additions and 37 deletions
|
|
@ -15,10 +15,6 @@ class Entity{
|
|||
virtual void process() {}
|
||||
virtual void draw() const {}
|
||||
virtual void tick() {}
|
||||
virtual void collision(Entity* with) {}
|
||||
void queue_free();
|
||||
private:
|
||||
bool free_queued;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -40,7 +36,6 @@ class Pacman : public Entity{
|
|||
void process() override;
|
||||
void animation_tick();
|
||||
void draw() const override;
|
||||
void collision(Entity* with) override;
|
||||
};
|
||||
|
||||
class Wall : public Entity {
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
#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;
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ void Pacman::tick() {
|
|||
|
||||
World& world = get_world();
|
||||
|
||||
if (dynamic_cast<Wall*>(world.grid[indexify_position(new_position)]) == nullptr){
|
||||
if (world.grid[indexify_position(new_position)] == nullptr){
|
||||
this->position=new_position;
|
||||
}
|
||||
|
||||
|
|
@ -73,12 +73,5 @@ void Pacman::draw() const {
|
|||
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,8 +1,10 @@
|
|||
#include "components.h"
|
||||
#include "world.h"
|
||||
#include <iostream>
|
||||
#include <raylib.h>
|
||||
|
||||
Wall::Wall() {
|
||||
std::cout << get_world().get_atlas() <<'\n';
|
||||
this->texture = TextureAtlas(get_world().get_atlas(),0,64,16,16);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,13 +92,6 @@ void World::update_grid() {
|
|||
int indexified_position = indexify_position(this->entities[i]->position);
|
||||
if (indexified_position < 0 || indexified_position >= GRID_CAPACITY)
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue