-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcscene.cpp
More file actions
63 lines (57 loc) · 1.45 KB
/
Copy pathcscene.cpp
File metadata and controls
63 lines (57 loc) · 1.45 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
#include "cscene.h"
CScene::CScene(QObject *parent) :
QGraphicsScene(parent)
{
m_timer = new QTimer(this);
m_timer->start(25);
// LArrow and RArrow for smooth change between right and left walk
m_actualKey.bLArrow = FALSE;
m_actualKey.bRArrow = FALSE;
m_actualKey.bLCtrl = FALSE;
}
void CScene::keyPressEvent(QKeyEvent *event)
{
extern CStalker *hero;
switch(event->key())
{
case Qt::Key_Right:
hero->SetWalk(RIGHT);
m_actualKey.bRArrow = TRUE;
break;
case Qt::Key_Left:
hero->SetWalk(LEFT);
m_actualKey.bLArrow = TRUE;
break;
case Qt::Key_Space:
hero->SetJump(); break;
}
}
void CScene::keyReleaseEvent(QKeyEvent *event)
{
extern CStalker *hero;
switch(event->key())
{
case Qt::Key_Right:
if(m_actualKey.bLArrow)
{
m_actualKey.bRArrow = FALSE;
break;
}
hero->StopWalk(RIGHT);
m_actualKey.bRArrow = FALSE;
break;
case Qt::Key_Left:
if(m_actualKey.bRArrow)
{
m_actualKey.bLArrow = FALSE;
break;
}
hero->StopWalk(LEFT);
m_actualKey.bLArrow = FALSE;
break;
}
}
KeyPress * CScene::GetKeyPressed()
{
return &m_actualKey;
}