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
*/
89c4a3a6 sago007 2008-08-29 14:32 20
215ca7b3 sago007 2009-03-06 16:37 21
#include "common.h"
26ddb424 sago007 2011-06-09 20:06 22
#include "global.hpp"
215ca7b3 sago007 2009-03-06 16:37 23
27ae0175 sago007 2009-01-30 06:02 24
#include <string.h>
27ae0175 sago007 2009-01-30 06:02 25
27ae0175 sago007 2009-01-30 06:02 26
1572de2b sago007 2008-09-11 18:15 27
#ifndef VERSION_NUMBER
e2de69cf sago007 2010-01-15 22:48 28
    #define VERSION_NUMBER "version 1.4.2 BETA"
1572de2b sago007 2008-09-11 18:15 29
#endif
89c4a3a6 sago007 2008-08-29 14:32 30
89c4a3a6 sago007 2008-08-29 14:32 31
//If DEBUG is defined: AI info and FPS will be written to screen
1572de2b sago007 2008-09-11 18:15 32
#ifndef DEBUG
2f30c381 sago007 2008-09-14 13:08 33
    #define DEBUG 0
1572de2b sago007 2008-09-11 18:15 34
#endif
89c4a3a6 sago007 2008-08-29 14:32 35
89c4a3a6 sago007 2008-08-29 14:32 36
//If NETWORK id defined: enet will be used
1572de2b sago007 2008-09-11 18:15 37
#ifndef NETWORK
1572de2b sago007 2008-09-11 18:15 38
    #define NETWORK 1
1572de2b sago007 2008-09-11 18:15 39
#endif
1572de2b sago007 2008-09-11 18:15 40
1572de2b sago007 2008-09-11 18:15 41
//Build-in level editor is still experimental!
1572de2b sago007 2008-09-11 18:15 42
#ifndef LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 43
    #define LEVELEDITOR 0
1572de2b sago007 2008-09-11 18:15 44
#endif
89c4a3a6 sago007 2008-08-29 14:32 45
2e57d791 sago007 2009-06-04 17:48 46
#define WITH_SDL 1
2e57d791 sago007 2009-06-04 17:48 47
aca2f4b0 sago007 2009-05-10 18:11 48
//Macros to convert surfaces (ffor faster drawing)
89c4a3a6 sago007 2008-08-29 14:32 49
#define CONVERT(n) tmp = SDL_DisplayFormat(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 50
#define CONVERTA(n) tmp = SDL_DisplayFormatAlpha(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 51
89c4a3a6 sago007 2008-08-29 14:32 52
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 53
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 54
#include <time.h>           //Used for srand()
769a41a0 sago007 2008-09-24 12:54 55
#include <sstream>          //Still used by itoa2
89c4a3a6 sago007 2008-08-29 14:32 56
#include <string>
89c4a3a6 sago007 2008-08-29 14:32 57
#include "SDL.h"            //The SDL libary, used for most things
89c4a3a6 sago007 2008-08-29 14:32 58
#include <SDL_mixer.h>      //Used for sound & music
89c4a3a6 sago007 2008-08-29 14:32 59
#include <SDL_image.h>      //To load PNG images!
41f02ab2 sago007 2009-05-10 21:40 60
#include <physfs.h>         //Abstract file system. To use containers
41f02ab2 sago007 2009-05-10 21:40 61
#include "physfs_stream.hpp" //To use C++ style file streams
925b7e58 sago007 2011-04-25 16:35 62
#include "Libs/NFont.h"
47529580 sago007 2008-12-09 02:34 63
//#include "ttfont.h"        //To use True Type Fonts in SDL
89c4a3a6 sago007 2008-08-29 14:32 64
//#include "config.h"
89c4a3a6 sago007 2008-08-29 14:32 65
#include <vector>
95bc02ff sago007 2009-03-15 02:46 66
#include <SDL/SDL_timer.h>
925b7e58 sago007 2011-04-25 16:35 67
#include <SDL/SDL_video.h>
925b7e58 sago007 2011-04-25 16:35 68
#include <SDL/SDL_ttf.h>
605138b3 sago007 2012-04-14 15:12 69
#include "CppSdlImageHolder.hpp"
b7590374 sago007 2011-05-19 16:15 70
#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 71
89c4a3a6 sago007 2008-08-29 14:32 72
//if SHAREDIR is not used we look in current directory
89c4a3a6 sago007 2008-08-29 14:32 73
#ifndef SHAREDIR
89c4a3a6 sago007 2008-08-29 14:32 74
#define SHAREDIR "."
89c4a3a6 sago007 2008-08-29 14:32 75
#endif
89c4a3a6 sago007 2008-08-29 14:32 76
c9dd376f sago007 2012-01-20 17:13 77
#ifndef LOCALEDIR
c9dd376f sago007 2012-01-20 17:13 78
#define LOCALEDIR SHAREDIR"/locale"
c9dd376f sago007 2012-01-20 17:13 79
#endif
89c4a3a6 sago007 2008-08-29 14:32 80
c9dd376f sago007 2012-01-20 17:13 81
#ifndef PACKAGE
c9dd376f sago007 2012-01-20 17:13 82
#define PACKAGE "blockattack_roftb"
c9dd376f sago007 2012-01-20 17:13 83
#endif
89c4a3a6 sago007 2008-08-29 14:32 84
89c4a3a6 sago007 2008-08-29 14:32 85
//enet things
1572de2b sago007 2008-09-11 18:15 86
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 87
#include "enet/enet.h"
89c4a3a6 sago007 2008-08-29 14:32 88
#endif
89c4a3a6 sago007 2008-08-29 14:32 89
//enet things end
89c4a3a6 sago007 2008-08-29 14:32 90
925b7e58 sago007 2011-04-25 16:35 91
//#include "SFont.h"          //Used to write on screen
89c4a3a6 sago007 2008-08-29 14:32 92
#include "highscore.h"      //Stores highscores
89c4a3a6 sago007 2008-08-29 14:32 93
#include "ReadKeyboard.h"   //Reads text from keyboard
89c4a3a6 sago007 2008-08-29 14:32 94
#include "joypad.h"         //Used for joypads
89c4a3a6 sago007 2008-08-29 14:32 95
#include "listFiles.h"	    //Used to show files on screen
89c4a3a6 sago007 2008-08-29 14:32 96
#include "replay.h"			//Used for replays
89c4a3a6 sago007 2008-08-29 14:32 97
#include "stats.h"          //Saves general stats 
1572de2b sago007 2008-09-11 18:15 98
#if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 99
#include "editor/editorMain.hpp" //The level editor
1572de2b sago007 2008-09-11 18:15 100
#endif
bc9ea011 sago007 2009-04-12 17:43 101
//#include "uploadReplay.h"   //Takes care of everything libcurl related
89c4a3a6 sago007 2008-08-29 14:32 102
89c4a3a6 sago007 2008-08-29 14:32 103
#include "common.h"
89c4a3a6 sago007 2008-08-29 14:32 104
89c4a3a6 sago007 2008-08-29 14:32 105
/*******************************************************************************
89c4a3a6 sago007 2008-08-29 14:32 106
* All variables and constant has been moved to mainVars.hpp for the overview.  *
89c4a3a6 sago007 2008-08-29 14:32 107
*******************************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 108
#include "mainVars.hpp"
89c4a3a6 sago007 2008-08-29 14:32 109
4b0c248f sago007 2010-11-10 21:13 110
static void MakeBackground(int,int);
89c4a3a6 sago007 2008-08-29 14:32 111
89c4a3a6 sago007 2008-08-29 14:32 112
void closeAllMenus()
89c4a3a6 sago007 2008-08-29 14:32 113
{
89c4a3a6 sago007 2008-08-29 14:32 114
    bNewGameOpen=false;          //show sub menues
89c4a3a6 sago007 2008-08-29 14:32 115
    bOptionsOpen=false;          //Show OptionsMenu (Configure and Select Puzzle)
89c4a3a6 sago007 2008-08-29 14:32 116
    b1playerOpen=false;			//show submenu
89c4a3a6 sago007 2008-08-29 14:32 117
    b2playersOpen=false;
89c4a3a6 sago007 2008-08-29 14:32 118
    bReplayOpen = false;
1572de2b sago007 2008-09-11 18:15 119
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 120
    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 121
#endif
89c4a3a6 sago007 2008-08-29 14:32 122
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 123
89c4a3a6 sago007 2008-08-29 14:32 124
}
89c4a3a6 sago007 2008-08-29 14:32 125
1f61db96 sago007 2010-11-15 20:12 126
SDL_Surface * IMG_Load2(string path)
64ea862c sago007 2009-05-05 02:45 127
{
1f61db96 sago007 2010-11-15 20:12 128
    if (!PHYSFS_exists(path.c_str()))
64ea862c sago007 2009-05-05 02:45 129
    {
64ea862c sago007 2009-05-05 02:45 130
        cout << "File not in blockattack.data: " << path << endl;
64ea862c sago007 2009-05-05 02:45 131
        return NULL; //file doesn't exist
64ea862c sago007 2009-05-05 02:45 132
    }
64ea862c sago007 2009-05-05 02:45 133
1f61db96 sago007 2010-11-15 20:12 134
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
64ea862c sago007 2009-05-05 02:45 135
64ea862c sago007 2009-05-05 02:45 136
    // Get the lenght of the file
64ea862c sago007 2009-05-05 02:45 137
    unsigned int m_size = PHYSFS_fileLength(myfile);
64ea862c sago007 2009-05-05 02:45 138
64ea862c sago007 2009-05-05 02:45 139
    // Get the file data.
64ea862c sago007 2009-05-05 02:45 140
    char *m_data = new char[m_size];
64ea862c sago007 2009-05-05 02:45 141
64ea862c sago007 2009-05-05 02:45 142
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
64ea862c sago007 2009-05-05 02:45 143
64ea862c sago007 2009-05-05 02:45 144
    if (length_read != (int)m_size)
64ea862c sago007 2009-05-05 02:45 145
    {
64ea862c sago007 2009-05-05 02:45 146
            delete [] m_data;
64ea862c sago007 2009-05-05 02:45 147
            m_data = 0;
64ea862c sago007 2009-05-05 02:45 148
            PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 149
            cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 150
            return NULL;
64ea862c sago007 2009-05-05 02:45 151
    }
89c4a3a6 sago007 2008-08-29 14:32 152
64ea862c sago007 2009-05-05 02:45 153
    PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 154
64ea862c sago007 2009-05-05 02:45 155
// And this is how you load an image from a memory buffer with SDL
64ea862c sago007 2009-05-05 02:45 156
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
64ea862c sago007 2009-05-05 02:45 157
64ea862c sago007 2009-05-05 02:45 158
    //The above might fail an return null.
64ea862c sago007 2009-05-05 02:45 159
    if(!rw)
64ea862c sago007 2009-05-05 02:45 160
    {
64ea862c sago007 2009-05-05 02:45 161
        delete [] m_data;
64ea862c sago007 2009-05-05 02:45 162
        m_data = 0;
64ea862c sago007 2009-05-05 02:45 163
        PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 164
        cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 165
        return NULL;
64ea862c sago007 2009-05-05 02:45 166
    }
64ea862c sago007 2009-05-05 02:45 167
adaf31bf sago007 2009-05-05 16:01 168
    SDL_Surface* surface = IMG_Load_RW(rw,true); //the second argument tells the function to three RWops
64ea862c sago007 2009-05-05 02:45 169
64ea862c sago007 2009-05-05 02:45 170
    return surface;
64ea862c sago007 2009-05-05 02:45 171
}
89c4a3a6 sago007 2008-08-29 14:32 172
8d488d32 sago007 2011-04-17 13:02 173
CppSdl::CppSdlImageHolder IMG_Load3(string path)
8d488d32 sago007 2011-04-17 13:02 174
{
8d488d32 sago007 2011-04-17 13:02 175
    if (!PHYSFS_exists(path.c_str()))
8d488d32 sago007 2011-04-17 13:02 176
    {
8d488d32 sago007 2011-04-17 13:02 177
        cout << "File not in blockattack.data: " << path << endl;
8d488d32 sago007 2011-04-17 13:02 178
        throw exception();
8d488d32 sago007 2011-04-17 13:02 179
    }
8d488d32 sago007 2011-04-17 13:02 180
8d488d32 sago007 2011-04-17 13:02 181
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
8d488d32 sago007 2011-04-17 13:02 182
8d488d32 sago007 2011-04-17 13:02 183
    // Get the lenght of the file
8d488d32 sago007 2011-04-17 13:02 184
    unsigned int m_size = PHYSFS_fileLength(myfile);
8d488d32 sago007 2011-04-17 13:02 185
8d488d32 sago007 2011-04-17 13:02 186
    // Get the file data.
8d488d32 sago007 2011-04-17 13:02 187
    char *m_data = new char[m_size];
8d488d32 sago007 2011-04-17 13:02 188
8d488d32 sago007 2011-04-17 13:02 189
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
8d488d32 sago007 2011-04-17 13:02 190
8d488d32 sago007 2011-04-17 13:02 191
    if (length_read != (int)m_size)
8d488d32 sago007 2011-04-17 13:02 192
    {
8d488d32 sago007 2011-04-17 13:02 193
            delete [] m_data;
8d488d32 sago007 2011-04-17 13:02 194
            m_data = 0;
8d488d32 sago007 2011-04-17 13:02 195
            PHYSFS_close(myfile);
8d488d32 sago007 2011-04-17 13:02 196
            cout << "Error. Curropt data file!" << endl;
8d488d32 sago007 2011-04-17 13:02 197
            throw exception();
8d488d32 sago007 2011-04-17 13:02 198
    }
8d488d32 sago007 2011-04-17 13:02 199
8d488d32 sago007 2011-04-17 13:02 200
    PHYSFS_close(myfile);
8d488d32 sago007 2011-04-17 13:02 201
8d488d32 sago007 2011-04-17 13:02 202
    CppSdl::CppSdlImageHolder surface(m_data, m_size);
8d488d32 sago007 2011-04-17 13:02 203
8d488d32 sago007 2011-04-17 13:02 204
    return surface;
8d488d32 sago007 2011-04-17 13:02 205
}
8d488d32 sago007 2011-04-17 13:02 206
4b0c248f sago007 2010-11-10 21:13 207
static void UnloadImages();
4b0c248f sago007 2010-11-10 21:13 208
static int InitImages();
866417ca sago007 2009-05-10 21:35 209
866417ca sago007 2009-05-10 21:35 210
static string oldThemePath = "default";
41f02ab2 sago007 2009-05-10 21:40 211
static bool loaded = false;
89c4a3a6 sago007 2008-08-29 14:32 212
89c4a3a6 sago007 2008-08-29 14:32 213
void loadTheme(string themeName)
89c4a3a6 sago007 2008-08-29 14:32 214
{
41f02ab2 sago007 2009-05-10 21:40 215
    if(loaded)
866417ca sago007 2009-05-10 21:35 216
        UnloadImages();
866417ca sago007 2009-05-10 21:35 217
#if defined(__unix__)
866417ca sago007 2009-05-10 21:35 218
    string home = (string)getenv("HOME")+(string)"/.gamesaves/blockattack";
866417ca sago007 2009-05-10 21:35 219
#elif defined(_WIN32)
866417ca sago007 2009-05-10 21:35 220
    string home = (string)getMyDocumentsPath()+(string)"/My Games/blockattack";
89c4a3a6 sago007 2008-08-29 14:32 221
#endif
866417ca sago007 2009-05-10 21:35 222
    //Remove old theme
866417ca sago007 2009-05-10 21:35 223
    PHYSFS_removeFromSearchPath(oldThemePath.c_str());
866417ca sago007 2009-05-10 21:35 224
    //Look in blockattack.data
866417ca sago007 2009-05-10 21:35 225
    PHYSFS_addToSearchPath(((string)SHAREDIR+"/blockattack.data").c_str(), 1);
866417ca sago007 2009-05-10 21:35 226
    //Look in folder
866417ca sago007 2009-05-10 21:35 227
    PHYSFS_addToSearchPath(SHAREDIR, 1);
866417ca sago007 2009-05-10 21:35 228
    //Look in home folder
866417ca sago007 2009-05-10 21:35 229
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 230
    PHYSFS_addToSearchPath(home.c_str(), 1);
866417ca sago007 2009-05-10 21:35 231
    #endif
2e57d791 sago007 2009-06-04 17:48 232
    if(themeName.compare(Config::getInstance()->getString("themename"))!=0)
2e57d791 sago007 2009-06-04 17:48 233
    {
2e57d791 sago007 2009-06-04 17:48 234
        //If this is a theme different from the saved one. Remember it!
2e57d791 sago007 2009-06-04 17:48 235
        Config::getInstance()->setString("themename",themeName);
2e57d791 sago007 2009-06-04 17:48 236
    }
866417ca sago007 2009-05-10 21:35 237
    if(themeName.compare("default")==0 || (themeName.compare("start")==0))
89c4a3a6 sago007 2008-08-29 14:32 238
    {
866417ca sago007 2009-05-10 21:35 239
        InitImages();
41f02ab2 sago007 2009-05-10 21:40 240
        loaded =true;
866417ca sago007 2009-05-10 21:35 241
        return; //Nothing more to do
89c4a3a6 sago007 2008-08-29 14:32 242
    }
866417ca sago007 2009-05-10 21:35 243
    oldThemePath = "themes/"+themeName;
866417ca sago007 2009-05-10 21:35 244
    PHYSFS_addToSearchPath(oldThemePath.c_str(),0);
866417ca sago007 2009-05-10 21:35 245
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 246
    PHYSFS_addToSearchPath((home+(string)"/"+oldThemePath).c_str(), 0);
89c4a3a6 sago007 2008-08-29 14:32 247
    #endif
866417ca sago007 2009-05-10 21:35 248
    InitImages();
41f02ab2 sago007 2009-05-10 21:40 249
    loaded = true;
89c4a3a6 sago007 2008-08-29 14:32 250
}
89c4a3a6 sago007 2008-08-29 14:32 251
89c4a3a6 sago007 2008-08-29 14:32 252
925b7e58 sago007 2011-04-25 16:35 253
long NFont_OpenFont(NFont *target, string path,int ptsize, SDL_Color color, int style=TTF_STYLE_NORMAL) {
925b7e58 sago007 2011-04-25 16:35 254
    if (!PHYSFS_exists(path.c_str()))
925b7e58 sago007 2011-04-25 16:35 255
    {
925b7e58 sago007 2011-04-25 16:35 256
        cout << "File not in blockattack.data: " << path << endl;
925b7e58 sago007 2011-04-25 16:35 257
        return -1; //file doesn't exist
925b7e58 sago007 2011-04-25 16:35 258
    }
925b7e58 sago007 2011-04-25 16:35 259
89c4a3a6 sago007 2008-08-29 14:32 260
    if(!(TTF_WasInit()))
89c4a3a6 sago007 2008-08-29 14:32 261
       TTF_Init();
925b7e58 sago007 2011-04-25 16:35 262
925b7e58 sago007 2011-04-25 16:35 263
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
925b7e58 sago007 2011-04-25 16:35 264
925b7e58 sago007 2011-04-25 16:35 265
    // Get the lenght of the file
925b7e58 sago007 2011-04-25 16:35 266
    unsigned int m_size = PHYSFS_fileLength(myfile);
925b7e58 sago007 2011-04-25 16:35 267
925b7e58 sago007 2011-04-25 16:35 268
    // Get the file data.
925b7e58 sago007 2011-04-25 16:35 269
    char *m_data = new char[m_size];
925b7e58 sago007 2011-04-25 16:35 270
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
925b7e58 sago007 2011-04-25 16:35 271
925b7e58 sago007 2011-04-25 16:35 272
    if (length_read != (int)m_size)
925b7e58 sago007 2011-04-25 16:35 273
    {
925b7e58 sago007 2011-04-25 16:35 274
            delete [] m_data;
925b7e58 sago007 2011-04-25 16:35 275
            m_data = 0;
925b7e58 sago007 2011-04-25 16:35 276
            PHYSFS_close(myfile);
925b7e58 sago007 2011-04-25 16:35 277
            cout << "Error. Curropt data file!" << endl;
593aeae4 sago007 2011-06-25 22:42 278
            return -3;
925b7e58 sago007 2011-04-25 16:35 279
    }
925b7e58 sago007 2011-04-25 16:35 280
925b7e58 sago007 2011-04-25 16:35 281
    PHYSFS_close(myfile);
925b7e58 sago007 2011-04-25 16:35 282
925b7e58 sago007 2011-04-25 16:35 283
// And this is how you load from a memory buffer with SDL
925b7e58 sago007 2011-04-25 16:35 284
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
925b7e58 sago007 2011-04-25 16:35 285
925b7e58 sago007 2011-04-25 16:35 286
    //The above might fail an return null.
925b7e58 sago007 2011-04-25 16:35 287
    if(!rw)
925b7e58 sago007 2011-04-25 16:35 288
    {
925b7e58 sago007 2011-04-25 16:35 289
        delete [] m_data;
925b7e58 sago007 2011-04-25 16:35 290
        m_data = 0;
925b7e58 sago007 2011-04-25 16:35 291
        PHYSFS_close(myfile);
925b7e58 sago007 2011-04-25 16:35 292
        cout << "Error. Curropt data file!" << endl;
925b7e58 sago007 2011-04-25 16:35 293
        return -2;
925b7e58 sago007 2011-04-25 16:35 294
    }
925b7e58 sago007 2011-04-25 16:35 295
925b7e58 sago007 2011-04-25 16:35 296
    TTF_Font *font;
925b7e58 sago007 2011-04-25 16:35 297
    font=TTF_OpenFontRW(rw, 1, ptsize);
925b7e58 sago007 2011-04-25 16:35 298
    TTF_SetFontStyle(font,style);
925b7e58 sago007 2011-04-25 16:35 299
925b7e58 sago007 2011-04-25 16:35 300
    target->load(font,color);
925b7e58 sago007 2011-04-25 16:35 301
925b7e58 sago007 2011-04-25 16:35 302
    TTF_CloseFont(font); //Once loaded we don't care anymore!
925b7e58 sago007 2011-04-25 16:35 303
925b7e58 sago007 2011-04-25 16:35 304
    return 0;
925b7e58 sago007 2011-04-25 16:35 305
}
89c4a3a6 sago007 2008-08-29 14:32 306
41f02ab2 sago007 2009-05-10 21:40 307
1f61db96 sago007 2010-11-15 20:12 308
Mix_Music * Mix_LoadMUS2(string path)
adaf31bf sago007 2009-05-05 16:01 309
{
1f61db96 sago007 2010-11-15 20:12 310
    if (!PHYSFS_exists(path.c_str()))
adaf31bf sago007 2009-05-05 16:01 311
    {
adaf31bf sago007 2009-05-05 16:01 312
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 313
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 314
    }
adaf31bf sago007 2009-05-05 16:01 315
1f61db96 sago007 2010-11-15 20:12 316
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
adaf31bf sago007 2009-05-05 16:01 317
adaf31bf sago007 2009-05-05 16:01 318
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 319
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 320
adaf31bf sago007 2009-05-05 16:01 321
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 322
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 323
adaf31bf sago007 2009-05-05 16:01 324
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 325
adaf31bf sago007 2009-05-05 16:01 326
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 327
    {
adaf31bf sago007 2009-05-05 16:01 328
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 329
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 330
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 331
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 332
            return NULL;
adaf31bf sago007 2009-05-05 16:01 333
    }
adaf31bf sago007 2009-05-05 16:01 334
adaf31bf sago007 2009-05-05 16:01 335
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 336
adaf31bf sago007 2009-05-05 16:01 337
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 338
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 339
adaf31bf sago007 2009-05-05 16:01 340
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 341
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 342
    {
adaf31bf sago007 2009-05-05 16:01 343
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 344
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 345
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 346
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 347
        return NULL;
adaf31bf sago007 2009-05-05 16:01 348
    }
adaf31bf sago007 2009-05-05 16:01 349
adaf31bf sago007 2009-05-05 16:01 350
    Mix_Music* ret = Mix_LoadMUS_RW(rw);
adaf31bf sago007 2009-05-05 16:01 351
adaf31bf sago007 2009-05-05 16:01 352
    return ret;
adaf31bf sago007 2009-05-05 16:01 353
}
89c4a3a6 sago007 2008-08-29 14:32 354
89c4a3a6 sago007 2008-08-29 14:32 355
adaf31bf sago007 2009-05-05 16:01 356
Mix_Chunk * Mix_LoadWAV2(char* path)
adaf31bf sago007 2009-05-05 16:01 357
{
adaf31bf sago007 2009-05-05 16:01 358
    if (!PHYSFS_exists(path))
adaf31bf sago007 2009-05-05 16:01 359
    {
adaf31bf sago007 2009-05-05 16:01 360
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 361
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 362
    }
adaf31bf sago007 2009-05-05 16:01 363
adaf31bf sago007 2009-05-05 16:01 364
    PHYSFS_file* myfile = PHYSFS_openRead(path);
adaf31bf sago007 2009-05-05 16:01 365
adaf31bf sago007 2009-05-05 16:01 366
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 367
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 368
adaf31bf sago007 2009-05-05 16:01 369
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 370
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 371
adaf31bf sago007 2009-05-05 16:01 372
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 373
adaf31bf sago007 2009-05-05 16:01 374
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 375
    {
adaf31bf sago007 2009-05-05 16:01 376
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 377
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 378
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 379
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 380
            return NULL;
adaf31bf sago007 2009-05-05 16:01 381
    }
adaf31bf sago007 2009-05-05 16:01 382
adaf31bf sago007 2009-05-05 16:01 383
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 384
adaf31bf sago007 2009-05-05 16:01 385
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 386
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 387
adaf31bf sago007 2009-05-05 16:01 388
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 389
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 390
    {
adaf31bf sago007 2009-05-05 16:01 391
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 392
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 393
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 394
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 395
        return NULL;
adaf31bf sago007 2009-05-05 16:01 396
    }
adaf31bf sago007 2009-05-05 16:01 397
adaf31bf sago007 2009-05-05 16:01 398
    Mix_Chunk* ret = Mix_LoadWAV_RW(rw,true); //the second argument tells the function to three RWops
adaf31bf sago007 2009-05-05 16:01 399
adaf31bf sago007 2009-05-05 16:01 400
    return ret;
adaf31bf sago007 2009-05-05 16:01 401
}
89c4a3a6 sago007 2008-08-29 14:32 402
89c4a3a6 sago007 2008-08-29 14:32 403
//Load all image files to memory
4b0c248f sago007 2010-11-10 21:13 404
static int InitImages()
89c4a3a6 sago007 2008-08-29 14:32 405
{
1f61db96 sago007 2010-11-15 20:12 406
    if (!((backgroundImage = IMG_Load2("gfx/background.png"))
1f61db96 sago007 2010-11-15 20:12 407
            && (background = IMG_Load2("gfx/blackBackGround.png"))
69d650b4 sago007 2011-07-20 15:24 408
//            && (b1player = IMG_Load2("gfx/bOnePlayer.png"))
69d650b4 sago007 2011-07-20 15:24 409
//            && (b2players = IMG_Load2("gfx/bTwoPlayers.png"))
69d650b4 sago007 2011-07-20 15:24 410
//            && (bVsMode = IMG_Load2("gfx/bVsGame.png"))
69d650b4 sago007 2011-07-20 15:24 411
//            && (bVsModeConfig = IMG_Load2("gfx/bVsGameConfig.png"))
69d650b4 sago007 2011-07-20 15:24 412
//            && (bPuzzle = IMG_Load2((char*)"gfx/bPuzzle.png"))
69d650b4 sago007 2011-07-20 15:24 413
//            && (bStageClear = IMG_Load2((char*)"gfx/bStageClear.png"))
69d650b4 sago007 2011-07-20 15:24 414
//            && (bTimeTrial = IMG_Load2((char*)"gfx/bTimeTrial.png"))
69d650b4 sago007 2011-07-20 15:24 415
            //&& (bEndless = IMG_Load2((char*)"gfx/bEndless.png"))
89c4a3a6 sago007 2008-08-29 14:32 416
            && (bOptions = IMG_Load2((char*)"gfx/bOptions.png"))
89c4a3a6 sago007 2008-08-29 14:32 417
            && (bConfigure = IMG_Load2((char*)"gfx/bConfigure.png"))
89c4a3a6 sago007 2008-08-29 14:32 418
            && (bSelectPuzzle = IMG_Load2((char*)"gfx/bSelectPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 419
            && (bHighScore = IMG_Load2((char*)"gfx/bHighScore.png"))
69d650b4 sago007 2011-07-20 15:24 420
//            && (bExit = IMG_Load2((char*)"gfx/bExit.png"))
89c4a3a6 sago007 2008-08-29 14:32 421
            && (bBack = IMG_Load2((char*)"gfx/bBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 422
            && (bForward = IMG_Load2((char*)"gfx/bForward.png"))
69d650b4 sago007 2011-07-20 15:24 423
//            && (bReplay = IMG_Load2((char*)"gfx/bReplays.png"))
69d650b4 sago007 2011-07-20 15:24 424
//            && (bSave = IMG_Load2((char*)"gfx/bSave.png"))
69d650b4 sago007 2011-07-20 15:24 425
//            && (bLoad = IMG_Load2((char*)"gfx/bLoad.png"))
69d650b4 sago007 2011-07-20 15:24 426
/*#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 427
            && (bNetwork = IMG_Load2((char*)"gfx/bNetwork.png"))
89c4a3a6 sago007 2008-08-29 14:32 428
            && (bHost = IMG_Load2((char*)"gfx/bHost.png"))
89c4a3a6 sago007 2008-08-29 14:32 429
            && (bConnect = IMG_Load2((char*)"gfx/bConnect.png"))
69d650b4 sago007 2011-07-20 15:24 430
#endif*/
89c4a3a6 sago007 2008-08-29 14:32 431
            && (blackLine = IMG_Load2((char*)"gfx/blackLine.png"))
89c4a3a6 sago007 2008-08-29 14:32 432
            && (stageBobble = IMG_Load2((char*)"gfx/iStageClearLimit.png"))
a039f5c4 sago007 2008-09-19 23:12 433
            && (bricks[0] = IMG_Load2((char*)"gfx/bricks/blue.png"))
a039f5c4 sago007 2008-09-19 23:12 434
            && (bricks[1] = IMG_Load2((char*)"gfx/bricks/green.png"))
a039f5c4 sago007 2008-09-19 23:12 435
            && (bricks[2] = IMG_Load2((char*)"gfx/bricks/purple.png"))
a039f5c4 sago007 2008-09-19 23:12 436
            && (bricks[3] = IMG_Load2((char*)"gfx/bricks/red.png"))
a039f5c4 sago007 2008-09-19 23:12 437
            && (bricks[4] = IMG_Load2((char*)"gfx/bricks/turkish.png"))
a039f5c4 sago007 2008-09-19 23:12 438
            && (bricks[5] = IMG_Load2((char*)"gfx/bricks/yellow.png"))
a039f5c4 sago007 2008-09-19 23:12 439
            && (bricks[6] = IMG_Load2((char*)"gfx/bricks/grey.png"))
89c4a3a6 sago007 2008-08-29 14:32 440
            && (crossover = IMG_Load2((char*)"gfx/crossover.png"))
89c4a3a6 sago007 2008-08-29 14:32 441
            && (balls[0] = IMG_Load2((char*)"gfx/balls/ballBlue.png"))
89c4a3a6 sago007 2008-08-29 14:32 442
            && (balls[1] = IMG_Load2((char*)"gfx/balls/ballGreen.png"))
89c4a3a6 sago007 2008-08-29 14:32 443
            && (balls[2] = IMG_Load2((char*)"gfx/balls/ballPurple.png"))
89c4a3a6 sago007 2008-08-29 14:32 444
            && (balls[3] = IMG_Load2((char*)"gfx/balls/ballRed.png"))
89c4a3a6 sago007 2008-08-29 14:32 445
            && (balls[4] = IMG_Load2((char*)"gfx/balls/ballTurkish.png"))
89c4a3a6 sago007 2008-08-29 14:32 446
            && (balls[5] = IMG_Load2((char*)"gfx/balls/ballYellow.png"))
89c4a3a6 sago007 2008-08-29 14:32 447
            && (balls[6] = IMG_Load2((char*)"gfx/balls/ballGray.png"))
