-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandleBall.cpp
63 lines (48 loc) · 1.54 KB
/
HandleBall.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
#pragma once
#include "HandleBall.h"
#include "cBall.h"
#include "cDeath.h"
#include "constants.h"
#include <AstuSuite2D.h>
#include <AstuECS.h>
using namespace astu::suite2d;
using namespace astu2d;
using namespace astu;
using namespace std;
const astu::EntityFamily HandleBall::FAMILY = EntityFamily::Create<cBall>();
HandleBall::HandleBall(int updatePriority)
:BaseService("Ball HandlerService")
,IteratingEntitySystem(FAMILY,updatePriority)
{
}
void HandleBall::OnStartup() {
auto& imps = ASTU_SERVICE(InputMappingService);
respawnBallAction = imps.BindAction("Respawn");
}
void HandleBall::OnShutdown() {
auto& imps = ASTU_SERVICE(InputMappingService);
imps.RemoveActionBinding(respawnBallAction);
respawnBallAction = nullptr;
}
void HandleBall::DestroyBall(astu::Entity& ball){
ball.GetComponent<CBody>().SetLinearVelocity(0,0);
ball.GetComponent<CPose>().transform.SetTranslation(BALL_INIT_POS);
EmitSignal(GameEvent(GameEvent::Type::BallOut));
}
bool HandleBall::OnCollision(astu::Entity& entityA, astu::Entity& entityB){
if(entityA.HasComponent<cBall>()&& entityB.HasComponent<cDeath>()){
DestroyBall(entityA);
}
if(entityB.HasComponent<cBall>()&& entityA.HasComponent<cDeath>()){
DestroyBall(entityB);
}
return 0;
}
void HandleBall::ProcessEntity(Entity& entity){
if(respawnBallAction->IsPressed()){
auto& body = entity.GetComponent<CBody>();
if(body.GetLinearVelocity()==Vector2f(0,0)){
body.SetLinearVelocity(0,BALL_INITSPEED);
}
}
}