-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventHandle.cpp
121 lines (93 loc) · 2.5 KB
/
EventHandle.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
#include "stdafx.h"
EventHandle::EventHandle()
{
memset( &KEYS, false, sizeof( bool ) * 322 );
}
EventHandle::~EventHandle()
{
}
void EventHandle::Update()
{
while (SDL_PollEvent(&e) != 0)
{
//uset request quit
if (e.type == SDL_QUIT)
{
SDL_wrapper::Instance()->quit = true;
}
if (e.type == SDL_MOUSEMOTION || e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP)
{
bool isReleased = false;
if ( e.type == SDL_MOUSEBUTTONDOWN )
{
isReleased = false;
}
else if ( e.type == SDL_MOUSEBUTTONUP )
{
isReleased = true;
}
SDL_wrapper::Instance()->onMouseButtonEvent(e.motion.x, e.motion.y, isReleased, e.button.button);
}
const Uint8* currentKeyState = SDL_GetKeyboardState(NULL);
// SDL_Log("currentstate %d", currentKeyState);
if (currentKeyState[SDL_SCANCODE_LEFT])
{
}
if (currentKeyState[SDL_SCANCODE_RIGHT])
{
}
if ( e.type == SDL_KEYDOWN && e.key.repeat == 0 )
{
KEYS[ e.key.keysym.scancode ] = true;
SDL_wrapper::Instance()->onKeyPress( e.key.keysym.scancode );
}
if ( e.type == SDL_KEYUP && e.key.repeat == 0 )
{
KEYS[ e.key.keysym.scancode ] = false;
SDL_wrapper::Instance()->onKeyRelease( e.key.keysym.scancode );
break;
}
}
handleInput();
}
void EventHandle::handleInput()
{
if ( KEYS[ SDL_SCANCODE_LEFT ] )
{
BodyManager::Instance()->getPlayer()->move( b2Vec2( 0, 1 ) );
}
//if ( !KEYS[ SDL_SCANCODE_LEFT ] )
//{
// SDL_wrapper::Instance()->pl->move( b2Vec2( 0, 1 ) );
//}
if ( KEYS[ SDL_SCANCODE_RIGHT ] )
{
BodyManager::Instance()->getPlayer()->move( b2Vec2( 0, -1 ) );
}
if ( KEYS[ SDL_SCANCODE_SPACE ] )
{
BodyManager::Instance()->getPlayer()->jump( );
}
/*
int a = SDL_SCANCODE_TO_KEYCODE(SDLK_LEFT);
SDL_Log(" SDLKLEFT %d", SDL_SCANCODE_TO_KEYCODE(SDLK_LEFT) );
SDL_Log(" SDLKLEFT %d", SDLK_LEFT );
SDL_Log(" SDLKLEFT %d", SDLK_SCANCODE_MASK | SDLK_LEFT );
if( KEYS[ SDL_SCANCODE_TO_KEYCODE( SDLK_LEFT ) ] == true )
{
SDL_wrapper::Instance()->pl->move( b2Vec2( 0, 1 ) );
}
if (KEYS[ SDL_SCANCODE_TO_KEYCODE( SDLK_RIGHT ) ] == true)
{
SDL_wrapper::Instance()->pl->move( b2Vec2( 0, -1 ) );
}
if( KEYS[ SDL_SCANCODE_TO_KEYCODE( SDLK_LEFT ) ] == false )
{
SDL_wrapper::Instance()->pl->move( b2Vec2( 0, 1 ) );
}
if ( KEYS[ SDL_SCANCODE_TO_KEYCODE( SDLK_RIGHT ) ] == false )
{
SDL_wrapper::Instance()->pl->move( b2Vec2( 0, -1 ) );
}
*/
}