-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPC.cpp
85 lines (72 loc) · 1.78 KB
/
PC.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
84
85
#include "PC.h"
#include <ctype>
#include <time>
void PC::Draw( sf::RenderTarget& rt )
{
rt.draw( sprite );
}
void PC::SetDirection( const sf::Vector2f& dir )
{
if( dir.x > 0.0f )
{
curAnimation = AnimationIndex::WalkingRight;
}
else if( dir.x < 0.0f )
{
curAnimation = AnimationIndex::WalkingLeft;
}
else if( dir.y < 0.0f )
{
curAnimation = AnimationIndex::WalkingUp;
}
else if( dir.y > 0.0f )
{
curAnimation = AnimationIndex::WalkingDown;
}
else
{
if( vel.x > 0.0f )
{
curAnimation = AnimationIndex::StandingRight;
}
else if( vel.x < 0.0f )
{
curAnimation = AnimationIndex::StandingLeft;
}
else if( vel.y < 0.0f )
{
curAnimation = AnimationIndex::StandingUp;
}
else if( vel.y > 0.0f )
{
curAnimation = AnimationIndex::StandingDown;
}
}
vel = dir * speed;
}
void PC::Update( float dt )
{
pos += vel * dt;
collision_coordinates += vel*dt;
collisionbounds.top = pos.y + 7;
collisionbounds.left = pos.x + 8;
animations[int( curAnimation )].update( dt );
animations[int( curAnimation )].ApplyToSprite( sprite );
sprite.setPosition( pos );
}
sf::FloatRect PC::nextframe(sf::Vector2f& dire, float dt)
{
sf::Vector2f position = pos;
sf::Vector2f vel = dire * speed;
position += vel*dt;
return sf::FloatRect( position.x+8 , position.y + 7, collisionbounds.width, collisionbounds.height);
}
sf::Vector2f PC::nextpos(sf::Vector2f& dire, float dt)
{
sf::Vector2f position = pos;
bottomright = sf::Vector2f(pos.x+8 + collisionbounds.width, pos.y + 7 + collisionbounds.height)
;sf::Vector2f vel = dire * (speed);
position += vel*dt;
position.x+=8 ; position.y +=7;
return position;
}