diff --git a/source/code/joypad.cpp b/source/code/joypad.cpp deleted file mode 100644 index 19c8e11..0000000 --- a/source/code/joypad.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.net -=========================================================================== -*/ - -#include "joypad.h" - -bool Joypad_init() { - if (0==SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { - return true; - } - else { - return false; - } -} - -Joypad_status Joypad_getStatus(SDL_Joystick* joystick) { - Joypad_status status; - for (int i=0; i=SDL_JoystickNumAxes(joystick)) { - status.padDown[i]=false; - status.padUp[i] = false; - status.padLeft[i] = false; - status.padRight[i] = false; - } - else { - //cout << SDL_JoystickGetAxis(joystick,i*2+1)<< endl; - if (SDL_JoystickGetAxis(joystick,i*2)<(-8000)) { - status.padLeft[i]=1; - } - else { - status.padLeft[i]=0; - } - if (SDL_JoystickGetAxis(joystick,i*2)>(8000)) { - status.padRight[i]=1; - } - else { - status.padRight[i]=0; - } - if (SDL_JoystickGetAxis(joystick,i*2+1)<(-8000)) { - status.padUp[i]=1; - } - else { - status.padUp[i]=0; - } - if (SDL_JoystickGetAxis(joystick,i*2+1)>(8000)) { - status.padDown[i]=1; - } - else { - status.padDown[i]=0; - } - } - }//NRofPADS - for (int i=0; i=SDL_JoystickNumButtons(joystick)) { - status.button[i]=false; - } - else if (1==SDL_JoystickGetButton(joystick,i)) { - status.button[i] = true; - } - else { - status.button[i] = false; - } - } - return status; -} - -Joypad::Joypad() { - up=false; - down=false; - left=false; - right=false; - but1=false; - but2=false; - upREL=true; - downREL=true; - leftREL=true; - rightREL=true; - but1REL=true; - but2REL=true; - int joynum = 0; - /*while ((SDL_JoystickOpened(joynum))&&(joynum=Joypad_number) { - working = false; - } - else { - joystick=SDL_JoystickOpen(joynum); - if (joystick==nullptr) { - working =false; - } - else { - working=true; - } - } -} - -Joypad::~Joypad() { - if (working) { - SDL_JoystickClose(joystick); - } -} - -void Joypad::update() { - SDL_JoystickUpdate(); - Joypad_status status = Joypad_getStatus(joystick); - if ((upREL)&&((status.padUp[0])||(status.padUp[1])||(status.padUp[2])||(status.padUp[3]))) { - up=true; - upREL=false; - } - else { - up=false; - } - if ((downREL)&&((status.padDown[0])||(status.padDown[1])||(status.padDown[2])||(status.padDown[3]))) { - down=true; - downREL=false; - } - else { - down=false; - } - if ((leftREL)&&((status.padLeft[0])||(status.padLeft[1])||(status.padLeft[2])||(status.padLeft[3]))) { - left=true; - leftREL=false; - } - else { - left=false; - } - if ((rightREL)&&((status.padRight[0])||(status.padRight[1])||(status.padRight[2])||(status.padRight[3]))) { - right=true; - rightREL=false; - } - else { - right=false; - } - if ((but1REL)&&((status.button[0])||(status.button[2])||(status.button[4])||(status.button[6]))) { - but1=true; - but1REL=false; - } - else { - but1=false; - } - if ((but2REL)&&((status.button[1])||(status.button[3])||(status.button[5])||(status.button[7]))) { - but2=true; - but2REL=false; - } - else { - but2=false; - } - //Now testing for up - if (!((status.padUp[0])||(status.padUp[1])||(status.padUp[2])||(status.padUp[3]))) { - upREL = true; - } - if (!((status.padDown[0])||(status.padDown[1])||(status.padDown[2])||(status.padDown[3]))) { - downREL = true; - } - if (!((status.padLeft[0])||(status.padLeft[1])||(status.padLeft[2])||(status.padLeft[3]))) { - leftREL = true; - } - if (!((status.padRight[0])||(status.padRight[1])||(status.padRight[2])||(status.padRight[3]))) { - rightREL= true; - } - if (!((status.button[0])||(status.button[2])||(status.button[4])||(status.button[6]))) { - but1REL = true; - } - if (!((status.button[1])||(status.button[3])||(status.button[5])||(status.button[7]))) { - but2REL = true; - } -} diff --git a/source/code/joypad.h b/source/code/joypad.h deleted file mode 100644 index cfaa5a1..0000000 --- a/source/code/joypad.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.net -=========================================================================== -*/ - -//headerfile joypad.h - -#include -#include -#include - -#define NRofPADS 4 -#define NRofBUTTONS 12 - -struct Joypad_status -{ - bool padLeft[NRofPADS]; - bool padRight[NRofPADS]; - bool padUp[NRofPADS]; - bool padDown[NRofPADS]; - bool button[NRofBUTTONS]; -}; - -//Contains the init code -bool Joypad_init(); - -//How many joypads are availble? -#define Joypad_number SDL_NumJoysticks() - -//Open a joystick -#define Joypad_open(X) SDL_JoystickOpen(X) - -//Returns the status of the joypad -Joypad_status Joypad_getStatus(SDL_Joystick); - -class Joypad -{ -private: - SDL_Joystick *joystick; - static int Joy_count; -public: - bool up,down,left,right,but1,but2; - bool upREL,downREL,leftREL,rightREL,but1REL,but2REL; - bool working; - - Joypad(); - ~Joypad(); - - void update(); -}; diff --git a/source/code/main.cpp b/source/code/main.cpp index 48ffee4..a139876 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -77,7 +77,6 @@ http://www.blockattack.net #include "highscore.h" //Stores highscores #include "ReadKeyboard.h" //Reads text from keyboard -#include "joypad.h" //Used for joypads #include "stats.h" //Saves general stats //#include "uploadReplay.h" //Takes care of everything libcurl related @@ -1575,10 +1574,6 @@ int main(int argc, char* argv[]) { SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); - Joypad_init(); //Prepare the joysticks - Joypad joypad1 = Joypad(); //Creates a joypad - Joypad joypad2 = Joypad(); //Creates a joypad - theTextManager = TextManager(); //Open Audio @@ -1630,8 +1625,6 @@ int main(int argc, char* argv[]) { SoundEnabled = (bool)configSettings->getInt("soundenabled"); mouseplay1 = (bool)configSettings->getInt("mouseplay1"); mouseplay2 = (bool)configSettings->getInt("mouseplay2"); - joyplay1 = (bool)configSettings->getInt("joypad1"); - joyplay2 = (bool)configSettings->getInt("joypad2"); if (configSettings->exists("sdl2_player1keyup")) { keySettings[0].up = (SDL_Keycode)configSettings->getInt("sdl2_player1keyup"); @@ -1830,9 +1823,6 @@ int runGame(int gametype, int level) { theGame.name = player1name; theGame2.name = player2name; - Joypad joypad1 = Joypad(); //Creates a joypad - Joypad joypad2 = Joypad(); //Creates a joypad - if (singlePuzzle) { LoadPuzzleStages(); BlockGameStartInfo s; @@ -2016,106 +2006,6 @@ int runGame(int gametype, int level) { } } //while event PollEvent - read keys - /********************************************************************** - ***************************** Joypad start **************************** - **********************************************************************/ - - //Gameplay - if (joyplay1||joyplay2) { - if (joypad1.working && !theGame.GetAIenabled()) { - if (joyplay1) { - joypad1.update(); - if (joypad1.up) { - theGame.MoveCursor('N'); - } - if (joypad1.down) { - theGame.MoveCursor('S'); - } - if (joypad1.left) { - theGame.MoveCursor('W'); - } - if (joypad1.right) { - theGame.MoveCursor('E'); - } - if (joypad1.but1) { - theGame.SwitchAtCursor(); - } - if (joypad1.but2) { - theGame.PushLine(); - } - } - else { - joypad1.update(); - if (joypad1.up) { - theGame2.MoveCursor('N'); - } - if (joypad1.down) { - theGame2.MoveCursor('S'); - } - if (joypad1.left) { - theGame2.MoveCursor('W'); - } - if (joypad1.right) { - theGame2.MoveCursor('E'); - } - if (joypad1.but1) { - theGame2.SwitchAtCursor(); - } - if (joypad1.but2) { - theGame2.PushLine(); - } - } - } - if (joypad2.working && !theGame2.GetAIenabled()) { - if (!joyplay2) { - joypad2.update(); - if (joypad2.up) { - theGame.MoveCursor('N'); - } - if (joypad2.down) { - theGame.MoveCursor('S'); - } - if (joypad2.left) { - theGame.MoveCursor('W'); - } - if (joypad2.right) { - theGame.MoveCursor('E'); - } - if (joypad2.but1) { - theGame.SwitchAtCursor(); - } - if (joypad2.but2) { - theGame.PushLine(); - } - } - else { - joypad2.update(); - if (joypad2.up) { - theGame2.MoveCursor('N'); - } - if (joypad2.down) { - theGame2.MoveCursor('S'); - } - if (joypad2.left) { - theGame2.MoveCursor('W'); - } - if (joypad2.right) { - theGame2.MoveCursor('E'); - } - if (joypad2.but1) { - theGame2.SwitchAtCursor(); - } - if (joypad2.but2) { - theGame2.PushLine(); - } - } - } - } - - /********************************************************************** - ***************************** Joypad end ****************************** - **********************************************************************/ - SDL_GetMouseState(&mousex,&mousey); /********************************************************************