89c4a3a6 sago007 2008-08-29 14:32 448
            && (cursor[0] = IMG_Load2((char*)"gfx/animations/cursor/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 449
            && (cursor[1] = IMG_Load2((char*)"gfx/animations/cursor/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 450
            && (bomb[0] = IMG_Load2((char*)"gfx/animations/bomb/bomb_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 451
            && (bomb[1] = IMG_Load2((char*)"gfx/animations/bomb/bomb_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 452
            && (ready[0] = IMG_Load2((char*)"gfx/animations/ready/ready_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 453
            && (ready[1] = IMG_Load2((char*)"gfx/animations/ready/ready_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 454
            && (explosion[0] = IMG_Load2((char*)"gfx/animations/explosion/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 455
            && (explosion[1] = IMG_Load2((char*)"gfx/animations/explosion/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 456
            && (explosion[2] = IMG_Load2((char*)"gfx/animations/explosion/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 457
            && (explosion[3] = IMG_Load2((char*)"gfx/animations/explosion/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 458
            && (counter[0] = IMG_Load2((char*)"gfx/counter/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 459
            && (counter[1] = IMG_Load2((char*)"gfx/counter/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 460
            && (counter[2] = IMG_Load2((char*)"gfx/counter/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 461
            && (backBoard = IMG_Load2((char*)"gfx/BackBoard.png")) //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 462
            && (iGameOver = IMG_Load2((char*)"gfx/iGameOver.png"))
89c4a3a6 sago007 2008-08-29 14:32 463
            && (iWinner = IMG_Load2((char*)"gfx/iWinner.png"))
89c4a3a6 sago007 2008-08-29 14:32 464
            && (iDraw = IMG_Load2((char*)"gfx/iDraw.png"))
89c4a3a6 sago007 2008-08-29 14:32 465
            && (iLoser = IMG_Load2((char*)"gfx/iLoser.png"))
89c4a3a6 sago007 2008-08-29 14:32 466
            && (iChainBack = IMG_Load2((char*)"gfx/chainFrame.png"))
14e13624 sago007 2011-07-20 17:14 467
//            && (optionsBack = IMG_Load2((char*)"gfx/options.png"))
89c4a3a6 sago007 2008-08-29 14:32 468
            && (bOn = IMG_Load2((char*)"gfx/bOn.png"))
89c4a3a6 sago007 2008-08-29 14:32 469
            && (bOff = IMG_Load2((char*)"gfx/bOff.png"))
14e13624 sago007 2011-07-20 17:14 470
//            && (bChange = IMG_Load2((char*)"gfx/bChange.png"))
89c4a3a6 sago007 2008-08-29 14:32 471
            && (b1024 = IMG_Load2((char*)"gfx/b1024.png"))
89c4a3a6 sago007 2008-08-29 14:32 472
            && (dialogBox = IMG_Load2((char*)"gfx/dialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 473
//	&& (fileDialogBox = IMG_Load2("gfx/fileDialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 474
            && (iLevelCheck = IMG_Load2((char*)"gfx/iLevelCheck.png"))
89c4a3a6 sago007 2008-08-29 14:32 475
            && (iLevelCheckBox = IMG_Load2((char*)"gfx/iLevelCheckBox.png"))
cc6724c9 sago007 2012-04-16 21:11 476
            && (iLevelCheckBoxMarked = IMG_Load2((char*)"gfx/iLevelCheckBoxMarked.png"))
89c4a3a6 sago007 2008-08-29 14:32 477
            && (iCheckBoxArea = IMG_Load2((char*)"gfx/iCheckBoxArea.png"))
89c4a3a6 sago007 2008-08-29 14:32 478
            && (boardBackBack = IMG_Load2((char*)"gfx/boardBackBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 479
            && (changeButtonsBack = IMG_Load2((char*)"gfx/changeButtonsBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 480
            && (garbageTL = IMG_Load2((char*)"gfx/garbage/garbageTL.png"))
89c4a3a6 sago007 2008-08-29 14:32 481
            && (garbageT = IMG_Load2((char*)"gfx/garbage/garbageT.png"))
89c4a3a6 sago007 2008-08-29 14:32 482
            && (garbageTR = IMG_Load2((char*)"gfx/garbage/garbageTR.png"))
89c4a3a6 sago007 2008-08-29 14:32 483
            && (garbageR = IMG_Load2((char*)"gfx/garbage/garbageR.png"))
89c4a3a6 sago007 2008-08-29 14:32 484
            && (garbageBR = IMG_Load2((char*)"gfx/garbage/garbageBR.png"))
89c4a3a6 sago007 2008-08-29 14:32 485
            && (garbageB = IMG_Load2((char*)"gfx/garbage/garbageB.png"))
89c4a3a6 sago007 2008-08-29 14:32 486
            && (garbageBL = IMG_Load2((char*)"gfx/garbage/garbageBL.png"))
89c4a3a6 sago007 2008-08-29 14:32 487
            && (garbageL = IMG_Load2((char*)"gfx/garbage/garbageL.png"))
89c4a3a6 sago007 2008-08-29 14:32 488
            && (garbageFill = IMG_Load2((char*)"gfx/garbage/garbageFill.png"))
89c4a3a6 sago007 2008-08-29 14:32 489
            && (garbageML = IMG_Load2((char*)"gfx/garbage/garbageML.png"))
89c4a3a6 sago007 2008-08-29 14:32 490
            && (garbageM = IMG_Load2((char*)"gfx/garbage/garbageM.png"))
89c4a3a6 sago007 2008-08-29 14:32 491
            && (garbageMR = IMG_Load2((char*)"gfx/garbage/garbageMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 492
            && (garbageGM = IMG_Load2((char*)"gfx/garbage/garbageGM.png"))
89c4a3a6 sago007 2008-08-29 14:32 493
            && (garbageGML = IMG_Load2((char*)"gfx/garbage/garbageGML.png"))
89c4a3a6 sago007 2008-08-29 14:32 494
            && (garbageGMR = IMG_Load2((char*)"gfx/garbage/garbageGMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 495
            && (smiley[0] = IMG_Load2((char*)"gfx/smileys/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 496
            && (smiley[1] = IMG_Load2((char*)"gfx/smileys/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 497
            && (smiley[2] = IMG_Load2((char*)"gfx/smileys/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 498
            && (smiley[3] = IMG_Load2((char*)"gfx/smileys/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 499
            //new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 500
            && (transCover = IMG_Load2((char*)"gfx/transCover.png"))
1572de2b sago007 2008-09-11 18:15 501
            #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 502
            && (bCreateFile = IMG_Load2((char*)"gfx/editor/bCreateFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 503
            && (bDeletePuzzle = IMG_Load2((char*)"gfx/editor/bDeletePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 504
            && (bLoadFile = IMG_Load2((char*)"gfx/editor/bLoadFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 505
            && (bMoveBack = IMG_Load2((char*)"gfx/editor/bMoveBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 506
            && (bMoveDown = IMG_Load2((char*)"gfx/editor/bMoveDown.png"))
89c4a3a6 sago007 2008-08-29 14:32 507
            && (bMoveForward = IMG_Load2((char*)"gfx/editor/bMoveForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 508
            && (bMoveLeft = IMG_Load2((char*)"gfx/editor/bMoveLeft.png"))
89c4a3a6 sago007 2008-08-29 14:32 509
            && (bMoveRight = IMG_Load2((char*)"gfx/editor/bMoveRight.png"))
89c4a3a6 sago007 2008-08-29 14:32 510
            && (bMoveUp = IMG_Load2((char*)"gfx/editor/bMoveUp.png"))
89c4a3a6 sago007 2008-08-29 14:32 511
            && (bNewPuzzle = IMG_Load2((char*)"gfx/editor/bNewPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 512
            && (bSaveFileAs = IMG_Load2((char*)"gfx/editor/bSaveFileAs.png"))
89c4a3a6 sago007 2008-08-29 14:32 513
            && (bSavePuzzle = IMG_Load2((char*)"gfx/editor/bSavePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 514
            && (bSaveToFile = IMG_Load2((char*)"gfx/editor/bSaveToFile.png"))
1572de2b sago007 2008-09-11 18:15 515
            && (bTestPuzzle = IMG_Load2((char*)"gfx/editor/bTestPuzzle.png"))
1572de2b sago007 2008-09-11 18:15 516
            #endif
89c4a3a6 sago007 2008-08-29 14:32 517
            //end new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 518
            //new in 1.4.0
89c4a3a6 sago007 2008-08-29 14:32 519
            && (bTheme = IMG_Load2((char*)"gfx/bTheme.png"))
89c4a3a6 sago007 2008-08-29 14:32 520
            && (bSkip = IMG_Load2((char*)"gfx/bSkip.png"))
89c4a3a6 sago007 2008-08-29 14:32 521
            && (bNext = IMG_Load2((char*)"gfx/bNext.png"))
89c4a3a6 sago007 2008-08-29 14:32 522
            && (bRetry = IMG_Load2((char*)"gfx/bRetry.png"))
89c4a3a6 sago007 2008-08-29 14:32 523
         ))
89c4a3a6 sago007 2008-08-29 14:32 524
        //if there was a problem ie. "File not found"
89c4a3a6 sago007 2008-08-29 14:32 525
    {
89c4a3a6 sago007 2008-08-29 14:32 526
        cout << "Error loading image file: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 527
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 528
    }
8d488d32 sago007 2011-04-17 13:02 529
    try{
43611709 sago007 2011-04-23 17:18 530
        bNewGame = IMG_Load3("gfx/bNewGame.png");
8d488d32 sago007 2011-04-17 13:02 531
        mouse = IMG_Load3("gfx/mouse.png");
b7590374 sago007 2011-05-19 16:15 532
        menuMarked = IMG_Load3("gfx/menu/marked.png");
b7590374 sago007 2011-05-19 16:15 533
        menuUnmarked = IMG_Load3("gfx/menu/unmarked.png");
8d488d32 sago007 2011-04-17 13:02 534
    } catch (exception e) {
8d488d32 sago007 2011-04-17 13:02 535
        cout << e.what() << endl;
8d488d32 sago007 2011-04-17 13:02 536
        exit(1);
8d488d32 sago007 2011-04-17 13:02 537
    }
89c4a3a6 sago007 2008-08-29 14:32 538
89c4a3a6 sago007 2008-08-29 14:32 539
89c4a3a6 sago007 2008-08-29 14:32 540
    //Prepare for fast blittering!
89c4a3a6 sago007 2008-08-29 14:32 541
    CONVERT(background);
89c4a3a6 sago007 2008-08-29 14:32 542
    CONVERT(backgroundImage);
69d650b4 sago007 2011-07-20 15:24 543
//    CONVERT(b1player);
69d650b4 sago007 2011-07-20 15:24 544
//    CONVERT(b2players);
69d650b4 sago007 2011-07-20 15:24 545
//    CONVERT(bVsMode);
69d650b4 sago007 2011-07-20 15:24 546
//    CONVERT(bVsModeConfig);
69d650b4 sago007 2011-07-20 15:24 547
//    CONVERT(bPuzzle);
69d650b4 sago007 2011-07-20 15:24 548
//    CONVERT(bStageClear);
69d650b4 sago007 2011-07-20 15:24 549
//    CONVERT(bTimeTrial);
69d650b4 sago007 2011-07-20 15:24 550
    //CONVERT(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 551
    CONVERT(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 552
    CONVERTA(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 553
    CONVERTA(bSelectPuzzle);
69d650b4 sago007 2011-07-20 15:24 554
//    CONVERTA(bReplay);
69d650b4 sago007 2011-07-20 15:24 555
//    CONVERTA(bSave);
69d650b4 sago007 2011-07-20 15:24 556
//    CONVERTA(bLoad);
89c4a3a6 sago007 2008-08-29 14:32 557
    CONVERTA(bTheme);
89c4a3a6 sago007 2008-08-29 14:32 558
    CONVERTA(bSkip);
89c4a3a6 sago007 2008-08-29 14:32 559
    CONVERTA(bRetry);
89c4a3a6 sago007 2008-08-29 14:32 560
    CONVERTA(bNext);
69d650b4 sago007 2011-07-20 15:24 561
/*#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 562
    CONVERTA(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 563
    CONVERTA(bHost);
89c4a3a6 sago007 2008-08-29 14:32 564
    CONVERTA(bConnect);
69d650b4 sago007 2011-07-20 15:24 565
#endif*/
89c4a3a6 sago007 2008-08-29 14:32 566
    CONVERT(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 567
    CONVERTA(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 568
    CONVERT(backBoard);
89c4a3a6 sago007 2008-08-29 14:32 569
    CONVERT(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 570
    CONVERTA(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 571
    CONVERTA(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 572
    CONVERTA(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 573
    CONVERTA(counter[0]);
89c4a3a6 sago007 2008-08-29 14:32 574
    CONVERTA(counter[1]);
89c4a3a6 sago007 2008-08-29 14:32 575
    CONVERTA(counter[2]);
14e13624 sago007 2011-07-20 17:14 576
//    CONVERTA(optionsBack);
69d650b4 sago007 2011-07-20 15:24 577
//    CONVERT(bExit);
89c4a3a6 sago007 2008-08-29 14:32 578
    CONVERT(bOn);
89c4a3a6 sago007 2008-08-29 14:32 579
    CONVERT(bOff);
14e13624 sago007 2011-07-20 17:14 580
//    CONVERT(bChange);
89c4a3a6 sago007 2008-08-29 14:32 581
    CONVERT(b1024);
89c4a3a6 sago007 2008-08-29 14:32 582
    CONVERTA(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 583
//	CONVERTA(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 584
    CONVERTA(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 585
    CONVERT(iLevelCheckBox);
cc6724c9 sago007 2012-04-16 21:11 586
    CONVERT(iLevelCheckBoxMarked);
89c4a3a6 sago007 2008-08-29 14:32 587
    CONVERTA(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 588
    for (int i = 0;i<4;i++)
89c4a3a6 sago007 2008-08-29 14:32 589
    {
89c4a3a6 sago007 2008-08-29 14:32 590
        CONVERTA(explosion[i]);
89c4a3a6 sago007 2008-08-29 14:32 591
    }
89c4a3a6 sago007 2008-08-29 14:32 592
    for (int i = 0; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 593
    {
89c4a3a6 sago007 2008-08-29 14:32 594
        CONVERTA(bricks[i]);
89c4a3a6 sago007 2008-08-29 14:32 595
        CONVERTA(balls[i]);
89c4a3a6 sago007 2008-08-29 14:32 596
    }
89c4a3a6 sago007 2008-08-29 14:32 597
    CONVERTA(crossover);
89c4a3a6 sago007 2008-08-29 14:32 598
    CONVERTA(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 599
    CONVERTA(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 600
    CONVERTA(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 601
    CONVERTA(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 602
    CONVERTA(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 603
    CONVERTA(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 604
    CONVERTA(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 605
    CONVERTA(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 606
    CONVERTA(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 607
    CONVERTA(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 608
    CONVERTA(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 609
    CONVERTA(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 610
    CONVERTA(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 611
    CONVERTA(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 612
    CONVERTA(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 613
    CONVERTA(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 614
    CONVERTA(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 615
    CONVERTA(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 616
    CONVERTA(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 617
    CONVERTA(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 618
    CONVERTA(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 619
    CONVERTA(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 620
    CONVERTA(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 621
    CONVERTA(iGameOver);
8d488d32 sago007 2011-04-17 13:02 622
    mouse.OptimizeForBlit(true);
43611709 sago007 2011-04-23 17:18 623
    bNewGame.OptimizeForBlit(true);
89c4a3a6 sago007 2008-08-29 14:32 624
    CONVERTA(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 625
    CONVERTA(transCover);
89c4a3a6 sago007 2008-08-29 14:32 626
    //Editor:
1572de2b sago007 2008-09-11 18:15 627
    #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 628
    CONVERTA(bCreateFile);
89c4a3a6 sago007 2008-08-29 14:32 629
    CONVERTA(bDeletePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 630
    CONVERTA(bLoadFile);
89c4a3a6 sago007 2008-08-29 14:32 631
    CONVERTA(bMoveBack);
89c4a3a6 sago007 2008-08-29 14:32 632
    CONVERTA(bMoveDown);
89c4a3a6 sago007 2008-08-29 14:32 633
    CONVERTA(bMoveForward);
89c4a3a6 sago007 2008-08-29 14:32 634
    CONVERTA(bMoveLeft);
89c4a3a6 sago007 2008-08-29 14:32 635
    CONVERTA(bMoveRight);
89c4a3a6 sago007 2008-08-29 14:32 636
    CONVERTA(bMoveUp);
89c4a3a6 sago007 2008-08-29 14:32 637
    CONVERTA(bNewPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 638
    CONVERTA(bSaveFileAs);
89c4a3a6 sago007 2008-08-29 14:32 639
    CONVERTA(bSavePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 640
    CONVERTA(bSaveToFile);
1572de2b sago007 2008-09-11 18:15 641
    CONVERTA(bTestPuzzle);
1572de2b sago007 2008-09-11 18:15 642
    #endif
1572de2b sago007 2008-09-11 18:15 643
    
925b7e58 sago007 2011-04-25 16:35 644
    SDL_Color nf_button_color, nf_standard_blue_color, nf_standard_small_color;
925b7e58 sago007 2011-04-25 16:35 645
    memset(&nf_button_color,0,sizeof(SDL_Color));
925b7e58 sago007 2011-04-25 16:35 646
    nf_button_color.b = 255; nf_button_color.g = 255; nf_button_color.r = 255;
925b7e58 sago007 2011-04-25 16:35 647
    nf_standard_blue_color.b = 255; nf_standard_blue_color.g = 0; nf_standard_blue_color.r = 0;
925b7e58 sago007 2011-04-25 16:35 648
    nf_standard_small_color.b = 0; nf_standard_small_color.g = 0; nf_standard_small_color.r = 200;
925b7e58 sago007 2011-04-25 16:35 649
    NFont_OpenFont(&nf_button_font,"fonts/FreeSerif.ttf",24,nf_button_color);
925b7e58 sago007 2011-04-25 16:35 650
    nf_button_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 651
    NFont_OpenFont(&nf_standard_blue_font,"fonts/FreeSerif.ttf",30,nf_standard_blue_color);
925b7e58 sago007 2011-04-25 16:35 652
    nf_standard_blue_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 653
    NFont_OpenFont(&nf_standard_small_font,"fonts/FreeSerif.ttf",16,nf_standard_small_color);
925b7e58 sago007 2011-04-25 16:35 654
    nf_standard_small_font.setDest(screen);
71181267 sago007 2011-04-29 19:22 655
    NFont_OpenFont(&nf_scoreboard_font,"fonts/PenguinAttack.ttf",20,nf_button_color);
71181267 sago007 2011-04-29 19:22 656
    nf_scoreboard_font.setDest(boardBackBack);
c9dd376f sago007 2012-01-20 17:13 657
    nf_scoreboard_font.draw(370,148,_("Score:") );
c9dd376f sago007 2012-01-20 17:13 658
    nf_scoreboard_font.draw(370,197,_("Time:") );
c9dd376f sago007 2012-01-20 17:13 659
    nf_scoreboard_font.draw(370,246,_("Chain:") );
c9dd376f sago007 2012-01-20 17:13 660
    nf_scoreboard_font.draw(370,295,_("Speed:") );
89c4a3a6 sago007 2008-08-29 14:32 661
71181267 sago007 2011-04-29 19:22 662
    
89c4a3a6 sago007 2008-08-29 14:32 663
//Loads the sound if sound present
89c4a3a6 sago007 2008-08-29 14:32 664
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 665
    {
89c4a3a6 sago007 2008-08-29 14:32 666
        //And here the music:
89c4a3a6 sago007 2008-08-29 14:32 667
        bgMusic = Mix_LoadMUS2((char*)"music/bgMusic.ogg");
6d48320c sago007 2009-03-28 17:06 668
        highbeatMusic = Mix_LoadMUS2((char*)"music/highbeat.ogg");
89c4a3a6 sago007 2008-08-29 14:32 669
        //the music... we just hope it exists, else the user won't hear anything
89c4a3a6 sago007 2008-08-29 14:32 670
        //Same goes for the sounds
89c4a3a6 sago007 2008-08-29 14:32 671
        boing = Mix_LoadWAV2((char*)"sound/pop.ogg");
89c4a3a6 sago007 2008-08-29 14:32 672
        applause = Mix_LoadWAV2((char*)"sound/applause.ogg");
89c4a3a6 sago007 2008-08-29 14:32 673
        photoClick = Mix_LoadWAV2((char*)"sound/cameraclick.ogg");
89c4a3a6 sago007 2008-08-29 14:32 674
        typingChunk = Mix_LoadWAV2((char*)"sound/typing.ogg");
89c4a3a6 sago007 2008-08-29 14:32 675
        counterChunk = Mix_LoadWAV2((char*)"sound/counter.ogg");
24a6ea5f sago007 2008-11-13 22:28 676
        counterFinalChunk = Mix_LoadWAV2((char*)"sound/counterFinal.ogg");
89c4a3a6 sago007 2008-08-29 14:32 677
    } //All sound has been loaded or not
89c4a3a6 sago007 2008-08-29 14:32 678
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 679
} //InitImages()
89c4a3a6 sago007 2008-08-29 14:32 680
89c4a3a6 sago007 2008-08-29 14:32 681
89c4a3a6 sago007 2008-08-29 14:32 682
//Unload images and fonts and sounds
89c4a3a6 sago007 2008-08-29 14:32 683
void UnloadImages()
89c4a3a6 sago007 2008-08-29 14:32 684
{
866417ca sago007 2009-05-10 21:35 685
    cout << "Unloading data..." << endl;
89c4a3a6 sago007 2008-08-29 14:32 686
    if (!NoSound) //Only unload then it has been loaded!
89c4a3a6 sago007 2008-08-29 14:32 687
    {
866417ca sago007 2009-05-10 21:35 688
        Mix_HaltMusic();
89c4a3a6 sago007 2008-08-29 14:32 689
        Mix_FreeMusic(bgMusic);
6d48320c sago007 2009-03-28 17:06 690
        Mix_FreeMusic(highbeatMusic);
89c4a3a6 sago007 2008-08-29 14:32 691
        Mix_FreeChunk(boing);
89c4a3a6 sago007 2008-08-29 14:32 692
        Mix_FreeChunk(applause);
89c4a3a6 sago007 2008-08-29 14:32 693
        Mix_FreeChunk(photoClick);
89c4a3a6 sago007 2008-08-29 14:32 694
        Mix_FreeChunk(counterChunk);
24a6ea5f sago007 2008-11-13 22:28 695
        Mix_FreeChunk(counterFinalChunk);
89c4a3a6 sago007 2008-08-29 14:32 696
        Mix_FreeChunk(typingChunk);
89c4a3a6 sago007 2008-08-29 14:32 697
    }
89c4a3a6 sago007 2008-08-29 14:32 698
    //Free surfaces:
89c4a3a6 sago007 2008-08-29 14:32 699
    //I think this will crash, at least it happend to me...
866417ca sago007 2009-05-10 21:35 700
    //Chrashes no more. Caused by an undocumented double free
89c4a3a6 sago007 2008-08-29 14:32 701
    SDL_FreeSurface(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 702
    SDL_FreeSurface(background);
43611709 sago007 2011-04-23 17:18 703
    //SDL_FreeSurface(bNewGame);
69d650b4 sago007 2011-07-20 15:24 704
//    SDL_FreeSurface(b1player);
69d650b4 sago007 2011-07-20 15:24 705
//    SDL_FreeSurface(b2players);
69d650b4 sago007 2011-07-20 15:24 706
//    SDL_FreeSurface(bVsMode);
69d650b4 sago007 2011-07-20 15:24 707
//    SDL_FreeSurface(bVsModeConfig);
69d650b4 sago007 2011-07-20 15:24 708
//    SDL_FreeSurface(bPuzzle);
69d650b4 sago007 2011-07-20 15:24 709
//    SDL_FreeSurface(bStageClear);
69d650b4 sago007 2011-07-20 15:24 710
//    SDL_FreeSurface(bTimeTrial);
69d650b4 sago007 2011-07-20 15:24 711
    //SDL_FreeSurface(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 712
    SDL_FreeSurface(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 713
    SDL_FreeSurface(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 714
    SDL_FreeSurface(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 715
    SDL_FreeSurface(bHighScore);
69d650b4 sago007 2011-07-20 15:24 716
//    SDL_FreeSurface(bReplay);
69d650b4 sago007 2011-07-20 15:24 717
//    SDL_FreeSurface(bSave);
69d650b4 sago007 2011-07-20 15:24 718
//    SDL_FreeSurface(bLoad);
69d650b4 sago007 2011-07-20 15:24 719
/*    #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 720
    SDL_FreeSurface(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 721
    SDL_FreeSurface(bHost);
89c4a3a6 sago007 2008-08-29 14:32 722
    SDL_FreeSurface(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 723
    #endif
69d650b4 sago007 2011-07-20 15:24 724
    SDL_FreeSurface(bExit);*/
89c4a3a6 sago007 2008-08-29 14:32 725
    SDL_FreeSurface(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 726
    SDL_FreeSurface(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 727
    SDL_FreeSurface(bricks[0]);
89c4a3a6 sago007 2008-08-29 14:32 728
    SDL_FreeSurface(bricks[1]);
89c4a3a6 sago007 2008-08-29 14:32 729
    SDL_FreeSurface(bricks[2]);
89c4a3a6 sago007 2008-08-29 14:32 730
    SDL_FreeSurface(bricks[3]);
89c4a3a6 sago007 2008-08-29 14:32 731
    SDL_FreeSurface(bricks[4]);
89c4a3a6 sago007 2008-08-29 14:32 732
    SDL_FreeSurface(bricks[5]);
89c4a3a6 sago007 2008-08-29 14:32 733
    SDL_FreeSurface(bricks[6]);
89c4a3a6 sago007 2008-08-29 14:32 734
    SDL_FreeSurface(crossover);
89c4a3a6 sago007 2008-08-29 14:32 735
    SDL_FreeSurface(balls[0]);
89c4a3a6 sago007 2008-08-29 14:32 736
    SDL_FreeSurface(balls[1]);
89c4a3a6 sago007 2008-08-29 14:32 737
    SDL_FreeSurface(balls[2]);
89c4a3a6 sago007 2008-08-29 14:32 738
    SDL_FreeSurface(balls[3]);
89c4a3a6 sago007 2008-08-29 14:32 739
    SDL_FreeSurface(balls[4]);
89c4a3a6 sago007 2008-08-29 14:32 740
    SDL_FreeSurface(balls[5]);
89c4a3a6 sago007 2008-08-29 14:32 741
    SDL_FreeSurface(balls[6]);
89c4a3a6 sago007 2008-08-29 14:32 742
    SDL_FreeSurface(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 743
    SDL_FreeSurface(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 744
    SDL_FreeSurface(backBoard); //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 745
    SDL_FreeSurface(iGameOver);
89c4a3a6 sago007 2008-08-29 14:32 746
    SDL_FreeSurface(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 747
    SDL_FreeSurface(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 748
    SDL_FreeSurface(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 749
    SDL_FreeSurface(iChainBack);
14e13624 sago007 2011-07-20 17:14 750
//    SDL_FreeSurface(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 751
    SDL_FreeSurface(bOn);
89c4a3a6 sago007 2008-08-29 14:32 752
    SDL_FreeSurface(bOff);
14e13624 sago007 2011-07-20 17:14 753
//    SDL_FreeSurface(bChange);
89c4a3a6 sago007 2008-08-29 14:32 754
    SDL_FreeSurface(b1024);
89c4a3a6 sago007 2008-08-29 14:32 755
    SDL_FreeSurface(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 756
    //SDL_FreeSurface(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 757
    SDL_FreeSurface(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 758
    SDL_FreeSurface(iLevelCheckBox);
cc6724c9 sago007 2012-04-16 21:11 759
    SDL_FreeSurface(iLevelCheckBoxMarked);
89c4a3a6 sago007 2008-08-29 14:32 760
    SDL_FreeSurface(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 761
    SDL_FreeSurface(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 762
    SDL_FreeSurface(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 763
    SDL_FreeSurface(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 764
    SDL_FreeSurface(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 765
    SDL_FreeSurface(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 766
    SDL_FreeSurface(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 767
    SDL_FreeSurface(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 768
    SDL_FreeSurface(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 769
    SDL_FreeSurface(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 770
    SDL_FreeSurface(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 771
    SDL_FreeSurface(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 772
    SDL_FreeSurface(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 773
    SDL_FreeSurface(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 774
    SDL_FreeSurface(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 775
    SDL_FreeSurface(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 776
    SDL_FreeSurface(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 777
    SDL_FreeSurface(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 778
    SDL_FreeSurface(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 779
    SDL_FreeSurface(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 780
    SDL_FreeSurface(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 781
    SDL_FreeSurface(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 782
    SDL_FreeSurface(transCover);
8d488d32 sago007 2011-04-17 13:02 783
    mouse.MakeNull();
43611709 sago007 2011-04-23 17:18 784
    bNewGame.MakeNull();
89c4a3a6 sago007 2008-08-29 14:32 785
}
89c4a3a6 sago007 2008-08-29 14:32 786
89c4a3a6 sago007 2008-08-29 14:32 787
//Function to convert numbers to string
769a41a0 sago007 2008-09-24 12:54 788
/*string itoa(int num)
89c4a3a6 sago007 2008-08-29 14:32 789
{
89c4a3a6 sago007 2008-08-29 14:32 790
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 791
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 792
    return converter.str();
769a41a0 sago007 2008-09-24 12:54 793
}*/
89c4a3a6 sago007 2008-08-29 14:32 794
89c4a3a6 sago007 2008-08-29 14:32 795
//Function to convert numbers to string (2 diget)
4b0c248f sago007 2010-11-10 21:13 796
static string itoa2(int num)
89c4a3a6 sago007 2008-08-29 14:32 797
{
89c4a3a6 sago007 2008-08-29 14:32 798
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 799
    if(num<10)
89c4a3a6 sago007 2008-08-29 14:32 800
        converter << "0";
89c4a3a6 sago007 2008-08-29 14:32 801
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 802
    return converter.str();
89c4a3a6 sago007 2008-08-29 14:32 803
}
89c4a3a6 sago007 2008-08-29 14:32 804
89c4a3a6 sago007 2008-08-29 14:32 805
/*Loads all the puzzle levels*/
4b0c248f sago007 2010-11-10 21:13 806
static int LoadPuzzleStages()
89c4a3a6 sago007 2008-08-29 14:32 807
{
89c4a3a6 sago007 2008-08-29 14:32 808
    //if(puzzleLoaded)
89c4a3a6 sago007 2008-08-29 14:32 809
    //    return 1;
aca2f4b0 sago007 2009-05-10 18:11 810
    if (!PHYSFS_exists(("puzzles/"+puzzleName).c_str()))
aca2f4b0 sago007 2009-05-10 18:11 811
    {
aca2f4b0 sago007 2009-05-10 18:11 812
        cout << "File not in blockattack.data: " << ("puzzles/"+puzzleName) << endl;
aca2f4b0 sago007 2009-05-10 18:11 813
        return -1; //file doesn't exist
aca2f4b0 sago007 2009-05-10 18:11 814
    }
aca2f4b0 sago007 2009-05-10 18:11 815
    PhysFS::ifstream inFile(("puzzles/"+puzzleName).c_str());
aca2f4b0 sago007 2009-05-10 18:11 816
89c4a3a6 sago007 2008-08-29 14:32 817
    inFile >> nrOfPuzzles;
89c4a3a6 sago007 2008-08-29 14:32 818
    if (nrOfPuzzles>maxNrOfPuzzleStages)
89c4a3a6 sago007 2008-08-29 14:32 819
        nrOfPuzzles=maxNrOfPuzzleStages;
aca2f4b0 sago007 2009-05-10 18:11 820
    for (int k=0; (k<nrOfPuzzles) /*&&(!inFile.eof())*/ ; k++)
89c4a3a6 sago007 2008-08-29 14:32 821
    {
89c4a3a6 sago007 2008-08-29 14:32 822
        inFile >> nrOfMovesAllowed[k];
89c4a3a6 sago007 2008-08-29 14:32 823
        for (int i=11;i>=0;i--)
89c4a3a6 sago007 2008-08-29 14:32 824
            for (int j=0;j<6;j++)
89c4a3a6 sago007 2008-08-29 14:32 825
            {
89c4a3a6 sago007 2008-08-29 14:32 826
                inFile >> puzzleLevels[k][j][i];
89c4a3a6 sago007 2008-08-29 14:32 827
            }
89c4a3a6 sago007 2008-08-29 14:32 828
    }
89c4a3a6 sago007 2008-08-29 14:32 829
    puzzleLoaded = true;
89c4a3a6 sago007 2008-08-29 14:32 830
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 831
}
89c4a3a6 sago007 2008-08-29 14:32 832
89c4a3a6 sago007 2008-08-29 14:32 833
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
e1290bdf sago007 2010-10-25 19:56 834
void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 835
{
89c4a3a6 sago007 2008-08-29 14:32 836
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 837
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 838
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 839
    SDL_BlitSurface(img, NULL, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 840
}
89c4a3a6 sago007 2008-08-29 14:32 841
89c4a3a6 sago007 2008-08-29 14:32 842
/*Draws a part of an image on a surface of choice*/
89c4a3a6 sago007 2008-08-29 14:32 843
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 844
{
89c4a3a6 sago007 2008-08-29 14:32 845
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 846
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 847
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 848
    SDL_Rect dest2;
89c4a3a6 sago007 2008-08-29 14:32 849
    dest2.x = x2;
89c4a3a6 sago007 2008-08-29 14:32 850
    dest2.y = y2;
89c4a3a6 sago007 2008-08-29 14:32 851
    dest2.w = w;
89c4a3a6 sago007 2008-08-29 14:32 852
    dest2.h = h;
89c4a3a6 sago007 2008-08-29 14:32 853
    SDL_BlitSurface(img, &dest2, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 854
}
89c4a3a6 sago007 2008-08-29 14:32 855
925b7e58 sago007 2011-04-25 16:35 856
void NFont_Write(SDL_Surface *target,int x,int y,string text) {
925b7e58 sago007 2011-04-25 16:35 857
    nf_standard_blue_font.setDest(target);
925b7e58 sago007 2011-04-25 16:35 858
    nf_standard_blue_font.draw(x,y,text.c_str());
925b7e58 sago007 2011-04-25 16:35 859
    nf_standard_blue_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 860
}
925b7e58 sago007 2011-04-25 16:35 861
26ddb424 sago007 2011-06-09 20:06 862
void ResetFullscreen(){
26ddb424 sago007 2011-06-09 20:06 863
#if defined(WIN32)
26ddb424 sago007 2011-06-09 20:06 864
                        if (bFullscreen) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
26ddb424 sago007 2011-06-09 20:06 865
                        else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
26ddb424 sago007 2011-06-09 20:06 866
                        DrawIMG(background, screen, 0, 0);
26ddb424 sago007 2011-06-09 20:06 867
#else
26ddb424 sago007 2011-06-09 20:06 868
                        SDL_WM_ToggleFullScreen(screen); //Will only work in Linux
26ddb424 sago007 2011-06-09 20:06 869
#endif
26ddb424 sago007 2011-06-09 20:06 870
                        SDL_ShowCursor(SDL_DISABLE);
78d03b38 sago007 2008-11-13 19:56 871
}
78d03b38 sago007 2008-11-13 19:56 872
78d03b38 sago007 2008-11-13 19:56 873
89c4a3a6 sago007 2008-08-29 14:32 874
//The small things that are faaling when you clear something
89c4a3a6 sago007 2008-08-29 14:32 875
class aBall
89c4a3a6 sago007 2008-08-29 14:32 876
{
89c4a3a6 sago007 2008-08-29 14:32 877
private:
89c4a3a6 sago007 2008-08-29 14:32 878
    double x;
89c4a3a6 sago007 2008-08-29 14:32 879
    double y;
89c4a3a6 sago007 2008-08-29 14:32 880
    double velocityY;
89c4a3a6 sago007 2008-08-29 14:32 881
    double velocityX;
89c4a3a6 sago007 2008-08-29 14:32 882
    int color;
89c4a3a6 sago007 2008-08-29 14:32 883
    unsigned long int lastTime;
89c4a3a6 sago007 2008-08-29 14:32 884
public:
89c4a3a6 sago007 2008-08-29 14:32 885
89c4a3a6 sago007 2008-08-29 14:32 886
    aBall()
89c4a3a6 sago007 2008-08-29 14:32 887
    {}
89c4a3a6 sago007 2008-08-29 14:32 888
89c4a3a6 sago007 2008-08-29 14:32 889
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 890
    aBall(int X, int Y, bool right, int coulor)
89c4a3a6 sago007 2008-08-29 14:32 891
    {
89c4a3a6 sago007 2008-08-29 14:32 892
        double tal = 1.0;
89c4a3a6 sago007 2008-08-29 14:32 893
        velocityY = -tal*startVelocityY;
89c4a3a6 sago007 2008-08-29 14:32 894
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 895
        x = (double)X;
89c4a3a6 sago007 2008-08-29 14:32 896
        y = (double)Y;
89c4a3a6 sago007 2008-08-29 14:32 897
        color = coulor;
89c4a3a6 sago007 2008-08-29 14:32 898
        if (right)
89c4a3a6 sago007 2008-08-29 14:32 899
            velocityX = tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 900
        else
89c4a3a6 sago007 2008-08-29 14:32 901
            velocityX = -tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 902
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 903
89c4a3a6 sago007 2008-08-29 14:32 904
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 905
    ~aBall()
89c4a3a6 sago007 2008-08-29 14:32 906
    {
89c4a3a6 sago007 2008-08-29 14:32 907
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 908
89c4a3a6 sago007 2008-08-29 14:32 909
    void update()
89c4a3a6 sago007 2008-08-29 14:32 910
    {
89c4a3a6 sago007 2008-08-29 14:32 911
        double timePassed = (((double)(currentTime-lastTime))/1000.0);  //time passed in seconds
89c4a3a6 sago007 2008-08-29 14:32 912
        x = x+timePassed*velocityX;
89c4a3a6 sago007 2008-08-29 14:32 913
        y = y+timePassed*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 914
        velocityY = velocityY + gravity*timePassed;
89c4a3a6 sago007 2008-08-29 14:32 915
        if (y<1.0)
89c4a3a6 sago007 2008-08-29 14:32 916
            velocityY=10.0;
89c4a3a6 sago007 2008-08-29 14:32 917
        if ((velocityY>minVelocity) && (y>(double)(768-ballSize)) && (y<768.0))
89c4a3a6 sago007 2008-08-29 14:32 918
        {
89c4a3a6 sago007 2008-08-29 14:32 919
            velocityY = -0.70*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 920
            y = 768.0-ballSize;
89c4a3a6 sago007 2008-08-29 14:32 921
        }
89c4a3a6 sago007 2008-08-29 14:32 922
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 923
    }
89c4a3a6 sago007 2008-08-29 14:32 924
89c4a3a6 sago007 2008-08-29 14:32 925
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 926
    {
89c4a3a6 sago007 2008-08-29 14:32 927
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 928
    }
89c4a3a6 sago007 2008-08-29 14:32 929
89c4a3a6 sago007 2008-08-29 14:32 930
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 931
    {
89c4a3a6 sago007 2008-08-29 14:32 932
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 933
    }
89c4a3a6 sago007 2008-08-29 14:32 934
89c4a3a6 sago007 2008-08-29 14:32 935
    int getColor()
89c4a3a6 sago007 2008-08-29 14:32 936
    {
89c4a3a6 sago007 2008-08-29 14:32 937
        return color;
89c4a3a6 sago007 2008-08-29 14:32 938
    }
89c4a3a6 sago007 2008-08-29 14:32 939
};  //aBall
89c4a3a6 sago007 2008-08-29 14:32 940
4b0c248f sago007 2010-11-10 21:13 941
static const int maxNumberOfBalls = 6*12*2*2;
89c4a3a6 sago007 2008-08-29 14:32 942
89c4a3a6 sago007 2008-08-29 14:32 943
class ballManeger
89c4a3a6 sago007 2008-08-29 14:32 944
{
89c4a3a6 sago007 2008-08-29 14:32 945
public:
89c4a3a6 sago007 2008-08-29 14:32 946
    aBall ballArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 947
    bool ballUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 948
    //The old ball information is also saved so balls can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 949
    aBall oldBallArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 950
    bool oldBallUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 951
89c4a3a6 sago007 2008-08-29 14:32 952
    ballManeger()
89c4a3a6 sago007 2008-08-29 14:32 953
    {
89c4a3a6 sago007 2008-08-29 14:32 954
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 955
        {
89c4a3a6 sago007 2008-08-29 14:32 956
            ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 957
            oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 958
        }
89c4a3a6 sago007 2008-08-29 14:32 959
    }
89c4a3a6 sago007 2008-08-29 14:32 960
6d48320c sago007 2009-03-28 17:06 961
    //Adds a ball to the screen at given coordiantes, traveling right or not with color
89c4a3a6 sago007 2008-08-29 14:32 962
    int addBall(int x, int y,bool right,int color)
89c4a3a6 sago007 2008-08-29 14:32 963
    {
89c4a3a6 sago007 2008-08-29 14:32 964
        int ballNumber = 0;
6d48320c sago007 2009-03-28 17:06 965
        //Find a free ball
89c4a3a6 sago007 2008-08-29 14:32 966
        while ((ballUsed[ballNumber])&&(ballNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 967
            ballNumber++;
6d48320c sago007 2009-03-28 17:06 968
        //Could not find a free ball, return -1
89c4a3a6 sago007 2008-08-29 14:32 969
        if (ballNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 970
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 971
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 972
        ballArray[ballNumber] = aBall(x,y,right,color);
89c4a3a6 sago007 2008-08-29 14:32 973
        ballUsed[ballNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 974
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 975
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 976
89c4a3a6 sago007 2008-08-29 14:32 977
    void update()
89c4a3a6 sago007 2008-08-29 14:32 978
    {
89c4a3a6 sago007 2008-08-29 14:32 979
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 980
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 981
        {
89c4a3a6 sago007 2008-08-29 14:32 982
89c4a3a6 sago007 2008-08-29 14:32 983
            if (ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 984
            {
89c4a3a6 sago007 2008-08-29 14:32 985
                oldBallUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 986
                oldBallArray[i] = ballArray[i];
89c4a3a6 sago007 2008-08-29 14:32 987
                ballArray[i].update();
6d48320c sago007 2009-03-28 17:06 988
                if (ballArray[i].getY()>800 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize)
89c4a3a6 sago007 2008-08-29 14:32 989
                {
89c4a3a6 sago007 2008-08-29 14:32 990
                    ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 991
                }
89c4a3a6 sago007 2008-08-29 14:32 992
            }
89c4a3a6 sago007 2008-08-29 14:32 993
            else
89c4a3a6 sago007 2008-08-29 14:32 994
            {
89c4a3a6 sago007 2008-08-29 14:32 995
                oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 996
            }
89c4a3a6 sago007 2008-08-29 14:32 997
        }
89c4a3a6 sago007 2008-08-29 14:32 998
    } //update
89c4a3a6 sago007 2008-08-29 14:32 999
89c4a3a6 sago007 2008-08-29 14:32 1000
89c4a3a6 sago007 2008-08-29 14:32 1001
}; //theBallManeger
89c4a3a6 sago007 2008-08-29 14:32 1002
4b0c248f sago007 2010-11-10 21:13 1003
static ballManeger theBallManeger;
89c4a3a6 sago007 2008-08-29 14:32 1004
89c4a3a6 sago007 2008-08-29 14:32 1005
//a explosions, non moving
89c4a3a6 sago007 2008-08-29 14:32 1006
class anExplosion
89c4a3a6 sago007 2008-08-29 14:32 1007
{
89c4a3a6 sago007 2008-08-29 14:32 1008
private:
89c4a3a6 sago007 2008-08-29 14:32 1009
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1010
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1011
    Uint8 frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 1012
#define frameLength 80
89c4a3a6 sago007 2008-08-29 14:32 1013
    //How long an image in an animation should be showed
89c4a3a6 sago007 2008-08-29 14:32 1014
#define maxFrame 4
89c4a3a6 sago007 2008-08-29 14:32 1015
    //How many images there are in the animation
89c4a3a6 sago007 2008-08-29 14:32 1016
    unsigned long int placeTime; //Then the explosion occored
89c4a3a6 sago007 2008-08-29 14:32 1017
public:
89c4a3a6 sago007 2008-08-29 14:32 1018
89c4a3a6 sago007 2008-08-29 14:32 1019
    anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 1020
    {}
89c4a3a6 sago007 2008-08-29 14:32 1021
89c4a3a6 sago007 2008-08-29 14:32 1022
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1023
    anExplosion(int X, int Y)
89c4a3a6 sago007 2008-08-29 14:32 1024
    {
89c4a3a6 sago007 2008-08-29 14:32 1025
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1026
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1027
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1028
        frameNumber=0;
89c4a3a6 sago007 2008-08-29 14:32 1029
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1030
89c4a3a6 sago007 2008-08-29 14:32 1031
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1032
    ~anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 1033
    {
89c4a3a6 sago007 2008-08-29 14:32 1034
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1035
89c4a3a6 sago007 2008-08-29 14:32 1036
    //true if animation has played and object should be removed from the screen
89c4a3a6 sago007 2008-08-29 14:32 1037
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1038
    {
89c4a3a6 sago007 2008-08-29 14:32 1039
        frameNumber = (currentTime-placeTime)/frameLength;
89c4a3a6 sago007 2008-08-29 14:32 1040
        return (!(frameNumber<maxFrame));
89c4a3a6 sago007 2008-08-29 14:32 1041
    }
89c4a3a6 sago007 2008-08-29 14:32 1042
89c4a3a6 sago007 2008-08-29 14:32 1043
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1044
    {
89c4a3a6 sago007 2008-08-29 14:32 1045
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 1046
    }
89c4a3a6 sago007 2008-08-29 14:32 1047
89c4a3a6 sago007 2008-08-29 14:32 1048
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1049
    {
89c4a3a6 sago007 2008-08-29 14:32 1050
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 1051
    }
89c4a3a6 sago007 2008-08-29 14:32 1052
89c4a3a6 sago007 2008-08-29 14:32 1053
    int getFrame()
89c4a3a6 sago007 2008-08-29 14:32 1054
    {
89c4a3a6 sago007 2008-08-29 14:32 1055
        return frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 1056
    }
89c4a3a6 sago007 2008-08-29 14:32 1057
};  //nExplosion
89c4a3a6 sago007 2008-08-29 14:32 1058
89c4a3a6 sago007 2008-08-29 14:32 1059
class explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1060
{
89c4a3a6 sago007 2008-08-29 14:32 1061
public:
89c4a3a6 sago007 2008-08-29 14:32 1062
    anExplosion explosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1063
    bool explosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1064
    //The old explosion information is also saved so explosions can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1065
    anExplosion oldExplosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1066
    bool oldExplosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1067
89c4a3a6 sago007 2008-08-29 14:32 1068
    explosionManeger()
89c4a3a6 sago007 2008-08-29 14:32 1069
    {
89c4a3a6 sago007 2008-08-29 14:32 1070
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1071
        {
89c4a3a6 sago007 2008-08-29 14:32 1072
            explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1073
            oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1074
        }
89c4a3a6 sago007 2008-08-29 14:32 1075
    }
89c4a3a6 sago007 2008-08-29 14:32 1076
89c4a3a6 sago007 2008-08-29 14:32 1077
    int addExplosion(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 1078
    {
89c4a3a6 sago007 2008-08-29 14:32 1079
        //cout << "Tries to add an explosion" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1080
        int explosionNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1081
        while ((explosionUsed[explosionNumber])&&(explosionNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 1082
            explosionNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1083
        if (explosionNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1084
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1085
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1086
        explosionArray[explosionNumber] = anExplosion(x,y);
89c4a3a6 sago007 2008-08-29 14:32 1087
        explosionUsed[explosionNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1088
        //cout << "Explosion added" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1089
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1090
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 1091
89c4a3a6 sago007 2008-08-29 14:32 1092
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1093
    {
89c4a3a6 sago007 2008-08-29 14:32 1094
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1095
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1096
        {
89c4a3a6 sago007 2008-08-29 14:32 1097
89c4a3a6 sago007 2008-08-29 14:32 1098
            if (explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1099
            {
89c4a3a6 sago007 2008-08-29 14:32 1100
                oldExplosionUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1101
                oldExplosionArray[i] = explosionArray[i];
89c4a3a6 sago007 2008-08-29 14:32 1102
                if (explosionArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1103
                {
89c4a3a6 sago007 2008-08-29 14:32 1104
                    explosionArray[i].~anExplosion();
89c4a3a6 sago007 2008-08-29 14:32 1105
                    explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1106
                    //cout << "Explosion removed" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1107
                }
89c4a3a6 sago007 2008-08-29 14:32 1108
            }
89c4a3a6 sago007 2008-08-29 14:32 1109
            else
89c4a3a6 sago007 2008-08-29 14:32 1110
            {
89c4a3a6 sago007 2008-08-29 14:32 1111
                oldExplosionUsed[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
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1115
89c4a3a6 sago007 2008-08-29 14:32 1116
89c4a3a6 sago007 2008-08-29 14:32 1117
}; //explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1118
4b0c248f sago007 2010-11-10 21:13 1119
static explosionManeger theExplosionManeger;
89c4a3a6 sago007 2008-08-29 14:32 1120
89c4a3a6 sago007 2008-08-29 14:32 1121
//text pop-up
89c4a3a6 sago007 2008-08-29 14:32 1122
class textMessage
89c4a3a6 sago007 2008-08-29 14:32 1123
{
89c4a3a6 sago007 2008-08-29 14:32 1124
private:
89c4a3a6 sago007 2008-08-29 14:32 1125
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1126
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1127
    char textt[10];
89c4a3a6 sago007 2008-08-29 14:32 1128
    unsigned long int time;
89c4a3a6 sago007 2008-08-29 14:32 1129
    unsigned long int placeTime; //Then the text was placed
89c4a3a6 sago007 2008-08-29 14:32 1130
public:
89c4a3a6 sago007 2008-08-29 14:32 1131
89c4a3a6 sago007 2008-08-29 14:32 1132
    textMessage()
89c4a3a6 sago007 2008-08-29 14:32 1133
    {}
89c4a3a6 sago007 2008-08-29 14:32 1134
89c4a3a6 sago007 2008-08-29 14:32 1135
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1136
    textMessage(int X, int Y,const char* Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1137
    {
89c4a3a6 sago007 2008-08-29 14:32 1138
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1139
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1140
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1141
        strncpy(textt,Text,10);
89c4a3a6 sago007 2008-08-29 14:32 1142
        textt[9]=0;
89c4a3a6 sago007 2008-08-29 14:32 1143
        time = Time;
89c4a3a6 sago007 2008-08-29 14:32 1144
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1145
89c4a3a6 sago007 2008-08-29 14:32 1146
    //true if the text has expired
89c4a3a6 sago007 2008-08-29 14:32 1147
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1148
    {
89c4a3a6 sago007 2008-08-29 14:32 1149
        return currentTime-placeTime>time;
89c4a3a6 sago007 2008-08-29 14:32 1150
    }
89c4a3a6 sago007 2008-08-29 14:32 1151
89c4a3a6 sago007 2008-08-29 14:32 1152
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1153
    {
89c4a3a6 sago007 2008-08-29 14:32 1154
        return x;
89c4a3a6 sago007 2008-08-29 14:32 1155
    }
89c4a3a6 sago007 2008-08-29 14:32 1156
89c4a3a6 sago007 2008-08-29 14:32 1157
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1158
    {
89c4a3a6 sago007 2008-08-29 14:32 1159
        return y;
89c4a3a6 sago007 2008-08-29 14:32 1160
    }
89c4a3a6 sago007 2008-08-29 14:32 1161
89c4a3a6 sago007 2008-08-29 14:32 1162
    char* getText()
89c4a3a6 sago007 2008-08-29 14:32 1163
    {
89c4a3a6 sago007 2008-08-29 14:32 1164
        return textt;
89c4a3a6 sago007 2008-08-29 14:32 1165
    }
89c4a3a6 sago007 2008-08-29 14:32 1166
};  //text popup
89c4a3a6 sago007 2008-08-29 14:32 1167
89c4a3a6 sago007 2008-08-29 14:32 1168
class textManeger
89c4a3a6 sago007 2008-08-29 14:32 1169
{
89c4a3a6 sago007 2008-08-29 14:32 1170
public:
89c4a3a6 sago007 2008-08-29 14:32 1171
    textMessage textArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1172
    bool textUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1173
    //The old text information is also saved so text can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1174
    textMessage oldTextArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1175
    bool oldTextUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1176
89c4a3a6 sago007 2008-08-29 14:32 1177
    textManeger()
89c4a3a6 sago007 2008-08-29 14:32 1178
    {
89c4a3a6 sago007 2008-08-29 14:32 1179
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1180
        {
89c4a3a6 sago007 2008-08-29 14:32 1181
            textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1182
            oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1183
        }
89c4a3a6 sago007 2008-08-29 14:32 1184
    }
89c4a3a6 sago007 2008-08-29 14:32 1185
89c4a3a6 sago007 2008-08-29 14:32 1186
    int addText(int x, int y,string Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1187
    {
89c4a3a6 sago007 2008-08-29 14:32 1188
        //cout << "Tries to add text" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1189
        int textNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1190
        while ((textNumber<maxNumberOfBalls)&&((textUsed[textNumber])||(oldTextUsed[textNumber])))
89c4a3a6 sago007 2008-08-29 14:32 1191
            textNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1192
        if (textNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1193
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1194
        //cout << "adding to: " << textNumber << ":" << textUsed[textNumber] << ":" << &textArray[textNumber] << endl;
89c4a3a6 sago007 2008-08-29 14:32 1195
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1196
        textArray[textNumber] = textMessage(x,y,Text.c_str(),Time);
89c4a3a6 sago007 2008-08-29 14:32 1197
        textUsed[textNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1198
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1199
    }  //addText
89c4a3a6 sago007 2008-08-29 14:32 1200
89c4a3a6 sago007 2008-08-29 14:32 1201
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1202
    {
89c4a3a6 sago007 2008-08-29 14:32 1203
        //cout << "Running update" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1204
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1205
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1206
        {
89c4a3a6 sago007 2008-08-29 14:32 1207
89c4a3a6 sago007 2008-08-29 14:32 1208
            if (textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1209
            {
89c4a3a6 sago007 2008-08-29 14:32 1210
                if (!oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1211
                {
89c4a3a6 sago007 2008-08-29 14:32 1212
                    oldTextUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1213
                    oldTextArray[i] = textMessage(textArray[i]);
89c4a3a6 sago007 2008-08-29 14:32 1214
                }
89c4a3a6 sago007 2008-08-29 14:32 1215
                if (textArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1216
                {
89c4a3a6 sago007 2008-08-29 14:32 1217
                    textArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1218
                    textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1219
                }
89c4a3a6 sago007 2008-08-29 14:32 1220
            }
89c4a3a6 sago007 2008-08-29 14:32 1221
            else
89c4a3a6 sago007 2008-08-29 14:32 1222
                if (oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1223
                {
89c4a3a6 sago007 2008-08-29 14:32 1224
                    oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1225
                    oldTextArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1226
                }
89c4a3a6 sago007 2008-08-29 14:32 1227
        }
89c4a3a6 sago007 2008-08-29 14:32 1228
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1229
89c4a3a6 sago007 2008-08-29 14:32 1230
89c4a3a6 sago007 2008-08-29 14:32 1231
}; //textManeger
89c4a3a6 sago007 2008-08-29 14:32 1232
4b0c248f sago007 2010-11-10 21:13 1233
static textManeger theTextManeger;
89c4a3a6 sago007 2008-08-29 14:32 1234
89c4a3a6 sago007 2008-08-29 14:32 1235
//Here comes the Block Game object
89c4a3a6 sago007 2008-08-29 14:32 1236
#include "BlockGame.hpp"
17916a2e sago007 2010-11-07 11:26 1237
#include "BlockGame.cpp"
89c4a3a6 sago007 2008-08-29 14:32 1238
6b1dc7a6 sago007 2010-11-08 21:03 1239
class BlockGameSdl : public BlockGame {
6b1dc7a6 sago007 2010-11-08 21:03 1240
public:
6b1dc7a6 sago007 2010-11-08 21:03 1241
    SDL_Surface* sBoard;
6b1dc7a6 sago007 2010-11-08 21:03 1242
6b1dc7a6 sago007 2010-11-08 21:03 1243
    BlockGameSdl(int tx, int ty) {
6b1dc7a6 sago007 2010-11-08 21:03 1244
        tmp = IMG_Load2((char*)"gfx/BackBoard.png");
6b1dc7a6 sago007 2010-11-08 21:03 1245
        sBoard = SDL_DisplayFormat(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1246
        SDL_FreeSurface(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1247
        //BlockGame::BlockGame(tx,ty);
6b1dc7a6 sago007 2010-11-08 21:03 1248
        BlockGame::topx = tx;
6b1dc7a6 sago007 2010-11-08 21:03 1249
        BlockGame::topy = ty;
6b1dc7a6 sago007 2010-11-08 21:03 1250
    }
6b1dc7a6 sago007 2010-11-08 21:03 1251
    ~BlockGameSdl() {
6b1dc7a6 sago007 2010-11-08 21:03 1252
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1253
    }
6b1dc7a6 sago007 2010-11-08 21:03 1254
private:
6b1dc7a6 sago007 2010-11-08 21:03 1255
    void convertSurface() {
6b1dc7a6 sago007 2010-11-08 21:03 1256
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1257
        sBoard = SDL_DisplayFormat(backBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1258
    }
6b1dc7a6 sago007 2010-11-08 21:03 1259
    //Draws all the bricks to the board (including garbage)
6b1dc7a6 sago007 2010-11-08 21:03 1260
    void PaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1261
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1262
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1263
                if ((board[j][i]%10 != -1) && (board[j][i]%10 < 7) && ((board[j][i]/1000000)%10==0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1264
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1265
                    if ((board[j][i]/BLOCKWAIT)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1266
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1267
                    if ((board[j][i]/BLOCKHANG)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1268
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1269
6b1dc7a6 sago007 2010-11-08 21:03 1270
                }
6b1dc7a6 sago007 2010-11-08 21:03 1271
                if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1272
                    int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1273
                    int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1274
                    if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1275
                    else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1276
                    if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1277
                    else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1278
                    if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1279
                    else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1280
                    if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1281
                    else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1282
                    if ((left == number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1283
                        DrawIMG(garbageFill, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1284
                    if ((left != number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1285
                        DrawIMG(garbageL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1286
                    if ((left == number)&&(right != number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1287
                        DrawIMG(garbageR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1288
                    if ((left == number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1289
                        DrawIMG(garbageT, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1290
                    if ((left == number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1291
                        DrawIMG(garbageB, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1292
                    if ((left != number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1293
                        DrawIMG(garbageTL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1294
                    if ((left != number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1295
                        DrawIMG(garbageBL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1296
                    if ((left == number)&&(right != number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1297
                        DrawIMG(garbageTR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1298
                    if ((left == number)&&(right != number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1299
                        DrawIMG(garbageBR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1300
                    if ((left == number)&&(right != number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1301
                        DrawIMG(garbageMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1302
                    if ((left == number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1303
                        DrawIMG(garbageM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1304
                    if ((left != number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1305
                        DrawIMG(garbageML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1306
                }
6b1dc7a6 sago007 2010-11-08 21:03 1307
                if ((board[j][i]/1000000)%10==2) {
6b1dc7a6 sago007 2010-11-08 21:03 1308
                    if (j==0)
6b1dc7a6 sago007 2010-11-08 21:03 1309
                        DrawIMG(garbageGML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1310
                    else
6b1dc7a6 sago007 2010-11-08 21:03 1311
                        if (j==5)
6b1dc7a6 sago007 2010-11-08 21:03 1312
                            DrawIMG(garbageGMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1313
                        else
6b1dc7a6 sago007 2010-11-08 21:03 1314
                            DrawIMG(garbageGM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1315
                }
6b1dc7a6 sago007 2010-11-08 21:03 1316
            }
6b1dc7a6 sago007 2010-11-08 21:03 1317
        const int j = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1318
6b1dc7a6 sago007 2010-11-08 21:03 1319
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1320
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1321
            if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1322
                int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1323
                int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1324
                if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1325
                else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1326
                if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1327
                else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1328
                if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1329
                else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1330
                if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1331
                else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1332
                if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1333
                    DrawIMG(smiley[board[j][i]%4], sBoard, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1334
                }
6b1dc7a6 sago007 2010-11-08 21:03 1335
                if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1336
                {
6b1dc7a6 sago007 2010-11-08 21:03 1337
                    garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1338
                }
6b1dc7a6 sago007 2010-11-08 21:03 1339
                else {
6b1dc7a6 sago007 2010-11-08 21:03 1340
                    //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1341
                    garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1342
                }
6b1dc7a6 sago007 2010-11-08 21:03 1343
6b1dc7a6 sago007 2010-11-08 21:03 1344
            }
6b1dc7a6 sago007 2010-11-08 21:03 1345
        }
6b1dc7a6 sago007 2010-11-08 21:03 1346
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1347
            if (board[i][0]!=-1)
6b1dc7a6 sago007 2010-11-08 21:03 1348
                DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant
6b1dc7a6 sago007 2010-11-08 21:03 1349
6b1dc7a6 sago007 2010-11-08 21:03 1350
    }
6b1dc7a6 sago007 2010-11-08 21:03 1351
    //Paints the bricks gotten from a replay/net package
6b1dc7a6 sago007 2010-11-08 21:03 1352
    void SimplePaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1353
        /*
6b1dc7a6 sago007 2010-11-08 21:03 1354
         * 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 1355
         */
6b1dc7a6 sago007 2010-11-08 21:03 1356
        bool bbomb[6][13]; //has a bomb on it!
6b1dc7a6 sago007 2010-11-08 21:03 1357
        bool falling[6][13]; //this is falling
6b1dc7a6 sago007 2010-11-08 21:03 1358
        bool getReady[6][13]; //getReady
6b1dc7a6 sago007 2010-11-08 21:03 1359
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1360
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1361
                bbomb[i][j]=false; //All false by default
6b1dc7a6 sago007 2010-11-08 21:03 1362
                falling[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1363
                if (board[i][j]>29)
6b1dc7a6 sago007 2010-11-08 21:03 1364
                    getReady[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1365
                else
6b1dc7a6 sago007 2010-11-08 21:03 1366
                    getReady[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1367
            }
6b1dc7a6 sago007 2010-11-08 21:03 1368
        //See that is falling
6b1dc7a6 sago007 2010-11-08 21:03 1369
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1370
            bool rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1371
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1372
                if (rowFalling)
6b1dc7a6 sago007 2010-11-08 21:03 1373
                    falling[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1374
                if ((!rowFalling)&&(board[i][j]%30==-1))
6b1dc7a6 sago007 2010-11-08 21:03 1375
                    rowFalling = true;
6b1dc7a6 sago007 2010-11-08 21:03 1376
                if ((rowFalling)&&(board[i][j]%30>6))
6b1dc7a6 sago007 2010-11-08 21:03 1377
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1378
                if (getReady[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1379
                    falling[i][j]=true; //getReady is the same as falling
6b1dc7a6 sago007 2010-11-08 21:03 1380
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1381
                }
6b1dc7a6 sago007 2010-11-08 21:03 1382
            }
6b1dc7a6 sago007 2010-11-08 21:03 1383
        }
6b1dc7a6 sago007 2010-11-08 21:03 1384
        //Now looking at rows:
6b1dc7a6 sago007 2010-11-08 21:03 1385
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1386
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1387
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1388
            for (int j=1;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1389
                if ((board[i][j]%30==color)&&(!falling[i][j]))
6b1dc7a6 sago007 2010-11-08 21:03 1390
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1391
                else
6b1dc7a6 sago007 2010-11-08 21:03 1392
                    if (falling[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1393
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1394
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1395
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1396
                        color=board[i][j]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1397
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1398
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1399
                if ((count>2)&&(color>-1)&&(color)<7) {
6b1dc7a6 sago007 2010-11-08 21:03 1400
                    bbomb[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1401
                    bbomb[i][j-1]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1402
                    bbomb[i][j-2]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1403
                }
6b1dc7a6 sago007 2010-11-08 21:03 1404
            }
6b1dc7a6 sago007 2010-11-08 21:03 1405
        }
6b1dc7a6 sago007 2010-11-08 21:03 1406
        //now looking for lines
6b1dc7a6 sago007 2010-11-08 21:03 1407
        for (int i=1;i<13;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1408
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1409
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1410
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1411
                if ((board[j][i]%30==color)&&(!falling[j][i]))
6b1dc7a6 sago007 2010-11-08 21:03 1412
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1413
                else
6b1dc7a6 sago007 2010-11-08 21:03 1414
                    if (falling[j][i]) {
6b1dc7a6 sago007 2010-11-08 21:03 1415
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1416
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1417
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1418
                        color=board[j][i]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1419
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1420
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1421
                if ((count>2)&&(color>-1)&&(color<7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1422
                    bbomb[j][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1423
                    bbomb[j-1][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1424
                    bbomb[j-2][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1425
                }
6b1dc7a6 sago007 2010-11-08 21:03 1426
            }
6b1dc7a6 sago007 2010-11-08 21:03 1427
        }
6b1dc7a6 sago007 2010-11-08 21:03 1428
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1429
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1430
                if ((board[j][i]%10 != -1) && (board[j][i]%30 < 7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1431
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1432
                    if (bbomb[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1433
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1434
                    if (getReady[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1435
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1436
                }
6b1dc7a6 sago007 2010-11-08 21:03 1437
                if (board[j][i]%30>6) {
6b1dc7a6 sago007 2010-11-08 21:03 1438
                    if (board[j][i]%30==7)
6b1dc7a6 sago007 2010-11-08 21:03 1439
                        DrawIMG(garbageR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1440
                    if (board[j][i]%30==9)
6b1dc7a6 sago007 2010-11-08 21:03 1441
                        DrawIMG(garbageML, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1442
                    if (board[j][i]%30==10)
6b1dc7a6 sago007 2010-11-08 21:03 1443
                        DrawIMG(garbageMR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1444
                    if (board[j][i]%30==11)
6b1dc7a6 sago007 2010-11-08 21:03 1445
                        DrawIMG(garbageTR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1446
                    if (board[j][i]%30==12)
6b1dc7a6 sago007 2010-11-08 21:03 1447
                        DrawIMG(garbageTL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1448
                    if (board[j][i]%30==13)
6b1dc7a6 sago007 2010-11-08 21:03 1449
                        DrawIMG(garbageBL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1450
                    if (board[j][i]%30==14)
6b1dc7a6 sago007 2010-11-08 21:03 1451
                        DrawIMG(garbageBR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1452
                    if (board[j][i]%30==15)
6b1dc7a6 sago007 2010-11-08 21:03 1453
                        DrawIMG(garbageM, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1454
                    if (board[j][i]%30==16)
6b1dc7a6 sago007 2010-11-08 21:03 1455
                        DrawIMG(garbageFill, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1456
                    if (board[j][i]%30==17)
6b1dc7a6 sago007 2010-11-08 21:03 1457
                        DrawIMG(garbageT, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1458
                    if (board[j][i]%30==18)
6b1dc7a6 sago007 2010-11-08 21:03 1459
                        DrawIMG(garbageB, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1460
                    if (board[j][i]%30==19)
6b1dc7a6 sago007 2010-11-08 21:03 1461
                        DrawIMG(garbageL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1462
                    if (board[j][i]%30==20)
6b1dc7a6 sago007 2010-11-08 21:03 1463
                        switch(j) {
6b1dc7a6 sago007 2010-11-08 21:03 1464
                            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1465
                                DrawIMG(garbageGML, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1466
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1467
                            case 5:
6b1dc7a6 sago007 2010-11-08 21:03 1468
                                DrawIMG(garbageGMR, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1469
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1470
                            default:
6b1dc7a6 sago007 2010-11-08 21:03 1471
                                DrawIMG(garbageGM, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1472
                        }
6b1dc7a6 sago007 2010-11-08 21:03 1473
                    //cout << "IS: " << board[j][i] << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1474
                }
6b1dc7a6 sago007 2010-11-08 21:03 1475
6b1dc7a6 sago007 2010-11-08 21:03 1476
6b1dc7a6 sago007 2010-11-08 21:03 1477
            }
6b1dc7a6 sago007 2010-11-08 21:03 1478
6b1dc7a6 sago007 2010-11-08 21:03 1479
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1480
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1481
            if ((board[0][i]%30==12)&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1482
                DrawIMG(smiley[0], sBoard, 2*bsize, bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1483
            }
6b1dc7a6 sago007 2010-11-08 21:03 1484
            if (board[0][i]%30!=19) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1485
            {
6b1dc7a6 sago007 2010-11-08 21:03 1486
                garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1487
            }
6b1dc7a6 sago007 2010-11-08 21:03 1488
            else {
6b1dc7a6 sago007 2010-11-08 21:03 1489
                //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1490
                garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1491
            }
6b1dc7a6 sago007 2010-11-08 21:03 1492
6b1dc7a6 sago007 2010-11-08 21:03 1493
        }
6b1dc7a6 sago007 2010-11-08 21:03 1494
    }
6b1dc7a6 sago007 2010-11-08 21:03 1495
public:
6b1dc7a6 sago007 2010-11-08 21:03 1496
    //Draws everything
6b1dc7a6 sago007 2010-11-08 21:03 1497
    void DoPaintJob() {
6b1dc7a6 sago007 2010-11-08 21:03 1498
        DrawIMG(backBoard, sBoard, 0, 0);
925b7e58 sago007 2011-04-25 16:35 1499
        nf_standard_blue_font.setDest(sBoard); //reset to screen at the end of this funciton!
6b1dc7a6 sago007 2010-11-08 21:03 1500
        #if NETWORK
6b1dc7a6 sago007 2010-11-08 21:03 1501
        if ((!bReplaying)&&(!bNetworkPlayer))
6b1dc7a6 sago007 2010-11-08 21:03 1502
        #else
6b1dc7a6 sago007 2010-11-08 21:03 1503
        if (!bReplaying)
6b1dc7a6 sago007 2010-11-08 21:03 1504
        #endif
6b1dc7a6 sago007 2010-11-08 21:03 1505
            PaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1506
        else
6b1dc7a6 sago007 2010-11-08 21:03 1507
            SimplePaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1508
        if (stageClear) DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1);
6b1dc7a6 sago007 2010-11-08 21:03 1509
        if (puzzleMode&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1510
            //We need to write nr. of moves left!
6b1dc7a6 sago007 2010-11-08 21:03 1511
            strHolder = "Moves left: " + itoa(MovesLeft);
925b7e58 sago007 2011-04-25 16:35 1512
            nf_standard_blue_font.draw(5,5,strHolder.c_str());
925b7e58 sago007 2011-04-25 16:35 1513
            
6b1dc7a6 sago007 2010-11-08 21:03 1514
        }
6b1dc7a6 sago007 2010-11-08 21:03 1515
        if(puzzleMode && stageButtonStatus == SBpuzzleMode)
6b1dc7a6 sago007 2010-11-08 21:03 1516
        {
6b1dc7a6 sago007 2010-11-08 21:03 1517
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1518
            if(Level<nrOfPuzzles-1)
6b1dc7a6 sago007 2010-11-08 21:03 1519
            {
6b1dc7a6 sago007 2010-11-08 21:03 1520
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1521
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1522
                else
6b1dc7a6 sago007 2010-11-08 21:03 1523
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1524
            }
6b1dc7a6 sago007 2010-11-08 21:03 1525
            else
6b1dc7a6 sago007 2010-11-08 21:03 1526
            {
6b1dc7a6 sago007 2010-11-08 21:03 1527
                strHolder = "Last puzzle";
925b7e58 sago007 2011-04-25 16:35 1528
                nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1529
            }
6b1dc7a6 sago007 2010-11-08 21:03 1530
        }
6b1dc7a6 sago007 2010-11-08 21:03 1531
        if(stageClear && stageButtonStatus == SBstageClear)
6b1dc7a6 sago007 2010-11-08 21:03 1532
        {
6b1dc7a6 sago007 2010-11-08 21:03 1533
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1534
            if(Level<50-1)
6b1dc7a6 sago007 2010-11-08 21:03 1535
            {
6b1dc7a6 sago007 2010-11-08 21:03 1536
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1537
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1538
                else
6b1dc7a6 sago007 2010-11-08 21:03 1539
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1540
            }
6b1dc7a6 sago007 2010-11-08 21:03 1541
            else
6b1dc7a6 sago007 2010-11-08 21:03 1542
            {
6b1dc7a6 sago007 2010-11-08 21:03 1543
                strHolder = "Last stage";
925b7e58 sago007 2011-04-25 16:35 1544
                nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1545
            }
6b1dc7a6 sago007 2010-11-08 21:03 1546
        }
6b1dc7a6 sago007 2010-11-08 21:03 1547
6b1dc7a6 sago007 2010-11-08 21:03 1548
#if DEBUG
6b1dc7a6 sago007 2010-11-08 21:03 1549
        if (AI_Enabled&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1550
            strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear);
925b7e58 sago007 2011-04-25 16:35 1551
            //NFont_Write(sBoard,   5, 5, strHolder.c_str());
925b7e58 sago007 2011-04-25 16:35 1552
            nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1553
        }
6b1dc7a6 sago007 2010-11-08 21:03 1554
#endif
6b1dc7a6 sago007 2010-11-08 21:03 1555
        if (!bGameOver)DrawIMG(cursor[(ticks/600)%2],sBoard,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
6b1dc7a6 sago007 2010-11-08 21:03 1556
        if (ticks<gameStartedAt)
6b1dc7a6 sago007 2010-11-08 21:03 1557
        {
6b1dc7a6 sago007 2010-11-08 21:03 1558
            int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1559
            if( (currentCounter!=lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1560
                Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1561
            lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1562
            switch (currentCounter) {
6b1dc7a6 sago007 2010-11-08 21:03 1563
            case 2:
6b1dc7a6 sago007 2010-11-08 21:03 1564
                DrawIMG(counter[2], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1565
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1566
            case 1:
6b1dc7a6 sago007 2010-11-08 21:03 1567
                DrawIMG(counter[1], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1568
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1569
            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1570
                DrawIMG(counter[0], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1571
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1572
            default:
6b1dc7a6 sago007 2010-11-08 21:03 1573
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1574
            }
6b1dc7a6 sago007 2010-11-08 21:03 1575
        }
6b1dc7a6 sago007 2010-11-08 21:03 1576
        else
6b1dc7a6 sago007 2010-11-08 21:03 1577
        {
6b1dc7a6 sago007 2010-11-08 21:03 1578
            if(SoundEnabled&&(!NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver))
6b1dc7a6 sago007 2010-11-08 21:03 1579
            {
6b1dc7a6 sago007 2010-11-08 21:03 1580
                int currentCounter = (ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1581
                if(currentCounter!=lastCounter)
6b1dc7a6 sago007 2010-11-08 21:03 1582
                {
6b1dc7a6 sago007 2010-11-08 21:03 1583
                    if(currentCounter>115 && currentCounter<120)
6b1dc7a6 sago007 2010-11-08 21:03 1584
                        Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1585
                }
6b1dc7a6 sago007 2010-11-08 21:03 1586
                lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1587
            }
6b1dc7a6 sago007 2010-11-08 21:03 1588
            else
6b1dc7a6 sago007 2010-11-08 21:03 1589
            {
6b1dc7a6 sago007 2010-11-08 21:03 1590
                if( (0==lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1591
                {
6b1dc7a6 sago007 2010-11-08 21:03 1592
                    Mix_PlayChannel(1,counterFinalChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1593
                }
6b1dc7a6 sago007 2010-11-08 21:03 1594
                lastCounter = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1595
            }
6b1dc7a6 sago007 2010-11-08 21:03 1596
        }
6b1dc7a6 sago007 2010-11-08 21:03 1597
6b1dc7a6 sago007 2010-11-08 21:03 1598
        if ((bGameOver)&&(!editorMode))
6b1dc7a6 sago007 2010-11-08 21:03 1599
            if (hasWonTheGame)DrawIMG(iWinner, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1600
            else if (bDraw) DrawIMG(iDraw, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1601
            else
6b1dc7a6 sago007 2010-11-08 21:03 1602
                DrawIMG(iGameOver, sBoard, 0, 5*bsize);
925b7e58 sago007 2011-04-25 16:35 1603
            nf_standard_blue_font.setDest(screen);
6b1dc7a6 sago007 2010-11-08 21:03 1604
    }
6b1dc7a6 sago007 2010-11-08 21:03 1605
6b1dc7a6 sago007 2010-11-08 21:03 1606
6b1dc7a6 sago007 2010-11-08 21:03 1607
    void Update(int newtick) {
6b1dc7a6 sago007 2010-11-08 21:03 1608
        BlockGame::Update(newtick);
6b1dc7a6 sago007 2010-11-08 21:03 1609
        DoPaintJob();
6b1dc7a6 sago007 2010-11-08 21:03 1610
    }
6b1dc7a6 sago007 2010-11-08 21:03 1611
};
6b1dc7a6 sago007 2010-11-08 21:03 1612
6b1dc7a6 sago007 2010-11-08 21:03 1613
6b1dc7a6 sago007 2010-11-08 21:03 1614
6b1dc7a6 sago007 2010-11-08 21:03 1615
89c4a3a6 sago007 2008-08-29 14:32 1616
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
89c4a3a6 sago007 2008-08-29 14:32 1617
void writeScreenShot()
89c4a3a6 sago007 2008-08-29 14:32 1618
{
89c4a3a6 sago007 2008-08-29 14:32 1619
    cout << "Saving screenshot" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1620
    int rightNow = (int)time(NULL);
215ca7b3 sago007 2009-03-06 16:37 1621
/*#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 1622
    char buf[514];
89c4a3a6 sago007 2008-08-29 14:32 1623
    sprintf( buf, "%s/.gamesaves/blockattack/screenshots/screenshot%i.bmp", getenv("HOME"), rightNow );
91886cae sago007 2008-09-12 16:28 1624
#elif defined(__win32__)
89c4a3a6 sago007 2008-08-29 14:32 1625
    char buf[MAX_PATH];
89c4a3a6 sago007 2008-08-29 14:32 1626
    sprintf( buf, "%s\\My Games\\blockattack\\screenshots\\screenshot%i.bmp", (getMyDocumentsPath()).c_str(), rightNow );
91886cae sago007 2008-09-12 16:28 1627
#else
91886cae sago007 2008-09-12 16:28 1628
    char buf[MAX_PATH];
91886cae sago007 2008-09-12 16:28 1629
    sprintf( buf, "screenshot%i.bmp", rightNow );
215ca7b3 sago007 2009-03-06 16:37 1630
#endif*/
215ca7b3 sago007 2009-03-06 16:37 1631
#if defined(__unix__)
215ca7b3 sago007 2009-03-06 16:37 1632
    string buf = (string)getenv("HOME")+"/.gamesaves/blockattack/screenshots/screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1633
#elif defined(__win32__)
215ca7b3 sago007 2009-03-06 16:37 1634
    string buf = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots\\screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1635
#else
215ca7b3 sago007 2009-03-06 16:37 1636
    string buf = "screenshot"+itoa(rightNow)+".bmp";
89c4a3a6 sago007 2008-08-29 14:32 1637
#endif
215ca7b3 sago007 2009-03-06 16:37 1638
    SDL_SaveBMP( screen, buf.c_str() );
89c4a3a6 sago007 2008-08-29 14:32 1639
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 1640
        if (SoundEnabled)Mix_PlayChannel(1,photoClick,0);
89c4a3a6 sago007 2008-08-29 14:32 1641
}
89c4a3a6 sago007 2008-08-29 14:32 1642
89c4a3a6 sago007 2008-08-29 14:32 1643
//Function to return the name of a key, to be displayed...
593aeae4 sago007 2011-06-25 22:42 1644
static string getKeyName(SDLKey key)
89c4a3a6 sago007 2008-08-29 14:32 1645
{
4b0c248f sago007 2010-11-10 21:13 1646
    string keyname(SDL_GetKeyName(key));
215ca7b3 sago007 2009-03-06 16:37 1647
    return keyname;
89c4a3a6 sago007 2008-08-29 14:32 1648
}
89c4a3a6 sago007 2008-08-29 14:32 1649
89c4a3a6 sago007 2008-08-29 14:32 1650
void MakeBackground(int xsize,int ysize,BlockGame &theGame, BlockGame &theGame2);
89c4a3a6 sago007 2008-08-29 14:32 1651
14e13624 sago007 2011-07-20 17:14 1652
/*int OpenControlsBox(int x, int y, int player)
89c4a3a6 sago007 2008-08-29 14:32 1653
{
89c4a3a6 sago007 2008-08-29 14:32 1654
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 1655
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 1656
    bool done =false;
215ca7b3 sago007 2009-03-06 16:37 1657
    string keyname;
27ae0175 sago007 2009-01-30 06:02 1658
    MakeBackground(xsize,ysize);
cc3ef158 sago007 2011-07-03 16:13 1659
    while (!done && !Config::getInstance()->isShuttingDown())
89c4a3a6 sago007 2008-08-29 14:32 1660
    {
89c4a3a6 sago007 2008-08-29 14:32 1661
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 1662
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1663
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 1664
        if (player == 0)
925b7e58 sago007 2011-04-25 16:35 1665
            NFont_Write(screen, x+40,y+2,"Player 1 keys");
89c4a3a6 sago007 2008-08-29 14:32 1666
        else
925b7e58 sago007 2011-04-25 16:35 1667
            NFont_Write(screen, x+40,y+2,"Player 2 keys");
925b7e58 sago007 2011-04-25 16:35 1668
        NFont_Write(screen, x+6,y+50,"Up");
89c4a3a6 sago007 2008-08-29 14:32 1669
        keyname = getKeyName(keySettings[player].up);
925b7e58 sago007 2011-04-25 16:35 1670
        NFont_Write(screen, x+200,y+50,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1671
        NFont_Write(screen, x+6,y+100,"Down");
89c4a3a6 sago007 2008-08-29 14:32 1672
        keyname = getKeyName(keySettings[player].down);
925b7e58 sago007 2011-04-25 16:35 1673
        NFont_Write(screen, x+200,y+100,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1674
        NFont_Write(screen, x+6,y+150,"Left");
89c4a3a6 sago007 2008-08-29 14:32 1675
        keyname = getKeyName(keySettings[player].left);
925b7e58 sago007 2011-04-25 16:35 1676
        NFont_Write(screen, x+200,y+150,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1677
        NFont_Write(screen, x+6,y+200,"Right");
89c4a3a6 sago007 2008-08-29 14:32 1678
        keyname = getKeyName(keySettings[player].right);
925b7e58 sago007 2011-04-25 16:35 1679
        NFont_Write(screen, x+200,y+200,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1680
        NFont_Write(screen, x+6,y+250,"Push");
89c4a3a6 sago007 2008-08-29 14:32 1681
        keyname = getKeyName(keySettings[player].push);
925b7e58 sago007 2011-04-25 16:35 1682
        NFont_Write(screen, x+200,y+250,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1683
        NFont_Write(screen, x+6,y+300,"Change");
89c4a3a6 sago007 2008-08-29 14:32 1684
        keyname = getKeyName(keySettings[player].change);
925b7e58 sago007 2011-04-25 16:35 1685
        NFont_Write(screen, x+200,y+300,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1686
        //Ask for mouse play
925b7e58 sago007 2011-04-25 16:35 1687
        NFont_Write(screen, x+6,y+350,"Mouse play?");
89c4a3a6 sago007 2008-08-29 14:32 1688
        DrawIMG(iLevelCheckBox,screen,x+220,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1689
        if (((player==0)&&(mouseplay1))||((player==2)&&(mouseplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1690
            DrawIMG(iLevelCheck,screen,x+220,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1691
        //Ask for joypad play
925b7e58 sago007 2011-04-25 16:35 1692
        NFont_Write(screen, x+300,y+350,"Joypad?");
89c4a3a6 sago007 2008-08-29 14:32 1693
        DrawIMG(iLevelCheckBox,screen,x+460,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1694
        if (((player==0)&&(joyplay1))||((player==2)&&(joyplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1695
            DrawIMG(iLevelCheck,screen,x+460,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1696
        for (int i=1; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 1697
            DrawIMG(bChange,screen,x+420,y+50*i);
89c4a3a6 sago007 2008-08-29 14:32 1698
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1699
89c4a3a6 sago007 2008-08-29 14:32 1700
        while (SDL_PollEvent(&event))
89c4a3a6 sago007 2008-08-29 14:32 1701
        {
89c4a3a6 sago007 2008-08-29 14:32 1702
            if ( event.type == SDL_QUIT )  {
cc3ef158 sago007 2011-07-03 16:13 1703
                Config::getInstance()->setShuttingDown(5);
89c4a3a6 sago007 2008-08-29 14:32 1704
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1705
            }
89c4a3a6 sago007 2008-08-29 14:32 1706
89c4a3a6 sago007 2008-08-29 14:32 1707
            if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1708
            {
89c4a3a6 sago007 2008-08-29 14:32 1709
                if (event.key.keysym.sym == SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1710
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1711
            }
89c4a3a6 sago007 2008-08-29 14:32 1712
        }	//PollEvent
89c4a3a6 sago007 2008-08-29 14:32 1713
89c4a3a6 sago007 2008-08-29 14:32 1714
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1715
89c4a3a6 sago007 2008-08-29 14:32 1716
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 1717
89c4a3a6 sago007 2008-08-29 14:32 1718
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 1719
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 1720
        {
89c4a3a6 sago007 2008-08-29 14:32 1721
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 1722
        }
89c4a3a6 sago007 2008-08-29 14:32 1723
89c4a3a6 sago007 2008-08-29 14:32 1724
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 1725
        {
89c4a3a6 sago007 2008-08-29 14:32 1726
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 1727
89c4a3a6 sago007 2008-08-29 14:32 1728
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(50+y)) && (mousey<(90+y)))
89c4a3a6 sago007 2008-08-29 14:32 1729
            {
89c4a3a6 sago007 2008-08-29 14:32 1730
                //up
89c4a3a6 sago007 2008-08-29 14:32 1731
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1732
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1733
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1734
                    {
89c4a3a6 sago007 2008-08-29 14:32 1735
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1736
                        {
89c4a3a6 sago007 2008-08-29 14:32 1737
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1738
                                keySettings[player].up = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1739
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1740
                        }
89c4a3a6 sago007 2008-08-29 14:32 1741
                    }
89c4a3a6 sago007 2008-08-29 14:32 1742
            } //up
89c4a3a6 sago007 2008-08-29 14:32 1743
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(100+y)) && (mousey<(140+y)))
89c4a3a6 sago007 2008-08-29 14:32 1744
            {
89c4a3a6 sago007 2008-08-29 14:32 1745
                //down
89c4a3a6 sago007 2008-08-29 14:32 1746
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1747
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1748
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1749
                    {
89c4a3a6 sago007 2008-08-29 14:32 1750
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1751
                        {
89c4a3a6 sago007 2008-08-29 14:32 1752
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1753
                                keySettings[player].down = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1754
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1755
                        }
89c4a3a6 sago007 2008-08-29 14:32 1756
                    }
89c4a3a6 sago007 2008-08-29 14:32 1757
            } //down
89c4a3a6 sago007 2008-08-29 14:32 1758
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(150+y)) && (mousey<(190+y)))
89c4a3a6 sago007 2008-08-29 14:32 1759
            {
89c4a3a6 sago007 2008-08-29 14:32 1760
                //left
89c4a3a6 sago007 2008-08-29 14:32 1761
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1762
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1763
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1764
                    {
89c4a3a6 sago007 2008-08-29 14:32 1765
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1766
                        {
89c4a3a6 sago007 2008-08-29 14:32 1767
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1768
                                keySettings[player].left = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1769
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1770
                        }
89c4a3a6 sago007 2008-08-29 14:32 1771
                    }
89c4a3a6 sago007 2008-08-29 14:32 1772
            } //left
89c4a3a6 sago007 2008-08-29 14:32 1773
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(200+y)) && (mousey<(240+y)))
89c4a3a6 sago007 2008-08-29 14:32 1774
            {
89c4a3a6 sago007 2008-08-29 14:32 1775
                //right
89c4a3a6 sago007 2008-08-29 14:32 1776
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1777
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1778
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1779
                    {
89c4a3a6 sago007 2008-08-29 14:32 1780
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1781
                        {
89c4a3a6 sago007 2008-08-29 14:32 1782
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1783
                                keySettings[player].right = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1784
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1785
                        }
89c4a3a6 sago007 2008-08-29 14:32 1786
                    }
89c4a3a6 sago007 2008-08-29 14:32 1787
            } //right
89c4a3a6 sago007 2008-08-29 14:32 1788
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(250+y)) && (mousey<(290+y)))
89c4a3a6 sago007 2008-08-29 14:32 1789
            {
89c4a3a6 sago007 2008-08-29 14:32 1790
                //push
89c4a3a6 sago007 2008-08-29 14:32 1791
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1792
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1793
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1794
                    {
89c4a3a6 sago007 2008-08-29 14:32 1795
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1796
                        {
89c4a3a6 sago007 2008-08-29 14:32 1797
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1798
                                keySettings[player].push = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1799
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1800
                        }
89c4a3a6 sago007 2008-08-29 14:32 1801
                    }
89c4a3a6 sago007 2008-08-29 14:32 1802
            } //push
89c4a3a6 sago007 2008-08-29 14:32 1803
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(300+y)) && (mousey<(340+y)))
89c4a3a6 sago007 2008-08-29 14:32 1804
            {
89c4a3a6 sago007 2008-08-29 14:32 1805
                //change
89c4a3a6 sago007 2008-08-29 14:32 1806
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1807
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1808
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1809
                    {
89c4a3a6 sago007 2008-08-29 14:32 1810
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1811
                        {
89c4a3a6 sago007 2008-08-29 14:32 1812
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1813
                                keySettings[player].change = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1814
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1815
                        }
89c4a3a6 sago007 2008-08-29 14:32 1816
                    }
89c4a3a6 sago007 2008-08-29 14:32 1817
            } //change
89c4a3a6 sago007 2008-08-29 14:32 1818
            //mouseplay:
89c4a3a6 sago007 2008-08-29 14:32 1819
            if ((mousex>(220+x)) && (mousex<(262+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1820
            {
89c4a3a6 sago007 2008-08-29 14:32 1821
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1822
                {
89c4a3a6 sago007 2008-08-29 14:32 1823
                    mouseplay1 = !mouseplay1;
89c4a3a6 sago007 2008-08-29 14:32 1824
                }
89c4a3a6 sago007 2008-08-29 14:32 1825
                else
89c4a3a6 sago007 2008-08-29 14:32 1826
                {
89c4a3a6 sago007 2008-08-29 14:32 1827
                    mouseplay2 = !mouseplay2;
89c4a3a6 sago007 2008-08-29 14:32 1828
                }
89c4a3a6 sago007 2008-08-29 14:32 1829
            }
89c4a3a6 sago007 2008-08-29 14:32 1830
            //Joyplay:
89c4a3a6 sago007 2008-08-29 14:32 1831
            if ((mousex>(460+x)) && (mousex<(502+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1832
            {
89c4a3a6 sago007 2008-08-29 14:32 1833
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1834
                {
89c4a3a6 sago007 2008-08-29 14:32 1835
                    joyplay1 = !joyplay1;
89c4a3a6 sago007 2008-08-29 14:32 1836
                }
89c4a3a6 sago007 2008-08-29 14:32 1837
                else
89c4a3a6 sago007 2008-08-29 14:32 1838
                {
89c4a3a6 sago007 2008-08-29 14:32 1839
                    joyplay2 = !joyplay2;
89c4a3a6 sago007 2008-08-29 14:32 1840
                }
89c4a3a6 sago007 2008-08-29 14:32 1841
            }
89c4a3a6 sago007 2008-08-29 14:32 1842
        }	//get mouse state
89c4a3a6 sago007 2008-08-29 14:32 1843
8d488d32 sago007 2011-04-17 13:02 1844
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 1845
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 1846
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 1847
    }	//while !done
89c4a3a6 sago007 2008-08-29 14:32 1848
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1849
    return 0;
14e13624 sago007 2011-07-20 17:14 1850
}**/
89c4a3a6 sago007 2008-08-29 14:32 1851
89c4a3a6 sago007 2008-08-29 14:32 1852
89c4a3a6 sago007 2008-08-29 14:32 1853
//Dialogbox
89c4a3a6 sago007 2008-08-29 14:32 1854
bool OpenDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 1855
{
89c4a3a6 sago007 2008-08-29 14:32 1856
    bool done = false;     //We are done!
89c4a3a6 sago007 2008-08-29 14:32 1857
    bool accept = false;   //New name is accepted! (not Cancelled)
89c4a3a6 sago007 2008-08-29 14:32 1858
    bool repeating = false; //The key is being held (BACKSPACE)
89c4a3a6 sago007 2008-08-29 14:32 1859
    const int repeatDelay = 200;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 1860
    unsigned long time = 0;
89c4a3a6 sago007 2008-08-29 14:32 1861
    ReadKeyboard rk = ReadKeyboard(name);
89c4a3a6 sago007 2008-08-29 14:32 1862
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 1863
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 1864
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1865
    DrawIMG(background,screen,0,0);
cc3ef158 sago007 2011-07-03 16:13 1866
    while (!done && !Config::getInstance()->isShuttingDown())
89c4a3a6 sago007 2008-08-29 14:32 1867
    {
89c4a3a6 sago007 2008-08-29 14:32 1868
        DrawIMG(dialogBox,screen,x,y);
71181267 sago007 2011-04-29 19:22 1869
        NFont_Write(screen, x+40,y+76,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1870
        strHolder = rk.GetString();
89c4a3a6 sago007 2008-08-29 14:32 1871
        strHolder.erase((int)rk.CharsBeforeCursor());
89c4a3a6 sago007 2008-08-29 14:32 1872
89c4a3a6 sago007 2008-08-29 14:32 1873
        if (((SDL_GetTicks()/600)%2)==1)
71181267 sago007 2011-04-29 19:22 1874
            NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( strHolder.c_str()),y+76,"|");
89c4a3a6 sago007 2008-08-29 14:32 1875
89c4a3a6 sago007 2008-08-29 14:32 1876
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1877
89c4a3a6 sago007 2008-08-29 14:32 1878
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1879
        {
89c4a3a6 sago007 2008-08-29 14:32 1880
            if ( event.type == SDL_QUIT )  {
cc3ef158 sago007 2011-07-03 16:13 1881
                Config::getInstance()->setShuttingDown(5);
89c4a3a6 sago007 2008-08-29 14:32 1882
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1883
                accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1884
            }
89c4a3a6 sago007 2008-08-29 14:32 1885
89c4a3a6 sago007 2008-08-29 14:32 1886
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 1887
            {
89c4a3a6 sago007 2008-08-29 14:32 1888
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
89c4a3a6 sago007 2008-08-29 14:32 1889
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1890
                    accept = true;
89c4a3a6 sago007 2008-08-29 14:32 1891
                }
89c4a3a6 sago007 2008-08-29 14:32 1892
                else
89c4a3a6 sago007 2008-08-29 14:32 1893
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 1894
                        done = true;
89c4a3a6 sago007 2008-08-29 14:32 1895
                        accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1896
                    }
89c4a3a6 sago007 2008-08-29 14:32 1897
                    else if (!(event.key.keysym.sym == SDLK_BACKSPACE)){
89c4a3a6 sago007 2008-08-29 14:32 1898
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1899
                    }
89c4a3a6 sago007 2008-08-29 14:32 1900
                    else if ((event.key.keysym.sym == SDLK_BACKSPACE)&&(!repeating)){
89c4a3a6 sago007 2008-08-29 14:32 1901
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1902
                        repeating = true;
89c4a3a6 sago007 2008-08-29 14:32 1903
                        time=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1904
                    }
89c4a3a6 sago007 2008-08-29 14:32 1905
            }
89c4a3a6 sago007 2008-08-29 14:32 1906
89c4a3a6 sago007 2008-08-29 14:32 1907
        }	//while(event)
89c4a3a6 sago007 2008-08-29 14:32 1908
89c4a3a6 sago007 2008-08-29 14:32 1909
        if (SDL_GetTicks()>(time+repeatDelay))
89c4a3a6 sago007 2008-08-29 14:32 1910
        {
89c4a3a6 sago007 2008-08-29 14:32 1911
            time = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1912
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1913
            if ( (keys[SDLK_BACKSPACE])&&(repeating) )
89c4a3a6 sago007 2008-08-29 14:32 1914
            {
89c4a3a6 sago007 2008-08-29 14:32 1915
                if ((rk.ReadKey(SDLK_BACKSPACE))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1916
            }
89c4a3a6 sago007 2008-08-29 14:32 1917
            else
89c4a3a6 sago007 2008-08-29 14:32 1918
                repeating = false;
89c4a3a6 sago007 2008-08-29 14:32 1919
        }
89c4a3a6 sago007 2008-08-29 14:32 1920
89c4a3a6 sago007 2008-08-29 14:32 1921
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 1922
    }	//while(!done)
89c4a3a6 sago007 2008-08-29 14:32 1923
    strcpy(name,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1924
    bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 1925
    showDialog = false;
89c4a3a6 sago007 2008-08-29 14:32 1926
    return accept;
89c4a3a6 sago007 2008-08-29 14:32 1927
}
89c4a3a6 sago007 2008-08-29 14:32 1928
47529580 sago007 2008-12-09 02:34 1929
//Draws the highscores
47529580 sago007 2008-12-09 02:34 1930
void DrawHighscores(int x, int y, bool endless)
47529580 sago007 2008-12-09 02:34 1931
{
27ae0175 sago007 2009-01-30 06:02 1932
    MakeBackground(xsize,ysize);
47529580 sago007 2008-12-09 02:34 1933
    DrawIMG(background,screen,0,0);
c9dd376f sago007 2012-01-20 17:13 1934
    if (endless) nf_standard_blue_font.draw(x+100,y+100,_("Endless:") );
c9dd376f sago007 2012-01-20 17:13 1935
    else nf_standard_blue_font.draw(x+100,y+100,_("Time Trial:") ); 
47529580 sago007 2008-12-09 02:34 1936
    for (int i =0;i<10;i++)
47529580 sago007 2008-12-09 02:34 1937
    {
47529580 sago007 2008-12-09 02:34 1938
        char playerScore[32];
47529580 sago007 2008-12-09 02:34 1939
        char playerName[32];
47529580 sago007 2008-12-09 02:34 1940
        if (endless)
47529580 sago007 2008-12-09 02:34 1941
        {
47529580 sago007 2008-12-09 02:34 1942
            sprintf(playerScore, "%i", theTopScoresEndless.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1943
        }
47529580 sago007 2008-12-09 02:34 1944
        else
47529580 sago007 2008-12-09 02:34 1945
        {
47529580 sago007 2008-12-09 02:34 1946
            sprintf(playerScore, "%i", theTopScoresTimeTrial.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1947
        }
47529580 sago007 2008-12-09 02:34 1948
        if (endless)
47529580 sago007 2008-12-09 02:34 1949
        {
47529580 sago007 2008-12-09 02:34 1950
            strcpy(playerName,theTopScoresEndless.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1951
        }
47529580 sago007 2008-12-09 02:34 1952
        else
47529580 sago007 2008-12-09 02:34 1953
        {
47529580 sago007 2008-12-09 02:34 1954
            strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1955
        }
925b7e58 sago007 2011-04-25 16:35 1956
        nf_standard_blue_font.draw(x+420,y+150+i*35,playerScore);
925b7e58 sago007 2011-04-25 16:35 1957
        nf_standard_blue_font.draw(x+60,y+150+i*35,playerName);
47529580 sago007 2008-12-09 02:34 1958
    }
47529580 sago007 2008-12-09 02:34 1959
}
47529580 sago007 2008-12-09 02:34 1960
47529580 sago007 2008-12-09 02:34 1961
void DrawStats()
81d9c25d sago007 2008-11-24 09:50 1962
{
27ae0175 sago007 2009-01-30 06:02 1963
    MakeBackground(xsize,ysize);
81d9c25d sago007 2008-11-24 09:50 1964
    DrawIMG(background,screen,0,0);
81d9c25d sago007 2008-11-24 09:50 1965
    int y = 5;
81d9c25d sago007 2008-11-24 09:50 1966
    const int y_spacing = 30;
c9dd376f sago007 2012-01-20 17:13 1967
    NFont_Write(screen, 10,y,_("Stats") );
81d9c25d sago007 2008-11-24 09:50 1968
    y+=y_spacing*2;
c9dd376f sago007 2012-01-20 17:13 1969
    NFont_Write(screen, 10,y,_("Chains") );
81d9c25d sago007 2008-11-24 09:50 1970
    for(int i=2;i<13;i++)
81d9c25d sago007 2008-11-24 09:50 1971
    {
81d9c25d sago007 2008-11-24 09:50 1972
        y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1973
        NFont_Write(screen, 10,y,(itoa(i)+"X").c_str());
81d9c25d sago007 2008-11-24 09:50 1974
        string numberAsString = itoa(Stats::getInstance()->getNumberOf("chainX"+itoa(i)));
925b7e58 sago007 2011-04-25 16:35 1975
        NFont_Write(screen, 300,y,numberAsString.c_str());
81d9c25d sago007 2008-11-24 09:50 1976
    }
81d9c25d sago007 2008-11-24 09:50 1977
    y+=y_spacing*2;
c9dd376f sago007 2012-01-20 17:13 1978
    NFont_Write(screen, 10,y,_("Lines Pushed: ") );
81d9c25d sago007 2008-11-24 09:50 1979
    string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed"));
925b7e58 sago007 2011-04-25 16:35 1980
    NFont_Write(screen, 300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 1981
81d9c25d sago007 2008-11-24 09:50 1982
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 1983
    NFont_Write(screen, 10,y, _("Puzzles solved: ") );
81d9c25d sago007 2008-11-24 09:50 1984
    numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved"));
925b7e58 sago007 2011-04-25 16:35 1985
    NFont_Write(screen, 300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 1986
d07b805e sago007 2009-01-27 13:15 1987
    y+=y_spacing*2;
c9dd376f sago007 2012-01-20 17:13 1988
    NFont_Write(screen, 10,y, _("Run time: ") );
cd12e0fe sago007 2009-01-29 08:47 1989
    commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
d07b805e sago007 2009-01-27 13:15 1990
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 1991
    NFont_Write(screen, 10,y,((string)( _("Days: ")+itoa(ct.days))).c_str());
d07b805e sago007 2009-01-27 13:15 1992
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 1993
    NFont_Write(screen, 10,y,((string)( _("Hours: ")+itoa(ct.hours))).c_str());
d07b805e sago007 2009-01-27 13:15 1994
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 1995
    NFont_Write(screen, 10,y,((string)( _("Minutes: ")+itoa(ct.minutes))).c_str());
d07b805e sago007 2009-01-27 13:15 1996
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 1997
    NFont_Write(screen, 10,y,((string)( _("Seconds: ")+itoa(ct.seconds))).c_str());
d07b805e sago007 2009-01-27 13:15 1998
cd12e0fe sago007 2009-01-29 08:47 1999
    y-=y_spacing*4; //Four rows back
27ae0175 sago007 2009-01-30 06:02 2000
    const int x_offset3 = xsize/3+10; //Ofset for three rows
c9dd376f sago007 2012-01-20 17:13 2001
    NFont_Write(screen, x_offset3,y, _("Play time: ") );
cd12e0fe sago007 2009-01-29 08:47 2002
    ct = TimeHandler::getTime("playTime");
cd12e0fe sago007 2009-01-29 08:47 2003
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 2004
    NFont_Write(screen, x_offset3,y,((string)( _("Days: ")+itoa(ct.days))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2005
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 2006
    NFont_Write(screen, x_offset3,y,((string)( _("Hours: ")+itoa(ct.hours))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2007
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 2008
    NFont_Write(screen, x_offset3,y,((string)( _("Minutes: ")+itoa(ct.minutes))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2009
    y+=y_spacing;
c9dd376f sago007 2012-01-20 17:13 2010
    NFont_Write(screen, x_offset3,y,((string)( _("Seconds: ")+itoa(ct.seconds))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2011
27ae0175 sago007 2009-01-30 06:02 2012
    const int x_offset = xsize/2+10;
81d9c25d sago007 2008-11-24 09:50 2013
    y = 5+y_spacing*2;
c9dd376f sago007 2012-01-20 17:13 2014
    NFont_Write(screen, x_offset,y, _("VS CPU (win/loss)") );
81d9c25d sago007 2008-11-24 09:50 2015
    for(int i=0;i<7;i++)
81d9c25d sago007 2008-11-24 09:50 2016
    {
81d9c25d sago007 2008-11-24 09:50 2017
        y += y_spacing;
925b7e58 sago007 2011-04-25 16:35 2018
        NFont_Write(screen, x_offset,y,("AI "+itoa(i+1)).c_str());
81d9c25d sago007 2008-11-24 09:50 2019
        numberAsString = itoa(Stats::getInstance()->getNumberOf("defeatedAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2020
        string numberAsString2 = itoa(Stats::getInstance()->getNumberOf("defeatedByAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2021
        string toPrint = numberAsString + "/" + numberAsString2;
925b7e58 sago007 2011-04-25 16:35 2022
        NFont_Write(screen, x_offset+230,y,toPrint.c_str());
81d9c25d sago007 2008-11-24 09:50 2023
    }
47529580 sago007 2008-12-09 02:34 2024
}
47529580 sago007 2008-12-09 02:34 2025
47529580 sago007 2008-12-09 02:34 2026
void OpenScoresDisplay()
47529580 sago007 2008-12-09 02:34 2027
{
9050a50a sago007 2008-12-09 13:35 2028
    int mousex,mousey;
47529580 sago007 2008-12-09 02:34 2029
    bool done = false;     //We are done!
47529580 sago007 2008-12-09 02:34 2030
    int page = 0;
47529580 sago007 2008-12-09 02:34 2031
    const int numberOfPages = 3;
7ca669ac sago007 2008-12-09 16:30 2032
    //button coodinates:
7ca669ac sago007 2008-12-09 16:30 2033
    const int scoreX = buttonXsize*2;
7ca669ac sago007 2008-12-09 16:30 2034
    const int scoreY = 0;
7ca669ac sago007 2008-12-09 16:30 2035
    const int backX = 20;
7ca669ac sago007 2008-12-09 16:30 2036
    const int backY = ysize-buttonYsize-20;
7ca669ac sago007 2008-12-09 16:30 2037
    const int nextX = xsize-buttonXsize-20;
7ca669ac sago007 2008-12-09 16:30 2038
    const int nextY = backY;
cc3ef158 sago007 2011-07-03 16:13 2039
    while (!done && !Config::getInstance()->isShuttingDown())
81d9c25d sago007 2008-11-24 09:50 2040
    {
47529580 sago007 2008-12-09 02:34 2041
        switch(page)
47529580 sago007 2008-12-09 02:34 2042
        {
47529580 sago007 2008-12-09 02:34 2043
            case 0:
47529580 sago007 2008-12-09 02:34 2044
                //Highscores, endless
47529580 sago007 2008-12-09 02:34 2045
                DrawHighscores(100,100,true);
47529580 sago007 2008-12-09 02:34 2046
                break;
47529580 sago007 2008-12-09 02:34 2047
            case 1:
47529580 sago007 2008-12-09 02:34 2048
                //Highscores, Time Trial
47529580 sago007 2008-12-09 02:34 2049
                DrawHighscores(100,100,false);
47529580 sago007 2008-12-09 02:34 2050
                break;
47529580 sago007 2008-12-09 02:34 2051
            case 2:
47529580 sago007 2008-12-09 02:34 2052
            default:
47529580 sago007 2008-12-09 02:34 2053
                DrawStats();
47529580 sago007 2008-12-09 02:34 2054
        };
47529580 sago007 2008-12-09 02:34 2055
7ca669ac sago007 2008-12-09 16:30 2056
        //Draw buttons:
7ca669ac sago007 2008-12-09 16:30 2057
        DrawIMG(bHighScore,screen,scoreX,scoreY);
7ca669ac sago007 2008-12-09 16:30 2058
        DrawIMG(bBack,screen,backX,backY);
7ca669ac sago007 2008-12-09 16:30 2059
        DrawIMG(bNext,screen,nextX,nextY);
7ca669ac sago007 2008-12-09 16:30 2060
7ca669ac sago007 2008-12-09 16:30 2061
        //Draw page number
c9dd376f sago007 2012-01-20 17:13 2062
        string pageXofY = (format(_("Page %1% of %2%") )%(page+1)%numberOfPages).str(); 
925b7e58 sago007 2011-04-25 16:35 2063
        NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
9050a50a sago007 2008-12-09 13:35 2064
        
81d9c25d sago007 2008-11-24 09:50 2065
        SDL_Delay(10);
81d9c25d sago007 2008-11-24 09:50 2066
        SDL_Event event;
9050a50a sago007 2008-12-09 13:35 2067
9050a50a sago007 2008-12-09 13:35 2068
        SDL_GetMouseState(&mousex,&mousey);
81d9c25d sago007 2008-11-24 09:50 2069
        
81d9c25d sago007 2008-11-24 09:50 2070
        while ( SDL_PollEvent(&event) )
81d9c25d sago007 2008-11-24 09:50 2071
        {
9050a50a sago007 2008-12-09 13:35 2072
9050a50a sago007 2008-12-09 13:35 2073
81d9c25d sago007 2008-11-24 09:50 2074
            if ( event.type == SDL_QUIT )  {
cc3ef158 sago007 2011-07-03 16:13 2075
                Config::getInstance()->setShuttingDown(5);
81d9c25d sago007 2008-11-24 09:50 2076
                done = true;
81d9c25d sago007 2008-11-24 09:50 2077
            }
81d9c25d sago007 2008-11-24 09:50 2078
81d9c25d sago007 2008-11-24 09:50 2079
            if ( event.type == SDL_KEYDOWN )
81d9c25d sago007 2008-11-24 09:50 2080
            {
47529580 sago007 2008-12-09 02:34 2081
                if( (event.key.keysym.sym == SDLK_RIGHT))
47529580 sago007 2008-12-09 02:34 2082
                {
47529580 sago007 2008-12-09 02:34 2083
                    page++;
47529580 sago007 2008-12-09 02:34 2084
                    if(page>=numberOfPages)
47529580 sago007 2008-12-09 02:34 2085
                        page = 0;
47529580 sago007 2008-12-09 02:34 2086
                }
7ca669ac sago007 2008-12-09 16:30 2087
                else
47529580 sago007 2008-12-09 02:34 2088
                if( (event.key.keysym.sym == SDLK_LEFT))
47529580 sago007 2008-12-09 02:34 2089
                {
47529580 sago007 2008-12-09 02:34 2090
                    page--;
47529580 sago007 2008-12-09 02:34 2091
                    if(page<0)
47529580 sago007 2008-12-09 02:34 2092
                        page = numberOfPages-1;
47529580 sago007 2008-12-09 02:34 2093
                }
7ca669ac sago007 2008-12-09 16:30 2094
                else
7ca669ac sago007 2008-12-09 16:30 2095
                    done = true;
fcd5a134 sago007 2008-12-19 01:11 2096
                
fcd5a134 sago007 2008-12-19 01:11 2097
                if ( event.key.keysym.sym == SDLK_F9 ) {
fcd5a134 sago007 2008-12-19 01:11 2098
                    writeScreenShot();
fcd5a134 sago007 2008-12-19 01:11 2099
                }
47529580 sago007 2008-12-09 02:34 2100
81d9c25d sago007 2008-11-24 09:50 2101
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
81d9c25d sago007 2008-11-24 09:50 2102
                    done = true;
81d9c25d sago007 2008-11-24 09:50 2103
                }
81d9c25d sago007 2008-11-24 09:50 2104
                else
81d9c25d sago007 2008-11-24 09:50 2105
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
81d9c25d sago007 2008-11-24 09:50 2106
                        done = true;
81d9c25d sago007 2008-11-24 09:50 2107
                    }
81d9c25d sago007 2008-11-24 09:50 2108
            }
81d9c25d sago007 2008-11-24 09:50 2109
81d9c25d sago007 2008-11-24 09:50 2110
        }	//while(event)
7ca669ac sago007 2008-12-09 16:30 2111
7ca669ac sago007 2008-12-09 16:30 2112
        // If the mouse button is released, make bMouseUp equal true
7ca669ac sago007 2008-12-09 16:30 2113
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
7ca669ac sago007 2008-12-09 16:30 2114
        {
7ca669ac sago007 2008-12-09 16:30 2115
            bMouseUp=true;
7ca669ac sago007 2008-12-09 16:30 2116
        }
7ca669ac sago007 2008-12-09 16:30 2117
7ca669ac sago007 2008-12-09 16:30 2118
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
7ca669ac sago007 2008-12-09 16:30 2119
        {
7ca669ac sago007 2008-12-09 16:30 2120
            bMouseUp = false;
7ca669ac sago007 2008-12-09 16:30 2121
7ca669ac sago007 2008-12-09 16:30 2122
            //The Score button:
7ca669ac sago007 2008-12-09 16:30 2123
            if((mousex>scoreX) && (mousex<scoreX+buttonXsize) && (mousey>scoreY) && (mousey<scoreY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2124
                done =true;
7ca669ac sago007 2008-12-09 16:30 2125
7ca669ac sago007 2008-12-09 16:30 2126
            //The back button:
7ca669ac sago007 2008-12-09 16:30 2127
            if((mousex>backX) && (mousex<backX+buttonXsize) && (mousey>backY) && (mousey<backY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2128
            {
7ca669ac sago007 2008-12-09 16:30 2129
                page--;
7ca669ac sago007 2008-12-09 16:30 2130
                if(page<0)
7ca669ac sago007 2008-12-09 16:30 2131
                    page = numberOfPages-1;
7ca669ac sago007 2008-12-09 16:30 2132
            }
7ca669ac sago007 2008-12-09 16:30 2133
7ca669ac sago007 2008-12-09 16:30 2134
            //The next button:
7ca669ac sago007 2008-12-09 16:30 2135
            if((mousex>nextX) && (mousex<nextX+buttonXsize) && (mousey>nextY) && (mousey<nextY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2136
            {
7ca669ac sago007 2008-12-09 16:30 2137
                page++;
7ca669ac sago007 2008-12-09 16:30 2138
                if(page>=numberOfPages)
7ca669ac sago007 2008-12-09 16:30 2139
                    page = 0;
7ca669ac sago007 2008-12-09 16:30 2140
            }
7ca669ac sago007 2008-12-09 16:30 2141
        }
7ca669ac sago007 2008-12-09 16:30 2142
8d488d32 sago007 2011-04-17 13:02 2143
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2144
        mouse.PaintTo(screen,mousex,mousey);
9050a50a sago007 2008-12-09 13:35 2145
        SDL_Flip(screen); //Update screen
81d9c25d sago007 2008-11-24 09:50 2146
    }
6b1dc7a6 sago007 2010-11-08 21:03 2147
6b1dc7a6 sago007 2010-11-08 21:03 2148
81d9c25d sago007 2008-11-24 09:50 2149
}
81d9c25d sago007 2008-11-24 09:50 2150
89c4a3a6 sago007 2008-08-29 14:32 2151
89c4a3a6 sago007 2008-08-29 14:32 2152
//Open a puzzle file
89c4a3a6 sago007 2008-08-29 14:32 2153
bool OpenFileDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2154
{
89c4a3a6 sago007 2008-08-29 14:32 2155
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2156
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2157
    ListFiles lf = ListFiles();
aca2f4b0 sago007 2009-05-10 18:11 2158
    string folder = (string)SHAREDIR+(string)"/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2159
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2160
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2161
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2162
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2163
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2164
#endif
89c4a3a6 sago007 2008-08-29 14:32 2165
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2166
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2167
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2168
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2169
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2170
    DrawIMG(bBack,background,x+20,y+420);
cc3ef158 sago007 2011-07-03 16:13 2171
    while (!done && !Config::getInstance()->isShuttingDown())
89c4a3a6 sago007 2008-08-29 14:32 2172
    {
89c4a3a6 sago007 2008-08-29 14:32 2173
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2174
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2175
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2176
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2177
        {
925b7e58 sago007 2011-04-25 16:35 2178
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2179
        }
89c4a3a6 sago007 2008-08-29 14:32 2180
89c4a3a6 sago007 2008-08-29 14:32 2181
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2182
89c4a3a6 sago007 2008-08-29 14:32 2183
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2184
        {
89c4a3a6 sago007 2008-08-29 14:32 2185
            if ( event.type == SDL_QUIT )  {
cc3ef158 sago007 2011-07-03 16:13 2186
                Config::getInstance()->setShuttingDown(5);
89c4a3a6 sago007 2008-08-29 14:32 2187
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2188
            }
89c4a3a6 sago007 2008-08-29 14:32 2189
89c4a3a6 sago007 2008-08-29 14:32 2190
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2191
            {
89c4a3a6 sago007 2008-08-29 14:32 2192
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2193
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2194
                }
89c4a3a6 sago007 2008-08-29 14:32 2195
89c4a3a6 sago007 2008-08-29 14:32 2196
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2197
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2198
                }
89c4a3a6 sago007 2008-08-29 14:32 2199
89c4a3a6 sago007 2008-08-29 14:32 2200
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2201
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2202
                }
89c4a3a6 sago007 2008-08-29 14:32 2203
            }
89c4a3a6 sago007 2008-08-29 14:32 2204
89c4a3a6 sago007 2008-08-29 14:32 2205
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2206
89c4a3a6 sago007 2008-08-29 14:32 2207
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2208
89c4a3a6 sago007 2008-08-29 14:32 2209
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2210
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2211
        {
89c4a3a6 sago007 2008-08-29 14:32 2212
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2213
        }
89c4a3a6 sago007 2008-08-29 14:32 2214
89c4a3a6 sago007 2008-08-29 14:32 2215
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2216
        {
89c4a3a6 sago007 2008-08-29 14:32 2217
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2218
89c4a3a6 sago007 2008-08-29 14:32 2219
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2220
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2221
            {
89c4a3a6 sago007 2008-08-29 14:32 2222
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2223
            }
89c4a3a6 sago007 2008-08-29 14:32 2224
89c4a3a6 sago007 2008-08-29 14:32 2225
            //The back button:
9050a50a sago007 2008-12-09 13:35 2226
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2227
            {
89c4a3a6 sago007 2008-08-29 14:32 2228
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2229
            }
89c4a3a6 sago007 2008-08-29 14:32 2230
89c4a3a6 sago007 2008-08-29 14:32 2231
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2232
            {
89c4a3a6 sago007 2008-08-29 14:32 2233
                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 2234
                {
89c4a3a6 sago007 2008-08-29 14:32 2235
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2236
                    {
89c4a3a6 sago007 2008-08-29 14:32 2237
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2238
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2239
                    }
89c4a3a6 sago007 2008-08-29 14:32 2240
                }
89c4a3a6 sago007 2008-08-29 14:32 2241
            }
89c4a3a6 sago007 2008-08-29 14:32 2242
        }
89c4a3a6 sago007 2008-08-29 14:32 2243
8d488d32 sago007 2011-04-17 13:02 2244
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2245
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2246
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2247
    }
89c4a3a6 sago007 2008-08-29 14:32 2248
}
89c4a3a6 sago007 2008-08-29 14:32 2249
89c4a3a6 sago007 2008-08-29 14:32 2250
//Slelect a theme
89c4a3a6 sago007 2008-08-29 14:32 2251
bool SelectThemeDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2252
{
89c4a3a6 sago007 2008-08-29 14:32 2253
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2254
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2255
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2256
    string folder = (string)SHAREDIR+(string)"/themes";
89c4a3a6 sago007 2008-08-29 14:32 2257
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2258
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2259
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2260
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/themes";
89c4a3a6 sago007 2008-08-29 14:32 2261
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2262
#endif
89c4a3a6 sago007 2008-08-29 14:32 2263
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2264
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2265
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2266
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2267
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2268
    DrawIMG(bBack,background,x+20,y+420);
cc3ef158 sago007 2011-07-03 16:13 2269
    while (!done && !Config::getInstance()->isShuttingDown())
89c4a3a6 sago007 2008-08-29 14:32 2270
    {
89c4a3a6 sago007 2008-08-29 14:32 2271
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2272
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2273
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2274
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2275
        {
925b7e58 sago007 2011-04-25 16:35 2276
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2277
        }
89c4a3a6 sago007 2008-08-29 14:32 2278
89c4a3a6 sago007 2008-08-29 14:32 2279
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2280
89c4a3a6 sago007 2008-08-29 14:32 2281
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2282
        {
89c4a3a6 sago007 2008-08-29 14:32 2283
            if ( event.type == SDL_QUIT )  {
cc3ef158 sago007 2011-07-03 16:13 2284
                Config::getInstance()->setShuttingDown(5);
89c4a3a6 sago007 2008-08-29 14:32 2285
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2286
            }
89c4a3a6 sago007 2008-08-29 14:32 2287
89c4a3a6 sago007 2008-08-29 14:32 2288
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2289
            {
89c4a3a6 sago007 2008-08-29 14:32 2290
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2291
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2292
                }
89c4a3a6 sago007 2008-08-29 14:32 2293
89c4a3a6 sago007 2008-08-29 14:32 2294
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2295
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2296
                }
89c4a3a6 sago007 2008-08-29 14:32 2297
89c4a3a6 sago007 2008-08-29 14:32 2298
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2299
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2300
                }
89c4a3a6 sago007 2008-08-29 14:32 2301
            }
89c4a3a6 sago007 2008-08-29 14:32 2302
89c4a3a6 sago007 2008-08-29 14:32 2303
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2304
89c4a3a6 sago007 2008-08-29 14:32 2305
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2306
89c4a3a6 sago007 2008-08-29 14:32 2307
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2308
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2309
        {
89c4a3a6 sago007 2008-08-29 14:32 2310
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2311
        }
89c4a3a6 sago007 2008-08-29 14:32 2312
89c4a3a6 sago007 2008-08-29 14:32 2313
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2314
        {
89c4a3a6 sago007 2008-08-29 14:32 2315
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2316
89c4a3a6 sago007 2008-08-29 14:32 2317
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2318
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2319
            {
89c4a3a6 sago007 2008-08-29 14:32 2320
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2321
            }
89c4a3a6 sago007 2008-08-29 14:32 2322
89c4a3a6 sago007 2008-08-29 14:32 2323
            //The back button:
9050a50a sago007 2008-12-09 13:35 2324
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2325
            {
89c4a3a6 sago007 2008-08-29 14:32 2326
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2327
            }
89c4a3a6 sago007 2008-08-29 14:32 2328
89c4a3a6 sago007 2008-08-29 14:32 2329
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2330
            {
89c4a3a6 sago007 2008-08-29 14:32 2331
                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 2332
                {
89c4a3a6 sago007 2008-08-29 14:32 2333
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2334
                    {
89c4a3a6 sago007 2008-08-29 14:32 2335
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2336
                        loadTheme(lf.getFileName(i));
89c4a3a6 sago007 2008-08-29 14:32 2337
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2338
                    }
89c4a3a6 sago007 2008-08-29 14:32 2339
                }
89c4a3a6 sago007 2008-08-29 14:32 2340
            }
89c4a3a6 sago007 2008-08-29 14:32 2341
        }
89c4a3a6 sago007 2008-08-29 14:32 2342
8d488d32 sago007 2011-04-17 13:02 2343
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2344
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2345
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2346
    }
89c4a3a6 sago007 2008-08-29 14:32 2347
}
89c4a3a6 sago007 2008-08-29 14:32 2348
89c4a3a6 sago007 2008-08-29 14:32 2349
//Open a saved replay
89c4a3a6 sago007 2008-08-29 14:32 2350
bool OpenReplayDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2351
{
89c4a3a6 sago007 2008-08-29 14:32 2352
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2353
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2354
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2355
    cout << "Ready to set directory!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2356
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2357
    string directory = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2358
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 2359
    string directory = getMyDocumentsPath()+(string)"/My Games/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2360
#else
89c4a3a6 sago007 2008-08-29 14:32 2361
    string directory = "./replays";
89c4a3a6 sago007 2008-08-29 14:32 2362
#endif
89c4a3a6 sago007 2008-08-29 14:32 2363
    lf.setDirectory(directory);
89c4a3a6 sago007 2008-08-29 14:32 2364
    cout << "Directory sat" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2365
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2366
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2367
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2368
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2369
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2370
    DrawIMG(bBack,background,x+20,y+420);
cc3ef158 sago007 2011-07-03 16:13 2371
    while (!done && !Config::getInstance()->isShuttingDown())
89c4a3a6 sago007 2008-08-29 14:32 2372
    {
89c4a3a6 sago007 2008-08-29 14:32 2373
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2374
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2375
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2376
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2377
        {
925b7e58 sago007 2011-04-25 16:35 2378
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2379
        }
89c4a3a6 sago007 2008-08-29 14:32 2380
89c4a3a6 sago007 2008-08-29 14:32 2381
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2382
89c4a3a6 sago007 2008-08-29 14:32 2383
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2384
        {
89c4a3a6 sago007 2008-08-29 14:32 2385
            if ( event.type == SDL_QUIT )  {
cc3ef158 sago007 2011-07-03 16:13 2386
                Config::getInstance()->setShuttingDown(5);
89c4a3a6 sago007 2008-08-29 14:32 2387
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2388
                return false;
89c4a3a6 sago007 2008-08-29 14:32 2389
            }
89c4a3a6 sago007 2008-08-29 14:32 2390
89c4a3a6 sago007 2008-08-29 14:32 2391
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2392
            {
89c4a3a6 sago007 2008-08-29 14:32 2393
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2394
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2395
                    return false;
89c4a3a6 sago007 2008-08-29 14:32 2396
                }
89c4a3a6 sago007 2008-08-29 14:32 2397
89c4a3a6 sago007 2008-08-29 14:32 2398
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2399
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2400
                }
89c4a3a6 sago007 2008-08-29 14:32 2401
89c4a3a6 sago007 2008-08-29 14:32 2402
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2403
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2404
                }
89c4a3a6 sago007 2008-08-29 14:32 2405
            }
89c4a3a6 sago007 2008-08-29 14:32 2406
89c4a3a6 sago007 2008-08-29 14:32 2407
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2408
89c4a3a6 sago007 2008-08-29 14:32 2409
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2410
89c4a3a6 sago007 2008-08-29 14:32 2411
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2412
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2413
        {
89c4a3a6 sago007 2008-08-29 14:32 2414
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2415
        }
89c4a3a6 sago007 2008-08-29 14:32 2416
89c4a3a6 sago007 2008-08-29 14:32 2417
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2418
        {
89c4a3a6 sago007 2008-08-29 14:32 2419
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2420
89c4a3a6 sago007 2008-08-29 14:32 2421
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2422
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2423
            {
89c4a3a6 sago007 2008-08-29 14:32 2424
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2425
            }
89c4a3a6 sago007 2008-08-29 14:32 2426
89c4a3a6 sago007 2008-08-29 14:32 2427
            //The back button:
9050a50a sago007 2008-12-09 13:35 2428
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2429
            {
89c4a3a6 sago007 2008-08-29 14:32 2430
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2431
            }
89c4a3a6 sago007 2008-08-29 14:32 2432
89c4a3a6 sago007 2008-08-29 14:32 2433
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2434
            {
89c4a3a6 sago007 2008-08-29 14:32 2435
                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 2436
                {
89c4a3a6 sago007 2008-08-29 14:32 2437
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2438
                    {
89c4a3a6 sago007 2008-08-29 14:32 2439
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2440
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2441
                        return true;
89c4a3a6 sago007 2008-08-29 14:32 2442
                    }
89c4a3a6 sago007 2008-08-29 14:32 2443
                }
89c4a3a6 sago007 2008-08-29 14:32 2444
            }
89c4a3a6 sago007 2008-08-29 14:32 2445
        }
89c4a3a6 sago007 2008-08-29 14:32 2446
8d488d32 sago007 2011-04-17 13:02 2447
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2448
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2449
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2450
    }
89c4a3a6 sago007 2008-08-29 14:32 2451
}
89c4a3a6 sago007 2008-08-29 14:32 2452
89c4a3a6 sago007 2008-08-29 14:32 2453
//Draws the balls and explosions
4b0c248f sago007 2010-11-10 21:13 2454
static void DrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2455
{
89c4a3a6 sago007 2008-08-29 14:32 2456
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2457
    {
89c4a3a6 sago007 2008-08-29 14:32 2458
        if (theBallManeger.ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2459
        {
89c4a3a6 sago007 2008-08-29 14:32 2460
            DrawIMG(balls[theBallManeger.ballArray[i].getColor()],screen,theBallManeger.ballArray[i].getX(),theBallManeger.ballArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2461
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2462
        if (theExplosionManeger.explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2463
        {
89c4a3a6 sago007 2008-08-29 14:32 2464
            DrawIMG(explosion[theExplosionManeger.explosionArray[i].getFrame()],screen,theExplosionManeger.explosionArray[i].getX(),theExplosionManeger.explosionArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2465
        }
89c4a3a6 sago007 2008-08-29 14:32 2466
        if (theTextManeger.textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2467
        {
89c4a3a6 sago007 2008-08-29 14:32 2468
            //cout << "Printing text: " << theTextManeger.textArray[i].getText() << endl;
925b7e58 sago007 2011-04-25 16:35 2469
            int x = theTextManeger.textArray[i].getX()-12;
925b7e58 sago007 2011-04-25 16:35 2470
            int y = theTextManeger.textArray[i].getY()-12;
89c4a3a6 sago007 2008-08-29 14:32 2471
            DrawIMG(iChainBack,screen,x,y);
925b7e58 sago007 2011-04-25 16:35 2472
            nf_standard_small_font.drawCenter(x+12,y+7,theTextManeger.textArray[i].getText());
89c4a3a6 sago007 2008-08-29 14:32 2473
        }
89c4a3a6 sago007 2008-08-29 14:32 2474
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2475
}    //DrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2476
89c4a3a6 sago007 2008-08-29 14:32 2477
//Removes the old balls
89c4a3a6 sago007 2008-08-29 14:32 2478
void UndrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2479
{
89c4a3a6 sago007 2008-08-29 14:32 2480
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2481
    {
89c4a3a6 sago007 2008-08-29 14:32 2482
        if (theBallManeger.oldBallUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2483
        {
89c4a3a6 sago007 2008-08-29 14:32 2484
            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 2485
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2486
        if (theExplosionManeger.oldExplosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2487
        {
89c4a3a6 sago007 2008-08-29 14:32 2488
            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 2489
        }
89c4a3a6 sago007 2008-08-29 14:32 2490
        if (theTextManeger.oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2491
        {
925b7e58 sago007 2011-04-25 16:35 2492
            int x = theTextManeger.oldTextArray[i].getX()-12;
925b7e58 sago007 2011-04-25 16:35 2493
            int y = theTextManeger.oldTextArray[i].getY()-12;
89c4a3a6 sago007 2008-08-29 14:32 2494
            DrawIMG(background,screen,x,y,25,25,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2495
        }
89c4a3a6 sago007 2008-08-29 14:32 2496
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2497
}   //UndrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2498
89c4a3a6 sago007 2008-08-29 14:32 2499
//draws everything
6b1dc7a6 sago007 2010-11-08 21:03 2500
void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2501
{
89c4a3a6 sago007 2008-08-29 14:32 2502
    SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 2503
    //draw background:
89c4a3a6 sago007 2008-08-29 14:32 2504
    if (forceredraw != 1)
89c4a3a6 sago007 2008-08-29 14:32 2505
    {
89c4a3a6 sago007 2008-08-29 14:32 2506
89c4a3a6 sago007 2008-08-29 14:32 2507
        UndrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2508
        DrawIMG(background,screen,oldMousex,oldMousey,32,32,oldMousex,oldMousey);
89c4a3a6 sago007 2008-08-29 14:32 2509
        DrawIMG(background,screen,oldBubleX,oldBubleY,140,50,oldBubleX,oldBubleY);
89c4a3a6 sago007 2008-08-29 14:32 2510
89c4a3a6 sago007 2008-08-29 14:32 2511
89c4a3a6 sago007 2008-08-29 14:32 2512
        DrawIMG(background,screen,350,200,120,200,350,200);
89c4a3a6 sago007 2008-08-29 14:32 2513
        DrawIMG(background,screen,830,200,120,200,830,200);
89c4a3a6 sago007 2008-08-29 14:32 2514
        DrawIMG(background,screen,800,0,140,50,800,0);
89c4a3a6 sago007 2008-08-29 14:32 2515
89c4a3a6 sago007 2008-08-29 14:32 2516
        DrawIMG(background,screen,50,60,300,50,50,60);
89c4a3a6 sago007 2008-08-29 14:32 2517
        DrawIMG(background,screen,510,60,300,50,510,60);
89c4a3a6 sago007 2008-08-29 14:32 2518
    }
89c4a3a6 sago007 2008-08-29 14:32 2519
    else
89c4a3a6 sago007 2008-08-29 14:32 2520
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2521
    //draw bottons (should be moves and drawn directly to background once)
cc3ef158 sago007 2011-07-03 16:13 2522
    /*if (!editorMode)
2f30c381 sago007 2008-09-14 13:08 2523
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2524
        if (!networkActive) //We don't show the menu while running server or connected to a server
2f30c381 sago007 2008-09-14 13:08 2525
        #else
2f30c381 sago007 2008-09-14 13:08 2526
            if(true)
2f30c381 sago007 2008-09-14 13:08 2527
        #endif
89c4a3a6 sago007 2008-08-29 14:32 2528
        {
89c4a3a6 sago007 2008-08-29 14:32 2529
            //Here we draw the menu
43611709 sago007 2011-04-23 17:18 2530
            bNewGame.PaintTo(screen,0,0);
9050a50a sago007 2008-12-09 13:35 2531
            DrawIMG(bOptions, screen, buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2532
            DrawIMG(bHighScore, screen, 2*buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2533
            DrawIMG(bReplay,screen,3*buttonXsize,0);
89c4a3a6 sago007 2008-08-29 14:32 2534
        }
89c4a3a6 sago007 2008-08-29 14:32 2535
        else
89c4a3a6 sago007 2008-08-29 14:32 2536
        { //If network is active
89c4a3a6 sago007 2008-08-29 14:32 2537
            DrawIMG(bBack, screen, 0, 0); //Display a disconnect button
89c4a3a6 sago007 2008-08-29 14:32 2538
        }
89c4a3a6 sago007 2008-08-29 14:32 2539
    if (!editorMode)
cc3ef158 sago007 2011-07-03 16:13 2540
        DrawIMG(bExit, screen, xsize-120,ysize-120);*/
e1290bdf sago007 2010-10-25 19:56 2541
    //DrawIMG(boardBackBack,screen,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2542
    DrawIMG(theGame->sBoard,screen,theGame->GetTopX(),theGame->GetTopY());
89c4a3a6 sago007 2008-08-29 14:32 2543
    string strHolder;
e1290bdf sago007 2010-10-25 19:56 2544
    strHolder = itoa(theGame->GetScore()+theGame->GetHandicap());
925b7e58 sago007 2011-04-25 16:35 2545
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2546
    if (theGame->GetAIenabled())
c9dd376f sago007 2012-01-20 17:13 2547
        NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("AI") );
89c4a3a6 sago007 2008-08-29 14:32 2548
    else
89c4a3a6 sago007 2008-08-29 14:32 2549
        if (editorMode)
c9dd376f sago007 2012-01-20 17:13 2550
            NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("Playing field") );
89c4a3a6 sago007 2008-08-29 14:32 2551
        else
89c4a3a6 sago007 2008-08-29 14:32 2552
            if (!singlePuzzle)
71181267 sago007 2011-04-29 19:22 2553
                NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name);
e1290bdf sago007 2010-10-25 19:56 2554
    if (theGame->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2555
    {
e1290bdf sago007 2010-10-25 19:56 2556
        int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2557
        int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2558
        int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2559
        if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2560
        {
e1290bdf sago007 2010-10-25 19:56 2561
            minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2562
            seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2563
        }
89c4a3a6 sago007 2008-08-29 14:32 2564
        else
89c4a3a6 sago007 2008-08-29 14:32 2565
        {
e1290bdf sago007 2010-10-25 19:56 2566
            minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2567
            seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2568
        }
e1290bdf sago007 2010-10-25 19:56 2569
        if (theGame->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2570
        if (theGame->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2571
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2572
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2573
        else strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2574
        //if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
925b7e58 sago007 2011-04-25 16:35 2575
        NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2576
    }
89c4a3a6 sago007 2008-08-29 14:32 2577
    else
89c4a3a6 sago007 2008-08-29 14:32 2578
    {
e1290bdf sago007 2010-10-25 19:56 2579
        int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2580
        int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2581
        if (theGame->isGameOver()) minutes=(theGame->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2582
        if (theGame->isGameOver()) seconds=(theGame->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2583
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2584
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2585
        else
89c4a3a6 sago007 2008-08-29 14:32 2586
            strHolder = itoa(minutes)+":0"+itoa(seconds);
925b7e58 sago007 2011-04-25 16:35 2587
        NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2588
    }
e1290bdf sago007 2010-10-25 19:56 2589
    strHolder = itoa(theGame->GetChains());
925b7e58 sago007 2011-04-25 16:35 2590
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2591
    //drawspeedLevel:
e1290bdf sago007 2010-10-25 19:56 2592
    strHolder = itoa(theGame->GetSpeedLevel());
925b7e58 sago007 2011-04-25 16:35 2593
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2594
    if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY()))
89c4a3a6 sago007 2008-08-29 14:32 2595
    {
e1290bdf sago007 2010-10-25 19:56 2596
        oldBubleX = theGame->GetTopX()+280;
e1290bdf sago007 2010-10-25 19:56 2597
        oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1;
e1290bdf sago007 2010-10-25 19:56 2598
        DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
89c4a3a6 sago007 2008-08-29 14:32 2599
    }
89c4a3a6 sago007 2008-08-29 14:32 2600
    //player1 finnish, player2 start
e1290bdf sago007 2010-10-25 19:56 2601
    //DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2602
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2603
    {
f72abf8b sago007 2010-01-16 20:00 2604
        /*
f72abf8b sago007 2010-01-16 20:00 2605
         *If single player mode (and not VS)
f72abf8b sago007 2010-01-16 20:00 2606
         */
e1290bdf sago007 2010-10-25 19:56 2607
        if(!twoPlayers && !theGame->isGameOver())
e2de69cf sago007 2010-01-15 22:48 2608
        {
f72abf8b sago007 2010-01-16 20:00 2609
            //Blank player2's board:
e1290bdf sago007 2010-10-25 19:56 2610
            DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
f72abf8b sago007 2010-01-16 20:00 2611
            //Write a description:
e1290bdf sago007 2010-10-25 19:56 2612
            if(theGame->isTimeTrial())
f72abf8b sago007 2010-01-16 20:00 2613
            {
925b7e58 sago007 2011-04-25 16:35 2614
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial");
925b7e58 sago007 2011-04-25 16:35 2615
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2616
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much");
925b7e58 sago007 2011-04-25 16:35 2617
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "as possible in");
925b7e58 sago007 2011-04-25 16:35 2618
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"2 minutes");
e1290bdf sago007 2010-10-25 19:56 2619
            } else if(theGame->isStageClear())
f72abf8b sago007 2010-01-16 20:00 2620
            {
925b7e58 sago007 2011-04-25 16:35 2621
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear");
925b7e58 sago007 2011-04-25 16:35 2622
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2623
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "You must clear a");
925b7e58 sago007 2011-04-25 16:35 2624
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "number of lines.");
925b7e58 sago007 2011-04-25 16:35 2625
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"Speed is rapidly");
925b7e58 sago007 2011-04-25 16:35 2626
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"increased.");
e1290bdf sago007 2010-10-25 19:56 2627
            } else if(theGame->isPuzzleMode())
f72abf8b sago007 2010-01-16 20:00 2628
            {
925b7e58 sago007 2011-04-25 16:35 2629
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle");
925b7e58 sago007 2011-04-25 16:35 2630
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2631
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Clear the entire");
925b7e58 sago007 2011-04-25 16:35 2632
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "board with a");
925b7e58 sago007 2011-04-25 16:35 2633
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limited number of");
925b7e58 sago007 2011-04-25 16:35 2634
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"moves.");
f72abf8b sago007 2010-01-16 20:00 2635
            } else
f72abf8b sago007 2010-01-16 20:00 2636
            {
925b7e58 sago007 2011-04-25 16:35 2637
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless");
925b7e58 sago007 2011-04-25 16:35 2638
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2639
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much as");
925b7e58 sago007 2011-04-25 16:35 2640
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "possible. No time");
925b7e58 sago007 2011-04-25 16:35 2641
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limit.");
f72abf8b sago007 2010-01-16 20:00 2642
            }
f72abf8b sago007 2010-01-16 20:00 2643
f72abf8b sago007 2010-01-16 20:00 2644
            //Write the keys that are in use
e1290bdf sago007 2010-10-25 19:56 2645
            int y = theGame2->GetTopY()+400;
c9dd376f sago007 2012-01-20 17:13 2646
            NFont_Write(screen, theGame2->GetTopX()+7,y,_("Movement keys:") );
925b7e58 sago007 2011-04-25 16:35 2647
            NFont_Write(screen, theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
925b7e58 sago007 2011-04-25 16:35 2648
            NFont_Write(screen, theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
c9dd376f sago007 2012-01-20 17:13 2649
            NFont_Write(screen, theGame2->GetTopX()+7,y+120,( _("Switch: ")+getKeyName(keySettings[0].change) ).c_str() );
e1290bdf sago007 2010-10-25 19:56 2650
            if(theGame->isPuzzleMode())
c9dd376f sago007 2012-01-20 17:13 2651
                NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Restart: ")+getKeyName(keySettings[0].push) ).c_str() );
f72abf8b sago007 2010-01-16 20:00 2652
            else
c9dd376f sago007 2012-01-20 17:13 2653
                NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Push line: ")+getKeyName(keySettings[0].push) ).c_str() );
e2de69cf sago007 2010-01-15 22:48 2654
        }
e2de69cf sago007 2010-01-15 22:48 2655
        else
e1290bdf sago007 2010-10-25 19:56 2656
            DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
e1290bdf sago007 2010-10-25 19:56 2657
        strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap());
925b7e58 sago007 2011-04-25 16:35 2658
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2659
        if (theGame2->GetAIenabled())
c9dd376f sago007 2012-01-20 17:13 2660
            NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,_("AI") );
89c4a3a6 sago007 2008-08-29 14:32 2661
        else
71181267 sago007 2011-04-29 19:22 2662
            NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name);
e1290bdf sago007 2010-10-25 19:56 2663
        if (theGame2->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2664
        {
e1290bdf sago007 2010-10-25 19:56 2665
            int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2666
            int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2667
            int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2668
            if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2669
            {
e1290bdf sago007 2010-10-25 19:56 2670
                minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2671
                seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2672
            }
89c4a3a6 sago007 2008-08-29 14:32 2673
            else
89c4a3a6 sago007 2008-08-29 14:32 2674
            {
e1290bdf sago007 2010-10-25 19:56 2675
                minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2676
                seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2677
            }
e1290bdf sago007 2010-10-25 19:56 2678
            if (theGame2->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2679
            if (theGame2->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2680
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2681
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2682
            else
89c4a3a6 sago007 2008-08-29 14:32 2683
                strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2684
            //if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
925b7e58 sago007 2011-04-25 16:35 2685
            NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2686
        }
89c4a3a6 sago007 2008-08-29 14:32 2687
        else
89c4a3a6 sago007 2008-08-29 14:32 2688
        {
e1290bdf sago007 2010-10-25 19:56 2689
            int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2690
            int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2691
            if (theGame2->isGameOver()) minutes=(theGame2->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2692
            if (theGame2->isGameOver()) seconds=(theGame2->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2693
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2694
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2695
            else
89c4a3a6 sago007 2008-08-29 14:32 2696
                strHolder = itoa(minutes)+":0"+itoa(seconds);
925b7e58 sago007 2011-04-25 16:35 2697
            NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2698
        }
e1290bdf sago007 2010-10-25 19:56 2699
        strHolder = itoa(theGame2->GetChains());
925b7e58 sago007 2011-04-25 16:35 2700
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2701
        strHolder = itoa(theGame2->GetSpeedLevel());
925b7e58 sago007 2011-04-25 16:35 2702
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2703
    }
89c4a3a6 sago007 2008-08-29 14:32 2704
    //player2 finnish
89c4a3a6 sago007 2008-08-29 14:32 2705
89c4a3a6 sago007 2008-08-29 14:32 2706
89c4a3a6 sago007 2008-08-29 14:32 2707
    DrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2708
1572de2b sago007 2008-09-11 18:15 2709
#if DEBUG
89c4a3a6 sago007 2008-08-29 14:32 2710
    Frames++;
89c4a3a6 sago007 2008-08-29 14:32 2711
    if (SDL_GetTicks() >= Ticks + 1000)
89c4a3a6 sago007 2008-08-29 14:32 2712
    {
89c4a3a6 sago007 2008-08-29 14:32 2713
        if (Frames > 999) Frames=999;
78d03b38 sago007 2008-11-13 19:56 2714
        sprintf(FPS, "%lu fps", Frames);
89c4a3a6 sago007 2008-08-29 14:32 2715
        Frames = 0;
89c4a3a6 sago007 2008-08-29 14:32 2716
        Ticks = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2717
    }
89c4a3a6 sago007 2008-08-29 14:32 2718
925b7e58 sago007 2011-04-25 16:35 2719
    //NFont_Write(screen, 800,4,FPS);
925b7e58 sago007 2011-04-25 16:35 2720
    nf_standard_blue_font.draw(800,4,FPS);
89c4a3a6 sago007 2008-08-29 14:32 2721
#endif
89c4a3a6 sago007 2008-08-29 14:32 2722
89c4a3a6 sago007 2008-08-29 14:32 2723
    //SDL_Flip(screen); Update screen is now called outside DrawEvrything, bacause the mouse needs to be painted
89c4a3a6 sago007 2008-08-29 14:32 2724
89c4a3a6 sago007 2008-08-29 14:32 2725
}
89c4a3a6 sago007 2008-08-29 14:32 2726
89c4a3a6 sago007 2008-08-29 14:32 2727
//Generates the standard background
4b0c248f sago007 2010-11-10 21:13 2728
static void MakeBackground(int xsize,int ysize)
89c4a3a6 sago007 2008-08-29 14:32 2729
{
27ae0175 sago007 2009-01-30 06:02 2730
    int w = backgroundImage->w;
27ae0175 sago007 2009-01-30 06:02 2731
    int h = backgroundImage->h;
27ae0175 sago007 2009-01-30 06:02 2732
    for(int i=0;i*w<xsize;i++)
27ae0175 sago007 2009-01-30 06:02 2733
        for(int j=0;j*h<ysize;j++)
27ae0175 sago007 2009-01-30 06:02 2734
            DrawIMG(backgroundImage,background,i*w,j*h);
89c4a3a6 sago007 2008-08-29 14:32 2735
    standardBackground = true;
89c4a3a6 sago007 2008-08-29 14:32 2736
}
89c4a3a6 sago007 2008-08-29 14:32 2737
89c4a3a6 sago007 2008-08-29 14:32 2738
//Generates the background with red board backs
4b0c248f sago007 2010-11-10 21:13 2739
static void MakeBackground(int xsize,int ysize,BlockGame *theGame, BlockGame *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2740
{
27ae0175 sago007 2009-01-30 06:02 2741
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2742
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2743
    DrawIMG(boardBackBack,background,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2744
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2745
}
89c4a3a6 sago007 2008-08-29 14:32 2746
4b0c248f sago007 2010-11-10 21:13 2747
static void MakeBackground(int xsize, int ysize, BlockGame *theGame)
89c4a3a6 sago007 2008-08-29 14:32 2748
{
27ae0175 sago007 2009-01-30 06:02 2749
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2750
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2751
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2752
}
89c4a3a6 sago007 2008-08-29 14:32 2753
89c4a3a6 sago007 2008-08-29 14:32 2754
89c4a3a6 sago007 2008-08-29 14:32 2755
//The function that allows the player to choose PuzzleLevel
89c4a3a6 sago007 2008-08-29 14:32 2756
int PuzzleLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2757
{
89c4a3a6 sago007 2008-08-29 14:32 2758
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2759
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2760
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2761
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2762
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2763
    bool tempBool;
cc6724c9 sago007 2012-04-16 21:11 2764
	int selected = 0;
89c4a3a6 sago007 2008-08-29 14:32 2765
89c4a3a6 sago007 2008-08-29 14:32 2766
    //Loads the levels, if they havn't been loaded:
89c4a3a6 sago007 2008-08-29 14:32 2767
    LoadPuzzleStages();
89c4a3a6 sago007 2008-08-29 14:32 2768
89c4a3a6 sago007 2008-08-29 14:32 2769
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2770
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2771
89c4a3a6 sago007 2008-08-29 14:32 2772
    ifstream puzzleFile(puzzleSavePath.c_str(),ios::binary);
27ae0175 sago007 2009-01-30 06:02 2773
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2774
    if (puzzleFile)
89c4a3a6 sago007 2008-08-29 14:32 2775
    {
89c4a3a6 sago007 2008-08-29 14:32 2776
        for (int i=0;(i<nrOfPuzzles)&&(!puzzleFile.eof()); i++)
89c4a3a6 sago007 2008-08-29 14:32 2777
        {
89c4a3a6 sago007 2008-08-29 14:32 2778
            puzzleFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2779
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2780
        }
89c4a3a6 sago007 2008-08-29 14:32 2781
        puzzleFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2782
    }
89c4a3a6 sago007 2008-08-29 14:32 2783
    else
89c4a3a6 sago007 2008-08-29 14:32 2784
    {
89c4a3a6 sago007 2008-08-29 14:32 2785
        tempBool = false;
89c4a3a6 sago007 2008-08-29 14:32 2786
        for (int i=0; i<nrOfPuzzles; i++)
89c4a3a6 sago007 2008-08-29 14:32 2787
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2788
    }
89c4a3a6 sago007 2008-08-29 14:32 2789
89c4a3a6 sago007 2008-08-29 14:32 2790
    do
89c4a3a6 sago007 2008-08-29 14:32 2791
    {
89c4a3a6 sago007 2008-08-29 14:32 2792
        nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2793
89c4a3a6 sago007 2008-08-29 14:32 2794
89c4a3a6 sago007 2008-08-29 14:32 2795
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2796
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
c9dd376f sago007 2012-01-20 17:13 2797
        NFont_Write(screen, xplace+12,yplace+2,_("Select Puzzle") );
89c4a3a6 sago007 2008-08-29 14:32 2798
        //Now drow the fields you click in (and a V if clicked):
89c4a3a6 sago007 2008-08-29 14:32 2799
        for (int i = 0; i < nrOfPuzzles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2800
        {
89c4a3a6 sago007 2008-08-29 14:32 2801
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
cc6724c9 sago007 2012-04-16 21:11 2802
	if(i==selected) DrawIMG(iLevelCheckBoxMarked,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2803
            if (puzzleCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2804
        }
89c4a3a6 sago007 2008-08-29 14:32 2805
89c4a3a6 sago007 2008-08-29 14:32 2806
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2807
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2808
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2809
            {
89c4a3a6 sago007 2008-08-29 14:32 2810
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 2811
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 2812
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2813
                }
cc6724c9 sago007 2012-04-16 21:11 2814
		if ( event.key.keysym.sym == SDLK_RIGHT ) {
cc6724c9 sago007 2012-04-16 21:11 2815
			++selected;
cc6724c9 sago007 2012-04-16 21:11 2816
			if(selected >= nrOfPuzzles)
cc6724c9 sago007 2012-04-16 21:11 2817
				selected = 0;
cc6724c9 sago007 2012-04-16 21:11 2818
			cout << "Selected: "<< selected << endl;
cc6724c9 sago007 2012-04-16 21:11 2819
		}
89c4a3a6 sago007 2008-08-29 14:32 2820
            }
89c4a3a6 sago007 2008-08-29 14:32 2821
89c4a3a6 sago007 2008-08-29 14:32 2822
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2823
89c4a3a6 sago007 2008-08-29 14:32 2824
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2825
89c4a3a6 sago007 2008-08-29 14:32 2826
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2827
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2828
        {
89c4a3a6 sago007 2008-08-29 14:32 2829
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2830
        }
89c4a3a6 sago007 2008-08-29 14:32 2831
89c4a3a6 sago007 2008-08-29 14:32 2832
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2833
        {
89c4a3a6 sago007 2008-08-29 14:32 2834
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2835
89c4a3a6 sago007 2008-08-29 14:32 2836
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 2837
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2838
            for (i = 0; (i<nrOfPuzzles/10)||((i<nrOfPuzzles/10+1)&&(nrOfPuzzles%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2839
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2840
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2841
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2842
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 2843
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2844
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2845
                    {
89c4a3a6 sago007 2008-08-29 14:32 2846
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 2847
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2848
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 2849
                    }
89c4a3a6 sago007 2008-08-29 14:32 2850
        }
89c4a3a6 sago007 2008-08-29 14:32 2851
8d488d32 sago007 2011-04-17 13:02 2852
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2853
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2854
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 2855
89c4a3a6 sago007 2008-08-29 14:32 2856
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 2857
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2858
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 2859
}
89c4a3a6 sago007 2008-08-29 14:32 2860
89c4a3a6 sago007 2008-08-29 14:32 2861
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 2862
int StageLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2863
{
89c4a3a6 sago007 2008-08-29 14:32 2864
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2865
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2866
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2867
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2868
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2869
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2870
    Uint32 tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2871
    Uint32 totalScore = 0;
89c4a3a6 sago007 2008-08-29 14:32 2872
    Uint32 totalTime = 0;
89c4a3a6 sago007 2008-08-29 14:32 2873
89c4a3a6 sago007 2008-08-29 14:32 2874
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2875
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2876
27ae0175 sago007 2009-01-30 06:02 2877
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2878
    ifstream stageFile(stageClearSavePath.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 2879
    if (stageFile)
89c4a3a6 sago007 2008-08-29 14:32 2880
    {
89c4a3a6 sago007 2008-08-29 14:32 2881
        for (int i = 0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2882
        {
89c4a3a6 sago007 2008-08-29 14:32 2883
            stageFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2884
            stageCleared[i]=tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2885
        }
89c4a3a6 sago007 2008-08-29 14:32 2886
        if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2887
        {
89c4a3a6 sago007 2008-08-29 14:32 2888
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2889
            {
89c4a3a6 sago007 2008-08-29 14:32 2890
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2891
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2892
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2893
                stageScores[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2894
                totalScore+=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2895
            }
89c4a3a6 sago007 2008-08-29 14:32 2896
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2897
            {
89c4a3a6 sago007 2008-08-29 14:32 2898
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2899
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2900
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2901
                stageTimes[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2902
                totalTime += tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2903
            }
89c4a3a6 sago007 2008-08-29 14:32 2904
        }
89c4a3a6 sago007 2008-08-29 14:32 2905
        else
89c4a3a6 sago007 2008-08-29 14:32 2906
        {
89c4a3a6 sago007 2008-08-29 14:32 2907
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2908
            {
89c4a3a6 sago007 2008-08-29 14:32 2909
                 stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2910
                 stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2911
            }
89c4a3a6 sago007 2008-08-29 14:32 2912
        }
89c4a3a6 sago007 2008-08-29 14:32 2913
        stageFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2914
    }
89c4a3a6 sago007 2008-08-29 14:32 2915
    else
89c4a3a6 sago007 2008-08-29 14:32 2916
    {
89c4a3a6 sago007 2008-08-29 14:32 2917
        for (int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2918
        {
89c4a3a6 sago007 2008-08-29 14:32 2919
            stageCleared[i]= false;
89c4a3a6 sago007 2008-08-29 14:32 2920
            stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2921
            stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2922
        }
89c4a3a6 sago007 2008-08-29 14:32 2923
    }
89c4a3a6 sago007 2008-08-29 14:32 2924
89c4a3a6 sago007 2008-08-29 14:32 2925
89c4a3a6 sago007 2008-08-29 14:32 2926
    do
89c4a3a6 sago007 2008-08-29 14:32 2927
    {
89c4a3a6 sago007 2008-08-29 14:32 2928
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2929
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2930
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
c9dd376f sago007 2012-01-20 17:13 2931
        NFont_Write(screen, xplace+12,yplace+2, _("Stage Clear Level Select") );
89c4a3a6 sago007 2008-08-29 14:32 2932
        for (int i = 0; i < nrOfStageLevels;i++)
89c4a3a6 sago007 2008-08-29 14:32 2933
        {
89c4a3a6 sago007 2008-08-29 14:32 2934
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2935
            if (stageCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2936
        }
89c4a3a6 sago007 2008-08-29 14:32 2937
89c4a3a6 sago007 2008-08-29 14:32 2938
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2939
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2940
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2941
            {
89c4a3a6 sago007 2008-08-29 14:32 2942
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 2943
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 2944
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2945
                }
89c4a3a6 sago007 2008-08-29 14:32 2946
            }
89c4a3a6 sago007 2008-08-29 14:32 2947
89c4a3a6 sago007 2008-08-29 14:32 2948
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2949
89c4a3a6 sago007 2008-08-29 14:32 2950
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2951
89c4a3a6 sago007 2008-08-29 14:32 2952
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2953
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2954
        {
89c4a3a6 sago007 2008-08-29 14:32 2955
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2956
        }
89c4a3a6 sago007 2008-08-29 14:32 2957
89c4a3a6 sago007 2008-08-29 14:32 2958
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2959
        {
89c4a3a6 sago007 2008-08-29 14:32 2960
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2961
89c4a3a6 sago007 2008-08-29 14:32 2962
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 2963
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2964
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2965
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2966
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2967
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2968
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 2969
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2970
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2971
                    {
89c4a3a6 sago007 2008-08-29 14:32 2972
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 2973
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2974
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 2975
                    }
89c4a3a6 sago007 2008-08-29 14:32 2976
        }
89c4a3a6 sago007 2008-08-29 14:32 2977
        //Find what we are over:
89c4a3a6 sago007 2008-08-29 14:32 2978
            int overLevel = -1;
89c4a3a6 sago007 2008-08-29 14:32 2979
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2980
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2981
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2982
                    overLevel = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2983
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2984
            if (overLevel != -1)
89c4a3a6 sago007 2008-08-29 14:32 2985
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2986
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2987
                    {
89c4a3a6 sago007 2008-08-29 14:32 2988
                        overLevel +=j;
c9dd376f sago007 2012-01-20 17:13 2989
                        string scoreString = _("Best score: 0");
c9dd376f sago007 2012-01-20 17:13 2990
                        string timeString = _("Time used: -- : --");
89c4a3a6 sago007 2008-08-29 14:32 2991
                        
89c4a3a6 sago007 2008-08-29 14:32 2992
                        if(stageScores.at(overLevel)>0)
c9dd376f sago007 2012-01-20 17:13 2993
                            scoreString = _("Best score: ")+itoa(stageScores[overLevel]);
89c4a3a6 sago007 2008-08-29 14:32 2994
                        if(stageTimes[overLevel]>0)
c9dd376f sago007 2012-01-20 17:13 2995
                            timeString = _("Time used: ")+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60);
89c4a3a6 sago007 2008-08-29 14:32 2996
                        
925b7e58 sago007 2011-04-25 16:35 2997
                        NFont_Write(screen, 200,200,scoreString.c_str());
925b7e58 sago007 2011-04-25 16:35 2998
                        NFont_Write(screen, 200,250,timeString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2999
                        
89c4a3a6 sago007 2008-08-29 14:32 3000
                        overLevel;
89c4a3a6 sago007 2008-08-29 14:32 3001
                    }
c9dd376f sago007 2012-01-20 17:13 3002
            string totalString = (format("Total score: %1% in %2%:%3%")%totalScore%(totalTime/1000/60)%((totalTime/1000)%60)).str(); //"Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60);
925b7e58 sago007 2011-04-25 16:35 3003
            NFont_Write(screen, 200,600,totalString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3004
8d488d32 sago007 2011-04-17 13:02 3005
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3006
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3007
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3008
89c4a3a6 sago007 2008-08-29 14:32 3009
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 3010
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3011
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 3012
}
89c4a3a6 sago007 2008-08-29 14:32 3013
89c4a3a6 sago007 2008-08-29 14:32 3014
//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 3015
int startSingleVs()
89c4a3a6 sago007 2008-08-29 14:32 3016
{
89c4a3a6 sago007 2008-08-29 14:32 3017
    //Where to place the windows
89c4a3a6 sago007 2008-08-29 14:32 3018
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3019
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3020
    Uint8 *keys;	//To take keyboard input
89c4a3a6 sago007 2008-08-29 14:32 3021
    int mousex, mousey;	//To allow mouse
89c4a3a6 sago007 2008-08-29 14:32 3022
    bool done = false;	//When are we done?
89c4a3a6 sago007 2008-08-29 14:32 3023
27ae0175 sago007 2009-01-30 06:02 3024
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3025
    DrawIMG(changeButtonsBack,background,xplace,yplace);
c9dd376f sago007 2012-01-20 17:13 3026
    NFont_Write(background, xplace+10,yplace+10,_("1 : Very Easy") );
c9dd376f sago007 2012-01-20 17:13 3027
    NFont_Write(background, xplace+10,yplace+40,_("2 : Easy") );
c9dd376f sago007 2012-01-20 17:13 3028
    NFont_Write(background, xplace+10,yplace+70,_("3 : Below Normal") );
c9dd376f sago007 2012-01-20 17:13 3029
    NFont_Write(background, xplace+10,yplace+100,_("4 : Normal") );
c9dd376f sago007 2012-01-20 17:13 3030
    NFont_Write(background, xplace+10,yplace+130,_("5 : Above Normal") );
c9dd376f sago007 2012-01-20 17:13 3031
    NFont_Write(background, xplace+10,yplace+160,_("6 : Hard") );
c9dd376f sago007 2012-01-20 17:13 3032
    NFont_Write(background, xplace+10,yplace+190,_("7 : Hardest") );
89c4a3a6 sago007 2008-08-29 14:32 3033
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3034
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3035
    do
89c4a3a6 sago007 2008-08-29 14:32 3036
    {
89c4a3a6 sago007 2008-08-29 14:32 3037
89c4a3a6 sago007 2008-08-29 14:32 3038
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3039
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3040
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3041
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3042
            {
4f1d27f1 sago007 2011-03-18 15:53 3043
                if ( event.key.keysym.sym == SDLK_KP_ENTER || event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_RETURN ) {
89c4a3a6 sago007 2008-08-29 14:32 3044
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3045
                }
4f1d27f1 sago007 2011-03-18 15:53 3046
                if ( event.key.keysym.sym == SDLK_1 || event.key.keysym.sym == SDLK_KP1 ) {
89c4a3a6 sago007 2008-08-29 14:32 3047
                    return 0;
89c4a3a6 sago007 2008-08-29 14:32 3048
                }
4f1d27f1 sago007 2011-03-18 15:53 3049
                if ( event.key.keysym.sym == SDLK_2 || event.key.keysym.sym == SDLK_KP2 ) {
89c4a3a6 sago007 2008-08-29 14:32 3050
                    return 1;
89c4a3a6 sago007 2008-08-29 14:32 3051
                }
4f1d27f1 sago007 2011-03-18 15:53 3052
                if ( event.key.keysym.sym == SDLK_3 || event.key.keysym.sym == SDLK_KP3 ) {
89c4a3a6 sago007 2008-08-29 14:32 3053
                    return 2;
89c4a3a6 sago007 2008-08-29 14:32 3054
                }
4f1d27f1 sago007 2011-03-18 15:53 3055
                if ( event.key.keysym.sym == SDLK_4 || event.key.keysym.sym == SDLK_KP4 ) {
89c4a3a6 sago007 2008-08-29 14:32 3056
                    return 3;
89c4a3a6 sago007 2008-08-29 14:32 3057
                }
4f1d27f1 sago007 2011-03-18 15:53 3058
                if ( event.key.keysym.sym == SDLK_5 || event.key.keysym.sym == SDLK_KP5 ) {
89c4a3a6 sago007 2008-08-29 14:32 3059
                    return 4;
89c4a3a6 sago007 2008-08-29 14:32 3060
                }
4f1d27f1 sago007 2011-03-18 15:53 3061
                if ( event.key.keysym.sym == SDLK_6 || event.key.keysym.sym == SDLK_KP6 ) {
89c4a3a6 sago007 2008-08-29 14:32 3062
                    return 5;
89c4a3a6 sago007 2008-08-29 14:32 3063
                }
4f1d27f1 sago007 2011-03-18 15:53 3064
                if ( event.key.keysym.sym == SDLK_7 || event.key.keysym.sym == SDLK_KP7 ) {
89c4a3a6 sago007 2008-08-29 14:32 3065
                    return 6;
89c4a3a6 sago007 2008-08-29 14:32 3066
                }
89c4a3a6 sago007 2008-08-29 14:32 3067
            }
89c4a3a6 sago007 2008-08-29 14:32 3068
89c4a3a6 sago007 2008-08-29 14:32 3069
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3070
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3071
        {
89c4a3a6 sago007 2008-08-29 14:32 3072
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3073
        }
89c4a3a6 sago007 2008-08-29 14:32 3074
89c4a3a6 sago007 2008-08-29 14:32 3075
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3076
        {
89c4a3a6 sago007 2008-08-29 14:32 3077
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3078
89c4a3a6 sago007 2008-08-29 14:32 3079
            for (int i=0; i<7;i++)
89c4a3a6 sago007 2008-08-29 14:32 3080
            {
89c4a3a6 sago007 2008-08-29 14:32 3081
                if ((mousex>xplace+10)&&(mousex<xplace+410)&&(mousey>yplace+10+i*30)&&(mousey<yplace+38+i*30))
89c4a3a6 sago007 2008-08-29 14:32 3082
                    return i;
89c4a3a6 sago007 2008-08-29 14:32 3083
            }
89c4a3a6 sago007 2008-08-29 14:32 3084
        }
89c4a3a6 sago007 2008-08-29 14:32 3085
89c4a3a6 sago007 2008-08-29 14:32 3086
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3087
        DrawIMG(background, screen, 0, 0);
8d488d32 sago007 2011-04-17 13:02 3088
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3089
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3090
        SDL_Flip(screen); //draws it all to the screen
cc3ef158 sago007 2011-07-03 16:13 3091
    }while (!done && !Config::getInstance()->isShuttingDown());
89c4a3a6 sago007 2008-08-29 14:32 3092
89c4a3a6 sago007 2008-08-29 14:32 3093
89c4a3a6 sago007 2008-08-29 14:32 3094
    return 3; //Returns normal
89c4a3a6 sago007 2008-08-29 14:32 3095
}
89c4a3a6 sago007 2008-08-29 14:32 3096
89c4a3a6 sago007 2008-08-29 14:32 3097
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 3098
void startVsMenu()
89c4a3a6 sago007 2008-08-29 14:32 3099
{
89c4a3a6 sago007 2008-08-29 14:32 3100
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3101
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3102
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3103
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 3104
    bool done = false;
89c4a3a6 sago007 2008-08-29 14:32 3105
89c4a3a6 sago007 2008-08-29 14:32 3106
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3107
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3108
27ae0175 sago007 2009-01-30 06:02 3109
    MakeBackground(xsize,ysize);
c9dd376f sago007 2012-01-20 17:13 3110
    NFont_Write(background, 360,650, _("Press ESC to accept") );
27ae0175 sago007 2009-01-30 06:02 3111
    DrawIMG(bBack,background,xsize/2-120/2,600);
89c4a3a6 sago007 2008-08-29 14:32 3112
    do
89c4a3a6 sago007 2008-08-29 14:32 3113
    {
89c4a3a6 sago007 2008-08-29 14:32 3114
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3115
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3116
        DrawIMG(changeButtonsBack,screen,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 3117
        NFont_Write(screen, xplace+50,yplace+20,"Player 1");
925b7e58 sago007 2011-04-25 16:35 3118
        NFont_Write(screen, xplace+300+50,yplace+20,"Player 2");
925b7e58 sago007 2011-04-25 16:35 3119
        NFont_Write(screen, xplace+50,yplace+70,"Speed:");
925b7e58 sago007 2011-04-25 16:35 3120
        NFont_Write(screen, xplace+50+300,yplace+70,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 3121
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3122
        {
89c4a3a6 sago007 2008-08-29 14:32 3123
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3124
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3125
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3126
            NFont_Write(screen, xplace+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3127
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3128
            if (player1Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3129
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3130
        }
89c4a3a6 sago007 2008-08-29 14:32 3131
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3132
        {
89c4a3a6 sago007 2008-08-29 14:32 3133
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3134
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3135
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3136
            NFont_Write(screen, xplace+300+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3137
            DrawIMG(iLevelCheckBox,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3138
            if (player2Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3139
                DrawIMG(iLevelCheck,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3140
        }
925b7e58 sago007 2011-04-25 16:35 3141
        NFont_Write(screen, xplace+50,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3142
        DrawIMG(iLevelCheckBox,screen,xplace+50+70,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3143
        if (player1AI)
89c4a3a6 sago007 2008-08-29 14:32 3144
            DrawIMG(iLevelCheck,screen,xplace+50+70,yplace+200);
925b7e58 sago007 2011-04-25 16:35 3145
        NFont_Write(screen, xplace+50,yplace+250,"TT Handicap: ");
925b7e58 sago007 2011-04-25 16:35 3146
        NFont_Write(screen, xplace+50+300,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3147
        DrawIMG(iLevelCheckBox,screen,xplace+50+70+300,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3148
        if (player2AI)
89c4a3a6 sago007 2008-08-29 14:32 3149
            DrawIMG(iLevelCheck,screen,xplace+50+70+300,yplace+200);
925b7e58 sago007 2011-04-25 16:35 3150
        NFont_Write(screen, xplace+50+300,yplace+250,"TT Handicap: ");
89c4a3a6 sago007 2008-08-29 14:32 3151
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3152
        {
89c4a3a6 sago007 2008-08-29 14:32 3153
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3154
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3155
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3156
            NFont_Write(screen, xplace+50+i*40,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3157
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3158
            if (player1handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3159
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3160
        }
89c4a3a6 sago007 2008-08-29 14:32 3161
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3162
        {
89c4a3a6 sago007 2008-08-29 14:32 3163
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3164
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3165
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3166
            NFont_Write(screen, xplace+50+i*40+300,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3167
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3168
            if (player2handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3169
                DrawIMG(iLevelCheck,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3170
        }
89c4a3a6 sago007 2008-08-29 14:32 3171
89c4a3a6 sago007 2008-08-29 14:32 3172
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3173
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3174
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3175
            {
89c4a3a6 sago007 2008-08-29 14:32 3176
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3177
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3178
                }
89c4a3a6 sago007 2008-08-29 14:32 3179
                if ( event.key.keysym.sym == SDLK_RETURN ) {
89c4a3a6 sago007 2008-08-29 14:32 3180
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3181
                }
89c4a3a6 sago007 2008-08-29 14:32 3182
                if ( event.key.keysym.sym == SDLK_KP_ENTER ) {
89c4a3a6 sago007 2008-08-29 14:32 3183
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3184
                }
89c4a3a6 sago007 2008-08-29 14:32 3185
            }
89c4a3a6 sago007 2008-08-29 14:32 3186
89c4a3a6 sago007 2008-08-29 14:32 3187
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3188
89c4a3a6 sago007 2008-08-29 14:32 3189
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3190
89c4a3a6 sago007 2008-08-29 14:32 3191
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3192
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3193
        {
89c4a3a6 sago007 2008-08-29 14:32 3194
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3195
        }
89c4a3a6 sago007 2008-08-29 14:32 3196
89c4a3a6 sago007 2008-08-29 14:32 3197
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3198
        {
89c4a3a6 sago007 2008-08-29 14:32 3199
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3200
89c4a3a6 sago007 2008-08-29 14:32 3201
            if ((mousex>xplace+50+70)&&(mousey>yplace+200)&&(mousex<xplace+50+70+30)&&(mousey<yplace+200+30))
89c4a3a6 sago007 2008-08-29 14:32 3202
                player1AI=!player1AI;
89c4a3a6 sago007 2008-08-29 14:32 3203
            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 3204
                player2AI=!player2AI;
89c4a3a6 sago007 2008-08-29 14:32 3205
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3206
            {
89c4a3a6 sago007 2008-08-29 14:32 3207
                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 3208
                    player1Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3209
            }
89c4a3a6 sago007 2008-08-29 14:32 3210
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3211
            {
89c4a3a6 sago007 2008-08-29 14:32 3212
                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 3213
                    player2Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3214
            }
89c4a3a6 sago007 2008-08-29 14:32 3215
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3216
            {
89c4a3a6 sago007 2008-08-29 14:32 3217
                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 3218
                    player1handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3219
            }
89c4a3a6 sago007 2008-08-29 14:32 3220
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3221
            {
89c4a3a6 sago007 2008-08-29 14:32 3222
                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 3223
                    player2handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3224
            }
27ae0175 sago007 2009-01-30 06:02 3225
            if ((mousex>xsize/2-120/2)&&(mousex<xsize/2+120/2)&&(mousey>600)&&(mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 3226
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 3227
        }
89c4a3a6 sago007 2008-08-29 14:32 3228
8d488d32 sago007 2011-04-17 13:02 3229
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3230
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3231
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3232
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3233
cc3ef158 sago007 2011-07-03 16:13 3234
    } while (!done && !Config::getInstance()->isShuttingDown());
89c4a3a6 sago007 2008-08-29 14:32 3235
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3236
}
89c4a3a6 sago007 2008-08-29 14:32 3237
89c4a3a6 sago007 2008-08-29 14:32 3238
//This function will promt for the user to select another file for puzzle mode
89c4a3a6 sago007 2008-08-29 14:32 3239
void changePuzzleLevels()
89c4a3a6 sago007 2008-08-29 14:32 3240
{
89c4a3a6 sago007 2008-08-29 14:32 3241
    char theFileName[30];
89c4a3a6 sago007 2008-08-29 14:32 3242
    strcpy(theFileName,puzzleName.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3243
    for (int i=puzzleName.length();i<30;i++)
89c4a3a6 sago007 2008-08-29 14:32 3244
        theFileName[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 3245
    theFileName[29]=0;
89c4a3a6 sago007 2008-08-29 14:32 3246
    if (OpenFileDialogbox(200,100,theFileName))
89c4a3a6 sago007 2008-08-29 14:32 3247
    {
89c4a3a6 sago007 2008-08-29 14:32 3248
        for (int i=28;((theFileName[i]==' ')&&(i>0));i--)
89c4a3a6 sago007 2008-08-29 14:32 3249
            theFileName[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3250
        puzzleName = theFileName;
89c4a3a6 sago007 2008-08-29 14:32 3251
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3252
        string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3253
        puzzleSavePath = home+"/.gamesaves/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3254
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3255
        string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3256
        if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3257
        {
89c4a3a6 sago007 2008-08-29 14:32 3258
            puzzleSavePath = home+"/My Games/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3259
        }
89c4a3a6 sago007 2008-08-29 14:32 3260
        else
89c4a3a6 sago007 2008-08-29 14:32 3261
        {
89c4a3a6 sago007 2008-08-29 14:32 3262
            puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3263
        }
89c4a3a6 sago007 2008-08-29 14:32 3264
#else
89c4a3a6 sago007 2008-08-29 14:32 3265
        puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3266
#endif
89c4a3a6 sago007 2008-08-29 14:32 3267
    }
89c4a3a6 sago007 2008-08-29 14:32 3268
89c4a3a6 sago007 2008-08-29 14:32 3269
}
89c4a3a6 sago007 2008-08-29 14:32 3270
30f910dd sago007 2010-11-10 21:02 3271
static BlockGameSdl *player1;
30f910dd sago007 2010-11-10 21:02 3272
static BlockGameSdl *player2;
30f910dd sago007 2010-11-10 21:02 3273
30f910dd sago007 2010-11-10 21:02 3274
void StartSinglePlayerEndless() {
30f910dd sago007 2010-11-10 21:02 3275
    //1 player - endless
30f910dd sago007 2010-11-10 21:02 3276
    player1->NewGame(50,100,SDL_GetTicks());
30f910dd sago007 2010-11-10 21:02 3277
    player1->putStartBlocks(time(0));
30f910dd sago007 2010-11-10 21:02 3278
    bNewGameOpen = false;
30f910dd sago007 2010-11-10 21:02 3279
    b1playerOpen = false;
30f910dd sago007 2010-11-10 21:02 3280
    twoPlayers =false;
30f910dd sago007 2010-11-10 21:02 3281
    player2->SetGameOver();
30f910dd sago007 2010-11-10 21:02 3282
    showGame = true;
30f910dd sago007 2010-11-10 21:02 3283
    strcpy(player1->name, player1name);
30f910dd sago007 2010-11-10 21:02 3284
    strcpy(player2->name, player2name);
30f910dd sago007 2010-11-10 21:02 3285
}
30f910dd sago007 2010-11-10 21:02 3286
4f1d27f1 sago007 2011-03-18 15:53 3287
void StartSinglePlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3288
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3289
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3290
    twoPlayers =false;
4f1d27f1 sago007 2011-03-18 15:53 3291
    player2->SetGameOver();
4f1d27f1 sago007 2011-03-18 15:53 3292
    showGame = true;
4f1d27f1 sago007 2011-03-18 15:53 3293
    //vsMode = false;
4f1d27f1 sago007 2011-03-18 15:53 3294
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3295
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3296
}
4f1d27f1 sago007 2011-03-18 15:53 3297
b7590374 sago007 2011-05-19 16:15 3298
void StartSinglePlayerPuzzle() {
b7590374 sago007 2011-05-19 16:15 3299
    int myLevel = PuzzleLevelSelect();
b7590374 sago007 2011-05-19 16:15 3300
    player1->NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 3301
    MakeBackground(xsize,ysize,player1,player2);
b7590374 sago007 2011-05-19 16:15 3302
    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3303
    closeAllMenus();
b7590374 sago007 2011-05-19 16:15 3304
    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 3305
    player2->SetGameOver();
b7590374 sago007 2011-05-19 16:15 3306
    showGame = true;
b7590374 sago007 2011-05-19 16:15 3307
    //vsMode = true;
b7590374 sago007 2011-05-19 16:15 3308
    strcpy(player1->name, player1name);
b7590374 sago007 2011-05-19 16:15 3309
    strcpy(player2->name, player2name);
b7590374 sago007 2011-05-19 16:15 3310
}
b7590374 sago007 2011-05-19 16:15 3311
4f1d27f1 sago007 2011-03-18 15:53 3312
4f1d27f1 sago007 2011-03-18 15:53 3313
void StarTwoPlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3314
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3315
    player2->NewTimeTrialGame(xsize-500,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3316
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3317
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3318
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3319
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3320
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3321
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3322
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3323
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3324
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3325
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3326
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3327
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3328
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3329
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3330
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3331
}
4f1d27f1 sago007 2011-03-18 15:53 3332
4f1d27f1 sago007 2011-03-18 15:53 3333
void StartTwoPlayerVs() {
4f1d27f1 sago007 2011-03-18 15:53 3334
    //2 player - VsMode
4f1d27f1 sago007 2011-03-18 15:53 3335
    player1->NewVsGame(50,100,player2,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3336
    player2->NewVsGame(xsize-500,100,player1,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3337
    bNewGameOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3338
    //vsMode = true;
4f1d27f1 sago007 2011-03-18 15:53 3339
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3340
    b2playersOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3341
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3342
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3343
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3344
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3345
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3346
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3347
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3348
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3349
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3350
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3351
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3352
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3353
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3354
}
4f1d27f1 sago007 2011-03-18 15:53 3355
1572de2b sago007 2008-09-11 18:15 3356
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3357
#include "NetworkThing.hpp"
eec83b7d sago007 2009-03-29 15:46 3358
//#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 3359
#endif
89c4a3a6 sago007 2008-08-29 14:32 3360
89c4a3a6 sago007 2008-08-29 14:32 3361
//The main function, quite big... too big
89c4a3a6 sago007 2008-08-29 14:32 3362
int main(int argc, char *argv[])
89c4a3a6 sago007 2008-08-29 14:32 3363
{
89c4a3a6 sago007 2008-08-29 14:32 3364
    //We first create the folder there we will save (only on UNIX systems)
89c4a3a6 sago007 2008-08-29 14:32 3365
    //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 3366
#if defined(__unix__)
42f8ed5f sago007 2009-03-05 11:47 3367
    //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 3368
    if(system("mkdir -p ~/.gamesaves/blockattack/screenshots"))
42f8ed5f sago007 2009-03-05 11:47 3369
        cout << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl;
42f8ed5f sago007 2009-03-05 11:47 3370
    if(system("mkdir -p ~/.gamesaves/blockattack/replays"))
42f8ed5f sago007 2009-03-05 11:47 3371
        cout << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl;
42f8ed5f sago007 2009-03-05 11:47 3372
    if(system("mkdir -p ~/.gamesaves/blockattack/puzzles"))
42f8ed5f sago007 2009-03-05 11:47 3373
        cout << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3374
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3375
    //Now for Windows NT/2k/xp/2k3 etc.
89c4a3a6 sago007 2008-08-29 14:32 3376
    string tempA = getMyDocumentsPath()+"\\My Games";
c325f4fa sago007 2009-05-09 18:33 3377
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3378
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack";
c325f4fa sago007 2009-05-09 18:33 3379
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3380
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays";
c325f4fa sago007 2009-05-09 18:33 3381
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3382
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots";
c325f4fa sago007 2009-05-09 18:33 3383
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3384
#endif
78d03b38 sago007 2008-11-13 19:56 3385
    highPriority = false;	//if true the game will take most resources, but increase framerate.
89c4a3a6 sago007 2008-08-29 14:32 3386
    bFullscreen = false;
2e57d791 sago007 2009-06-04 17:48 3387
    //Set default Config variables:
2e57d791 sago007 2009-06-04 17:48 3388
    Config::getInstance()->setDefault("themename","default");
c9dd376f sago007 2012-01-20 17:13 3389
    setlocale (LC_ALL, "");
c9dd376f sago007 2012-01-20 17:13 3390
   bindtextdomain (PACKAGE, LOCALEDIR);
c9dd376f sago007 2012-01-20 17:13 3391
   textdomain (PACKAGE);
89c4a3a6 sago007 2008-08-29 14:32 3392
    if (argc > 1)
89c4a3a6 sago007 2008-08-29 14:32 3393
    {
89c4a3a6 sago007 2008-08-29 14:32 3394
        int argumentNr = 1;
89c4a3a6 sago007 2008-08-29 14:32 3395
        forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3396
        while (argc>argumentNr)
89c4a3a6 sago007 2008-08-29 14:32 3397
        {
89c4a3a6 sago007 2008-08-29 14:32 3398
            char helpString[] = "--help";
89c4a3a6 sago007 2008-08-29 14:32 3399
            char priorityString[] = "-priority";
89c4a3a6 sago007 2008-08-29 14:32 3400
            char forceRedrawString[] = "-forceredraw";
89c4a3a6 sago007 2008-08-29 14:32 3401
            char forcepartdrawString[] = "-forcepartdraw";
89c4a3a6 sago007 2008-08-29 14:32 3402
            char singlePuzzleString[] = "-SP";
89c4a3a6 sago007 2008-08-29 14:32 3403
            char noSoundAtAll[] = "-nosound";
89c4a3a6 sago007 2008-08-29 14:32 3404
            char IntegratedEditor[] = "-editor";
2e57d791 sago007 2009-06-04 17:48 3405
            char selectTheme[] = "-theme";
89c4a3a6 sago007 2008-08-29 14:32 3406
            if (!(strncmp(argv[argumentNr],helpString,6)))
89c4a3a6 sago007 2008-08-29 14:32 3407
            {
c9dd376f sago007 2012-01-20 17:13 3408
                cout << "Block Attack Help" << endl << "--help  " << _("Displays this message") <<
c9dd376f sago007 2012-01-20 17:13 3409
                endl << "-priority  " << _("Starts game in high priority") << endl <<
c9dd376f sago007 2012-01-20 17:13 3410
                "-forceredraw  " << _("Redraw the whole screen every frame, prevents garbage") << endl <<
c9dd376f sago007 2012-01-20 17:13 3411
                "-forcepartdraw  " << _("Only draw what is changed, sometimes cause garbage") << endl <<
c9dd376f sago007 2012-01-20 17:13 3412
                "-nosound  " << _("No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)") << endl <<
c9dd376f sago007 2012-01-20 17:13 3413
                "-theme <" << _("THEMENAME") << ">  " << _("Changes to the theme <THEMENAME> on startup") << endl <<
c9dd376f sago007 2012-01-20 17:13 3414
                "-editor  " << _("Starts the build-in editor (not yet integrated)") << endl;
89c4a3a6 sago007 2008-08-29 14:32 3415
#ifdef WIN32
89c4a3a6 sago007 2008-08-29 14:32 3416
                system("Pause");
89c4a3a6 sago007 2008-08-29 14:32 3417
#endif
89c4a3a6 sago007 2008-08-29 14:32 3418
                return 0;
89c4a3a6 sago007 2008-08-29 14:32 3419
            }
89c4a3a6 sago007 2008-08-29 14:32 3420
            if (!(strncmp(argv[argumentNr],priorityString,9)))
89c4a3a6 sago007 2008-08-29 14:32 3421
            {
89c4a3a6 sago007 2008-08-29 14:32 3422
                cout << "Priority mode" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3423
                highPriority = true;
89c4a3a6 sago007 2008-08-29 14:32 3424
            }
89c4a3a6 sago007 2008-08-29 14:32 3425
            if (!(strncmp(argv[argumentNr],forceRedrawString,12)))
89c4a3a6 sago007 2008-08-29 14:32 3426
            {
89c4a3a6 sago007 2008-08-29 14:32 3427
                forceredraw = 1;
89c4a3a6 sago007 2008-08-29 14:32 3428
            }
89c4a3a6 sago007 2008-08-29 14:32 3429
            if (!(strncmp(argv[argumentNr],forcepartdrawString,14)))
89c4a3a6 sago007 2008-08-29 14:32 3430
            {
89c4a3a6 sago007 2008-08-29 14:32 3431
                forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3432
            }
89c4a3a6 sago007 2008-08-29 14:32 3433
            if (!(strncmp(argv[argumentNr],singlePuzzleString,3)))
89c4a3a6 sago007 2008-08-29 14:32 3434
            {
89c4a3a6 sago007 2008-08-29 14:32 3435
                singlePuzzle = true; //We will just have one puzzle
89c4a3a6 sago007 2008-08-29 14:32 3436
                if (argv[argumentNr+1][1]!=0)
89c4a3a6 sago007 2008-08-29 14:32 3437
                    singlePuzzleNr = (argv[argumentNr+1][1]-'0')+(argv[argumentNr+1][0]-'0')*10;
89c4a3a6 sago007 2008-08-29 14:32 3438
                else
89c4a3a6 sago007 2008-08-29 14:32 3439
                    singlePuzzleNr = (argv[argumentNr+1][0]-'0');
89c4a3a6 sago007 2008-08-29 14:32 3440
                singlePuzzleFile = argv[argumentNr+2];
89c4a3a6 sago007 2008-08-29 14:32 3441
                argumentNr+=2;
89c4a3a6 sago007 2008-08-29 14:32 3442
                cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl;
89c4a3a6 sago007 2008-08-29 14:32 3443
            }
89c4a3a6 sago007 2008-08-29 14:32 3444
            if (!(strncmp(argv[argumentNr],noSoundAtAll,8)))
89c4a3a6 sago007 2008-08-29 14:32 3445
            {
89c4a3a6 sago007 2008-08-29 14:32 3446
                NoSound = true;
89c4a3a6 sago007 2008-08-29 14:32 3447
            }
89c4a3a6 sago007 2008-08-29 14:32 3448
            if (!(strncmp(argv[argumentNr],IntegratedEditor,7)))
89c4a3a6 sago007 2008-08-29 14:32 3449
            {
1572de2b sago007 2008-09-11 18:15 3450
                #if LEVELEDITOR
89c4a3a6 sago007 2008-08-29 14:32 3451
                editorMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3452
                cout << "Integrated Puzzle Editor Activated" << endl;
1572de2b sago007 2008-09-11 18:15 3453
                #else
1572de2b sago007 2008-09-11 18:15 3454
                cout << "Integrated Puzzle Editor was disabled at compile time" << endl;
2e57d791 sago007 2009-06-04 17:48 3455
                return -1;
1572de2b sago007 2008-09-11 18:15 3456
                #endif
89c4a3a6 sago007 2008-08-29 14:32 3457
            }
2e57d791 sago007 2009-06-04 17:48 3458
            if(!(strncmp(argv[argumentNr],selectTheme,6)))
2e57d791 sago007 2009-06-04 17:48 3459
            {
2e57d791 sago007 2009-06-04 17:48 3460
                argumentNr++; //Go to themename (the next argument)
2e57d791 sago007 2009-06-04 17:48 3461
                cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
2e57d791 sago007 2009-06-04 17:48 3462
                Config::getInstance()->setString("themename",argv[argumentNr]);
2e57d791 sago007 2009-06-04 17:48 3463
            }
89c4a3a6 sago007 2008-08-29 14:32 3464
            argumentNr++;
89c4a3a6 sago007 2008-08-29 14:32 3465
        }   //while
89c4a3a6 sago007 2008-08-29 14:32 3466
    }   //if
89c4a3a6 sago007 2008-08-29 14:32 3467
89c4a3a6 sago007 2008-08-29 14:32 3468
    SoundEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3469
    MusicEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3470
    int mousex, mousey;   //Mouse coordinates
89c4a3a6 sago007 2008-08-29 14:32 3471
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3472
    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3473
    b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3474
    bReplayOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3475
    bScreenLocked = false;
f72abf8b sago007 2010-01-16 20:00 3476
    twoPlayers = false;	//true if two players splitscreen
89c4a3a6 sago007 2008-08-29 14:32 3477
    bool vsMode = false;
89c4a3a6 sago007 2008-08-29 14:32 3478
    theTopScoresEndless = Highscore(1);
89c4a3a6 sago007 2008-08-29 14:32 3479
    theTopScoresTimeTrial = Highscore(2);
89c4a3a6 sago007 2008-08-29 14:32 3480
    drawBalls = true;
89c4a3a6 sago007 2008-08-29 14:32 3481
    puzzleLoaded = false;
89c4a3a6 sago007 2008-08-29 14:32 3482
    bool weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3483
89c4a3a6 sago007 2008-08-29 14:32 3484
    //Things used for repeating keystrokes:
30f910dd sago007 2010-11-10 21:02 3485
    bool repeatingS[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3486
    bool repeatingW[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3487
    bool repeatingN[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3488
    bool repeatingE[2] = {false,false};
89c4a3a6 sago007 2008-08-29 14:32 3489
    const int startRepeat = 200;
89c4a3a6 sago007 2008-08-29 14:32 3490
    const int repeatDelay = 100;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 3491
    unsigned long timeHeldP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3492
    unsigned long timeHeldP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3493
    unsigned long timeHeldP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3494
    unsigned long timeHeldP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3495
    unsigned long timeHeldP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3496
    unsigned long timeHeldP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3497
    unsigned long timeHeldP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3498
    unsigned long timeHeldP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3499
    unsigned long timesRepeatedP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3500
    unsigned long timesRepeatedP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3501
    unsigned long timesRepeatedP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3502
    unsigned long timesRepeatedP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3503
    unsigned long timesRepeatedP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3504
    unsigned long timesRepeatedP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3505
    unsigned long timesRepeatedP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3506
    unsigned long timesRepeatedP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3507
89c4a3a6 sago007 2008-08-29 14:32 3508
    theBallManeger = ballManeger();
89c4a3a6 sago007 2008-08-29 14:32 3509
    theExplosionManeger = explosionManeger();
89c4a3a6 sago007 2008-08-29 14:32 3510
89c4a3a6 sago007 2008-08-29 14:32 3511
//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 3512
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3513
    string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3514
    string optionsPath = home+"/.gamesaves/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3515
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3516
    string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3517
    string optionsPath;
89c4a3a6 sago007 2008-08-29 14:32 3518
    if (&home!=NULL) //Null if no APPDATA dir exists (win 9x)
89c4a3a6 sago007 2008-08-29 14:32 3519
        optionsPath = home+"/My Games/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3520
    else
89c4a3a6 sago007 2008-08-29 14:32 3521
        optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3522
#else
89c4a3a6 sago007 2008-08-29 14:32 3523
    string optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3524
#endif
89c4a3a6 sago007 2008-08-29 14:32 3525
89c4a3a6 sago007 2008-08-29 14:32 3526
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3527
    stageClearSavePath = home+"/.gamesaves/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3528
    puzzleSavePath = home+"/.gamesaves/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3529
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3530
    if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3531
    {
89c4a3a6 sago007 2008-08-29 14:32 3532
        stageClearSavePath = home+"/My Games/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3533
        puzzleSavePath = home+"/My Games/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3534
    }
89c4a3a6 sago007 2008-08-29 14:32 3535
    else
89c4a3a6 sago007 2008-08-29 14:32 3536
    {
89c4a3a6 sago007 2008-08-29 14:32 3537
        stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3538
        puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3539
    }
89c4a3a6 sago007 2008-08-29 14:32 3540
#else
89c4a3a6 sago007 2008-08-29 14:32 3541
    stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3542
    puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3543
#endif
89c4a3a6 sago007 2008-08-29 14:32 3544
    puzzleName="puzzle.levels";
89c4a3a6 sago007 2008-08-29 14:32 3545
89c4a3a6 sago007 2008-08-29 14:32 3546
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3547
866417ca sago007 2009-05-10 21:35 3548
95bc02ff sago007 2009-03-15 02:46 3549
89c4a3a6 sago007 2008-08-29 14:32 3550
    //Init SDL
89c4a3a6 sago007 2008-08-29 14:32 3551
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
89c4a3a6 sago007 2008-08-29 14:32 3552
    {
89c4a3a6 sago007 2008-08-29 14:32 3553
        cout << "Unable to init SDL: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3554
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3555
    }
89c4a3a6 sago007 2008-08-29 14:32 3556
    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 3557
    
89c4a3a6 sago007 2008-08-29 14:32 3558
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
89c4a3a6 sago007 2008-08-29 14:32 3559
89c4a3a6 sago007 2008-08-29 14:32 3560
    Joypad_init();    //Prepare the joysticks
89c4a3a6 sago007 2008-08-29 14:32 3561
89c4a3a6 sago007 2008-08-29 14:32 3562
    Joypad joypad1 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3563
    Joypad joypad2 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3564
89c4a3a6 sago007 2008-08-29 14:32 3565
    theTextManeger = textManeger();
89c4a3a6 sago007 2008-08-29 14:32 3566
89c4a3a6 sago007 2008-08-29 14:32 3567
    //Open Audio
89c4a3a6 sago007 2008-08-29 14:32 3568
    if (!NoSound) //If sound has not been disabled, then load the sound system
89c4a3a6 sago007 2008-08-29 14:32 3569
        if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
89c4a3a6 sago007 2008-08-29 14:32 3570
        {
89c4a3a6 sago007 2008-08-29 14:32 3571
            cout << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
89c4a3a6 sago007 2008-08-29 14:32 3572
            << "Sound will be disabled!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3573
            NoSound = true; //Tries to stop all sound from playing/loading
89c4a3a6 sago007 2008-08-29 14:32 3574
        }
89c4a3a6 sago007 2008-08-29 14:32 3575
89c4a3a6 sago007 2008-08-29 14:32 3576
    SDL_WM_SetCaption("Block Attack - Rise of the Blocks", NULL); //Sets title line
866417ca sago007 2009-05-10 21:35 3577
    
89c4a3a6 sago007 2008-08-29 14:32 3578
89c4a3a6 sago007 2008-08-29 14:32 3579
    //Copyright notice:
4f1d27f1 sago007 2011-03-18 15:53 3580
    cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << endl << "http://blockattack.sf.net" << endl << "Copyright 2004-2011 Poul Sander" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3581
    "A SDL based game (see www.libsdl.org)" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3582
    "The game is availeble under the GPL, see COPYING for details." << endl;
89c4a3a6 sago007 2008-08-29 14:32 3583
#if defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3584
    cout << "Windows build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3585
#elif defined(__linux__)
89c4a3a6 sago007 2008-08-29 14:32 3586
    cout << "Linux build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3587
#elif defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3588
    cout << "Unix build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3589
#else
89c4a3a6 sago007 2008-08-29 14:32 3590
    cout << "Alternative build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3591
#endif
89c4a3a6 sago007 2008-08-29 14:32 3592
    cout << "-------------------------------------------" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3593
95bc02ff sago007 2009-03-15 02:46 3594
89c4a3a6 sago007 2008-08-29 14:32 3595
    keySettings[0].up= SDLK_UP;
89c4a3a6 sago007 2008-08-29 14:32 3596
    keySettings[0].down = SDLK_DOWN;
89c4a3a6 sago007 2008-08-29 14:32 3597
    keySettings[0].left = SDLK_LEFT;
89c4a3a6 sago007 2008-08-29 14:32 3598
    keySettings[0].right = SDLK_RIGHT;
6d48320c sago007 2009-03-28 17:06 3599
    keySettings[0].change = SDLK_RCTRL;
6d48320c sago007 2009-03-28 17:06 3600
    keySettings[0].push = SDLK_RSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3601
89c4a3a6 sago007 2008-08-29 14:32 3602
    keySettings[2].up= SDLK_w;
89c4a3a6 sago007 2008-08-29 14:32 3603
    keySettings[2].down = SDLK_s;
89c4a3a6 sago007 2008-08-29 14:32 3604
    keySettings[2].left = SDLK_a;
89c4a3a6 sago007 2008-08-29 14:32 3605
    keySettings[2].right = SDLK_d;
89c4a3a6 sago007 2008-08-29 14:32 3606
    keySettings[2].change = SDLK_LCTRL;
89c4a3a6 sago007 2008-08-29 14:32 3607
    keySettings[2].push = SDLK_LSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3608
89c4a3a6 sago007 2008-08-29 14:32 3609
    player1keys=0;
89c4a3a6 sago007 2008-08-29 14:32 3610
    player2keys=2;
89c4a3a6 sago007 2008-08-29 14:32 3611
89c4a3a6 sago007 2008-08-29 14:32 3612
    strcpy(player1name, "Player 1                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3613
    strcpy(player2name, "Player 2                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3614
769a41a0 sago007 2008-09-24 12:54 3615
    Config *configSettings = Config::getInstance();
769a41a0 sago007 2008-09-24 12:54 3616
    //configSettings->setString("aNumber"," A string");
769a41a0 sago007 2008-09-24 12:54 3617
    //configSettings->save();
769a41a0 sago007 2008-09-24 12:54 3618
    if(configSettings->exists("fullscreen")) //Test if an configFile exists
89c4a3a6 sago007 2008-08-29 14:32 3619
    {
769a41a0 sago007 2008-09-24 12:54 3620
        bFullscreen = (bool)configSettings->getInt("fullscreen");
769a41a0 sago007 2008-09-24 12:54 3621
        MusicEnabled = (bool)configSettings->getInt("musicenabled");
769a41a0 sago007 2008-09-24 12:54 3622
        SoundEnabled = (bool)configSettings->getInt("soundenabled");
769a41a0 sago007 2008-09-24 12:54 3623
        mouseplay1 = (bool)configSettings->getInt("mouseplay1");
769a41a0 sago007 2008-09-24 12:54 3624
        mouseplay2 = (bool)configSettings->getInt("mouseplay2");
769a41a0 sago007 2008-09-24 12:54 3625
        joyplay1 = (bool)configSettings->getInt("joypad1");
769a41a0 sago007 2008-09-24 12:54 3626
        joyplay2 = (bool)configSettings->getInt("joypad2");
769a41a0 sago007 2008-09-24 12:54 3627
        
769a41a0 sago007 2008-09-24 12:54 3628
        if(configSettings->exists("player1keyup")) keySettings[0].up = (SDLKey)configSettings->getInt("player1keyup");
769a41a0 sago007 2008-09-24 12:54 3629
        if(configSettings->exists("player1keydown")) keySettings[0].down = (SDLKey)configSettings->getInt("player1keydown");
769a41a0 sago007 2008-09-24 12:54 3630
        if(configSettings->exists("player1keyleft")) keySettings[0].left = (SDLKey)configSettings->getInt("player1keyleft");
769a41a0 sago007 2008-09-24 12:54 3631
        if(configSettings->exists("player1keyright")) keySettings[0].right = (SDLKey)configSettings->getInt("player1keyright");
769a41a0 sago007 2008-09-24 12:54 3632
        if(configSettings->exists("player1keychange")) keySettings[0].change = (SDLKey)configSettings->getInt("player1keychange");
769a41a0 sago007 2008-09-24 12:54 3633
        if(configSettings->exists("player1keypush")) keySettings[0].push = (SDLKey)configSettings->getInt("player1keypush");
769a41a0 sago007 2008-09-24 12:54 3634
        
769a41a0 sago007 2008-09-24 12:54 3635
        if(configSettings->exists("player2keyup")) keySettings[2].up = (SDLKey)configSettings->getInt("player2keyup");
769a41a0 sago007 2008-09-24 12:54 3636
        if(configSettings->exists("player2keydown")) keySettings[2].down = (SDLKey)configSettings->getInt("player2keydown");
769a41a0 sago007 2008-09-24 12:54 3637
        if(configSettings->exists("player2keyleft")) keySettings[2].left = (SDLKey)configSettings->getInt("player2keyleft");
769a41a0 sago007 2008-09-24 12:54 3638
        if(configSettings->exists("player2keyright")) keySettings[2].right = (SDLKey)configSettings->getInt("player2keyright");
769a41a0 sago007 2008-09-24 12:54 3639
        if(configSettings->exists("player2keychange")) keySettings[2].change = (SDLKey)configSettings->getInt("player2keychange");
769a41a0 sago007 2008-09-24 12:54 3640
        if(configSettings->exists("player2keypush")) keySettings[2].push = (SDLKey)configSettings->getInt("player2keypush");
769a41a0 sago007 2008-09-24 12:54 3641
        if(configSettings->exists("player1name"))
769a41a0 sago007 2008-09-24 12:54 3642
            strncpy(player1name,(configSettings->getString("player1name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3643
        if(configSettings->exists("player2name"))
769a41a0 sago007 2008-09-24 12:54 3644
            strncpy(player2name,(configSettings->getString("player2name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3645
        cout << "Data loaded from config file" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3646
    }
89c4a3a6 sago007 2008-08-29 14:32 3647
    else
89c4a3a6 sago007 2008-08-29 14:32 3648
    {
769a41a0 sago007 2008-09-24 12:54 3649
        //Reads options from file:
769a41a0 sago007 2008-09-24 12:54 3650
        ifstream optionsFile(optionsPath.c_str(), ios::binary);
769a41a0 sago007 2008-09-24 12:54 3651
        if (optionsFile)
769a41a0 sago007 2008-09-24 12:54 3652
        {
769a41a0 sago007 2008-09-24 12:54 3653
            //reads data: xsize,ysize,fullescreen, player1keys, player2keys, MusicEnabled, SoundEnabled,player1name,player2name
769a41a0 sago007 2008-09-24 12:54 3654
            optionsFile.read(reinterpret_cast<char*>(&xsize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3655
            optionsFile.read(reinterpret_cast<char*>(&ysize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3656
            optionsFile.read(reinterpret_cast<char*>(&bFullscreen), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3657
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3658
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3659
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3660
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3661
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3662
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3663
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3664
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3665
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3666
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3667
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3668
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3669
            optionsFile.read(reinterpret_cast<char*>(&MusicEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3670
            optionsFile.read(reinterpret_cast<char*>(&SoundEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3671
            optionsFile.read(player1name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3672
            optionsFile.read(player2name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3673
            //mouseplay?
769a41a0 sago007 2008-09-24 12:54 3674
            if (!optionsFile.eof())
769a41a0 sago007 2008-09-24 12:54 3675
            {
769a41a0 sago007 2008-09-24 12:54 3676
                optionsFile.read(reinterpret_cast<char*>(&mouseplay1), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3677
                optionsFile.read(reinterpret_cast<char*>(&mouseplay2), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3678
                optionsFile.read(reinterpret_cast<char*>(&joyplay1),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3679
                optionsFile.read(reinterpret_cast<char*>(&joyplay2),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3680
            }
769a41a0 sago007 2008-09-24 12:54 3681
            optionsFile.close();
769a41a0 sago007 2008-09-24 12:54 3682
            cout << "Data loaded from oldstyle options file" << endl;
769a41a0 sago007 2008-09-24 12:54 3683
        }
769a41a0 sago007 2008-09-24 12:54 3684
        else
769a41a0 sago007 2008-09-24 12:54 3685
        {
769a41a0 sago007 2008-09-24 12:54 3686
            cout << "Unable to load options file, using default values" << endl;
769a41a0 sago007 2008-09-24 12:54 3687
        }
89c4a3a6 sago007 2008-08-29 14:32 3688
    }
27ae0175 sago007 2009-01-30 06:02 3689
    
27ae0175 sago007 2009-01-30 06:02 3690
#if NETWORK
27ae0175 sago007 2009-01-30 06:02 3691
    strcpy(serverAddress, "192.168.0.2                 \0");
27ae0175 sago007 2009-01-30 06:02 3692
    if(configSettings->exists("address0"))
27ae0175 sago007 2009-01-30 06:02 3693
    {
27ae0175 sago007 2009-01-30 06:02 3694
        strcpy(serverAddress, "                            \0");
27ae0175 sago007 2009-01-30 06:02 3695
        strncpy(serverAddress,configSettings->getString("address0").c_str(),sizeof(serverAddress)-1);
27ae0175 sago007 2009-01-30 06:02 3696
    }
27ae0175 sago007 2009-01-30 06:02 3697
#endif
89c4a3a6 sago007 2008-08-29 14:32 3698
89c4a3a6 sago007 2008-08-29 14:32 3699
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3700
    {
89c4a3a6 sago007 2008-08-29 14:32 3701
        xsize=300;
89c4a3a6 sago007 2008-08-29 14:32 3702
        ysize=600;
89c4a3a6 sago007 2008-08-29 14:32 3703
    }
89c4a3a6 sago007 2008-08-29 14:32 3704
    
89c4a3a6 sago007 2008-08-29 14:32 3705
    
89c4a3a6 sago007 2008-08-29 14:32 3706
    //Open video
89c4a3a6 sago007 2008-08-29 14:32 3707
    if ((bFullscreen)&&(!singlePuzzle)) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3708
    else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3709
89c4a3a6 sago007 2008-08-29 14:32 3710
    if ( screen == NULL )
89c4a3a6 sago007 2008-08-29 14:32 3711
    {
89c4a3a6 sago007 2008-08-29 14:32 3712
        cout << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3713
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3714
    }
89c4a3a6 sago007 2008-08-29 14:32 3715
866417ca sago007 2009-05-10 21:35 3716
    //Init the file system abstraction layer
866417ca sago007 2009-05-10 21:35 3717
    PHYSFS_init(argv[0]);
866417ca sago007 2009-05-10 21:35 3718
    //Load default theme
2e57d791 sago007 2009-06-04 17:48 3719
    loadTheme(Config::getInstance()->getString("themename"));
866417ca sago007 2009-05-10 21:35 3720
    //Now sets the icon:
1f61db96 sago007 2010-11-15 20:12 3721
    SDL_Surface *icon = IMG_Load2("gfx/icon.png");
866417ca sago007 2009-05-10 21:35 3722
    SDL_WM_SetIcon(icon,NULL);
89c4a3a6 sago007 2008-08-29 14:32 3723
89c4a3a6 sago007 2008-08-29 14:32 3724
    cout << "Images loaded" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3725
78d03b38 sago007 2008-11-13 19:56 3726
    //InitMenues();
89c4a3a6 sago007 2008-08-29 14:32 3727
6b1dc7a6 sago007 2010-11-08 21:03 3728
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
6b1dc7a6 sago007 2010-11-08 21:03 3729
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
30f910dd sago007 2010-11-10 21:02 3730
    player1 = &theGame;
30f910dd sago007 2010-11-10 21:02 3731
    player2 = &theGame2;
e1290bdf sago007 2010-10-25 19:56 3732
    /*if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3733
    {
e1290bdf sago007 2010-10-25 19:56 3734
        theGame.GetTopY()=0;
e1290bdf sago007 2010-10-25 19:56 3735
        theGame.GetTopX()=0;
e1290bdf sago007 2010-10-25 19:56 3736
        theGame2.GetTopY()=10000;
e1290bdf sago007 2010-10-25 19:56 3737
        theGame2.GetTopX()=10000;
e1290bdf sago007 2010-10-25 19:56 3738
    }*/
89c4a3a6 sago007 2008-08-29 14:32 3739
    theGame.DoPaintJob();			//Makes sure what there is something to paint
89c4a3a6 sago007 2008-08-29 14:32 3740
    theGame2.DoPaintJob();
89c4a3a6 sago007 2008-08-29 14:32 3741
    theGame.SetGameOver();		//sets the game over in the beginning
89c4a3a6 sago007 2008-08-29 14:32 3742
    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 3743
89c4a3a6 sago007 2008-08-29 14:32 3744
89c4a3a6 sago007 2008-08-29 14:32 3745
    //Takes names from file instead
89c4a3a6 sago007 2008-08-29 14:32 3746
    strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 3747
    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 3748
89c4a3a6 sago007 2008-08-29 14:32 3749
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3750
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3751
89c4a3a6 sago007 2008-08-29 14:32 3752
1572de2b sago007 2008-09-11 18:15 3753
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3754
    NetworkThing nt = NetworkThing();
89c4a3a6 sago007 2008-08-29 14:32 3755
    nt.setBGpointers(&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3756
#endif
89c4a3a6 sago007 2008-08-29 14:32 3757
89c4a3a6 sago007 2008-08-29 14:32 3758
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3759
    {
89c4a3a6 sago007 2008-08-29 14:32 3760
        LoadPuzzleStages();
e1290bdf sago007 2010-10-25 19:56 3761
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3762
        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 3763
        vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3764
    }
89c4a3a6 sago007 2008-08-29 14:32 3765
    //Draws everything to screen
89c4a3a6 sago007 2008-08-29 14:32 3766
    if (!editorMode)
e1290bdf sago007 2010-10-25 19:56 3767
        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3768
    else
e1290bdf sago007 2010-10-25 19:56 3769
        MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 3770
    DrawIMG(background, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 3771
    DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3772
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3773
    //game loop
cc3ef158 sago007 2011-07-03 16:13 3774
    MainMenu();
89c4a3a6 sago007 2008-08-29 14:32 3775
89c4a3a6 sago007 2008-08-29 14:32 3776
89c4a3a6 sago007 2008-08-29 14:32 3777
89c4a3a6 sago007 2008-08-29 14:32 3778
    //Saves options
89c4a3a6 sago007 2008-08-29 14:32 3779
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 3780
    {
769a41a0 sago007 2008-09-24 12:54 3781
        configSettings->setInt("fullscreen",(int)bFullscreen);
769a41a0 sago007 2008-09-24 12:54 3782
        configSettings->setInt("musicenabled",(int)MusicEnabled);
769a41a0 sago007 2008-09-24 12:54 3783
        configSettings->setInt("soundenabled",(int)SoundEnabled);
769a41a0 sago007 2008-09-24 12:54 3784
        configSettings->setInt("mouseplay1",(int)mouseplay1);
769a41a0 sago007 2008-09-24 12:54 3785
        configSettings->setInt("mouseplay2",(int)mouseplay2);
769a41a0 sago007 2008-09-24 12:54 3786
        configSettings->setInt("joypad1",(int)joyplay1);
769a41a0 sago007 2008-09-24 12:54 3787
        configSettings->setInt("joypad2",(int)joyplay2);
769a41a0 sago007 2008-09-24 12:54 3788
        
769a41a0 sago007 2008-09-24 12:54 3789
        configSettings->setInt("player1keyup",(int)keySettings[0].up);
769a41a0 sago007 2008-09-24 12:54 3790
        configSettings->setInt("player1keydown",(int)keySettings[0].down);
769a41a0 sago007 2008-09-24 12:54 3791
        configSettings->setInt("player1keyleft",(int)keySettings[0].left);
769a41a0 sago007 2008-09-24 12:54 3792
        configSettings->setInt("player1keyright",(int)keySettings[0].right);
769a41a0 sago007 2008-09-24 12:54 3793
        configSettings->setInt("player1keychange",(int)keySettings[0].change);
769a41a0 sago007 2008-09-24 12:54 3794
        configSettings->setInt("player1keypush",(int)keySettings[0].push);
769a41a0 sago007 2008-09-24 12:54 3795
        
769a41a0 sago007 2008-09-24 12:54 3796
        configSettings->setInt("player2keyup",(int)keySettings[2].up);
769a41a0 sago007 2008-09-24 12:54 3797
        configSettings->setInt("player2keydown",(int)keySettings[2].down);
769a41a0 sago007 2008-09-24 12:54 3798
        configSettings->setInt("player2keyleft",(int)keySettings[2].left);
769a41a0 sago007 2008-09-24 12:54 3799
        configSettings->setInt("player2keyright",(int)keySettings[2].right);
769a41a0 sago007 2008-09-24 12:54 3800
        configSettings->setInt("player2keychange",(int)keySettings[2].change);
769a41a0 sago007 2008-09-24 12:54 3801
        configSettings->setInt("player2keypush",(int)keySettings[2].push);
769a41a0 sago007 2008-09-24 12:54 3802
        
769a41a0 sago007 2008-09-24 12:54 3803
        configSettings->setString("player1name",player1name);
769a41a0 sago007 2008-09-24 12:54 3804
        configSettings->setString("player2name",player2name);
769a41a0 sago007 2008-09-24 12:54 3805
        configSettings->save();
89c4a3a6 sago007 2008-08-29 14:32 3806
    }
89c4a3a6 sago007 2008-08-29 14:32 3807
89c4a3a6 sago007 2008-08-29 14:32 3808
    //calculate uptime:
c09d0e4f sago007 2009-01-27 01:15 3809
    //int hours, mins, secs,
cd12e0fe sago007 2009-01-29 08:47 3810
    commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3811
c9dd376f sago007 2012-01-20 17:13 3812
    //cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
c9dd376f sago007 2012-01-20 17:13 3813
    cout << boost::format("Block Attack - Rise of the Blocks ran for: %1% hours %2% mins and %3% secs") % ct.hours % ct.minutes % ct.seconds << endl;
c9dd376f sago007 2012-01-20 17:13 3814
    
cd12e0fe sago007 2009-01-29 08:47 3815
    ct = TimeHandler::addTime("totalTime",ct);
c09d0e4f sago007 2009-01-27 01:15 3816
89c4a3a6 sago007 2008-08-29 14:32 3817
    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 3818
c09d0e4f sago007 2009-01-27 01:15 3819
    Stats::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 3820
c09d0e4f sago007 2009-01-27 01:15 3821
    Config::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 3822
    
c09d0e4f sago007 2009-01-27 01:15 3823
    //Frees memory from music and fonts
c09d0e4f sago007 2009-01-27 01:15 3824
    //This is done after writing of configurations and stats since it often crashes the program :(
c09d0e4f sago007 2009-01-27 01:15 3825
    UnloadImages();
41f02ab2 sago007 2009-05-10 21:40 3826
      
91886cae sago007 2008-09-12 16:28 3827
    //Close file system Apstraction layer!
91886cae sago007 2008-09-12 16:28 3828
    PHYSFS_deinit();
89c4a3a6 sago007 2008-08-29 14:32 3829
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 3830
}
b7590374 sago007 2011-05-19 16:15 3831
b7590374 sago007 2011-05-19 16:15 3832
b7590374 sago007 2011-05-19 16:15 3833
void runGame(int gametype) {
b7590374 sago007 2011-05-19 16:15 3834
    Uint8 *keys;
b7590374 sago007 2011-05-19 16:15 3835
     int mousex, mousey;   //Mouse coordinates
b7590374 sago007 2011-05-19 16:15 3836
    showOptions = false;
b7590374 sago007 2011-05-19 16:15 3837
    b1playerOpen = false;
b7590374 sago007 2011-05-19 16:15 3838
    b2playersOpen = false;
b7590374 sago007 2011-05-19 16:15 3839
    bReplayOpen = false;
b7590374 sago007 2011-05-19 16:15 3840
    bScreenLocked = false;
b7590374 sago007 2011-05-19 16:15 3841
    bool vsMode = false;
b7590374 sago007 2011-05-19 16:15 3842
    theTopScoresEndless = Highscore(1);
b7590374 sago007 2011-05-19 16:15 3843
    theTopScoresTimeTrial = Highscore(2);
b7590374 sago007 2011-05-19 16:15 3844
    drawBalls = true;
b7590374 sago007 2011-05-19 16:15 3845
    puzzleLoaded = false;
b7590374 sago007 2011-05-19 16:15 3846
    bool weWhereConnected = false;
b7590374 sago007 2011-05-19 16:15 3847
b7590374 sago007 2011-05-19 16:15 3848
    //Things used for repeating keystrokes:
b7590374 sago007 2011-05-19 16:15 3849
    bool repeatingS[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 3850
    bool repeatingW[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 3851
    bool repeatingN[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 3852
    bool repeatingE[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 3853
    const int startRepeat = 200;
b7590374 sago007 2011-05-19 16:15 3854
    const int repeatDelay = 100;    //Repeating
b7590374 sago007 2011-05-19 16:15 3855
    unsigned long timeHeldP1N = 0;
b7590374 sago007 2011-05-19 16:15 3856
    unsigned long timeHeldP1S = 0;
b7590374 sago007 2011-05-19 16:15 3857
    unsigned long timeHeldP1E = 0;
b7590374 sago007 2011-05-19 16:15 3858
    unsigned long timeHeldP1W = 0;
b7590374 sago007 2011-05-19 16:15 3859
    unsigned long timeHeldP2N = 0;
b7590374 sago007 2011-05-19 16:15 3860
    unsigned long timeHeldP2S = 0;
b7590374 sago007 2011-05-19 16:15 3861
    unsigned long timeHeldP2E = 0;
b7590374 sago007 2011-05-19 16:15 3862
    unsigned long timeHeldP2W = 0;
b7590374 sago007 2011-05-19 16:15 3863
    unsigned long timesRepeatedP1N = 0;
b7590374 sago007 2011-05-19 16:15 3864
    unsigned long timesRepeatedP1S = 0;
b7590374 sago007 2011-05-19 16:15 3865
    unsigned long timesRepeatedP1E = 0;
b7590374 sago007 2011-05-19 16:15 3866
    unsigned long timesRepeatedP1W = 0;
b7590374 sago007 2011-05-19 16:15 3867
    unsigned long timesRepeatedP2N = 0;
b7590374 sago007 2011-05-19 16:15 3868
    unsigned long timesRepeatedP2S = 0;
b7590374 sago007 2011-05-19 16:15 3869
    unsigned long timesRepeatedP2E = 0;
b7590374 sago007 2011-05-19 16:15 3870
    unsigned long timesRepeatedP2W = 0;
b7590374 sago007 2011-05-19 16:15 3871
b7590374 sago007 2011-05-19 16:15 3872
    theBallManeger = ballManeger();
b7590374 sago007 2011-05-19 16:15 3873
    theExplosionManeger = explosionManeger();
b7590374 sago007 2011-05-19 16:15 3874
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
b7590374 sago007 2011-05-19 16:15 3875
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
b7590374 sago007 2011-05-19 16:15 3876
    player1 = &theGame;
b7590374 sago007 2011-05-19 16:15 3877
    player2 = &theGame2;
b7590374 sago007 2011-05-19 16:15 3878
    /*if (singlePuzzle)
b7590374 sago007 2011-05-19 16:15 3879
    {
b7590374 sago007 2011-05-19 16:15 3880
        theGame.GetTopY()=0;
b7590374 sago007 2011-05-19 16:15 3881
        theGame.GetTopX()=0;
b7590374 sago007 2011-05-19 16:15 3882
        theGame2.GetTopY()=10000;
b7590374 sago007 2011-05-19 16:15 3883
        theGame2.GetTopX()=10000;
b7590374 sago007 2011-05-19 16:15 3884
    }*/
b7590374 sago007 2011-05-19 16:15 3885
    theGame.DoPaintJob();			//Makes sure what there is something to paint
b7590374 sago007 2011-05-19 16:15 3886
    theGame2.DoPaintJob();
b7590374 sago007 2011-05-19 16:15 3887
    theGame.SetGameOver();		//sets the game over in the beginning
b7590374 sago007 2011-05-19 16:15 3888
    theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 3889
b7590374 sago007 2011-05-19 16:15 3890
b7590374 sago007 2011-05-19 16:15 3891
    //Takes names from file instead
b7590374 sago007 2011-05-19 16:15 3892
    strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 3893
    strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 3894
b7590374 sago007 2011-05-19 16:15 3895
b7590374 sago007 2011-05-19 16:15 3896
    Joypad joypad1 = Joypad();    //Creates a joypad
b7590374 sago007 2011-05-19 16:15 3897
    Joypad joypad2 = Joypad();    //Creates a joypad
b7590374 sago007 2011-05-19 16:15 3898
b7590374 sago007 2011-05-19 16:15 3899
    //Keeps track of background;
b7590374 sago007 2011-05-19 16:15 3900
    int nowTime=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 3901
b7590374 sago007 2011-05-19 16:15 3902
b7590374 sago007 2011-05-19 16:15 3903
#if NETWORK
b7590374 sago007 2011-05-19 16:15 3904
    NetworkThing nt = NetworkThing();
b7590374 sago007 2011-05-19 16:15 3905
    nt.setBGpointers(&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 3906
#endif
b7590374 sago007 2011-05-19 16:15 3907
b7590374 sago007 2011-05-19 16:15 3908
    if (singlePuzzle)
b7590374 sago007 2011-05-19 16:15 3909
    {
b7590374 sago007 2011-05-19 16:15 3910
        LoadPuzzleStages();
b7590374 sago007 2011-05-19 16:15 3911
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 3912
        showGame = true;
b7590374 sago007 2011-05-19 16:15 3913
        vsMode = true;
b7590374 sago007 2011-05-19 16:15 3914
    }
b7590374 sago007 2011-05-19 16:15 3915
    //Draws everything to screen
b7590374 sago007 2011-05-19 16:15 3916
    if (!editorMode)
b7590374 sago007 2011-05-19 16:15 3917
        MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 3918
    else
b7590374 sago007 2011-05-19 16:15 3919
        MakeBackground(xsize,ysize,&theGame);
b7590374 sago007 2011-05-19 16:15 3920
    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3921
    DrawEverything(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 3922
    SDL_Flip(screen);
b7590374 sago007 2011-05-19 16:15 3923
    //game loop
b7590374 sago007 2011-05-19 16:15 3924
    int done = 0;
b7590374 sago007 2011-05-19 16:15 3925
    cout << "Starting game loop" << endl;
b7590374 sago007 2011-05-19 16:15 3926
69d650b4 sago007 2011-07-20 15:24 3927
    
69d650b4 sago007 2011-07-20 15:24 3928
    bool mustsetupgame = true;
69d650b4 sago007 2011-07-20 15:24 3929
    
b7590374 sago007 2011-05-19 16:15 3930
    while (done == 0)
b7590374 sago007 2011-05-19 16:15 3931
    {
69d650b4 sago007 2011-07-20 15:24 3932
        if(mustsetupgame) {
69d650b4 sago007 2011-07-20 15:24 3933
            switch(gametype) {
69d650b4 sago007 2011-07-20 15:24 3934
                case 1:
69d650b4 sago007 2011-07-20 15:24 3935
                    StartSinglePlayerTimeTrial();
69d650b4 sago007 2011-07-20 15:24 3936
                    break;
69d650b4 sago007 2011-07-20 15:24 3937
                case 3:
69d650b4 sago007 2011-07-20 15:24 3938
                    StartSinglePlayerPuzzle();
69d650b4 sago007 2011-07-20 15:24 3939
                    break;
69d650b4 sago007 2011-07-20 15:24 3940
                case 4:
69d650b4 sago007 2011-07-20 15:24 3941
                {
69d650b4 sago007 2011-07-20 15:24 3942
                    //1 player - Vs mode
69d650b4 sago007 2011-07-20 15:24 3943
                    bNewGameOpen = false;
69d650b4 sago007 2011-07-20 15:24 3944
                    b1playerOpen = false;
69d650b4 sago007 2011-07-20 15:24 3945
                    int theAIlevel = startSingleVs();
69d650b4 sago007 2011-07-20 15:24 3946
                    theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
69d650b4 sago007 2011-07-20 15:24 3947
                    theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
69d650b4 sago007 2011-07-20 15:24 3948
                    MakeBackground(xsize,ysize,&theGame,&theGame2);
69d650b4 sago007 2011-07-20 15:24 3949
                    DrawIMG(background, screen, 0, 0);
69d650b4 sago007 2011-07-20 15:24 3950
                    twoPlayers = true; //Single player, but AI plays
69d650b4 sago007 2011-07-20 15:24 3951
                    showGame = true;
69d650b4 sago007 2011-07-20 15:24 3952
                    vsMode = true;
69d650b4 sago007 2011-07-20 15:24 3953
                    theGame2.setAIlevel((Uint8)theAIlevel);
69d650b4 sago007 2011-07-20 15:24 3954
                    int theTime = time(0);
69d650b4 sago007 2011-07-20 15:24 3955
                    theGame.putStartBlocks(theTime);
69d650b4 sago007 2011-07-20 15:24 3956
                    theGame2.putStartBlocks(theTime);
69d650b4 sago007 2011-07-20 15:24 3957
                    strcpy(theGame.name, player1name);
69d650b4 sago007 2011-07-20 15:24 3958
                    strcpy(theGame2.name, player2name);
69d650b4 sago007 2011-07-20 15:24 3959
                }
69d650b4 sago007 2011-07-20 15:24 3960
                    break;
69d650b4 sago007 2011-07-20 15:24 3961
                case 0:
69d650b4 sago007 2011-07-20 15:24 3962
                default:
69d650b4 sago007 2011-07-20 15:24 3963
                    StartSinglePlayerEndless();
69d650b4 sago007 2011-07-20 15:24 3964
                    break;
69d650b4 sago007 2011-07-20 15:24 3965
            };
69d650b4 sago007 2011-07-20 15:24 3966
            mustsetupgame = false;
69d650b4 sago007 2011-07-20 15:24 3967
        }
69d650b4 sago007 2011-07-20 15:24 3968
        
b7590374 sago007 2011-05-19 16:15 3969
        if (!(highPriority)) SDL_Delay(10);
b7590374 sago007 2011-05-19 16:15 3970
b7590374 sago007 2011-05-19 16:15 3971
        if ((standardBackground)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 3972
        {
b7590374 sago007 2011-05-19 16:15 3973
            MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 3974
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3975
        }
b7590374 sago007 2011-05-19 16:15 3976
b7590374 sago007 2011-05-19 16:15 3977
        if ((standardBackground)&&(editorMode))
b7590374 sago007 2011-05-19 16:15 3978
        {
b7590374 sago007 2011-05-19 16:15 3979
            DrawIMG(backgroundImage, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3980
            MakeBackground(xsize,ysize,&theGame);
b7590374 sago007 2011-05-19 16:15 3981
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3982
        }
b7590374 sago007 2011-05-19 16:15 3983
b7590374 sago007 2011-05-19 16:15 3984
        //updates the balls and explosions:
b7590374 sago007 2011-05-19 16:15 3985
        theBallManeger.update();
b7590374 sago007 2011-05-19 16:15 3986
        theExplosionManeger.update();
b7590374 sago007 2011-05-19 16:15 3987
        theTextManeger.update();
b7590374 sago007 2011-05-19 16:15 3988
b7590374 sago007 2011-05-19 16:15 3989
#if NETWORK
b7590374 sago007 2011-05-19 16:15 3990
        if (nt.isConnected())
b7590374 sago007 2011-05-19 16:15 3991
        {
b7590374 sago007 2011-05-19 16:15 3992
            nt.updateNetwork();
b7590374 sago007 2011-05-19 16:15 3993
            networkActive = true;
b7590374 sago007 2011-05-19 16:15 3994
            if (!nt.isConnectedToPeer())
b7590374 sago007 2011-05-19 16:15 3995
                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3996
        }
b7590374 sago007 2011-05-19 16:15 3997
        else
b7590374 sago007 2011-05-19 16:15 3998
            networkActive = false;
b7590374 sago007 2011-05-19 16:15 3999
        if (nt.isConnectedToPeer())
b7590374 sago007 2011-05-19 16:15 4000
        {
b7590374 sago007 2011-05-19 16:15 4001
            networkPlay=true;
b7590374 sago007 2011-05-19 16:15 4002
            if (!weWhereConnected) //We have just connected
b7590374 sago007 2011-05-19 16:15 4003
            {
b7590374 sago007 2011-05-19 16:15 4004
                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4005
                theGame.putStartBlocks(nt.theSeed);
b7590374 sago007 2011-05-19 16:15 4006
                theGame2.playNetwork(xsize-500,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4007
                nt.theGameHasStarted();
b7590374 sago007 2011-05-19 16:15 4008
                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 4009
            }
b7590374 sago007 2011-05-19 16:15 4010
            weWhereConnected = true;
b7590374 sago007 2011-05-19 16:15 4011
        }
b7590374 sago007 2011-05-19 16:15 4012
        else
b7590374 sago007 2011-05-19 16:15 4013
        {
b7590374 sago007 2011-05-19 16:15 4014
            networkPlay=false;
b7590374 sago007 2011-05-19 16:15 4015
            weWhereConnected = false;
b7590374 sago007 2011-05-19 16:15 4016
        }
b7590374 sago007 2011-05-19 16:15 4017
#endif
b7590374 sago007 2011-05-19 16:15 4018
b7590374 sago007 2011-05-19 16:15 4019
        if (!bScreenLocked)
b7590374 sago007 2011-05-19 16:15 4020
        {
b7590374 sago007 2011-05-19 16:15 4021
            SDL_Event event;
b7590374 sago007 2011-05-19 16:15 4022
b7590374 sago007 2011-05-19 16:15 4023
            while ( SDL_PollEvent(&event) )
b7590374 sago007 2011-05-19 16:15 4024
            {
b7590374 sago007 2011-05-19 16:15 4025
                if ( event.type == SDL_QUIT )  {
cc3ef158 sago007 2011-07-03 16:13 4026
                Config::getInstance()->setShuttingDown(5);
b7590374 sago007 2011-05-19 16:15 4027
                    done = 1;
b7590374 sago007 2011-05-19 16:15 4028
                }
b7590374 sago007 2011-05-19 16:15 4029
b7590374 sago007 2011-05-19 16:15 4030
                if ( event.type == SDL_KEYDOWN )
b7590374 sago007 2011-05-19 16:15 4031
                {
ac4a9268 sago007 2012-04-14 21:29 4032
                    if ( event.key.keysym.sym == SDLK_ESCAPE || ( event.key.keysym.sym == SDLK_RETURN && theGame.isGameOver() ) )
b7590374 sago007 2011-05-19 16:15 4033
                    {
b7590374 sago007 2011-05-19 16:15 4034
                            if (showOptions)
b7590374 sago007 2011-05-19 16:15 4035
                            {
b7590374 sago007 2011-05-19 16:15 4036
                                showOptions = false;
b7590374 sago007 2011-05-19 16:15 4037
                            }
b7590374 sago007 2011-05-19 16:15 4038
                            else
b7590374 sago007 2011-05-19 16:15 4039
                                done=1;
b7590374 sago007 2011-05-19 16:15 4040
                        DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 4041
b7590374 sago007 2011-05-19 16:15 4042
                    }
b7590374 sago007 2011-05-19 16:15 4043
                    if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled()))
b7590374 sago007 2011-05-19 16:15 4044
                    {
b7590374 sago007 2011-05-19 16:15 4045
                        //player1:
b7590374 sago007 2011-05-19 16:15 4046
                        if ( event.key.keysym.sym == keySettings[player1keys].up ) {
b7590374 sago007 2011-05-19 16:15 4047
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4048
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 4049
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4050
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 4051
                        }
b7590374 sago007 2011-05-19 16:15 4052
                        if ( event.key.keysym.sym == keySettings[player1keys].down ) {
b7590374 sago007 2011-05-19 16:15 4053
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4054
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 4055
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4056
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 4057
                        }
b7590374 sago007 2011-05-19 16:15 4058
                        if ( (event.key.keysym.sym == keySettings[player1keys].left) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 4059
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4060
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 4061
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4062
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 4063
                        }
b7590374 sago007 2011-05-19 16:15 4064
                        if ( (event.key.keysym.sym == keySettings[player1keys].right) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 4065
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4066
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 4067
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4068
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 4069
                        }
b7590374 sago007 2011-05-19 16:15 4070
                        if ( event.key.keysym.sym == keySettings[player1keys].push ) {
b7590374 sago007 2011-05-19 16:15 4071
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 4072
                        }
b7590374 sago007 2011-05-19 16:15 4073
                        if ( event.key.keysym.sym == keySettings[player1keys].change ) {
b7590374 sago007 2011-05-19 16:15 4074
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4075
                        }
b7590374 sago007 2011-05-19 16:15 4076
                    }
b7590374 sago007 2011-05-19 16:15 4077
                    if (!editorMode && !theGame2.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 4078
                    {
b7590374 sago007 2011-05-19 16:15 4079
                        //player2:
b7590374 sago007 2011-05-19 16:15 4080
                        if ( event.key.keysym.sym == keySettings[player2keys].up ) {
b7590374 sago007 2011-05-19 16:15 4081
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4082
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 4083
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4084
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 4085
                        }
b7590374 sago007 2011-05-19 16:15 4086
                        if ( event.key.keysym.sym == keySettings[player2keys].down ) {
b7590374 sago007 2011-05-19 16:15 4087
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4088
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 4089
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4090
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 4091
                        }
b7590374 sago007 2011-05-19 16:15 4092
                        if ( (event.key.keysym.sym == keySettings[player2keys].left) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 4093
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4094
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 4095
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4096
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 4097
                        }
b7590374 sago007 2011-05-19 16:15 4098
                        if ( (event.key.keysym.sym == keySettings[player2keys].right) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 4099
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4100
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 4101
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4102
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 4103
                        }
b7590374 sago007 2011-05-19 16:15 4104
                        if ( event.key.keysym.sym == keySettings[player2keys].push ) {
b7590374 sago007 2011-05-19 16:15 4105
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 4106
                        }
b7590374 sago007 2011-05-19 16:15 4107
                        if ( event.key.keysym.sym == keySettings[player2keys].change ) {
b7590374 sago007 2011-05-19 16:15 4108
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4109
                        }
b7590374 sago007 2011-05-19 16:15 4110
                    }
b7590374 sago007 2011-05-19 16:15 4111
                    //common:
b7590374 sago007 2011-05-19 16:15 4112
                    if ((!singlePuzzle)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 4113
                    {
b7590374 sago007 2011-05-19 16:15 4114
                        if ( event.key.keysym.sym == SDLK_F2 ) {
69d650b4 sago007 2011-07-20 15:24 4115
                            /*#if NETWORK
b7590374 sago007 2011-05-19 16:15 4116
                            if ((!showOptions)&&(!networkActive)){
b7590374 sago007 2011-05-19 16:15 4117
                            #else
b7590374 sago007 2011-05-19 16:15 4118
                            if ((!showOptions)){
b7590374 sago007 2011-05-19 16:15 4119
                            #endif
b7590374 sago007 2011-05-19 16:15 4120
                                StartSinglePlayerEndless();
69d650b4 sago007 2011-07-20 15:24 4121
                            }
69d650b4 sago007 2011-07-20 15:24 4122
                             */
69d650b4 sago007 2011-07-20 15:24 4123
                            mustsetupgame = true;
69d650b4 sago007 2011-07-20 15:24 4124
                        }
b7590374 sago007 2011-05-19 16:15 4125
                        if ( event.key.keysym.sym == SDLK_F3 ) {
b7590374 sago007 2011-05-19 16:15 4126
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 4127
                            if ((!showOptions)&&(!networkActive)){
b7590374 sago007 2011-05-19 16:15 4128
                            #else
b7590374 sago007 2011-05-19 16:15 4129
                            if ((!showOptions)){
b7590374 sago007 2011-05-19 16:15 4130
                            #endif
b7590374 sago007 2011-05-19 16:15 4131
                                StartSinglePlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 4132
                            }}
b7590374 sago007 2011-05-19 16:15 4133
                        if ( event.key.keysym.sym == SDLK_F5 )
b7590374 sago007 2011-05-19 16:15 4134
                        {
b7590374 sago007 2011-05-19 16:15 4135
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 4136
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 4137
                            #else
b7590374 sago007 2011-05-19 16:15 4138
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 4139
                            #endif
b7590374 sago007 2011-05-19 16:15 4140
                            {
b7590374 sago007 2011-05-19 16:15 4141
                                int myLevel = StageLevelSelect();
b7590374 sago007 2011-05-19 16:15 4142
                                theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4143
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 4144
                                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 4145
                                closeAllMenus();
b7590374 sago007 2011-05-19 16:15 4146
                                twoPlayers =false;
b7590374 sago007 2011-05-19 16:15 4147
                                theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 4148
                                showGame = true;
b7590374 sago007 2011-05-19 16:15 4149
                                vsMode = false;
b7590374 sago007 2011-05-19 16:15 4150
                                strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 4151
                                strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 4152
                            }
b7590374 sago007 2011-05-19 16:15 4153
                        }
b7590374 sago007 2011-05-19 16:15 4154
                        if ( event.key.keysym.sym == SDLK_F6 )
b7590374 sago007 2011-05-19 16:15 4155
                        {
b7590374 sago007 2011-05-19 16:15 4156
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 4157
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 4158
                            #else
b7590374 sago007 2011-05-19 16:15 4159
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 4160
                            #endif
b7590374 sago007 2011-05-19 16:15 4161
                            {
b7590374 sago007 2011-05-19 16:15 4162
                                StartTwoPlayerVs();
b7590374 sago007 2011-05-19 16:15 4163
                            }
b7590374 sago007 2011-05-19 16:15 4164
                        }
b7590374 sago007 2011-05-19 16:15 4165
                        if ( event.key.keysym.sym == SDLK_F4 )
b7590374 sago007 2011-05-19 16:15 4166
                        {
b7590374 sago007 2011-05-19 16:15 4167
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 4168
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 4169
                            #else
b7590374 sago007 2011-05-19 16:15 4170
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 4171
                            #endif
b7590374 sago007 2011-05-19 16:15 4172
                            {
b7590374 sago007 2011-05-19 16:15 4173
                                StarTwoPlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 4174
                            }
b7590374 sago007 2011-05-19 16:15 4175
                        }
b7590374 sago007 2011-05-19 16:15 4176
                        if ( event.key.keysym.sym == SDLK_F7 )
b7590374 sago007 2011-05-19 16:15 4177
                        {
b7590374 sago007 2011-05-19 16:15 4178
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 4179
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 4180
                            #else
b7590374 sago007 2011-05-19 16:15 4181
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 4182
                            #endif
b7590374 sago007 2011-05-19 16:15 4183
                            {
b7590374 sago007 2011-05-19 16:15 4184
                                int myLevel = PuzzleLevelSelect();
b7590374 sago007 2011-05-19 16:15 4185
                                theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4186
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 4187
                                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 4188
                                closeAllMenus();
b7590374 sago007 2011-05-19 16:15 4189
                                twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 4190
                                theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 4191
                                showGame = true;
b7590374 sago007 2011-05-19 16:15 4192
                                vsMode = true;
b7590374 sago007 2011-05-19 16:15 4193
                                strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 4194
                                strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 4195
                            }
b7590374 sago007 2011-05-19 16:15 4196
                        }
b7590374 sago007 2011-05-19 16:15 4197
                        if ( event.key.keysym.sym == SDLK_F8 )
b7590374 sago007 2011-05-19 16:15 4198
                        {
b7590374 sago007 2011-05-19 16:15 4199
                        }
b7590374 sago007 2011-05-19 16:15 4200
                        if ( event.key.keysym.sym == SDLK_F9 ) {
b7590374 sago007 2011-05-19 16:15 4201
                            writeScreenShot();
b7590374 sago007 2011-05-19 16:15 4202
                        }
b7590374 sago007 2011-05-19 16:15 4203
                        if ( event.key.keysym.sym == SDLK_F11 ) {
b7590374 sago007 2011-05-19 16:15 4204
                            /*This is the test place, place function to test here*/
b7590374 sago007 2011-05-19 16:15 4205
b7590374 sago007 2011-05-19 16:15 4206
                            //theGame.CreateGreyGarbage();
b7590374 sago007 2011-05-19 16:15 4207
                            //char mitNavn[30];
b7590374 sago007 2011-05-19 16:15 4208
                            //SelectThemeDialogbox(300,400,mitNavn);
b7590374 sago007 2011-05-19 16:15 4209
                           MainMenu();
b7590374 sago007 2011-05-19 16:15 4210
                            //OpenScoresDisplay();
b7590374 sago007 2011-05-19 16:15 4211
                        } //F11
b7590374 sago007 2011-05-19 16:15 4212
                    }
b7590374 sago007 2011-05-19 16:15 4213
                    if ( event.key.keysym.sym == SDLK_F12 ) {
b7590374 sago007 2011-05-19 16:15 4214
                        done=1;
b7590374 sago007 2011-05-19 16:15 4215
                    }
b7590374 sago007 2011-05-19 16:15 4216
                }
b7590374 sago007 2011-05-19 16:15 4217
            } //while event PollEvent - read keys
b7590374 sago007 2011-05-19 16:15 4218
b7590374 sago007 2011-05-19 16:15 4219
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 4220
            **************************** Repeating start **************************
b7590374 sago007 2011-05-19 16:15 4221
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 4222
b7590374 sago007 2011-05-19 16:15 4223
            keys = SDL_GetKeyState(NULL);
b7590374 sago007 2011-05-19 16:15 4224
//Also the joysticks:
b7590374 sago007 2011-05-19 16:15 4225
//Repeating not implemented
b7590374 sago007 2011-05-19 16:15 4226
b7590374 sago007 2011-05-19 16:15 4227
//Player 1 start
b7590374 sago007 2011-05-19 16:15 4228
            if (!(keys[keySettings[player1keys].up]))
b7590374 sago007 2011-05-19 16:15 4229
                repeatingN[0]=false;
b7590374 sago007 2011-05-19 16:15 4230
            while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4231
            {
b7590374 sago007 2011-05-19 16:15 4232
                theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4233
                timesRepeatedP1N++;
b7590374 sago007 2011-05-19 16:15 4234
            }
b7590374 sago007 2011-05-19 16:15 4235
b7590374 sago007 2011-05-19 16:15 4236
            if (!(keys[keySettings[player1keys].down]))
b7590374 sago007 2011-05-19 16:15 4237
                repeatingS[0]=false;
b7590374 sago007 2011-05-19 16:15 4238
            while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4239
            {
b7590374 sago007 2011-05-19 16:15 4240
                theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4241
                timesRepeatedP1S++;
b7590374 sago007 2011-05-19 16:15 4242
            }
b7590374 sago007 2011-05-19 16:15 4243
b7590374 sago007 2011-05-19 16:15 4244
            if (!(keys[keySettings[player1keys].left]))
b7590374 sago007 2011-05-19 16:15 4245
                repeatingW[0]=false;
b7590374 sago007 2011-05-19 16:15 4246
            while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4247
            {
b7590374 sago007 2011-05-19 16:15 4248
                timesRepeatedP1W++;
b7590374 sago007 2011-05-19 16:15 4249
                theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4250
            }
b7590374 sago007 2011-05-19 16:15 4251
b7590374 sago007 2011-05-19 16:15 4252
            if (!(keys[keySettings[player1keys].right]))
b7590374 sago007 2011-05-19 16:15 4253
                repeatingE[0]=false;
b7590374 sago007 2011-05-19 16:15 4254
            while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4255
            {
b7590374 sago007 2011-05-19 16:15 4256
                timesRepeatedP1E++;
b7590374 sago007 2011-05-19 16:15 4257
                theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4258
            }
b7590374 sago007 2011-05-19 16:15 4259
b7590374 sago007 2011-05-19 16:15 4260
//Player 1 end
b7590374 sago007 2011-05-19 16:15 4261
b7590374 sago007 2011-05-19 16:15 4262
//Player 2 start
b7590374 sago007 2011-05-19 16:15 4263
            if (!(keys[keySettings[player2keys].up]))
b7590374 sago007 2011-05-19 16:15 4264
                repeatingN[1]=false;
b7590374 sago007 2011-05-19 16:15 4265
            while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4266
            {
b7590374 sago007 2011-05-19 16:15 4267
                theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4268
                timesRepeatedP2N++;
b7590374 sago007 2011-05-19 16:15 4269
            }
b7590374 sago007 2011-05-19 16:15 4270
b7590374 sago007 2011-05-19 16:15 4271
            if (!(keys[keySettings[player2keys].down]))
b7590374 sago007 2011-05-19 16:15 4272
                repeatingS[1]=false;
b7590374 sago007 2011-05-19 16:15 4273
            while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4274
            {
b7590374 sago007 2011-05-19 16:15 4275
                theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4276
                timesRepeatedP2S++;
b7590374 sago007 2011-05-19 16:15 4277
            }
b7590374 sago007 2011-05-19 16:15 4278
b7590374 sago007 2011-05-19 16:15 4279
            if (!(keys[keySettings[player2keys].left]))
b7590374 sago007 2011-05-19 16:15 4280
                repeatingW[1]=false;
b7590374 sago007 2011-05-19 16:15 4281
            while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4282
            {
b7590374 sago007 2011-05-19 16:15 4283
                theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4284
                timesRepeatedP2W++;
b7590374 sago007 2011-05-19 16:15 4285
            }
b7590374 sago007 2011-05-19 16:15 4286
b7590374 sago007 2011-05-19 16:15 4287
            if (!(keys[keySettings[player2keys].right]))
b7590374 sago007 2011-05-19 16:15 4288
                repeatingE[1]=false;
b7590374 sago007 2011-05-19 16:15 4289
            while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 4290
            {
b7590374 sago007 2011-05-19 16:15 4291
                theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4292
                timesRepeatedP2E++;
b7590374 sago007 2011-05-19 16:15 4293
            }
b7590374 sago007 2011-05-19 16:15 4294
b7590374 sago007 2011-05-19 16:15 4295
//Player 2 end
b7590374 sago007 2011-05-19 16:15 4296
b7590374 sago007 2011-05-19 16:15 4297
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 4298
            **************************** Repeating end ****************************
b7590374 sago007 2011-05-19 16:15 4299
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 4300
b7590374 sago007 2011-05-19 16:15 4301
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 4302
            ***************************** Joypad start ****************************
b7590374 sago007 2011-05-19 16:15 4303
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 4304
b7590374 sago007 2011-05-19 16:15 4305
            //Gameplay
b7590374 sago007 2011-05-19 16:15 4306
            if (joyplay1||joyplay2)
b7590374 sago007 2011-05-19 16:15 4307
            {
b7590374 sago007 2011-05-19 16:15 4308
                if (joypad1.working && !theGame.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 4309
                    if (joyplay1)
b7590374 sago007 2011-05-19 16:15 4310
                    {
b7590374 sago007 2011-05-19 16:15 4311
                        joypad1.update();
b7590374 sago007 2011-05-19 16:15 4312
                        if (joypad1.up)
b7590374 sago007 2011-05-19 16:15 4313
                        {
b7590374 sago007 2011-05-19 16:15 4314
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4315
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 4316
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4317
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 4318
                        }
b7590374 sago007 2011-05-19 16:15 4319
                        if (joypad1.down)
b7590374 sago007 2011-05-19 16:15 4320
                        {
b7590374 sago007 2011-05-19 16:15 4321
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4322
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 4323
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4324
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 4325
                        }
b7590374 sago007 2011-05-19 16:15 4326
                        if (joypad1.left)
b7590374 sago007 2011-05-19 16:15 4327
                        {
b7590374 sago007 2011-05-19 16:15 4328
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4329
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 4330
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4331
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 4332
                        }
b7590374 sago007 2011-05-19 16:15 4333
                        if (joypad1.right)
b7590374 sago007 2011-05-19 16:15 4334
                        {
b7590374 sago007 2011-05-19 16:15 4335
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4336
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 4337
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4338
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 4339
                        }
b7590374 sago007 2011-05-19 16:15 4340
                        if (joypad1.but1)
b7590374 sago007 2011-05-19 16:15 4341
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4342
                        if (joypad1.but2)
b7590374 sago007 2011-05-19 16:15 4343
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 4344
                    }
b7590374 sago007 2011-05-19 16:15 4345
                    else
b7590374 sago007 2011-05-19 16:15 4346
                    {
b7590374 sago007 2011-05-19 16:15 4347
                        joypad1.update();
b7590374 sago007 2011-05-19 16:15 4348
                        if (joypad1.up)
b7590374 sago007 2011-05-19 16:15 4349
                        {
b7590374 sago007 2011-05-19 16:15 4350
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4351
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 4352
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4353
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 4354
                        }
b7590374 sago007 2011-05-19 16:15 4355
                        if (joypad1.down)
b7590374 sago007 2011-05-19 16:15 4356
                        {
b7590374 sago007 2011-05-19 16:15 4357
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4358
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 4359
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4360
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 4361
                        }
b7590374 sago007 2011-05-19 16:15 4362
                        if (joypad1.left)
b7590374 sago007 2011-05-19 16:15 4363
                        {
b7590374 sago007 2011-05-19 16:15 4364
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4365
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 4366
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4367
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 4368
                        }
b7590374 sago007 2011-05-19 16:15 4369
                        if (joypad1.right)
b7590374 sago007 2011-05-19 16:15 4370
                        {
b7590374 sago007 2011-05-19 16:15 4371
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4372
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 4373
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4374
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 4375
                        }
b7590374 sago007 2011-05-19 16:15 4376
                        if (joypad1.but1)
b7590374 sago007 2011-05-19 16:15 4377
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4378
                        if (joypad1.but2)
b7590374 sago007 2011-05-19 16:15 4379
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 4380
                    }
b7590374 sago007 2011-05-19 16:15 4381
                if (joypad2.working && !theGame2.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 4382
                    if (!joyplay2)
b7590374 sago007 2011-05-19 16:15 4383
                    {
b7590374 sago007 2011-05-19 16:15 4384
                        joypad2.update();
b7590374 sago007 2011-05-19 16:15 4385
                        if (joypad2.up)
b7590374 sago007 2011-05-19 16:15 4386
                        {
b7590374 sago007 2011-05-19 16:15 4387
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4388
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 4389
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4390
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 4391
                        }
b7590374 sago007 2011-05-19 16:15 4392
                        if (joypad2.down)
b7590374 sago007 2011-05-19 16:15 4393
                        {
b7590374 sago007 2011-05-19 16:15 4394
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4395
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 4396
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4397
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 4398
                        }
b7590374 sago007 2011-05-19 16:15 4399
                        if (joypad2.left)
b7590374 sago007 2011-05-19 16:15 4400
                        {
b7590374 sago007 2011-05-19 16:15 4401
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4402
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 4403
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4404
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 4405
                        }
b7590374 sago007 2011-05-19 16:15 4406
                        if (joypad2.right)
b7590374 sago007 2011-05-19 16:15 4407
                        {
b7590374 sago007 2011-05-19 16:15 4408
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4409
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 4410
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4411
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 4412
                        }
b7590374 sago007 2011-05-19 16:15 4413
                        if (joypad2.but1)
b7590374 sago007 2011-05-19 16:15 4414
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4415
                        if (joypad2.but2)
b7590374 sago007 2011-05-19 16:15 4416
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 4417
                    }
b7590374 sago007 2011-05-19 16:15 4418
                    else
b7590374 sago007 2011-05-19 16:15 4419
                    {
b7590374 sago007 2011-05-19 16:15 4420
                        joypad2.update();
b7590374 sago007 2011-05-19 16:15 4421
                        if (joypad2.up)
b7590374 sago007 2011-05-19 16:15 4422
                        {
b7590374 sago007 2011-05-19 16:15 4423
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 4424
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 4425
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4426
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 4427
                        }
b7590374 sago007 2011-05-19 16:15 4428
                        if (joypad2.down)
b7590374 sago007 2011-05-19 16:15 4429
                        {
b7590374 sago007 2011-05-19 16:15 4430
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 4431
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 4432
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4433
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 4434
                        }
b7590374 sago007 2011-05-19 16:15 4435
                        if (joypad2.left)
b7590374 sago007 2011-05-19 16:15 4436
                        {
b7590374 sago007 2011-05-19 16:15 4437
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 4438
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 4439
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4440
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 4441
                        }
b7590374 sago007 2011-05-19 16:15 4442
                        if (joypad2.right)
b7590374 sago007 2011-05-19 16:15 4443
                        {
b7590374 sago007 2011-05-19 16:15 4444
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 4445
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 4446
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 4447
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 4448
                        }
b7590374 sago007 2011-05-19 16:15 4449
                        if (joypad2.but1)
b7590374 sago007 2011-05-19 16:15 4450
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4451
                        if (joypad2.but2)
b7590374 sago007 2011-05-19 16:15 4452
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 4453
                    }
b7590374 sago007 2011-05-19 16:15 4454
            }
b7590374 sago007 2011-05-19 16:15 4455
b7590374 sago007 2011-05-19 16:15 4456
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 4457
            ***************************** Joypad end ******************************
b7590374 sago007 2011-05-19 16:15 4458
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 4459
b7590374 sago007 2011-05-19 16:15 4460
b7590374 sago007 2011-05-19 16:15 4461
            keys = SDL_GetKeyState(NULL);
b7590374 sago007 2011-05-19 16:15 4462
b7590374 sago007 2011-05-19 16:15 4463
            SDL_GetMouseState(&mousex,&mousey);
b7590374 sago007 2011-05-19 16:15 4464
b7590374 sago007 2011-05-19 16:15 4465
            /********************************************************************
b7590374 sago007 2011-05-19 16:15 4466
            **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 4467
            ********************************************************************/
b7590374 sago007 2011-05-19 16:15 4468
b7590374 sago007 2011-05-19 16:15 4469
            if ((mouseplay1)&&((!editorMode)&&(!theGame.GetAIenabled())||(editorModeTest))) //player 1
b7590374 sago007 2011-05-19 16:15 4470
                if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 4471
                {
b7590374 sago007 2011-05-19 16:15 4472
                    int yLine, xLine;
b7590374 sago007 2011-05-19 16:15 4473
                    yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50;
b7590374 sago007 2011-05-19 16:15 4474
                    xLine = (mousex-50+25)/50;
b7590374 sago007 2011-05-19 16:15 4475
                    yLine-=2;
b7590374 sago007 2011-05-19 16:15 4476
                    xLine-=1;
b7590374 sago007 2011-05-19 16:15 4477
                    if ((yLine>10)&&(theGame.GetTowerHeight()<12))
b7590374 sago007 2011-05-19 16:15 4478
                        yLine=10;
b7590374 sago007 2011-05-19 16:15 4479
                    if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11))
b7590374 sago007 2011-05-19 16:15 4480
                        yLine=11;
b7590374 sago007 2011-05-19 16:15 4481
                    if (yLine<0)
b7590374 sago007 2011-05-19 16:15 4482
                        yLine=0;
b7590374 sago007 2011-05-19 16:15 4483
                    if (xLine<0)
b7590374 sago007 2011-05-19 16:15 4484
                        xLine=0;
b7590374 sago007 2011-05-19 16:15 4485
                    if (xLine>4)
b7590374 sago007 2011-05-19 16:15 4486
                        xLine=4;
b7590374 sago007 2011-05-19 16:15 4487
                    theGame.MoveCursorTo(xLine,yLine);
b7590374 sago007 2011-05-19 16:15 4488
                }
b7590374 sago007 2011-05-19 16:15 4489
b7590374 sago007 2011-05-19 16:15 4490
            if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2
b7590374 sago007 2011-05-19 16:15 4491
                if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 4492
                {
b7590374 sago007 2011-05-19 16:15 4493
                    int yLine, xLine;
b7590374 sago007 2011-05-19 16:15 4494
                    yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50;
b7590374 sago007 2011-05-19 16:15 4495
                    xLine = (mousex-(xsize-500)+25)/50;
b7590374 sago007 2011-05-19 16:15 4496
                    yLine-=2;
b7590374 sago007 2011-05-19 16:15 4497
                    xLine-=1;
b7590374 sago007 2011-05-19 16:15 4498
                    if ((yLine>10)&&(theGame2.GetTowerHeight()<12))
b7590374 sago007 2011-05-19 16:15 4499
                        yLine=10;
b7590374 sago007 2011-05-19 16:15 4500
                    if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11))
b7590374 sago007 2011-05-19 16:15 4501
                        yLine=11;
b7590374 sago007 2011-05-19 16:15 4502
                    if (yLine<0)
b7590374 sago007 2011-05-19 16:15 4503
                        yLine=0;
b7590374 sago007 2011-05-19 16:15 4504
                    if (xLine<0)
b7590374 sago007 2011-05-19 16:15 4505
                        xLine=0;
b7590374 sago007 2011-05-19 16:15 4506
                    if (xLine>4)
b7590374 sago007 2011-05-19 16:15 4507
                        xLine=4;
b7590374 sago007 2011-05-19 16:15 4508
                    theGame2.MoveCursorTo(xLine,yLine);
b7590374 sago007 2011-05-19 16:15 4509
                }
b7590374 sago007 2011-05-19 16:15 4510
b7590374 sago007 2011-05-19 16:15 4511
            /********************************************************************
b7590374 sago007 2011-05-19 16:15 4512
            **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 4513
            ********************************************************************/
b7590374 sago007 2011-05-19 16:15 4514
b7590374 sago007 2011-05-19 16:15 4515
            // If the mouse button is released, make bMouseUp equal true
b7590374 sago007 2011-05-19 16:15 4516
            if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
b7590374 sago007 2011-05-19 16:15 4517
            {
b7590374 sago007 2011-05-19 16:15 4518
                bMouseUp=true;
b7590374 sago007 2011-05-19 16:15 4519
            }
b7590374 sago007 2011-05-19 16:15 4520
b7590374 sago007 2011-05-19 16:15 4521
            // If the mouse button 2 is released, make bMouseUp2 equal true
b7590374 sago007 2011-05-19 16:15 4522
            if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3))
b7590374 sago007 2011-05-19 16:15 4523
            {
b7590374 sago007 2011-05-19 16:15 4524
                bMouseUp2=true;
b7590374 sago007 2011-05-19 16:15 4525
            }
b7590374 sago007 2011-05-19 16:15 4526
b7590374 sago007 2011-05-19 16:15 4527
            if ((!singlePuzzle)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 4528
            {
b7590374 sago007 2011-05-19 16:15 4529
                //read mouse events
b7590374 sago007 2011-05-19 16:15 4530
                if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
b7590374 sago007 2011-05-19 16:15 4531
                {
b7590374 sago007 2011-05-19 16:15 4532
                    bMouseUp = false;
b7590374 sago007 2011-05-19 16:15 4533
                    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 4534
                    
b7590374 sago007 2011-05-19 16:15 4535
b7590374 sago007 2011-05-19 16:15 4536
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 4537
                    **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 4538
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 4539
                    if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 4540
                    {
b7590374 sago007 2011-05-19 16:15 4541
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
b7590374 sago007 2011-05-19 16:15 4542
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 4543
                            {
b7590374 sago007 2011-05-19 16:15 4544
                                theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4545
                            }
b7590374 sago007 2011-05-19 16:15 4546
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
b7590374 sago007 2011-05-19 16:15 4547
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 4548
                            {
b7590374 sago007 2011-05-19 16:15 4549
                                theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 4550
                            }
b7590374 sago007 2011-05-19 16:15 4551
                    }
b7590374 sago007 2011-05-19 16:15 4552
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 4553
                    **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 4554
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 4555
b7590374 sago007 2011-05-19 16:15 4556
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
b7590374 sago007 2011-05-19 16:15 4557
                            &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
b7590374 sago007 2011-05-19 16:15 4558
                            &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize))
b7590374 sago007 2011-05-19 16:15 4559
                    {
b7590374 sago007 2011-05-19 16:15 4560
                        //Clicked the next button after a stage clear or puzzle
b7590374 sago007 2011-05-19 16:15 4561
                        theGame.nextLevel(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4562
                    }
b7590374 sago007 2011-05-19 16:15 4563
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
b7590374 sago007 2011-05-19 16:15 4564
                            &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
b7590374 sago007 2011-05-19 16:15 4565
                            &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize))
b7590374 sago007 2011-05-19 16:15 4566
                    {
b7590374 sago007 2011-05-19 16:15 4567
                        //Clicked the retry button
b7590374 sago007 2011-05-19 16:15 4568
                        theGame.retryLevel(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4569
                    }
b7590374 sago007 2011-05-19 16:15 4570
b7590374 sago007 2011-05-19 16:15 4571
b7590374 sago007 2011-05-19 16:15 4572
                    //cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
b7590374 sago007 2011-05-19 16:15 4573
                }
b7590374 sago007 2011-05-19 16:15 4574
b7590374 sago007 2011-05-19 16:15 4575
                //Mouse button 2:
b7590374 sago007 2011-05-19 16:15 4576
                if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2)
b7590374 sago007 2011-05-19 16:15 4577
                {
b7590374 sago007 2011-05-19 16:15 4578
                    bMouseUp2=false; //The button is pressed
b7590374 sago007 2011-05-19 16:15 4579
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 4580
                    **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 4581
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 4582
                    if (!showOptions)
b7590374 sago007 2011-05-19 16:15 4583
                    {
b7590374 sago007 2011-05-19 16:15 4584
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
b7590374 sago007 2011-05-19 16:15 4585
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 4586
                            {
b7590374 sago007 2011-05-19 16:15 4587
                                theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 4588
                            }
b7590374 sago007 2011-05-19 16:15 4589
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
b7590374 sago007 2011-05-19 16:15 4590
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 4591
                            {
b7590374 sago007 2011-05-19 16:15 4592
                                theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 4593
                            }
b7590374 sago007 2011-05-19 16:15 4594
                    }
b7590374 sago007 2011-05-19 16:15 4595
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 4596
                    **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 4597
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 4598
                }
b7590374 sago007 2011-05-19 16:15 4599
            } //if !singlePuzzle
b7590374 sago007 2011-05-19 16:15 4600
            else
b7590374 sago007 2011-05-19 16:15 4601
            {
b7590374 sago007 2011-05-19 16:15 4602
b7590374 sago007 2011-05-19 16:15 4603
            }
b7590374 sago007 2011-05-19 16:15 4604
        } //if !bScreenBocked;
b7590374 sago007 2011-05-19 16:15 4605
b7590374 sago007 2011-05-19 16:15 4606
b7590374 sago007 2011-05-19 16:15 4607
        //Sees if music is stopped and if music is enabled
b7590374 sago007 2011-05-19 16:15 4608
        if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath))
b7590374 sago007 2011-05-19 16:15 4609
        {
b7590374 sago007 2011-05-19 16:15 4610
            // then starts playing it.
b7590374 sago007 2011-05-19 16:15 4611
            Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 4612
            Mix_PlayMusic(bgMusic, -1); //music loop
b7590374 sago007 2011-05-19 16:15 4613
        }
b7590374 sago007 2011-05-19 16:15 4614
b7590374 sago007 2011-05-19 16:15 4615
        if(bNearDeath!=bNearDeathPrev)
b7590374 sago007 2011-05-19 16:15 4616
        {
b7590374 sago007 2011-05-19 16:15 4617
            if(bNearDeath)
b7590374 sago007 2011-05-19 16:15 4618
            {
b7590374 sago007 2011-05-19 16:15 4619
                if(!NoSound &&(MusicEnabled)) {
b7590374 sago007 2011-05-19 16:15 4620
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 4621
                    Mix_PlayMusic(highbeatMusic, 1);
b7590374 sago007 2011-05-19 16:15 4622
                }
b7590374 sago007 2011-05-19 16:15 4623
            }
b7590374 sago007 2011-05-19 16:15 4624
            else
b7590374 sago007 2011-05-19 16:15 4625
            {
b7590374 sago007 2011-05-19 16:15 4626
                if(!NoSound &&(MusicEnabled)) {
b7590374 sago007 2011-05-19 16:15 4627
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 4628
                    Mix_PlayMusic(bgMusic, -1);
b7590374 sago007 2011-05-19 16:15 4629
                }
b7590374 sago007 2011-05-19 16:15 4630
            }
b7590374 sago007 2011-05-19 16:15 4631
        }
b7590374 sago007 2011-05-19 16:15 4632
b7590374 sago007 2011-05-19 16:15 4633
        bNearDeathPrev = bNearDeath;
b7590374 sago007 2011-05-19 16:15 4634
b7590374 sago007 2011-05-19 16:15 4635
b7590374 sago007 2011-05-19 16:15 4636
        //set bNearDeath to false theGame*.Update() will change to true as needed
b7590374 sago007 2011-05-19 16:15 4637
        bNearDeath = false;
b7590374 sago007 2011-05-19 16:15 4638
        //Updates the objects
b7590374 sago007 2011-05-19 16:15 4639
        theGame.Update(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4640
        theGame2.Update(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 4641
b7590374 sago007 2011-05-19 16:15 4642
//see if anyone has won (two players only)
b7590374 sago007 2011-05-19 16:15 4643
        #if NETWORK
b7590374 sago007 2011-05-19 16:15 4644
        if (!networkPlay)
b7590374 sago007 2011-05-19 16:15 4645
        #endif
b7590374 sago007 2011-05-19 16:15 4646
            if (twoPlayers)
b7590374 sago007 2011-05-19 16:15 4647
            {
b7590374 sago007 2011-05-19 16:15 4648
                lastNrOfPlayers = 2;
b7590374 sago007 2011-05-19 16:15 4649
                if ((theGame.isGameOver()) && (theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 4650
                {
b7590374 sago007 2011-05-19 16:15 4651
                    if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap())
b7590374 sago007 2011-05-19 16:15 4652
                        theGame.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 4653
                    else
b7590374 sago007 2011-05-19 16:15 4654
                        if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap())
b7590374 sago007 2011-05-19 16:15 4655
                            theGame2.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 4656
                        else {
b7590374 sago007 2011-05-19 16:15 4657
                            theGame.setDraw();
b7590374 sago007 2011-05-19 16:15 4658
                            theGame2.setDraw();
b7590374 sago007 2011-05-19 16:15 4659
                        }
b7590374 sago007 2011-05-19 16:15 4660
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 4661
                }
b7590374 sago007 2011-05-19 16:15 4662
                if ((theGame.isGameOver()) && (!theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 4663
                {
b7590374 sago007 2011-05-19 16:15 4664
                    theGame2.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 4665
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 4666
                }
b7590374 sago007 2011-05-19 16:15 4667
                if ((!theGame.isGameOver()) && (theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 4668
                {
b7590374 sago007 2011-05-19 16:15 4669
                    theGame.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 4670
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 4671
                }
b7590374 sago007 2011-05-19 16:15 4672
            }
b7590374 sago007 2011-05-19 16:15 4673
b7590374 sago007 2011-05-19 16:15 4674
        //Once evrything has been checked, update graphics
b7590374 sago007 2011-05-19 16:15 4675
        DrawEverything(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 4676
        SDL_GetMouseState(&mousex,&mousey);
b7590374 sago007 2011-05-19 16:15 4677
        //Remember mouse placement
b7590374 sago007 2011-05-19 16:15 4678
        oldMousex = mousex;
b7590374 sago007 2011-05-19 16:15 4679
        oldMousey = mousey;
b7590374 sago007 2011-05-19 16:15 4680
        //Draw the mouse:
b7590374 sago007 2011-05-19 16:15 4681
        //DrawIMG(mouse,screen,mousex,mousey);
b7590374 sago007 2011-05-19 16:15 4682
        mouse.PaintTo(screen,mousex,mousey);
b7590374 sago007 2011-05-19 16:15 4683
        SDL_Flip(screen);
b7590374 sago007 2011-05-19 16:15 4684
    } //game loop
605138b3 sago007 2012-04-14 15:12 4685
}
1970-01-01 00:00 4686