-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerMP.cpp
47 lines (40 loc) · 938 Bytes
/
PlayerMP.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
#include "PlayerMP.h"
PlayerMP::PlayerMP(int idIn) : id(idIn), Entity()
{
prevSnapShot = SnapShot();
latestSnapShot = SnapShot();
size = glm::vec2(80, 160);
currTime = SDL_GetTicks();
}
void PlayerMP::setLatestSnapShot(float x, float y, int tick)
{
if(latestSnapShot.time > tick)
std::cout << "ERROR TIME ERRORORORORO" << std::endl;
prevSnapShot = latestSnapShot;
latestSnapShot = SnapShot(glm::vec2(x, y), tick);
timer = 0;
}
SnapShot PlayerMP::getLatestSnapShot(void)
{
return latestSnapShot;
}
SnapShot PlayerMP::getPrevSnapShot(void)
{
return prevSnapShot;
}
glm::vec2 PlayerMP::getSize(void)
{
return size;
}
int PlayerMP::getId(void)
{
return id;
}
void PlayerMP::update(void)
{
oldTime = currTime;
currTime = SDL_GetTicks();
float tmp = (currTime - oldTime) / (float)(latestSnapShot.time - prevSnapShot.time);
timer += tmp;
position = prevSnapShot.pos + ((latestSnapShot.pos-prevSnapShot.pos) * timer);
}