-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerControl.cpp
More file actions
67 lines (57 loc) · 1.29 KB
/
PlayerControl.cpp
File metadata and controls
67 lines (57 loc) · 1.29 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
#include "PlayerControl.h"
PlayerControl::PlayerControl()
{
//Collision size of the player
m_width = 25;
m_height = 26;
}
PlayerControl::~PlayerControl()
{
}
void PlayerControl::createPlayer(sf::RenderWindow &win)
{
mp_player.loadPlayer();
mc_cam.createCam(win);
}
void PlayerControl::drawPlayer(sf::RenderWindow &win)
{
win.draw(mp_player);
}
void PlayerControl::playerAktion(sf::RenderWindow &win,float frametime,Tilemap& t)
{
mp_player.getFrameTime(frametime);
//set top and left of the player
m_top = static_cast<int>(mp_player.getPosition().y);
m_left = static_cast<int>(mp_player.getPosition().x);
if(m_sm.listen() == false)
{
//check if player collide
if(t.isWalkable(m_left,m_top,m_width,m_height) == 1)
{
//set old position
mp_player.SetOldPosition();
}
//move the player
mp_player.movePlayer(win);
}
else if(m_sm.listen() == true)
{
//check if player collide
if(t.isWalkable(m_left,m_top,m_width,m_height) == 1)
{
//set old position
mp_player.SetOldPosition();
}
m_sm.checkScene(mp_player);
}
//update the cam
mc_cam.updateCamPos(mp_player.getPosition().x,mp_player.getPosition().y,win);
}
float PlayerControl::getPlayerPosX()
{
return mp_player.getPosition().x;
}
float PlayerControl::getPlayerPosY()
{
return mp_player.getPosition().y;
}