-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectFactoryPlayMode.cpp
More file actions
69 lines (64 loc) · 2.06 KB
/
Copy pathGameObjectFactoryPlayMode.cpp
File metadata and controls
69 lines (64 loc) · 2.06 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
65
66
67
68
69
#include "GameObjectFactoryPlayMode.h"
#include <iostream>
#include "TransformComponent.h"
#include "StandardGraphicsComponent.h"
#include "PlayerUpdateComponent.h"
#include "RectColliderComponent.h"
#include "InvaderUpdateComponent.h"
#include "BulletUpdateComponent.h"
#include <memory> // need for make_shared
using namespace std;
using namespace sf;
void GameObjectFactoryPlayMode::buildGameObject(
GameObjectBlueprint& bp,
std::vector<GameObject>& gameObjects
)
{
GameObject gameObject;
gameObject.setTag(bp.getName());
auto it = bp.getComponentList().begin();
auto end = bp.getComponentList().end();
for (; it != end; ++it)
{
if (*it == "Transform")
{
gameObject.addComponent(
make_shared<TransformComponent>(
bp.getWidth(),
bp.getHeight(),
Vector2f(bp.getLocationX(), bp.getLocationY())
)
);
}
else if (*it == "Player Update")
{
gameObject.addComponent(make_shared<PlayerUpdateComponent>());
}
else if (*it == "Invader Update")
{
gameObject.addComponent(make_shared<InvaderUpdateComponent>());
}
else if (*it == "Bullet Update")
{
gameObject.addComponent(make_shared<BulletUpdateComponent>());
}
else if (*it == "Standard Graphics")
{
shared_ptr<StandardGraphicsComponent> sgp = make_shared<StandardGraphicsComponent>();
gameObject.addComponent(sgp);
sgp->initializeGraphics(bp.getBitmapName(), Vector2f(bp.getWidth(), bp.getHeight()));
}
}
if (bp.getEncompassingRectCollider())
{
shared_ptr<RectColliderComponent> rcc = make_shared<RectColliderComponent>(bp.getEncompassingRectColliderLabel());
gameObject.addComponent(rcc);
rcc->setOrMoveCollider(
bp.getLocationX(),
bp.getLocationY(),
bp.getWidth(),
bp.getHeight()
);
}
gameObjects.push_back(gameObject);
}