Added AsloEngine 0.9.0 to Repository
This commit is contained in:
parent
d017dd84b3
commit
881e6c70f2
60 changed files with 2648 additions and 0 deletions
124
asloengine/builtin/grid_container.cpp
Executable file
124
asloengine/builtin/grid_container.cpp
Executable file
|
|
@ -0,0 +1,124 @@
|
|||
#include "headers/grid_container.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
GridContainer::GridContainer(sf::String _name, sf::Vector2u _grid_size, sf::Vector2f _cell_size)
|
||||
: grid_size(_grid_size), cell_size(_cell_size), GameObject(_name) {}
|
||||
|
||||
GridContainer::~GridContainer() {}
|
||||
|
||||
void GridContainer::update_positions()
|
||||
{
|
||||
|
||||
sf::Vector2f grid_anchor_position = get_position() - (get_origin() * to_vector2f(grid_size) * cell_size);
|
||||
|
||||
for (int x = 0; x < grid_size.x; x++)
|
||||
{
|
||||
for (int y = 0; y < grid_size.y; y++)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int x = 0;
|
||||
unsigned int y = 0;
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
|
||||
if (x >= grid_size.x)
|
||||
{
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (y >= grid_size.y)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
sf::Vector2f tmp_vec = grid_anchor_position + sf::Vector2f(x * cell_size.x, y * cell_size.y);
|
||||
object->set_position(tmp_vec);
|
||||
|
||||
x++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::add_object(GameObject *object)
|
||||
{
|
||||
|
||||
objects.emplace_back(object);
|
||||
|
||||
update_positions();
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::remove_object(int index)
|
||||
{
|
||||
|
||||
objects.erase(objects.begin() + index);
|
||||
|
||||
update_positions();
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::draw()
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::on_start()
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->start(render_window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::on_update(float delta_time)
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->update(delta_time);
|
||||
if (!object->alive)
|
||||
{
|
||||
needs_clean = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::clean()
|
||||
{
|
||||
|
||||
for (int i = 0; i < objects.size(); i++)
|
||||
{
|
||||
objects.erase(objects.begin() + i);
|
||||
}
|
||||
|
||||
needs_clean = false;
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::on_destroy()
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue