-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
98 lines (82 loc) · 2.19 KB
/
Player.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
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "stdafx.h"
#include "Player.h"
Player::Player()
{
setMoveBounds( SCREEN_WIDTH, SCREEN_HEIGHT );
setVelocity( 0, 0 );
std::cout << "PL S" << std::endl;
setSkin(TextureManager::getTexture("Hero.png"), tPlayer);
Pos().setX(SCREEN_WIDTH / 2);
Pos().setY(SCREEN_HEIGHT / 2);
std::cout << "PL E" << std::endl;
}
Player::~Player()
{
}
void Player::handleEvent(SDL_Event& e)
{
//If a key was pressed
if (e.type == SDL_KEYDOWN && e.key.repeat == 0)
{
//Adjust the velocity
switch (e.key.keysym.sym)
{
case SDLK_UP: setVelocity(getVelocity() + vecUP); break;
case SDLK_DOWN: setVelocity(getVelocity() + vecDOWN); break;
case SDLK_LEFT: setVelocity(getVelocity() + vecLEFT); break;
case SDLK_RIGHT: setVelocity(getVelocity() + vecRIGHT); break;
}
//setVelocity( getVelocity() * speed );
}
if (e.type == SDL_KEYUP && e.key.repeat == 0)
{
//Adjust the velocity
switch (e.key.keysym.sym)
{
case SDLK_UP: setVelocity(getVelocity() - vecUP); break;
case SDLK_DOWN: setVelocity(getVelocity() - vecDOWN); break;
case SDLK_LEFT: setVelocity(getVelocity() - vecLEFT); break;
case SDLK_RIGHT: setVelocity(getVelocity() - vecRIGHT); break;
}
//setVelocity( getVelocity() * speed );
}
}
void Player::move()
{
}
void Player::Attack()
{
}
bool Player::outOfBounds()
{
if (Pos(world).getX() + getSkin().getWidth() > getMoveBounds().getX() || Pos(world).getX() < 0) {
//Pos(world).setX(Pos(world).getX() - getVelocity().getX() * timer->DeltaTime());
printf("Out of bounds x \n");
Pos(world).setX(Pos(world).getX() - getVelocity().getX());
//UpdateBox();
return true;
}
if (Pos(world).getY() + getSkin().getHeight() > getMoveBounds().getY() || Pos(world).getY() < 0) {
//Pos(world).setY(Pos().getY() - vel.getY() * timer->DeltaTime());
printf("Out of bounds y \n");
Pos(world).setY(Pos().getY() - getVelocity().getY());
//UpdateBox();
return true;
}
return false;
}
void Player::Update(Object * obj)
{
printf("Player pos: \n x: %lf, y: %lf \n", Pos().getX(), Pos().getY());
if ( !outOfBounds() )
{
Pos( Pos() + getVelocity() );
}
}
void Player::Draw()
{
getSkin().render(Pos() - Camera::Instance()->Pos());
}
void Player::collisionDetected(Object * obj)
{
}