2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "inputManager.h"
22 /// ***** Private Variables *****
32 static const int keySize = 323;
33 static State keyState[keySize];
35 /// ***** Initializers/Cleaners *****
39 for(int i=0; i< keySize; i++)
47 /// ***** Public Methods *****
53 for(int i=0; i< keySize; i++)
55 if(keyState[i] == wasR)
57 else if(keyState[i] == wasP)
61 while(SDL_PollEvent(&event))
66 keyState[event.key.keysym.sym] = wasR;
69 keyState[event.key.keysym.sym] = wasP;
75 Vector2 input::mousePosition()
78 SDL_GetMouseState(&x, &y);
83 bool input::mouseLeft()
85 Uint8 state = SDL_GetMouseState(NULL, NULL);
87 return state & SDL_BUTTON(1);
89 bool input::mouseRight()
91 Uint8 state = SDL_GetMouseState(NULL, NULL);
93 return state & SDL_BUTTON(3);
96 bool input::isPressed(Uint8 key)
98 return keyState[key] == isP || keyState[key] == wasP;
100 bool input::isReleased(Uint8 key)
102 return keyState[key] == isR || keyState[key] == wasR;
105 bool input::wasPressed(Uint8 key)
107 return keyState[key] == wasP;
109 bool input::wasReleased(Uint8 key)
111 return keyState[key] == wasR;