-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
53 lines (47 loc) · 1.12 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
#include "player.h"
#include "gamewindow.h"
/** Default constructor. Creates a Player with the specified parameters.
* @param pixmap The Pixmap to display this object with
* @param parent The GameWindow which created this object
* @param scene The scene in which this object exists
*/
Player::Player(QPixmap & pixmap, GameWindow * parent, QGraphicsScene *scene) : Thing(pixmap, 0, 0)
{
offscreen = false;
shoots = false;
scene_ = scene;
parent_ = parent;
cooldown = 30;
x_ = 200;
y_ = 500;
setZValue(6);
setPos(x_, y_);
health_ = 5;
}
/** Destructor */
Player::~Player()
{
}
/** Moves the Player by updating it's position and calling a set Position function.
*/
void Player::move()
{
cooldown ++;
if (parent_->pressedD){
if ((x_+pixmap().width()+4) < parent_->xSize_)
x_ += 2;
}
if (parent_->pressedW){
if (y_ > 4)
y_ -= 2;
}
if (parent_->pressedA){
if (x_ > 4)
x_ -= 2;
}
if (parent_->pressedS){
if ((y_ + pixmap().height()+4) < parent_->ySize_ )
y_ += 2;
}
setPos(x_, y_);
}