20130313
[gdash.git] / src / input / gameinputhandler.cpp
blobf7348503908067a93c19b4527e64d1467400df5f
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "config.h"
19 #include "input/gameinputhandler.hpp"
20 #include "input/joystick.hpp"
22 GameInputHandler::GameInputHandler()
24 clear_all_keypresses();
28 void GameInputHandler::clear_all_keypresses() {
29 up_k = false;
30 down_k = false;
31 left_k = false;
32 right_k = false;
33 fire1_k = false;
34 fire2_k = false;
35 suicide = false;
36 fast_forward = false;
37 alternate_status = false;
38 restart_level = false;
42 void GameInputHandler::keyrelease(int gfxlib_keycode) {
43 for (unsigned i = 0; i != KeysNum; ++i) {
44 KeyAssignment const &key = get_key(Keys(i));
45 if (gfxlib_keycode == key.gfxlib_keycode) {
46 this->*key.ptr = false;
52 void GameInputHandler::keypress(int gfxlib_keycode) {
53 for (unsigned i = 0; i != KeysNum; ++i) {
54 KeyAssignment const &key = get_key(Keys(i));
55 if (gfxlib_keycode == key.gfxlib_keycode) {
56 this->*key.ptr = true;
62 char const *GameInputHandler::get_key_name(Keys keyindex) {
63 return get_key_name_from_keycode(get_key(keyindex).gfxlib_keycode);
67 int &GameInputHandler::get_key_variable(Keys keyindex) {
68 return get_key(keyindex).gfxlib_keycode;
72 bool GameInputHandler::up() {
73 return up_k || Joystick::up();
77 bool GameInputHandler::down() {
78 return down_k || Joystick::down();
82 bool GameInputHandler::left() {
83 return left_k || Joystick::left();
87 bool GameInputHandler::right() {
88 return right_k || Joystick::right();
92 bool GameInputHandler::fire1() {
93 return fire1_k || Joystick::fire1();
97 bool GameInputHandler::fire2() {
98 return fire2_k || Joystick::fire2();