-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cpp
More file actions
103 lines (92 loc) · 2.31 KB
/
Copy pathplayer.cpp
File metadata and controls
103 lines (92 loc) · 2.31 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
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
99
100
101
102
103
#include "player.h"
#include <iostream>
Player::Player(int posx, int posy, int speed) :
Entity::Entity(posx, posy, speed)
{
lives = 3;
// Load images for different directions
forward.load("://Images/Characters/gator_forward.png");
forward2.load("://Images/Characters/gator_forward2.png");
reverse.load("://Images/Characters/gator_reverse.png");
reverse2.load("://Images/Characters/gator_reverse2.png");
up.load("://Images/Characters/gator_forward_up.png");
up2.load("://Images/Characters/gator_forward_up2.png");
down.load("://Images/Characters/gator_forward_down.png");
down2.load("://Images/Characters/gator_forward_down2.png");
}
void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
switch(facingDirection)
{
case LEFT:
if (state > 2)
{
if (state > 4)
state = 0;
painter->drawPixmap(posx,posy,charW,charW,reverse2);
}
else
{
painter->drawPixmap(posx,posy,charW,charW,reverse);
}
break;
case RIGHT:
if (state > 2)
{
if (state > 4)
state = 0;
painter->drawPixmap(posx,posy,charW,charW,forward2);
}
else
{
painter->drawPixmap(posx,posy,charW,charW,forward);
}
break;
case UP:
if (state > 2)
{
if (state > 4)
state = 0;
painter->drawPixmap(posx,posy,charW,charW,up2);
}
else
{
painter->drawPixmap(posx,posy,charW,charW,up);
}
break;
case DOWN:
if (state > 2)
{
if (state > 4)
state = 0;
painter->drawPixmap(posx,posy,charW,charW,down2);
}
else
{
painter->drawPixmap(posx,posy,charW,charW,down);
}
break;
case NONE:
painter->drawPixmap(posx,posy,charW,charW,forward);
break;
}
}
int Player::getLives() const
{
return lives;
}
void Player::setLives(int lives)
{
if (lives >= 0 || lives <= 3)
{
this->lives = lives;
}
}
void Player::setDirection(Direction dir)
{
facingDirection = dir;
}
void Player::setNextDirection(Direction dir)
{
nextDirection = dir;
}