-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.cpp
More file actions
71 lines (58 loc) · 1.2 KB
/
Copy pathPlayer.cpp
File metadata and controls
71 lines (58 loc) · 1.2 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
70
71
#include "Player.h"
#include "InputHandler.h"
#include"SDL2/SDL.h"
Player::Player()
:SDL_GameObject()
{}
void Player::load(const LoaderParams *params)
{
SDL_GameObject::load(params);
}
void Player::HandleInput()
{
/*if (InputHandler::Instance()->GetMouseButtonState(LEFT))
{
m_velocity.SetX(1);
}
else
{
m_velocity.SetX(0);
}*/
// Vector2D* pos = InputHandler::Instance()->GetMousePosition();
// m_velocity = (*pos - m_position) / 100;
/*if (InputHandler::Instance()->IsKeyDown(SDL_SCANCODE_LEFT))
{
m_velocity.SetX(-2);
}
else if (InputHandler::Instance()->IsKeyDown(SDL_SCANCODE_RIGHT))
{
m_velocity.SetX(2);
}
if (InputHandler::Instance()->IsKeyDown(SDL_SCANCODE_UP))
{
m_velocity.SetY(-2);
}
else if (InputHandler::Instance()->IsKeyDown(SDL_SCANCODE_DOWN))
{
m_velocity.SetY(2);
}*/
Vector2D* target = InputHandler::Instance()->GetMousePosition();
m_velocity = *target - m_position;
m_velocity /= 50;
}
void Player::Draw()
{
SDL_GameObject::Draw();
}
void Player::Update()
{
HandleInput();
// m_accelaration.SetX(1);
// m_velocity.SetX(1);
m_currentFrame = int(((SDL_GetTicks() / 100) % 4));
SDL_GameObject::Update();
}
void Player::Clean()
{
SDL_GameObject::Clean();
}