GameState.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // Das Tank - Copyright (C) 2006, 2007 Windsor Schmidt <windsor@windsorworld.net>
00004 //
00005 // This program is free software; you can redistribute it and/or modify it
00006 // under the terms of the GNU General Public License as published by the Free
00007 // Software Foundation; either version 2 of the License, or (at your option)
00008 // any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful, but WITHOUT
00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 // more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along with
00016 // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017 // Place, Suite 330, Boston, MA 02111-1307 USA
00018 //
00020 
00021 
00022 #ifndef STDAFX
00023 #include "stdafx.h"
00024 #endif
00025 
00030 GameState::GameState(void)
00031 {
00032        iGreenHandicap = 0;
00033        iBrownHandicap = 0;
00034        iCurrentLevel = 1;
00035        iMaxLevel = 1;
00036        bFullScreen = RUN_FULLSCREEN;
00037        bAutoAdvanceLevel = true;
00038        iSFXLevel = DEFAULT_SFX_VOLUME;
00039        iBGMLevel = DEFAULT_BGM_VOLUME;
00040        char temp;
00041 
00042        iTotalJoysticks = SDL_NumJoysticks();     
00043        if(iTotalJoysticks > MAX_JOYSTICKS) { iTotalJoysticks = 4; }
00044 
00045        for(int i=0; i < MAX_JOYSTICKS; i++)
00046        {
00047 
00048               cJoystickNames[i] = (char *) malloc(sizeof(char) * 256);
00049 
00050               sprintf(cJoystickNames[i], "%s", SDL_JoystickName(i));
00051 
00052               for(int j = 0; cJoystickNames[i][ j ]; j++)
00053               {
00054                      cJoystickNames[i][j] = tolower(cJoystickNames[i][j]);
00055               }
00056 
00057               Joysticks[i] = SDL_JoystickOpen(i);
00058        }
00059 
00060        SDL_JoystickEventState(SDL_ENABLE);
00061 
00062        // assign joysticks to players dumbly
00063        if(iTotalJoysticks > 1)
00064        {
00065               iGreenPlayerJoystick = 0;
00066               iBrownPlayerJoystick = 1;
00067        }
00068        else if(iTotalJoysticks == 1) // got at least 1
00069        {
00070               iGreenPlayerJoystick = 0;
00071               iBrownPlayerJoystick = -1;
00072        }
00073        else
00074        {
00075               iGreenPlayerJoystick = -1;
00076               iBrownPlayerJoystick = -1;
00077        }
00078 
00079        World = NULL;
00080 
00081        UpdateMaxLevel();
00082 }
00083 
00087 void GameState::UpdateMaxLevel(void)
00088 {
00089        int i = 1;
00090        char filename[256];
00091        FILE * file;
00092 
00093        while(i < MAX_LEVELS) // try to open each level file to confirm its availability
00094        {
00095               sprintf_s(filename, "lvl\\%d.lvl", i); // get level filename from level #
00096               
00097               // open level file
00098               fopen_s(&file, filename, "r" );
00099 
00100               if(file == NULL)
00101               {
00102                      i--;
00103                      break;
00104               }
00105               else
00106               {
00107                      i++;
00108                      fclose(file);
00109               }
00110        }
00111 
00112        iMaxLevel = i; // update iMaxLevel to however far we got in the loop
00113 }

 

Copyright Windsor Schmidt 2006 - All rights reserved.