This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.cpp
89 lines (75 loc) · 1.65 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
#include "player.h"
#include "route.h"
#include "game.h"
#include "shot.h"
#include "gameobject.h"
#include <iostream>
#include <QJsonArray>
#include <QJsonObject>
#include "shotpool.h"
Player::Player()
{
gameObjectType = GameObject::Type::Player;
setPixmap(":/images/images/PlayerSprite.png");
rect = QRect(268,700,48,48);
addRoute(Route::Path::None);
addRoute(Route::Path::Left);
addRoute(Route::Path::Right);
setCurrentRoute(Route::Path::None);
speed = 10;
lives = 1;
fireGun = false;
}
Player::~Player()
{
std::cout<<"destroy player"<< std::endl;
}
int Player::getLives(){
return lives;
}
QPixmap Player::getPixmap(){
return pixmap;
}
void Player::setCurrentRoute(Route::Path route){
if(route == Route::Path::None){
currentRoute = routes[0];
}
if(route == Route::Path::Left){
currentRoute = routes[1];
}
if(route == Route::Path::Right){
currentRoute = routes[2];
}
}
void Player::move()
{
if(currentRoute->getRoutePath() == Route::Path::Left && rect.x() > 10){
rect.moveTo(currentRoute->getNextPoint(speed));
}
if(currentRoute->getRoutePath() == Route::Path::Right && rect.x() < 590 - rect.width()){
rect.moveTo(currentRoute->getNextPoint(speed));
}
if(this->isFireGun()){
this->fire();
}
}
void Player::fire()
{
this->addShot(ShotPool::getInstance().createNew(this->getPoint()+QPoint(24,24),GameObject::Type::PlayerShot));
}
void Player::makeFireGun(bool firegun)
{
fireGun = firegun;
}
bool Player::isFireGun()
{
return fireGun;
}
void Player::read(const QJsonObject &json)
{
GameObject::read(json);
}
void Player::write(QJsonObject &json) const
{
GameObject::write(json);
}