//Game.cpp
Code:
#include "EntityManager.h"
void System::Init()
{
engine = new System();
engine -> SetWindow(800, 600, "Test");
Entity player;
player.Load("test.png", 100, 100);
manager.Add(player);
}
void System::Run()
{
sf::Event ev;
while (engine -> window -> IsOpened())
{
engine -> window -> PollEvent(ev);
engine -> window -> Clear();
manager.Update();
engine -> window -> Display();
}
}
//System.cpp
Code:
#include "System.h"
void System::SetScreenDim(int width, int height)
{
this -> SCREENW = width;
this -> SCREENH = height;
}
void System::SetTitle(std::string title)
{
this -> Title = title;
}
void System::SetWindow(int width, int height, std::string title)
{
this -> SCREENW = width;
this -> SCREENH = height;
this -> window = new sf::RenderWindow(sf::VideoMode(width, height), title.c_str());
}
//EntityManager.cpp
Code:
#include "EntityManager.h"
#include "System.h"
void Manager::Update()
{
Entity entity;
std::list<Entity>::iterator iter = eList.begin();
while (iter != eList.end())
{
entity = *iter;
entity.GetSprite().SetPosition(entity.GetX(), entity.GetY());
engine -> window -> Draw(entity.GetSprite());
iter++;
}
}
void Manager::Add(Entity entity)
{
eList.push_back(entity);
}
//Entity.cpp
Code:
#include "Entity.h"
void Entity::Load(std::string filename, float x, float y)
{
this -> Filename = filename;
this -> Image.LoadFromFile(this -> Filename.c_str());
this -> Sprite.SetImage(this -> Image);
this -> posx = x;
this -> posy = y;
}
void Entity::Update()
{
this -> Sprite.SetPosition(this -> posx, this -> posy);
}
[/code]






