Add GameState and MainGame

This commit is contained in:
Riyyi
2015-03-16 19:47:35 +01:00
parent e5ee39e736
commit ece39bed38
5 changed files with 140 additions and 36 deletions
+35
View File
@@ -0,0 +1,35 @@
#include "maingame.h"
void UpdateCollisions(Entity* entityA, Entity* entityB) {
std::cout << "Collisions!" << std::endl;
}
void MainGame::Initialize(sf::RenderWindow* window) {
entityManager = new EntityManager();
entityManager->SetCollisionMethod(UpdateCollisions);
this->entityManager->AddEntity("test", new Entity("data\\gfx\\test.png"));
this->entityManager->AddEntity("test", new Entity("data\\gfx\\test.png"));
this->entityManager->Get("test0")->velocity.x = 0.5;
this->entityManager->Get("test")->setPosition(sf::Vector2f(50, 50));
}
void MainGame::Update(sf::RenderWindow* window) {
if(inputManager.IsPressed(InputManager::Left)) {
std::cout << "LEFT" << std::endl;
}
if(inputManager.IsPressed(InputManager::Down)) {
std::cout << "DOWN" << std::endl;
}
this->entityManager->Update();
}
void MainGame::Render(sf::RenderWindow* window) {
this->entityManager->Render(window);
}
void MainGame::Destroy(sf::RenderWindow* window) {
delete this->entityManager;
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef MAINGAME_H
#define MAINGAME_H
#include <iostream>
#include "gamestate.h"
#include "entitymanager.h"
#include "inputmanager.h"
class MainGame : public GameState
{
public:
void Initialize(sf::RenderWindow* window);
void Update(sf::RenderWindow* window);
void Render(sf::RenderWindow* window);
void Destroy(sf::RenderWindow* window);
private:
EntityManager* entityManager;
};
#endif // MAINGAME_H