-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathracket.cpp
85 lines (70 loc) · 1.38 KB
/
racket.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
#include "racket.h"
#include <QGraphicsRectItem>
#include <QGraphicsItem>
#include <QObject>
#include <iostream>
#include <QMediaPlayer>
Racket::Racket(int side)
: side(side),score(0)
{
setRect(0 , 0 , Global::Width/55.0 ,Global::Height/5.0*Global::playerSizeConst ); //set position and shape
score_sound = new QMediaPlayer;
score_sound->setMedia(QUrl("qrc:/sounds/coin.wav"));
}
void Racket::move()
{
if(direction == Up)
moveUp();
if(direction == Down)
moveDown();
}
void Racket::moveUp()
{
if(y() < 0)
setPos(x(),0);
setPos(x(),y() - speed);
}
void Racket::moveDown()
{
if(y()+rect().height() > Global::Height)
setPos(x(),Global::Height-rect().height());
setPos(x(),y() + speed);
}
bool Racket::getSide() const
{
return side;
}
bool Racket::getAIMode() const
{
return aiMode;
}
unsigned int Racket::getScore() const
{
return score;
}
void Racket::resetScore()
{
score = 0;
}
void Racket::resize()
{
setRect(0 , 0 , Global::Width/55.0 , Global::Height/5.0*Global::playerSizeConst );
speed = Global::Height/410.0*Global::playerSpeedConst;
}
void Racket::changeDirection(Dir dir)
{
direction = dir;
}
void Racket::setAIMode(bool enabled)
{
aiMode = enabled;
}
void Racket::mute(int sound)
{
score_sound->setVolume(sound);
}
void Racket::increaseScore()
{
score++;
score_sound->play();
}