-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestScene.cpp
102 lines (89 loc) · 2.64 KB
/
TestScene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* TestScene is the hub to test all code changes.
*
* Author: Skylar Payne
* Date: 7/31/2013
* File: TestScene.h
**/
#include "TestScene.h"
#include <SFML/Graphics.hpp>
#include "IListener.h"
#include <lua.hpp>
#include "LuaBindings.h"
#include "Logger.h"
#include "PositionComponent.h"
#include "MovementComponent.h"
#include "MovementSystem.h"
#include "CircleComponent.h"
#include "RectangleComponent.h"
#include "SpriteComponent.h"
#include "TextComponent.h"
#include "ParticleComponent.h"
#include "Entity.h"
#include "RenderSystem.h"
#include "ScriptableBehavior.h"
#include "CollisionSystem.h"
#include "ColliderComponent.h"
#include "BehaviorSystem.h"
#include "ParticleSystem.h"
bool TestScene::Load()
{
RenderSystem* rs = new RenderSystem();
sm.Add(rs);
MovementSystem* ms = new MovementSystem();
sm.Add(ms);
CollisionSystem* cs = new CollisionSystem(sf::Vector2f(this->GetWindow()->getSize()), sf::Vector2f(200, 200));
sm.Add(cs);
BehaviorSystem* bs = new BehaviorSystem();
sm.Add(bs);
ParticleSystem* ps = new ParticleSystem();
sm.Add(ps);
ef.Register("Position", []() { return new PositionComponent(); });
ef.Register("Movement", []() { return new MovementComponent(); });
ef.Register("Collider", []() { return new ColliderComponent(); });
ef.Register("Circle", []() { return new CircleComponent(); });
ef.Register("Rectangle", []() { return new RectangleComponent(); });
ef.Register("Sprite", []() { return new SpriteComponent(); });
ef.Register("Text", []() { return new TextComponent(); });
ef.Register("Particle", []() { return new ParticleComponent();});
rm.AddFont("Lorena.ttf");
rm.AddTexture("spaceship.png");
ef.Create("entity2.lua", 50, 50);
ef.Create("entity.lua", 400, 400);
return true;
}
void TestScene::Update()
{
sf::Event event;
while(this->GetWindow()->pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
ExitMessage msg;
msg.ExitStatus = 0;
Emit<ExitMessage>(msg);
}
else if(event.type == sf::Event::KeyPressed)
{
if(event.key.code == sf::Keyboard::Q)
{
lua_State* L = luaL_newstate();
SetBindings(L);
if(luaL_dofile(L, "luatest.lua"))
{
g_Logger << lua_tostring(L, -1) << "\n";
lua_pop(L, 1);
}
lua_close(L);
}
}
}
this->GetWindow()->clear();
em.Update();
sm.Update();
this->GetWindow()->display();
}
void TestScene::Unload()
{
rm.Unload();
}