-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionSystem.cpp
More file actions
65 lines (52 loc) · 1.6 KB
/
ActionSystem.cpp
File metadata and controls
65 lines (52 loc) · 1.6 KB
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
//
// Created by Fabien on 10/09/2016.
//
#include "ActionSystem.hpp"
ActionSystem::ActionSystem(tmx::MapLoader& pLoader):mLoader(pLoader),mCollision(false),mObject(nullptr),mActionPending(false)
{
}
void ActionSystem::configure(entityx::EventManager &event_manager) {
event_manager.subscribe<Collision>(*this);
event_manager.subscribe<EndCollision>(*this);
mChai.add(chaiscript::fun([this](const std::string& who, const std::string& something){ say(who,something); }), "say");
mEventManager = &event_manager;
}
void ActionSystem::update(entityx::EntityManager &es, entityx::EventManager &events, entityx::TimeDelta dt)
{
// tester l'état du clavier
if (mCollision)
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
if(!mActionPending) {
mActionPending = true;
if (mObject != nullptr) {
mChai.eval_file(mObject->GetPropertyString("action"));
}
}
}
else
{
mActionPending=false;
}
}
}
void ActionSystem::receive(const Collision &collision) {
switch (collision.mType) {
case Collision::CollisionType::FAR :
mObject = collision.mObject;
mCollision = true;
break;
default:
break;
}
}
void ActionSystem::receive(const EndCollision &collision)
{
mCollision = false;
mObject = nullptr;
}
void ActionSystem::say(const std::string& who, const std::string &something) const {
if(mEventManager!= nullptr) {
mEventManager->emit<DialogEvent>(who, something);
}
}