Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions SFMLengine_alpha/modules/components/draw_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#include<SFML/Graphics.hpp>
#include"component.h"

class DrawComponent : public Component, public sf::Drawable
class DrawComponent : public Component, public sf::Drawable, public sf::Transformable
{
protected:
sf::Drawable* object;

public:
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

void set(sf::Drawable* obj);
void set(sf::Drawable& obj);
};
6 changes: 5 additions & 1 deletion SFMLengine_alpha/modules/components/soul_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ class SoulComponent :public Component
Object* obj;
public:


template<class T>
void set(Game* game, Scence* scence, Entity* entity);
void set(Game* game, Scence* scence, Entity* entity) {
obj = new T();
obj->set(game, scence, entity);
}

void logic();
};
15 changes: 11 additions & 4 deletions SFMLengine_alpha/modules/main_srtuctures/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ class Entity:public sf::Drawable
sf::Vector2f pos;

template<class T>
void add_component();
void add_component() {
components.push_back(new T());
}

template<class T>
T& get_component() const;
T& get_component() const {
for (auto& comp : components)
if (typeid(*comp) == typeid(T))
return static_cast<T&>(*comp);
}
//���� - ������ �������� ��� ������
template<class T>
void set_soul(Game* game, Scence* scence);

void set_soul(Game* game, Scence* scence) {
get_component<SoulComponent>().set<T>(game, scence, this);
}

void logic();

Expand Down
2 changes: 2 additions & 0 deletions SFMLengine_alpha/modules/main_srtuctures/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Game
sf::Texture texture;
sf::Event event;

private:
sf::CircleShape sh;
public:
Game();

Expand Down
6 changes: 3 additions & 3 deletions SFMLengine_alpha/modules/main_srtuctures/Scence.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Scence : public sf::Drawable
void logic();
//����� ���������� ��� ��������� ��� ������� ������������ ��������
template<class T>
void set(Game* game,int numb=0);
void set(Game* game, int numb) {
entities[numb].set_soul<T>(game, this);
}

//��������
private:
sf::CircleShape sh;
};
6 changes: 2 additions & 4 deletions SFMLengine_alpha/src/components/draw_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

void DrawComponent::draw(sf::RenderTarget& target, sf::RenderStates states)const {
target.draw(*object, states);

}

void DrawComponent::set(sf::Drawable* obj) {
this->object = obj;
void DrawComponent::set(sf::Drawable& obj) {
this->object = &obj;
}
6 changes: 0 additions & 6 deletions SFMLengine_alpha/src/components/soul_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
//#include"../../modules/main_srtuctures/Entity.h"
//#include"../../modules/components/soul_component.h"

template<class T>
void SoulComponent::set(Game* game, Scence* scence, Entity* entity) {
obj = new T();
obj->set(game, scence, entity);
}

void SoulComponent::logic() {
obj->logic();
}
18 changes: 0 additions & 18 deletions SFMLengine_alpha/src/main_structures/Entity.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
#include"../../modules/main_srtuctures/Game.h"


template<class T>
void Entity::add_component(){
components.push_back(new T());
}

template<class T>
T& Entity::get_component() const {
for (auto& comp : components)
if (typeid(*comp) == typeid(T))
return static_cast<T&>(*comp);
}

template<class T>
void Entity::set_soul(Game* game, Scence* scence) {
get_component<SoulComponent>().set<T>(game, scence, this);
}

void Entity::logic() {
get_component<SoulComponent>().logic();
}
Expand Down
15 changes: 11 additions & 4 deletions SFMLengine_alpha/src/main_structures/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Game::Game() {
window.setFramerateLimit(60);

add_scence();
sh.setFillColor(sf::Color::Green);
sh.setPosition(sf::Vector2f(200, 200));
sh.setRadius(40);
scences[0].get()->get_component<DrawComponent>().set(sh);

}

Expand All @@ -14,8 +18,9 @@ void Game::add_scence() {
}

void Game::draw() {

window.clear();
window.draw(*n_sc);
window.display();
}

void Game::logic() {
Expand All @@ -29,7 +34,9 @@ void Game::even() {
}

void Game::main_loop() {
even();
logic();
draw();
while (window.isOpen()) {
even();
logic();
draw();
}
}
9 changes: 1 addition & 8 deletions SFMLengine_alpha/src/main_structures/Scence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ Scence::Scence(Game* game) {
entities[0].add_component<DrawComponent>();
entities[0].add_component<SoulComponent>();
entities[0].set_soul<Object>(game, this);
sh.setFillColor(sf::Color::Green);
sh.setPosition(sf::Vector2f(200, 200));
sh.setRadius(40);
entities[0].get_component<DrawComponent>().set(&sh);

}

void Scence::add_entity() {
Expand All @@ -25,7 +22,3 @@ void Scence::logic() {
ent.logic();
}

template<class T>
void Scence::set(Game* game,int numb) {
entities[numb].set_soul<T>(game, this);
}