git repos / blockattack-game

blame: source/code/main.cpp

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
89c4a3a6 sago007 2008-08-29 14:32 2
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
89c4a3a6 sago007 2008-08-29 14:32 3
Copyright (C) 2008 Poul Sander
89c4a3a6 sago007 2008-08-29 14:32 4
89c4a3a6 sago007 2008-08-29 14:32 5
    This program is free software; you can redistribute it and/or modify
89c4a3a6 sago007 2008-08-29 14:32 6
    it under the terms of the GNU General Public License as published by
89c4a3a6 sago007 2008-08-29 14:32 7
    the Free Software Foundation; either version 2 of the License, or
89c4a3a6 sago007 2008-08-29 14:32 8
    (at your option) any later version.
89c4a3a6 sago007 2008-08-29 14:32 9
89c4a3a6 sago007 2008-08-29 14:32 10
    This program is distributed in the hope that it will be useful,
89c4a3a6 sago007 2008-08-29 14:32 11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
89c4a3a6 sago007 2008-08-29 14:32 12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89c4a3a6 sago007 2008-08-29 14:32 13
    GNU General Public License for more details.
89c4a3a6 sago007 2008-08-29 14:32 14
89c4a3a6 sago007 2008-08-29 14:32 15
    You should have received a copy of the GNU General Public License
89c4a3a6 sago007 2008-08-29 14:32 16
    along with this program; if not, write to the Free Software
89c4a3a6 sago007 2008-08-29 14:32 17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
89c4a3a6 sago007 2008-08-29 14:32 18
89c4a3a6 sago007 2008-08-29 14:32 19
    Poul Sander
89c4a3a6 sago007 2008-08-29 14:32 20
    R�vehjvej 36, V. 1111
89c4a3a6 sago007 2008-08-29 14:32 21
    2800 Kgs. Lyngby
89c4a3a6 sago007 2008-08-29 14:32 22
    DENMARK
89c4a3a6 sago007 2008-08-29 14:32 23
    blockattack@poulsander.com
89c4a3a6 sago007 2008-08-29 14:32 24
    http://blockattack.sf.net
89c4a3a6 sago007 2008-08-29 14:32 25
*/
89c4a3a6 sago007 2008-08-29 14:32 26
215ca7b3 sago007 2009-03-06 16:37 27
#include "common.h"
215ca7b3 sago007 2009-03-06 16:37 28
215ca7b3 sago007 2009-03-06 16:37 29
27ae0175 sago007 2009-01-30 06:02 30
#include <string.h>
27ae0175 sago007 2009-01-30 06:02 31
27ae0175 sago007 2009-01-30 06:02 32
1572de2b sago007 2008-09-11 18:15 33
#ifndef VERSION_NUMBER
e2de69cf sago007 2010-01-15 22:48 34
    #define VERSION_NUMBER "version 1.4.2 BETA"
1572de2b sago007 2008-09-11 18:15 35
#endif
89c4a3a6 sago007 2008-08-29 14:32 36
89c4a3a6 sago007 2008-08-29 14:32 37
//If DEBUG is defined: AI info and FPS will be written to screen
1572de2b sago007 2008-09-11 18:15 38
#ifndef DEBUG
2f30c381 sago007 2008-09-14 13:08 39
    #define DEBUG 0
1572de2b sago007 2008-09-11 18:15 40
#endif
89c4a3a6 sago007 2008-08-29 14:32 41
89c4a3a6 sago007 2008-08-29 14:32 42
//If NETWORK id defined: enet will be used
1572de2b sago007 2008-09-11 18:15 43
#ifndef NETWORK
1572de2b sago007 2008-09-11 18:15 44
    #define NETWORK 1
1572de2b sago007 2008-09-11 18:15 45
#endif
1572de2b sago007 2008-09-11 18:15 46
1572de2b sago007 2008-09-11 18:15 47
//Build-in level editor is still experimental!
1572de2b sago007 2008-09-11 18:15 48
#ifndef LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 49
    #define LEVELEDITOR 0
1572de2b sago007 2008-09-11 18:15 50
#endif
89c4a3a6 sago007 2008-08-29 14:32 51
2e57d791 sago007 2009-06-04 17:48 52
#define WITH_SDL 1
2e57d791 sago007 2009-06-04 17:48 53
aca2f4b0 sago007 2009-05-10 18:11 54
//Macros to convert surfaces (ffor faster drawing)
89c4a3a6 sago007 2008-08-29 14:32 55
#define CONVERT(n) tmp = SDL_DisplayFormat(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 56
#define CONVERTA(n) tmp = SDL_DisplayFormatAlpha(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 57
89c4a3a6 sago007 2008-08-29 14:32 58
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 59
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 60
#include <time.h>           //Used for srand()
769a41a0 sago007 2008-09-24 12:54 61
#include <sstream>          //Still used by itoa2
89c4a3a6 sago007 2008-08-29 14:32 62
#include <string>
89c4a3a6 sago007 2008-08-29 14:32 63
#include "SDL.h"            //The SDL libary, used for most things
89c4a3a6 sago007 2008-08-29 14:32 64
#include <SDL_mixer.h>      //Used for sound & music
89c4a3a6 sago007 2008-08-29 14:32 65
#include <SDL_image.h>      //To load PNG images!
41f02ab2 sago007 2009-05-10 21:40 66
#include <physfs.h>         //Abstract file system. To use containers
41f02ab2 sago007 2009-05-10 21:40 67
#include "physfs_stream.hpp" //To use C++ style file streams
47529580 sago007 2008-12-09 02:34 68
//#include "ttfont.h"        //To use True Type Fonts in SDL
89c4a3a6 sago007 2008-08-29 14:32 69
//#include "config.h"
89c4a3a6 sago007 2008-08-29 14:32 70
#include <vector>
95bc02ff sago007 2009-03-15 02:46 71
#include <SDL/SDL_timer.h>
78d03b38 sago007 2008-11-13 19:56 72
//#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 73
89c4a3a6 sago007 2008-08-29 14:32 74
//if SHAREDIR is not used we look in current directory
89c4a3a6 sago007 2008-08-29 14:32 75
#ifndef SHAREDIR
89c4a3a6 sago007 2008-08-29 14:32 76
#define SHAREDIR "."
89c4a3a6 sago007 2008-08-29 14:32 77
#endif
89c4a3a6 sago007 2008-08-29 14:32 78
89c4a3a6 sago007 2008-08-29 14:32 79
89c4a3a6 sago007 2008-08-29 14:32 80
89c4a3a6 sago007 2008-08-29 14:32 81
//enet things
1572de2b sago007 2008-09-11 18:15 82
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 83
#include "enet/enet.h"
89c4a3a6 sago007 2008-08-29 14:32 84
#endif
89c4a3a6 sago007 2008-08-29 14:32 85
//enet things end
89c4a3a6 sago007 2008-08-29 14:32 86
89c4a3a6 sago007 2008-08-29 14:32 87
#include "SFont.h"          //Used to write on screen
89c4a3a6 sago007 2008-08-29 14:32 88
#include "highscore.h"      //Stores highscores
89c4a3a6 sago007 2008-08-29 14:32 89
#include "ReadKeyboard.h"   //Reads text from keyboard
89c4a3a6 sago007 2008-08-29 14:32 90
#include "joypad.h"         //Used for joypads
89c4a3a6 sago007 2008-08-29 14:32 91
#include "listFiles.h"	    //Used to show files on screen
89c4a3a6 sago007 2008-08-29 14:32 92
#include "replay.h"			//Used for replays
89c4a3a6 sago007 2008-08-29 14:32 93
#include "stats.h"          //Saves general stats 
1572de2b sago007 2008-09-11 18:15 94
#if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 95
#include "editor/editorMain.hpp" //The level editor
1572de2b sago007 2008-09-11 18:15 96
#endif
bc9ea011 sago007 2009-04-12 17:43 97
//#include "uploadReplay.h"   //Takes care of everything libcurl related
89c4a3a6 sago007 2008-08-29 14:32 98
89c4a3a6 sago007 2008-08-29 14:32 99
#include "common.h"
89c4a3a6 sago007 2008-08-29 14:32 100
89c4a3a6 sago007 2008-08-29 14:32 101
/*******************************************************************************
89c4a3a6 sago007 2008-08-29 14:32 102
* All variables and constant has been moved to mainVars.hpp for the overview.  *
89c4a3a6 sago007 2008-08-29 14:32 103
*******************************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 104
#include "mainVars.hpp"
89c4a3a6 sago007 2008-08-29 14:32 105
89c4a3a6 sago007 2008-08-29 14:32 106
void MakeBackground(int,int);
89c4a3a6 sago007 2008-08-29 14:32 107
89c4a3a6 sago007 2008-08-29 14:32 108
void closeAllMenus()
89c4a3a6 sago007 2008-08-29 14:32 109
{
89c4a3a6 sago007 2008-08-29 14:32 110
    bNewGameOpen=false;          //show sub menues
89c4a3a6 sago007 2008-08-29 14:32 111
    bOptionsOpen=false;          //Show OptionsMenu (Configure and Select Puzzle)
89c4a3a6 sago007 2008-08-29 14:32 112
    b1playerOpen=false;			//show submenu
89c4a3a6 sago007 2008-08-29 14:32 113
    b2playersOpen=false;
89c4a3a6 sago007 2008-08-29 14:32 114
    bReplayOpen = false;
1572de2b sago007 2008-09-11 18:15 115
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 116
    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 117
#endif
89c4a3a6 sago007 2008-08-29 14:32 118
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 119
89c4a3a6 sago007 2008-08-29 14:32 120
}
89c4a3a6 sago007 2008-08-29 14:32 121
89c4a3a6 sago007 2008-08-29 14:32 122
64ea862c sago007 2009-05-05 02:45 123
SDL_Surface * IMG_Load2(char* path)
64ea862c sago007 2009-05-05 02:45 124
{
64ea862c sago007 2009-05-05 02:45 125
    if (!PHYSFS_exists(path))
64ea862c sago007 2009-05-05 02:45 126
    {
64ea862c sago007 2009-05-05 02:45 127
        cout << "File not in blockattack.data: " << path << endl;
64ea862c sago007 2009-05-05 02:45 128
        return NULL; //file doesn't exist
64ea862c sago007 2009-05-05 02:45 129
    }
64ea862c sago007 2009-05-05 02:45 130
64ea862c sago007 2009-05-05 02:45 131
    PHYSFS_file* myfile = PHYSFS_openRead(path);
64ea862c sago007 2009-05-05 02:45 132
64ea862c sago007 2009-05-05 02:45 133
    // Get the lenght of the file
64ea862c sago007 2009-05-05 02:45 134
    unsigned int m_size = PHYSFS_fileLength(myfile);
64ea862c sago007 2009-05-05 02:45 135
64ea862c sago007 2009-05-05 02:45 136
    // Get the file data.
64ea862c sago007 2009-05-05 02:45 137
    char *m_data = new char[m_size];
64ea862c sago007 2009-05-05 02:45 138
64ea862c sago007 2009-05-05 02:45 139
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
64ea862c sago007 2009-05-05 02:45 140
64ea862c sago007 2009-05-05 02:45 141
    if (length_read != (int)m_size)
64ea862c sago007 2009-05-05 02:45 142
    {
64ea862c sago007 2009-05-05 02:45 143
            delete [] m_data;
64ea862c sago007 2009-05-05 02:45 144
            m_data = 0;
64ea862c sago007 2009-05-05 02:45 145
            PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 146
            cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 147
            return NULL;
64ea862c sago007 2009-05-05 02:45 148
    }
89c4a3a6 sago007 2008-08-29 14:32 149
64ea862c sago007 2009-05-05 02:45 150
    PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 151
64ea862c sago007 2009-05-05 02:45 152
// And this is how you load an image from a memory buffer with SDL
64ea862c sago007 2009-05-05 02:45 153
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
64ea862c sago007 2009-05-05 02:45 154
64ea862c sago007 2009-05-05 02:45 155
    //The above might fail an return null.
64ea862c sago007 2009-05-05 02:45 156
    if(!rw)
64ea862c sago007 2009-05-05 02:45 157
    {
64ea862c sago007 2009-05-05 02:45 158
        delete [] m_data;
64ea862c sago007 2009-05-05 02:45 159
        m_data = 0;
64ea862c sago007 2009-05-05 02:45 160
        PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 161
        cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 162
        return NULL;
64ea862c sago007 2009-05-05 02:45 163
    }
64ea862c sago007 2009-05-05 02:45 164
adaf31bf sago007 2009-05-05 16:01 165
    SDL_Surface* surface = IMG_Load_RW(rw,true); //the second argument tells the function to three RWops
64ea862c sago007 2009-05-05 02:45 166
64ea862c sago007 2009-05-05 02:45 167
    return surface;
64ea862c sago007 2009-05-05 02:45 168
}
89c4a3a6 sago007 2008-08-29 14:32 169
866417ca sago007 2009-05-10 21:35 170
void UnloadImages();
866417ca sago007 2009-05-10 21:35 171
int InitImages();
866417ca sago007 2009-05-10 21:35 172
866417ca sago007 2009-05-10 21:35 173
static string oldThemePath = "default";
41f02ab2 sago007 2009-05-10 21:40 174
static bool loaded = false;
89c4a3a6 sago007 2008-08-29 14:32 175
89c4a3a6 sago007 2008-08-29 14:32 176
void loadTheme(string themeName)
89c4a3a6 sago007 2008-08-29 14:32 177
{
41f02ab2 sago007 2009-05-10 21:40 178
    if(loaded)
866417ca sago007 2009-05-10 21:35 179
        UnloadImages();
866417ca sago007 2009-05-10 21:35 180
#if defined(__unix__)
866417ca sago007 2009-05-10 21:35 181
    string home = (string)getenv("HOME")+(string)"/.gamesaves/blockattack";
866417ca sago007 2009-05-10 21:35 182
#elif defined(_WIN32)
866417ca sago007 2009-05-10 21:35 183
    string home = (string)getMyDocumentsPath()+(string)"/My Games/blockattack";
89c4a3a6 sago007 2008-08-29 14:32 184
#endif
866417ca sago007 2009-05-10 21:35 185
    //Remove old theme
866417ca sago007 2009-05-10 21:35 186
    PHYSFS_removeFromSearchPath(oldThemePath.c_str());
866417ca sago007 2009-05-10 21:35 187
    //Look in blockattack.data
866417ca sago007 2009-05-10 21:35 188
    PHYSFS_addToSearchPath(((string)SHAREDIR+"/blockattack.data").c_str(), 1);
866417ca sago007 2009-05-10 21:35 189
    //Look in folder
866417ca sago007 2009-05-10 21:35 190
    PHYSFS_addToSearchPath(SHAREDIR, 1);
866417ca sago007 2009-05-10 21:35 191
    //Look in home folder
866417ca sago007 2009-05-10 21:35 192
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 193
    PHYSFS_addToSearchPath(home.c_str(), 1);
866417ca sago007 2009-05-10 21:35 194
    #endif
2e57d791 sago007 2009-06-04 17:48 195
    if(themeName.compare(Config::getInstance()->getString("themename"))!=0)
2e57d791 sago007 2009-06-04 17:48 196
    {
2e57d791 sago007 2009-06-04 17:48 197
        //If this is a theme different from the saved one. Remember it!
2e57d791 sago007 2009-06-04 17:48 198
        Config::getInstance()->setString("themename",themeName);
2e57d791 sago007 2009-06-04 17:48 199
    }
866417ca sago007 2009-05-10 21:35 200
    if(themeName.compare("default")==0 || (themeName.compare("start")==0))
89c4a3a6 sago007 2008-08-29 14:32 201
    {
866417ca sago007 2009-05-10 21:35 202
        InitImages();
41f02ab2 sago007 2009-05-10 21:40 203
        loaded =true;
866417ca sago007 2009-05-10 21:35 204
        return; //Nothing more to do
89c4a3a6 sago007 2008-08-29 14:32 205
    }
866417ca sago007 2009-05-10 21:35 206
    oldThemePath = "themes/"+themeName;
866417ca sago007 2009-05-10 21:35 207
    PHYSFS_addToSearchPath(oldThemePath.c_str(),0);
866417ca sago007 2009-05-10 21:35 208
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 209
    PHYSFS_addToSearchPath((home+(string)"/"+oldThemePath).c_str(), 0);
89c4a3a6 sago007 2008-08-29 14:32 210
    #endif
866417ca sago007 2009-05-10 21:35 211
    InitImages();
41f02ab2 sago007 2009-05-10 21:40 212
    loaded = true;
89c4a3a6 sago007 2008-08-29 14:32 213
}
89c4a3a6 sago007 2008-08-29 14:32 214
47529580 sago007 2008-12-09 02:34 215
/*TTF_Font * TTF_OpenFont2(char* path, int ptsize) {
89c4a3a6 sago007 2008-08-29 14:32 216
89c4a3a6 sago007 2008-08-29 14:32 217
    char * tmp;
89c4a3a6 sago007 2008-08-29 14:32 218
    TTF_Font * ret=NULL;
89c4a3a6 sago007 2008-08-29 14:32 219
    tmp = (char*)malloc (sizeof(char)*(strlen(path)+strlen(sharedir)+2));
89c4a3a6 sago007 2008-08-29 14:32 220
    strcpy(tmp, sharedir);
89c4a3a6 sago007 2008-08-29 14:32 221
    strcat(tmp, "/");
89c4a3a6 sago007 2008-08-29 14:32 222
    strcat(tmp, path);
1572de2b sago007 2008-09-11 18:15 223
#if DEBUG
89c4a3a6 sago007 2008-08-29 14:32 224
    printf("loading %s\n",tmp);
89c4a3a6 sago007 2008-08-29 14:32 225
#endif
89c4a3a6 sago007 2008-08-29 14:32 226
    if(!(TTF_WasInit()))
89c4a3a6 sago007 2008-08-29 14:32 227
       TTF_Init();
89c4a3a6 sago007 2008-08-29 14:32 228
    if (!(ret = TTF_OpenFont(tmp, ptsize)))
89c4a3a6 sago007 2008-08-29 14:32 229
        ret = TTF_OpenFont(path, ptsize);
89c4a3a6 sago007 2008-08-29 14:32 230
    if(!ret)
89c4a3a6 sago007 2008-08-29 14:32 231
        cout << "failed to load font: " << TTF_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 232
    free(tmp);
89c4a3a6 sago007 2008-08-29 14:32 233
    return ret;
47529580 sago007 2008-12-09 02:34 234
}*/
89c4a3a6 sago007 2008-08-29 14:32 235
41f02ab2 sago007 2009-05-10 21:40 236
adaf31bf sago007 2009-05-05 16:01 237
Mix_Music * Mix_LoadMUS2(char* path)
adaf31bf sago007 2009-05-05 16:01 238
{
adaf31bf sago007 2009-05-05 16:01 239
    if (!PHYSFS_exists(path))
adaf31bf sago007 2009-05-05 16:01 240
    {
adaf31bf sago007 2009-05-05 16:01 241
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 242
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 243
    }
adaf31bf sago007 2009-05-05 16:01 244
adaf31bf sago007 2009-05-05 16:01 245
    PHYSFS_file* myfile = PHYSFS_openRead(path);
adaf31bf sago007 2009-05-05 16:01 246
adaf31bf sago007 2009-05-05 16:01 247
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 248
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 249
adaf31bf sago007 2009-05-05 16:01 250
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 251
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 252
adaf31bf sago007 2009-05-05 16:01 253
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 254
adaf31bf sago007 2009-05-05 16:01 255
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 256
    {
adaf31bf sago007 2009-05-05 16:01 257
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 258
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 259
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 260
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 261
            return NULL;
adaf31bf sago007 2009-05-05 16:01 262
    }
adaf31bf sago007 2009-05-05 16:01 263
adaf31bf sago007 2009-05-05 16:01 264
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 265
adaf31bf sago007 2009-05-05 16:01 266
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 267
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 268
adaf31bf sago007 2009-05-05 16:01 269
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 270
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 271
    {
adaf31bf sago007 2009-05-05 16:01 272
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 273
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 274
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 275
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 276
        return NULL;
adaf31bf sago007 2009-05-05 16:01 277
    }
adaf31bf sago007 2009-05-05 16:01 278
adaf31bf sago007 2009-05-05 16:01 279
    Mix_Music* ret = Mix_LoadMUS_RW(rw);
adaf31bf sago007 2009-05-05 16:01 280
adaf31bf sago007 2009-05-05 16:01 281
    return ret;
adaf31bf sago007 2009-05-05 16:01 282
}
89c4a3a6 sago007 2008-08-29 14:32 283
89c4a3a6 sago007 2008-08-29 14:32 284
adaf31bf sago007 2009-05-05 16:01 285
Mix_Chunk * Mix_LoadWAV2(char* path)
adaf31bf sago007 2009-05-05 16:01 286
{
adaf31bf sago007 2009-05-05 16:01 287
    if (!PHYSFS_exists(path))
adaf31bf sago007 2009-05-05 16:01 288
    {
adaf31bf sago007 2009-05-05 16:01 289
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 290
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 291
    }
adaf31bf sago007 2009-05-05 16:01 292
adaf31bf sago007 2009-05-05 16:01 293
    PHYSFS_file* myfile = PHYSFS_openRead(path);
adaf31bf sago007 2009-05-05 16:01 294
adaf31bf sago007 2009-05-05 16:01 295
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 296
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 297
adaf31bf sago007 2009-05-05 16:01 298
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 299
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 300
adaf31bf sago007 2009-05-05 16:01 301
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 302
adaf31bf sago007 2009-05-05 16:01 303
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 304
    {
adaf31bf sago007 2009-05-05 16:01 305
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 306
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 307
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 308
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 309
            return NULL;
adaf31bf sago007 2009-05-05 16:01 310
    }
adaf31bf sago007 2009-05-05 16:01 311
adaf31bf sago007 2009-05-05 16:01 312
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 313
adaf31bf sago007 2009-05-05 16:01 314
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 315
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 316
adaf31bf sago007 2009-05-05 16:01 317
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 318
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 319
    {
adaf31bf sago007 2009-05-05 16:01 320
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 321
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 322
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 323
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 324
        return NULL;
adaf31bf sago007 2009-05-05 16:01 325
    }
adaf31bf sago007 2009-05-05 16:01 326
adaf31bf sago007 2009-05-05 16:01 327
    Mix_Chunk* ret = Mix_LoadWAV_RW(rw,true); //the second argument tells the function to three RWops
adaf31bf sago007 2009-05-05 16:01 328
adaf31bf sago007 2009-05-05 16:01 329
    return ret;
adaf31bf sago007 2009-05-05 16:01 330
}
89c4a3a6 sago007 2008-08-29 14:32 331
89c4a3a6 sago007 2008-08-29 14:32 332
//Load all image files to memory
89c4a3a6 sago007 2008-08-29 14:32 333
int InitImages()
89c4a3a6 sago007 2008-08-29 14:32 334
{
89c4a3a6 sago007 2008-08-29 14:32 335
    if (!((backgroundImage = IMG_Load2((char*)"gfx/background.png"))
89c4a3a6 sago007 2008-08-29 14:32 336
            && (background = IMG_Load2((char*)"gfx/blackBackGround.png"))
89c4a3a6 sago007 2008-08-29 14:32 337
            && (bNewGame = IMG_Load2((char*)"gfx/bNewGame.png"))
89c4a3a6 sago007 2008-08-29 14:32 338
            && (b1player = IMG_Load2((char*)"gfx/bOnePlayer.png"))
89c4a3a6 sago007 2008-08-29 14:32 339
            && (b2players = IMG_Load2((char*)"gfx/bTwoPlayers.png"))
89c4a3a6 sago007 2008-08-29 14:32 340
            && (bVsMode = IMG_Load2((char*)"gfx/bVsGame.png"))
e3e0644e sago007 2008-09-25 14:00 341
            && (bVsModeConfig = IMG_Load2((char*)"gfx/bVsGameConfig.png"))
89c4a3a6 sago007 2008-08-29 14:32 342
            && (bPuzzle = IMG_Load2((char*)"gfx/bPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 343
            && (bStageClear = IMG_Load2((char*)"gfx/bStageClear.png"))
89c4a3a6 sago007 2008-08-29 14:32 344
            && (bTimeTrial = IMG_Load2((char*)"gfx/bTimeTrial.png"))
89c4a3a6 sago007 2008-08-29 14:32 345
            && (bEndless = IMG_Load2((char*)"gfx/bEndless.png"))
89c4a3a6 sago007 2008-08-29 14:32 346
            && (bOptions = IMG_Load2((char*)"gfx/bOptions.png"))
89c4a3a6 sago007 2008-08-29 14:32 347
            && (bConfigure = IMG_Load2((char*)"gfx/bConfigure.png"))
89c4a3a6 sago007 2008-08-29 14:32 348
            && (bSelectPuzzle = IMG_Load2((char*)"gfx/bSelectPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 349
            && (bHighScore = IMG_Load2((char*)"gfx/bHighScore.png"))
89c4a3a6 sago007 2008-08-29 14:32 350
            && (bExit = IMG_Load2((char*)"gfx/bExit.png"))
89c4a3a6 sago007 2008-08-29 14:32 351
            && (bBack = IMG_Load2((char*)"gfx/bBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 352
            && (bForward = IMG_Load2((char*)"gfx/bForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 353
            && (bReplay = IMG_Load2((char*)"gfx/bReplays.png"))
89c4a3a6 sago007 2008-08-29 14:32 354
            && (bSave = IMG_Load2((char*)"gfx/bSave.png"))
89c4a3a6 sago007 2008-08-29 14:32 355
            && (bLoad = IMG_Load2((char*)"gfx/bLoad.png"))
1572de2b sago007 2008-09-11 18:15 356
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 357
            && (bNetwork = IMG_Load2((char*)"gfx/bNetwork.png"))
89c4a3a6 sago007 2008-08-29 14:32 358
            && (bHost = IMG_Load2((char*)"gfx/bHost.png"))
89c4a3a6 sago007 2008-08-29 14:32 359
            && (bConnect = IMG_Load2((char*)"gfx/bConnect.png"))
89c4a3a6 sago007 2008-08-29 14:32 360
#endif
89c4a3a6 sago007 2008-08-29 14:32 361
            && (blackLine = IMG_Load2((char*)"gfx/blackLine.png"))
89c4a3a6 sago007 2008-08-29 14:32 362
            && (stageBobble = IMG_Load2((char*)"gfx/iStageClearLimit.png"))
a039f5c4 sago007 2008-09-19 23:12 363
            && (bricks[0] = IMG_Load2((char*)"gfx/bricks/blue.png"))
a039f5c4 sago007 2008-09-19 23:12 364
            && (bricks[1] = IMG_Load2((char*)"gfx/bricks/green.png"))
a039f5c4 sago007 2008-09-19 23:12 365
            && (bricks[2] = IMG_Load2((char*)"gfx/bricks/purple.png"))
a039f5c4 sago007 2008-09-19 23:12 366
            && (bricks[3] = IMG_Load2((char*)"gfx/bricks/red.png"))
a039f5c4 sago007 2008-09-19 23:12 367
            && (bricks[4] = IMG_Load2((char*)"gfx/bricks/turkish.png"))
a039f5c4 sago007 2008-09-19 23:12 368
            && (bricks[5] = IMG_Load2((char*)"gfx/bricks/yellow.png"))
a039f5c4 sago007 2008-09-19 23:12 369
            && (bricks[6] = IMG_Load2((char*)"gfx/bricks/grey.png"))
89c4a3a6 sago007 2008-08-29 14:32 370
            && (crossover = IMG_Load2((char*)"gfx/crossover.png"))
89c4a3a6 sago007 2008-08-29 14:32 371
            && (balls[0] = IMG_Load2((char*)"gfx/balls/ballBlue.png"))
89c4a3a6 sago007 2008-08-29 14:32 372
            && (balls[1] = IMG_Load2((char*)"gfx/balls/ballGreen.png"))
89c4a3a6 sago007 2008-08-29 14:32 373
            && (balls[2] = IMG_Load2((char*)"gfx/balls/ballPurple.png"))
89c4a3a6 sago007 2008-08-29 14:32 374
            && (balls[3] = IMG_Load2((char*)"gfx/balls/ballRed.png"))
89c4a3a6 sago007 2008-08-29 14:32 375
            && (balls[4] = IMG_Load2((char*)"gfx/balls/ballTurkish.png"))
89c4a3a6 sago007 2008-08-29 14:32 376
            && (balls[5] = IMG_Load2((char*)"gfx/balls/ballYellow.png"))
89c4a3a6 sago007 2008-08-29 14:32 377
            && (balls[6] = IMG_Load2((char*)"gfx/balls/ballGray.png"))
89c4a3a6 sago007 2008-08-29 14:32 378
            && (cursor[0] = IMG_Load2((char*)"gfx/animations/cursor/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 379
            && (cursor[1] = IMG_Load2((char*)"gfx/animations/cursor/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 380
            && (bomb[0] = IMG_Load2((char*)"gfx/animations/bomb/bomb_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 381
            && (bomb[1] = IMG_Load2((char*)"gfx/animations/bomb/bomb_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 382
            && (ready[0] = IMG_Load2((char*)"gfx/animations/ready/ready_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 383
            && (ready[1] = IMG_Load2((char*)"gfx/animations/ready/ready_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 384
            && (explosion[0] = IMG_Load2((char*)"gfx/animations/explosion/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 385
            && (explosion[1] = IMG_Load2((char*)"gfx/animations/explosion/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 386
            && (explosion[2] = IMG_Load2((char*)"gfx/animations/explosion/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 387
            && (explosion[3] = IMG_Load2((char*)"gfx/animations/explosion/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 388
            && (counter[0] = IMG_Load2((char*)"gfx/counter/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 389
            && (counter[1] = IMG_Load2((char*)"gfx/counter/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 390
            && (counter[2] = IMG_Load2((char*)"gfx/counter/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 391
            && (backBoard = IMG_Load2((char*)"gfx/BackBoard.png")) //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 392
            && (iGameOver = IMG_Load2((char*)"gfx/iGameOver.png"))
89c4a3a6 sago007 2008-08-29 14:32 393
            && (iWinner = IMG_Load2((char*)"gfx/iWinner.png"))
89c4a3a6 sago007 2008-08-29 14:32 394
            && (iDraw = IMG_Load2((char*)"gfx/iDraw.png"))
89c4a3a6 sago007 2008-08-29 14:32 395
            && (iLoser = IMG_Load2((char*)"gfx/iLoser.png"))
89c4a3a6 sago007 2008-08-29 14:32 396
            && (iChainBack = IMG_Load2((char*)"gfx/chainFrame.png"))
89c4a3a6 sago007 2008-08-29 14:32 397
            && (iBlueFont = IMG_Load2((char*)"gfx/24P_Arial_Blue.png"))
89c4a3a6 sago007 2008-08-29 14:32 398
            && (iSmallFont = IMG_Load2((char*)"gfx/14P_Arial_Angle_Red.png"))
89c4a3a6 sago007 2008-08-29 14:32 399
            && (optionsBack = IMG_Load2((char*)"gfx/options.png"))
89c4a3a6 sago007 2008-08-29 14:32 400
            && (bOn = IMG_Load2((char*)"gfx/bOn.png"))
89c4a3a6 sago007 2008-08-29 14:32 401
            && (bOff = IMG_Load2((char*)"gfx/bOff.png"))
89c4a3a6 sago007 2008-08-29 14:32 402
            && (bChange = IMG_Load2((char*)"gfx/bChange.png"))
89c4a3a6 sago007 2008-08-29 14:32 403
            && (b1024 = IMG_Load2((char*)"gfx/b1024.png"))
89c4a3a6 sago007 2008-08-29 14:32 404
            && (dialogBox = IMG_Load2((char*)"gfx/dialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 405
//	&& (fileDialogBox = IMG_Load2("gfx/fileDialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 406
            && (iLevelCheck = IMG_Load2((char*)"gfx/iLevelCheck.png"))
89c4a3a6 sago007 2008-08-29 14:32 407
            && (iLevelCheckBox = IMG_Load2((char*)"gfx/iLevelCheckBox.png"))
89c4a3a6 sago007 2008-08-29 14:32 408
            && (iCheckBoxArea = IMG_Load2((char*)"gfx/iCheckBoxArea.png"))
89c4a3a6 sago007 2008-08-29 14:32 409
            && (boardBackBack = IMG_Load2((char*)"gfx/boardBackBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 410
            && (changeButtonsBack = IMG_Load2((char*)"gfx/changeButtonsBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 411
            && (garbageTL = IMG_Load2((char*)"gfx/garbage/garbageTL.png"))
89c4a3a6 sago007 2008-08-29 14:32 412
            && (garbageT = IMG_Load2((char*)"gfx/garbage/garbageT.png"))
89c4a3a6 sago007 2008-08-29 14:32 413
            && (garbageTR = IMG_Load2((char*)"gfx/garbage/garbageTR.png"))
89c4a3a6 sago007 2008-08-29 14:32 414
            && (garbageR = IMG_Load2((char*)"gfx/garbage/garbageR.png"))
89c4a3a6 sago007 2008-08-29 14:32 415
            && (garbageBR = IMG_Load2((char*)"gfx/garbage/garbageBR.png"))
89c4a3a6 sago007 2008-08-29 14:32 416
            && (garbageB = IMG_Load2((char*)"gfx/garbage/garbageB.png"))
89c4a3a6 sago007 2008-08-29 14:32 417
            && (garbageBL = IMG_Load2((char*)"gfx/garbage/garbageBL.png"))
89c4a3a6 sago007 2008-08-29 14:32 418
            && (garbageL = IMG_Load2((char*)"gfx/garbage/garbageL.png"))
89c4a3a6 sago007 2008-08-29 14:32 419
            && (garbageFill = IMG_Load2((char*)"gfx/garbage/garbageFill.png"))
89c4a3a6 sago007 2008-08-29 14:32 420
            && (garbageML = IMG_Load2((char*)"gfx/garbage/garbageML.png"))
89c4a3a6 sago007 2008-08-29 14:32 421
            && (garbageM = IMG_Load2((char*)"gfx/garbage/garbageM.png"))
89c4a3a6 sago007 2008-08-29 14:32 422
            && (garbageMR = IMG_Load2((char*)"gfx/garbage/garbageMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 423
            && (garbageGM = IMG_Load2((char*)"gfx/garbage/garbageGM.png"))
89c4a3a6 sago007 2008-08-29 14:32 424
            && (garbageGML = IMG_Load2((char*)"gfx/garbage/garbageGML.png"))
89c4a3a6 sago007 2008-08-29 14:32 425
            && (garbageGMR = IMG_Load2((char*)"gfx/garbage/garbageGMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 426
            && (smiley[0] = IMG_Load2((char*)"gfx/smileys/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 427
            && (smiley[1] = IMG_Load2((char*)"gfx/smileys/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 428
            && (smiley[2] = IMG_Load2((char*)"gfx/smileys/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 429
            && (smiley[3] = IMG_Load2((char*)"gfx/smileys/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 430
            //new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 431
            && (transCover = IMG_Load2((char*)"gfx/transCover.png"))
1572de2b sago007 2008-09-11 18:15 432
            #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 433
            && (bCreateFile = IMG_Load2((char*)"gfx/editor/bCreateFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 434
            && (bDeletePuzzle = IMG_Load2((char*)"gfx/editor/bDeletePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 435
            && (bLoadFile = IMG_Load2((char*)"gfx/editor/bLoadFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 436
            && (bMoveBack = IMG_Load2((char*)"gfx/editor/bMoveBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 437
            && (bMoveDown = IMG_Load2((char*)"gfx/editor/bMoveDown.png"))
89c4a3a6 sago007 2008-08-29 14:32 438
            && (bMoveForward = IMG_Load2((char*)"gfx/editor/bMoveForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 439
            && (bMoveLeft = IMG_Load2((char*)"gfx/editor/bMoveLeft.png"))
89c4a3a6 sago007 2008-08-29 14:32 440
            && (bMoveRight = IMG_Load2((char*)"gfx/editor/bMoveRight.png"))
89c4a3a6 sago007 2008-08-29 14:32 441
            && (bMoveUp = IMG_Load2((char*)"gfx/editor/bMoveUp.png"))
89c4a3a6 sago007 2008-08-29 14:32 442
            && (bNewPuzzle = IMG_Load2((char*)"gfx/editor/bNewPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 443
            && (bSaveFileAs = IMG_Load2((char*)"gfx/editor/bSaveFileAs.png"))
89c4a3a6 sago007 2008-08-29 14:32 444
            && (bSavePuzzle = IMG_Load2((char*)"gfx/editor/bSavePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 445
            && (bSaveToFile = IMG_Load2((char*)"gfx/editor/bSaveToFile.png"))
1572de2b sago007 2008-09-11 18:15 446
            && (bTestPuzzle = IMG_Load2((char*)"gfx/editor/bTestPuzzle.png"))
1572de2b sago007 2008-09-11 18:15 447
            #endif
89c4a3a6 sago007 2008-08-29 14:32 448
            //end new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 449
            //new in 1.4.0
89c4a3a6 sago007 2008-08-29 14:32 450
            && (bTheme = IMG_Load2((char*)"gfx/bTheme.png"))
89c4a3a6 sago007 2008-08-29 14:32 451
            && (bSkip = IMG_Load2((char*)"gfx/bSkip.png"))
89c4a3a6 sago007 2008-08-29 14:32 452
            && (bNext = IMG_Load2((char*)"gfx/bNext.png"))
89c4a3a6 sago007 2008-08-29 14:32 453
            && (bRetry = IMG_Load2((char*)"gfx/bRetry.png"))
78d03b38 sago007 2008-11-13 19:56 454
            //&& (menuMarked = IMG_Load2((char*)"gfx/menu/marked.png"))
78d03b38 sago007 2008-11-13 19:56 455
            //&& (menuUnmarked = IMG_Load2((char*)"gfx/menu/unmarked.png"))
89c4a3a6 sago007 2008-08-29 14:32 456
            //end new in 1.4.0
89c4a3a6 sago007 2008-08-29 14:32 457
            && (mouse = IMG_Load2((char*)"gfx/mouse.png"))
89c4a3a6 sago007 2008-08-29 14:32 458
         ))
89c4a3a6 sago007 2008-08-29 14:32 459
        //if there was a problem ie. "File not found"
89c4a3a6 sago007 2008-08-29 14:32 460
    {
89c4a3a6 sago007 2008-08-29 14:32 461
        cout << "Error loading image file: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 462
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 463
    }
89c4a3a6 sago007 2008-08-29 14:32 464
89c4a3a6 sago007 2008-08-29 14:32 465
89c4a3a6 sago007 2008-08-29 14:32 466
    //Prepare for fast blittering!
89c4a3a6 sago007 2008-08-29 14:32 467
    CONVERT(background);
89c4a3a6 sago007 2008-08-29 14:32 468
    CONVERT(bNewGame);
89c4a3a6 sago007 2008-08-29 14:32 469
    CONVERT(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 470
    CONVERT(b1player);
89c4a3a6 sago007 2008-08-29 14:32 471
    CONVERT(b2players);
89c4a3a6 sago007 2008-08-29 14:32 472
    CONVERT(bVsMode);
e3e0644e sago007 2008-09-25 14:00 473
    CONVERT(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 474
    CONVERT(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 475
    CONVERT(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 476
    CONVERT(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 477
    CONVERT(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 478
    CONVERT(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 479
    CONVERTA(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 480
    CONVERTA(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 481
    CONVERTA(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 482
    CONVERTA(bSave);
89c4a3a6 sago007 2008-08-29 14:32 483
    CONVERTA(bLoad);
89c4a3a6 sago007 2008-08-29 14:32 484
    CONVERTA(bTheme);
89c4a3a6 sago007 2008-08-29 14:32 485
    CONVERTA(bSkip);
89c4a3a6 sago007 2008-08-29 14:32 486
    CONVERTA(bRetry);
89c4a3a6 sago007 2008-08-29 14:32 487
    CONVERTA(bNext);
78d03b38 sago007 2008-11-13 19:56 488
    //CONVERTA(menuMarked);
78d03b38 sago007 2008-11-13 19:56 489
    //CONVERTA(menuUnmarked);
1572de2b sago007 2008-09-11 18:15 490
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 491
    CONVERTA(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 492
    CONVERTA(bHost);
89c4a3a6 sago007 2008-08-29 14:32 493
    CONVERTA(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 494
#endif
89c4a3a6 sago007 2008-08-29 14:32 495
    CONVERT(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 496
    CONVERTA(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 497
    CONVERT(backBoard);
89c4a3a6 sago007 2008-08-29 14:32 498
    CONVERT(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 499
    CONVERTA(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 500
    CONVERTA(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 501
    CONVERTA(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 502
    CONVERTA(counter[0]);
89c4a3a6 sago007 2008-08-29 14:32 503
    CONVERTA(counter[1]);
89c4a3a6 sago007 2008-08-29 14:32 504
    CONVERTA(counter[2]);
89c4a3a6 sago007 2008-08-29 14:32 505
    CONVERTA(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 506
    CONVERT(bExit);
89c4a3a6 sago007 2008-08-29 14:32 507
    CONVERT(bOn);
89c4a3a6 sago007 2008-08-29 14:32 508
    CONVERT(bOff);
89c4a3a6 sago007 2008-08-29 14:32 509
    CONVERT(bChange);
89c4a3a6 sago007 2008-08-29 14:32 510
    CONVERT(b1024);
89c4a3a6 sago007 2008-08-29 14:32 511
    CONVERTA(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 512
//	CONVERTA(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 513
    CONVERTA(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 514
    CONVERT(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 515
    CONVERTA(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 516
    for (int i = 0;i<4;i++)
89c4a3a6 sago007 2008-08-29 14:32 517
    {
89c4a3a6 sago007 2008-08-29 14:32 518
        CONVERTA(explosion[i]);
89c4a3a6 sago007 2008-08-29 14:32 519
    }
89c4a3a6 sago007 2008-08-29 14:32 520
    for (int i = 0; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 521
    {
89c4a3a6 sago007 2008-08-29 14:32 522
        CONVERTA(bricks[i]);
89c4a3a6 sago007 2008-08-29 14:32 523
        CONVERTA(balls[i]);
89c4a3a6 sago007 2008-08-29 14:32 524
    }
89c4a3a6 sago007 2008-08-29 14:32 525
    CONVERTA(crossover);
89c4a3a6 sago007 2008-08-29 14:32 526
    CONVERTA(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 527
    CONVERTA(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 528
    CONVERTA(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 529
    CONVERTA(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 530
    CONVERTA(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 531
    CONVERTA(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 532
    CONVERTA(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 533
    CONVERTA(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 534
    CONVERTA(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 535
    CONVERTA(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 536
    CONVERTA(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 537
    CONVERTA(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 538
    CONVERTA(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 539
    CONVERTA(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 540
    CONVERTA(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 541
    CONVERTA(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 542
    CONVERTA(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 543
    CONVERTA(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 544
    CONVERTA(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 545
    CONVERTA(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 546
    CONVERTA(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 547
    CONVERTA(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 548
    CONVERTA(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 549
    CONVERTA(iBlueFont);
89c4a3a6 sago007 2008-08-29 14:32 550
    CONVERTA(iSmallFont);
89c4a3a6 sago007 2008-08-29 14:32 551
    CONVERTA(iGameOver);
89c4a3a6 sago007 2008-08-29 14:32 552
    CONVERTA(mouse);
89c4a3a6 sago007 2008-08-29 14:32 553
    CONVERTA(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 554
    CONVERTA(transCover);
89c4a3a6 sago007 2008-08-29 14:32 555
    //Editor:
1572de2b sago007 2008-09-11 18:15 556
    #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 557
    CONVERTA(bCreateFile);
89c4a3a6 sago007 2008-08-29 14:32 558
    CONVERTA(bDeletePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 559
    CONVERTA(bLoadFile);
89c4a3a6 sago007 2008-08-29 14:32 560
    CONVERTA(bMoveBack);
89c4a3a6 sago007 2008-08-29 14:32 561
    CONVERTA(bMoveDown);
89c4a3a6 sago007 2008-08-29 14:32 562
    CONVERTA(bMoveForward);
89c4a3a6 sago007 2008-08-29 14:32 563
    CONVERTA(bMoveLeft);
89c4a3a6 sago007 2008-08-29 14:32 564
    CONVERTA(bMoveRight);
89c4a3a6 sago007 2008-08-29 14:32 565
    CONVERTA(bMoveUp);
89c4a3a6 sago007 2008-08-29 14:32 566
    CONVERTA(bNewPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 567
    CONVERTA(bSaveFileAs);
89c4a3a6 sago007 2008-08-29 14:32 568
    CONVERTA(bSavePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 569
    CONVERTA(bSaveToFile);
1572de2b sago007 2008-09-11 18:15 570
    CONVERTA(bTestPuzzle);
1572de2b sago007 2008-09-11 18:15 571
    #endif
1572de2b sago007 2008-09-11 18:15 572
    
89c4a3a6 sago007 2008-08-29 14:32 573
    //Here comes the fonts:
89c4a3a6 sago007 2008-08-29 14:32 574
    fBlueFont = SFont_InitFont(iBlueFont);
89c4a3a6 sago007 2008-08-29 14:32 575
    fSmallFont = SFont_InitFont(iSmallFont);
89c4a3a6 sago007 2008-08-29 14:32 576
    
89c4a3a6 sago007 2008-08-29 14:32 577
    //And the ttf font:
78d03b38 sago007 2008-11-13 19:56 578
    /*TTF_Font *ttFont1 = TTF_OpenFont2((char*)"fonts/FreeSerif.ttf", 24);
78d03b38 sago007 2008-11-13 19:56 579
    TTF_SetFontStyle(ttFont1,TTF_STYLE_BOLD);
78d03b38 sago007 2008-11-13 19:56 580
    ttfont = TTFont(ttFont1);*/
89c4a3a6 sago007 2008-08-29 14:32 581
89c4a3a6 sago007 2008-08-29 14:32 582
//Loads the sound if sound present
89c4a3a6 sago007 2008-08-29 14:32 583
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 584
    {
89c4a3a6 sago007 2008-08-29 14:32 585
        //And here the music:
89c4a3a6 sago007 2008-08-29 14:32 586
        bgMusic = Mix_LoadMUS2((char*)"music/bgMusic.ogg");
6d48320c sago007 2009-03-28 17:06 587
        highbeatMusic = Mix_LoadMUS2((char*)"music/highbeat.ogg");
89c4a3a6 sago007 2008-08-29 14:32 588
        //the music... we just hope it exists, else the user won't hear anything
89c4a3a6 sago007 2008-08-29 14:32 589
        //Same goes for the sounds
89c4a3a6 sago007 2008-08-29 14:32 590
        boing = Mix_LoadWAV2((char*)"sound/pop.ogg");
89c4a3a6 sago007 2008-08-29 14:32 591
        applause = Mix_LoadWAV2((char*)"sound/applause.ogg");
89c4a3a6 sago007 2008-08-29 14:32 592
        photoClick = Mix_LoadWAV2((char*)"sound/cameraclick.ogg");
89c4a3a6 sago007 2008-08-29 14:32 593
        typingChunk = Mix_LoadWAV2((char*)"sound/typing.ogg");
89c4a3a6 sago007 2008-08-29 14:32 594
        counterChunk = Mix_LoadWAV2((char*)"sound/counter.ogg");
24a6ea5f sago007 2008-11-13 22:28 595
        counterFinalChunk = Mix_LoadWAV2((char*)"sound/counterFinal.ogg");
89c4a3a6 sago007 2008-08-29 14:32 596
    } //All sound has been loaded or not
89c4a3a6 sago007 2008-08-29 14:32 597
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 598
} //InitImages()
89c4a3a6 sago007 2008-08-29 14:32 599
89c4a3a6 sago007 2008-08-29 14:32 600
89c4a3a6 sago007 2008-08-29 14:32 601
//Unload images and fonts and sounds
89c4a3a6 sago007 2008-08-29 14:32 602
void UnloadImages()
89c4a3a6 sago007 2008-08-29 14:32 603
{
866417ca sago007 2009-05-10 21:35 604
    cout << "Unloading data..." << endl;
89c4a3a6 sago007 2008-08-29 14:32 605
    //Fonts and Sounds needs to be freed
89c4a3a6 sago007 2008-08-29 14:32 606
    SFont_FreeFont(fBlueFont);
89c4a3a6 sago007 2008-08-29 14:32 607
    SFont_FreeFont(fSmallFont);
89c4a3a6 sago007 2008-08-29 14:32 608
    if (!NoSound) //Only unload then it has been loaded!
89c4a3a6 sago007 2008-08-29 14:32 609
    {
866417ca sago007 2009-05-10 21:35 610
        Mix_HaltMusic();
89c4a3a6 sago007 2008-08-29 14:32 611
        Mix_FreeMusic(bgMusic);
6d48320c sago007 2009-03-28 17:06 612
        Mix_FreeMusic(highbeatMusic);
89c4a3a6 sago007 2008-08-29 14:32 613
        Mix_FreeChunk(boing);
89c4a3a6 sago007 2008-08-29 14:32 614
        Mix_FreeChunk(applause);
89c4a3a6 sago007 2008-08-29 14:32 615
        Mix_FreeChunk(photoClick);
89c4a3a6 sago007 2008-08-29 14:32 616
        Mix_FreeChunk(counterChunk);
24a6ea5f sago007 2008-11-13 22:28 617
        Mix_FreeChunk(counterFinalChunk);
89c4a3a6 sago007 2008-08-29 14:32 618
        Mix_FreeChunk(typingChunk);
89c4a3a6 sago007 2008-08-29 14:32 619
    }
89c4a3a6 sago007 2008-08-29 14:32 620
    //Free surfaces:
89c4a3a6 sago007 2008-08-29 14:32 621
    //I think this will crash, at least it happend to me...
866417ca sago007 2009-05-10 21:35 622
    //Chrashes no more. Caused by an undocumented double free
89c4a3a6 sago007 2008-08-29 14:32 623
    SDL_FreeSurface(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 624
    SDL_FreeSurface(background);
89c4a3a6 sago007 2008-08-29 14:32 625
    SDL_FreeSurface(bNewGame);
89c4a3a6 sago007 2008-08-29 14:32 626
    SDL_FreeSurface(b1player);
89c4a3a6 sago007 2008-08-29 14:32 627
    SDL_FreeSurface(b2players);
89c4a3a6 sago007 2008-08-29 14:32 628
    SDL_FreeSurface(bVsMode);
e3e0644e sago007 2008-09-25 14:00 629
    SDL_FreeSurface(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 630
    SDL_FreeSurface(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 631
    SDL_FreeSurface(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 632
    SDL_FreeSurface(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 633
    SDL_FreeSurface(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 634
    SDL_FreeSurface(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 635
    SDL_FreeSurface(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 636
    SDL_FreeSurface(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 637
    SDL_FreeSurface(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 638
    SDL_FreeSurface(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 639
    SDL_FreeSurface(bSave);
89c4a3a6 sago007 2008-08-29 14:32 640
    SDL_FreeSurface(bLoad);
1572de2b sago007 2008-09-11 18:15 641
    #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 642
    SDL_FreeSurface(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 643
    SDL_FreeSurface(bHost);
89c4a3a6 sago007 2008-08-29 14:32 644
    SDL_FreeSurface(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 645
    #endif
89c4a3a6 sago007 2008-08-29 14:32 646
    SDL_FreeSurface(bExit);
89c4a3a6 sago007 2008-08-29 14:32 647
    SDL_FreeSurface(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 648
    SDL_FreeSurface(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 649
    SDL_FreeSurface(bricks[0]);
89c4a3a6 sago007 2008-08-29 14:32 650
    SDL_FreeSurface(bricks[1]);
89c4a3a6 sago007 2008-08-29 14:32 651
    SDL_FreeSurface(bricks[2]);
89c4a3a6 sago007 2008-08-29 14:32 652
    SDL_FreeSurface(bricks[3]);
89c4a3a6 sago007 2008-08-29 14:32 653
    SDL_FreeSurface(bricks[4]);
89c4a3a6 sago007 2008-08-29 14:32 654
    SDL_FreeSurface(bricks[5]);
89c4a3a6 sago007 2008-08-29 14:32 655
    SDL_FreeSurface(bricks[6]);
89c4a3a6 sago007 2008-08-29 14:32 656
    SDL_FreeSurface(crossover);
89c4a3a6 sago007 2008-08-29 14:32 657
    SDL_FreeSurface(balls[0]);
89c4a3a6 sago007 2008-08-29 14:32 658
    SDL_FreeSurface(balls[1]);
89c4a3a6 sago007 2008-08-29 14:32 659
    SDL_FreeSurface(balls[2]);
89c4a3a6 sago007 2008-08-29 14:32 660
    SDL_FreeSurface(balls[3]);
89c4a3a6 sago007 2008-08-29 14:32 661
    SDL_FreeSurface(balls[4]);
89c4a3a6 sago007 2008-08-29 14:32 662
    SDL_FreeSurface(balls[5]);
89c4a3a6 sago007 2008-08-29 14:32 663
    SDL_FreeSurface(balls[6]);
89c4a3a6 sago007 2008-08-29 14:32 664
    SDL_FreeSurface(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 665
    SDL_FreeSurface(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 666
    SDL_FreeSurface(backBoard); //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 667
    SDL_FreeSurface(iGameOver);
89c4a3a6 sago007 2008-08-29 14:32 668
    SDL_FreeSurface(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 669
    SDL_FreeSurface(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 670
    SDL_FreeSurface(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 671
    SDL_FreeSurface(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 672
    //SDL_FreeSurface(iBlueFont); //Segfault
89c4a3a6 sago007 2008-08-29 14:32 673
    //SDL_FreeSurface(iSmallFont); //Segfault
89c4a3a6 sago007 2008-08-29 14:32 674
    SDL_FreeSurface(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 675
    SDL_FreeSurface(bOn);
89c4a3a6 sago007 2008-08-29 14:32 676
    SDL_FreeSurface(bOff);
89c4a3a6 sago007 2008-08-29 14:32 677
    SDL_FreeSurface(bChange);
89c4a3a6 sago007 2008-08-29 14:32 678
    SDL_FreeSurface(b1024);
89c4a3a6 sago007 2008-08-29 14:32 679
    SDL_FreeSurface(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 680
    //SDL_FreeSurface(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 681
    SDL_FreeSurface(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 682
    SDL_FreeSurface(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 683
    SDL_FreeSurface(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 684
    SDL_FreeSurface(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 685
    SDL_FreeSurface(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 686
    SDL_FreeSurface(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 687
    SDL_FreeSurface(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 688
    SDL_FreeSurface(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 689
    SDL_FreeSurface(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 690
    SDL_FreeSurface(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 691
    SDL_FreeSurface(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 692
    SDL_FreeSurface(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 693
    SDL_FreeSurface(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 694
    SDL_FreeSurface(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 695
    SDL_FreeSurface(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 696
    SDL_FreeSurface(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 697
    SDL_FreeSurface(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 698
    SDL_FreeSurface(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 699
    SDL_FreeSurface(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 700
    SDL_FreeSurface(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 701
    SDL_FreeSurface(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 702
    SDL_FreeSurface(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 703
    SDL_FreeSurface(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 704
    SDL_FreeSurface(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 705
    SDL_FreeSurface(transCover);
89c4a3a6 sago007 2008-08-29 14:32 706
    SDL_FreeSurface(mouse);
89c4a3a6 sago007 2008-08-29 14:32 707
    
89c4a3a6 sago007 2008-08-29 14:32 708
}
89c4a3a6 sago007 2008-08-29 14:32 709
89c4a3a6 sago007 2008-08-29 14:32 710
//Function to convert numbers to string
769a41a0 sago007 2008-09-24 12:54 711
/*string itoa(int num)
89c4a3a6 sago007 2008-08-29 14:32 712
{
89c4a3a6 sago007 2008-08-29 14:32 713
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 714
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 715
    return converter.str();
769a41a0 sago007 2008-09-24 12:54 716
}*/
89c4a3a6 sago007 2008-08-29 14:32 717
89c4a3a6 sago007 2008-08-29 14:32 718
//Function to convert numbers to string (2 diget)
89c4a3a6 sago007 2008-08-29 14:32 719
string itoa2(int num)
89c4a3a6 sago007 2008-08-29 14:32 720
{
89c4a3a6 sago007 2008-08-29 14:32 721
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 722
    if(num<10)
89c4a3a6 sago007 2008-08-29 14:32 723
        converter << "0";
89c4a3a6 sago007 2008-08-29 14:32 724
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 725
    return converter.str();
89c4a3a6 sago007 2008-08-29 14:32 726
}
89c4a3a6 sago007 2008-08-29 14:32 727
89c4a3a6 sago007 2008-08-29 14:32 728
/*Loads all the puzzle levels*/
89c4a3a6 sago007 2008-08-29 14:32 729
int LoadPuzzleStages()
89c4a3a6 sago007 2008-08-29 14:32 730
{
89c4a3a6 sago007 2008-08-29 14:32 731
    //if(puzzleLoaded)
89c4a3a6 sago007 2008-08-29 14:32 732
    //    return 1;
aca2f4b0 sago007 2009-05-10 18:11 733
    if (!PHYSFS_exists(("puzzles/"+puzzleName).c_str()))
aca2f4b0 sago007 2009-05-10 18:11 734
    {
aca2f4b0 sago007 2009-05-10 18:11 735
        cout << "File not in blockattack.data: " << ("puzzles/"+puzzleName) << endl;
aca2f4b0 sago007 2009-05-10 18:11 736
        return -1; //file doesn't exist
aca2f4b0 sago007 2009-05-10 18:11 737
    }
aca2f4b0 sago007 2009-05-10 18:11 738
    PhysFS::ifstream inFile(("puzzles/"+puzzleName).c_str());
aca2f4b0 sago007 2009-05-10 18:11 739
89c4a3a6 sago007 2008-08-29 14:32 740
    inFile >> nrOfPuzzles;
89c4a3a6 sago007 2008-08-29 14:32 741
    if (nrOfPuzzles>maxNrOfPuzzleStages)
89c4a3a6 sago007 2008-08-29 14:32 742
        nrOfPuzzles=maxNrOfPuzzleStages;
aca2f4b0 sago007 2009-05-10 18:11 743
    for (int k=0; (k<nrOfPuzzles) /*&&(!inFile.eof())*/ ; k++)
89c4a3a6 sago007 2008-08-29 14:32 744
    {
89c4a3a6 sago007 2008-08-29 14:32 745
        inFile >> nrOfMovesAllowed[k];
89c4a3a6 sago007 2008-08-29 14:32 746
        for (int i=11;i>=0;i--)
89c4a3a6 sago007 2008-08-29 14:32 747
            for (int j=0;j<6;j++)
89c4a3a6 sago007 2008-08-29 14:32 748
            {
89c4a3a6 sago007 2008-08-29 14:32 749
                inFile >> puzzleLevels[k][j][i];
89c4a3a6 sago007 2008-08-29 14:32 750
            }
89c4a3a6 sago007 2008-08-29 14:32 751
    }
89c4a3a6 sago007 2008-08-29 14:32 752
    puzzleLoaded = true;
89c4a3a6 sago007 2008-08-29 14:32 753
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 754
}
89c4a3a6 sago007 2008-08-29 14:32 755
89c4a3a6 sago007 2008-08-29 14:32 756
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
e1290bdf sago007 2010-10-25 19:56 757
void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 758
{
89c4a3a6 sago007 2008-08-29 14:32 759
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 760
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 761
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 762
    SDL_BlitSurface(img, NULL, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 763
}
89c4a3a6 sago007 2008-08-29 14:32 764
89c4a3a6 sago007 2008-08-29 14:32 765
/*Draws a part of an image on a surface of choice*/
89c4a3a6 sago007 2008-08-29 14:32 766
void DrawIMG(SDL_Surface *img, SDL_Surface * target, int x, int y, int w, int h, int x2, int y2)
89c4a3a6 sago007 2008-08-29 14:32 767
{
89c4a3a6 sago007 2008-08-29 14:32 768
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 769
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 770
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 771
    SDL_Rect dest2;
89c4a3a6 sago007 2008-08-29 14:32 772
    dest2.x = x2;
89c4a3a6 sago007 2008-08-29 14:32 773
    dest2.y = y2;
89c4a3a6 sago007 2008-08-29 14:32 774
    dest2.w = w;
89c4a3a6 sago007 2008-08-29 14:32 775
    dest2.h = h;
89c4a3a6 sago007 2008-08-29 14:32 776
    SDL_BlitSurface(img, &dest2, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 777
}
89c4a3a6 sago007 2008-08-29 14:32 778
78d03b38 sago007 2008-11-13 19:56 779
//Menu
78d03b38 sago007 2008-11-13 19:56 780
/*void PrintHi()
78d03b38 sago007 2008-11-13 19:56 781
{
78d03b38 sago007 2008-11-13 19:56 782
    cout << "Hi" <<endl;
78d03b38 sago007 2008-11-13 19:56 783
}
78d03b38 sago007 2008-11-13 19:56 784
78d03b38 sago007 2008-11-13 19:56 785
void InitMenues()
78d03b38 sago007 2008-11-13 19:56 786
{
78d03b38 sago007 2008-11-13 19:56 787
    ButtonGfx::setSurfaces(&menuMarked,&menuUnmarked);
78d03b38 sago007 2008-11-13 19:56 788
    ButtonGfx::ttf = &ttfont;
78d03b38 sago007 2008-11-13 19:56 789
}
78d03b38 sago007 2008-11-13 19:56 790
78d03b38 sago007 2008-11-13 19:56 791
void MainMenu()
78d03b38 sago007 2008-11-13 19:56 792
{
78d03b38 sago007 2008-11-13 19:56 793
    Menu m(&screen,true);
78d03b38 sago007 2008-11-13 19:56 794
    Button bHi;
78d03b38 sago007 2008-11-13 19:56 795
    bHi.setLabel("Write hi");
78d03b38 sago007 2008-11-13 19:56 796
    bHi.setAction(PrintHi);
78d03b38 sago007 2008-11-13 19:56 797
    m.addButton(bHi);
78d03b38 sago007 2008-11-13 19:56 798
    m.run();
78d03b38 sago007 2008-11-13 19:56 799
}*/
78d03b38 sago007 2008-11-13 19:56 800
89c4a3a6 sago007 2008-08-29 14:32 801
//The small things that are faaling when you clear something
89c4a3a6 sago007 2008-08-29 14:32 802
class aBall
89c4a3a6 sago007 2008-08-29 14:32 803
{
89c4a3a6 sago007 2008-08-29 14:32 804
private:
89c4a3a6 sago007 2008-08-29 14:32 805
    double x;
89c4a3a6 sago007 2008-08-29 14:32 806
    double y;
89c4a3a6 sago007 2008-08-29 14:32 807
    double velocityY;
89c4a3a6 sago007 2008-08-29 14:32 808
    double velocityX;
89c4a3a6 sago007 2008-08-29 14:32 809
    int color;
89c4a3a6 sago007 2008-08-29 14:32 810
    unsigned long int lastTime;
89c4a3a6 sago007 2008-08-29 14:32 811
public:
89c4a3a6 sago007 2008-08-29 14:32 812
89c4a3a6 sago007 2008-08-29 14:32 813
    aBall()
89c4a3a6 sago007 2008-08-29 14:32 814
    {}
89c4a3a6 sago007 2008-08-29 14:32 815
89c4a3a6 sago007 2008-08-29 14:32 816
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 817
    aBall(int X, int Y, bool right, int coulor)
89c4a3a6 sago007 2008-08-29 14:32 818
    {
89c4a3a6 sago007 2008-08-29 14:32 819
        double tal = 1.0;
89c4a3a6 sago007 2008-08-29 14:32 820
        velocityY = -tal*startVelocityY;
89c4a3a6 sago007 2008-08-29 14:32 821
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 822
        x = (double)X;
89c4a3a6 sago007 2008-08-29 14:32 823
        y = (double)Y;
89c4a3a6 sago007 2008-08-29 14:32 824
        color = coulor;
89c4a3a6 sago007 2008-08-29 14:32 825
        if (right)
89c4a3a6 sago007 2008-08-29 14:32 826
            velocityX = tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 827
        else
89c4a3a6 sago007 2008-08-29 14:32 828
            velocityX = -tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 829
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 830
89c4a3a6 sago007 2008-08-29 14:32 831
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 832
    ~aBall()
89c4a3a6 sago007 2008-08-29 14:32 833
    {
89c4a3a6 sago007 2008-08-29 14:32 834
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 835
89c4a3a6 sago007 2008-08-29 14:32 836
    void update()
89c4a3a6 sago007 2008-08-29 14:32 837
    {
89c4a3a6 sago007 2008-08-29 14:32 838
        double timePassed = (((double)(currentTime-lastTime))/1000.0);  //time passed in seconds
89c4a3a6 sago007 2008-08-29 14:32 839
        x = x+timePassed*velocityX;
89c4a3a6 sago007 2008-08-29 14:32 840
        y = y+timePassed*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 841
        velocityY = velocityY + gravity*timePassed;
89c4a3a6 sago007 2008-08-29 14:32 842
        if (y<1.0)
89c4a3a6 sago007 2008-08-29 14:32 843
            velocityY=10.0;
89c4a3a6 sago007 2008-08-29 14:32 844
        if ((velocityY>minVelocity) && (y>(double)(768-ballSize)) && (y<768.0))
89c4a3a6 sago007 2008-08-29 14:32 845
        {
89c4a3a6 sago007 2008-08-29 14:32 846
            velocityY = -0.70*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 847
            y = 768.0-ballSize;
89c4a3a6 sago007 2008-08-29 14:32 848
        }
89c4a3a6 sago007 2008-08-29 14:32 849
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 850
    }
89c4a3a6 sago007 2008-08-29 14:32 851
89c4a3a6 sago007 2008-08-29 14:32 852
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 853
    {
89c4a3a6 sago007 2008-08-29 14:32 854
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 855
    }
89c4a3a6 sago007 2008-08-29 14:32 856
89c4a3a6 sago007 2008-08-29 14:32 857
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 858
    {
89c4a3a6 sago007 2008-08-29 14:32 859
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 860
    }
89c4a3a6 sago007 2008-08-29 14:32 861
89c4a3a6 sago007 2008-08-29 14:32 862
    int getColor()
89c4a3a6 sago007 2008-08-29 14:32 863
    {
89c4a3a6 sago007 2008-08-29 14:32 864
        return color;
89c4a3a6 sago007 2008-08-29 14:32 865
    }
89c4a3a6 sago007 2008-08-29 14:32 866
};  //aBall
89c4a3a6 sago007 2008-08-29 14:32 867
6d48320c sago007 2009-03-28 17:06 868
const int maxNumberOfBalls = 6*12*2*2;
89c4a3a6 sago007 2008-08-29 14:32 869
89c4a3a6 sago007 2008-08-29 14:32 870
class ballManeger
89c4a3a6 sago007 2008-08-29 14:32 871
{
89c4a3a6 sago007 2008-08-29 14:32 872
public:
89c4a3a6 sago007 2008-08-29 14:32 873
    aBall ballArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 874
    bool ballUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 875
    //The old ball information is also saved so balls can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 876
    aBall oldBallArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 877
    bool oldBallUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 878
89c4a3a6 sago007 2008-08-29 14:32 879
    ballManeger()
89c4a3a6 sago007 2008-08-29 14:32 880
    {
89c4a3a6 sago007 2008-08-29 14:32 881
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 882
        {
89c4a3a6 sago007 2008-08-29 14:32 883
            ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 884
            oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 885
        }
89c4a3a6 sago007 2008-08-29 14:32 886
    }
89c4a3a6 sago007 2008-08-29 14:32 887
6d48320c sago007 2009-03-28 17:06 888
    //Adds a ball to the screen at given coordiantes, traveling right or not with color
89c4a3a6 sago007 2008-08-29 14:32 889
    int addBall(int x, int y,bool right,int color)
89c4a3a6 sago007 2008-08-29 14:32 890
    {
89c4a3a6 sago007 2008-08-29 14:32 891
        int ballNumber = 0;
6d48320c sago007 2009-03-28 17:06 892
        //Find a free ball
89c4a3a6 sago007 2008-08-29 14:32 893
        while ((ballUsed[ballNumber])&&(ballNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 894
            ballNumber++;
6d48320c sago007 2009-03-28 17:06 895
        //Could not find a free ball, return -1
89c4a3a6 sago007 2008-08-29 14:32 896
        if (ballNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 897
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 898
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 899
        ballArray[ballNumber] = aBall(x,y,right,color);
89c4a3a6 sago007 2008-08-29 14:32 900
        ballUsed[ballNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 901
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 902
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 903
89c4a3a6 sago007 2008-08-29 14:32 904
    void update()
89c4a3a6 sago007 2008-08-29 14:32 905
    {
89c4a3a6 sago007 2008-08-29 14:32 906
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 907
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 908
        {
89c4a3a6 sago007 2008-08-29 14:32 909
89c4a3a6 sago007 2008-08-29 14:32 910
            if (ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 911
            {
89c4a3a6 sago007 2008-08-29 14:32 912
                oldBallUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 913
                oldBallArray[i] = ballArray[i];
89c4a3a6 sago007 2008-08-29 14:32 914
                ballArray[i].update();
6d48320c sago007 2009-03-28 17:06 915
                if (ballArray[i].getY()>800 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize)
89c4a3a6 sago007 2008-08-29 14:32 916
                {
89c4a3a6 sago007 2008-08-29 14:32 917
                    ballArray[i].~aBall();
89c4a3a6 sago007 2008-08-29 14:32 918
                    ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 919
                    //cout << "Ball removed" << endl;
89c4a3a6 sago007 2008-08-29 14:32 920
                }
89c4a3a6 sago007 2008-08-29 14:32 921
            }
89c4a3a6 sago007 2008-08-29 14:32 922
            else
89c4a3a6 sago007 2008-08-29 14:32 923
            {
89c4a3a6 sago007 2008-08-29 14:32 924
                oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 925
            }
89c4a3a6 sago007 2008-08-29 14:32 926
        }
89c4a3a6 sago007 2008-08-29 14:32 927
    } //update
89c4a3a6 sago007 2008-08-29 14:32 928
89c4a3a6 sago007 2008-08-29 14:32 929
89c4a3a6 sago007 2008-08-29 14:32 930
}; //theBallManeger
89c4a3a6 sago007 2008-08-29 14:32 931
89c4a3a6 sago007 2008-08-29 14:32 932
ballManeger theBallManeger;
89c4a3a6 sago007 2008-08-29 14:32 933
89c4a3a6 sago007 2008-08-29 14:32 934
//a explosions, non moving
89c4a3a6 sago007 2008-08-29 14:32 935
class anExplosion
89c4a3a6 sago007 2008-08-29 14:32 936
{
89c4a3a6 sago007 2008-08-29 14:32 937
private:
89c4a3a6 sago007 2008-08-29 14:32 938
    int x;
89c4a3a6 sago007 2008-08-29 14:32 939
    int y;
89c4a3a6 sago007 2008-08-29 14:32 940
    Uint8 frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 941
#define frameLength 80
89c4a3a6 sago007 2008-08-29 14:32 942
    //How long an image in an animation should be showed
89c4a3a6 sago007 2008-08-29 14:32 943
#define maxFrame 4
89c4a3a6 sago007 2008-08-29 14:32 944
    //How many images there are in the animation
89c4a3a6 sago007 2008-08-29 14:32 945
    unsigned long int placeTime; //Then the explosion occored
89c4a3a6 sago007 2008-08-29 14:32 946
public:
89c4a3a6 sago007 2008-08-29 14:32 947
89c4a3a6 sago007 2008-08-29 14:32 948
    anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 949
    {}
89c4a3a6 sago007 2008-08-29 14:32 950
89c4a3a6 sago007 2008-08-29 14:32 951
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 952
    anExplosion(int X, int Y)
89c4a3a6 sago007 2008-08-29 14:32 953
    {
89c4a3a6 sago007 2008-08-29 14:32 954
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 955
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 956
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 957
        frameNumber=0;
89c4a3a6 sago007 2008-08-29 14:32 958
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 959
89c4a3a6 sago007 2008-08-29 14:32 960
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 961
    ~anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 962
    {
89c4a3a6 sago007 2008-08-29 14:32 963
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 964
89c4a3a6 sago007 2008-08-29 14:32 965
    //true if animation has played and object should be removed from the screen
89c4a3a6 sago007 2008-08-29 14:32 966
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 967
    {
89c4a3a6 sago007 2008-08-29 14:32 968
        frameNumber = (currentTime-placeTime)/frameLength;
89c4a3a6 sago007 2008-08-29 14:32 969
        return (!(frameNumber<maxFrame));
89c4a3a6 sago007 2008-08-29 14:32 970
    }
89c4a3a6 sago007 2008-08-29 14:32 971
89c4a3a6 sago007 2008-08-29 14:32 972
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 973
    {
89c4a3a6 sago007 2008-08-29 14:32 974
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 975
    }
89c4a3a6 sago007 2008-08-29 14:32 976
89c4a3a6 sago007 2008-08-29 14:32 977
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 978
    {
89c4a3a6 sago007 2008-08-29 14:32 979
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 980
    }
89c4a3a6 sago007 2008-08-29 14:32 981
89c4a3a6 sago007 2008-08-29 14:32 982
    int getFrame()
89c4a3a6 sago007 2008-08-29 14:32 983
    {
89c4a3a6 sago007 2008-08-29 14:32 984
        return frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 985
    }
89c4a3a6 sago007 2008-08-29 14:32 986
};  //nExplosion
89c4a3a6 sago007 2008-08-29 14:32 987
89c4a3a6 sago007 2008-08-29 14:32 988
class explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 989
{
89c4a3a6 sago007 2008-08-29 14:32 990
public:
89c4a3a6 sago007 2008-08-29 14:32 991
    anExplosion explosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 992
    bool explosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 993
    //The old explosion information is also saved so explosions can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 994
    anExplosion oldExplosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 995
    bool oldExplosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 996
89c4a3a6 sago007 2008-08-29 14:32 997
    explosionManeger()
89c4a3a6 sago007 2008-08-29 14:32 998
    {
89c4a3a6 sago007 2008-08-29 14:32 999
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1000
        {
89c4a3a6 sago007 2008-08-29 14:32 1001
            explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1002
            oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1003
        }
89c4a3a6 sago007 2008-08-29 14:32 1004
    }
89c4a3a6 sago007 2008-08-29 14:32 1005
89c4a3a6 sago007 2008-08-29 14:32 1006
    int addExplosion(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 1007
    {
89c4a3a6 sago007 2008-08-29 14:32 1008
        //cout << "Tries to add an explosion" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1009
        int explosionNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1010
        while ((explosionUsed[explosionNumber])&&(explosionNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 1011
            explosionNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1012
        if (explosionNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1013
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1014
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1015
        explosionArray[explosionNumber] = anExplosion(x,y);
89c4a3a6 sago007 2008-08-29 14:32 1016
        explosionUsed[explosionNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1017
        //cout << "Explosion added" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1018
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1019
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 1020
89c4a3a6 sago007 2008-08-29 14:32 1021
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1022
    {
89c4a3a6 sago007 2008-08-29 14:32 1023
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1024
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1025
        {
89c4a3a6 sago007 2008-08-29 14:32 1026
89c4a3a6 sago007 2008-08-29 14:32 1027
            if (explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1028
            {
89c4a3a6 sago007 2008-08-29 14:32 1029
                oldExplosionUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1030
                oldExplosionArray[i] = explosionArray[i];
89c4a3a6 sago007 2008-08-29 14:32 1031
                if (explosionArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1032
                {
89c4a3a6 sago007 2008-08-29 14:32 1033
                    explosionArray[i].~anExplosion();
89c4a3a6 sago007 2008-08-29 14:32 1034
                    explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1035
                    //cout << "Explosion removed" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1036
                }
89c4a3a6 sago007 2008-08-29 14:32 1037
            }
89c4a3a6 sago007 2008-08-29 14:32 1038
            else
89c4a3a6 sago007 2008-08-29 14:32 1039
            {
89c4a3a6 sago007 2008-08-29 14:32 1040
                oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1041
            }
89c4a3a6 sago007 2008-08-29 14:32 1042
        }
89c4a3a6 sago007 2008-08-29 14:32 1043
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1044
89c4a3a6 sago007 2008-08-29 14:32 1045
89c4a3a6 sago007 2008-08-29 14:32 1046
}; //explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1047
89c4a3a6 sago007 2008-08-29 14:32 1048
explosionManeger theExplosionManeger;
89c4a3a6 sago007 2008-08-29 14:32 1049
89c4a3a6 sago007 2008-08-29 14:32 1050
//text pop-up
89c4a3a6 sago007 2008-08-29 14:32 1051
class textMessage
89c4a3a6 sago007 2008-08-29 14:32 1052
{
89c4a3a6 sago007 2008-08-29 14:32 1053
private:
89c4a3a6 sago007 2008-08-29 14:32 1054
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1055
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1056
    char textt[10];
89c4a3a6 sago007 2008-08-29 14:32 1057
    unsigned long int time;
89c4a3a6 sago007 2008-08-29 14:32 1058
    unsigned long int placeTime; //Then the text was placed
89c4a3a6 sago007 2008-08-29 14:32 1059
public:
89c4a3a6 sago007 2008-08-29 14:32 1060
89c4a3a6 sago007 2008-08-29 14:32 1061
    textMessage()
89c4a3a6 sago007 2008-08-29 14:32 1062
    {}
89c4a3a6 sago007 2008-08-29 14:32 1063
89c4a3a6 sago007 2008-08-29 14:32 1064
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1065
    textMessage(int X, int Y,const char* Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1066
    {
89c4a3a6 sago007 2008-08-29 14:32 1067
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1068
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1069
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1070
        strncpy(textt,Text,10);
89c4a3a6 sago007 2008-08-29 14:32 1071
        textt[9]=0;
89c4a3a6 sago007 2008-08-29 14:32 1072
        time = Time;
89c4a3a6 sago007 2008-08-29 14:32 1073
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1074
89c4a3a6 sago007 2008-08-29 14:32 1075
    //true if the text has expired
89c4a3a6 sago007 2008-08-29 14:32 1076
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1077
    {
89c4a3a6 sago007 2008-08-29 14:32 1078
        return currentTime-placeTime>time;
89c4a3a6 sago007 2008-08-29 14:32 1079
    }
89c4a3a6 sago007 2008-08-29 14:32 1080
89c4a3a6 sago007 2008-08-29 14:32 1081
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1082
    {
89c4a3a6 sago007 2008-08-29 14:32 1083
        return x;
89c4a3a6 sago007 2008-08-29 14:32 1084
    }
89c4a3a6 sago007 2008-08-29 14:32 1085
89c4a3a6 sago007 2008-08-29 14:32 1086
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1087
    {
89c4a3a6 sago007 2008-08-29 14:32 1088
        return y;
89c4a3a6 sago007 2008-08-29 14:32 1089
    }
89c4a3a6 sago007 2008-08-29 14:32 1090
89c4a3a6 sago007 2008-08-29 14:32 1091
    char* getText()
89c4a3a6 sago007 2008-08-29 14:32 1092
    {
89c4a3a6 sago007 2008-08-29 14:32 1093
        return textt;
89c4a3a6 sago007 2008-08-29 14:32 1094
    }
89c4a3a6 sago007 2008-08-29 14:32 1095
};  //text popup
89c4a3a6 sago007 2008-08-29 14:32 1096
89c4a3a6 sago007 2008-08-29 14:32 1097
class textManeger
89c4a3a6 sago007 2008-08-29 14:32 1098
{
89c4a3a6 sago007 2008-08-29 14:32 1099
public:
89c4a3a6 sago007 2008-08-29 14:32 1100
    textMessage textArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1101
    bool textUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1102
    //The old text information is also saved so text can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1103
    textMessage oldTextArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1104
    bool oldTextUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1105
89c4a3a6 sago007 2008-08-29 14:32 1106
    textManeger()
89c4a3a6 sago007 2008-08-29 14:32 1107
    {
89c4a3a6 sago007 2008-08-29 14:32 1108
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1109
        {
89c4a3a6 sago007 2008-08-29 14:32 1110
            textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1111
            oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1112
        }
89c4a3a6 sago007 2008-08-29 14:32 1113
    }
89c4a3a6 sago007 2008-08-29 14:32 1114
89c4a3a6 sago007 2008-08-29 14:32 1115
    int addText(int x, int y,string Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1116
    {
89c4a3a6 sago007 2008-08-29 14:32 1117
        //cout << "Tries to add text" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1118
        int textNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1119
        while ((textNumber<maxNumberOfBalls)&&((textUsed[textNumber])||(oldTextUsed[textNumber])))
89c4a3a6 sago007 2008-08-29 14:32 1120
            textNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1121
        if (textNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1122
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1123
        //cout << "adding to: " << textNumber << ":" << textUsed[textNumber] << ":" << &textArray[textNumber] << endl;
89c4a3a6 sago007 2008-08-29 14:32 1124
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1125
        textArray[textNumber] = textMessage(x,y,Text.c_str(),Time);
89c4a3a6 sago007 2008-08-29 14:32 1126
        textUsed[textNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1127
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1128
    }  //addText
89c4a3a6 sago007 2008-08-29 14:32 1129
89c4a3a6 sago007 2008-08-29 14:32 1130
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1131
    {
89c4a3a6 sago007 2008-08-29 14:32 1132
        //cout << "Running update" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1133
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1134
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1135
        {
89c4a3a6 sago007 2008-08-29 14:32 1136
89c4a3a6 sago007 2008-08-29 14:32 1137
            if (textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1138
            {
89c4a3a6 sago007 2008-08-29 14:32 1139
                if (!oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1140
                {
89c4a3a6 sago007 2008-08-29 14:32 1141
                    oldTextUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1142
                    oldTextArray[i] = textMessage(textArray[i]);
89c4a3a6 sago007 2008-08-29 14:32 1143
                }
89c4a3a6 sago007 2008-08-29 14:32 1144
                if (textArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1145
                {
89c4a3a6 sago007 2008-08-29 14:32 1146
                    textArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1147
                    textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1148
                }
89c4a3a6 sago007 2008-08-29 14:32 1149
            }
89c4a3a6 sago007 2008-08-29 14:32 1150
            else
89c4a3a6 sago007 2008-08-29 14:32 1151
                if (oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1152
                {
89c4a3a6 sago007 2008-08-29 14:32 1153
                    oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1154
                    oldTextArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1155
                }
89c4a3a6 sago007 2008-08-29 14:32 1156
        }
89c4a3a6 sago007 2008-08-29 14:32 1157
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1158
89c4a3a6 sago007 2008-08-29 14:32 1159
89c4a3a6 sago007 2008-08-29 14:32 1160
}; //textManeger
89c4a3a6 sago007 2008-08-29 14:32 1161
89c4a3a6 sago007 2008-08-29 14:32 1162
textManeger theTextManeger;
89c4a3a6 sago007 2008-08-29 14:32 1163
89c4a3a6 sago007 2008-08-29 14:32 1164
//Here comes the Block Game object
89c4a3a6 sago007 2008-08-29 14:32 1165
#include "BlockGame.hpp"
17916a2e sago007 2010-11-07 11:26 1166
#include "BlockGame.cpp"
7ca669ac sago007 2008-12-09 16:30 1167
#include "SFont.h"
89c4a3a6 sago007 2008-08-29 14:32 1168
6b1dc7a6 sago007 2010-11-08 21:03 1169
class BlockGameSdl : public BlockGame {
6b1dc7a6 sago007 2010-11-08 21:03 1170
public:
6b1dc7a6 sago007 2010-11-08 21:03 1171
    SDL_Surface* sBoard;
6b1dc7a6 sago007 2010-11-08 21:03 1172
6b1dc7a6 sago007 2010-11-08 21:03 1173
    BlockGameSdl(int tx, int ty) {
6b1dc7a6 sago007 2010-11-08 21:03 1174
        tmp = IMG_Load2((char*)"gfx/BackBoard.png");
6b1dc7a6 sago007 2010-11-08 21:03 1175
        sBoard = SDL_DisplayFormat(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1176
        SDL_FreeSurface(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1177
        //BlockGame::BlockGame(tx,ty);
6b1dc7a6 sago007 2010-11-08 21:03 1178
        BlockGame::topx = tx;
6b1dc7a6 sago007 2010-11-08 21:03 1179
        BlockGame::topy = ty;
6b1dc7a6 sago007 2010-11-08 21:03 1180
    }
6b1dc7a6 sago007 2010-11-08 21:03 1181
    ~BlockGameSdl() {
6b1dc7a6 sago007 2010-11-08 21:03 1182
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1183
    }
6b1dc7a6 sago007 2010-11-08 21:03 1184
private:
6b1dc7a6 sago007 2010-11-08 21:03 1185
    void convertSurface() {
6b1dc7a6 sago007 2010-11-08 21:03 1186
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1187
        sBoard = SDL_DisplayFormat(backBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1188
    }
6b1dc7a6 sago007 2010-11-08 21:03 1189
    //Draws all the bricks to the board (including garbage)
6b1dc7a6 sago007 2010-11-08 21:03 1190
    void PaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1191
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1192
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1193
                if ((board[j][i]%10 != -1) && (board[j][i]%10 < 7) && ((board[j][i]/1000000)%10==0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1194
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1195
                    if ((board[j][i]/BLOCKWAIT)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1196
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1197
                    if ((board[j][i]/BLOCKHANG)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1198
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1199
6b1dc7a6 sago007 2010-11-08 21:03 1200
                }
6b1dc7a6 sago007 2010-11-08 21:03 1201
                if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1202
                    int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1203
                    int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1204
                    if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1205
                    else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1206
                    if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1207
                    else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1208
                    if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1209
                    else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1210
                    if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1211
                    else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1212
                    if ((left == number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1213
                        DrawIMG(garbageFill, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1214
                    if ((left != number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1215
                        DrawIMG(garbageL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1216
                    if ((left == number)&&(right != number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1217
                        DrawIMG(garbageR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1218
                    if ((left == number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1219
                        DrawIMG(garbageT, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1220
                    if ((left == number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1221
                        DrawIMG(garbageB, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1222
                    if ((left != number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1223
                        DrawIMG(garbageTL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1224
                    if ((left != number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1225
                        DrawIMG(garbageBL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1226
                    if ((left == number)&&(right != number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1227
                        DrawIMG(garbageTR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1228
                    if ((left == number)&&(right != number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1229
                        DrawIMG(garbageBR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1230
                    if ((left == number)&&(right != number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1231
                        DrawIMG(garbageMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1232
                    if ((left == number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1233
                        DrawIMG(garbageM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1234
                    if ((left != number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1235
                        DrawIMG(garbageML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1236
                }
6b1dc7a6 sago007 2010-11-08 21:03 1237
                if ((board[j][i]/1000000)%10==2) {
6b1dc7a6 sago007 2010-11-08 21:03 1238
                    if (j==0)
6b1dc7a6 sago007 2010-11-08 21:03 1239
                        DrawIMG(garbageGML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1240
                    else
6b1dc7a6 sago007 2010-11-08 21:03 1241
                        if (j==5)
6b1dc7a6 sago007 2010-11-08 21:03 1242
                            DrawIMG(garbageGMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1243
                        else
6b1dc7a6 sago007 2010-11-08 21:03 1244
                            DrawIMG(garbageGM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1245
                }
6b1dc7a6 sago007 2010-11-08 21:03 1246
            }
6b1dc7a6 sago007 2010-11-08 21:03 1247
        const int j = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1248
6b1dc7a6 sago007 2010-11-08 21:03 1249
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1250
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1251
            if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1252
                int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1253
                int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1254
                if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1255
                else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1256
                if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1257
                else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1258
                if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1259
                else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1260
                if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1261
                else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1262
                if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1263
                    DrawIMG(smiley[board[j][i]%4], sBoard, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1264
                }
6b1dc7a6 sago007 2010-11-08 21:03 1265
                if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1266
                {
6b1dc7a6 sago007 2010-11-08 21:03 1267
                    garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1268
                }
6b1dc7a6 sago007 2010-11-08 21:03 1269
                else {
6b1dc7a6 sago007 2010-11-08 21:03 1270
                    //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1271
                    garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1272
                }
6b1dc7a6 sago007 2010-11-08 21:03 1273
6b1dc7a6 sago007 2010-11-08 21:03 1274
            }
6b1dc7a6 sago007 2010-11-08 21:03 1275
        }
6b1dc7a6 sago007 2010-11-08 21:03 1276
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1277
            if (board[i][0]!=-1)
6b1dc7a6 sago007 2010-11-08 21:03 1278
                DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant
6b1dc7a6 sago007 2010-11-08 21:03 1279
6b1dc7a6 sago007 2010-11-08 21:03 1280
    }
6b1dc7a6 sago007 2010-11-08 21:03 1281
    //Paints the bricks gotten from a replay/net package
6b1dc7a6 sago007 2010-11-08 21:03 1282
    void SimplePaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1283
        /*
6b1dc7a6 sago007 2010-11-08 21:03 1284
         * We will need to mark the blocks that must have a bomb, we will here need to see, what is falling
6b1dc7a6 sago007 2010-11-08 21:03 1285
         */
6b1dc7a6 sago007 2010-11-08 21:03 1286
        bool bbomb[6][13]; //has a bomb on it!
6b1dc7a6 sago007 2010-11-08 21:03 1287
        bool falling[6][13]; //this is falling
6b1dc7a6 sago007 2010-11-08 21:03 1288
        bool getReady[6][13]; //getReady
6b1dc7a6 sago007 2010-11-08 21:03 1289
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1290
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1291
                bbomb[i][j]=false; //All false by default
6b1dc7a6 sago007 2010-11-08 21:03 1292
                falling[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1293
                if (board[i][j]>29)
6b1dc7a6 sago007 2010-11-08 21:03 1294
                    getReady[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1295
                else
6b1dc7a6 sago007 2010-11-08 21:03 1296
                    getReady[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1297
            }
6b1dc7a6 sago007 2010-11-08 21:03 1298
        //See that is falling
6b1dc7a6 sago007 2010-11-08 21:03 1299
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1300
            bool rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1301
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1302
                if (rowFalling)
6b1dc7a6 sago007 2010-11-08 21:03 1303
                    falling[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1304
                if ((!rowFalling)&&(board[i][j]%30==-1))
6b1dc7a6 sago007 2010-11-08 21:03 1305
                    rowFalling = true;
6b1dc7a6 sago007 2010-11-08 21:03 1306
                if ((rowFalling)&&(board[i][j]%30>6))
6b1dc7a6 sago007 2010-11-08 21:03 1307
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1308
                if (getReady[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1309
                    falling[i][j]=true; //getReady is the same as falling
6b1dc7a6 sago007 2010-11-08 21:03 1310
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1311
                }
6b1dc7a6 sago007 2010-11-08 21:03 1312
            }
6b1dc7a6 sago007 2010-11-08 21:03 1313
        }
6b1dc7a6 sago007 2010-11-08 21:03 1314
        //Now looking at rows:
6b1dc7a6 sago007 2010-11-08 21:03 1315
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1316
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1317
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1318
            for (int j=1;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1319
                if ((board[i][j]%30==color)&&(!falling[i][j]))
6b1dc7a6 sago007 2010-11-08 21:03 1320
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1321
                else
6b1dc7a6 sago007 2010-11-08 21:03 1322
                    if (falling[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1323
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1324
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1325
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1326
                        color=board[i][j]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1327
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1328
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1329
                if ((count>2)&&(color>-1)&&(color)<7) {
6b1dc7a6 sago007 2010-11-08 21:03 1330
                    bbomb[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1331
                    bbomb[i][j-1]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1332
                    bbomb[i][j-2]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1333
                }
6b1dc7a6 sago007 2010-11-08 21:03 1334
            }
6b1dc7a6 sago007 2010-11-08 21:03 1335
        }
6b1dc7a6 sago007 2010-11-08 21:03 1336
        //now looking for lines
6b1dc7a6 sago007 2010-11-08 21:03 1337
        for (int i=1;i<13;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1338
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1339
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1340
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1341
                if ((board[j][i]%30==color)&&(!falling[j][i]))
6b1dc7a6 sago007 2010-11-08 21:03 1342
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1343
                else
6b1dc7a6 sago007 2010-11-08 21:03 1344
                    if (falling[j][i]) {
6b1dc7a6 sago007 2010-11-08 21:03 1345
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1346
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1347
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1348
                        color=board[j][i]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1349
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1350
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1351
                if ((count>2)&&(color>-1)&&(color<7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1352
                    bbomb[j][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1353
                    bbomb[j-1][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1354
                    bbomb[j-2][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1355
                }
6b1dc7a6 sago007 2010-11-08 21:03 1356
            }
6b1dc7a6 sago007 2010-11-08 21:03 1357
        }
6b1dc7a6 sago007 2010-11-08 21:03 1358
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1359
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1360
                if ((board[j][i]%10 != -1) && (board[j][i]%30 < 7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1361
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1362
                    if (bbomb[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1363
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1364
                    if (getReady[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1365
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1366
                }
6b1dc7a6 sago007 2010-11-08 21:03 1367
                if (board[j][i]%30>6) {
6b1dc7a6 sago007 2010-11-08 21:03 1368
                    if (board[j][i]%30==7)
6b1dc7a6 sago007 2010-11-08 21:03 1369
                        DrawIMG(garbageR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1370
                    if (board[j][i]%30==9)
6b1dc7a6 sago007 2010-11-08 21:03 1371
                        DrawIMG(garbageML, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1372
                    if (board[j][i]%30==10)
6b1dc7a6 sago007 2010-11-08 21:03 1373
                        DrawIMG(garbageMR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1374
                    if (board[j][i]%30==11)
6b1dc7a6 sago007 2010-11-08 21:03 1375
                        DrawIMG(garbageTR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1376
                    if (board[j][i]%30==12)
6b1dc7a6 sago007 2010-11-08 21:03 1377
                        DrawIMG(garbageTL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1378
                    if (board[j][i]%30==13)
6b1dc7a6 sago007 2010-11-08 21:03 1379
                        DrawIMG(garbageBL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1380
                    if (board[j][i]%30==14)
6b1dc7a6 sago007 2010-11-08 21:03 1381
                        DrawIMG(garbageBR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1382
                    if (board[j][i]%30==15)
6b1dc7a6 sago007 2010-11-08 21:03 1383
                        DrawIMG(garbageM, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1384
                    if (board[j][i]%30==16)
6b1dc7a6 sago007 2010-11-08 21:03 1385
                        DrawIMG(garbageFill, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1386
                    if (board[j][i]%30==17)
6b1dc7a6 sago007 2010-11-08 21:03 1387
                        DrawIMG(garbageT, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1388
                    if (board[j][i]%30==18)
6b1dc7a6 sago007 2010-11-08 21:03 1389
                        DrawIMG(garbageB, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1390
                    if (board[j][i]%30==19)
6b1dc7a6 sago007 2010-11-08 21:03 1391
                        DrawIMG(garbageL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1392
                    if (board[j][i]%30==20)
6b1dc7a6 sago007 2010-11-08 21:03 1393
                        switch(j) {
6b1dc7a6 sago007 2010-11-08 21:03 1394
                            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1395
                                DrawIMG(garbageGML, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1396
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1397
                            case 5:
6b1dc7a6 sago007 2010-11-08 21:03 1398
                                DrawIMG(garbageGMR, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1399
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1400
                            default:
6b1dc7a6 sago007 2010-11-08 21:03 1401
                                DrawIMG(garbageGM, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1402
                        }
6b1dc7a6 sago007 2010-11-08 21:03 1403
                    //cout << "IS: " << board[j][i] << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1404
                }
6b1dc7a6 sago007 2010-11-08 21:03 1405
6b1dc7a6 sago007 2010-11-08 21:03 1406
6b1dc7a6 sago007 2010-11-08 21:03 1407
            }
6b1dc7a6 sago007 2010-11-08 21:03 1408
6b1dc7a6 sago007 2010-11-08 21:03 1409
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1410
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1411
            if ((board[0][i]%30==12)&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1412
                DrawIMG(smiley[0], sBoard, 2*bsize, bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1413
            }
6b1dc7a6 sago007 2010-11-08 21:03 1414
            if (board[0][i]%30!=19) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1415
            {
6b1dc7a6 sago007 2010-11-08 21:03 1416
                garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1417
            }
6b1dc7a6 sago007 2010-11-08 21:03 1418
            else {
6b1dc7a6 sago007 2010-11-08 21:03 1419
                //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1420
                garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1421
            }
6b1dc7a6 sago007 2010-11-08 21:03 1422
6b1dc7a6 sago007 2010-11-08 21:03 1423
        }
6b1dc7a6 sago007 2010-11-08 21:03 1424
    }
6b1dc7a6 sago007 2010-11-08 21:03 1425
public:
6b1dc7a6 sago007 2010-11-08 21:03 1426
    //Draws everything
6b1dc7a6 sago007 2010-11-08 21:03 1427
    void DoPaintJob() {
6b1dc7a6 sago007 2010-11-08 21:03 1428
        DrawIMG(backBoard, sBoard, 0, 0);
6b1dc7a6 sago007 2010-11-08 21:03 1429
        #if NETWORK
6b1dc7a6 sago007 2010-11-08 21:03 1430
        if ((!bReplaying)&&(!bNetworkPlayer))
6b1dc7a6 sago007 2010-11-08 21:03 1431
        #else
6b1dc7a6 sago007 2010-11-08 21:03 1432
        if (!bReplaying)
6b1dc7a6 sago007 2010-11-08 21:03 1433
        #endif
6b1dc7a6 sago007 2010-11-08 21:03 1434
            PaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1435
        else
6b1dc7a6 sago007 2010-11-08 21:03 1436
            SimplePaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1437
        if (stageClear) DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1);
6b1dc7a6 sago007 2010-11-08 21:03 1438
        if (puzzleMode&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1439
            //We need to write nr. of moves left!
6b1dc7a6 sago007 2010-11-08 21:03 1440
            strHolder = "Moves left: " + itoa(MovesLeft);
6b1dc7a6 sago007 2010-11-08 21:03 1441
            SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1442
        }
6b1dc7a6 sago007 2010-11-08 21:03 1443
        if(puzzleMode && stageButtonStatus == SBpuzzleMode)
6b1dc7a6 sago007 2010-11-08 21:03 1444
        {
6b1dc7a6 sago007 2010-11-08 21:03 1445
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1446
            if(Level<nrOfPuzzles-1)
6b1dc7a6 sago007 2010-11-08 21:03 1447
            {
6b1dc7a6 sago007 2010-11-08 21:03 1448
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1449
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1450
                else
6b1dc7a6 sago007 2010-11-08 21:03 1451
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1452
            }
6b1dc7a6 sago007 2010-11-08 21:03 1453
            else
6b1dc7a6 sago007 2010-11-08 21:03 1454
            {
6b1dc7a6 sago007 2010-11-08 21:03 1455
                strHolder = "Last puzzle";
6b1dc7a6 sago007 2010-11-08 21:03 1456
                SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1457
            }
6b1dc7a6 sago007 2010-11-08 21:03 1458
        }
6b1dc7a6 sago007 2010-11-08 21:03 1459
        if(stageClear && stageButtonStatus == SBstageClear)
6b1dc7a6 sago007 2010-11-08 21:03 1460
        {
6b1dc7a6 sago007 2010-11-08 21:03 1461
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1462
            if(Level<50-1)
6b1dc7a6 sago007 2010-11-08 21:03 1463
            {
6b1dc7a6 sago007 2010-11-08 21:03 1464
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1465
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1466
                else
6b1dc7a6 sago007 2010-11-08 21:03 1467
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1468
            }
6b1dc7a6 sago007 2010-11-08 21:03 1469
            else
6b1dc7a6 sago007 2010-11-08 21:03 1470
            {
6b1dc7a6 sago007 2010-11-08 21:03 1471
                strHolder = "Last stage";
6b1dc7a6 sago007 2010-11-08 21:03 1472
                SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1473
            }
6b1dc7a6 sago007 2010-11-08 21:03 1474
        }
6b1dc7a6 sago007 2010-11-08 21:03 1475
6b1dc7a6 sago007 2010-11-08 21:03 1476
#if DEBUG
6b1dc7a6 sago007 2010-11-08 21:03 1477
        if (AI_Enabled&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1478
            strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear);
6b1dc7a6 sago007 2010-11-08 21:03 1479
            SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1480
        }
6b1dc7a6 sago007 2010-11-08 21:03 1481
#endif
6b1dc7a6 sago007 2010-11-08 21:03 1482
        if (!bGameOver)DrawIMG(cursor[(ticks/600)%2],sBoard,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
6b1dc7a6 sago007 2010-11-08 21:03 1483
        if (ticks<gameStartedAt)
6b1dc7a6 sago007 2010-11-08 21:03 1484
        {
6b1dc7a6 sago007 2010-11-08 21:03 1485
            int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1486
            if( (currentCounter!=lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1487
                Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1488
            lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1489
            switch (currentCounter) {
6b1dc7a6 sago007 2010-11-08 21:03 1490
            case 2:
6b1dc7a6 sago007 2010-11-08 21:03 1491
                DrawIMG(counter[2], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1492
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1493
            case 1:
6b1dc7a6 sago007 2010-11-08 21:03 1494
                DrawIMG(counter[1], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1495
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1496
            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1497
                DrawIMG(counter[0], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1498
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1499
            default:
6b1dc7a6 sago007 2010-11-08 21:03 1500
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1501
            }
6b1dc7a6 sago007 2010-11-08 21:03 1502
        }
6b1dc7a6 sago007 2010-11-08 21:03 1503
        else
6b1dc7a6 sago007 2010-11-08 21:03 1504
        {
6b1dc7a6 sago007 2010-11-08 21:03 1505
            if(SoundEnabled&&(!NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver))
6b1dc7a6 sago007 2010-11-08 21:03 1506
            {
6b1dc7a6 sago007 2010-11-08 21:03 1507
                int currentCounter = (ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1508
                if(currentCounter!=lastCounter)
6b1dc7a6 sago007 2010-11-08 21:03 1509
                {
6b1dc7a6 sago007 2010-11-08 21:03 1510
                    if(currentCounter>115 && currentCounter<120)
6b1dc7a6 sago007 2010-11-08 21:03 1511
                        Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1512
                }
6b1dc7a6 sago007 2010-11-08 21:03 1513
                lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1514
            }
6b1dc7a6 sago007 2010-11-08 21:03 1515
            else
6b1dc7a6 sago007 2010-11-08 21:03 1516
            {
6b1dc7a6 sago007 2010-11-08 21:03 1517
                if( (0==lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1518
                {
6b1dc7a6 sago007 2010-11-08 21:03 1519
                    Mix_PlayChannel(1,counterFinalChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1520
                }
6b1dc7a6 sago007 2010-11-08 21:03 1521
                lastCounter = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1522
            }
6b1dc7a6 sago007 2010-11-08 21:03 1523
        }
6b1dc7a6 sago007 2010-11-08 21:03 1524
6b1dc7a6 sago007 2010-11-08 21:03 1525
        if ((bGameOver)&&(!editorMode))
6b1dc7a6 sago007 2010-11-08 21:03 1526
            if (hasWonTheGame)DrawIMG(iWinner, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1527
            else if (bDraw) DrawIMG(iDraw, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1528
            else
6b1dc7a6 sago007 2010-11-08 21:03 1529
                DrawIMG(iGameOver, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1530
    }
6b1dc7a6 sago007 2010-11-08 21:03 1531
6b1dc7a6 sago007 2010-11-08 21:03 1532
6b1dc7a6 sago007 2010-11-08 21:03 1533
    void Update(int newtick) {
6b1dc7a6 sago007 2010-11-08 21:03 1534
        BlockGame::Update(newtick);
6b1dc7a6 sago007 2010-11-08 21:03 1535
        DoPaintJob();
6b1dc7a6 sago007 2010-11-08 21:03 1536
    }
6b1dc7a6 sago007 2010-11-08 21:03 1537
};
6b1dc7a6 sago007 2010-11-08 21:03 1538
6b1dc7a6 sago007 2010-11-08 21:03 1539
6b1dc7a6 sago007 2010-11-08 21:03 1540
6b1dc7a6 sago007 2010-11-08 21:03 1541
89c4a3a6 sago007 2008-08-29 14:32 1542
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
89c4a3a6 sago007 2008-08-29 14:32 1543
void writeScreenShot()
89c4a3a6 sago007 2008-08-29 14:32 1544
{
89c4a3a6 sago007 2008-08-29 14:32 1545
    cout << "Saving screenshot" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1546
    int rightNow = (int)time(NULL);
215ca7b3 sago007 2009-03-06 16:37 1547
/*#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 1548
    char buf[514];
89c4a3a6 sago007 2008-08-29 14:32 1549
    sprintf( buf, "%s/.gamesaves/blockattack/screenshots/screenshot%i.bmp", getenv("HOME"), rightNow );
91886cae sago007 2008-09-12 16:28 1550
#elif defined(__win32__)
89c4a3a6 sago007 2008-08-29 14:32 1551
    char buf[MAX_PATH];
89c4a3a6 sago007 2008-08-29 14:32 1552
    sprintf( buf, "%s\\My Games\\blockattack\\screenshots\\screenshot%i.bmp", (getMyDocumentsPath()).c_str(), rightNow );
91886cae sago007 2008-09-12 16:28 1553
#else
91886cae sago007 2008-09-12 16:28 1554
    char buf[MAX_PATH];
91886cae sago007 2008-09-12 16:28 1555
    sprintf( buf, "screenshot%i.bmp", rightNow );
215ca7b3 sago007 2009-03-06 16:37 1556
#endif*/
215ca7b3 sago007 2009-03-06 16:37 1557
#if defined(__unix__)
215ca7b3 sago007 2009-03-06 16:37 1558
    string buf = (string)getenv("HOME")+"/.gamesaves/blockattack/screenshots/screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1559
#elif defined(__win32__)
215ca7b3 sago007 2009-03-06 16:37 1560
    string buf = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots\\screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1561
#else
215ca7b3 sago007 2009-03-06 16:37 1562
    string buf = "screenshot"+itoa(rightNow)+".bmp";
89c4a3a6 sago007 2008-08-29 14:32 1563
#endif
215ca7b3 sago007 2009-03-06 16:37 1564
    SDL_SaveBMP( screen, buf.c_str() );
89c4a3a6 sago007 2008-08-29 14:32 1565
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 1566
        if (SoundEnabled)Mix_PlayChannel(1,photoClick,0);
89c4a3a6 sago007 2008-08-29 14:32 1567
}
89c4a3a6 sago007 2008-08-29 14:32 1568
89c4a3a6 sago007 2008-08-29 14:32 1569
//Function to return the name of a key, to be displayed...
215ca7b3 sago007 2009-03-06 16:37 1570
string getKeyName(SDLKey key)
89c4a3a6 sago007 2008-08-29 14:32 1571
{
215ca7b3 sago007 2009-03-06 16:37 1572
    string keyname;
89c4a3a6 sago007 2008-08-29 14:32 1573
    char charToPut = '\0';
89c4a3a6 sago007 2008-08-29 14:32 1574
    switch (key)
89c4a3a6 sago007 2008-08-29 14:32 1575
    {
89c4a3a6 sago007 2008-08-29 14:32 1576
    case SDLK_a:
89c4a3a6 sago007 2008-08-29 14:32 1577
        charToPut = 'A';
89c4a3a6 sago007 2008-08-29 14:32 1578
        break;
89c4a3a6 sago007 2008-08-29 14:32 1579
    case SDLK_b:
89c4a3a6 sago007 2008-08-29 14:32 1580
        charToPut = 'B';
89c4a3a6 sago007 2008-08-29 14:32 1581
        break;
89c4a3a6 sago007 2008-08-29 14:32 1582
    case SDLK_c:
89c4a3a6 sago007 2008-08-29 14:32 1583
        charToPut = 'C';
89c4a3a6 sago007 2008-08-29 14:32 1584
        break;
89c4a3a6 sago007 2008-08-29 14:32 1585
    case SDLK_d:
89c4a3a6 sago007 2008-08-29 14:32 1586
        charToPut = 'D';
89c4a3a6 sago007 2008-08-29 14:32 1587
        break;
89c4a3a6 sago007 2008-08-29 14:32 1588
    case SDLK_e:
89c4a3a6 sago007 2008-08-29 14:32 1589
        charToPut = 'E';
89c4a3a6 sago007 2008-08-29 14:32 1590
        break;
89c4a3a6 sago007 2008-08-29 14:32 1591
    case SDLK_f:
89c4a3a6 sago007 2008-08-29 14:32 1592
        charToPut = 'F';
89c4a3a6 sago007 2008-08-29 14:32 1593
        break;
89c4a3a6 sago007 2008-08-29 14:32 1594
    case SDLK_g:
89c4a3a6 sago007 2008-08-29 14:32 1595
        charToPut = 'G';
89c4a3a6 sago007 2008-08-29 14:32 1596
        break;
89c4a3a6 sago007 2008-08-29 14:32 1597
    case SDLK_h:
89c4a3a6 sago007 2008-08-29 14:32 1598
        charToPut = 'H';
89c4a3a6 sago007 2008-08-29 14:32 1599
        break;
89c4a3a6 sago007 2008-08-29 14:32 1600
    case SDLK_i:
89c4a3a6 sago007 2008-08-29 14:32 1601
        charToPut = 'I';
89c4a3a6 sago007 2008-08-29 14:32 1602
        break;
89c4a3a6 sago007 2008-08-29 14:32 1603
    case SDLK_j:
89c4a3a6 sago007 2008-08-29 14:32 1604
        charToPut = 'J';
89c4a3a6 sago007 2008-08-29 14:32 1605
        break;
89c4a3a6 sago007 2008-08-29 14:32 1606
    case SDLK_k:
89c4a3a6 sago007 2008-08-29 14:32 1607
        charToPut = 'K';
89c4a3a6 sago007 2008-08-29 14:32 1608
        break;
89c4a3a6 sago007 2008-08-29 14:32 1609
    case SDLK_l:
89c4a3a6 sago007 2008-08-29 14:32 1610
        charToPut = 'L';
89c4a3a6 sago007 2008-08-29 14:32 1611
        break;
89c4a3a6 sago007 2008-08-29 14:32 1612
    case SDLK_m:
89c4a3a6 sago007 2008-08-29 14:32 1613
        charToPut = 'M';
89c4a3a6 sago007 2008-08-29 14:32 1614
        break;
89c4a3a6 sago007 2008-08-29 14:32 1615
    case SDLK_n:
89c4a3a6 sago007 2008-08-29 14:32 1616
        charToPut = 'N';
89c4a3a6 sago007 2008-08-29 14:32 1617
        break;
89c4a3a6 sago007 2008-08-29 14:32 1618
    case SDLK_o:
89c4a3a6 sago007 2008-08-29 14:32 1619
        charToPut = 'O';
89c4a3a6 sago007 2008-08-29 14:32 1620
        break;
89c4a3a6 sago007 2008-08-29 14:32 1621
    case SDLK_p:
89c4a3a6 sago007 2008-08-29 14:32 1622
        charToPut = 'P';
89c4a3a6 sago007 2008-08-29 14:32 1623
        break;
89c4a3a6 sago007 2008-08-29 14:32 1624
    case SDLK_q:
89c4a3a6 sago007 2008-08-29 14:32 1625
        charToPut = 'Q';
89c4a3a6 sago007 2008-08-29 14:32 1626
        break;
89c4a3a6 sago007 2008-08-29 14:32 1627
    case SDLK_r:
89c4a3a6 sago007 2008-08-29 14:32 1628
        charToPut = 'R';
89c4a3a6 sago007 2008-08-29 14:32 1629
        break;
89c4a3a6 sago007 2008-08-29 14:32 1630
    case SDLK_s:
89c4a3a6 sago007 2008-08-29 14:32 1631
        charToPut = 'S';
89c4a3a6 sago007 2008-08-29 14:32 1632
        break;
89c4a3a6 sago007 2008-08-29 14:32 1633
    case SDLK_t:
89c4a3a6 sago007 2008-08-29 14:32 1634
        charToPut = 'T';
89c4a3a6 sago007 2008-08-29 14:32 1635
        break;
89c4a3a6 sago007 2008-08-29 14:32 1636
    case SDLK_u:
89c4a3a6 sago007 2008-08-29 14:32 1637
        charToPut = 'U';
89c4a3a6 sago007 2008-08-29 14:32 1638
        break;
89c4a3a6 sago007 2008-08-29 14:32 1639
    case SDLK_v:
89c4a3a6 sago007 2008-08-29 14:32 1640
        charToPut = 'V';
89c4a3a6 sago007 2008-08-29 14:32 1641
        break;
89c4a3a6 sago007 2008-08-29 14:32 1642
    case SDLK_w:
89c4a3a6 sago007 2008-08-29 14:32 1643
        charToPut = 'W';
89c4a3a6 sago007 2008-08-29 14:32 1644
        break;
89c4a3a6 sago007 2008-08-29 14:32 1645
    case SDLK_x:
89c4a3a6 sago007 2008-08-29 14:32 1646
        charToPut = 'X';
89c4a3a6 sago007 2008-08-29 14:32 1647
        break;
89c4a3a6 sago007 2008-08-29 14:32 1648
    case SDLK_y:
89c4a3a6 sago007 2008-08-29 14:32 1649
        charToPut = 'Y';
89c4a3a6 sago007 2008-08-29 14:32 1650
        break;
89c4a3a6 sago007 2008-08-29 14:32 1651
    case SDLK_z:
89c4a3a6 sago007 2008-08-29 14:32 1652
        charToPut = 'Z';
89c4a3a6 sago007 2008-08-29 14:32 1653
        break;
89c4a3a6 sago007 2008-08-29 14:32 1654
    case SDLK_0:
89c4a3a6 sago007 2008-08-29 14:32 1655
        charToPut = '0';
89c4a3a6 sago007 2008-08-29 14:32 1656
        break;
89c4a3a6 sago007 2008-08-29 14:32 1657
    case SDLK_1:
89c4a3a6 sago007 2008-08-29 14:32 1658
        charToPut = '1';
89c4a3a6 sago007 2008-08-29 14:32 1659
        break;
89c4a3a6 sago007 2008-08-29 14:32 1660
    case SDLK_2:
89c4a3a6 sago007 2008-08-29 14:32 1661
        charToPut = '2';
89c4a3a6 sago007 2008-08-29 14:32 1662
        break;
89c4a3a6 sago007 2008-08-29 14:32 1663
    case SDLK_3:
89c4a3a6 sago007 2008-08-29 14:32 1664
        charToPut = '3';
89c4a3a6 sago007 2008-08-29 14:32 1665
        break;
89c4a3a6 sago007 2008-08-29 14:32 1666
    case SDLK_4:
89c4a3a6 sago007 2008-08-29 14:32 1667
        charToPut = '4';
89c4a3a6 sago007 2008-08-29 14:32 1668
        break;
89c4a3a6 sago007 2008-08-29 14:32 1669
    case SDLK_5:
89c4a3a6 sago007 2008-08-29 14:32 1670
        charToPut = '5';
89c4a3a6 sago007 2008-08-29 14:32 1671
        break;
89c4a3a6 sago007 2008-08-29 14:32 1672
    case SDLK_6:
89c4a3a6 sago007 2008-08-29 14:32 1673
        charToPut = '6';
89c4a3a6 sago007 2008-08-29 14:32 1674
        break;
89c4a3a6 sago007 2008-08-29 14:32 1675
    case SDLK_7:
89c4a3a6 sago007 2008-08-29 14:32 1676
        charToPut = '7';
89c4a3a6 sago007 2008-08-29 14:32 1677
        break;
89c4a3a6 sago007 2008-08-29 14:32 1678
    case SDLK_8:
89c4a3a6 sago007 2008-08-29 14:32 1679
        charToPut = '8';
89c4a3a6 sago007 2008-08-29 14:32 1680
        break;
89c4a3a6 sago007 2008-08-29 14:32 1681
    case SDLK_9:
89c4a3a6 sago007 2008-08-29 14:32 1682
        charToPut = '9';
89c4a3a6 sago007 2008-08-29 14:32 1683
        break;
89c4a3a6 sago007 2008-08-29 14:32 1684
    case SDLK_KP0:
215ca7b3 sago007 2009-03-06 16:37 1685
        keyname = "NP_0";
89c4a3a6 sago007 2008-08-29 14:32 1686
        break;
89c4a3a6 sago007 2008-08-29 14:32 1687
    case SDLK_KP1:
215ca7b3 sago007 2009-03-06 16:37 1688
        keyname = "NP_1";
89c4a3a6 sago007 2008-08-29 14:32 1689
        break;
89c4a3a6 sago007 2008-08-29 14:32 1690
    case SDLK_KP2:
215ca7b3 sago007 2009-03-06 16:37 1691
        keyname = "NP_2";
89c4a3a6 sago007 2008-08-29 14:32 1692
        break;
89c4a3a6 sago007 2008-08-29 14:32 1693
    case SDLK_KP3:
215ca7b3 sago007 2009-03-06 16:37 1694
        keyname = "NP_3";
89c4a3a6 sago007 2008-08-29 14:32 1695
        break;
89c4a3a6 sago007 2008-08-29 14:32 1696
    case SDLK_KP4:
215ca7b3 sago007 2009-03-06 16:37 1697
        keyname = "NP_4";
89c4a3a6 sago007 2008-08-29 14:32 1698
        break;
89c4a3a6 sago007 2008-08-29 14:32 1699
    case SDLK_KP5:
215ca7b3 sago007 2009-03-06 16:37 1700
        keyname = "NP_5";
89c4a3a6 sago007 2008-08-29 14:32 1701
        break;
89c4a3a6 sago007 2008-08-29 14:32 1702
    case SDLK_KP6:
215ca7b3 sago007 2009-03-06 16:37 1703
        keyname = "NP_6";
89c4a3a6 sago007 2008-08-29 14:32 1704
        break;
89c4a3a6 sago007 2008-08-29 14:32 1705
    case SDLK_KP7:
215ca7b3 sago007 2009-03-06 16:37 1706
        keyname = "NP_7";
89c4a3a6 sago007 2008-08-29 14:32 1707
        break;
89c4a3a6 sago007 2008-08-29 14:32 1708
    case SDLK_KP8:
215ca7b3 sago007 2009-03-06 16:37 1709
        keyname = "NP_8";
89c4a3a6 sago007 2008-08-29 14:32 1710
        break;
89c4a3a6 sago007 2008-08-29 14:32 1711
    case SDLK_KP9:
215ca7b3 sago007 2009-03-06 16:37 1712
        keyname = "NP_9";
89c4a3a6 sago007 2008-08-29 14:32 1713
        break;
89c4a3a6 sago007 2008-08-29 14:32 1714
    case SDLK_BACKSPACE:
215ca7b3 sago007 2009-03-06 16:37 1715
        keyname = "Backspace";
89c4a3a6 sago007 2008-08-29 14:32 1716
        break;
89c4a3a6 sago007 2008-08-29 14:32 1717
    case SDLK_TAB:
215ca7b3 sago007 2009-03-06 16:37 1718
        keyname = "Tab";
89c4a3a6 sago007 2008-08-29 14:32 1719
        break;
89c4a3a6 sago007 2008-08-29 14:32 1720
    case SDLK_CLEAR:
215ca7b3 sago007 2009-03-06 16:37 1721
        keyname = "Clear";
89c4a3a6 sago007 2008-08-29 14:32 1722
        break;
89c4a3a6 sago007 2008-08-29 14:32 1723
    case SDLK_RETURN:
215ca7b3 sago007 2009-03-06 16:37 1724
        keyname = "Return";
89c4a3a6 sago007 2008-08-29 14:32 1725
        break;
89c4a3a6 sago007 2008-08-29 14:32 1726
    case SDLK_PAUSE:
215ca7b3 sago007 2009-03-06 16:37 1727
        keyname = "Pause";
89c4a3a6 sago007 2008-08-29 14:32 1728
        break;
89c4a3a6 sago007 2008-08-29 14:32 1729
    case SDLK_SPACE:
215ca7b3 sago007 2009-03-06 16:37 1730
        keyname = "Space";
89c4a3a6 sago007 2008-08-29 14:32 1731
        break;
89c4a3a6 sago007 2008-08-29 14:32 1732
    case SDLK_EXCLAIM:
89c4a3a6 sago007 2008-08-29 14:32 1733
        charToPut = '!';
89c4a3a6 sago007 2008-08-29 14:32 1734
        break;
89c4a3a6 sago007 2008-08-29 14:32 1735
    case SDLK_QUOTEDBL:
215ca7b3 sago007 2009-03-06 16:37 1736
        keyname = "QuoteDBL";
89c4a3a6 sago007 2008-08-29 14:32 1737
        break;
89c4a3a6 sago007 2008-08-29 14:32 1738
    case SDLK_HASH:
89c4a3a6 sago007 2008-08-29 14:32 1739
        charToPut = '#';
89c4a3a6 sago007 2008-08-29 14:32 1740
        break;
89c4a3a6 sago007 2008-08-29 14:32 1741
    case SDLK_DOLLAR:
215ca7b3 sago007 2009-03-06 16:37 1742
        keyname = "$";
89c4a3a6 sago007 2008-08-29 14:32 1743
        break;
89c4a3a6 sago007 2008-08-29 14:32 1744
    case SDLK_ASTERISK:
215ca7b3 sago007 2009-03-06 16:37 1745
        keyname = "Asterisk";
89c4a3a6 sago007 2008-08-29 14:32 1746
        break;
89c4a3a6 sago007 2008-08-29 14:32 1747
    case SDLK_PLUS:
215ca7b3 sago007 2009-03-06 16:37 1748
        keyname = "Plus";
89c4a3a6 sago007 2008-08-29 14:32 1749
        break;
89c4a3a6 sago007 2008-08-29 14:32 1750
    case SDLK_COMMA:
215ca7b3 sago007 2009-03-06 16:37 1751
        keyname = "Comma";
89c4a3a6 sago007 2008-08-29 14:32 1752
        break;
89c4a3a6 sago007 2008-08-29 14:32 1753
    case SDLK_MINUS:
215ca7b3 sago007 2009-03-06 16:37 1754
        keyname = "Minus";
89c4a3a6 sago007 2008-08-29 14:32 1755
        break;
89c4a3a6 sago007 2008-08-29 14:32 1756
    case SDLK_PERIOD:
215ca7b3 sago007 2009-03-06 16:37 1757
        keyname = "Period";
89c4a3a6 sago007 2008-08-29 14:32 1758
        break;
89c4a3a6 sago007 2008-08-29 14:32 1759
    case SDLK_SLASH:
89c4a3a6 sago007 2008-08-29 14:32 1760
        charToPut ='/';
89c4a3a6 sago007 2008-08-29 14:32 1761
        break;
89c4a3a6 sago007 2008-08-29 14:32 1762
    case SDLK_COLON:
215ca7b3 sago007 2009-03-06 16:37 1763
        keyname = "Colon";
89c4a3a6 sago007 2008-08-29 14:32 1764
        break;
89c4a3a6 sago007 2008-08-29 14:32 1765
    case SDLK_SEMICOLON:
215ca7b3 sago007 2009-03-06 16:37 1766
        keyname = "SemiColon";
89c4a3a6 sago007 2008-08-29 14:32 1767
        break;
89c4a3a6 sago007 2008-08-29 14:32 1768
    case SDLK_LESS:
89c4a3a6 sago007 2008-08-29 14:32 1769
        charToPut = '<';
89c4a3a6 sago007 2008-08-29 14:32 1770
        break;
89c4a3a6 sago007 2008-08-29 14:32 1771
    case SDLK_EQUALS:
215ca7b3 sago007 2009-03-06 16:37 1772
        keyname = "Equals";
89c4a3a6 sago007 2008-08-29 14:32 1773
        break;
89c4a3a6 sago007 2008-08-29 14:32 1774
    case SDLK_DELETE:
215ca7b3 sago007 2009-03-06 16:37 1775
        keyname = "Delete";
89c4a3a6 sago007 2008-08-29 14:32 1776
        break;
89c4a3a6 sago007 2008-08-29 14:32 1777
    case SDLK_KP_PERIOD:
215ca7b3 sago007 2009-03-06 16:37 1778
        keyname = "NPperiod";
89c4a3a6 sago007 2008-08-29 14:32 1779
        break;
89c4a3a6 sago007 2008-08-29 14:32 1780
    case SDLK_KP_DIVIDE:
215ca7b3 sago007 2009-03-06 16:37 1781
        keyname = "NPdivide";
89c4a3a6 sago007 2008-08-29 14:32 1782
        break;
89c4a3a6 sago007 2008-08-29 14:32 1783
    case SDLK_KP_MULTIPLY:
215ca7b3 sago007 2009-03-06 16:37 1784
        keyname = "NPmultiply";
89c4a3a6 sago007 2008-08-29 14:32 1785
        break;
89c4a3a6 sago007 2008-08-29 14:32 1786
    case SDLK_KP_MINUS:
215ca7b3 sago007 2009-03-06 16:37 1787
        keyname = "NPminus";
89c4a3a6 sago007 2008-08-29 14:32 1788
        break;
89c4a3a6 sago007 2008-08-29 14:32 1789
    case SDLK_KP_PLUS:
215ca7b3 sago007 2009-03-06 16:37 1790
        keyname = "NPplus";
89c4a3a6 sago007 2008-08-29 14:32 1791
        break;
89c4a3a6 sago007 2008-08-29 14:32 1792
    case SDLK_KP_ENTER:
215ca7b3 sago007 2009-03-06 16:37 1793
        keyname = "NP_Enter";
89c4a3a6 sago007 2008-08-29 14:32 1794
        break;
89c4a3a6 sago007 2008-08-29 14:32 1795
    case SDLK_KP_EQUALS:
215ca7b3 sago007 2009-03-06 16:37 1796
        keyname = "NP=";
89c4a3a6 sago007 2008-08-29 14:32 1797
        break;
89c4a3a6 sago007 2008-08-29 14:32 1798
    case SDLK_UP:
215ca7b3 sago007 2009-03-06 16:37 1799
        keyname = "UP";
89c4a3a6 sago007 2008-08-29 14:32 1800
        break;
89c4a3a6 sago007 2008-08-29 14:32 1801
    case SDLK_DOWN:
215ca7b3 sago007 2009-03-06 16:37 1802
        keyname = "DOWN";
89c4a3a6 sago007 2008-08-29 14:32 1803
        break;
89c4a3a6 sago007 2008-08-29 14:32 1804
    case SDLK_RIGHT:
215ca7b3 sago007 2009-03-06 16:37 1805
        keyname = "RIGHT";
89c4a3a6 sago007 2008-08-29 14:32 1806
        break;
89c4a3a6 sago007 2008-08-29 14:32 1807
    case SDLK_LEFT:
215ca7b3 sago007 2009-03-06 16:37 1808
        keyname = "LEFT";
89c4a3a6 sago007 2008-08-29 14:32 1809
        break;
89c4a3a6 sago007 2008-08-29 14:32 1810
    case SDLK_INSERT:
215ca7b3 sago007 2009-03-06 16:37 1811
        keyname = "Insert";
89c4a3a6 sago007 2008-08-29 14:32 1812
        break;
89c4a3a6 sago007 2008-08-29 14:32 1813
    case SDLK_HOME:
215ca7b3 sago007 2009-03-06 16:37 1814
        keyname = "Home";
89c4a3a6 sago007 2008-08-29 14:32 1815
        break;
89c4a3a6 sago007 2008-08-29 14:32 1816
    case SDLK_END:
215ca7b3 sago007 2009-03-06 16:37 1817
        keyname = "End";
89c4a3a6 sago007 2008-08-29 14:32 1818
        break;
89c4a3a6 sago007 2008-08-29 14:32 1819
    case SDLK_PAGEUP:
215ca7b3 sago007 2009-03-06 16:37 1820
        keyname = "PageUp";
89c4a3a6 sago007 2008-08-29 14:32 1821
        break;
89c4a3a6 sago007 2008-08-29 14:32 1822
    case SDLK_PAGEDOWN:
215ca7b3 sago007 2009-03-06 16:37 1823
        keyname = "PageDown";
89c4a3a6 sago007 2008-08-29 14:32 1824
        break;
89c4a3a6 sago007 2008-08-29 14:32 1825
    case SDLK_NUMLOCK:
215ca7b3 sago007 2009-03-06 16:37 1826
        keyname = "NumLock";
89c4a3a6 sago007 2008-08-29 14:32 1827
        break;
89c4a3a6 sago007 2008-08-29 14:32 1828
    case SDLK_CAPSLOCK:
215ca7b3 sago007 2009-03-06 16:37 1829
        keyname = "CapsLock";
89c4a3a6 sago007 2008-08-29 14:32 1830
        break;
89c4a3a6 sago007 2008-08-29 14:32 1831
    case SDLK_SCROLLOCK:
215ca7b3 sago007 2009-03-06 16:37 1832
        keyname = "ScrolLock";
89c4a3a6 sago007 2008-08-29 14:32 1833
        break;
89c4a3a6 sago007 2008-08-29 14:32 1834
    case SDLK_RSHIFT:
215ca7b3 sago007 2009-03-06 16:37 1835
        keyname = "Rshift";
89c4a3a6 sago007 2008-08-29 14:32 1836
        break;
89c4a3a6 sago007 2008-08-29 14:32 1837
    case SDLK_LSHIFT:
215ca7b3 sago007 2009-03-06 16:37 1838
        keyname = "Lshift";
89c4a3a6 sago007 2008-08-29 14:32 1839
        break;
89c4a3a6 sago007 2008-08-29 14:32 1840
    case SDLK_RCTRL:
215ca7b3 sago007 2009-03-06 16:37 1841
        keyname = "Rctrl";
89c4a3a6 sago007 2008-08-29 14:32 1842
        break;
89c4a3a6 sago007 2008-08-29 14:32 1843
    case SDLK_LCTRL:
215ca7b3 sago007 2009-03-06 16:37 1844
        keyname = "Lctrl";
89c4a3a6 sago007 2008-08-29 14:32 1845
        break;
89c4a3a6 sago007 2008-08-29 14:32 1846
    case SDLK_RALT:
215ca7b3 sago007 2009-03-06 16:37 1847
        keyname = "Ralt";
89c4a3a6 sago007 2008-08-29 14:32 1848
        break;
89c4a3a6 sago007 2008-08-29 14:32 1849
    case SDLK_LALT:
215ca7b3 sago007 2009-03-06 16:37 1850
        keyname = "Lalt";
89c4a3a6 sago007 2008-08-29 14:32 1851
        break;
89c4a3a6 sago007 2008-08-29 14:32 1852
    case SDLK_RMETA:
215ca7b3 sago007 2009-03-06 16:37 1853
        keyname = "Rmeta";
89c4a3a6 sago007 2008-08-29 14:32 1854
        break;
89c4a3a6 sago007 2008-08-29 14:32 1855
    case SDLK_LMETA:
215ca7b3 sago007 2009-03-06 16:37 1856
        keyname = "Lmeta";
89c4a3a6 sago007 2008-08-29 14:32 1857
        break;
89c4a3a6 sago007 2008-08-29 14:32 1858
    case SDLK_LSUPER:
215ca7b3 sago007 2009-03-06 16:37 1859
        keyname = "Lwin";
89c4a3a6 sago007 2008-08-29 14:32 1860
        break;
89c4a3a6 sago007 2008-08-29 14:32 1861
    case SDLK_RSUPER:
215ca7b3 sago007 2009-03-06 16:37 1862
        keyname = "Rwin";
89c4a3a6 sago007 2008-08-29 14:32 1863
        break;
89c4a3a6 sago007 2008-08-29 14:32 1864
    case SDLK_MODE:
215ca7b3 sago007 2009-03-06 16:37 1865
        keyname = "Mode";
89c4a3a6 sago007 2008-08-29 14:32 1866
        break;
89c4a3a6 sago007 2008-08-29 14:32 1867
    case SDLK_HELP:
215ca7b3 sago007 2009-03-06 16:37 1868
        keyname = "Help";
89c4a3a6 sago007 2008-08-29 14:32 1869
        break;
89c4a3a6 sago007 2008-08-29 14:32 1870
    default:
215ca7b3 sago007 2009-03-06 16:37 1871
        keyname = "Unknown";
89c4a3a6 sago007 2008-08-29 14:32 1872
        break;
89c4a3a6 sago007 2008-08-29 14:32 1873
    }
89c4a3a6 sago007 2008-08-29 14:32 1874
    if (charToPut != '\0')
215ca7b3 sago007 2009-03-06 16:37 1875
    {
215ca7b3 sago007 2009-03-06 16:37 1876
        keyname.clear();
215ca7b3 sago007 2009-03-06 16:37 1877
        keyname.append(1,charToPut);
215ca7b3 sago007 2009-03-06 16:37 1878
    }
215ca7b3 sago007 2009-03-06 16:37 1879
    return keyname;
89c4a3a6 sago007 2008-08-29 14:32 1880
}
89c4a3a6 sago007 2008-08-29 14:32 1881
89c4a3a6 sago007 2008-08-29 14:32 1882
void MakeBackground(int xsize,int ysize,BlockGame &theGame, BlockGame &theGame2);
89c4a3a6 sago007 2008-08-29 14:32 1883
89c4a3a6 sago007 2008-08-29 14:32 1884
int OpenControlsBox(int x, int y, int player)
89c4a3a6 sago007 2008-08-29 14:32 1885
{
89c4a3a6 sago007 2008-08-29 14:32 1886
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 1887
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 1888
    bool done =false;
215ca7b3 sago007 2009-03-06 16:37 1889
    string keyname;
27ae0175 sago007 2009-01-30 06:02 1890
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1891
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 1892
    {
89c4a3a6 sago007 2008-08-29 14:32 1893
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 1894
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1895
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 1896
        if (player == 0)
89c4a3a6 sago007 2008-08-29 14:32 1897
            SFont_Write(screen,fBlueFont,x+40,y+2,"Player 1 keys");
89c4a3a6 sago007 2008-08-29 14:32 1898
        else
89c4a3a6 sago007 2008-08-29 14:32 1899
            SFont_Write(screen,fBlueFont,x+40,y+2,"Player 2 keys");
89c4a3a6 sago007 2008-08-29 14:32 1900
        SFont_Write(screen,fBlueFont,x+6,y+50,"Up");
89c4a3a6 sago007 2008-08-29 14:32 1901
        keyname = getKeyName(keySettings[player].up);
215ca7b3 sago007 2009-03-06 16:37 1902
        SFont_Write(screen,fBlueFont,x+200,y+50,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1903
        SFont_Write(screen,fBlueFont,x+6,y+100,"Down");
89c4a3a6 sago007 2008-08-29 14:32 1904
        keyname = getKeyName(keySettings[player].down);
215ca7b3 sago007 2009-03-06 16:37 1905
        SFont_Write(screen,fBlueFont,x+200,y+100,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1906
        SFont_Write(screen,fBlueFont,x+6,y+150,"Left");
89c4a3a6 sago007 2008-08-29 14:32 1907
        keyname = getKeyName(keySettings[player].left);
215ca7b3 sago007 2009-03-06 16:37 1908
        SFont_Write(screen,fBlueFont,x+200,y+150,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1909
        SFont_Write(screen,fBlueFont,x+6,y+200,"Right");
89c4a3a6 sago007 2008-08-29 14:32 1910
        keyname = getKeyName(keySettings[player].right);
215ca7b3 sago007 2009-03-06 16:37 1911
        SFont_Write(screen,fBlueFont,x+200,y+200,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1912
        SFont_Write(screen,fBlueFont,x+6,y+250,"Push");
89c4a3a6 sago007 2008-08-29 14:32 1913
        keyname = getKeyName(keySettings[player].push);
215ca7b3 sago007 2009-03-06 16:37 1914
        SFont_Write(screen,fBlueFont,x+200,y+250,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1915
        SFont_Write(screen,fBlueFont,x+6,y+300,"Change");
89c4a3a6 sago007 2008-08-29 14:32 1916
        keyname = getKeyName(keySettings[player].change);
215ca7b3 sago007 2009-03-06 16:37 1917
        SFont_Write(screen,fBlueFont,x+200,y+300,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1918
        //Ask for mouse play
89c4a3a6 sago007 2008-08-29 14:32 1919
        SFont_Write(screen,fBlueFont,x+6,y+350,"Mouse play?");
89c4a3a6 sago007 2008-08-29 14:32 1920
        DrawIMG(iLevelCheckBox,screen,x+220,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1921
        if (((player==0)&&(mouseplay1))||((player==2)&&(mouseplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1922
            DrawIMG(iLevelCheck,screen,x+220,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1923
        //Ask for joypad play
89c4a3a6 sago007 2008-08-29 14:32 1924
        SFont_Write(screen,fBlueFont,x+300,y+350,"Joypad?");
89c4a3a6 sago007 2008-08-29 14:32 1925
        DrawIMG(iLevelCheckBox,screen,x+460,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1926
        if (((player==0)&&(joyplay1))||((player==2)&&(joyplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1927
            DrawIMG(iLevelCheck,screen,x+460,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1928
        for (int i=1; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 1929
            DrawIMG(bChange,screen,x+420,y+50*i);
89c4a3a6 sago007 2008-08-29 14:32 1930
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1931
89c4a3a6 sago007 2008-08-29 14:32 1932
        while (SDL_PollEvent(&event))
89c4a3a6 sago007 2008-08-29 14:32 1933
        {
89c4a3a6 sago007 2008-08-29 14:32 1934
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 1935
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1936
            }
89c4a3a6 sago007 2008-08-29 14:32 1937
89c4a3a6 sago007 2008-08-29 14:32 1938
            if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1939
            {
89c4a3a6 sago007 2008-08-29 14:32 1940
                if (event.key.keysym.sym == SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1941
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1942
            }
89c4a3a6 sago007 2008-08-29 14:32 1943
        }	//PollEvent
89c4a3a6 sago007 2008-08-29 14:32 1944
89c4a3a6 sago007 2008-08-29 14:32 1945
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1946
89c4a3a6 sago007 2008-08-29 14:32 1947
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 1948
89c4a3a6 sago007 2008-08-29 14:32 1949
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 1950
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 1951
        {
89c4a3a6 sago007 2008-08-29 14:32 1952
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 1953
        }
89c4a3a6 sago007 2008-08-29 14:32 1954
89c4a3a6 sago007 2008-08-29 14:32 1955
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 1956
        {
89c4a3a6 sago007 2008-08-29 14:32 1957
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 1958
89c4a3a6 sago007 2008-08-29 14:32 1959
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(50+y)) && (mousey<(90+y)))
89c4a3a6 sago007 2008-08-29 14:32 1960
            {
89c4a3a6 sago007 2008-08-29 14:32 1961
                //up
89c4a3a6 sago007 2008-08-29 14:32 1962
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1963
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1964
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1965
                    {
89c4a3a6 sago007 2008-08-29 14:32 1966
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1967
                        {
89c4a3a6 sago007 2008-08-29 14:32 1968
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1969
                                keySettings[player].up = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1970
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1971
                        }
89c4a3a6 sago007 2008-08-29 14:32 1972
                    }
89c4a3a6 sago007 2008-08-29 14:32 1973
            } //up
89c4a3a6 sago007 2008-08-29 14:32 1974
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(100+y)) && (mousey<(140+y)))
89c4a3a6 sago007 2008-08-29 14:32 1975
            {
89c4a3a6 sago007 2008-08-29 14:32 1976
                //down
89c4a3a6 sago007 2008-08-29 14:32 1977
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1978
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1979
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1980
                    {
89c4a3a6 sago007 2008-08-29 14:32 1981
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1982
                        {
89c4a3a6 sago007 2008-08-29 14:32 1983
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1984
                                keySettings[player].down = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1985
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1986
                        }
89c4a3a6 sago007 2008-08-29 14:32 1987
                    }
89c4a3a6 sago007 2008-08-29 14:32 1988
            } //down
89c4a3a6 sago007 2008-08-29 14:32 1989
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(150+y)) && (mousey<(190+y)))
89c4a3a6 sago007 2008-08-29 14:32 1990
            {
89c4a3a6 sago007 2008-08-29 14:32 1991
                //left
89c4a3a6 sago007 2008-08-29 14:32 1992
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1993
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1994
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1995
                    {
89c4a3a6 sago007 2008-08-29 14:32 1996
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1997
                        {
89c4a3a6 sago007 2008-08-29 14:32 1998
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1999
                                keySettings[player].left = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 2000
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 2001
                        }
89c4a3a6 sago007 2008-08-29 14:32 2002
                    }
89c4a3a6 sago007 2008-08-29 14:32 2003
            } //left
89c4a3a6 sago007 2008-08-29 14:32 2004
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(200+y)) && (mousey<(240+y)))
89c4a3a6 sago007 2008-08-29 14:32 2005
            {
89c4a3a6 sago007 2008-08-29 14:32 2006
                //right
89c4a3a6 sago007 2008-08-29 14:32 2007
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 2008
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 2009
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2010
                    {
89c4a3a6 sago007 2008-08-29 14:32 2011
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 2012
                        {
89c4a3a6 sago007 2008-08-29 14:32 2013
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 2014
                                keySettings[player].right = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 2015
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 2016
                        }
89c4a3a6 sago007 2008-08-29 14:32 2017
                    }
89c4a3a6 sago007 2008-08-29 14:32 2018
            } //right
89c4a3a6 sago007 2008-08-29 14:32 2019
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(250+y)) && (mousey<(290+y)))
89c4a3a6 sago007 2008-08-29 14:32 2020
            {
89c4a3a6 sago007 2008-08-29 14:32 2021
                //push
89c4a3a6 sago007 2008-08-29 14:32 2022
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 2023
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 2024
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2025
                    {
89c4a3a6 sago007 2008-08-29 14:32 2026
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 2027
                        {
89c4a3a6 sago007 2008-08-29 14:32 2028
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 2029
                                keySettings[player].push = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 2030
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 2031
                        }
89c4a3a6 sago007 2008-08-29 14:32 2032
                    }
89c4a3a6 sago007 2008-08-29 14:32 2033
            } //push
89c4a3a6 sago007 2008-08-29 14:32 2034
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(300+y)) && (mousey<(340+y)))
89c4a3a6 sago007 2008-08-29 14:32 2035
            {
89c4a3a6 sago007 2008-08-29 14:32 2036
                //change
89c4a3a6 sago007 2008-08-29 14:32 2037
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 2038
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 2039
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2040
                    {
89c4a3a6 sago007 2008-08-29 14:32 2041
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 2042
                        {
89c4a3a6 sago007 2008-08-29 14:32 2043
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 2044
                                keySettings[player].change = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 2045
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 2046
                        }
89c4a3a6 sago007 2008-08-29 14:32 2047
                    }
89c4a3a6 sago007 2008-08-29 14:32 2048
            } //change
89c4a3a6 sago007 2008-08-29 14:32 2049
            //mouseplay:
89c4a3a6 sago007 2008-08-29 14:32 2050
            if ((mousex>(220+x)) && (mousex<(262+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 2051
            {
89c4a3a6 sago007 2008-08-29 14:32 2052
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 2053
                {
89c4a3a6 sago007 2008-08-29 14:32 2054
                    mouseplay1 = !mouseplay1;
89c4a3a6 sago007 2008-08-29 14:32 2055
                }
89c4a3a6 sago007 2008-08-29 14:32 2056
                else
89c4a3a6 sago007 2008-08-29 14:32 2057
                {
89c4a3a6 sago007 2008-08-29 14:32 2058
                    mouseplay2 = !mouseplay2;
89c4a3a6 sago007 2008-08-29 14:32 2059
                }
89c4a3a6 sago007 2008-08-29 14:32 2060
            }
89c4a3a6 sago007 2008-08-29 14:32 2061
            //Joyplay:
89c4a3a6 sago007 2008-08-29 14:32 2062
            if ((mousex>(460+x)) && (mousex<(502+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 2063
            {
89c4a3a6 sago007 2008-08-29 14:32 2064
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 2065
                {
89c4a3a6 sago007 2008-08-29 14:32 2066
                    joyplay1 = !joyplay1;
89c4a3a6 sago007 2008-08-29 14:32 2067
                }
89c4a3a6 sago007 2008-08-29 14:32 2068
                else
89c4a3a6 sago007 2008-08-29 14:32 2069
                {
89c4a3a6 sago007 2008-08-29 14:32 2070
                    joyplay2 = !joyplay2;
89c4a3a6 sago007 2008-08-29 14:32 2071
                }
89c4a3a6 sago007 2008-08-29 14:32 2072
            }
89c4a3a6 sago007 2008-08-29 14:32 2073
        }	//get mouse state
89c4a3a6 sago007 2008-08-29 14:32 2074
89c4a3a6 sago007 2008-08-29 14:32 2075
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2076
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 2077
    }	//while !done
89c4a3a6 sago007 2008-08-29 14:32 2078
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2079
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 2080
}
89c4a3a6 sago007 2008-08-29 14:32 2081
89c4a3a6 sago007 2008-08-29 14:32 2082
89c4a3a6 sago007 2008-08-29 14:32 2083
//Dialogbox
89c4a3a6 sago007 2008-08-29 14:32 2084
bool OpenDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2085
{
89c4a3a6 sago007 2008-08-29 14:32 2086
    bool done = false;     //We are done!
89c4a3a6 sago007 2008-08-29 14:32 2087
    bool accept = false;   //New name is accepted! (not Cancelled)
89c4a3a6 sago007 2008-08-29 14:32 2088
    bool repeating = false; //The key is being held (BACKSPACE)
89c4a3a6 sago007 2008-08-29 14:32 2089
    const int repeatDelay = 200;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 2090
    unsigned long time = 0;
89c4a3a6 sago007 2008-08-29 14:32 2091
    ReadKeyboard rk = ReadKeyboard(name);
89c4a3a6 sago007 2008-08-29 14:32 2092
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2093
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2094
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2095
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2096
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2097
    {
89c4a3a6 sago007 2008-08-29 14:32 2098
        DrawIMG(dialogBox,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2099
        SFont_Write(screen,fBlueFont,x+40,y+72,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 2100
        strHolder = rk.GetString();
89c4a3a6 sago007 2008-08-29 14:32 2101
        strHolder.erase((int)rk.CharsBeforeCursor());
89c4a3a6 sago007 2008-08-29 14:32 2102
89c4a3a6 sago007 2008-08-29 14:32 2103
        if (((SDL_GetTicks()/600)%2)==1)
89c4a3a6 sago007 2008-08-29 14:32 2104
            SFont_Write(screen,fBlueFont,x+40+SFont_TextWidth(fBlueFont,strHolder.c_str()),y+69,"|");
89c4a3a6 sago007 2008-08-29 14:32 2105
89c4a3a6 sago007 2008-08-29 14:32 2106
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2107
89c4a3a6 sago007 2008-08-29 14:32 2108
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2109
        {
89c4a3a6 sago007 2008-08-29 14:32 2110
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2111
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2112
                accept = false;
89c4a3a6 sago007 2008-08-29 14:32 2113
            }
89c4a3a6 sago007 2008-08-29 14:32 2114
89c4a3a6 sago007 2008-08-29 14:32 2115
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2116
            {
89c4a3a6 sago007 2008-08-29 14:32 2117
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
89c4a3a6 sago007 2008-08-29 14:32 2118
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2119
                    accept = true;
89c4a3a6 sago007 2008-08-29 14:32 2120
                }
89c4a3a6 sago007 2008-08-29 14:32 2121
                else
89c4a3a6 sago007 2008-08-29 14:32 2122
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2123
                        done = true;
89c4a3a6 sago007 2008-08-29 14:32 2124
                        accept = false;
89c4a3a6 sago007 2008-08-29 14:32 2125
                    }
89c4a3a6 sago007 2008-08-29 14:32 2126
                    else if (!(event.key.keysym.sym == SDLK_BACKSPACE)){
89c4a3a6 sago007 2008-08-29 14:32 2127
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 2128
                    }
89c4a3a6 sago007 2008-08-29 14:32 2129
                    else if ((event.key.keysym.sym == SDLK_BACKSPACE)&&(!repeating)){
89c4a3a6 sago007 2008-08-29 14:32 2130
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 2131
                        repeating = true;
89c4a3a6 sago007 2008-08-29 14:32 2132
                        time=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2133
                    }
89c4a3a6 sago007 2008-08-29 14:32 2134
            }
89c4a3a6 sago007 2008-08-29 14:32 2135
89c4a3a6 sago007 2008-08-29 14:32 2136
        }	//while(event)
89c4a3a6 sago007 2008-08-29 14:32 2137
89c4a3a6 sago007 2008-08-29 14:32 2138
        if (SDL_GetTicks()>(time+repeatDelay))
89c4a3a6 sago007 2008-08-29 14:32 2139
        {
89c4a3a6 sago007 2008-08-29 14:32 2140
            time = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2141
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2142
            if ( (keys[SDLK_BACKSPACE])&&(repeating) )
89c4a3a6 sago007 2008-08-29 14:32 2143
            {
89c4a3a6 sago007 2008-08-29 14:32 2144
                if ((rk.ReadKey(SDLK_BACKSPACE))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 2145
            }
89c4a3a6 sago007 2008-08-29 14:32 2146
            else
89c4a3a6 sago007 2008-08-29 14:32 2147
                repeating = false;
89c4a3a6 sago007 2008-08-29 14:32 2148
        }
89c4a3a6 sago007 2008-08-29 14:32 2149
89c4a3a6 sago007 2008-08-29 14:32 2150
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2151
    }	//while(!done)
89c4a3a6 sago007 2008-08-29 14:32 2152
    strcpy(name,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 2153
    bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 2154
    showDialog = false;
89c4a3a6 sago007 2008-08-29 14:32 2155
    return accept;
89c4a3a6 sago007 2008-08-29 14:32 2156
}
89c4a3a6 sago007 2008-08-29 14:32 2157
47529580 sago007 2008-12-09 02:34 2158
//Draws the highscores
47529580 sago007 2008-12-09 02:34 2159
void DrawHighscores(int x, int y, bool endless)
47529580 sago007 2008-12-09 02:34 2160
{
27ae0175 sago007 2009-01-30 06:02 2161
    MakeBackground(xsize,ysize);
47529580 sago007 2008-12-09 02:34 2162
    DrawIMG(background,screen,0,0);
47529580 sago007 2008-12-09 02:34 2163
    if (endless) SFont_Write(screen,fBlueFont,x+100,y+100,"Endless:");
47529580 sago007 2008-12-09 02:34 2164
    else SFont_Write(screen,fBlueFont,x+100,y+100,"Time Trial:");
47529580 sago007 2008-12-09 02:34 2165
    for (int i =0;i<10;i++)
47529580 sago007 2008-12-09 02:34 2166
    {
47529580 sago007 2008-12-09 02:34 2167
        char playerScore[32];
47529580 sago007 2008-12-09 02:34 2168
        char playerName[32];
47529580 sago007 2008-12-09 02:34 2169
        if (endless)
47529580 sago007 2008-12-09 02:34 2170
        {
47529580 sago007 2008-12-09 02:34 2171
            sprintf(playerScore, "%i", theTopScoresEndless.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 2172
        }
47529580 sago007 2008-12-09 02:34 2173
        else
47529580 sago007 2008-12-09 02:34 2174
        {
47529580 sago007 2008-12-09 02:34 2175
            sprintf(playerScore, "%i", theTopScoresTimeTrial.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 2176
        }
47529580 sago007 2008-12-09 02:34 2177
        if (endless)
47529580 sago007 2008-12-09 02:34 2178
        {
47529580 sago007 2008-12-09 02:34 2179
            strcpy(playerName,theTopScoresEndless.getScoreName(i));
47529580 sago007 2008-12-09 02:34 2180
        }
47529580 sago007 2008-12-09 02:34 2181
        else
47529580 sago007 2008-12-09 02:34 2182
        {
47529580 sago007 2008-12-09 02:34 2183
            strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
47529580 sago007 2008-12-09 02:34 2184
        }
47529580 sago007 2008-12-09 02:34 2185
        SFont_Write(screen,fBlueFont,x+420,y+150+i*35,playerScore);
47529580 sago007 2008-12-09 02:34 2186
        SFont_Write(screen,fBlueFont,x+60,y+150+i*35,playerName);
47529580 sago007 2008-12-09 02:34 2187
    }
47529580 sago007 2008-12-09 02:34 2188
}
47529580 sago007 2008-12-09 02:34 2189
47529580 sago007 2008-12-09 02:34 2190
void DrawStats()
81d9c25d sago007 2008-11-24 09:50 2191
{
27ae0175 sago007 2009-01-30 06:02 2192
    MakeBackground(xsize,ysize);
81d9c25d sago007 2008-11-24 09:50 2193
    DrawIMG(background,screen,0,0);
81d9c25d sago007 2008-11-24 09:50 2194
    int y = 5;
81d9c25d sago007 2008-11-24 09:50 2195
    const int y_spacing = 30;
81d9c25d sago007 2008-11-24 09:50 2196
    SFont_Write(screen,fBlueFont,10,y,"Stats");
81d9c25d sago007 2008-11-24 09:50 2197
    y+=y_spacing*2;
81d9c25d sago007 2008-11-24 09:50 2198
    SFont_Write(screen,fBlueFont,10,y,"Chains");
81d9c25d sago007 2008-11-24 09:50 2199
    for(int i=2;i<13;i++)
81d9c25d sago007 2008-11-24 09:50 2200
    {
81d9c25d sago007 2008-11-24 09:50 2201
        y+=y_spacing;
81d9c25d sago007 2008-11-24 09:50 2202
        SFont_Write(screen,fBlueFont,10,y,(itoa(i)+"X").c_str());
81d9c25d sago007 2008-11-24 09:50 2203
        string numberAsString = itoa(Stats::getInstance()->getNumberOf("chainX"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2204
        SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
81d9c25d sago007 2008-11-24 09:50 2205
    }
81d9c25d sago007 2008-11-24 09:50 2206
    y+=y_spacing*2;
81d9c25d sago007 2008-11-24 09:50 2207
    SFont_Write(screen,fBlueFont,10,y,"Lines Pushed: ");
81d9c25d sago007 2008-11-24 09:50 2208
    string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed"));
81d9c25d sago007 2008-11-24 09:50 2209
    SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 2210
81d9c25d sago007 2008-11-24 09:50 2211
    y+=y_spacing;
81d9c25d sago007 2008-11-24 09:50 2212
    SFont_Write(screen,fBlueFont,10,y,"Puzzles solved: ");
81d9c25d sago007 2008-11-24 09:50 2213
    numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved"));
81d9c25d sago007 2008-11-24 09:50 2214
    SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 2215
d07b805e sago007 2009-01-27 13:15 2216
    y+=y_spacing*2;
d07b805e sago007 2009-01-27 13:15 2217
    SFont_Write(screen,fBlueFont,10,y,"Run time: ");
cd12e0fe sago007 2009-01-29 08:47 2218
    commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
d07b805e sago007 2009-01-27 13:15 2219
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 2220
    SFont_Write(screen,fBlueFont,10,y,((string)("Days: "+itoa(ct.days))).c_str());
d07b805e sago007 2009-01-27 13:15 2221
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 2222
    SFont_Write(screen,fBlueFont,10,y,((string)("Hours: "+itoa(ct.hours))).c_str());
d07b805e sago007 2009-01-27 13:15 2223
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 2224
    SFont_Write(screen,fBlueFont,10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
d07b805e sago007 2009-01-27 13:15 2225
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 2226
    SFont_Write(screen,fBlueFont,10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
d07b805e sago007 2009-01-27 13:15 2227
cd12e0fe sago007 2009-01-29 08:47 2228
    y-=y_spacing*4; //Four rows back
27ae0175 sago007 2009-01-30 06:02 2229
    const int x_offset3 = xsize/3+10; //Ofset for three rows
cd12e0fe sago007 2009-01-29 08:47 2230
    SFont_Write(screen,fBlueFont,x_offset3,y,"Play time: ");
cd12e0fe sago007 2009-01-29 08:47 2231
    ct = TimeHandler::getTime("playTime");
cd12e0fe sago007 2009-01-29 08:47 2232
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 2233
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Days: "+itoa(ct.days))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2234
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 2235
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Hours: "+itoa(ct.hours))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2236
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 2237
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2238
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 2239
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2240
27ae0175 sago007 2009-01-30 06:02 2241
    const int x_offset = xsize/2+10;
81d9c25d sago007 2008-11-24 09:50 2242
    y = 5+y_spacing*2;
81d9c25d sago007 2008-11-24 09:50 2243
    SFont_Write(screen,fBlueFont,x_offset,y,"VS CPU (win/loss)");
81d9c25d sago007 2008-11-24 09:50 2244
    for(int i=0;i<7;i++)
81d9c25d sago007 2008-11-24 09:50 2245
    {
81d9c25d sago007 2008-11-24 09:50 2246
        y += y_spacing;
81d9c25d sago007 2008-11-24 09:50 2247
        SFont_Write(screen,fBlueFont,x_offset,y,("AI "+itoa(i+1)).c_str());
81d9c25d sago007 2008-11-24 09:50 2248
        numberAsString = itoa(Stats::getInstance()->getNumberOf("defeatedAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2249
        string numberAsString2 = itoa(Stats::getInstance()->getNumberOf("defeatedByAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2250
        string toPrint = numberAsString + "/" + numberAsString2;
81d9c25d sago007 2008-11-24 09:50 2251
        SFont_Write(screen,fBlueFont,x_offset+230,y,toPrint.c_str());
81d9c25d sago007 2008-11-24 09:50 2252
    }
47529580 sago007 2008-12-09 02:34 2253
}
47529580 sago007 2008-12-09 02:34 2254
47529580 sago007 2008-12-09 02:34 2255
void OpenScoresDisplay()
47529580 sago007 2008-12-09 02:34 2256
{
9050a50a sago007 2008-12-09 13:35 2257
    int mousex,mousey;
47529580 sago007 2008-12-09 02:34 2258
    bool done = false;     //We are done!
47529580 sago007 2008-12-09 02:34 2259
    int page = 0;
47529580 sago007 2008-12-09 02:34 2260
    const int numberOfPages = 3;
7ca669ac sago007 2008-12-09 16:30 2261
    //button coodinates:
7ca669ac sago007 2008-12-09 16:30 2262
    const int scoreX = buttonXsize*2;
7ca669ac sago007 2008-12-09 16:30 2263
    const int scoreY = 0;
7ca669ac sago007 2008-12-09 16:30 2264
    const int backX = 20;
7ca669ac sago007 2008-12-09 16:30 2265
    const int backY = ysize-buttonYsize-20;
7ca669ac sago007 2008-12-09 16:30 2266
    const int nextX = xsize-buttonXsize-20;
7ca669ac sago007 2008-12-09 16:30 2267
    const int nextY = backY;
81d9c25d sago007 2008-11-24 09:50 2268
    while (!done)
81d9c25d sago007 2008-11-24 09:50 2269
    {
47529580 sago007 2008-12-09 02:34 2270
        switch(page)
47529580 sago007 2008-12-09 02:34 2271
        {
47529580 sago007 2008-12-09 02:34 2272
            case 0:
47529580 sago007 2008-12-09 02:34 2273
                //Highscores, endless
47529580 sago007 2008-12-09 02:34 2274
                DrawHighscores(100,100,true);
47529580 sago007 2008-12-09 02:34 2275
                break;
47529580 sago007 2008-12-09 02:34 2276
            case 1:
47529580 sago007 2008-12-09 02:34 2277
                //Highscores, Time Trial
47529580 sago007 2008-12-09 02:34 2278
                DrawHighscores(100,100,false);
47529580 sago007 2008-12-09 02:34 2279
                break;
47529580 sago007 2008-12-09 02:34 2280
            case 2:
47529580 sago007 2008-12-09 02:34 2281
            default:
47529580 sago007 2008-12-09 02:34 2282
                DrawStats();
47529580 sago007 2008-12-09 02:34 2283
        };
47529580 sago007 2008-12-09 02:34 2284
7ca669ac sago007 2008-12-09 16:30 2285
        //Draw buttons:
7ca669ac sago007 2008-12-09 16:30 2286
        DrawIMG(bHighScore,screen,scoreX,scoreY);
7ca669ac sago007 2008-12-09 16:30 2287
        DrawIMG(bBack,screen,backX,backY);
7ca669ac sago007 2008-12-09 16:30 2288
        DrawIMG(bNext,screen,nextX,nextY);
7ca669ac sago007 2008-12-09 16:30 2289
7ca669ac sago007 2008-12-09 16:30 2290
        //Draw page number
7ca669ac sago007 2008-12-09 16:30 2291
        string pageXofY = ((string)"Page ")+itoa(page+1)+((string)" of ")+itoa(numberOfPages);
7ca669ac sago007 2008-12-09 16:30 2292
        SFont_Write(screen,fBlueFont,xsize/2-SFont_TextWidth(fBlueFont,pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
9050a50a sago007 2008-12-09 13:35 2293
        
81d9c25d sago007 2008-11-24 09:50 2294
        SDL_Delay(10);
81d9c25d sago007 2008-11-24 09:50 2295
        SDL_Event event;
9050a50a sago007 2008-12-09 13:35 2296
9050a50a sago007 2008-12-09 13:35 2297
        SDL_GetMouseState(&mousex,&mousey);
81d9c25d sago007 2008-11-24 09:50 2298
        
81d9c25d sago007 2008-11-24 09:50 2299
        while ( SDL_PollEvent(&event) )
81d9c25d sago007 2008-11-24 09:50 2300
        {
9050a50a sago007 2008-12-09 13:35 2301
9050a50a sago007 2008-12-09 13:35 2302
81d9c25d sago007 2008-11-24 09:50 2303
            if ( event.type == SDL_QUIT )  {
81d9c25d sago007 2008-11-24 09:50 2304
                done = true;
81d9c25d sago007 2008-11-24 09:50 2305
            }
81d9c25d sago007 2008-11-24 09:50 2306
81d9c25d sago007 2008-11-24 09:50 2307
            if ( event.type == SDL_KEYDOWN )
81d9c25d sago007 2008-11-24 09:50 2308
            {
47529580 sago007 2008-12-09 02:34 2309
                if( (event.key.keysym.sym == SDLK_RIGHT))
47529580 sago007 2008-12-09 02:34 2310
                {
47529580 sago007 2008-12-09 02:34 2311
                    page++;
47529580 sago007 2008-12-09 02:34 2312
                    if(page>=numberOfPages)
47529580 sago007 2008-12-09 02:34 2313
                        page = 0;
47529580 sago007 2008-12-09 02:34 2314
                }
7ca669ac sago007 2008-12-09 16:30 2315
                else
47529580 sago007 2008-12-09 02:34 2316
                if( (event.key.keysym.sym == SDLK_LEFT))
47529580 sago007 2008-12-09 02:34 2317
                {
47529580 sago007 2008-12-09 02:34 2318
                    page--;
47529580 sago007 2008-12-09 02:34 2319
                    if(page<0)
47529580 sago007 2008-12-09 02:34 2320
                        page = numberOfPages-1;
47529580 sago007 2008-12-09 02:34 2321
                }
7ca669ac sago007 2008-12-09 16:30 2322
                else
7ca669ac sago007 2008-12-09 16:30 2323
                    done = true;
fcd5a134 sago007 2008-12-19 01:11 2324
                
fcd5a134 sago007 2008-12-19 01:11 2325
                if ( event.key.keysym.sym == SDLK_F9 ) {
fcd5a134 sago007 2008-12-19 01:11 2326
                    writeScreenShot();
fcd5a134 sago007 2008-12-19 01:11 2327
                }
47529580 sago007 2008-12-09 02:34 2328
81d9c25d sago007 2008-11-24 09:50 2329
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
81d9c25d sago007 2008-11-24 09:50 2330
                    done = true;
81d9c25d sago007 2008-11-24 09:50 2331
                }
81d9c25d sago007 2008-11-24 09:50 2332
                else
81d9c25d sago007 2008-11-24 09:50 2333
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
81d9c25d sago007 2008-11-24 09:50 2334
                        done = true;
81d9c25d sago007 2008-11-24 09:50 2335
                    }
81d9c25d sago007 2008-11-24 09:50 2336
            }
81d9c25d sago007 2008-11-24 09:50 2337
81d9c25d sago007 2008-11-24 09:50 2338
        }	//while(event)
7ca669ac sago007 2008-12-09 16:30 2339
7ca669ac sago007 2008-12-09 16:30 2340
        // If the mouse button is released, make bMouseUp equal true
7ca669ac sago007 2008-12-09 16:30 2341
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
7ca669ac sago007 2008-12-09 16:30 2342
        {
7ca669ac sago007 2008-12-09 16:30 2343
            bMouseUp=true;
7ca669ac sago007 2008-12-09 16:30 2344
        }
7ca669ac sago007 2008-12-09 16:30 2345
7ca669ac sago007 2008-12-09 16:30 2346
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
7ca669ac sago007 2008-12-09 16:30 2347
        {
7ca669ac sago007 2008-12-09 16:30 2348
            bMouseUp = false;
7ca669ac sago007 2008-12-09 16:30 2349
7ca669ac sago007 2008-12-09 16:30 2350
            //The Score button:
7ca669ac sago007 2008-12-09 16:30 2351
            if((mousex>scoreX) && (mousex<scoreX+buttonXsize) && (mousey>scoreY) && (mousey<scoreY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2352
                done =true;
7ca669ac sago007 2008-12-09 16:30 2353
7ca669ac sago007 2008-12-09 16:30 2354
            //The back button:
7ca669ac sago007 2008-12-09 16:30 2355
            if((mousex>backX) && (mousex<backX+buttonXsize) && (mousey>backY) && (mousey<backY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2356
            {
7ca669ac sago007 2008-12-09 16:30 2357
                page--;
7ca669ac sago007 2008-12-09 16:30 2358
                if(page<0)
7ca669ac sago007 2008-12-09 16:30 2359
                    page = numberOfPages-1;
7ca669ac sago007 2008-12-09 16:30 2360
            }
7ca669ac sago007 2008-12-09 16:30 2361
7ca669ac sago007 2008-12-09 16:30 2362
            //The next button:
7ca669ac sago007 2008-12-09 16:30 2363
            if((mousex>nextX) && (mousex<nextX+buttonXsize) && (mousey>nextY) && (mousey<nextY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2364
            {
7ca669ac sago007 2008-12-09 16:30 2365
                page++;
7ca669ac sago007 2008-12-09 16:30 2366
                if(page>=numberOfPages)
7ca669ac sago007 2008-12-09 16:30 2367
                    page = 0;
7ca669ac sago007 2008-12-09 16:30 2368
            }
7ca669ac sago007 2008-12-09 16:30 2369
        }
7ca669ac sago007 2008-12-09 16:30 2370
9050a50a sago007 2008-12-09 13:35 2371
        DrawIMG(mouse,screen,mousex,mousey);
9050a50a sago007 2008-12-09 13:35 2372
        SDL_Flip(screen); //Update screen
81d9c25d sago007 2008-11-24 09:50 2373
    }
6b1dc7a6 sago007 2010-11-08 21:03 2374
6b1dc7a6 sago007 2010-11-08 21:03 2375
81d9c25d sago007 2008-11-24 09:50 2376
}
81d9c25d sago007 2008-11-24 09:50 2377
89c4a3a6 sago007 2008-08-29 14:32 2378
89c4a3a6 sago007 2008-08-29 14:32 2379
//Open a puzzle file
89c4a3a6 sago007 2008-08-29 14:32 2380
bool OpenFileDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2381
{
89c4a3a6 sago007 2008-08-29 14:32 2382
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2383
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2384
    ListFiles lf = ListFiles();
aca2f4b0 sago007 2009-05-10 18:11 2385
    string folder = (string)SHAREDIR+(string)"/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2386
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2387
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2388
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2389
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2390
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2391
#endif
89c4a3a6 sago007 2008-08-29 14:32 2392
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2393
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2394
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2395
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2396
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2397
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2398
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2399
    {
89c4a3a6 sago007 2008-08-29 14:32 2400
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2401
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2402
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2403
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2404
        {
89c4a3a6 sago007 2008-08-29 14:32 2405
            SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2406
        }
89c4a3a6 sago007 2008-08-29 14:32 2407
89c4a3a6 sago007 2008-08-29 14:32 2408
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2409
89c4a3a6 sago007 2008-08-29 14:32 2410
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2411
        {
89c4a3a6 sago007 2008-08-29 14:32 2412
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2413
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2414
            }
89c4a3a6 sago007 2008-08-29 14:32 2415
89c4a3a6 sago007 2008-08-29 14:32 2416
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2417
            {
89c4a3a6 sago007 2008-08-29 14:32 2418
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2419
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2420
                }
89c4a3a6 sago007 2008-08-29 14:32 2421
89c4a3a6 sago007 2008-08-29 14:32 2422
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2423
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2424
                }
89c4a3a6 sago007 2008-08-29 14:32 2425
89c4a3a6 sago007 2008-08-29 14:32 2426
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2427
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2428
                }
89c4a3a6 sago007 2008-08-29 14:32 2429
            }
89c4a3a6 sago007 2008-08-29 14:32 2430
89c4a3a6 sago007 2008-08-29 14:32 2431
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2432
89c4a3a6 sago007 2008-08-29 14:32 2433
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2434
89c4a3a6 sago007 2008-08-29 14:32 2435
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2436
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2437
        {
89c4a3a6 sago007 2008-08-29 14:32 2438
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2439
        }
89c4a3a6 sago007 2008-08-29 14:32 2440
89c4a3a6 sago007 2008-08-29 14:32 2441
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2442
        {
89c4a3a6 sago007 2008-08-29 14:32 2443
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2444
89c4a3a6 sago007 2008-08-29 14:32 2445
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2446
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2447
            {
89c4a3a6 sago007 2008-08-29 14:32 2448
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2449
            }
89c4a3a6 sago007 2008-08-29 14:32 2450
89c4a3a6 sago007 2008-08-29 14:32 2451
            //The back button:
9050a50a sago007 2008-12-09 13:35 2452
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2453
            {
89c4a3a6 sago007 2008-08-29 14:32 2454
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2455
            }
89c4a3a6 sago007 2008-08-29 14:32 2456
89c4a3a6 sago007 2008-08-29 14:32 2457
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2458
            {
89c4a3a6 sago007 2008-08-29 14:32 2459
                if ( (mousex>x+10) && (mousex<x+480) && (mousey>y+10+i*36) && (mousey<y+10+i*36+32) )
89c4a3a6 sago007 2008-08-29 14:32 2460
                {
89c4a3a6 sago007 2008-08-29 14:32 2461
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2462
                    {
89c4a3a6 sago007 2008-08-29 14:32 2463
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2464
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2465
                    }
89c4a3a6 sago007 2008-08-29 14:32 2466
                }
89c4a3a6 sago007 2008-08-29 14:32 2467
            }
89c4a3a6 sago007 2008-08-29 14:32 2468
        }
89c4a3a6 sago007 2008-08-29 14:32 2469
89c4a3a6 sago007 2008-08-29 14:32 2470
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2471
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2472
    }
89c4a3a6 sago007 2008-08-29 14:32 2473
}
89c4a3a6 sago007 2008-08-29 14:32 2474
89c4a3a6 sago007 2008-08-29 14:32 2475
//Slelect a theme
89c4a3a6 sago007 2008-08-29 14:32 2476
bool SelectThemeDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2477
{
89c4a3a6 sago007 2008-08-29 14:32 2478
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2479
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2480
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2481
    string folder = (string)SHAREDIR+(string)"/themes";
89c4a3a6 sago007 2008-08-29 14:32 2482
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2483
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2484
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2485
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/themes";
89c4a3a6 sago007 2008-08-29 14:32 2486
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2487
#endif
89c4a3a6 sago007 2008-08-29 14:32 2488
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2489
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2490
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2491
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2492
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2493
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2494
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2495
    {
89c4a3a6 sago007 2008-08-29 14:32 2496
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2497
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2498
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2499
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2500
        {
89c4a3a6 sago007 2008-08-29 14:32 2501
            SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2502
        }
89c4a3a6 sago007 2008-08-29 14:32 2503
89c4a3a6 sago007 2008-08-29 14:32 2504
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2505
89c4a3a6 sago007 2008-08-29 14:32 2506
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2507
        {
89c4a3a6 sago007 2008-08-29 14:32 2508
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2509
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2510
            }
89c4a3a6 sago007 2008-08-29 14:32 2511
89c4a3a6 sago007 2008-08-29 14:32 2512
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2513
            {
89c4a3a6 sago007 2008-08-29 14:32 2514
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2515
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2516
                }
89c4a3a6 sago007 2008-08-29 14:32 2517
89c4a3a6 sago007 2008-08-29 14:32 2518
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2519
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2520
                }
89c4a3a6 sago007 2008-08-29 14:32 2521
89c4a3a6 sago007 2008-08-29 14:32 2522
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2523
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2524
                }
89c4a3a6 sago007 2008-08-29 14:32 2525
            }
89c4a3a6 sago007 2008-08-29 14:32 2526
89c4a3a6 sago007 2008-08-29 14:32 2527
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2528
89c4a3a6 sago007 2008-08-29 14:32 2529
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2530
89c4a3a6 sago007 2008-08-29 14:32 2531
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2532
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2533
        {
89c4a3a6 sago007 2008-08-29 14:32 2534
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2535
        }
89c4a3a6 sago007 2008-08-29 14:32 2536
89c4a3a6 sago007 2008-08-29 14:32 2537
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2538
        {
89c4a3a6 sago007 2008-08-29 14:32 2539
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2540
89c4a3a6 sago007 2008-08-29 14:32 2541
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2542
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2543
            {
89c4a3a6 sago007 2008-08-29 14:32 2544
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2545
            }
89c4a3a6 sago007 2008-08-29 14:32 2546
89c4a3a6 sago007 2008-08-29 14:32 2547
            //The back button:
9050a50a sago007 2008-12-09 13:35 2548
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2549
            {
89c4a3a6 sago007 2008-08-29 14:32 2550
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2551
            }
89c4a3a6 sago007 2008-08-29 14:32 2552
89c4a3a6 sago007 2008-08-29 14:32 2553
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2554
            {
89c4a3a6 sago007 2008-08-29 14:32 2555
                if ( (mousex>x+10) && (mousex<x+480) && (mousey>y+10+i*36) && (mousey<y+10+i*36+32) )
89c4a3a6 sago007 2008-08-29 14:32 2556
                {
89c4a3a6 sago007 2008-08-29 14:32 2557
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2558
                    {
89c4a3a6 sago007 2008-08-29 14:32 2559
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2560
                        loadTheme(lf.getFileName(i));
89c4a3a6 sago007 2008-08-29 14:32 2561
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2562
                    }
89c4a3a6 sago007 2008-08-29 14:32 2563
                }
89c4a3a6 sago007 2008-08-29 14:32 2564
            }
89c4a3a6 sago007 2008-08-29 14:32 2565
        }
89c4a3a6 sago007 2008-08-29 14:32 2566
89c4a3a6 sago007 2008-08-29 14:32 2567
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2568
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2569
    }
89c4a3a6 sago007 2008-08-29 14:32 2570
}
89c4a3a6 sago007 2008-08-29 14:32 2571
89c4a3a6 sago007 2008-08-29 14:32 2572
//Open a saved replay
89c4a3a6 sago007 2008-08-29 14:32 2573
bool OpenReplayDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2574
{
89c4a3a6 sago007 2008-08-29 14:32 2575
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2576
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2577
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2578
    cout << "Ready to set directory!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2579
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2580
    string directory = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2581
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 2582
    string directory = getMyDocumentsPath()+(string)"/My Games/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2583
#else
89c4a3a6 sago007 2008-08-29 14:32 2584
    string directory = "./replays";
89c4a3a6 sago007 2008-08-29 14:32 2585
#endif
89c4a3a6 sago007 2008-08-29 14:32 2586
    lf.setDirectory(directory);
89c4a3a6 sago007 2008-08-29 14:32 2587
    cout << "Directory sat" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2588
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2589
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2590
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2591
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2592
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2593
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2594
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2595
    {
89c4a3a6 sago007 2008-08-29 14:32 2596
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2597
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2598
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2599
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2600
        {
89c4a3a6 sago007 2008-08-29 14:32 2601
            SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2602
        }
89c4a3a6 sago007 2008-08-29 14:32 2603
89c4a3a6 sago007 2008-08-29 14:32 2604
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2605
89c4a3a6 sago007 2008-08-29 14:32 2606
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2607
        {
89c4a3a6 sago007 2008-08-29 14:32 2608
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2609
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2610
                return false;
89c4a3a6 sago007 2008-08-29 14:32 2611
            }
89c4a3a6 sago007 2008-08-29 14:32 2612
89c4a3a6 sago007 2008-08-29 14:32 2613
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2614
            {
89c4a3a6 sago007 2008-08-29 14:32 2615
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2616
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2617
                    return false;
89c4a3a6 sago007 2008-08-29 14:32 2618
                }
89c4a3a6 sago007 2008-08-29 14:32 2619
89c4a3a6 sago007 2008-08-29 14:32 2620
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2621
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2622
                }
89c4a3a6 sago007 2008-08-29 14:32 2623
89c4a3a6 sago007 2008-08-29 14:32 2624
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2625
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2626
                }
89c4a3a6 sago007 2008-08-29 14:32 2627
            }
89c4a3a6 sago007 2008-08-29 14:32 2628
89c4a3a6 sago007 2008-08-29 14:32 2629
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2630
89c4a3a6 sago007 2008-08-29 14:32 2631
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2632
89c4a3a6 sago007 2008-08-29 14:32 2633
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2634
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2635
        {
89c4a3a6 sago007 2008-08-29 14:32 2636
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2637
        }
89c4a3a6 sago007 2008-08-29 14:32 2638
89c4a3a6 sago007 2008-08-29 14:32 2639
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2640
        {
89c4a3a6 sago007 2008-08-29 14:32 2641
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2642
89c4a3a6 sago007 2008-08-29 14:32 2643
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2644
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2645
            {
89c4a3a6 sago007 2008-08-29 14:32 2646
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2647
            }
89c4a3a6 sago007 2008-08-29 14:32 2648
89c4a3a6 sago007 2008-08-29 14:32 2649
            //The back button:
9050a50a sago007 2008-12-09 13:35 2650
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2651
            {
89c4a3a6 sago007 2008-08-29 14:32 2652
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2653
            }
89c4a3a6 sago007 2008-08-29 14:32 2654
89c4a3a6 sago007 2008-08-29 14:32 2655
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2656
            {
89c4a3a6 sago007 2008-08-29 14:32 2657
                if ( (mousex>x+10) && (mousex<x+480) && (mousey>y+10+i*36) && (mousey<y+10+i*36+32) )
89c4a3a6 sago007 2008-08-29 14:32 2658
                {
89c4a3a6 sago007 2008-08-29 14:32 2659
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2660
                    {
89c4a3a6 sago007 2008-08-29 14:32 2661
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2662
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2663
                        return true;
89c4a3a6 sago007 2008-08-29 14:32 2664
                    }
89c4a3a6 sago007 2008-08-29 14:32 2665
                }
89c4a3a6 sago007 2008-08-29 14:32 2666
            }
89c4a3a6 sago007 2008-08-29 14:32 2667
        }
89c4a3a6 sago007 2008-08-29 14:32 2668
89c4a3a6 sago007 2008-08-29 14:32 2669
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2670
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2671
    }
89c4a3a6 sago007 2008-08-29 14:32 2672
}
89c4a3a6 sago007 2008-08-29 14:32 2673
89c4a3a6 sago007 2008-08-29 14:32 2674
89c4a3a6 sago007 2008-08-29 14:32 2675
//draws options:
e1290bdf sago007 2010-10-25 19:56 2676
void DrawOptions(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 2677
{
9050a50a sago007 2008-12-09 13:35 2678
    if (MusicEnabled) DrawIMG(bOn,optionsBack,400,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2679
    else DrawIMG(bOff,optionsBack,400,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2680
    if (SoundEnabled) DrawIMG(bOn,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2681
    else DrawIMG(bOff,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2682
    if (bFullscreen) DrawIMG(bOn,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2683
    else DrawIMG(bOff,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2684
    DrawIMG(bChange,optionsBack,230,435);
89c4a3a6 sago007 2008-08-29 14:32 2685
    DrawIMG(bChange,optionsBack,410,435);
89c4a3a6 sago007 2008-08-29 14:32 2686
    DrawIMG(bChange,optionsBack,230,500);
89c4a3a6 sago007 2008-08-29 14:32 2687
    DrawIMG(bChange,optionsBack,410,500);
89c4a3a6 sago007 2008-08-29 14:32 2688
    DrawIMG(optionsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2689
}  //drawOptions
89c4a3a6 sago007 2008-08-29 14:32 2690
89c4a3a6 sago007 2008-08-29 14:32 2691
//Draws the balls and explosions
89c4a3a6 sago007 2008-08-29 14:32 2692
void DrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2693
{
89c4a3a6 sago007 2008-08-29 14:32 2694
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2695
    {
89c4a3a6 sago007 2008-08-29 14:32 2696
        if (theBallManeger.ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2697
        {
89c4a3a6 sago007 2008-08-29 14:32 2698
            DrawIMG(balls[theBallManeger.ballArray[i].getColor()],screen,theBallManeger.ballArray[i].getX(),theBallManeger.ballArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2699
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2700
        if (theExplosionManeger.explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2701
        {
89c4a3a6 sago007 2008-08-29 14:32 2702
            DrawIMG(explosion[theExplosionManeger.explosionArray[i].getFrame()],screen,theExplosionManeger.explosionArray[i].getX(),theExplosionManeger.explosionArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2703
        }
89c4a3a6 sago007 2008-08-29 14:32 2704
        if (theTextManeger.textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2705
        {
89c4a3a6 sago007 2008-08-29 14:32 2706
            //cout << "Printing text: " << theTextManeger.textArray[i].getText() << endl;
89c4a3a6 sago007 2008-08-29 14:32 2707
            int x = theTextManeger.textArray[i].getX()-SFont_TextWidth(fSmallFont,theTextManeger.textArray[i].getText())/2;
89c4a3a6 sago007 2008-08-29 14:32 2708
            int y = theTextManeger.textArray[i].getY()-SFont_TextHeight(fSmallFont)/2;
89c4a3a6 sago007 2008-08-29 14:32 2709
            DrawIMG(iChainBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2710
            SFont_Write(screen,fSmallFont,x+(25-SFont_TextWidth(fSmallFont,theTextManeger.textArray[i].getText()))/2,y+(25-SFont_TextHeight(fSmallFont))/2,theTextManeger.textArray[i].getText());
89c4a3a6 sago007 2008-08-29 14:32 2711
        }
89c4a3a6 sago007 2008-08-29 14:32 2712
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2713
}    //DrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2714
89c4a3a6 sago007 2008-08-29 14:32 2715
//Removes the old balls
89c4a3a6 sago007 2008-08-29 14:32 2716
void UndrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2717
{
89c4a3a6 sago007 2008-08-29 14:32 2718
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2719
    {
89c4a3a6 sago007 2008-08-29 14:32 2720
        if (theBallManeger.oldBallUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2721
        {
89c4a3a6 sago007 2008-08-29 14:32 2722
            DrawIMG(background,screen,theBallManeger.oldBallArray[i].getX(),theBallManeger.oldBallArray[i].getY(),ballSize,ballSize,theBallManeger.oldBallArray[i].getX(),theBallManeger.oldBallArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2723
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2724
        if (theExplosionManeger.oldExplosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2725
        {
89c4a3a6 sago007 2008-08-29 14:32 2726
            DrawIMG(background,screen,theExplosionManeger.oldExplosionArray[i].getX(),theExplosionManeger.oldExplosionArray[i].getY(),70,120,theExplosionManeger.oldExplosionArray[i].getX(),theExplosionManeger.oldExplosionArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2727
        }
89c4a3a6 sago007 2008-08-29 14:32 2728
        if (theTextManeger.oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2729
        {
89c4a3a6 sago007 2008-08-29 14:32 2730
            int x = theTextManeger.oldTextArray[i].getX()-SFont_TextWidth(fSmallFont,theTextManeger.oldTextArray[i].getText())/2;
89c4a3a6 sago007 2008-08-29 14:32 2731
            int y = theTextManeger.oldTextArray[i].getY()-SFont_TextHeight(fSmallFont)/2;
89c4a3a6 sago007 2008-08-29 14:32 2732
            DrawIMG(background,screen,x,y,25,25,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2733
        }
89c4a3a6 sago007 2008-08-29 14:32 2734
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2735
}   //UndrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2736
89c4a3a6 sago007 2008-08-29 14:32 2737
//draws everything
6b1dc7a6 sago007 2010-11-08 21:03 2738
void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2739
{
89c4a3a6 sago007 2008-08-29 14:32 2740
    SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 2741
    //draw background:
89c4a3a6 sago007 2008-08-29 14:32 2742
    if (forceredraw != 1)
89c4a3a6 sago007 2008-08-29 14:32 2743
    {
89c4a3a6 sago007 2008-08-29 14:32 2744
89c4a3a6 sago007 2008-08-29 14:32 2745
        UndrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2746
        DrawIMG(background,screen,oldMousex,oldMousey,32,32,oldMousex,oldMousey);
89c4a3a6 sago007 2008-08-29 14:32 2747
        DrawIMG(background,screen,oldBubleX,oldBubleY,140,50,oldBubleX,oldBubleY);
89c4a3a6 sago007 2008-08-29 14:32 2748
89c4a3a6 sago007 2008-08-29 14:32 2749
89c4a3a6 sago007 2008-08-29 14:32 2750
        DrawIMG(background,screen,350,200,120,200,350,200);
89c4a3a6 sago007 2008-08-29 14:32 2751
        DrawIMG(background,screen,830,200,120,200,830,200);
89c4a3a6 sago007 2008-08-29 14:32 2752
        DrawIMG(background,screen,800,0,140,50,800,0);
89c4a3a6 sago007 2008-08-29 14:32 2753
89c4a3a6 sago007 2008-08-29 14:32 2754
        DrawIMG(background,screen,50,60,300,50,50,60);
89c4a3a6 sago007 2008-08-29 14:32 2755
        DrawIMG(background,screen,510,60,300,50,510,60);
89c4a3a6 sago007 2008-08-29 14:32 2756
    }
89c4a3a6 sago007 2008-08-29 14:32 2757
    else
89c4a3a6 sago007 2008-08-29 14:32 2758
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2759
    //draw bottons (should be moves and drawn directly to background once)
89c4a3a6 sago007 2008-08-29 14:32 2760
    if (!editorMode)
2f30c381 sago007 2008-09-14 13:08 2761
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2762
        if (!networkActive) //We don't show the menu while running server or connected to a server
2f30c381 sago007 2008-09-14 13:08 2763
        #else
2f30c381 sago007 2008-09-14 13:08 2764
            if(true)
2f30c381 sago007 2008-09-14 13:08 2765
        #endif
89c4a3a6 sago007 2008-08-29 14:32 2766
        {
89c4a3a6 sago007 2008-08-29 14:32 2767
            //Here we draw the menu
89c4a3a6 sago007 2008-08-29 14:32 2768
            DrawIMG(bNewGame, screen, 0, 0);
9050a50a sago007 2008-12-09 13:35 2769
            DrawIMG(bOptions, screen, buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2770
            DrawIMG(bHighScore, screen, 2*buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2771
            DrawIMG(bReplay,screen,3*buttonXsize,0);
89c4a3a6 sago007 2008-08-29 14:32 2772
        }
89c4a3a6 sago007 2008-08-29 14:32 2773
        else
89c4a3a6 sago007 2008-08-29 14:32 2774
        { //If network is active
89c4a3a6 sago007 2008-08-29 14:32 2775
            DrawIMG(bBack, screen, 0, 0); //Display a disconnect button
89c4a3a6 sago007 2008-08-29 14:32 2776
        }
89c4a3a6 sago007 2008-08-29 14:32 2777
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2778
        DrawIMG(bExit, screen, xsize-120,ysize-120);
e1290bdf sago007 2010-10-25 19:56 2779
    //DrawIMG(boardBackBack,screen,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2780
    DrawIMG(theGame->sBoard,screen,theGame->GetTopX(),theGame->GetTopY());
89c4a3a6 sago007 2008-08-29 14:32 2781
    string strHolder;
e1290bdf sago007 2010-10-25 19:56 2782
    strHolder = itoa(theGame->GetScore()+theGame->GetHandicap());
e1290bdf sago007 2010-10-25 19:56 2783
    SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2784
    if (theGame->GetAIenabled())
e1290bdf sago007 2010-10-25 19:56 2785
        SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2786
    else
89c4a3a6 sago007 2008-08-29 14:32 2787
        if (editorMode)
e1290bdf sago007 2010-10-25 19:56 2788
            SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,"Playing field");
89c4a3a6 sago007 2008-08-29 14:32 2789
        else
89c4a3a6 sago007 2008-08-29 14:32 2790
            if (!singlePuzzle)
e1290bdf sago007 2010-10-25 19:56 2791
                SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,player1name);
e1290bdf sago007 2010-10-25 19:56 2792
    if (theGame->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2793
    {
e1290bdf sago007 2010-10-25 19:56 2794
        int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2795
        int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2796
        int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2797
        if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2798
        {
e1290bdf sago007 2010-10-25 19:56 2799
            minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2800
            seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2801
        }
89c4a3a6 sago007 2008-08-29 14:32 2802
        else
89c4a3a6 sago007 2008-08-29 14:32 2803
        {
e1290bdf sago007 2010-10-25 19:56 2804
            minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2805
            seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2806
        }
e1290bdf sago007 2010-10-25 19:56 2807
        if (theGame->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2808
        if (theGame->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2809
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2810
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2811
        else strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2812
        //if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
e1290bdf sago007 2010-10-25 19:56 2813
        SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2814
    }
89c4a3a6 sago007 2008-08-29 14:32 2815
    else
89c4a3a6 sago007 2008-08-29 14:32 2816
    {
e1290bdf sago007 2010-10-25 19:56 2817
        int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2818
        int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2819
        if (theGame->isGameOver()) minutes=(theGame->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2820
        if (theGame->isGameOver()) seconds=(theGame->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2821
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2822
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2823
        else
89c4a3a6 sago007 2008-08-29 14:32 2824
            strHolder = itoa(minutes)+":0"+itoa(seconds);
e1290bdf sago007 2010-10-25 19:56 2825
        SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2826
    }
e1290bdf sago007 2010-10-25 19:56 2827
    strHolder = itoa(theGame->GetChains());
e1290bdf sago007 2010-10-25 19:56 2828
    SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2829
    //drawspeedLevel:
e1290bdf sago007 2010-10-25 19:56 2830
    strHolder = itoa(theGame->GetSpeedLevel());
e1290bdf sago007 2010-10-25 19:56 2831
    SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2832
    if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY()))
89c4a3a6 sago007 2008-08-29 14:32 2833
    {
e1290bdf sago007 2010-10-25 19:56 2834
        oldBubleX = theGame->GetTopX()+280;
e1290bdf sago007 2010-10-25 19:56 2835
        oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1;
e1290bdf sago007 2010-10-25 19:56 2836
        DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
89c4a3a6 sago007 2008-08-29 14:32 2837
    }
89c4a3a6 sago007 2008-08-29 14:32 2838
    //player1 finnish, player2 start
e1290bdf sago007 2010-10-25 19:56 2839
    //DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2840
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2841
    {
f72abf8b sago007 2010-01-16 20:00 2842
        /*
f72abf8b sago007 2010-01-16 20:00 2843
         *If single player mode (and not VS)
f72abf8b sago007 2010-01-16 20:00 2844
         */
e1290bdf sago007 2010-10-25 19:56 2845
        if(!twoPlayers && !theGame->isGameOver())
e2de69cf sago007 2010-01-15 22:48 2846
        {
f72abf8b sago007 2010-01-16 20:00 2847
            //Blank player2's board:
e1290bdf sago007 2010-10-25 19:56 2848
            DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
f72abf8b sago007 2010-01-16 20:00 2849
            //Write a description:
e1290bdf sago007 2010-10-25 19:56 2850
            if(theGame->isTimeTrial())
f72abf8b sago007 2010-01-16 20:00 2851
            {
e1290bdf sago007 2010-10-25 19:56 2852
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial");
e1290bdf sago007 2010-10-25 19:56 2853
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2854
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much");
e1290bdf sago007 2010-10-25 19:56 2855
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "as possible in");
e1290bdf sago007 2010-10-25 19:56 2856
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"2 minutes");
e1290bdf sago007 2010-10-25 19:56 2857
            } else if(theGame->isStageClear())
f72abf8b sago007 2010-01-16 20:00 2858
            {
e1290bdf sago007 2010-10-25 19:56 2859
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear");
e1290bdf sago007 2010-10-25 19:56 2860
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2861
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "You must clear a");
e1290bdf sago007 2010-10-25 19:56 2862
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "number of lines.");
e1290bdf sago007 2010-10-25 19:56 2863
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"Speed is rapidly");
e1290bdf sago007 2010-10-25 19:56 2864
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"increased.");
e1290bdf sago007 2010-10-25 19:56 2865
            } else if(theGame->isPuzzleMode())
f72abf8b sago007 2010-01-16 20:00 2866
            {
e1290bdf sago007 2010-10-25 19:56 2867
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle");
e1290bdf sago007 2010-10-25 19:56 2868
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2869
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Clear the entire");
e1290bdf sago007 2010-10-25 19:56 2870
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "board with a");
e1290bdf sago007 2010-10-25 19:56 2871
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limited number of");
e1290bdf sago007 2010-10-25 19:56 2872
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"moves.");
f72abf8b sago007 2010-01-16 20:00 2873
            } else
f72abf8b sago007 2010-01-16 20:00 2874
            {
e1290bdf sago007 2010-10-25 19:56 2875
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless");
e1290bdf sago007 2010-10-25 19:56 2876
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2877
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much as");
e1290bdf sago007 2010-10-25 19:56 2878
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "possible. No time");
e1290bdf sago007 2010-10-25 19:56 2879
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limit.");
f72abf8b sago007 2010-01-16 20:00 2880
            }
f72abf8b sago007 2010-01-16 20:00 2881
f72abf8b sago007 2010-01-16 20:00 2882
            //Write the keys that are in use
e1290bdf sago007 2010-10-25 19:56 2883
            int y = theGame2->GetTopY()+400;
e1290bdf sago007 2010-10-25 19:56 2884
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y,"Movement keys:" );
e1290bdf sago007 2010-10-25 19:56 2885
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
e1290bdf sago007 2010-10-25 19:56 2886
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
e1290bdf sago007 2010-10-25 19:56 2887
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+120,("Switch: "+getKeyName(keySettings[0].change) ).c_str() );
e1290bdf sago007 2010-10-25 19:56 2888
            if(theGame->isPuzzleMode())
e1290bdf sago007 2010-10-25 19:56 2889
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+160,("Restart: "+getKeyName(keySettings[0].push) ).c_str() );
f72abf8b sago007 2010-01-16 20:00 2890
            else
e1290bdf sago007 2010-10-25 19:56 2891
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+160,("Push line: "+getKeyName(keySettings[0].push) ).c_str() );
e2de69cf sago007 2010-01-15 22:48 2892
        }
e2de69cf sago007 2010-01-15 22:48 2893
        else
e1290bdf sago007 2010-10-25 19:56 2894
            DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
e1290bdf sago007 2010-10-25 19:56 2895
        strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap());
e1290bdf sago007 2010-10-25 19:56 2896
        SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2897
        if (theGame2->GetAIenabled())
e1290bdf sago007 2010-10-25 19:56 2898
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+10,theGame2->GetTopY()-40,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2899
        else
e1290bdf sago007 2010-10-25 19:56 2900
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+10,theGame2->GetTopY()-40,theGame2->name);
e1290bdf sago007 2010-10-25 19:56 2901
        if (theGame2->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2902
        {
e1290bdf sago007 2010-10-25 19:56 2903
            int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2904
            int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2905
            int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2906
            if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2907
            {
e1290bdf sago007 2010-10-25 19:56 2908
                minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2909
                seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2910
            }
89c4a3a6 sago007 2008-08-29 14:32 2911
            else
89c4a3a6 sago007 2008-08-29 14:32 2912
            {
e1290bdf sago007 2010-10-25 19:56 2913
                minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2914
                seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2915
            }
e1290bdf sago007 2010-10-25 19:56 2916
            if (theGame2->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2917
            if (theGame2->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2918
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2919
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2920
            else
89c4a3a6 sago007 2008-08-29 14:32 2921
                strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2922
            //if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
e1290bdf sago007 2010-10-25 19:56 2923
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2924
        }
89c4a3a6 sago007 2008-08-29 14:32 2925
        else
89c4a3a6 sago007 2008-08-29 14:32 2926
        {
e1290bdf sago007 2010-10-25 19:56 2927
            int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2928
            int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2929
            if (theGame2->isGameOver()) minutes=(theGame2->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2930
            if (theGame2->isGameOver()) seconds=(theGame2->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2931
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2932
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2933
            else
89c4a3a6 sago007 2008-08-29 14:32 2934
                strHolder = itoa(minutes)+":0"+itoa(seconds);
e1290bdf sago007 2010-10-25 19:56 2935
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2936
        }
e1290bdf sago007 2010-10-25 19:56 2937
        strHolder = itoa(theGame2->GetChains());
e1290bdf sago007 2010-10-25 19:56 2938
        SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2939
        strHolder = itoa(theGame2->GetSpeedLevel());
e1290bdf sago007 2010-10-25 19:56 2940
        SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2941
    }
89c4a3a6 sago007 2008-08-29 14:32 2942
    //player2 finnish
89c4a3a6 sago007 2008-08-29 14:32 2943
89c4a3a6 sago007 2008-08-29 14:32 2944
    if (bNewGameOpen)
89c4a3a6 sago007 2008-08-29 14:32 2945
    {
89c4a3a6 sago007 2008-08-29 14:32 2946
        DrawIMG(b1player,screen,0,40);
89c4a3a6 sago007 2008-08-29 14:32 2947
        DrawIMG(b2players,screen,0,80);
1572de2b sago007 2008-09-11 18:15 2948
#if NETWORK
9050a50a sago007 2008-12-09 13:35 2949
        DrawIMG(bNetwork,screen,0,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2950
#endif
89c4a3a6 sago007 2008-08-29 14:32 2951
        if (b1playerOpen)
89c4a3a6 sago007 2008-08-29 14:32 2952
        {
9050a50a sago007 2008-12-09 13:35 2953
            DrawIMG(bEndless,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2954
            DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2955
            DrawIMG(bStageClear,screen,buttonXsize,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2956
            DrawIMG(bPuzzle,screen,buttonXsize,160);
9050a50a sago007 2008-12-09 13:35 2957
            DrawIMG(bVsMode,screen,buttonXsize,200);
89c4a3a6 sago007 2008-08-29 14:32 2958
        }
89c4a3a6 sago007 2008-08-29 14:32 2959
        else
89c4a3a6 sago007 2008-08-29 14:32 2960
            if (b2playersOpen)
89c4a3a6 sago007 2008-08-29 14:32 2961
            {
9050a50a sago007 2008-12-09 13:35 2962
                DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2963
                DrawIMG(bVsMode,screen,buttonXsize,120);
89c4a3a6 sago007 2008-08-29 14:32 2964
            }
1572de2b sago007 2008-09-11 18:15 2965
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2966
            else
89c4a3a6 sago007 2008-08-29 14:32 2967
                if (bNetworkOpen)
89c4a3a6 sago007 2008-08-29 14:32 2968
                {
9050a50a sago007 2008-12-09 13:35 2969
                    DrawIMG(bHost,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2970
                    DrawIMG(bConnect,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2971
                }
89c4a3a6 sago007 2008-08-29 14:32 2972
#endif
89c4a3a6 sago007 2008-08-29 14:32 2973
    }
89c4a3a6 sago007 2008-08-29 14:32 2974
    if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 2975
    {
9050a50a sago007 2008-12-09 13:35 2976
        DrawIMG(bConfigure,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2977
        DrawIMG(bSelectPuzzle,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2978
        DrawIMG(bVsModeConfig,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2979
        DrawIMG(bTheme,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2980
    }
89c4a3a6 sago007 2008-08-29 14:32 2981
    if (bReplayOpen)
89c4a3a6 sago007 2008-08-29 14:32 2982
    {
89c4a3a6 sago007 2008-08-29 14:32 2983
        DrawIMG(bSave,screen,360,40);
89c4a3a6 sago007 2008-08-29 14:32 2984
        DrawIMG(bLoad,screen,360,80);
89c4a3a6 sago007 2008-08-29 14:32 2985
    }
89c4a3a6 sago007 2008-08-29 14:32 2986
    if (showOptions) DrawOptions(100,100);
89c4a3a6 sago007 2008-08-29 14:32 2987
89c4a3a6 sago007 2008-08-29 14:32 2988
    DrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2989
1572de2b sago007 2008-09-11 18:15 2990
#if DEBUG
89c4a3a6 sago007 2008-08-29 14:32 2991
    Frames++;
89c4a3a6 sago007 2008-08-29 14:32 2992
    if (SDL_GetTicks() >= Ticks + 1000)
89c4a3a6 sago007 2008-08-29 14:32 2993
    {
89c4a3a6 sago007 2008-08-29 14:32 2994
        if (Frames > 999) Frames=999;
78d03b38 sago007 2008-11-13 19:56 2995
        sprintf(FPS, "%lu fps", Frames);
89c4a3a6 sago007 2008-08-29 14:32 2996
        Frames = 0;
89c4a3a6 sago007 2008-08-29 14:32 2997
        Ticks = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2998
    }
89c4a3a6 sago007 2008-08-29 14:32 2999
89c4a3a6 sago007 2008-08-29 14:32 3000
    SFont_Write(screen,fBlueFont,800,4,FPS);
89c4a3a6 sago007 2008-08-29 14:32 3001
#endif
89c4a3a6 sago007 2008-08-29 14:32 3002
89c4a3a6 sago007 2008-08-29 14:32 3003
    //SDL_Flip(screen); Update screen is now called outside DrawEvrything, bacause the mouse needs to be painted
89c4a3a6 sago007 2008-08-29 14:32 3004
89c4a3a6 sago007 2008-08-29 14:32 3005
}
89c4a3a6 sago007 2008-08-29 14:32 3006
89c4a3a6 sago007 2008-08-29 14:32 3007
//Generates the standard background
89c4a3a6 sago007 2008-08-29 14:32 3008
void MakeBackground(int xsize,int ysize)
89c4a3a6 sago007 2008-08-29 14:32 3009
{
27ae0175 sago007 2009-01-30 06:02 3010
    int w = backgroundImage->w;
27ae0175 sago007 2009-01-30 06:02 3011
    int h = backgroundImage->h;
27ae0175 sago007 2009-01-30 06:02 3012
    for(int i=0;i*w<xsize;i++)
27ae0175 sago007 2009-01-30 06:02 3013
        for(int j=0;j*h<ysize;j++)
27ae0175 sago007 2009-01-30 06:02 3014
            DrawIMG(backgroundImage,background,i*w,j*h);
89c4a3a6 sago007 2008-08-29 14:32 3015
    standardBackground = true;
89c4a3a6 sago007 2008-08-29 14:32 3016
}
89c4a3a6 sago007 2008-08-29 14:32 3017
89c4a3a6 sago007 2008-08-29 14:32 3018
//Generates the background with red board backs
e1290bdf sago007 2010-10-25 19:56 3019
void MakeBackground(int xsize,int ysize,BlockGame *theGame, BlockGame *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 3020
{
27ae0175 sago007 2009-01-30 06:02 3021
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 3022
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 3023
    DrawIMG(boardBackBack,background,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 3024
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 3025
}
89c4a3a6 sago007 2008-08-29 14:32 3026
e1290bdf sago007 2010-10-25 19:56 3027
void MakeBackground(int xsize, int ysize, BlockGame *theGame)
89c4a3a6 sago007 2008-08-29 14:32 3028
{
27ae0175 sago007 2009-01-30 06:02 3029
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 3030
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 3031
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 3032
}
89c4a3a6 sago007 2008-08-29 14:32 3033
89c4a3a6 sago007 2008-08-29 14:32 3034
89c4a3a6 sago007 2008-08-29 14:32 3035
//The function that allows the player to choose PuzzleLevel
89c4a3a6 sago007 2008-08-29 14:32 3036
int PuzzleLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 3037
{
89c4a3a6 sago007 2008-08-29 14:32 3038
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3039
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 3040
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3041
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 3042
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 3043
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 3044
89c4a3a6 sago007 2008-08-29 14:32 3045
    //Loads the levels, if they havn't been loaded:
89c4a3a6 sago007 2008-08-29 14:32 3046
    LoadPuzzleStages();
89c4a3a6 sago007 2008-08-29 14:32 3047
89c4a3a6 sago007 2008-08-29 14:32 3048
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3049
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3050
89c4a3a6 sago007 2008-08-29 14:32 3051
    ifstream puzzleFile(puzzleSavePath.c_str(),ios::binary);
27ae0175 sago007 2009-01-30 06:02 3052
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3053
    if (puzzleFile)
89c4a3a6 sago007 2008-08-29 14:32 3054
    {
89c4a3a6 sago007 2008-08-29 14:32 3055
        for (int i=0;(i<nrOfPuzzles)&&(!puzzleFile.eof()); i++)
89c4a3a6 sago007 2008-08-29 14:32 3056
        {
89c4a3a6 sago007 2008-08-29 14:32 3057
            puzzleFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 3058
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 3059
        }
89c4a3a6 sago007 2008-08-29 14:32 3060
        puzzleFile.close();
89c4a3a6 sago007 2008-08-29 14:32 3061
    }
89c4a3a6 sago007 2008-08-29 14:32 3062
    else
89c4a3a6 sago007 2008-08-29 14:32 3063
    {
89c4a3a6 sago007 2008-08-29 14:32 3064
        tempBool = false;
89c4a3a6 sago007 2008-08-29 14:32 3065
        for (int i=0; i<nrOfPuzzles; i++)
89c4a3a6 sago007 2008-08-29 14:32 3066
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 3067
    }
89c4a3a6 sago007 2008-08-29 14:32 3068
89c4a3a6 sago007 2008-08-29 14:32 3069
    do
89c4a3a6 sago007 2008-08-29 14:32 3070
    {
89c4a3a6 sago007 2008-08-29 14:32 3071
        nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3072
89c4a3a6 sago007 2008-08-29 14:32 3073
89c4a3a6 sago007 2008-08-29 14:32 3074
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3075
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 3076
        SFont_Write(screen,fBlueFont,xplace+12,yplace+2,"Select Puzzle");
89c4a3a6 sago007 2008-08-29 14:32 3077
        //Now drow the fields you click in (and a V if clicked):
89c4a3a6 sago007 2008-08-29 14:32 3078
        for (int i = 0; i < nrOfPuzzles;i++)
89c4a3a6 sago007 2008-08-29 14:32 3079
        {
89c4a3a6 sago007 2008-08-29 14:32 3080
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 3081
            if (puzzleCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 3082
        }
89c4a3a6 sago007 2008-08-29 14:32 3083
89c4a3a6 sago007 2008-08-29 14:32 3084
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3085
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3086
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3087
            {
89c4a3a6 sago007 2008-08-29 14:32 3088
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3089
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 3090
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 3091
                }
89c4a3a6 sago007 2008-08-29 14:32 3092
            }
89c4a3a6 sago007 2008-08-29 14:32 3093
89c4a3a6 sago007 2008-08-29 14:32 3094
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3095
89c4a3a6 sago007 2008-08-29 14:32 3096
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3097
89c4a3a6 sago007 2008-08-29 14:32 3098
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3099
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3100
        {
89c4a3a6 sago007 2008-08-29 14:32 3101
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3102
        }
89c4a3a6 sago007 2008-08-29 14:32 3103
89c4a3a6 sago007 2008-08-29 14:32 3104
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3105
        {
89c4a3a6 sago007 2008-08-29 14:32 3106
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3107
89c4a3a6 sago007 2008-08-29 14:32 3108
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 3109
            int i;
89c4a3a6 sago007 2008-08-29 14:32 3110
            for (i = 0; (i<nrOfPuzzles/10)||((i<nrOfPuzzles/10+1)&&(nrOfPuzzles%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 3111
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 3112
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 3113
            i++;
89c4a3a6 sago007 2008-08-29 14:32 3114
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 3115
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 3116
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 3117
                    {
89c4a3a6 sago007 2008-08-29 14:32 3118
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 3119
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 3120
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 3121
                    }
89c4a3a6 sago007 2008-08-29 14:32 3122
        }
89c4a3a6 sago007 2008-08-29 14:32 3123
89c4a3a6 sago007 2008-08-29 14:32 3124
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3125
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3126
89c4a3a6 sago007 2008-08-29 14:32 3127
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 3128
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3129
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 3130
}
89c4a3a6 sago007 2008-08-29 14:32 3131
89c4a3a6 sago007 2008-08-29 14:32 3132
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 3133
int StageLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 3134
{
89c4a3a6 sago007 2008-08-29 14:32 3135
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3136
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 3137
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3138
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 3139
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 3140
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 3141
    Uint32 tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 3142
    Uint32 totalScore = 0;
89c4a3a6 sago007 2008-08-29 14:32 3143
    Uint32 totalTime = 0;
89c4a3a6 sago007 2008-08-29 14:32 3144
89c4a3a6 sago007 2008-08-29 14:32 3145
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3146
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3147
27ae0175 sago007 2009-01-30 06:02 3148
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3149
    ifstream stageFile(stageClearSavePath.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 3150
    if (stageFile)
89c4a3a6 sago007 2008-08-29 14:32 3151
    {
89c4a3a6 sago007 2008-08-29 14:32 3152
        for (int i = 0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 3153
        {
89c4a3a6 sago007 2008-08-29 14:32 3154
            stageFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 3155
            stageCleared[i]=tempBool;
89c4a3a6 sago007 2008-08-29 14:32 3156
        }
89c4a3a6 sago007 2008-08-29 14:32 3157
        if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 3158
        {
89c4a3a6 sago007 2008-08-29 14:32 3159
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 3160
            {
89c4a3a6 sago007 2008-08-29 14:32 3161
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 3162
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 3163
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 3164
                stageScores[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 3165
                totalScore+=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 3166
            }
89c4a3a6 sago007 2008-08-29 14:32 3167
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 3168
            {
89c4a3a6 sago007 2008-08-29 14:32 3169
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 3170
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 3171
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 3172
                stageTimes[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 3173
                totalTime += tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 3174
            }
89c4a3a6 sago007 2008-08-29 14:32 3175
        }
89c4a3a6 sago007 2008-08-29 14:32 3176
        else
89c4a3a6 sago007 2008-08-29 14:32 3177
        {
89c4a3a6 sago007 2008-08-29 14:32 3178
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 3179
            {
89c4a3a6 sago007 2008-08-29 14:32 3180
                 stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3181
                 stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3182
            }
89c4a3a6 sago007 2008-08-29 14:32 3183
        }
89c4a3a6 sago007 2008-08-29 14:32 3184
        stageFile.close();
89c4a3a6 sago007 2008-08-29 14:32 3185
    }
89c4a3a6 sago007 2008-08-29 14:32 3186
    else
89c4a3a6 sago007 2008-08-29 14:32 3187
    {
89c4a3a6 sago007 2008-08-29 14:32 3188
        for (int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 3189
        {
89c4a3a6 sago007 2008-08-29 14:32 3190
            stageCleared[i]= false;
89c4a3a6 sago007 2008-08-29 14:32 3191
            stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3192
            stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3193
        }
89c4a3a6 sago007 2008-08-29 14:32 3194
    }
89c4a3a6 sago007 2008-08-29 14:32 3195
89c4a3a6 sago007 2008-08-29 14:32 3196
89c4a3a6 sago007 2008-08-29 14:32 3197
    do
89c4a3a6 sago007 2008-08-29 14:32 3198
    {
89c4a3a6 sago007 2008-08-29 14:32 3199
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3200
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3201
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 3202
        SFont_Write(screen,fBlueFont,xplace+12,yplace+2,"Stage Clear Level Select");
89c4a3a6 sago007 2008-08-29 14:32 3203
        for (int i = 0; i < nrOfStageLevels;i++)
89c4a3a6 sago007 2008-08-29 14:32 3204
        {
89c4a3a6 sago007 2008-08-29 14:32 3205
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 3206
            if (stageCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 3207
        }
89c4a3a6 sago007 2008-08-29 14:32 3208
89c4a3a6 sago007 2008-08-29 14:32 3209
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3210
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3211
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3212
            {
89c4a3a6 sago007 2008-08-29 14:32 3213
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3214
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 3215
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 3216
                }
89c4a3a6 sago007 2008-08-29 14:32 3217
            }
89c4a3a6 sago007 2008-08-29 14:32 3218
89c4a3a6 sago007 2008-08-29 14:32 3219
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3220
89c4a3a6 sago007 2008-08-29 14:32 3221
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3222
89c4a3a6 sago007 2008-08-29 14:32 3223
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3224
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3225
        {
89c4a3a6 sago007 2008-08-29 14:32 3226
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3227
        }
89c4a3a6 sago007 2008-08-29 14:32 3228
89c4a3a6 sago007 2008-08-29 14:32 3229
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3230
        {
89c4a3a6 sago007 2008-08-29 14:32 3231
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3232
89c4a3a6 sago007 2008-08-29 14:32 3233
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 3234
            int i;
89c4a3a6 sago007 2008-08-29 14:32 3235
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 3236
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 3237
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 3238
            i++;
89c4a3a6 sago007 2008-08-29 14:32 3239
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 3240
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 3241
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 3242
                    {
89c4a3a6 sago007 2008-08-29 14:32 3243
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 3244
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 3245
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 3246
                    }
89c4a3a6 sago007 2008-08-29 14:32 3247
        }
89c4a3a6 sago007 2008-08-29 14:32 3248
        //Find what we are over:
89c4a3a6 sago007 2008-08-29 14:32 3249
            int overLevel = -1;
89c4a3a6 sago007 2008-08-29 14:32 3250
            int i;
89c4a3a6 sago007 2008-08-29 14:32 3251
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 3252
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 3253
                    overLevel = i*10;
89c4a3a6 sago007 2008-08-29 14:32 3254
            i++;
89c4a3a6 sago007 2008-08-29 14:32 3255
            if (overLevel != -1)
89c4a3a6 sago007 2008-08-29 14:32 3256
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 3257
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 3258
                    {
89c4a3a6 sago007 2008-08-29 14:32 3259
                        overLevel +=j;
89c4a3a6 sago007 2008-08-29 14:32 3260
                        string scoreString = "Best score: 0";
89c4a3a6 sago007 2008-08-29 14:32 3261
                        string timeString = "Time used: -- : --";
89c4a3a6 sago007 2008-08-29 14:32 3262
                        
89c4a3a6 sago007 2008-08-29 14:32 3263
                        if(stageScores.at(overLevel)>0)
89c4a3a6 sago007 2008-08-29 14:32 3264
                            scoreString = "Best score: "+itoa(stageScores[overLevel]);
89c4a3a6 sago007 2008-08-29 14:32 3265
                        if(stageTimes[overLevel]>0)
89c4a3a6 sago007 2008-08-29 14:32 3266
                            timeString = "Time used: "+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60);
89c4a3a6 sago007 2008-08-29 14:32 3267
                        
89c4a3a6 sago007 2008-08-29 14:32 3268
                        SFont_Write(screen,fBlueFont,200,200,scoreString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3269
                        SFont_Write(screen,fBlueFont,200,250,timeString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3270
                        
89c4a3a6 sago007 2008-08-29 14:32 3271
                        overLevel;
89c4a3a6 sago007 2008-08-29 14:32 3272
                    }
89c4a3a6 sago007 2008-08-29 14:32 3273
            string totalString = "Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60);
89c4a3a6 sago007 2008-08-29 14:32 3274
            SFont_Write(screen,fBlueFont,200,600,totalString.c_str());   
89c4a3a6 sago007 2008-08-29 14:32 3275
89c4a3a6 sago007 2008-08-29 14:32 3276
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3277
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3278
89c4a3a6 sago007 2008-08-29 14:32 3279
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 3280
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3281
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 3282
}
89c4a3a6 sago007 2008-08-29 14:32 3283
89c4a3a6 sago007 2008-08-29 14:32 3284
//Ask user for what AI level he will compete agains, return the number. Number must be 0..AIlevels
89c4a3a6 sago007 2008-08-29 14:32 3285
int startSingleVs()
89c4a3a6 sago007 2008-08-29 14:32 3286
{
89c4a3a6 sago007 2008-08-29 14:32 3287
    //Where to place the windows
89c4a3a6 sago007 2008-08-29 14:32 3288
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3289
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3290
    Uint8 *keys;	//To take keyboard input
89c4a3a6 sago007 2008-08-29 14:32 3291
    int mousex, mousey;	//To allow mouse
89c4a3a6 sago007 2008-08-29 14:32 3292
    bool done = false;	//When are we done?
89c4a3a6 sago007 2008-08-29 14:32 3293
27ae0175 sago007 2009-01-30 06:02 3294
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3295
    DrawIMG(changeButtonsBack,background,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 3296
    SFont_Write(background,fBlueFont,xplace+10,yplace+10,"1 : Very Easy");
89c4a3a6 sago007 2008-08-29 14:32 3297
    SFont_Write(background,fBlueFont,xplace+10,yplace+40,"2 : Easy");
89c4a3a6 sago007 2008-08-29 14:32 3298
    SFont_Write(background,fBlueFont,xplace+10,yplace+70,"3 : Below Normal");
89c4a3a6 sago007 2008-08-29 14:32 3299
    SFont_Write(background,fBlueFont,xplace+10,yplace+100,"4 : Normal");
89c4a3a6 sago007 2008-08-29 14:32 3300
    SFont_Write(background,fBlueFont,xplace+10,yplace+130,"5 : Above Normal");
89c4a3a6 sago007 2008-08-29 14:32 3301
    SFont_Write(background,fBlueFont,xplace+10,yplace+160,"6 : Hard");
89c4a3a6 sago007 2008-08-29 14:32 3302
    SFont_Write(background,fBlueFont,xplace+10,yplace+190,"7 : Hardest");
89c4a3a6 sago007 2008-08-29 14:32 3303
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3304
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3305
    do
89c4a3a6 sago007 2008-08-29 14:32 3306
    {
89c4a3a6 sago007 2008-08-29 14:32 3307
89c4a3a6 sago007 2008-08-29 14:32 3308
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3309
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3310
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3311
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3312
            {
89c4a3a6 sago007 2008-08-29 14:32 3313
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3314
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3315
                }
89c4a3a6 sago007 2008-08-29 14:32 3316
                if ( event.key.keysym.sym == SDLK_RETURN ) {
89c4a3a6 sago007 2008-08-29 14:32 3317
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3318
                }
89c4a3a6 sago007 2008-08-29 14:32 3319
                if ( event.key.keysym.sym == SDLK_KP_ENTER ) {
89c4a3a6 sago007 2008-08-29 14:32 3320
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3321
                }
89c4a3a6 sago007 2008-08-29 14:32 3322
                if ( event.key.keysym.sym == SDLK_1 ) {
89c4a3a6 sago007 2008-08-29 14:32 3323
                    return 0;
89c4a3a6 sago007 2008-08-29 14:32 3324
                }
89c4a3a6 sago007 2008-08-29 14:32 3325
                if ( event.key.keysym.sym == SDLK_2 ) {
89c4a3a6 sago007 2008-08-29 14:32 3326
                    return 1;
89c4a3a6 sago007 2008-08-29 14:32 3327
                }
89c4a3a6 sago007 2008-08-29 14:32 3328
                if ( event.key.keysym.sym == SDLK_3 ) {
89c4a3a6 sago007 2008-08-29 14:32 3329
                    return 2;
89c4a3a6 sago007 2008-08-29 14:32 3330
                }
89c4a3a6 sago007 2008-08-29 14:32 3331
                if ( event.key.keysym.sym == SDLK_4 ) {
89c4a3a6 sago007 2008-08-29 14:32 3332
                    return 3;
89c4a3a6 sago007 2008-08-29 14:32 3333
                }
89c4a3a6 sago007 2008-08-29 14:32 3334
                if ( event.key.keysym.sym == SDLK_5 ) {
89c4a3a6 sago007 2008-08-29 14:32 3335
                    return 4;
89c4a3a6 sago007 2008-08-29 14:32 3336
                }
89c4a3a6 sago007 2008-08-29 14:32 3337
                if ( event.key.keysym.sym == SDLK_6 ) {
89c4a3a6 sago007 2008-08-29 14:32 3338
                    return 5;
89c4a3a6 sago007 2008-08-29 14:32 3339
                }
89c4a3a6 sago007 2008-08-29 14:32 3340
                if ( event.key.keysym.sym == SDLK_7 ) {
89c4a3a6 sago007 2008-08-29 14:32 3341
                    return 6;
89c4a3a6 sago007 2008-08-29 14:32 3342
                }
89c4a3a6 sago007 2008-08-29 14:32 3343
                if ( event.key.keysym.sym == SDLK_KP1 ) {
89c4a3a6 sago007 2008-08-29 14:32 3344
                    return 0;
89c4a3a6 sago007 2008-08-29 14:32 3345
                }
89c4a3a6 sago007 2008-08-29 14:32 3346
                if ( event.key.keysym.sym == SDLK_KP2 ) {
89c4a3a6 sago007 2008-08-29 14:32 3347
                    return 1;
89c4a3a6 sago007 2008-08-29 14:32 3348
                }
89c4a3a6 sago007 2008-08-29 14:32 3349
                if ( event.key.keysym.sym == SDLK_KP3 ) {
89c4a3a6 sago007 2008-08-29 14:32 3350
                    return 2;
89c4a3a6 sago007 2008-08-29 14:32 3351
                }
89c4a3a6 sago007 2008-08-29 14:32 3352
                if ( event.key.keysym.sym == SDLK_KP4 ) {
89c4a3a6 sago007 2008-08-29 14:32 3353
                    return 3;
89c4a3a6 sago007 2008-08-29 14:32 3354
                }
89c4a3a6 sago007 2008-08-29 14:32 3355
                if ( event.key.keysym.sym == SDLK_KP5 ) {
89c4a3a6 sago007 2008-08-29 14:32 3356
                    return 4;
89c4a3a6 sago007 2008-08-29 14:32 3357
                }
89c4a3a6 sago007 2008-08-29 14:32 3358
                if ( event.key.keysym.sym == SDLK_KP6 ) {
89c4a3a6 sago007 2008-08-29 14:32 3359
                    return 5;
89c4a3a6 sago007 2008-08-29 14:32 3360
                }
89c4a3a6 sago007 2008-08-29 14:32 3361
                if ( event.key.keysym.sym == SDLK_KP7 ) {
89c4a3a6 sago007 2008-08-29 14:32 3362
                    return 6;
89c4a3a6 sago007 2008-08-29 14:32 3363
                }
89c4a3a6 sago007 2008-08-29 14:32 3364
89c4a3a6 sago007 2008-08-29 14:32 3365
            }
89c4a3a6 sago007 2008-08-29 14:32 3366
89c4a3a6 sago007 2008-08-29 14:32 3367
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3368
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3369
        {
89c4a3a6 sago007 2008-08-29 14:32 3370
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3371
        }
89c4a3a6 sago007 2008-08-29 14:32 3372
89c4a3a6 sago007 2008-08-29 14:32 3373
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3374
        {
89c4a3a6 sago007 2008-08-29 14:32 3375
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3376
89c4a3a6 sago007 2008-08-29 14:32 3377
            for (int i=0; i<7;i++)
89c4a3a6 sago007 2008-08-29 14:32 3378
            {
89c4a3a6 sago007 2008-08-29 14:32 3379
                if ((mousex>xplace+10)&&(mousex<xplace+410)&&(mousey>yplace+10+i*30)&&(mousey<yplace+38+i*30))
89c4a3a6 sago007 2008-08-29 14:32 3380
                    return i;
89c4a3a6 sago007 2008-08-29 14:32 3381
            }
89c4a3a6 sago007 2008-08-29 14:32 3382
        }
89c4a3a6 sago007 2008-08-29 14:32 3383
89c4a3a6 sago007 2008-08-29 14:32 3384
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3385
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3386
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3387
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3388
    }while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3389
89c4a3a6 sago007 2008-08-29 14:32 3390
89c4a3a6 sago007 2008-08-29 14:32 3391
    return 3; //Returns normal
89c4a3a6 sago007 2008-08-29 14:32 3392
}
89c4a3a6 sago007 2008-08-29 14:32 3393
89c4a3a6 sago007 2008-08-29 14:32 3394
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 3395
void startVsMenu()
89c4a3a6 sago007 2008-08-29 14:32 3396
{
89c4a3a6 sago007 2008-08-29 14:32 3397
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3398
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3399
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3400
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 3401
    bool done = false;
89c4a3a6 sago007 2008-08-29 14:32 3402
89c4a3a6 sago007 2008-08-29 14:32 3403
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3404
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3405
27ae0175 sago007 2009-01-30 06:02 3406
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3407
    SFont_Write(background,fBlueFont,360,650,"Press ESC to accept");
27ae0175 sago007 2009-01-30 06:02 3408
    DrawIMG(bBack,background,xsize/2-120/2,600);
89c4a3a6 sago007 2008-08-29 14:32 3409
    do
89c4a3a6 sago007 2008-08-29 14:32 3410
    {
89c4a3a6 sago007 2008-08-29 14:32 3411
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3412
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3413
        DrawIMG(changeButtonsBack,screen,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 3414
        SFont_Write(screen,fBlueFont,xplace+50,yplace+20,"Player 1");
89c4a3a6 sago007 2008-08-29 14:32 3415
        SFont_Write(screen,fBlueFont,xplace+300+50,yplace+20,"Player 2");
89c4a3a6 sago007 2008-08-29 14:32 3416
        SFont_Write(screen,fBlueFont,xplace+50,yplace+70,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 3417
        SFont_Write(screen,fBlueFont,xplace+50+300,yplace+70,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 3418
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3419
        {
89c4a3a6 sago007 2008-08-29 14:32 3420
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3421
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3422
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3423
            SFont_Write(screen,fBlueFont,xplace+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3424
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3425
            if (player1Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3426
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3427
        }
89c4a3a6 sago007 2008-08-29 14:32 3428
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3429
        {
89c4a3a6 sago007 2008-08-29 14:32 3430
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3431
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3432
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3433
            SFont_Write(screen,fBlueFont,xplace+300+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3434
            DrawIMG(iLevelCheckBox,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3435
            if (player2Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3436
                DrawIMG(iLevelCheck,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3437
        }
89c4a3a6 sago007 2008-08-29 14:32 3438
        SFont_Write(screen,fBlueFont,xplace+50,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3439
        DrawIMG(iLevelCheckBox,screen,xplace+50+70,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3440
        if (player1AI)
89c4a3a6 sago007 2008-08-29 14:32 3441
            DrawIMG(iLevelCheck,screen,xplace+50+70,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3442
        SFont_Write(screen,fBlueFont,xplace+50,yplace+250,"TT Handicap: ");
89c4a3a6 sago007 2008-08-29 14:32 3443
        SFont_Write(screen,fBlueFont,xplace+50+300,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3444
        DrawIMG(iLevelCheckBox,screen,xplace+50+70+300,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3445
        if (player2AI)
89c4a3a6 sago007 2008-08-29 14:32 3446
            DrawIMG(iLevelCheck,screen,xplace+50+70+300,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3447
        SFont_Write(screen,fBlueFont,xplace+50+300,yplace+250,"TT Handicap: ");
89c4a3a6 sago007 2008-08-29 14:32 3448
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3449
        {
89c4a3a6 sago007 2008-08-29 14:32 3450
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3451
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3452
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3453
            SFont_Write(screen,fBlueFont,xplace+50+i*40,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3454
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3455
            if (player1handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3456
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3457
        }
89c4a3a6 sago007 2008-08-29 14:32 3458
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3459
        {
89c4a3a6 sago007 2008-08-29 14:32 3460
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3461
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3462
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3463
            SFont_Write(screen,fBlueFont,xplace+50+i*40+300,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3464
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3465
            if (player2handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3466
                DrawIMG(iLevelCheck,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3467
        }
89c4a3a6 sago007 2008-08-29 14:32 3468
89c4a3a6 sago007 2008-08-29 14:32 3469
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3470
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3471
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3472
            {
89c4a3a6 sago007 2008-08-29 14:32 3473
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3474
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3475
                }
89c4a3a6 sago007 2008-08-29 14:32 3476
                if ( event.key.keysym.sym == SDLK_RETURN ) {
89c4a3a6 sago007 2008-08-29 14:32 3477
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3478
                }
89c4a3a6 sago007 2008-08-29 14:32 3479
                if ( event.key.keysym.sym == SDLK_KP_ENTER ) {
89c4a3a6 sago007 2008-08-29 14:32 3480
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3481
                }
89c4a3a6 sago007 2008-08-29 14:32 3482
            }
89c4a3a6 sago007 2008-08-29 14:32 3483
89c4a3a6 sago007 2008-08-29 14:32 3484
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3485
89c4a3a6 sago007 2008-08-29 14:32 3486
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3487
89c4a3a6 sago007 2008-08-29 14:32 3488
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3489
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3490
        {
89c4a3a6 sago007 2008-08-29 14:32 3491
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3492
        }
89c4a3a6 sago007 2008-08-29 14:32 3493
89c4a3a6 sago007 2008-08-29 14:32 3494
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3495
        {
89c4a3a6 sago007 2008-08-29 14:32 3496
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3497
89c4a3a6 sago007 2008-08-29 14:32 3498
            if ((mousex>xplace+50+70)&&(mousey>yplace+200)&&(mousex<xplace+50+70+30)&&(mousey<yplace+200+30))
89c4a3a6 sago007 2008-08-29 14:32 3499
                player1AI=!player1AI;
89c4a3a6 sago007 2008-08-29 14:32 3500
            if ((mousex>xplace+50+70+300)&&(mousey>yplace+200)&&(mousex<xplace+50+70+30+300)&&(mousey<yplace+200+30))
89c4a3a6 sago007 2008-08-29 14:32 3501
                player2AI=!player2AI;
89c4a3a6 sago007 2008-08-29 14:32 3502
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3503
            {
89c4a3a6 sago007 2008-08-29 14:32 3504
                if ((mousex>xplace+50+i*40)&&(mousex<xplace+50+i*40+30)&&(mousey>yplace+150)&&(mousey<yplace+150+30))
89c4a3a6 sago007 2008-08-29 14:32 3505
                    player1Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3506
            }
89c4a3a6 sago007 2008-08-29 14:32 3507
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3508
            {
89c4a3a6 sago007 2008-08-29 14:32 3509
                if ((mousex>xplace+50+i*40+300)&&(mousex<xplace+50+i*40+30+300)&&(mousey>yplace+150)&&(mousey<yplace+150+30))
89c4a3a6 sago007 2008-08-29 14:32 3510
                    player2Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3511
            }
89c4a3a6 sago007 2008-08-29 14:32 3512
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3513
            {
89c4a3a6 sago007 2008-08-29 14:32 3514
                if ((mousex>xplace+50+i*40)&&(mousex<xplace+50+i*40+30)&&(mousey>yplace+330)&&(mousey<yplace+330+30))
89c4a3a6 sago007 2008-08-29 14:32 3515
                    player1handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3516
            }
89c4a3a6 sago007 2008-08-29 14:32 3517
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3518
            {
89c4a3a6 sago007 2008-08-29 14:32 3519
                if ((mousex>xplace+50+i*40+300)&&(mousex<xplace+50+i*40+30+300)&&(mousey>yplace+330)&&(mousey<yplace+330+30))
89c4a3a6 sago007 2008-08-29 14:32 3520
                    player2handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3521
            }
27ae0175 sago007 2009-01-30 06:02 3522
            if ((mousex>xsize/2-120/2)&&(mousex<xsize/2+120/2)&&(mousey>600)&&(mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 3523
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 3524
        }
89c4a3a6 sago007 2008-08-29 14:32 3525
89c4a3a6 sago007 2008-08-29 14:32 3526
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3527
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3528
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3529
89c4a3a6 sago007 2008-08-29 14:32 3530
    } while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3531
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3532
}
89c4a3a6 sago007 2008-08-29 14:32 3533
89c4a3a6 sago007 2008-08-29 14:32 3534
//This function will promt for the user to select another file for puzzle mode
89c4a3a6 sago007 2008-08-29 14:32 3535
void changePuzzleLevels()
89c4a3a6 sago007 2008-08-29 14:32 3536
{
89c4a3a6 sago007 2008-08-29 14:32 3537
    char theFileName[30];
89c4a3a6 sago007 2008-08-29 14:32 3538
    strcpy(theFileName,puzzleName.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3539
    for (int i=puzzleName.length();i<30;i++)
89c4a3a6 sago007 2008-08-29 14:32 3540
        theFileName[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 3541
    theFileName[29]=0;
89c4a3a6 sago007 2008-08-29 14:32 3542
    if (OpenFileDialogbox(200,100,theFileName))
89c4a3a6 sago007 2008-08-29 14:32 3543
    {
89c4a3a6 sago007 2008-08-29 14:32 3544
        for (int i=28;((theFileName[i]==' ')&&(i>0));i--)
89c4a3a6 sago007 2008-08-29 14:32 3545
            theFileName[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3546
        puzzleName = theFileName;
89c4a3a6 sago007 2008-08-29 14:32 3547
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3548
        string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3549
        puzzleSavePath = home+"/.gamesaves/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3550
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3551
        string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3552
        if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3553
        {
89c4a3a6 sago007 2008-08-29 14:32 3554
            puzzleSavePath = home+"/My Games/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3555
        }
89c4a3a6 sago007 2008-08-29 14:32 3556
        else
89c4a3a6 sago007 2008-08-29 14:32 3557
        {
89c4a3a6 sago007 2008-08-29 14:32 3558
            puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3559
        }
89c4a3a6 sago007 2008-08-29 14:32 3560
#else
89c4a3a6 sago007 2008-08-29 14:32 3561
        puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3562
#endif
89c4a3a6 sago007 2008-08-29 14:32 3563
    }
89c4a3a6 sago007 2008-08-29 14:32 3564
89c4a3a6 sago007 2008-08-29 14:32 3565
}
89c4a3a6 sago007 2008-08-29 14:32 3566
6d48320c sago007 2009-03-28 17:06 3567
class Keymenu {
6d48320c sago007 2009-03-28 17:06 3568
    static void setXY(int x, int y)
6d48320c sago007 2009-03-28 17:06 3569
    {
6d48320c sago007 2009-03-28 17:06 3570
        keymenu.x = x;
6d48320c sago007 2009-03-28 17:06 3571
        keymenu.y = y;
6d48320c sago007 2009-03-28 17:06 3572
    }
6d48320c sago007 2009-03-28 17:06 3573
6d48320c sago007 2009-03-28 17:06 3574
    static void startMenu()
6d48320c sago007 2009-03-28 17:06 3575
    {
6d48320c sago007 2009-03-28 17:06 3576
        keymenu.activated = true;
6d48320c sago007 2009-03-28 17:06 3577
        setXY(0,0);
6d48320c sago007 2009-03-28 17:06 3578
    }
6d48320c sago007 2009-03-28 17:06 3579
6d48320c sago007 2009-03-28 17:06 3580
    static void stopMenu()
6d48320c sago007 2009-03-28 17:06 3581
    {
6d48320c sago007 2009-03-28 17:06 3582
        keymenu.activated = false;
6d48320c sago007 2009-03-28 17:06 3583
    }
6d48320c sago007 2009-03-28 17:06 3584
};
6d48320c sago007 2009-03-28 17:06 3585
30f910dd sago007 2010-11-10 21:02 3586
static BlockGameSdl *player1;
30f910dd sago007 2010-11-10 21:02 3587
static BlockGameSdl *player2;
30f910dd sago007 2010-11-10 21:02 3588
30f910dd sago007 2010-11-10 21:02 3589
void StartSinglePlayerEndless() {
30f910dd sago007 2010-11-10 21:02 3590
    //1 player - endless
30f910dd sago007 2010-11-10 21:02 3591
    player1->NewGame(50,100,SDL_GetTicks());
30f910dd sago007 2010-11-10 21:02 3592
    player1->putStartBlocks(time(0));
30f910dd sago007 2010-11-10 21:02 3593
    bNewGameOpen = false;
30f910dd sago007 2010-11-10 21:02 3594
    b1playerOpen = false;
30f910dd sago007 2010-11-10 21:02 3595
    twoPlayers =false;
30f910dd sago007 2010-11-10 21:02 3596
    player2->SetGameOver();
30f910dd sago007 2010-11-10 21:02 3597
    showGame = true;
30f910dd sago007 2010-11-10 21:02 3598
    strcpy(player1->name, player1name);
30f910dd sago007 2010-11-10 21:02 3599
    strcpy(player2->name, player2name);
30f910dd sago007 2010-11-10 21:02 3600
}
30f910dd sago007 2010-11-10 21:02 3601
1572de2b sago007 2008-09-11 18:15 3602
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3603
#include "NetworkThing.hpp"
eec83b7d sago007 2009-03-29 15:46 3604
//#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 3605
#endif
89c4a3a6 sago007 2008-08-29 14:32 3606
89c4a3a6 sago007 2008-08-29 14:32 3607
//The main function, quite big... too big
89c4a3a6 sago007 2008-08-29 14:32 3608
int main(int argc, char *argv[])
89c4a3a6 sago007 2008-08-29 14:32 3609
{
89c4a3a6 sago007 2008-08-29 14:32 3610
    //We first create the folder there we will save (only on UNIX systems)
89c4a3a6 sago007 2008-08-29 14:32 3611
    //we call the external command "mkdir"... the user might have renamed this, but we hope he hasn't
89c4a3a6 sago007 2008-08-29 14:32 3612
#if defined(__unix__)
42f8ed5f sago007 2009-03-05 11:47 3613
    //Compiler warns about unused result. The users envisonment should normally give the user all the information he needs
42f8ed5f sago007 2009-03-05 11:47 3614
    if(system("mkdir -p ~/.gamesaves/blockattack/screenshots"))
42f8ed5f sago007 2009-03-05 11:47 3615
        cout << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl;
42f8ed5f sago007 2009-03-05 11:47 3616
    if(system("mkdir -p ~/.gamesaves/blockattack/replays"))
42f8ed5f sago007 2009-03-05 11:47 3617
        cout << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl;
42f8ed5f sago007 2009-03-05 11:47 3618
    if(system("mkdir -p ~/.gamesaves/blockattack/puzzles"))
42f8ed5f sago007 2009-03-05 11:47 3619
        cout << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3620
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3621
    //Now for Windows NT/2k/xp/2k3 etc.
89c4a3a6 sago007 2008-08-29 14:32 3622
    string tempA = getMyDocumentsPath()+"\\My Games";
c325f4fa sago007 2009-05-09 18:33 3623
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3624
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack";
c325f4fa sago007 2009-05-09 18:33 3625
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3626
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays";
c325f4fa sago007 2009-05-09 18:33 3627
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3628
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots";
c325f4fa sago007 2009-05-09 18:33 3629
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3630
#endif
78d03b38 sago007 2008-11-13 19:56 3631
    highPriority = false;	//if true the game will take most resources, but increase framerate.
89c4a3a6 sago007 2008-08-29 14:32 3632
    bFullscreen = false;
2e57d791 sago007 2009-06-04 17:48 3633
    //Set default Config variables:
2e57d791 sago007 2009-06-04 17:48 3634
    Config::getInstance()->setDefault("themename","default");
89c4a3a6 sago007 2008-08-29 14:32 3635
    if (argc > 1)
89c4a3a6 sago007 2008-08-29 14:32 3636
    {
89c4a3a6 sago007 2008-08-29 14:32 3637
        int argumentNr = 1;
89c4a3a6 sago007 2008-08-29 14:32 3638
        forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3639
        while (argc>argumentNr)
89c4a3a6 sago007 2008-08-29 14:32 3640
        {
89c4a3a6 sago007 2008-08-29 14:32 3641
            char helpString[] = "--help";
89c4a3a6 sago007 2008-08-29 14:32 3642
            char priorityString[] = "-priority";
89c4a3a6 sago007 2008-08-29 14:32 3643
            char forceRedrawString[] = "-forceredraw";
89c4a3a6 sago007 2008-08-29 14:32 3644
            char forcepartdrawString[] = "-forcepartdraw";
89c4a3a6 sago007 2008-08-29 14:32 3645
            char singlePuzzleString[] = "-SP";
89c4a3a6 sago007 2008-08-29 14:32 3646
            char noSoundAtAll[] = "-nosound";
89c4a3a6 sago007 2008-08-29 14:32 3647
            char IntegratedEditor[] = "-editor";
2e57d791 sago007 2009-06-04 17:48 3648
            char selectTheme[] = "-theme";
89c4a3a6 sago007 2008-08-29 14:32 3649
            if (!(strncmp(argv[argumentNr],helpString,6)))
89c4a3a6 sago007 2008-08-29 14:32 3650
            {
89c4a3a6 sago007 2008-08-29 14:32 3651
                cout << "Block Attack Help" << endl << "--help Display this message" <<
89c4a3a6 sago007 2008-08-29 14:32 3652
                endl << "-priority  Starts game in high priority" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3653
                "-forceredraw  Redraw the whole screen every frame, prevents garbage" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3654
                "-forcepartdraw  Only draw what is changed, sometimes cause garbage" << endl <<
2e57d791 sago007 2009-06-04 17:48 3655
                "-nosound  No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)" << endl <<
2e57d791 sago007 2009-06-04 17:48 3656
                "-theme <THEMENAME>  Changes to the theme <THEMENAME> on startup" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3657
                "-editor  Starts the build-in editor (not yet integrated)" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3658
#ifdef WIN32
89c4a3a6 sago007 2008-08-29 14:32 3659
                system("Pause");
89c4a3a6 sago007 2008-08-29 14:32 3660
#endif
89c4a3a6 sago007 2008-08-29 14:32 3661
                return 0;
89c4a3a6 sago007 2008-08-29 14:32 3662
            }
89c4a3a6 sago007 2008-08-29 14:32 3663
            if (!(strncmp(argv[argumentNr],priorityString,9)))
89c4a3a6 sago007 2008-08-29 14:32 3664
            {
89c4a3a6 sago007 2008-08-29 14:32 3665
                cout << "Priority mode" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3666
                highPriority = true;
89c4a3a6 sago007 2008-08-29 14:32 3667
            }
89c4a3a6 sago007 2008-08-29 14:32 3668
            if (!(strncmp(argv[argumentNr],forceRedrawString,12)))
89c4a3a6 sago007 2008-08-29 14:32 3669
            {
89c4a3a6 sago007 2008-08-29 14:32 3670
                forceredraw = 1;
89c4a3a6 sago007 2008-08-29 14:32 3671
            }
89c4a3a6 sago007 2008-08-29 14:32 3672
            if (!(strncmp(argv[argumentNr],forcepartdrawString,14)))
89c4a3a6 sago007 2008-08-29 14:32 3673
            {
89c4a3a6 sago007 2008-08-29 14:32 3674
                forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3675
            }
89c4a3a6 sago007 2008-08-29 14:32 3676
            if (!(strncmp(argv[argumentNr],singlePuzzleString,3)))
89c4a3a6 sago007 2008-08-29 14:32 3677
            {
89c4a3a6 sago007 2008-08-29 14:32 3678
                singlePuzzle = true; //We will just have one puzzle
89c4a3a6 sago007 2008-08-29 14:32 3679
                if (argv[argumentNr+1][1]!=0)
89c4a3a6 sago007 2008-08-29 14:32 3680
                    singlePuzzleNr = (argv[argumentNr+1][1]-'0')+(argv[argumentNr+1][0]-'0')*10;
89c4a3a6 sago007 2008-08-29 14:32 3681
                else
89c4a3a6 sago007 2008-08-29 14:32 3682
                    singlePuzzleNr = (argv[argumentNr+1][0]-'0');
89c4a3a6 sago007 2008-08-29 14:32 3683
                singlePuzzleFile = argv[argumentNr+2];
89c4a3a6 sago007 2008-08-29 14:32 3684
                argumentNr+=2;
89c4a3a6 sago007 2008-08-29 14:32 3685
                cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl;
89c4a3a6 sago007 2008-08-29 14:32 3686
            }
89c4a3a6 sago007 2008-08-29 14:32 3687
            if (!(strncmp(argv[argumentNr],noSoundAtAll,8)))
89c4a3a6 sago007 2008-08-29 14:32 3688
            {
89c4a3a6 sago007 2008-08-29 14:32 3689
                NoSound = true;
89c4a3a6 sago007 2008-08-29 14:32 3690
            }
89c4a3a6 sago007 2008-08-29 14:32 3691
            if (!(strncmp(argv[argumentNr],IntegratedEditor,7)))
89c4a3a6 sago007 2008-08-29 14:32 3692
            {
1572de2b sago007 2008-09-11 18:15 3693
                #if LEVELEDITOR
89c4a3a6 sago007 2008-08-29 14:32 3694
                editorMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3695
                cout << "Integrated Puzzle Editor Activated" << endl;
1572de2b sago007 2008-09-11 18:15 3696
                #else
1572de2b sago007 2008-09-11 18:15 3697
                cout << "Integrated Puzzle Editor was disabled at compile time" << endl;
2e57d791 sago007 2009-06-04 17:48 3698
                return -1;
1572de2b sago007 2008-09-11 18:15 3699
                #endif
89c4a3a6 sago007 2008-08-29 14:32 3700
            }
2e57d791 sago007 2009-06-04 17:48 3701
            if(!(strncmp(argv[argumentNr],selectTheme,6)))
2e57d791 sago007 2009-06-04 17:48 3702
            {
2e57d791 sago007 2009-06-04 17:48 3703
                argumentNr++; //Go to themename (the next argument)
2e57d791 sago007 2009-06-04 17:48 3704
                cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
2e57d791 sago007 2009-06-04 17:48 3705
                Config::getInstance()->setString("themename",argv[argumentNr]);
2e57d791 sago007 2009-06-04 17:48 3706
            }
89c4a3a6 sago007 2008-08-29 14:32 3707
            argumentNr++;
89c4a3a6 sago007 2008-08-29 14:32 3708
        }   //while
89c4a3a6 sago007 2008-08-29 14:32 3709
    }   //if
89c4a3a6 sago007 2008-08-29 14:32 3710
89c4a3a6 sago007 2008-08-29 14:32 3711
    SoundEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3712
    MusicEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3713
    int mousex, mousey;   //Mouse coordinates
89c4a3a6 sago007 2008-08-29 14:32 3714
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3715
    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3716
    b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3717
    bReplayOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3718
    bScreenLocked = false;
f72abf8b sago007 2010-01-16 20:00 3719
    twoPlayers = false;	//true if two players splitscreen
89c4a3a6 sago007 2008-08-29 14:32 3720
    bool vsMode = false;
89c4a3a6 sago007 2008-08-29 14:32 3721
    theTopScoresEndless = Highscore(1);
89c4a3a6 sago007 2008-08-29 14:32 3722
    theTopScoresTimeTrial = Highscore(2);
89c4a3a6 sago007 2008-08-29 14:32 3723
    drawBalls = true;
89c4a3a6 sago007 2008-08-29 14:32 3724
    puzzleLoaded = false;
89c4a3a6 sago007 2008-08-29 14:32 3725
    bool weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3726
89c4a3a6 sago007 2008-08-29 14:32 3727
    //Things used for repeating keystrokes:
30f910dd sago007 2010-11-10 21:02 3728
    /*bool repeatingP1N = false; //The key is being held
89c4a3a6 sago007 2008-08-29 14:32 3729
    bool repeatingP1S = false; //The key is being held
89c4a3a6 sago007 2008-08-29 14:32 3730
    bool repeatingP1W = false; //The key is being held
89c4a3a6 sago007 2008-08-29 14:32 3731
    bool repeatingP1E = false; //The key is being held
89c4a3a6 sago007 2008-08-29 14:32 3732
    bool repeatingP2N = false; //The key is being held
89c4a3a6 sago007 2008-08-29 14:32 3733
    bool repeatingP2S = false; //The key is being held
89c4a3a6 sago007 2008-08-29 14:32 3734
    bool repeatingP2W = false; //The key is being held
89c4a3a6 sago007 2008-08-29 14:32 3735
    bool repeatingP2E = false; //The key is being held
30f910dd sago007 2010-11-10 21:02 3736
     * */
30f910dd sago007 2010-11-10 21:02 3737
    bool repeatingS[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3738
    bool repeatingW[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3739
    bool repeatingN[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3740
    bool repeatingE[2] = {false,false};
89c4a3a6 sago007 2008-08-29 14:32 3741
    const int startRepeat = 200;
89c4a3a6 sago007 2008-08-29 14:32 3742
    const int repeatDelay = 100;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 3743
    unsigned long timeHeldP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3744
    unsigned long timeHeldP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3745
    unsigned long timeHeldP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3746
    unsigned long timeHeldP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3747
    unsigned long timeHeldP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3748
    unsigned long timeHeldP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3749
    unsigned long timeHeldP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3750
    unsigned long timeHeldP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3751
    unsigned long timesRepeatedP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3752
    unsigned long timesRepeatedP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3753
    unsigned long timesRepeatedP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3754
    unsigned long timesRepeatedP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3755
    unsigned long timesRepeatedP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3756
    unsigned long timesRepeatedP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3757
    unsigned long timesRepeatedP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3758
    unsigned long timesRepeatedP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3759
89c4a3a6 sago007 2008-08-29 14:32 3760
    theBallManeger = ballManeger();
89c4a3a6 sago007 2008-08-29 14:32 3761
    theExplosionManeger = explosionManeger();
89c4a3a6 sago007 2008-08-29 14:32 3762
89c4a3a6 sago007 2008-08-29 14:32 3763
//We now set the paths were we are saving, we are using the keyword __unix__ . I hope that all UNIX systems has a home folder
89c4a3a6 sago007 2008-08-29 14:32 3764
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3765
    string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3766
    string optionsPath = home+"/.gamesaves/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3767
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3768
    string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3769
    string optionsPath;
89c4a3a6 sago007 2008-08-29 14:32 3770
    if (&home!=NULL) //Null if no APPDATA dir exists (win 9x)
89c4a3a6 sago007 2008-08-29 14:32 3771
        optionsPath = home+"/My Games/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3772
    else
89c4a3a6 sago007 2008-08-29 14:32 3773
        optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3774
#else
89c4a3a6 sago007 2008-08-29 14:32 3775
    string optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3776
#endif
89c4a3a6 sago007 2008-08-29 14:32 3777
89c4a3a6 sago007 2008-08-29 14:32 3778
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3779
    stageClearSavePath = home+"/.gamesaves/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3780
    puzzleSavePath = home+"/.gamesaves/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3781
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3782
    if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3783
    {
89c4a3a6 sago007 2008-08-29 14:32 3784
        stageClearSavePath = home+"/My Games/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3785
        puzzleSavePath = home+"/My Games/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3786
    }
89c4a3a6 sago007 2008-08-29 14:32 3787
    else
89c4a3a6 sago007 2008-08-29 14:32 3788
    {
89c4a3a6 sago007 2008-08-29 14:32 3789
        stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3790
        puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3791
    }
89c4a3a6 sago007 2008-08-29 14:32 3792
#else
89c4a3a6 sago007 2008-08-29 14:32 3793
    stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3794
    puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3795
#endif
89c4a3a6 sago007 2008-08-29 14:32 3796
    puzzleName="puzzle.levels";
89c4a3a6 sago007 2008-08-29 14:32 3797
89c4a3a6 sago007 2008-08-29 14:32 3798
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3799
866417ca sago007 2009-05-10 21:35 3800
95bc02ff sago007 2009-03-15 02:46 3801
89c4a3a6 sago007 2008-08-29 14:32 3802
    //Init SDL
89c4a3a6 sago007 2008-08-29 14:32 3803
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
89c4a3a6 sago007 2008-08-29 14:32 3804
    {
89c4a3a6 sago007 2008-08-29 14:32 3805
        cout << "Unable to init SDL: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3806
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3807
    }
89c4a3a6 sago007 2008-08-29 14:32 3808
    atexit(SDL_Quit);		//quits SDL when the game stops for some reason (like you hit exit or Esc)
89c4a3a6 sago007 2008-08-29 14:32 3809
    
89c4a3a6 sago007 2008-08-29 14:32 3810
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
89c4a3a6 sago007 2008-08-29 14:32 3811
89c4a3a6 sago007 2008-08-29 14:32 3812
    Joypad_init();    //Prepare the joysticks
89c4a3a6 sago007 2008-08-29 14:32 3813
89c4a3a6 sago007 2008-08-29 14:32 3814
    Joypad joypad1 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3815
    Joypad joypad2 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3816
89c4a3a6 sago007 2008-08-29 14:32 3817
    theTextManeger = textManeger();
89c4a3a6 sago007 2008-08-29 14:32 3818
89c4a3a6 sago007 2008-08-29 14:32 3819
    //Open Audio
89c4a3a6 sago007 2008-08-29 14:32 3820
    if (!NoSound) //If sound has not been disabled, then load the sound system
89c4a3a6 sago007 2008-08-29 14:32 3821
        if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
89c4a3a6 sago007 2008-08-29 14:32 3822
        {
89c4a3a6 sago007 2008-08-29 14:32 3823
            cout << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
89c4a3a6 sago007 2008-08-29 14:32 3824
            << "Sound will be disabled!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3825
            NoSound = true; //Tries to stop all sound from playing/loading
89c4a3a6 sago007 2008-08-29 14:32 3826
        }
89c4a3a6 sago007 2008-08-29 14:32 3827
89c4a3a6 sago007 2008-08-29 14:32 3828
    SDL_WM_SetCaption("Block Attack - Rise of the Blocks", NULL); //Sets title line
866417ca sago007 2009-05-10 21:35 3829
    
89c4a3a6 sago007 2008-08-29 14:32 3830
89c4a3a6 sago007 2008-08-29 14:32 3831
    //Copyright notice:
e2de69cf sago007 2010-01-15 22:48 3832
    cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << endl << "http://blockattack.sf.net" << endl << "Copyright 2004-2010 Poul Sander" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3833
    "A SDL based game (see www.libsdl.org)" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3834
    "The game is availeble under the GPL, see COPYING for details." << endl;
89c4a3a6 sago007 2008-08-29 14:32 3835
#if defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3836
    cout << "Windows build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3837
#elif defined(__linux__)
89c4a3a6 sago007 2008-08-29 14:32 3838
    cout << "Linux build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3839
#elif defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3840
    cout << "Unix build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3841
#else
89c4a3a6 sago007 2008-08-29 14:32 3842
    cout << "Alternative build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3843
#endif
89c4a3a6 sago007 2008-08-29 14:32 3844
    cout << "-------------------------------------------" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3845
95bc02ff sago007 2009-03-15 02:46 3846
    //The menu cannot be activated the first second to prevent unexpected events
95bc02ff sago007 2009-03-15 02:46 3847
    keymenu.canBeActivatedTime = SDL_GetTicks()+1000;
95bc02ff sago007 2009-03-15 02:46 3848
    keymenu.activated = false;
95bc02ff sago007 2009-03-15 02:46 3849
    for(int i=0;i<KEYMENU_MAXWITH;i++)
95bc02ff sago007 2009-03-15 02:46 3850
        keymenu.menumap[i][0] = true;
95bc02ff sago007 2009-03-15 02:46 3851
89c4a3a6 sago007 2008-08-29 14:32 3852
    keySettings[0].up= SDLK_UP;
89c4a3a6 sago007 2008-08-29 14:32 3853
    keySettings[0].down = SDLK_DOWN;
89c4a3a6 sago007 2008-08-29 14:32 3854
    keySettings[0].left = SDLK_LEFT;
89c4a3a6 sago007 2008-08-29 14:32 3855
    keySettings[0].right = SDLK_RIGHT;
6d48320c sago007 2009-03-28 17:06 3856
    keySettings[0].change = SDLK_RCTRL;
6d48320c sago007 2009-03-28 17:06 3857
    keySettings[0].push = SDLK_RSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3858
89c4a3a6 sago007 2008-08-29 14:32 3859
    keySettings[2].up= SDLK_w;
89c4a3a6 sago007 2008-08-29 14:32 3860
    keySettings[2].down = SDLK_s;
89c4a3a6 sago007 2008-08-29 14:32 3861
    keySettings[2].left = SDLK_a;
89c4a3a6 sago007 2008-08-29 14:32 3862
    keySettings[2].right = SDLK_d;
89c4a3a6 sago007 2008-08-29 14:32 3863
    keySettings[2].change = SDLK_LCTRL;
89c4a3a6 sago007 2008-08-29 14:32 3864
    keySettings[2].push = SDLK_LSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3865
89c4a3a6 sago007 2008-08-29 14:32 3866
    player1keys=0;
89c4a3a6 sago007 2008-08-29 14:32 3867
    player2keys=2;
89c4a3a6 sago007 2008-08-29 14:32 3868
89c4a3a6 sago007 2008-08-29 14:32 3869
    strcpy(player1name, "Player 1                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3870
    strcpy(player2name, "Player 2                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3871
769a41a0 sago007 2008-09-24 12:54 3872
    Config *configSettings = Config::getInstance();
769a41a0 sago007 2008-09-24 12:54 3873
    //configSettings->setString("aNumber"," A string");
769a41a0 sago007 2008-09-24 12:54 3874
    //configSettings->save();
769a41a0 sago007 2008-09-24 12:54 3875
    if(configSettings->exists("fullscreen")) //Test if an configFile exists
89c4a3a6 sago007 2008-08-29 14:32 3876
    {
769a41a0 sago007 2008-09-24 12:54 3877
        bFullscreen = (bool)configSettings->getInt("fullscreen");
769a41a0 sago007 2008-09-24 12:54 3878
        MusicEnabled = (bool)configSettings->getInt("musicenabled");
769a41a0 sago007 2008-09-24 12:54 3879
        SoundEnabled = (bool)configSettings->getInt("soundenabled");
769a41a0 sago007 2008-09-24 12:54 3880
        mouseplay1 = (bool)configSettings->getInt("mouseplay1");
769a41a0 sago007 2008-09-24 12:54 3881
        mouseplay2 = (bool)configSettings->getInt("mouseplay2");
769a41a0 sago007 2008-09-24 12:54 3882
        joyplay1 = (bool)configSettings->getInt("joypad1");
769a41a0 sago007 2008-09-24 12:54 3883
        joyplay2 = (bool)configSettings->getInt("joypad2");
769a41a0 sago007 2008-09-24 12:54 3884
        
769a41a0 sago007 2008-09-24 12:54 3885
        if(configSettings->exists("player1keyup")) keySettings[0].up = (SDLKey)configSettings->getInt("player1keyup");
769a41a0 sago007 2008-09-24 12:54 3886
        if(configSettings->exists("player1keydown")) keySettings[0].down = (SDLKey)configSettings->getInt("player1keydown");
769a41a0 sago007 2008-09-24 12:54 3887
        if(configSettings->exists("player1keyleft")) keySettings[0].left = (SDLKey)configSettings->getInt("player1keyleft");
769a41a0 sago007 2008-09-24 12:54 3888
        if(configSettings->exists("player1keyright")) keySettings[0].right = (SDLKey)configSettings->getInt("player1keyright");
769a41a0 sago007 2008-09-24 12:54 3889
        if(configSettings->exists("player1keychange")) keySettings[0].change = (SDLKey)configSettings->getInt("player1keychange");
769a41a0 sago007 2008-09-24 12:54 3890
        if(configSettings->exists("player1keypush")) keySettings[0].push = (SDLKey)configSettings->getInt("player1keypush");
769a41a0 sago007 2008-09-24 12:54 3891
        
769a41a0 sago007 2008-09-24 12:54 3892
        if(configSettings->exists("player2keyup")) keySettings[2].up = (SDLKey)configSettings->getInt("player2keyup");
769a41a0 sago007 2008-09-24 12:54 3893
        if(configSettings->exists("player2keydown")) keySettings[2].down = (SDLKey)configSettings->getInt("player2keydown");
769a41a0 sago007 2008-09-24 12:54 3894
        if(configSettings->exists("player2keyleft")) keySettings[2].left = (SDLKey)configSettings->getInt("player2keyleft");
769a41a0 sago007 2008-09-24 12:54 3895
        if(configSettings->exists("player2keyright")) keySettings[2].right = (SDLKey)configSettings->getInt("player2keyright");
769a41a0 sago007 2008-09-24 12:54 3896
        if(configSettings->exists("player2keychange")) keySettings[2].change = (SDLKey)configSettings->getInt("player2keychange");
769a41a0 sago007 2008-09-24 12:54 3897
        if(configSettings->exists("player2keypush")) keySettings[2].push = (SDLKey)configSettings->getInt("player2keypush");
769a41a0 sago007 2008-09-24 12:54 3898
        if(configSettings->exists("player1name"))
769a41a0 sago007 2008-09-24 12:54 3899
            strncpy(player1name,(configSettings->getString("player1name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3900
        if(configSettings->exists("player2name"))
769a41a0 sago007 2008-09-24 12:54 3901
            strncpy(player2name,(configSettings->getString("player2name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3902
        cout << "Data loaded from config file" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3903
    }
89c4a3a6 sago007 2008-08-29 14:32 3904
    else
89c4a3a6 sago007 2008-08-29 14:32 3905
    {
769a41a0 sago007 2008-09-24 12:54 3906
        //Reads options from file:
769a41a0 sago007 2008-09-24 12:54 3907
        ifstream optionsFile(optionsPath.c_str(), ios::binary);
769a41a0 sago007 2008-09-24 12:54 3908
        if (optionsFile)
769a41a0 sago007 2008-09-24 12:54 3909
        {
769a41a0 sago007 2008-09-24 12:54 3910
            //reads data: xsize,ysize,fullescreen, player1keys, player2keys, MusicEnabled, SoundEnabled,player1name,player2name
769a41a0 sago007 2008-09-24 12:54 3911
            optionsFile.read(reinterpret_cast<char*>(&xsize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3912
            optionsFile.read(reinterpret_cast<char*>(&ysize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3913
            optionsFile.read(reinterpret_cast<char*>(&bFullscreen), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3914
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3915
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3916
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3917
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3918
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3919
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3920
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3921
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3922
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3923
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3924
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3925
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3926
            optionsFile.read(reinterpret_cast<char*>(&MusicEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3927
            optionsFile.read(reinterpret_cast<char*>(&SoundEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3928
            optionsFile.read(player1name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3929
            optionsFile.read(player2name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3930
            //mouseplay?
769a41a0 sago007 2008-09-24 12:54 3931
            if (!optionsFile.eof())
769a41a0 sago007 2008-09-24 12:54 3932
            {
769a41a0 sago007 2008-09-24 12:54 3933
                optionsFile.read(reinterpret_cast<char*>(&mouseplay1), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3934
                optionsFile.read(reinterpret_cast<char*>(&mouseplay2), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3935
                optionsFile.read(reinterpret_cast<char*>(&joyplay1),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3936
                optionsFile.read(reinterpret_cast<char*>(&joyplay2),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3937
            }
769a41a0 sago007 2008-09-24 12:54 3938
            optionsFile.close();
769a41a0 sago007 2008-09-24 12:54 3939
            cout << "Data loaded from oldstyle options file" << endl;
769a41a0 sago007 2008-09-24 12:54 3940
        }
769a41a0 sago007 2008-09-24 12:54 3941
        else
769a41a0 sago007 2008-09-24 12:54 3942
        {
769a41a0 sago007 2008-09-24 12:54 3943
            cout << "Unable to load options file, using default values" << endl;
769a41a0 sago007 2008-09-24 12:54 3944
        }
89c4a3a6 sago007 2008-08-29 14:32 3945
    }
27ae0175 sago007 2009-01-30 06:02 3946
    
27ae0175 sago007 2009-01-30 06:02 3947
#if NETWORK
27ae0175 sago007 2009-01-30 06:02 3948
    strcpy(serverAddress, "192.168.0.2                 \0");
27ae0175 sago007 2009-01-30 06:02 3949
    if(configSettings->exists("address0"))
27ae0175 sago007 2009-01-30 06:02 3950
    {
27ae0175 sago007 2009-01-30 06:02 3951
        strcpy(serverAddress, "                            \0");
27ae0175 sago007 2009-01-30 06:02 3952
        strncpy(serverAddress,configSettings->getString("address0").c_str(),sizeof(serverAddress)-1);
27ae0175 sago007 2009-01-30 06:02 3953
    }
27ae0175 sago007 2009-01-30 06:02 3954
#endif
89c4a3a6 sago007 2008-08-29 14:32 3955
89c4a3a6 sago007 2008-08-29 14:32 3956
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3957
    {
89c4a3a6 sago007 2008-08-29 14:32 3958
        xsize=300;
89c4a3a6 sago007 2008-08-29 14:32 3959
        ysize=600;
89c4a3a6 sago007 2008-08-29 14:32 3960
    }
89c4a3a6 sago007 2008-08-29 14:32 3961
    
89c4a3a6 sago007 2008-08-29 14:32 3962
    
89c4a3a6 sago007 2008-08-29 14:32 3963
    //Open video
89c4a3a6 sago007 2008-08-29 14:32 3964
    if ((bFullscreen)&&(!singlePuzzle)) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3965
    else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3966
89c4a3a6 sago007 2008-08-29 14:32 3967
    if ( screen == NULL )
89c4a3a6 sago007 2008-08-29 14:32 3968
    {
89c4a3a6 sago007 2008-08-29 14:32 3969
        cout << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3970
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3971
    }
89c4a3a6 sago007 2008-08-29 14:32 3972
866417ca sago007 2009-05-10 21:35 3973
    //Init the file system abstraction layer
866417ca sago007 2009-05-10 21:35 3974
    PHYSFS_init(argv[0]);
866417ca sago007 2009-05-10 21:35 3975
    //Load default theme
2e57d791 sago007 2009-06-04 17:48 3976
    loadTheme(Config::getInstance()->getString("themename"));
866417ca sago007 2009-05-10 21:35 3977
    //Now sets the icon:
866417ca sago007 2009-05-10 21:35 3978
    SDL_Surface *icon = IMG_Load2((char*)"gfx/icon.png");
866417ca sago007 2009-05-10 21:35 3979
    SDL_WM_SetIcon(icon,NULL);
866417ca sago007 2009-05-10 21:35 3980
    //SDL_FreeSurface(icon);
89c4a3a6 sago007 2008-08-29 14:32 3981
89c4a3a6 sago007 2008-08-29 14:32 3982
    cout << "Images loaded" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3983
78d03b38 sago007 2008-11-13 19:56 3984
    //InitMenues();
89c4a3a6 sago007 2008-08-29 14:32 3985
6b1dc7a6 sago007 2010-11-08 21:03 3986
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
6b1dc7a6 sago007 2010-11-08 21:03 3987
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
30f910dd sago007 2010-11-10 21:02 3988
    player1 = &theGame;
30f910dd sago007 2010-11-10 21:02 3989
    player2 = &theGame2;
e1290bdf sago007 2010-10-25 19:56 3990
    /*if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3991
    {
e1290bdf sago007 2010-10-25 19:56 3992
        theGame.GetTopY()=0;
e1290bdf sago007 2010-10-25 19:56 3993
        theGame.GetTopX()=0;
e1290bdf sago007 2010-10-25 19:56 3994
        theGame2.GetTopY()=10000;
e1290bdf sago007 2010-10-25 19:56 3995
        theGame2.GetTopX()=10000;
e1290bdf sago007 2010-10-25 19:56 3996
    }*/
89c4a3a6 sago007 2008-08-29 14:32 3997
    theGame.DoPaintJob();			//Makes sure what there is something to paint
89c4a3a6 sago007 2008-08-29 14:32 3998
    theGame2.DoPaintJob();
89c4a3a6 sago007 2008-08-29 14:32 3999
    theGame.SetGameOver();		//sets the game over in the beginning
89c4a3a6 sago007 2008-08-29 14:32 4000
    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4001
89c4a3a6 sago007 2008-08-29 14:32 4002
89c4a3a6 sago007 2008-08-29 14:32 4003
    //Takes names from file instead
89c4a3a6 sago007 2008-08-29 14:32 4004
    strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 4005
    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4006
89c4a3a6 sago007 2008-08-29 14:32 4007
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 4008
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4009
89c4a3a6 sago007 2008-08-29 14:32 4010
1572de2b sago007 2008-09-11 18:15 4011
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4012
    NetworkThing nt = NetworkThing();
89c4a3a6 sago007 2008-08-29 14:32 4013
    nt.setBGpointers(&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4014
#endif
89c4a3a6 sago007 2008-08-29 14:32 4015
89c4a3a6 sago007 2008-08-29 14:32 4016
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 4017
    {
89c4a3a6 sago007 2008-08-29 14:32 4018
        LoadPuzzleStages();
e1290bdf sago007 2010-10-25 19:56 4019
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4020
        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4021
        vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 4022
    }
89c4a3a6 sago007 2008-08-29 14:32 4023
    //Draws everything to screen
89c4a3a6 sago007 2008-08-29 14:32 4024
    if (!editorMode)
e1290bdf sago007 2010-10-25 19:56 4025
        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4026
    else
e1290bdf sago007 2010-10-25 19:56 4027
        MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 4028
    DrawIMG(background, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 4029
    DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4030
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 4031
    //game loop
89c4a3a6 sago007 2008-08-29 14:32 4032
    int done = 0;
89c4a3a6 sago007 2008-08-29 14:32 4033
    cout << "Starting game loop" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4034
    while (done == 0)
89c4a3a6 sago007 2008-08-29 14:32 4035
    {
89c4a3a6 sago007 2008-08-29 14:32 4036
        if (!(highPriority)) SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 4037
89c4a3a6 sago007 2008-08-29 14:32 4038
        if ((standardBackground)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 4039
        {
e1290bdf sago007 2010-10-25 19:56 4040
            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4041
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4042
        }
89c4a3a6 sago007 2008-08-29 14:32 4043
89c4a3a6 sago007 2008-08-29 14:32 4044
        if ((standardBackground)&&(editorMode))
89c4a3a6 sago007 2008-08-29 14:32 4045
        {
89c4a3a6 sago007 2008-08-29 14:32 4046
            DrawIMG(backgroundImage, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 4047
            MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 4048
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4049
        }
89c4a3a6 sago007 2008-08-29 14:32 4050
89c4a3a6 sago007 2008-08-29 14:32 4051
        //updates the balls and explosions:
89c4a3a6 sago007 2008-08-29 14:32 4052
        theBallManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 4053
        theExplosionManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 4054
        theTextManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 4055
1572de2b sago007 2008-09-11 18:15 4056
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4057
        if (nt.isConnected())
89c4a3a6 sago007 2008-08-29 14:32 4058
        {
89c4a3a6 sago007 2008-08-29 14:32 4059
            nt.updateNetwork();
89c4a3a6 sago007 2008-08-29 14:32 4060
            networkActive = true;
89c4a3a6 sago007 2008-08-29 14:32 4061
            if (!nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 4062
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4063
        }
89c4a3a6 sago007 2008-08-29 14:32 4064
        else
89c4a3a6 sago007 2008-08-29 14:32 4065
            networkActive = false;
89c4a3a6 sago007 2008-08-29 14:32 4066
        if (nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 4067
        {
89c4a3a6 sago007 2008-08-29 14:32 4068
            networkPlay=true;
89c4a3a6 sago007 2008-08-29 14:32 4069
            if (!weWhereConnected) //We have just connected
89c4a3a6 sago007 2008-08-29 14:32 4070
            {
e1290bdf sago007 2010-10-25 19:56 4071
                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4072
                theGame.putStartBlocks(nt.theSeed);
e1290bdf sago007 2010-10-25 19:56 4073
                theGame2.playNetwork(xsize-500,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4074
                nt.theGameHasStarted();
89c4a3a6 sago007 2008-08-29 14:32 4075
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4076
            }
89c4a3a6 sago007 2008-08-29 14:32 4077
            weWhereConnected = true;
89c4a3a6 sago007 2008-08-29 14:32 4078
        }
89c4a3a6 sago007 2008-08-29 14:32 4079
        else
89c4a3a6 sago007 2008-08-29 14:32 4080
        {
89c4a3a6 sago007 2008-08-29 14:32 4081
            networkPlay=false;
89c4a3a6 sago007 2008-08-29 14:32 4082
            weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 4083
        }
89c4a3a6 sago007 2008-08-29 14:32 4084
#endif
89c4a3a6 sago007 2008-08-29 14:32 4085
89c4a3a6 sago007 2008-08-29 14:32 4086
        if (!bScreenLocked)
89c4a3a6 sago007 2008-08-29 14:32 4087
        {
89c4a3a6 sago007 2008-08-29 14:32 4088
            SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 4089
89c4a3a6 sago007 2008-08-29 14:32 4090
            while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 4091
            {
89c4a3a6 sago007 2008-08-29 14:32 4092
                if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 4093
                    done = 1;
89c4a3a6 sago007 2008-08-29 14:32 4094
                }
89c4a3a6 sago007 2008-08-29 14:32 4095
89c4a3a6 sago007 2008-08-29 14:32 4096
                if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 4097
                {
89c4a3a6 sago007 2008-08-29 14:32 4098
                    if ( event.key.keysym.sym == SDLK_ESCAPE )
89c4a3a6 sago007 2008-08-29 14:32 4099
                    {
89c4a3a6 sago007 2008-08-29 14:32 4100
                            if (showOptions)
89c4a3a6 sago007 2008-08-29 14:32 4101
                            {
89c4a3a6 sago007 2008-08-29 14:32 4102
                                showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4103
                            }
89c4a3a6 sago007 2008-08-29 14:32 4104
                            else
89c4a3a6 sago007 2008-08-29 14:32 4105
                                done=1;
89c4a3a6 sago007 2008-08-29 14:32 4106
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4107
89c4a3a6 sago007 2008-08-29 14:32 4108
                    }
e1290bdf sago007 2010-10-25 19:56 4109
                    if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled()))
89c4a3a6 sago007 2008-08-29 14:32 4110
                    {
89c4a3a6 sago007 2008-08-29 14:32 4111
                        //player1:
89c4a3a6 sago007 2008-08-29 14:32 4112
                        if ( event.key.keysym.sym == keySettings[player1keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 4113
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4114
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4115
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4116
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4117
                        }
89c4a3a6 sago007 2008-08-29 14:32 4118
                        if ( event.key.keysym.sym == keySettings[player1keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 4119
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4120
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4121
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4122
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4123
                        }
89c4a3a6 sago007 2008-08-29 14:32 4124
                        if ( (event.key.keysym.sym == keySettings[player1keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 4125
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4126
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4127
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4128
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4129
                        }
89c4a3a6 sago007 2008-08-29 14:32 4130
                        if ( (event.key.keysym.sym == keySettings[player1keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 4131
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4132
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4133
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4134
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4135
                        }
89c4a3a6 sago007 2008-08-29 14:32 4136
                        if ( event.key.keysym.sym == keySettings[player1keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 4137
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4138
                        }
89c4a3a6 sago007 2008-08-29 14:32 4139
                        if ( event.key.keysym.sym == keySettings[player1keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 4140
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4141
                        }
89c4a3a6 sago007 2008-08-29 14:32 4142
                    }
e1290bdf sago007 2010-10-25 19:56 4143
                    if (!editorMode && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4144
                    {
89c4a3a6 sago007 2008-08-29 14:32 4145
                        //player2:
89c4a3a6 sago007 2008-08-29 14:32 4146
                        if ( event.key.keysym.sym == keySettings[player2keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 4147
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4148
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4149
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4150
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4151
                        }
89c4a3a6 sago007 2008-08-29 14:32 4152
                        if ( event.key.keysym.sym == keySettings[player2keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 4153
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4154
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4155
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4156
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4157
                        }
89c4a3a6 sago007 2008-08-29 14:32 4158
                        if ( (event.key.keysym.sym == keySettings[player2keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 4159
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4160
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4161
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4162
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4163
                        }
89c4a3a6 sago007 2008-08-29 14:32 4164
                        if ( (event.key.keysym.sym == keySettings[player2keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 4165
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4166
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4167
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4168
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4169
                        }
89c4a3a6 sago007 2008-08-29 14:32 4170
                        if ( event.key.keysym.sym == keySettings[player2keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 4171
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4172
                        }
89c4a3a6 sago007 2008-08-29 14:32 4173
                        if ( event.key.keysym.sym == keySettings[player2keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 4174
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4175
                        }
89c4a3a6 sago007 2008-08-29 14:32 4176
                    }
89c4a3a6 sago007 2008-08-29 14:32 4177
                    //common:
89c4a3a6 sago007 2008-08-29 14:32 4178
                    if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 4179
                    {
89c4a3a6 sago007 2008-08-29 14:32 4180
                        if ( event.key.keysym.sym == SDLK_F2 ) {
2f30c381 sago007 2008-09-14 13:08 4181
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4182
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 4183
                            #else
47529580 sago007 2008-12-09 02:34 4184
                            if ((!showOptions)){
2f30c381 sago007 2008-09-14 13:08 4185
                            #endif
30f910dd sago007 2010-11-10 21:02 4186
                                StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 4187
                            }}
89c4a3a6 sago007 2008-08-29 14:32 4188
                        if ( event.key.keysym.sym == SDLK_F3 ) {
2f30c381 sago007 2008-09-14 13:08 4189
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4190
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 4191
                            #else
47529580 sago007 2008-12-09 02:34 4192
                            if ((!showOptions)){    
2f30c381 sago007 2008-09-14 13:08 4193
                            #endif
e1290bdf sago007 2010-10-25 19:56 4194
                                theGame.NewTimeTrialGame(50,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4195
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4196
                                twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4197
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4198
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4199
                                vsMode = false;
c96f480e sago007 2009-03-28 18:59 4200
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4201
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4202
                            }}
89c4a3a6 sago007 2008-08-29 14:32 4203
                        if ( event.key.keysym.sym == SDLK_F5 )
89c4a3a6 sago007 2008-08-29 14:32 4204
                        {
2f30c381 sago007 2008-09-14 13:08 4205
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4206
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4207
                            #else
47529580 sago007 2008-12-09 02:34 4208
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4209
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4210
                            {
89c4a3a6 sago007 2008-08-29 14:32 4211
                                int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4212
                                theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4213
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4214
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4215
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4216
                                twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4217
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4218
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4219
                                vsMode = false;
c96f480e sago007 2009-03-28 18:59 4220
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4221
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4222
                            }
89c4a3a6 sago007 2008-08-29 14:32 4223
                        }
89c4a3a6 sago007 2008-08-29 14:32 4224
                        if ( event.key.keysym.sym == SDLK_F6 )
89c4a3a6 sago007 2008-08-29 14:32 4225
                        {
2f30c381 sago007 2008-09-14 13:08 4226
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4227
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4228
                            #else
47529580 sago007 2008-12-09 02:34 4229
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4230
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4231
                            {
e1290bdf sago007 2010-10-25 19:56 4232
                                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4233
                                theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4234
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4235
                                vsMode = true;
c96f480e sago007 2009-03-28 18:59 4236
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4237
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4238
                                theGame.setGameSpeed(player1Speed);
89c4a3a6 sago007 2008-08-29 14:32 4239
                                theGame2.setGameSpeed(player2Speed);
89c4a3a6 sago007 2008-08-29 14:32 4240
                                theGame.setHandicap(player1handicap);
89c4a3a6 sago007 2008-08-29 14:32 4241
                                theGame2.setHandicap(player2handicap);
e1290bdf sago007 2010-10-25 19:56 4242
                                if(player1AI)
e1290bdf sago007 2010-10-25 19:56 4243
                                    theGame.setAIlevel(player1AIlevel);
e1290bdf sago007 2010-10-25 19:56 4244
                                if(player2AI)
e1290bdf sago007 2010-10-25 19:56 4245
                                    theGame2.setAIlevel(player2AIlevel);
89c4a3a6 sago007 2008-08-29 14:32 4246
                                int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4247
                                theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4248
                                theGame2.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4249
                                twoPlayers = true;
89c4a3a6 sago007 2008-08-29 14:32 4250
                            }
89c4a3a6 sago007 2008-08-29 14:32 4251
                        }
89c4a3a6 sago007 2008-08-29 14:32 4252
                        if ( event.key.keysym.sym == SDLK_F4 )
89c4a3a6 sago007 2008-08-29 14:32 4253
                        {
2f30c381 sago007 2008-09-14 13:08 4254
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4255
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4256
                            #else
47529580 sago007 2008-12-09 02:34 4257
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4258
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4259
                            {
e1290bdf sago007 2010-10-25 19:56 4260
                                theGame.NewTimeTrialGame(50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4261
                                theGame2.NewTimeTrialGame(xsize-500,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4262
                                int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4263
                                theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4264
                                theGame2.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4265
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4266
                                twoPlayers = true;
89c4a3a6 sago007 2008-08-29 14:32 4267
                                theGame.setGameSpeed(player1Speed);
89c4a3a6 sago007 2008-08-29 14:32 4268
                                theGame2.setGameSpeed(player2Speed);
89c4a3a6 sago007 2008-08-29 14:32 4269
                                theGame.setHandicap(player1handicap);
89c4a3a6 sago007 2008-08-29 14:32 4270
                                theGame2.setHandicap(player2handicap);
e1290bdf sago007 2010-10-25 19:56 4271
                                if(player1AI)
e1290bdf sago007 2010-10-25 19:56 4272
                                    theGame.setAIlevel(player1AIlevel);
e1290bdf sago007 2010-10-25 19:56 4273
                                if(player2AI)
e1290bdf sago007 2010-10-25 19:56 4274
                                    theGame2.setAIlevel(player2AIlevel);
c96f480e sago007 2009-03-28 18:59 4275
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4276
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4277
                            }
89c4a3a6 sago007 2008-08-29 14:32 4278
                        }
89c4a3a6 sago007 2008-08-29 14:32 4279
                        if ( event.key.keysym.sym == SDLK_F7 )
89c4a3a6 sago007 2008-08-29 14:32 4280
                        {
2f30c381 sago007 2008-09-14 13:08 4281
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4282
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4283
                            #else
47529580 sago007 2008-12-09 02:34 4284
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4285
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4286
                            {
89c4a3a6 sago007 2008-08-29 14:32 4287
                                int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4288
                                theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4289
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4290
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4291
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4292
                                twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4293
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4294
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4295
                                vsMode = true;
c96f480e sago007 2009-03-28 18:59 4296
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4297
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4298
                            }
89c4a3a6 sago007 2008-08-29 14:32 4299
                        }
89c4a3a6 sago007 2008-08-29 14:32 4300
                        if ( event.key.keysym.sym == SDLK_F8 )
89c4a3a6 sago007 2008-08-29 14:32 4301
                        {
95bc02ff sago007 2009-03-15 02:46 4302
                            if(!keymenu.activated && keymenu.canBeActivatedTime > SDL_GetTicks())
95bc02ff sago007 2009-03-15 02:46 4303
                            {
95bc02ff sago007 2009-03-15 02:46 4304
                                keymenu.activated = true;
95bc02ff sago007 2009-03-15 02:46 4305
                                keymenu.x = 0;
95bc02ff sago007 2009-03-15 02:46 4306
                                keymenu.y = 0;
95bc02ff sago007 2009-03-15 02:46 4307
                            }
89c4a3a6 sago007 2008-08-29 14:32 4308
                        }
89c4a3a6 sago007 2008-08-29 14:32 4309
                        if ( event.key.keysym.sym == SDLK_F9 ) {
89c4a3a6 sago007 2008-08-29 14:32 4310
                            writeScreenShot();
89c4a3a6 sago007 2008-08-29 14:32 4311
                        }
89c4a3a6 sago007 2008-08-29 14:32 4312
                        if ( event.key.keysym.sym == SDLK_F11 ) {
89c4a3a6 sago007 2008-08-29 14:32 4313
                            /*This is the test place, place function to test here*/
89c4a3a6 sago007 2008-08-29 14:32 4314
89c4a3a6 sago007 2008-08-29 14:32 4315
                            //theGame.CreateGreyGarbage();
78d03b38 sago007 2008-11-13 19:56 4316
                            //char mitNavn[30];
78d03b38 sago007 2008-11-13 19:56 4317
                            //SelectThemeDialogbox(300,400,mitNavn);
78d03b38 sago007 2008-11-13 19:56 4318
                           // MainMenu();
47529580 sago007 2008-12-09 02:34 4319
                            OpenScoresDisplay();
89c4a3a6 sago007 2008-08-29 14:32 4320
                        } //F11
89c4a3a6 sago007 2008-08-29 14:32 4321
                    }
89c4a3a6 sago007 2008-08-29 14:32 4322
                    if ( event.key.keysym.sym == SDLK_F12 ) {
89c4a3a6 sago007 2008-08-29 14:32 4323
                        done=1;
89c4a3a6 sago007 2008-08-29 14:32 4324
                    }
89c4a3a6 sago007 2008-08-29 14:32 4325
                }
89c4a3a6 sago007 2008-08-29 14:32 4326
            } //while event PollEvent - read keys
89c4a3a6 sago007 2008-08-29 14:32 4327
89c4a3a6 sago007 2008-08-29 14:32 4328
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4329
            **************************** Repeating start **************************
89c4a3a6 sago007 2008-08-29 14:32 4330
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4331
89c4a3a6 sago007 2008-08-29 14:32 4332
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4333
//Also the joysticks:
89c4a3a6 sago007 2008-08-29 14:32 4334
//Repeating not implemented
89c4a3a6 sago007 2008-08-29 14:32 4335
89c4a3a6 sago007 2008-08-29 14:32 4336
//Player 1 start
89c4a3a6 sago007 2008-08-29 14:32 4337
            if (!(keys[keySettings[player1keys].up]))
30f910dd sago007 2010-11-10 21:02 4338
                repeatingN[0]=false;
30f910dd sago007 2010-11-10 21:02 4339
            while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4340
            {
89c4a3a6 sago007 2008-08-29 14:32 4341
                theGame.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4342
                timesRepeatedP1N++;
89c4a3a6 sago007 2008-08-29 14:32 4343
            }
89c4a3a6 sago007 2008-08-29 14:32 4344
89c4a3a6 sago007 2008-08-29 14:32 4345
            if (!(keys[keySettings[player1keys].down]))
30f910dd sago007 2010-11-10 21:02 4346
                repeatingS[0]=false;
30f910dd sago007 2010-11-10 21:02 4347
            while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4348
            {
89c4a3a6 sago007 2008-08-29 14:32 4349
                theGame.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4350
                timesRepeatedP1S++;
89c4a3a6 sago007 2008-08-29 14:32 4351
            }
89c4a3a6 sago007 2008-08-29 14:32 4352
89c4a3a6 sago007 2008-08-29 14:32 4353
            if (!(keys[keySettings[player1keys].left]))
30f910dd sago007 2010-11-10 21:02 4354
                repeatingW[0]=false;
30f910dd sago007 2010-11-10 21:02 4355
            while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4356
            {
89c4a3a6 sago007 2008-08-29 14:32 4357
                timesRepeatedP1W++;
89c4a3a6 sago007 2008-08-29 14:32 4358
                theGame.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4359
            }
89c4a3a6 sago007 2008-08-29 14:32 4360
89c4a3a6 sago007 2008-08-29 14:32 4361
            if (!(keys[keySettings[player1keys].right]))
30f910dd sago007 2010-11-10 21:02 4362
                repeatingE[0]=false;
30f910dd sago007 2010-11-10 21:02 4363
            while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4364
            {
89c4a3a6 sago007 2008-08-29 14:32 4365
                timesRepeatedP1E++;
89c4a3a6 sago007 2008-08-29 14:32 4366
                theGame.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4367
            }
89c4a3a6 sago007 2008-08-29 14:32 4368
89c4a3a6 sago007 2008-08-29 14:32 4369
//Player 1 end
89c4a3a6 sago007 2008-08-29 14:32 4370
89c4a3a6 sago007 2008-08-29 14:32 4371
//Player 2 start
89c4a3a6 sago007 2008-08-29 14:32 4372
            if (!(keys[keySettings[player2keys].up]))
30f910dd sago007 2010-11-10 21:02 4373
                repeatingN[1]=false;
30f910dd sago007 2010-11-10 21:02 4374
            while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4375
            {
89c4a3a6 sago007 2008-08-29 14:32 4376
                theGame2.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4377
                timesRepeatedP2N++;
89c4a3a6 sago007 2008-08-29 14:32 4378
            }
89c4a3a6 sago007 2008-08-29 14:32 4379
89c4a3a6 sago007 2008-08-29 14:32 4380
            if (!(keys[keySettings[player2keys].down]))
30f910dd sago007 2010-11-10 21:02 4381
                repeatingS[1]=false;
30f910dd sago007 2010-11-10 21:02 4382
            while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4383
            {
89c4a3a6 sago007 2008-08-29 14:32 4384
                theGame2.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4385
                timesRepeatedP2S++;
89c4a3a6 sago007 2008-08-29 14:32 4386
            }
89c4a3a6 sago007 2008-08-29 14:32 4387
89c4a3a6 sago007 2008-08-29 14:32 4388
            if (!(keys[keySettings[player2keys].left]))
30f910dd sago007 2010-11-10 21:02 4389
                repeatingW[1]=false;
30f910dd sago007 2010-11-10 21:02 4390
            while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4391
            {
89c4a3a6 sago007 2008-08-29 14:32 4392
                theGame2.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4393
                timesRepeatedP2W++;
89c4a3a6 sago007 2008-08-29 14:32 4394
            }
89c4a3a6 sago007 2008-08-29 14:32 4395
89c4a3a6 sago007 2008-08-29 14:32 4396
            if (!(keys[keySettings[player2keys].right]))
30f910dd sago007 2010-11-10 21:02 4397
                repeatingE[1]=false;
30f910dd sago007 2010-11-10 21:02 4398
            while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4399
            {
89c4a3a6 sago007 2008-08-29 14:32 4400
                theGame2.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4401
                timesRepeatedP2E++;
89c4a3a6 sago007 2008-08-29 14:32 4402
            }
89c4a3a6 sago007 2008-08-29 14:32 4403
89c4a3a6 sago007 2008-08-29 14:32 4404
//Player 2 end
89c4a3a6 sago007 2008-08-29 14:32 4405
89c4a3a6 sago007 2008-08-29 14:32 4406
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4407
            **************************** Repeating end ****************************
89c4a3a6 sago007 2008-08-29 14:32 4408
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4409
89c4a3a6 sago007 2008-08-29 14:32 4410
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4411
            ***************************** Joypad start ****************************
89c4a3a6 sago007 2008-08-29 14:32 4412
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4413
6d48320c sago007 2009-03-28 17:06 4414
            //Menu
6d48320c sago007 2009-03-28 17:06 4415
            if(joypad1.working)
6d48320c sago007 2009-03-28 17:06 4416
            {
6d48320c sago007 2009-03-28 17:06 4417
                joypad1.update();
6d48320c sago007 2009-03-28 17:06 4418
                if(joypad1.but1)
6d48320c sago007 2009-03-28 17:06 4419
                {
6d48320c sago007 2009-03-28 17:06 4420
                    if(!keymenu.activated && keymenu.canBeActivatedTime > SDL_GetTicks())
6d48320c sago007 2009-03-28 17:06 4421
                    {
6d48320c sago007 2009-03-28 17:06 4422
                        keymenu.activated = true;
6d48320c sago007 2009-03-28 17:06 4423
                        keymenu.x = 0;
6d48320c sago007 2009-03-28 17:06 4424
                        keymenu.y = 0;
6d48320c sago007 2009-03-28 17:06 4425
                    }
6d48320c sago007 2009-03-28 17:06 4426
                }
6d48320c sago007 2009-03-28 17:06 4427
            }
6d48320c sago007 2009-03-28 17:06 4428
6d48320c sago007 2009-03-28 17:06 4429
            //Gameplay
89c4a3a6 sago007 2008-08-29 14:32 4430
            if (joyplay1||joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4431
            {
e1290bdf sago007 2010-10-25 19:56 4432
                if (joypad1.working && !theGame.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4433
                    if (joyplay1)
89c4a3a6 sago007 2008-08-29 14:32 4434
                    {
89c4a3a6 sago007 2008-08-29 14:32 4435
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4436
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4437
                        {
89c4a3a6 sago007 2008-08-29 14:32 4438
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4439
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4440
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4441
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4442
                        }
89c4a3a6 sago007 2008-08-29 14:32 4443
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4444
                        {
89c4a3a6 sago007 2008-08-29 14:32 4445
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4446
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4447
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4448
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4449
                        }
89c4a3a6 sago007 2008-08-29 14:32 4450
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4451
                        {
89c4a3a6 sago007 2008-08-29 14:32 4452
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4453
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4454
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4455
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4456
                        }
89c4a3a6 sago007 2008-08-29 14:32 4457
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4458
                        {
89c4a3a6 sago007 2008-08-29 14:32 4459
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4460
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4461
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4462
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4463
                        }
89c4a3a6 sago007 2008-08-29 14:32 4464
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4465
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4466
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4467
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4468
                    }
89c4a3a6 sago007 2008-08-29 14:32 4469
                    else
89c4a3a6 sago007 2008-08-29 14:32 4470
                    {
89c4a3a6 sago007 2008-08-29 14:32 4471
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4472
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4473
                        {
89c4a3a6 sago007 2008-08-29 14:32 4474
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4475
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4476
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4477
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4478
                        }
89c4a3a6 sago007 2008-08-29 14:32 4479
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4480
                        {
89c4a3a6 sago007 2008-08-29 14:32 4481
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4482
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4483
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4484
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4485
                        }
89c4a3a6 sago007 2008-08-29 14:32 4486
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4487
                        {
89c4a3a6 sago007 2008-08-29 14:32 4488
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4489
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4490
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4491
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4492
                        }
89c4a3a6 sago007 2008-08-29 14:32 4493
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4494
                        {
89c4a3a6 sago007 2008-08-29 14:32 4495
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4496
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4497
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4498
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4499
                        }
89c4a3a6 sago007 2008-08-29 14:32 4500
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4501
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4502
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4503
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4504
                    }
e1290bdf sago007 2010-10-25 19:56 4505
                if (joypad2.working && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4506
                    if (!joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4507
                    {
89c4a3a6 sago007 2008-08-29 14:32 4508
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4509
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4510
                        {
89c4a3a6 sago007 2008-08-29 14:32 4511
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4512
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4513
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4514
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4515
                        }
89c4a3a6 sago007 2008-08-29 14:32 4516
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4517
                        {
89c4a3a6 sago007 2008-08-29 14:32 4518
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4519
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4520
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4521
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4522
                        }
89c4a3a6 sago007 2008-08-29 14:32 4523
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4524
                        {
89c4a3a6 sago007 2008-08-29 14:32 4525
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4526
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4527
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4528
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4529
                        }
89c4a3a6 sago007 2008-08-29 14:32 4530
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4531
                        {
89c4a3a6 sago007 2008-08-29 14:32 4532
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4533
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4534
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4535
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4536
                        }
89c4a3a6 sago007 2008-08-29 14:32 4537
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4538
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4539
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4540
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4541
                    }
89c4a3a6 sago007 2008-08-29 14:32 4542
                    else
89c4a3a6 sago007 2008-08-29 14:32 4543
                    {
89c4a3a6 sago007 2008-08-29 14:32 4544
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4545
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4546
                        {
89c4a3a6 sago007 2008-08-29 14:32 4547
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4548
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4549
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4550
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4551
                        }
89c4a3a6 sago007 2008-08-29 14:32 4552
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4553
                        {
89c4a3a6 sago007 2008-08-29 14:32 4554
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4555
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4556
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4557
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4558
                        }
89c4a3a6 sago007 2008-08-29 14:32 4559
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4560
                        {
89c4a3a6 sago007 2008-08-29 14:32 4561
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4562
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4563
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4564
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4565
                        }
89c4a3a6 sago007 2008-08-29 14:32 4566
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4567
                        {
89c4a3a6 sago007 2008-08-29 14:32 4568
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4569
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4570
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4571
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4572
                        }
89c4a3a6 sago007 2008-08-29 14:32 4573
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4574
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4575
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4576
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4577
                    }
89c4a3a6 sago007 2008-08-29 14:32 4578
            }
89c4a3a6 sago007 2008-08-29 14:32 4579
89c4a3a6 sago007 2008-08-29 14:32 4580
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4581
            ***************************** Joypad end ******************************
89c4a3a6 sago007 2008-08-29 14:32 4582
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4583
89c4a3a6 sago007 2008-08-29 14:32 4584
89c4a3a6 sago007 2008-08-29 14:32 4585
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4586
6d48320c sago007 2009-03-28 17:06 4587
            if(keymenu.activated)
6d48320c sago007 2009-03-28 17:06 4588
            {
6d48320c sago007 2009-03-28 17:06 4589
                mousex = keymenu.x*buttonXsize-10;
6d48320c sago007 2009-03-28 17:06 4590
                mousey = keymenu.y*buttonYsize-10;
6d48320c sago007 2009-03-28 17:06 4591
            }
6d48320c sago007 2009-03-28 17:06 4592
            else
6d48320c sago007 2009-03-28 17:06 4593
                SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 4594
89c4a3a6 sago007 2008-08-29 14:32 4595
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4596
            **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4597
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4598
e1290bdf sago007 2010-10-25 19:56 4599
            if ((mouseplay1)&&((!editorMode)&&(!theGame.GetAIenabled())||(editorModeTest))) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4600
                if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4601
                {
89c4a3a6 sago007 2008-08-29 14:32 4602
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4603
                    yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4604
                    xLine = (mousex-50+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4605
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4606
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4607
                    if ((yLine>10)&&(theGame.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4608
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4609
                    if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4610
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4611
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4612
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4613
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4614
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4615
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4616
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4617
                    theGame.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4618
                }
89c4a3a6 sago007 2008-08-29 14:32 4619
e1290bdf sago007 2010-10-25 19:56 4620
            if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4621
                if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4622
                {
89c4a3a6 sago007 2008-08-29 14:32 4623
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4624
                    yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4625
                    xLine = (mousex-(xsize-500)+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4626
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4627
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4628
                    if ((yLine>10)&&(theGame2.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4629
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4630
                    if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4631
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4632
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4633
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4634
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4635
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4636
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4637
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4638
                    theGame2.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4639
                }
89c4a3a6 sago007 2008-08-29 14:32 4640
89c4a3a6 sago007 2008-08-29 14:32 4641
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4642
            **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4643
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4644
89c4a3a6 sago007 2008-08-29 14:32 4645
            // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 4646
            if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 4647
            {
89c4a3a6 sago007 2008-08-29 14:32 4648
                bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 4649
            }
89c4a3a6 sago007 2008-08-29 14:32 4650
89c4a3a6 sago007 2008-08-29 14:32 4651
            // If the mouse button 2 is released, make bMouseUp2 equal true
89c4a3a6 sago007 2008-08-29 14:32 4652
            if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3))
89c4a3a6 sago007 2008-08-29 14:32 4653
            {
89c4a3a6 sago007 2008-08-29 14:32 4654
                bMouseUp2=true;
89c4a3a6 sago007 2008-08-29 14:32 4655
            }
89c4a3a6 sago007 2008-08-29 14:32 4656
89c4a3a6 sago007 2008-08-29 14:32 4657
            if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 4658
            {
89c4a3a6 sago007 2008-08-29 14:32 4659
                //read mouse events
89c4a3a6 sago007 2008-08-29 14:32 4660
                if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 4661
                {
89c4a3a6 sago007 2008-08-29 14:32 4662
                    bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 4663
                    DrawIMG(background, screen, 0, 0);
2f30c381 sago007 2008-09-14 13:08 4664
                    #if NETWORK
2f30c381 sago007 2008-09-14 13:08 4665
                    //Nothing
2f30c381 sago007 2008-09-14 13:08 4666
                    #else
2f30c381 sago007 2008-09-14 13:08 4667
                    bool networkActive=false;
2f30c381 sago007 2008-09-14 13:08 4668
                    #endif
9050a50a sago007 2008-12-09 13:35 4669
                    if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4670
                    {
89c4a3a6 sago007 2008-08-29 14:32 4671
                        //New game clicked
89c4a3a6 sago007 2008-08-29 14:32 4672
                        bool state = (!bNewGameOpen);
89c4a3a6 sago007 2008-08-29 14:32 4673
                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4674
                        bNewGameOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4675
                        showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4676
                    }
89c4a3a6 sago007 2008-08-29 14:32 4677
                    else
1572de2b sago007 2008-09-11 18:15 4678
#if NETWORK
9050a50a sago007 2008-12-09 13:35 4679
                        if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4680
                        {
89c4a3a6 sago007 2008-08-29 14:32 4681
                            //Disconnect clicked!
89c4a3a6 sago007 2008-08-29 14:32 4682
                            cout << "Disconnect clicked!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4683
                            nt.ntDisconnect();
89c4a3a6 sago007 2008-08-29 14:32 4684
                        }
89c4a3a6 sago007 2008-08-29 14:32 4685
                        else
89c4a3a6 sago007 2008-08-29 14:32 4686
#endif
9050a50a sago007 2008-12-09 13:35 4687
                            if ((0<mousex) && (mousex<buttonXsize) && (40<mousey) && (mousey<80) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4688
                            {
89c4a3a6 sago007 2008-08-29 14:32 4689
                                //1player
89c4a3a6 sago007 2008-08-29 14:32 4690
                                b1playerOpen = (!b1playerOpen);
89c4a3a6 sago007 2008-08-29 14:32 4691
                                b2playersOpen = false;
1572de2b sago007 2008-09-11 18:15 4692
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4693
                                bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4694
#endif
89c4a3a6 sago007 2008-08-29 14:32 4695
                            }
89c4a3a6 sago007 2008-08-29 14:32 4696
                            else
9050a50a sago007 2008-12-09 13:35 4697
                                if ((0<mousex) && (mousex<buttonXsize) && (80<mousey) && (mousey<120) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4698
                                {
89c4a3a6 sago007 2008-08-29 14:32 4699
                                    //2player
89c4a3a6 sago007 2008-08-29 14:32 4700
                                    b2playersOpen = (!b2playersOpen);
89c4a3a6 sago007 2008-08-29 14:32 4701
                                    b1playerOpen = false;
1572de2b sago007 2008-09-11 18:15 4702
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4703
                                    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4704
#endif
89c4a3a6 sago007 2008-08-29 14:32 4705
                                }
1572de2b sago007 2008-09-11 18:15 4706
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4707
                                else
9050a50a sago007 2008-12-09 13:35 4708
                                    if ((0<mousex) && (mousex<buttonXsize) && (120<mousey) && (mousey<160) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4709
                                    {
89c4a3a6 sago007 2008-08-29 14:32 4710
                                        //Network
89c4a3a6 sago007 2008-08-29 14:32 4711
                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4712
                                        b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4713
                                        bNetworkOpen = (!bNetworkOpen);
89c4a3a6 sago007 2008-08-29 14:32 4714
                                    }
89c4a3a6 sago007 2008-08-29 14:32 4715
#endif
89c4a3a6 sago007 2008-08-29 14:32 4716
                                    else
9050a50a sago007 2008-12-09 13:35 4717
                                        if ((buttonXsize<mousex) && (mousex<240) && (40<mousey) && (mousey<80) && (b1playerOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4718
                                        {
30f910dd sago007 2010-11-10 21:02 4719
                                            StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 4720
                                        }
89c4a3a6 sago007 2008-08-29 14:32 4721
                                        else
9050a50a sago007 2008-12-09 13:35 4722
                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b1playerOpen) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4723
                                            {
89c4a3a6 sago007 2008-08-29 14:32 4724
                                                //1 player - time trial
e1290bdf sago007 2010-10-25 19:56 4725
                                                theGame.NewTimeTrialGame(50,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4726
                                                bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4727
                                                b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4728
                                                twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4729
                                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4730
                                                showGame = true;
c96f480e sago007 2009-03-28 18:59 4731
                                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4732
                                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4733
                                            }
89c4a3a6 sago007 2008-08-29 14:32 4734
                                            else
9050a50a sago007 2008-12-09 13:35 4735
                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b1playerOpen)&&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4736
                                                {
89c4a3a6 sago007 2008-08-29 14:32 4737
                                                    //1 player - stage clear
89c4a3a6 sago007 2008-08-29 14:32 4738
                                                    bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4739
                                                    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4740
                                                    int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4741
                                                    theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4742
                                                    MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4743
                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4744
                                                    twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4745
                                                    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4746
                                                    showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4747
                                                    vsMode = false;
c96f480e sago007 2009-03-28 18:59 4748
                                                    strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4749
                                                    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4750
                                                }
89c4a3a6 sago007 2008-08-29 14:32 4751
                                                else
9050a50a sago007 2008-12-09 13:35 4752
                                                    if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4753
                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4754
                                                        //1 player - puzzle
89c4a3a6 sago007 2008-08-29 14:32 4755
                                                        bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4756
                                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4757
                                                        int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4758
                                                        theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4759
                                                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4760
                                                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4761
                                                        twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4762
                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4763
                                                        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4764
                                                        vsMode = false;
c96f480e sago007 2009-03-28 18:59 4765
                                                        strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4766
                                                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4767
                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4768
                                                    else
9050a50a sago007 2008-12-09 13:35 4769
                                                        if ((buttonXsize<mousex) && (mousex<240) && (200<mousey) && (mousey<240) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4770
                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4771
                                                            //1 player - Vs mode
89c4a3a6 sago007 2008-08-29 14:32 4772
                                                            bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4773
                                                            b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4774
                                                            int theAIlevel = startSingleVs();
e1290bdf sago007 2010-10-25 19:56 4775
                                                            theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4776
                                                            theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4777
                                                            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4778
                                                            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4779
                                                            twoPlayers = true; //Single player, but AI plays
89c4a3a6 sago007 2008-08-29 14:32 4780
                                                            showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4781
                                                            vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 4782
                                                            theGame2.setAIlevel((Uint8)theAIlevel);
89c4a3a6 sago007 2008-08-29 14:32 4783
                                                            int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4784
                                                            theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4785
                                                            theGame2.putStartBlocks(theTime);
c96f480e sago007 2009-03-28 18:59 4786
                                                            strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4787
                                                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4788
                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4789
                                                        else
9050a50a sago007 2008-12-09 13:35 4790
                                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4791
                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4792
                                                                //2 player - time trial
e1290bdf sago007 2010-10-25 19:56 4793
                                                                theGame.NewTimeTrialGame(50,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4794
                                                                bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4795
                                                                b2playersOpen = false;
e1290bdf sago007 2010-10-25 19:56 4796
                                                                theGame.NewTimeTrialGame(50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4797
                                                                theGame2.NewTimeTrialGame(xsize-500,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4798
                                                                int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4799
                                                                theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4800
                                                                theGame2.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4801
                                                                theGame.setGameSpeed(player1Speed);
89c4a3a6 sago007 2008-08-29 14:32 4802
                                                                theGame2.setGameSpeed(player2Speed);
89c4a3a6 sago007 2008-08-29 14:32 4803
                                                                theGame.setHandicap(player1handicap);
89c4a3a6 sago007 2008-08-29 14:32 4804
                                                                theGame2.setHandicap(player2handicap);
e1290bdf sago007 2010-10-25 19:56 4805
                                                                if(player1AI)
e1290bdf sago007 2010-10-25 19:56 4806
                                                                    theGame.setAIlevel(player1AIlevel);
e1290bdf sago007 2010-10-25 19:56 4807
                                                                if(player1AI)
e1290bdf sago007 2010-10-25 19:56 4808
                                                                    theGame2.setAIlevel(player2AIlevel);
89c4a3a6 sago007 2008-08-29 14:32 4809
                                                                twoPlayers = true;
c96f480e sago007 2009-03-28 18:59 4810
                                                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4811
                                                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4812
                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4813
                                                            else
9050a50a sago007 2008-12-09 13:35 4814
                                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4815
                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4816
                                                                    //2 player - VsMode
e1290bdf sago007 2010-10-25 19:56 4817
                                                                    theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4818
                                                                    theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4819
                                                                    bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4820
                                                                    vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 4821
                                                                    twoPlayers = true;
89c4a3a6 sago007 2008-08-29 14:32 4822
                                                                    b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4823
                                                                    theGame.setGameSpeed(player1Speed);
89c4a3a6 sago007 2008-08-29 14:32 4824
                                                                    theGame2.setGameSpeed(player2Speed);
89c4a3a6 sago007 2008-08-29 14:32 4825
                                                                    theGame.setHandicap(player1handicap);
89c4a3a6 sago007 2008-08-29 14:32 4826
                                                                    theGame2.setHandicap(player2handicap);
e1290bdf sago007 2010-10-25 19:56 4827
                                                                    if(player1AI)
e1290bdf sago007 2010-10-25 19:56 4828
                                                                        theGame.setAIlevel(player1AIlevel);
e1290bdf sago007 2010-10-25 19:56 4829
                                                                    if(player2AI)
e1290bdf sago007 2010-10-25 19:56 4830
                                                                        theGame2.setAIlevel(player2AIlevel);
89c4a3a6 sago007 2008-08-29 14:32 4831
                                                                    int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4832
                                                                    theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4833
                                                                    theGame2.putStartBlocks(theTime);
c96f480e sago007 2009-03-28 18:59 4834
                                                                    strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4835
                                                                    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4836
                                                                }
1572de2b sago007 2008-09-11 18:15 4837
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4838
                                                                else
9050a50a sago007 2008-12-09 13:35 4839
                                                                    if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4840
                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4841
                                                                        //Host
89c4a3a6 sago007 2008-08-29 14:32 4842
                                                                        cout << "Host" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4843
                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4844
                                                                        theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4845
                                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4846
                                                                        nt.startServer();
89c4a3a6 sago007 2008-08-29 14:32 4847
                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4848
                                                                    else
9050a50a sago007 2008-12-09 13:35 4849
                                                                        if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4850
                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4851
                                                                            //Connect
89c4a3a6 sago007 2008-08-29 14:32 4852
                                                                            cout << "Connect" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4853
                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4854
                                                                            theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4855
                                                                            theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4856
                                                                            if (OpenDialogbox(200,100,serverAddress))
89c4a3a6 sago007 2008-08-29 14:32 4857
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4858
                                                                                char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4859
                                                                                memcpy(buf,serverAddress,30);
89c4a3a6 sago007 2008-08-29 14:32 4860
                                                                                nt.connectToServer(strtok(buf," "));
89c4a3a6 sago007 2008-08-29 14:32 4861
                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4862
                                                                            while ( SDL_PollEvent(&event) ); //If the user have pressed ESC or the like
89c4a3a6 sago007 2008-08-29 14:32 4863
                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4864
#endif
89c4a3a6 sago007 2008-08-29 14:32 4865
                                                                        else
9050a50a sago007 2008-12-09 13:35 4866
                                                                            if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4867
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4868
                                                                                //options button clicked
89c4a3a6 sago007 2008-08-29 14:32 4869
                                                                                if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 4870
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4871
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4872
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4873
                                                                                else
89c4a3a6 sago007 2008-08-29 14:32 4874
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4875
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4876
                                                                                    bOptionsOpen = true;
89c4a3a6 sago007 2008-08-29 14:32 4877
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4878
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4879
                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4880
                                                                            else
9050a50a sago007 2008-12-09 13:35 4881
                                                                                if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (40<mousey) && (mousey<80) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4882
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4883
                                                                                    //Configure button clicked
89c4a3a6 sago007 2008-08-29 14:32 4884
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4885
                                                                                    if (!showOptions) {
89c4a3a6 sago007 2008-08-29 14:32 4886
                                                                                        showOptions = true;
89c4a3a6 sago007 2008-08-29 14:32 4887
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4888
                                                                                    else showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4889
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4890
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4891
                                                                                else
9050a50a sago007 2008-12-09 13:35 4892
                                                                                    if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (80<mousey) && (mousey<120) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4893
                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4894
                                                                                        //Configure button clicked
89c4a3a6 sago007 2008-08-29 14:32 4895
                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4896
                                                                                        changePuzzleLevels();
89c4a3a6 sago007 2008-08-29 14:32 4897
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4898
                                                                                    else
9050a50a sago007 2008-12-09 13:35 4899
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (120<mousey) && (mousey<160) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4900
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4901
                                                                                            //vsMode button clicked
89c4a3a6 sago007 2008-08-29 14:32 4902
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4903
                                                                                            startVsMenu();
89c4a3a6 sago007 2008-08-29 14:32 4904
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4905
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4906
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (160<mousey) && (mousey<200) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4907
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4908
                                                                                            //selectThemClicked
89c4a3a6 sago007 2008-08-29 14:32 4909
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4910
                                                                                            char temp[30];
89c4a3a6 sago007 2008-08-29 14:32 4911
                                                                                            SelectThemeDialogbox(200,100,temp);
89c4a3a6 sago007 2008-08-29 14:32 4912
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4913
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4914
                                                                                            if ((buttonXsize*2<mousex) && (mousex<3*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4915
                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4916
                                                                                                //highscore button clicked
47529580 sago007 2008-12-09 02:34 4917
                                                                                                OpenScoresDisplay();
47529580 sago007 2008-12-09 02:34 4918
89c4a3a6 sago007 2008-08-29 14:32 4919
                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4920
                                                                                            else
9050a50a sago007 2008-12-09 13:35 4921
                                                                                                if ((360<mousex) && (mousex<4*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4922
                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4923
                                                                                                    //Replay clicked!
89c4a3a6 sago007 2008-08-29 14:32 4924
                                                                                                    bool state = (!bReplayOpen);
89c4a3a6 sago007 2008-08-29 14:32 4925
                                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4926
                                                                                                    bReplayOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4927
                                                                                                    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4928
                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4929
                                                                                                else
9050a50a sago007 2008-12-09 13:35 4930
                                                                                                    if ((360<mousex) && (mousex<4*buttonXsize) && (40<mousey) && (mousey<80) &&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4931
                                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4932
                                                                                                        //Replay->Save clicked!
89c4a3a6 sago007 2008-08-29 14:32 4933
                                                                                                        //cout << "Replay->Save clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4934
                                                                                                        char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4935
                                                                                                        for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4936
                                                                                                        buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4937
                                                                                                        OpenDialogbox(200,100,buf);
89c4a3a6 sago007 2008-08-29 14:32 4938
                                                                                                        for (int i=28;buf[i]==' ';i--)
89c4a3a6 sago007 2008-08-29 14:32 4939
                                                                                                            buf[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 4940
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 4941
                                                                                                        string saveHere = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4942
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 4943
                                                                                                        string saveHere = home+(string)"/My Games/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4944
#else
89c4a3a6 sago007 2008-08-29 14:32 4945
                                                                                                        string saveHere = (string)"./replays"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4946
#endif
89c4a3a6 sago007 2008-08-29 14:32 4947
                                                                                                        if (lastNrOfPlayers<2)
89c4a3a6 sago007 2008-08-29 14:32 4948
                                                                                                            theGame.theReplay.saveReplay(saveHere);
89c4a3a6 sago007 2008-08-29 14:32 4949
                                                                                                        else
89c4a3a6 sago007 2008-08-29 14:32 4950
                                                                                                            theGame.theReplay.saveReplay(saveHere,theGame2.theReplay);
89c4a3a6 sago007 2008-08-29 14:32 4951
89c4a3a6 sago007 2008-08-29 14:32 4952
                                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4953
                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4954
                                                                                                    else
9050a50a sago007 2008-12-09 13:35 4955
                                                                                                        if ((360<mousex) && (mousex<4*buttonXsize) && (80<mousey) && (mousey<120)&&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4956
                                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4957
                                                                                                            //Replay->Load clicked!
89c4a3a6 sago007 2008-08-29 14:32 4958
                                                                                                            //cout << "Replay->Load clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4959
89c4a3a6 sago007 2008-08-29 14:32 4960
                                                                                                            char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4961
                                                                                                            for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4962
                                                                                                            buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4963
                                                                                                            if (OpenReplayDialogbox(50,100,buf))
89c4a3a6 sago007 2008-08-29 14:32 4964
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4965
                                                                                                                //cout << "Good way" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4966
                                                                                                                for (int i=28;buf[i]==' ';i--)
89c4a3a6 sago007 2008-08-29 14:32 4967
                                                                                                                    buf[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 4968
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 4969
                                                                                                                string loadThis = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4970
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 4971
                                                                                                                string loadThis = home+(string)"/My Games/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4972
#else
89c4a3a6 sago007 2008-08-29 14:32 4973
                                                                                                                string loadThis = (string)"./replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4974
#endif
89c4a3a6 sago007 2008-08-29 14:32 4975
                                                                                                                ifstream replayFileIn;
89c4a3a6 sago007 2008-08-29 14:32 4976
                                                                                                                replayFileIn.open(loadThis.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 4977
                                                                                                                bool play2 = false;
89c4a3a6 sago007 2008-08-29 14:32 4978
                                                                                                                if (replayFileIn)
89c4a3a6 sago007 2008-08-29 14:32 4979
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4980
                                                                                                                    Uint8 version = 0;
89c4a3a6 sago007 2008-08-29 14:32 4981
                                                                                                                    replayFileIn.read(reinterpret_cast<char*>(&version),sizeof(Uint8));                                                                                                                  replayFileIn.close();
89c4a3a6 sago007 2008-08-29 14:32 4982
                                                                                                                    Replay r1;
e03ae476 sago007 2009-03-06 22:49 4983
                                                                                                                    if(r1.loadReplay(loadThis))
89c4a3a6 sago007 2008-08-29 14:32 4984
                                                                                                                    {
e03ae476 sago007 2009-03-06 22:49 4985
                                                                                                                        Replay r2;
e03ae476 sago007 2009-03-06 22:49 4986
                                                                                                                        play2 = r2.loadReplay2(loadThis);
e1290bdf sago007 2010-10-25 19:56 4987
                                                                                                                        theGame.playReplay(50,100,SDL_GetTicks()); //Fejlen sker her
e03ae476 sago007 2009-03-06 22:49 4988
                                                                                                                        theGame.theReplay = r1;
e03ae476 sago007 2009-03-06 22:49 4989
                                                                                                                        if (play2)
e03ae476 sago007 2009-03-06 22:49 4990
                                                                                                                        {
e1290bdf sago007 2010-10-25 19:56 4991
                                                                                                                            theGame2.playReplay(xsize-500,100,SDL_GetTicks());
e03ae476 sago007 2009-03-06 22:49 4992
                                                                                                                            theGame2.theReplay = r2;
e03ae476 sago007 2009-03-06 22:49 4993
                                                                                                                        }
e03ae476 sago007 2009-03-06 22:49 4994
                                                                                                                        else
e03ae476 sago007 2009-03-06 22:49 4995
                                                                                                                            theGame2.SetGameOver();
e03ae476 sago007 2009-03-06 22:49 4996
                                                                                                                        cout << "Replay should have been read" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4997
                                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4998
                                                                                                                    else
e03ae476 sago007 2009-03-06 22:49 4999
                                                                                                                        cout << "Failed to read replay" << endl;
89c4a3a6 sago007 2008-08-29 14:32 5000
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 5001
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 5002
                                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 5003
                                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 5004
                                                                                                        else
9050a50a sago007 2008-12-09 13:35 5005
                                                                                                            if ((xsize-120<mousex) && (xsize-20>mousex) && (ysize-buttonXsize<mousey) && (ysize-20>mousey))
89c4a3a6 sago007 2008-08-29 14:32 5006
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 5007
                                                                                                                //Exit clicked
89c4a3a6 sago007 2008-08-29 14:32 5008
                                                                                                                done=1;
89c4a3a6 sago007 2008-08-29 14:32 5009
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 5010
                                                                                                            else
89c4a3a6 sago007 2008-08-29 14:32 5011
                                                                                                                if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>220) && (mousey<260))
89c4a3a6 sago007 2008-08-29 14:32 5012
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 5013
                                                                                                                    MusicEnabled = !MusicEnabled;
89c4a3a6 sago007 2008-08-29 14:32 5014
                                                                                                                    if (!MusicEnabled) Mix_FadeOutMusic(500);
89c4a3a6 sago007 2008-08-29 14:32 5015
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 5016
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>270) && (mousey<310))
89c4a3a6 sago007 2008-08-29 14:32 5017
                    {
89c4a3a6 sago007 2008-08-29 14:32 5018
                        SoundEnabled = !SoundEnabled;
89c4a3a6 sago007 2008-08-29 14:32 5019
                    }
89c4a3a6 sago007 2008-08-29 14:32 5020
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>320) && (mousey<360))
89c4a3a6 sago007 2008-08-29 14:32 5021
                    {
89c4a3a6 sago007 2008-08-29 14:32 5022
                        //Fullscreen
89c4a3a6 sago007 2008-08-29 14:32 5023
                        bFullscreen = !bFullscreen;
89c4a3a6 sago007 2008-08-29 14:32 5024
#if defined(WIN32)
89c4a3a6 sago007 2008-08-29 14:32 5025
                        if (bFullscreen) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 5026
                        else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 5027
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 5028
#else
89c4a3a6 sago007 2008-08-29 14:32 5029
                        SDL_WM_ToggleFullScreen(screen); //Will only work in Linux
89c4a3a6 sago007 2008-08-29 14:32 5030
#endif
89c4a3a6 sago007 2008-08-29 14:32 5031
                        SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 5032
                    }
89c4a3a6 sago007 2008-08-29 14:32 5033
89c4a3a6 sago007 2008-08-29 14:32 5034
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 5035
                    {
89c4a3a6 sago007 2008-08-29 14:32 5036
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 5037
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 5038
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 5039
                        strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 5040
                        if (OpenDialogbox(200,100,player1name))
89c4a3a6 sago007 2008-08-29 14:32 5041
                            strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 5042
                        else
89c4a3a6 sago007 2008-08-29 14:32 5043
                            strcpy(player1name,theGame.name);
89c4a3a6 sago007 2008-08-29 14:32 5044
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 5045
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 5046
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 5047
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 5048
                    }
89c4a3a6 sago007 2008-08-29 14:32 5049
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 5050
                    {
89c4a3a6 sago007 2008-08-29 14:32 5051
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 5052
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 5053
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 5054
                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 5055
                        if (OpenDialogbox(200,100,player2name))
89c4a3a6 sago007 2008-08-29 14:32 5056
                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 5057
                        else
89c4a3a6 sago007 2008-08-29 14:32 5058
                            strcpy(player2name,theGame2.name);
89c4a3a6 sago007 2008-08-29 14:32 5059
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 5060
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 5061
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 5062
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 5063
                    }
89c4a3a6 sago007 2008-08-29 14:32 5064
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 5065
                    {
89c4a3a6 sago007 2008-08-29 14:32 5066
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 5067
                        OpenControlsBox(200,100,0);
e1290bdf sago007 2010-10-25 19:56 5068
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 5069
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 5070
                    }
89c4a3a6 sago007 2008-08-29 14:32 5071
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 5072
                    {
89c4a3a6 sago007 2008-08-29 14:32 5073
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 5074
                        OpenControlsBox(200,100,2);
e1290bdf sago007 2010-10-25 19:56 5075
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 5076
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 5077
                    }
89c4a3a6 sago007 2008-08-29 14:32 5078
89c4a3a6 sago007 2008-08-29 14:32 5079
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 5080
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 5081
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 5082
                    if ((!showOptions))
89c4a3a6 sago007 2008-08-29 14:32 5083
                    {
e1290bdf sago007 2010-10-25 19:56 5084
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 5085
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 5086
                            {
89c4a3a6 sago007 2008-08-29 14:32 5087
                                theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 5088
                            }
e1290bdf sago007 2010-10-25 19:56 5089
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 5090
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 5091
                            {
89c4a3a6 sago007 2008-08-29 14:32 5092
                                theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 5093
                            }
89c4a3a6 sago007 2008-08-29 14:32 5094
                    }
89c4a3a6 sago007 2008-08-29 14:32 5095
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 5096
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 5097
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 5098
e1290bdf sago007 2010-10-25 19:56 5099
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
e1290bdf sago007 2010-10-25 19:56 5100
                            &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
e1290bdf sago007 2010-10-25 19:56 5101
                            &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 5102
                    {
89c4a3a6 sago007 2008-08-29 14:32 5103
                        //Clicked the next button after a stage clear or puzzle
e1290bdf sago007 2010-10-25 19:56 5104
                        theGame.nextLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 5105
                    }
e1290bdf sago007 2010-10-25 19:56 5106
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
e1290bdf sago007 2010-10-25 19:56 5107
                            &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
e1290bdf sago007 2010-10-25 19:56 5108
                            &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 5109
                    {
89c4a3a6 sago007 2008-08-29 14:32 5110
                        //Clicked the retry button
e1290bdf sago007 2010-10-25 19:56 5111
                        theGame.retryLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 5112
                    }
89c4a3a6 sago007 2008-08-29 14:32 5113
                        
89c4a3a6 sago007 2008-08-29 14:32 5114
                    
89c4a3a6 sago007 2008-08-29 14:32 5115
                    //cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
89c4a3a6 sago007 2008-08-29 14:32 5116
                }
89c4a3a6 sago007 2008-08-29 14:32 5117
89c4a3a6 sago007 2008-08-29 14:32 5118
                //Mouse button 2:
89c4a3a6 sago007 2008-08-29 14:32 5119
                if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2)
89c4a3a6 sago007 2008-08-29 14:32 5120
                {
89c4a3a6 sago007 2008-08-29 14:32 5121
                    bMouseUp2=false; //The button is pressed
89c4a3a6 sago007 2008-08-29 14:32 5122
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 5123
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 5124
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 5125
                    if (!showOptions)
89c4a3a6 sago007 2008-08-29 14:32 5126
                    {
e1290bdf sago007 2010-10-25 19:56 5127
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 5128
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 5129
                            {
89c4a3a6 sago007 2008-08-29 14:32 5130
                                theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 5131
                            }
e1290bdf sago007 2010-10-25 19:56 5132
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 5133
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 5134
                            {
89c4a3a6 sago007 2008-08-29 14:32 5135
                                theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 5136
                            }
89c4a3a6 sago007 2008-08-29 14:32 5137
                    }
89c4a3a6 sago007 2008-08-29 14:32 5138
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 5139
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 5140
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 5141
                }
89c4a3a6 sago007 2008-08-29 14:32 5142
            } //if !singlePuzzle
89c4a3a6 sago007 2008-08-29 14:32 5143
            else
89c4a3a6 sago007 2008-08-29 14:32 5144
            {
89c4a3a6 sago007 2008-08-29 14:32 5145
89c4a3a6 sago007 2008-08-29 14:32 5146
            }
89c4a3a6 sago007 2008-08-29 14:32 5147
        } //if !bScreenBocked;
89c4a3a6 sago007 2008-08-29 14:32 5148
89c4a3a6 sago007 2008-08-29 14:32 5149
89c4a3a6 sago007 2008-08-29 14:32 5150
        //Sees if music is stopped and if music is enabled
6d48320c sago007 2009-03-28 17:06 5151
        if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath))
89c4a3a6 sago007 2008-08-29 14:32 5152
        {
89c4a3a6 sago007 2008-08-29 14:32 5153
            // then starts playing it.
6d48320c sago007 2009-03-28 17:06 5154
            Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 5155
            Mix_PlayMusic(bgMusic, -1); //music loop
89c4a3a6 sago007 2008-08-29 14:32 5156
        }
89c4a3a6 sago007 2008-08-29 14:32 5157
6d48320c sago007 2009-03-28 17:06 5158
        if(bNearDeath!=bNearDeathPrev)
6d48320c sago007 2009-03-28 17:06 5159
        {
6d48320c sago007 2009-03-28 17:06 5160
            if(bNearDeath)
6d48320c sago007 2009-03-28 17:06 5161
            {
6d48320c sago007 2009-03-28 17:06 5162
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 5163
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 5164
                    Mix_PlayMusic(highbeatMusic, 1);
6d48320c sago007 2009-03-28 17:06 5165
                }
6d48320c sago007 2009-03-28 17:06 5166
            }
6d48320c sago007 2009-03-28 17:06 5167
            else
6d48320c sago007 2009-03-28 17:06 5168
            {
6d48320c sago007 2009-03-28 17:06 5169
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 5170
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 5171
                    Mix_PlayMusic(bgMusic, -1);
6d48320c sago007 2009-03-28 17:06 5172
                }
6d48320c sago007 2009-03-28 17:06 5173
            }
6d48320c sago007 2009-03-28 17:06 5174
        }
6d48320c sago007 2009-03-28 17:06 5175
6d48320c sago007 2009-03-28 17:06 5176
        bNearDeathPrev = bNearDeath;
6d48320c sago007 2009-03-28 17:06 5177
6d48320c sago007 2009-03-28 17:06 5178
6d48320c sago007 2009-03-28 17:06 5179
        //set bNearDeath to false theGame*.Update() will change to true as needed
6d48320c sago007 2009-03-28 17:06 5180
        bNearDeath = false;
89c4a3a6 sago007 2008-08-29 14:32 5181
        //Updates the objects
e1290bdf sago007 2010-10-25 19:56 5182
        theGame.Update(SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 5183
        theGame2.Update(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 5184
89c4a3a6 sago007 2008-08-29 14:32 5185
//see if anyone has won (two players only)
2f30c381 sago007 2008-09-14 13:08 5186
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 5187
        if (!networkPlay)
2f30c381 sago007 2008-09-14 13:08 5188
        #endif
89c4a3a6 sago007 2008-08-29 14:32 5189
            if (twoPlayers)
89c4a3a6 sago007 2008-08-29 14:32 5190
            {
89c4a3a6 sago007 2008-08-29 14:32 5191
                lastNrOfPlayers = 2;
e1290bdf sago007 2010-10-25 19:56 5192
                if ((theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 5193
                {
e1290bdf sago007 2010-10-25 19:56 5194
                    if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 5195
                        theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 5196
                    else
e1290bdf sago007 2010-10-25 19:56 5197
                        if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 5198
                            theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 5199
                        else {
89c4a3a6 sago007 2008-08-29 14:32 5200
                            theGame.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 5201
                            theGame2.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 5202
                        }
89c4a3a6 sago007 2008-08-29 14:32 5203
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 5204
                }
e1290bdf sago007 2010-10-25 19:56 5205
                if ((theGame.isGameOver()) && (!theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 5206
                {
89c4a3a6 sago007 2008-08-29 14:32 5207
                    theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 5208
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 5209
                }
e1290bdf sago007 2010-10-25 19:56 5210
                if ((!theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 5211
                {
89c4a3a6 sago007 2008-08-29 14:32 5212
                    theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 5213
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 5214
                }
89c4a3a6 sago007 2008-08-29 14:32 5215
            }
89c4a3a6 sago007 2008-08-29 14:32 5216
89c4a3a6 sago007 2008-08-29 14:32 5217
        //Once evrything has been checked, update graphics
e1290bdf sago007 2010-10-25 19:56 5218
        DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 5219
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 5220
        //Remember mouse placement
89c4a3a6 sago007 2008-08-29 14:32 5221
        oldMousex = mousex;
89c4a3a6 sago007 2008-08-29 14:32 5222
        oldMousey = mousey;
89c4a3a6 sago007 2008-08-29 14:32 5223
        //Draw the mouse:
89c4a3a6 sago007 2008-08-29 14:32 5224
        DrawIMG(mouse,screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 5225
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 5226
    } //game loop
89c4a3a6 sago007 2008-08-29 14:32 5227
89c4a3a6 sago007 2008-08-29 14:32 5228
89c4a3a6 sago007 2008-08-29 14:32 5229
89c4a3a6 sago007 2008-08-29 14:32 5230
    //Saves options
89c4a3a6 sago007 2008-08-29 14:32 5231
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 5232
    {
769a41a0 sago007 2008-09-24 12:54 5233
        configSettings->setInt("fullscreen",(int)bFullscreen);
769a41a0 sago007 2008-09-24 12:54 5234
        configSettings->setInt("musicenabled",(int)MusicEnabled);
769a41a0 sago007 2008-09-24 12:54 5235
        configSettings->setInt("soundenabled",(int)SoundEnabled);
769a41a0 sago007 2008-09-24 12:54 5236
        configSettings->setInt("mouseplay1",(int)mouseplay1);
769a41a0 sago007 2008-09-24 12:54 5237
        configSettings->setInt("mouseplay2",(int)mouseplay2);
769a41a0 sago007 2008-09-24 12:54 5238
        configSettings->setInt("joypad1",(int)joyplay1);
769a41a0 sago007 2008-09-24 12:54 5239
        configSettings->setInt("joypad2",(int)joyplay2);
769a41a0 sago007 2008-09-24 12:54 5240
        
769a41a0 sago007 2008-09-24 12:54 5241
        configSettings->setInt("player1keyup",(int)keySettings[0].up);
769a41a0 sago007 2008-09-24 12:54 5242
        configSettings->setInt("player1keydown",(int)keySettings[0].down);
769a41a0 sago007 2008-09-24 12:54 5243
        configSettings->setInt("player1keyleft",(int)keySettings[0].left);
769a41a0 sago007 2008-09-24 12:54 5244
        configSettings->setInt("player1keyright",(int)keySettings[0].right);
769a41a0 sago007 2008-09-24 12:54 5245
        configSettings->setInt("player1keychange",(int)keySettings[0].change);
769a41a0 sago007 2008-09-24 12:54 5246
        configSettings->setInt("player1keypush",(int)keySettings[0].push);
769a41a0 sago007 2008-09-24 12:54 5247
        
769a41a0 sago007 2008-09-24 12:54 5248
        configSettings->setInt("player2keyup",(int)keySettings[2].up);
769a41a0 sago007 2008-09-24 12:54 5249
        configSettings->setInt("player2keydown",(int)keySettings[2].down);
769a41a0 sago007 2008-09-24 12:54 5250
        configSettings->setInt("player2keyleft",(int)keySettings[2].left);
769a41a0 sago007 2008-09-24 12:54 5251
        configSettings->setInt("player2keyright",(int)keySettings[2].right);
769a41a0 sago007 2008-09-24 12:54 5252
        configSettings->setInt("player2keychange",(int)keySettings[2].change);
769a41a0 sago007 2008-09-24 12:54 5253
        configSettings->setInt("player2keypush",(int)keySettings[2].push);
769a41a0 sago007 2008-09-24 12:54 5254
        
769a41a0 sago007 2008-09-24 12:54 5255
        configSettings->setString("player1name",player1name);
769a41a0 sago007 2008-09-24 12:54 5256
        configSettings->setString("player2name",player2name);
769a41a0 sago007 2008-09-24 12:54 5257
        configSettings->save();
89c4a3a6 sago007 2008-08-29 14:32 5258
    }
89c4a3a6 sago007 2008-08-29 14:32 5259
89c4a3a6 sago007 2008-08-29 14:32 5260
    //calculate uptime:
c09d0e4f sago007 2009-01-27 01:15 5261
    //int hours, mins, secs,
cd12e0fe sago007 2009-01-29 08:47 5262
    commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 5263
89c4a3a6 sago007 2008-08-29 14:32 5264
    cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
c09d0e4f sago007 2009-01-27 01:15 5265
cd12e0fe sago007 2009-01-29 08:47 5266
    ct = TimeHandler::addTime("totalTime",ct);
c09d0e4f sago007 2009-01-27 01:15 5267
89c4a3a6 sago007 2008-08-29 14:32 5268
    cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
c09d0e4f sago007 2009-01-27 01:15 5269
c09d0e4f sago007 2009-01-27 01:15 5270
    Stats::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 5271
c09d0e4f sago007 2009-01-27 01:15 5272
    Config::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 5273
    
c09d0e4f sago007 2009-01-27 01:15 5274
    //Frees memory from music and fonts
c09d0e4f sago007 2009-01-27 01:15 5275
    //This is done after writing of configurations and stats since it often crashes the program :(
c09d0e4f sago007 2009-01-27 01:15 5276
    UnloadImages();
41f02ab2 sago007 2009-05-10 21:40 5277
      
91886cae sago007 2008-09-12 16:28 5278
    //Close file system Apstraction layer!
91886cae sago007 2008-09-12 16:28 5279
    PHYSFS_deinit();
89c4a3a6 sago007 2008-08-29 14:32 5280
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 5281
}
1970-01-01 00:00 5282