-
Notifications
You must be signed in to change notification settings - Fork 1
/
C_KeyboardMovement.cpp
83 lines (68 loc) · 1.83 KB
/
C_KeyboardMovement.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
#include "C_KeyboardMovement.hpp"
#include "Object.hpp"
#include <imgui.h>
#include "SceneGame.hpp"
C_KeyboardMovement::C_KeyboardMovement(Object* owner)
: Component(owner), moveSpeed(300.0f) {}
void C_KeyboardMovement::Awake()
{
velocity = owner->GetComponent<C_Velocity>();
animation = owner->GetComponent<C_Animation>();
}
//void C_KeyboardMovement::SetInput(Input* input)
//{
// this->input = input;
//}
void C_KeyboardMovement::SetMovementSpeed(float moveSpeed)
{
this->moveSpeed = moveSpeed;
}
void C_KeyboardMovement::Update(float deltaTime)
{
if (owner->userMovementEnabled && !owner->IsDead()) // we set this via script engine
{
//TODO: keyboardmovement should not interact with animation component.
if (animation->GetAnimationState() == AnimationState::Projectile )
{
velocity->Set(0.f, 0.f);
return;
}
float xMove = 0.f;
if (owner->context->input->IsKeyPressed(Input::Key::Left))
{
xMove = -moveSpeed;
if (owner->transform->GetPosition().x < 0)
xMove = 0;
}
else if (owner->context->input->IsKeyPressed(Input::Key::Right))
{
xMove = moveSpeed;
if (owner->transform->GetPosition().x > owner->context->mapParser->WorldX - 64)
xMove = 0;
}
float yMove = 0.f;
if (owner->context->input->IsKeyPressed(Input::Key::Up))
{
yMove = -moveSpeed;
if (owner->transform->GetPosition().y < 0)
yMove = 0;
}
else if (owner->context->input->IsKeyPressed(Input::Key::Down))
{
yMove = moveSpeed;
if (owner->transform->GetPosition().y > owner->context->mapParser->WorldY - 64)
yMove = 0;
}
velocity->Set(xMove, yMove);
}
//if (owner->context->input->IsKeyPressed(Input::Key::R))
//{
//
// owner->context->currentScene->ChangeLevel1(1);
//}
//if (owner->context->input->IsKeyPressed(Input::Key::T))
//{
// owner->context->currentScene->ChangeLevel1(0);
//}
//
}