src/control/controller.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "control/controller.hpp"
00018 
00019 const char* Controller::controlNames[] = {
00020   "left",
00021   "right",
00022   "up",
00023   "down",
00024   "jump",
00025   "action",
00026   "pause-menu",
00027   "menu-select",
00028   "console",
00029   "peek-left",
00030   "peek-right",
00031   "peek-up",
00032   "peek-down",
00033   0
00034 };
00035 
00036 Controller::Controller()
00037 {
00038   reset();
00039 }
00040 
00041 Controller::~Controller()
00042 {}
00043 
00044 void
00045 Controller::reset()
00046 {
00047   for(int i = 0; i < CONTROLCOUNT; ++i) {
00048     controls[i] = false;
00049     oldControls[i] = false;
00050   }
00051 }
00052 
00053 void
00054 Controller::set_control(Control control, bool value)
00055 {
00056   controls[control] = value;
00057 }
00058 
00059 bool
00060 Controller::hold(Control control)
00061 {
00062   return controls[control];
00063 }
00064 
00065 bool
00066 Controller::pressed(Control control)
00067 {
00068   return !oldControls[control] && controls[control];
00069 }
00070 
00071 bool
00072 Controller::released(Control control)
00073 {
00074   return oldControls[control] && !controls[control];
00075 }
00076 
00077 void
00078 Controller::update()
00079 {
00080   for(int i = 0; i < CONTROLCOUNT; ++i)
00081     oldControls[i] = controls[i];
00082 }
00083 
00084 /* EOF */

Generated on Mon Jun 9 03:38:18 2014 for SuperTux by  doxygen 1.5.1