-
Notifications
You must be signed in to change notification settings - Fork 1
/
gamecontrol.cpp
157 lines (128 loc) · 3.28 KB
/
gamecontrol.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "gamescene.h"
#include "gameitem.h"
#include "gamemenu.h"
#include "gametools.h"
#include "gamebonus.h"
#include "gameprofile.h"
#include "gamestat.h"
#include <QGraphicsSceneMouseEvent>
////////////////////////////////////////////////////////////////////////////////
void GameScene::keyPressEvent ( QKeyEvent * keyEvent )
{
if (!menu->isActive())
{
switch (keyEvent->key())
{
case Qt::Key_Escape:
{
if (gameBonus->isActive())
{
gameBonus->hideBonusMenu(this);
break;
}
if (stat_active)
{
if (stat->code == STAT_GAME_WON)
{
exitToMainMenu();
break;
}
runNextLevel();
break;
}
pauseGame();
break;
}
#if 0
// that's only for debugging reasons
case Qt::Key_1:
case Qt::Key_2:
case Qt::Key_3:
case Qt::Key_4:
case Qt::Key_5:
case Qt::Key_6:
case Qt::Key_7:
case Qt::Key_8:
{
int id = keyEvent->key() - Qt::Key_1;
if (activeItems.count() <= id)
return;
id = activeItems.at(id);
gameBonus->addItemScore(id,100);
break;
}
case Qt::Key_9:
score += 1000;
toolset->addScore(1000);
break;
case Qt::Key_W:
levelWon();
break;
// case Qt::Key_X:
// level = max_level;
// gameProfile->currentPlayer()->level = level;
// levelWon();
// break;
case Qt::Key_F:
time = 2;
break;
case Qt::Key_H:
hintAvailableMoves();
break;
case Qt::Key_J:
hintMove = false;
break;
#endif
default:;
}
}
else {
QGraphicsScene::keyPressEvent(keyEvent);
}
}
////////////////////////////////////////////////////////////////////////////////
void GameScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
QGraphicsScene::mousePressEvent(mouseEvent);
if (mouseEvent->isAccepted())
return;
mouseEvent->accept();
// click on menu shortcuts
if (mouseEvent->button() == Qt::LeftButton)
menu->checkMenuMouseActions(mouseEvent->scenePos().toPoint());
if (inputDisabled || paintState)
return;
if (mouseEvent->button() == Qt::LeftButton)
{
// lets add more randomness
qsrand(QDateTime::currentDateTime().toTime_t());
// find position
lastClickPos = mouseEvent->scenePos();
}
}
////////////////////////////////////////////////////////////////////////////////
void GameScene::mouseMoveEvent ( QGraphicsSceneMouseEvent *mouseEvent )
{
QGraphicsScene::mouseMoveEvent(mouseEvent);
if (mouseEvent->isAccepted())
return;
// scene
cursorPos = mouseEvent->scenePos();
mouseEvent->accept();
if (inputDisabled || paintState)
return;
// simulate a click when mouse is moved with left button pressed while in selection mode
if (mouseEvent->buttons() & Qt::LeftButton && moveState == MS_SELECTED && !toolset->current())
{
// find position
lastClickPos = mouseEvent->scenePos();
return;
}
// check for hovers
QPoint pos = cursorPos.toPoint();
if (toolset->checkMouseHover(pos))
return;
if (gameBonus->checkMouseHover(pos))
return;
removeHint();
}