git repos / blockattack-game

blame: source/code/main.cpp

normal view · raw

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