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"
b7590374 sago007 2011-05-19 16:15 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"))
89c4a3a6 sago007 2008-08-29 14:32 467
            && (optionsBack = IMG_Load2((char*)"gfx/options.png"))
89c4a3a6 sago007 2008-08-29 14:32 468
            && (bOn = IMG_Load2((char*)"gfx/bOn.png"))
89c4a3a6 sago007 2008-08-29 14:32 469
            && (bOff = IMG_Load2((char*)"gfx/bOff.png"))
89c4a3a6 sago007 2008-08-29 14:32 470
            && (bChange = IMG_Load2((char*)"gfx/bChange.png"))
89c4a3a6 sago007 2008-08-29 14:32 471
            && (b1024 = IMG_Load2((char*)"gfx/b1024.png"))
89c4a3a6 sago007 2008-08-29 14:32 472
            && (dialogBox = IMG_Load2((char*)"gfx/dialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 473
//	&& (fileDialogBox = IMG_Load2("gfx/fileDialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 474
            && (iLevelCheck = IMG_Load2((char*)"gfx/iLevelCheck.png"))
89c4a3a6 sago007 2008-08-29 14:32 475
            && (iLevelCheckBox = IMG_Load2((char*)"gfx/iLevelCheckBox.png"))
89c4a3a6 sago007 2008-08-29 14:32 476
            && (iCheckBoxArea = IMG_Load2((char*)"gfx/iCheckBoxArea.png"))
89c4a3a6 sago007 2008-08-29 14:32 477
            && (boardBackBack = IMG_Load2((char*)"gfx/boardBackBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 478
            && (changeButtonsBack = IMG_Load2((char*)"gfx/changeButtonsBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 479
            && (garbageTL = IMG_Load2((char*)"gfx/garbage/garbageTL.png"))
89c4a3a6 sago007 2008-08-29 14:32 480
            && (garbageT = IMG_Load2((char*)"gfx/garbage/garbageT.png"))
89c4a3a6 sago007 2008-08-29 14:32 481
            && (garbageTR = IMG_Load2((char*)"gfx/garbage/garbageTR.png"))
89c4a3a6 sago007 2008-08-29 14:32 482
            && (garbageR = IMG_Load2((char*)"gfx/garbage/garbageR.png"))
89c4a3a6 sago007 2008-08-29 14:32 483
            && (garbageBR = IMG_Load2((char*)"gfx/garbage/garbageBR.png"))
89c4a3a6 sago007 2008-08-29 14:32 484
            && (garbageB = IMG_Load2((char*)"gfx/garbage/garbageB.png"))
89c4a3a6 sago007 2008-08-29 14:32 485
            && (garbageBL = IMG_Load2((char*)"gfx/garbage/garbageBL.png"))
89c4a3a6 sago007 2008-08-29 14:32 486
            && (garbageL = IMG_Load2((char*)"gfx/garbage/garbageL.png"))
89c4a3a6 sago007 2008-08-29 14:32 487
            && (garbageFill = IMG_Load2((char*)"gfx/garbage/garbageFill.png"))
89c4a3a6 sago007 2008-08-29 14:32 488
            && (garbageML = IMG_Load2((char*)"gfx/garbage/garbageML.png"))
89c4a3a6 sago007 2008-08-29 14:32 489
            && (garbageM = IMG_Load2((char*)"gfx/garbage/garbageM.png"))
89c4a3a6 sago007 2008-08-29 14:32 490
            && (garbageMR = IMG_Load2((char*)"gfx/garbage/garbageMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 491
            && (garbageGM = IMG_Load2((char*)"gfx/garbage/garbageGM.png"))
89c4a3a6 sago007 2008-08-29 14:32 492
            && (garbageGML = IMG_Load2((char*)"gfx/garbage/garbageGML.png"))
89c4a3a6 sago007 2008-08-29 14:32 493
            && (garbageGMR = IMG_Load2((char*)"gfx/garbage/garbageGMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 494
            && (smiley[0] = IMG_Load2((char*)"gfx/smileys/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 495
            && (smiley[1] = IMG_Load2((char*)"gfx/smileys/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 496
            && (smiley[2] = IMG_Load2((char*)"gfx/smileys/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 497
            && (smiley[3] = IMG_Load2((char*)"gfx/smileys/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 498
            //new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 499
            && (transCover = IMG_Load2((char*)"gfx/transCover.png"))
1572de2b sago007 2008-09-11 18:15 500
            #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 501
            && (bCreateFile = IMG_Load2((char*)"gfx/editor/bCreateFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 502
            && (bDeletePuzzle = IMG_Load2((char*)"gfx/editor/bDeletePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 503
            && (bLoadFile = IMG_Load2((char*)"gfx/editor/bLoadFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 504
            && (bMoveBack = IMG_Load2((char*)"gfx/editor/bMoveBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 505
            && (bMoveDown = IMG_Load2((char*)"gfx/editor/bMoveDown.png"))
89c4a3a6 sago007 2008-08-29 14:32 506
            && (bMoveForward = IMG_Load2((char*)"gfx/editor/bMoveForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 507
            && (bMoveLeft = IMG_Load2((char*)"gfx/editor/bMoveLeft.png"))
89c4a3a6 sago007 2008-08-29 14:32 508
            && (bMoveRight = IMG_Load2((char*)"gfx/editor/bMoveRight.png"))
89c4a3a6 sago007 2008-08-29 14:32 509
            && (bMoveUp = IMG_Load2((char*)"gfx/editor/bMoveUp.png"))
89c4a3a6 sago007 2008-08-29 14:32 510
            && (bNewPuzzle = IMG_Load2((char*)"gfx/editor/bNewPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 511
            && (bSaveFileAs = IMG_Load2((char*)"gfx/editor/bSaveFileAs.png"))
89c4a3a6 sago007 2008-08-29 14:32 512
            && (bSavePuzzle = IMG_Load2((char*)"gfx/editor/bSavePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 513
            && (bSaveToFile = IMG_Load2((char*)"gfx/editor/bSaveToFile.png"))
1572de2b sago007 2008-09-11 18:15 514
            && (bTestPuzzle = IMG_Load2((char*)"gfx/editor/bTestPuzzle.png"))
1572de2b sago007 2008-09-11 18:15 515
            #endif
89c4a3a6 sago007 2008-08-29 14:32 516
            //end new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 517
            //new in 1.4.0
89c4a3a6 sago007 2008-08-29 14:32 518
            && (bTheme = IMG_Load2((char*)"gfx/bTheme.png"))
89c4a3a6 sago007 2008-08-29 14:32 519
            && (bSkip = IMG_Load2((char*)"gfx/bSkip.png"))
89c4a3a6 sago007 2008-08-29 14:32 520
            && (bNext = IMG_Load2((char*)"gfx/bNext.png"))
89c4a3a6 sago007 2008-08-29 14:32 521
            && (bRetry = IMG_Load2((char*)"gfx/bRetry.png"))
89c4a3a6 sago007 2008-08-29 14:32 522
         ))
89c4a3a6 sago007 2008-08-29 14:32 523
        //if there was a problem ie. "File not found"
89c4a3a6 sago007 2008-08-29 14:32 524
    {
89c4a3a6 sago007 2008-08-29 14:32 525
        cout << "Error loading image file: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 526
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 527
    }
8d488d32 sago007 2011-04-17 13:02 528
    try{
43611709 sago007 2011-04-23 17:18 529
        bNewGame = IMG_Load3("gfx/bNewGame.png");
8d488d32 sago007 2011-04-17 13:02 530
        mouse = IMG_Load3("gfx/mouse.png");
b7590374 sago007 2011-05-19 16:15 531
        menuMarked = IMG_Load3("gfx/menu/marked.png");
b7590374 sago007 2011-05-19 16:15 532
        menuUnmarked = IMG_Load3("gfx/menu/unmarked.png");
8d488d32 sago007 2011-04-17 13:02 533
    } catch (exception e) {
8d488d32 sago007 2011-04-17 13:02 534
        cout << e.what() << endl;
8d488d32 sago007 2011-04-17 13:02 535
        exit(1);
8d488d32 sago007 2011-04-17 13:02 536
    }
89c4a3a6 sago007 2008-08-29 14:32 537
89c4a3a6 sago007 2008-08-29 14:32 538
89c4a3a6 sago007 2008-08-29 14:32 539
    //Prepare for fast blittering!
89c4a3a6 sago007 2008-08-29 14:32 540
    CONVERT(background);
89c4a3a6 sago007 2008-08-29 14:32 541
    CONVERT(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 542
    CONVERT(b1player);
89c4a3a6 sago007 2008-08-29 14:32 543
    CONVERT(b2players);
89c4a3a6 sago007 2008-08-29 14:32 544
    CONVERT(bVsMode);
e3e0644e sago007 2008-09-25 14:00 545
    CONVERT(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 546
    CONVERT(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 547
    CONVERT(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 548
    CONVERT(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 549
    CONVERT(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 550
    CONVERT(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 551
    CONVERTA(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 552
    CONVERTA(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 553
    CONVERTA(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 554
    CONVERTA(bSave);
89c4a3a6 sago007 2008-08-29 14:32 555
    CONVERTA(bLoad);
89c4a3a6 sago007 2008-08-29 14:32 556
    CONVERTA(bTheme);
89c4a3a6 sago007 2008-08-29 14:32 557
    CONVERTA(bSkip);
89c4a3a6 sago007 2008-08-29 14:32 558
    CONVERTA(bRetry);
89c4a3a6 sago007 2008-08-29 14:32 559
    CONVERTA(bNext);
1572de2b sago007 2008-09-11 18:15 560
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 561
    CONVERTA(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 562
    CONVERTA(bHost);
89c4a3a6 sago007 2008-08-29 14:32 563
    CONVERTA(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 564
#endif
89c4a3a6 sago007 2008-08-29 14:32 565
    CONVERT(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 566
    CONVERTA(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 567
    CONVERT(backBoard);
89c4a3a6 sago007 2008-08-29 14:32 568
    CONVERT(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 569
    CONVERTA(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 570
    CONVERTA(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 571
    CONVERTA(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 572
    CONVERTA(counter[0]);
89c4a3a6 sago007 2008-08-29 14:32 573
    CONVERTA(counter[1]);
89c4a3a6 sago007 2008-08-29 14:32 574
    CONVERTA(counter[2]);
89c4a3a6 sago007 2008-08-29 14:32 575
    CONVERTA(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 576
    CONVERT(bExit);
89c4a3a6 sago007 2008-08-29 14:32 577
    CONVERT(bOn);
89c4a3a6 sago007 2008-08-29 14:32 578
    CONVERT(bOff);
89c4a3a6 sago007 2008-08-29 14:32 579
    CONVERT(bChange);
89c4a3a6 sago007 2008-08-29 14:32 580
    CONVERT(b1024);
89c4a3a6 sago007 2008-08-29 14:32 581
    CONVERTA(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 582
//	CONVERTA(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 583
    CONVERTA(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 584
    CONVERT(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 585
    CONVERTA(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 586
    for (int i = 0;i<4;i++)
89c4a3a6 sago007 2008-08-29 14:32 587
    {
89c4a3a6 sago007 2008-08-29 14:32 588
        CONVERTA(explosion[i]);
89c4a3a6 sago007 2008-08-29 14:32 589
    }
89c4a3a6 sago007 2008-08-29 14:32 590
    for (int i = 0; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 591
    {
89c4a3a6 sago007 2008-08-29 14:32 592
        CONVERTA(bricks[i]);
89c4a3a6 sago007 2008-08-29 14:32 593
        CONVERTA(balls[i]);
89c4a3a6 sago007 2008-08-29 14:32 594
    }
89c4a3a6 sago007 2008-08-29 14:32 595
    CONVERTA(crossover);
89c4a3a6 sago007 2008-08-29 14:32 596
    CONVERTA(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 597
    CONVERTA(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 598
    CONVERTA(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 599
    CONVERTA(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 600
    CONVERTA(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 601
    CONVERTA(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 602
    CONVERTA(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 603
    CONVERTA(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 604
    CONVERTA(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 605
    CONVERTA(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 606
    CONVERTA(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 607
    CONVERTA(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 608
    CONVERTA(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 609
    CONVERTA(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 610
    CONVERTA(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 611
    CONVERTA(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 612
    CONVERTA(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 613
    CONVERTA(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 614
    CONVERTA(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 615
    CONVERTA(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 616
    CONVERTA(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 617
    CONVERTA(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 618
    CONVERTA(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 619
    CONVERTA(iGameOver);
8d488d32 sago007 2011-04-17 13:02 620
    mouse.OptimizeForBlit(true);
43611709 sago007 2011-04-23 17:18 621
    bNewGame.OptimizeForBlit(true);
89c4a3a6 sago007 2008-08-29 14:32 622
    CONVERTA(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 623
    CONVERTA(transCover);
89c4a3a6 sago007 2008-08-29 14:32 624
    //Editor:
1572de2b sago007 2008-09-11 18:15 625
    #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 626
    CONVERTA(bCreateFile);
89c4a3a6 sago007 2008-08-29 14:32 627
    CONVERTA(bDeletePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 628
    CONVERTA(bLoadFile);
89c4a3a6 sago007 2008-08-29 14:32 629
    CONVERTA(bMoveBack);
89c4a3a6 sago007 2008-08-29 14:32 630
    CONVERTA(bMoveDown);
89c4a3a6 sago007 2008-08-29 14:32 631
    CONVERTA(bMoveForward);
89c4a3a6 sago007 2008-08-29 14:32 632
    CONVERTA(bMoveLeft);
89c4a3a6 sago007 2008-08-29 14:32 633
    CONVERTA(bMoveRight);
89c4a3a6 sago007 2008-08-29 14:32 634
    CONVERTA(bMoveUp);
89c4a3a6 sago007 2008-08-29 14:32 635
    CONVERTA(bNewPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 636
    CONVERTA(bSaveFileAs);
89c4a3a6 sago007 2008-08-29 14:32 637
    CONVERTA(bSavePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 638
    CONVERTA(bSaveToFile);
1572de2b sago007 2008-09-11 18:15 639
    CONVERTA(bTestPuzzle);
1572de2b sago007 2008-09-11 18:15 640
    #endif
1572de2b sago007 2008-09-11 18:15 641
    
925b7e58 sago007 2011-04-25 16:35 642
    SDL_Color nf_button_color, nf_standard_blue_color, nf_standard_small_color;
925b7e58 sago007 2011-04-25 16:35 643
    memset(&nf_button_color,0,sizeof(SDL_Color));
925b7e58 sago007 2011-04-25 16:35 644
    nf_button_color.b = 255; nf_button_color.g = 255; nf_button_color.r = 255;
925b7e58 sago007 2011-04-25 16:35 645
    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 646
    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 647
    NFont_OpenFont(&nf_button_font,"fonts/FreeSerif.ttf",24,nf_button_color);
925b7e58 sago007 2011-04-25 16:35 648
    nf_button_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 649
    NFont_OpenFont(&nf_standard_blue_font,"fonts/FreeSerif.ttf",30,nf_standard_blue_color);
925b7e58 sago007 2011-04-25 16:35 650
    nf_standard_blue_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 651
    NFont_OpenFont(&nf_standard_small_font,"fonts/FreeSerif.ttf",16,nf_standard_small_color);
925b7e58 sago007 2011-04-25 16:35 652
    nf_standard_small_font.setDest(screen);
71181267 sago007 2011-04-29 19:22 653
    NFont_OpenFont(&nf_scoreboard_font,"fonts/PenguinAttack.ttf",20,nf_button_color);
71181267 sago007 2011-04-29 19:22 654
    nf_scoreboard_font.setDest(boardBackBack);
71181267 sago007 2011-04-29 19:22 655
    nf_scoreboard_font.draw(370,148,"Score:");
71181267 sago007 2011-04-29 19:22 656
    nf_scoreboard_font.draw(370,197,"Time:");
71181267 sago007 2011-04-29 19:22 657
    nf_scoreboard_font.draw(370,246,"Chain:");
71181267 sago007 2011-04-29 19:22 658
    nf_scoreboard_font.draw(370,295,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 659
71181267 sago007 2011-04-29 19:22 660
    
89c4a3a6 sago007 2008-08-29 14:32 661
//Loads the sound if sound present
89c4a3a6 sago007 2008-08-29 14:32 662
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 663
    {
89c4a3a6 sago007 2008-08-29 14:32 664
        //And here the music:
89c4a3a6 sago007 2008-08-29 14:32 665
        bgMusic = Mix_LoadMUS2((char*)"music/bgMusic.ogg");
6d48320c sago007 2009-03-28 17:06 666
        highbeatMusic = Mix_LoadMUS2((char*)"music/highbeat.ogg");
89c4a3a6 sago007 2008-08-29 14:32 667
        //the music... we just hope it exists, else the user won't hear anything
89c4a3a6 sago007 2008-08-29 14:32 668
        //Same goes for the sounds
89c4a3a6 sago007 2008-08-29 14:32 669
        boing = Mix_LoadWAV2((char*)"sound/pop.ogg");
89c4a3a6 sago007 2008-08-29 14:32 670
        applause = Mix_LoadWAV2((char*)"sound/applause.ogg");
89c4a3a6 sago007 2008-08-29 14:32 671
        photoClick = Mix_LoadWAV2((char*)"sound/cameraclick.ogg");
89c4a3a6 sago007 2008-08-29 14:32 672
        typingChunk = Mix_LoadWAV2((char*)"sound/typing.ogg");
89c4a3a6 sago007 2008-08-29 14:32 673
        counterChunk = Mix_LoadWAV2((char*)"sound/counter.ogg");
24a6ea5f sago007 2008-11-13 22:28 674
        counterFinalChunk = Mix_LoadWAV2((char*)"sound/counterFinal.ogg");
89c4a3a6 sago007 2008-08-29 14:32 675
    } //All sound has been loaded or not
89c4a3a6 sago007 2008-08-29 14:32 676
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 677
} //InitImages()
89c4a3a6 sago007 2008-08-29 14:32 678
89c4a3a6 sago007 2008-08-29 14:32 679
89c4a3a6 sago007 2008-08-29 14:32 680
//Unload images and fonts and sounds
89c4a3a6 sago007 2008-08-29 14:32 681
void UnloadImages()
89c4a3a6 sago007 2008-08-29 14:32 682
{
866417ca sago007 2009-05-10 21:35 683
    cout << "Unloading data..." << endl;
89c4a3a6 sago007 2008-08-29 14:32 684
    if (!NoSound) //Only unload then it has been loaded!
89c4a3a6 sago007 2008-08-29 14:32 685
    {
866417ca sago007 2009-05-10 21:35 686
        Mix_HaltMusic();
89c4a3a6 sago007 2008-08-29 14:32 687
        Mix_FreeMusic(bgMusic);
6d48320c sago007 2009-03-28 17:06 688
        Mix_FreeMusic(highbeatMusic);
89c4a3a6 sago007 2008-08-29 14:32 689
        Mix_FreeChunk(boing);
89c4a3a6 sago007 2008-08-29 14:32 690
        Mix_FreeChunk(applause);
89c4a3a6 sago007 2008-08-29 14:32 691
        Mix_FreeChunk(photoClick);
89c4a3a6 sago007 2008-08-29 14:32 692
        Mix_FreeChunk(counterChunk);
24a6ea5f sago007 2008-11-13 22:28 693
        Mix_FreeChunk(counterFinalChunk);
89c4a3a6 sago007 2008-08-29 14:32 694
        Mix_FreeChunk(typingChunk);
89c4a3a6 sago007 2008-08-29 14:32 695
    }
89c4a3a6 sago007 2008-08-29 14:32 696
    //Free surfaces:
89c4a3a6 sago007 2008-08-29 14:32 697
    //I think this will crash, at least it happend to me...
866417ca sago007 2009-05-10 21:35 698
    //Chrashes no more. Caused by an undocumented double free
89c4a3a6 sago007 2008-08-29 14:32 699
    SDL_FreeSurface(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 700
    SDL_FreeSurface(background);
43611709 sago007 2011-04-23 17:18 701
    //SDL_FreeSurface(bNewGame);
89c4a3a6 sago007 2008-08-29 14:32 702
    SDL_FreeSurface(b1player);
89c4a3a6 sago007 2008-08-29 14:32 703
    SDL_FreeSurface(b2players);
89c4a3a6 sago007 2008-08-29 14:32 704
    SDL_FreeSurface(bVsMode);
e3e0644e sago007 2008-09-25 14:00 705
    SDL_FreeSurface(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 706
    SDL_FreeSurface(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 707
    SDL_FreeSurface(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 708
    SDL_FreeSurface(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 709
    SDL_FreeSurface(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 710
    SDL_FreeSurface(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 711
    SDL_FreeSurface(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 712
    SDL_FreeSurface(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 713
    SDL_FreeSurface(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 714
    SDL_FreeSurface(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 715
    SDL_FreeSurface(bSave);
89c4a3a6 sago007 2008-08-29 14:32 716
    SDL_FreeSurface(bLoad);
1572de2b sago007 2008-09-11 18:15 717
    #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 718
    SDL_FreeSurface(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 719
    SDL_FreeSurface(bHost);
89c4a3a6 sago007 2008-08-29 14:32 720
    SDL_FreeSurface(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 721
    #endif
89c4a3a6 sago007 2008-08-29 14:32 722
    SDL_FreeSurface(bExit);
89c4a3a6 sago007 2008-08-29 14:32 723
    SDL_FreeSurface(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 724
    SDL_FreeSurface(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 725
    SDL_FreeSurface(bricks[0]);
89c4a3a6 sago007 2008-08-29 14:32 726
    SDL_FreeSurface(bricks[1]);
89c4a3a6 sago007 2008-08-29 14:32 727
    SDL_FreeSurface(bricks[2]);
89c4a3a6 sago007 2008-08-29 14:32 728
    SDL_FreeSurface(bricks[3]);
89c4a3a6 sago007 2008-08-29 14:32 729
    SDL_FreeSurface(bricks[4]);
89c4a3a6 sago007 2008-08-29 14:32 730
    SDL_FreeSurface(bricks[5]);
89c4a3a6 sago007 2008-08-29 14:32 731
    SDL_FreeSurface(bricks[6]);
89c4a3a6 sago007 2008-08-29 14:32 732
    SDL_FreeSurface(crossover);
89c4a3a6 sago007 2008-08-29 14:32 733
    SDL_FreeSurface(balls[0]);
89c4a3a6 sago007 2008-08-29 14:32 734
    SDL_FreeSurface(balls[1]);
89c4a3a6 sago007 2008-08-29 14:32 735
    SDL_FreeSurface(balls[2]);
89c4a3a6 sago007 2008-08-29 14:32 736
    SDL_FreeSurface(balls[3]);
89c4a3a6 sago007 2008-08-29 14:32 737
    SDL_FreeSurface(balls[4]);
89c4a3a6 sago007 2008-08-29 14:32 738
    SDL_FreeSurface(balls[5]);
89c4a3a6 sago007 2008-08-29 14:32 739
    SDL_FreeSurface(balls[6]);
89c4a3a6 sago007 2008-08-29 14:32 740
    SDL_FreeSurface(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 741
    SDL_FreeSurface(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 742
    SDL_FreeSurface(backBoard); //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 743
    SDL_FreeSurface(iGameOver);
89c4a3a6 sago007 2008-08-29 14:32 744
    SDL_FreeSurface(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 745
    SDL_FreeSurface(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 746
    SDL_FreeSurface(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 747
    SDL_FreeSurface(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 748
    SDL_FreeSurface(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 749
    SDL_FreeSurface(bOn);
89c4a3a6 sago007 2008-08-29 14:32 750
    SDL_FreeSurface(bOff);
89c4a3a6 sago007 2008-08-29 14:32 751
    SDL_FreeSurface(bChange);
89c4a3a6 sago007 2008-08-29 14:32 752
    SDL_FreeSurface(b1024);
89c4a3a6 sago007 2008-08-29 14:32 753
    SDL_FreeSurface(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 754
    //SDL_FreeSurface(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 755
    SDL_FreeSurface(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 756
    SDL_FreeSurface(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 757
    SDL_FreeSurface(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 758
    SDL_FreeSurface(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 759
    SDL_FreeSurface(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 760
    SDL_FreeSurface(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 761
    SDL_FreeSurface(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 762
    SDL_FreeSurface(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 763
    SDL_FreeSurface(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 764
    SDL_FreeSurface(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 765
    SDL_FreeSurface(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 766
    SDL_FreeSurface(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 767
    SDL_FreeSurface(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 768
    SDL_FreeSurface(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 769
    SDL_FreeSurface(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 770
    SDL_FreeSurface(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 771
    SDL_FreeSurface(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 772
    SDL_FreeSurface(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 773
    SDL_FreeSurface(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 774
    SDL_FreeSurface(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 775
    SDL_FreeSurface(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 776
    SDL_FreeSurface(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 777
    SDL_FreeSurface(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 778
    SDL_FreeSurface(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 779
    SDL_FreeSurface(transCover);
8d488d32 sago007 2011-04-17 13:02 780
    mouse.MakeNull();
43611709 sago007 2011-04-23 17:18 781
    bNewGame.MakeNull();
89c4a3a6 sago007 2008-08-29 14:32 782
}
89c4a3a6 sago007 2008-08-29 14:32 783
89c4a3a6 sago007 2008-08-29 14:32 784
//Function to convert numbers to string
769a41a0 sago007 2008-09-24 12:54 785
/*string itoa(int num)
89c4a3a6 sago007 2008-08-29 14:32 786
{
89c4a3a6 sago007 2008-08-29 14:32 787
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 788
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 789
    return converter.str();
769a41a0 sago007 2008-09-24 12:54 790
}*/
89c4a3a6 sago007 2008-08-29 14:32 791
89c4a3a6 sago007 2008-08-29 14:32 792
//Function to convert numbers to string (2 diget)
4b0c248f sago007 2010-11-10 21:13 793
static string itoa2(int num)
89c4a3a6 sago007 2008-08-29 14:32 794
{
89c4a3a6 sago007 2008-08-29 14:32 795
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 796
    if(num<10)
89c4a3a6 sago007 2008-08-29 14:32 797
        converter << "0";
89c4a3a6 sago007 2008-08-29 14:32 798
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 799
    return converter.str();
89c4a3a6 sago007 2008-08-29 14:32 800
}
89c4a3a6 sago007 2008-08-29 14:32 801
89c4a3a6 sago007 2008-08-29 14:32 802
/*Loads all the puzzle levels*/
4b0c248f sago007 2010-11-10 21:13 803
static int LoadPuzzleStages()
89c4a3a6 sago007 2008-08-29 14:32 804
{
89c4a3a6 sago007 2008-08-29 14:32 805
    //if(puzzleLoaded)
89c4a3a6 sago007 2008-08-29 14:32 806
    //    return 1;
aca2f4b0 sago007 2009-05-10 18:11 807
    if (!PHYSFS_exists(("puzzles/"+puzzleName).c_str()))
aca2f4b0 sago007 2009-05-10 18:11 808
    {
aca2f4b0 sago007 2009-05-10 18:11 809
        cout << "File not in blockattack.data: " << ("puzzles/"+puzzleName) << endl;
aca2f4b0 sago007 2009-05-10 18:11 810
        return -1; //file doesn't exist
aca2f4b0 sago007 2009-05-10 18:11 811
    }
aca2f4b0 sago007 2009-05-10 18:11 812
    PhysFS::ifstream inFile(("puzzles/"+puzzleName).c_str());
aca2f4b0 sago007 2009-05-10 18:11 813
89c4a3a6 sago007 2008-08-29 14:32 814
    inFile >> nrOfPuzzles;
89c4a3a6 sago007 2008-08-29 14:32 815
    if (nrOfPuzzles>maxNrOfPuzzleStages)
89c4a3a6 sago007 2008-08-29 14:32 816
        nrOfPuzzles=maxNrOfPuzzleStages;
aca2f4b0 sago007 2009-05-10 18:11 817
    for (int k=0; (k<nrOfPuzzles) /*&&(!inFile.eof())*/ ; k++)
89c4a3a6 sago007 2008-08-29 14:32 818
    {
89c4a3a6 sago007 2008-08-29 14:32 819
        inFile >> nrOfMovesAllowed[k];
89c4a3a6 sago007 2008-08-29 14:32 820
        for (int i=11;i>=0;i--)
89c4a3a6 sago007 2008-08-29 14:32 821
            for (int j=0;j<6;j++)
89c4a3a6 sago007 2008-08-29 14:32 822
            {
89c4a3a6 sago007 2008-08-29 14:32 823
                inFile >> puzzleLevels[k][j][i];
89c4a3a6 sago007 2008-08-29 14:32 824
            }
89c4a3a6 sago007 2008-08-29 14:32 825
    }
89c4a3a6 sago007 2008-08-29 14:32 826
    puzzleLoaded = true;
89c4a3a6 sago007 2008-08-29 14:32 827
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 828
}
89c4a3a6 sago007 2008-08-29 14:32 829
89c4a3a6 sago007 2008-08-29 14:32 830
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
e1290bdf sago007 2010-10-25 19:56 831
void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 832
{
89c4a3a6 sago007 2008-08-29 14:32 833
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 834
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 835
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 836
    SDL_BlitSurface(img, NULL, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 837
}
89c4a3a6 sago007 2008-08-29 14:32 838
89c4a3a6 sago007 2008-08-29 14:32 839
/*Draws a part of an image on a surface of choice*/
89c4a3a6 sago007 2008-08-29 14:32 840
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 841
{
89c4a3a6 sago007 2008-08-29 14:32 842
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 843
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 844
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 845
    SDL_Rect dest2;
89c4a3a6 sago007 2008-08-29 14:32 846
    dest2.x = x2;
89c4a3a6 sago007 2008-08-29 14:32 847
    dest2.y = y2;
89c4a3a6 sago007 2008-08-29 14:32 848
    dest2.w = w;
89c4a3a6 sago007 2008-08-29 14:32 849
    dest2.h = h;
89c4a3a6 sago007 2008-08-29 14:32 850
    SDL_BlitSurface(img, &dest2, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 851
}
89c4a3a6 sago007 2008-08-29 14:32 852
925b7e58 sago007 2011-04-25 16:35 853
void NFont_Write(SDL_Surface *target,int x,int y,string text) {
925b7e58 sago007 2011-04-25 16:35 854
    nf_standard_blue_font.setDest(target);
925b7e58 sago007 2011-04-25 16:35 855
    nf_standard_blue_font.draw(x,y,text.c_str());
925b7e58 sago007 2011-04-25 16:35 856
    nf_standard_blue_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 857
}
925b7e58 sago007 2011-04-25 16:35 858
78d03b38 sago007 2008-11-13 19:56 859
//Menu
b7590374 sago007 2011-05-19 16:15 860
void PrintHi()
78d03b38 sago007 2008-11-13 19:56 861
{
78d03b38 sago007 2008-11-13 19:56 862
    cout << "Hi" <<endl;
78d03b38 sago007 2008-11-13 19:56 863
}
78d03b38 sago007 2008-11-13 19:56 864
78d03b38 sago007 2008-11-13 19:56 865
void InitMenues()
78d03b38 sago007 2008-11-13 19:56 866
{
b7590374 sago007 2011-05-19 16:15 867
    ButtonGfx::setSurfaces(menuMarked,menuUnmarked);
b7590374 sago007 2011-05-19 16:15 868
    ButtonGfx::thefont = nf_scoreboard_font;
b7590374 sago007 2011-05-19 16:15 869
}
b7590374 sago007 2011-05-19 16:15 870
b7590374 sago007 2011-05-19 16:15 871
void runGame(int gametype);
b7590374 sago007 2011-05-19 16:15 872
b7590374 sago007 2011-05-19 16:15 873
void runSinglePlayerEndless() {
b7590374 sago007 2011-05-19 16:15 874
    runGame(0);
b7590374 sago007 2011-05-19 16:15 875
}
b7590374 sago007 2011-05-19 16:15 876
b7590374 sago007 2011-05-19 16:15 877
void runSinglePlayerTimeTrial() {
b7590374 sago007 2011-05-19 16:15 878
    runGame(1);
b7590374 sago007 2011-05-19 16:15 879
}
b7590374 sago007 2011-05-19 16:15 880
b7590374 sago007 2011-05-19 16:15 881
void runSinglePlayerPuzzle() {
b7590374 sago007 2011-05-19 16:15 882
    runGame(3);
b7590374 sago007 2011-05-19 16:15 883
}
b7590374 sago007 2011-05-19 16:15 884
b7590374 sago007 2011-05-19 16:15 885
void runSinglePlayerVs() {
b7590374 sago007 2011-05-19 16:15 886
    runGame(4);
78d03b38 sago007 2008-11-13 19:56 887
}
78d03b38 sago007 2008-11-13 19:56 888
78d03b38 sago007 2008-11-13 19:56 889
void MainMenu()
78d03b38 sago007 2008-11-13 19:56 890
{
b7590374 sago007 2011-05-19 16:15 891
    InitMenues();
78d03b38 sago007 2008-11-13 19:56 892
    Menu m(&screen,true);
b7590374 sago007 2011-05-19 16:15 893
    Button bHi,bTimetrial1, bPuzzle, bVs1;
b7590374 sago007 2011-05-19 16:15 894
    bHi.setLabel("Single player - endless");
b7590374 sago007 2011-05-19 16:15 895
    bHi.setAction(runSinglePlayerEndless);
b7590374 sago007 2011-05-19 16:15 896
    bTimetrial1.setLabel("Single player - time trial");
b7590374 sago007 2011-05-19 16:15 897
    bTimetrial1.setAction(runSinglePlayerTimeTrial);
b7590374 sago007 2011-05-19 16:15 898
    bPuzzle.setLabel("Single player - puzzle mode");
b7590374 sago007 2011-05-19 16:15 899
    bPuzzle.setAction(runSinglePlayerPuzzle);
b7590374 sago007 2011-05-19 16:15 900
    bVs1.setLabel("Single player - vs");
b7590374 sago007 2011-05-19 16:15 901
    bVs1.setAction(runSinglePlayerVs);
78d03b38 sago007 2008-11-13 19:56 902
    m.addButton(bHi);
b7590374 sago007 2011-05-19 16:15 903
    m.addButton(bTimetrial1);
b7590374 sago007 2011-05-19 16:15 904
    m.addButton(bPuzzle);
b7590374 sago007 2011-05-19 16:15 905
    m.addButton(bVs1);
78d03b38 sago007 2008-11-13 19:56 906
    m.run();
b7590374 sago007 2011-05-19 16:15 907
}
78d03b38 sago007 2008-11-13 19:56 908
89c4a3a6 sago007 2008-08-29 14:32 909
//The small things that are faaling when you clear something
89c4a3a6 sago007 2008-08-29 14:32 910
class aBall
89c4a3a6 sago007 2008-08-29 14:32 911
{
89c4a3a6 sago007 2008-08-29 14:32 912
private:
89c4a3a6 sago007 2008-08-29 14:32 913
    double x;
89c4a3a6 sago007 2008-08-29 14:32 914
    double y;
89c4a3a6 sago007 2008-08-29 14:32 915
    double velocityY;
89c4a3a6 sago007 2008-08-29 14:32 916
    double velocityX;
89c4a3a6 sago007 2008-08-29 14:32 917
    int color;
89c4a3a6 sago007 2008-08-29 14:32 918
    unsigned long int lastTime;
89c4a3a6 sago007 2008-08-29 14:32 919
public:
89c4a3a6 sago007 2008-08-29 14:32 920
89c4a3a6 sago007 2008-08-29 14:32 921
    aBall()
89c4a3a6 sago007 2008-08-29 14:32 922
    {}
89c4a3a6 sago007 2008-08-29 14:32 923
89c4a3a6 sago007 2008-08-29 14:32 924
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 925
    aBall(int X, int Y, bool right, int coulor)
89c4a3a6 sago007 2008-08-29 14:32 926
    {
89c4a3a6 sago007 2008-08-29 14:32 927
        double tal = 1.0;
89c4a3a6 sago007 2008-08-29 14:32 928
        velocityY = -tal*startVelocityY;
89c4a3a6 sago007 2008-08-29 14:32 929
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 930
        x = (double)X;
89c4a3a6 sago007 2008-08-29 14:32 931
        y = (double)Y;
89c4a3a6 sago007 2008-08-29 14:32 932
        color = coulor;
89c4a3a6 sago007 2008-08-29 14:32 933
        if (right)
89c4a3a6 sago007 2008-08-29 14:32 934
            velocityX = tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 935
        else
89c4a3a6 sago007 2008-08-29 14:32 936
            velocityX = -tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 937
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 938
89c4a3a6 sago007 2008-08-29 14:32 939
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 940
    ~aBall()
89c4a3a6 sago007 2008-08-29 14:32 941
    {
89c4a3a6 sago007 2008-08-29 14:32 942
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 943
89c4a3a6 sago007 2008-08-29 14:32 944
    void update()
89c4a3a6 sago007 2008-08-29 14:32 945
    {
89c4a3a6 sago007 2008-08-29 14:32 946
        double timePassed = (((double)(currentTime-lastTime))/1000.0);  //time passed in seconds
89c4a3a6 sago007 2008-08-29 14:32 947
        x = x+timePassed*velocityX;
89c4a3a6 sago007 2008-08-29 14:32 948
        y = y+timePassed*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 949
        velocityY = velocityY + gravity*timePassed;
89c4a3a6 sago007 2008-08-29 14:32 950
        if (y<1.0)
89c4a3a6 sago007 2008-08-29 14:32 951
            velocityY=10.0;
89c4a3a6 sago007 2008-08-29 14:32 952
        if ((velocityY>minVelocity) && (y>(double)(768-ballSize)) && (y<768.0))
89c4a3a6 sago007 2008-08-29 14:32 953
        {
89c4a3a6 sago007 2008-08-29 14:32 954
            velocityY = -0.70*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 955
            y = 768.0-ballSize;
89c4a3a6 sago007 2008-08-29 14:32 956
        }
89c4a3a6 sago007 2008-08-29 14:32 957
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 958
    }
89c4a3a6 sago007 2008-08-29 14:32 959
89c4a3a6 sago007 2008-08-29 14:32 960
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 961
    {
89c4a3a6 sago007 2008-08-29 14:32 962
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 963
    }
89c4a3a6 sago007 2008-08-29 14:32 964
89c4a3a6 sago007 2008-08-29 14:32 965
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 966
    {
89c4a3a6 sago007 2008-08-29 14:32 967
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 968
    }
89c4a3a6 sago007 2008-08-29 14:32 969
89c4a3a6 sago007 2008-08-29 14:32 970
    int getColor()
89c4a3a6 sago007 2008-08-29 14:32 971
    {
89c4a3a6 sago007 2008-08-29 14:32 972
        return color;
89c4a3a6 sago007 2008-08-29 14:32 973
    }
89c4a3a6 sago007 2008-08-29 14:32 974
};  //aBall
89c4a3a6 sago007 2008-08-29 14:32 975
4b0c248f sago007 2010-11-10 21:13 976
static const int maxNumberOfBalls = 6*12*2*2;
89c4a3a6 sago007 2008-08-29 14:32 977
89c4a3a6 sago007 2008-08-29 14:32 978
class ballManeger
89c4a3a6 sago007 2008-08-29 14:32 979
{
89c4a3a6 sago007 2008-08-29 14:32 980
public:
89c4a3a6 sago007 2008-08-29 14:32 981
    aBall ballArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 982
    bool ballUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 983
    //The old ball information is also saved so balls can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 984
    aBall oldBallArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 985
    bool oldBallUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 986
89c4a3a6 sago007 2008-08-29 14:32 987
    ballManeger()
89c4a3a6 sago007 2008-08-29 14:32 988
    {
89c4a3a6 sago007 2008-08-29 14:32 989
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 990
        {
89c4a3a6 sago007 2008-08-29 14:32 991
            ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 992
            oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 993
        }
89c4a3a6 sago007 2008-08-29 14:32 994
    }
89c4a3a6 sago007 2008-08-29 14:32 995
6d48320c sago007 2009-03-28 17:06 996
    //Adds a ball to the screen at given coordiantes, traveling right or not with color
89c4a3a6 sago007 2008-08-29 14:32 997
    int addBall(int x, int y,bool right,int color)
89c4a3a6 sago007 2008-08-29 14:32 998
    {
89c4a3a6 sago007 2008-08-29 14:32 999
        int ballNumber = 0;
6d48320c sago007 2009-03-28 17:06 1000
        //Find a free ball
89c4a3a6 sago007 2008-08-29 14:32 1001
        while ((ballUsed[ballNumber])&&(ballNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 1002
            ballNumber++;
6d48320c sago007 2009-03-28 17:06 1003
        //Could not find a free ball, return -1
89c4a3a6 sago007 2008-08-29 14:32 1004
        if (ballNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1005
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1006
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1007
        ballArray[ballNumber] = aBall(x,y,right,color);
89c4a3a6 sago007 2008-08-29 14:32 1008
        ballUsed[ballNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1009
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1010
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 1011
89c4a3a6 sago007 2008-08-29 14:32 1012
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1013
    {
89c4a3a6 sago007 2008-08-29 14:32 1014
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1015
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1016
        {
89c4a3a6 sago007 2008-08-29 14:32 1017
89c4a3a6 sago007 2008-08-29 14:32 1018
            if (ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1019
            {
89c4a3a6 sago007 2008-08-29 14:32 1020
                oldBallUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1021
                oldBallArray[i] = ballArray[i];
89c4a3a6 sago007 2008-08-29 14:32 1022
                ballArray[i].update();
6d48320c sago007 2009-03-28 17:06 1023
                if (ballArray[i].getY()>800 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize)
89c4a3a6 sago007 2008-08-29 14:32 1024
                {
89c4a3a6 sago007 2008-08-29 14:32 1025
                    ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1026
                }
89c4a3a6 sago007 2008-08-29 14:32 1027
            }
89c4a3a6 sago007 2008-08-29 14:32 1028
            else
89c4a3a6 sago007 2008-08-29 14:32 1029
            {
89c4a3a6 sago007 2008-08-29 14:32 1030
                oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1031
            }
89c4a3a6 sago007 2008-08-29 14:32 1032
        }
89c4a3a6 sago007 2008-08-29 14:32 1033
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1034
89c4a3a6 sago007 2008-08-29 14:32 1035
89c4a3a6 sago007 2008-08-29 14:32 1036
}; //theBallManeger
89c4a3a6 sago007 2008-08-29 14:32 1037
4b0c248f sago007 2010-11-10 21:13 1038
static ballManeger theBallManeger;
89c4a3a6 sago007 2008-08-29 14:32 1039
89c4a3a6 sago007 2008-08-29 14:32 1040
//a explosions, non moving
89c4a3a6 sago007 2008-08-29 14:32 1041
class anExplosion
89c4a3a6 sago007 2008-08-29 14:32 1042
{
89c4a3a6 sago007 2008-08-29 14:32 1043
private:
89c4a3a6 sago007 2008-08-29 14:32 1044
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1045
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1046
    Uint8 frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 1047
#define frameLength 80
89c4a3a6 sago007 2008-08-29 14:32 1048
    //How long an image in an animation should be showed
89c4a3a6 sago007 2008-08-29 14:32 1049
#define maxFrame 4
89c4a3a6 sago007 2008-08-29 14:32 1050
    //How many images there are in the animation
89c4a3a6 sago007 2008-08-29 14:32 1051
    unsigned long int placeTime; //Then the explosion occored
89c4a3a6 sago007 2008-08-29 14:32 1052
public:
89c4a3a6 sago007 2008-08-29 14:32 1053
89c4a3a6 sago007 2008-08-29 14:32 1054
    anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 1055
    {}
89c4a3a6 sago007 2008-08-29 14:32 1056
89c4a3a6 sago007 2008-08-29 14:32 1057
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1058
    anExplosion(int X, int Y)
89c4a3a6 sago007 2008-08-29 14:32 1059
    {
89c4a3a6 sago007 2008-08-29 14:32 1060
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1061
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1062
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1063
        frameNumber=0;
89c4a3a6 sago007 2008-08-29 14:32 1064
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1065
89c4a3a6 sago007 2008-08-29 14:32 1066
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1067
    ~anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 1068
    {
89c4a3a6 sago007 2008-08-29 14:32 1069
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1070
89c4a3a6 sago007 2008-08-29 14:32 1071
    //true if animation has played and object should be removed from the screen
89c4a3a6 sago007 2008-08-29 14:32 1072
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1073
    {
89c4a3a6 sago007 2008-08-29 14:32 1074
        frameNumber = (currentTime-placeTime)/frameLength;
89c4a3a6 sago007 2008-08-29 14:32 1075
        return (!(frameNumber<maxFrame));
89c4a3a6 sago007 2008-08-29 14:32 1076
    }
89c4a3a6 sago007 2008-08-29 14:32 1077
89c4a3a6 sago007 2008-08-29 14:32 1078
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1079
    {
89c4a3a6 sago007 2008-08-29 14:32 1080
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 1081
    }
89c4a3a6 sago007 2008-08-29 14:32 1082
89c4a3a6 sago007 2008-08-29 14:32 1083
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1084
    {
89c4a3a6 sago007 2008-08-29 14:32 1085
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 1086
    }
89c4a3a6 sago007 2008-08-29 14:32 1087
89c4a3a6 sago007 2008-08-29 14:32 1088
    int getFrame()
89c4a3a6 sago007 2008-08-29 14:32 1089
    {
89c4a3a6 sago007 2008-08-29 14:32 1090
        return frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 1091
    }
89c4a3a6 sago007 2008-08-29 14:32 1092
};  //nExplosion
89c4a3a6 sago007 2008-08-29 14:32 1093
89c4a3a6 sago007 2008-08-29 14:32 1094
class explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1095
{
89c4a3a6 sago007 2008-08-29 14:32 1096
public:
89c4a3a6 sago007 2008-08-29 14:32 1097
    anExplosion explosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1098
    bool explosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1099
    //The old explosion information is also saved so explosions can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1100
    anExplosion oldExplosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1101
    bool oldExplosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1102
89c4a3a6 sago007 2008-08-29 14:32 1103
    explosionManeger()
89c4a3a6 sago007 2008-08-29 14:32 1104
    {
89c4a3a6 sago007 2008-08-29 14:32 1105
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1106
        {
89c4a3a6 sago007 2008-08-29 14:32 1107
            explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1108
            oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1109
        }
89c4a3a6 sago007 2008-08-29 14:32 1110
    }
89c4a3a6 sago007 2008-08-29 14:32 1111
89c4a3a6 sago007 2008-08-29 14:32 1112
    int addExplosion(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 1113
    {
89c4a3a6 sago007 2008-08-29 14:32 1114
        //cout << "Tries to add an explosion" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1115
        int explosionNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1116
        while ((explosionUsed[explosionNumber])&&(explosionNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 1117
            explosionNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1118
        if (explosionNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1119
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1120
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1121
        explosionArray[explosionNumber] = anExplosion(x,y);
89c4a3a6 sago007 2008-08-29 14:32 1122
        explosionUsed[explosionNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1123
        //cout << "Explosion added" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1124
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1125
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 1126
89c4a3a6 sago007 2008-08-29 14:32 1127
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1128
    {
89c4a3a6 sago007 2008-08-29 14:32 1129
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1130
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1131
        {
89c4a3a6 sago007 2008-08-29 14:32 1132
89c4a3a6 sago007 2008-08-29 14:32 1133
            if (explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1134
            {
89c4a3a6 sago007 2008-08-29 14:32 1135
                oldExplosionUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1136
                oldExplosionArray[i] = explosionArray[i];
89c4a3a6 sago007 2008-08-29 14:32 1137
                if (explosionArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1138
                {
89c4a3a6 sago007 2008-08-29 14:32 1139
                    explosionArray[i].~anExplosion();
89c4a3a6 sago007 2008-08-29 14:32 1140
                    explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1141
                    //cout << "Explosion removed" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1142
                }
89c4a3a6 sago007 2008-08-29 14:32 1143
            }
89c4a3a6 sago007 2008-08-29 14:32 1144
            else
89c4a3a6 sago007 2008-08-29 14:32 1145
            {
89c4a3a6 sago007 2008-08-29 14:32 1146
                oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1147
            }
89c4a3a6 sago007 2008-08-29 14:32 1148
        }
89c4a3a6 sago007 2008-08-29 14:32 1149
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1150
89c4a3a6 sago007 2008-08-29 14:32 1151
89c4a3a6 sago007 2008-08-29 14:32 1152
}; //explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1153
4b0c248f sago007 2010-11-10 21:13 1154
static explosionManeger theExplosionManeger;
89c4a3a6 sago007 2008-08-29 14:32 1155
89c4a3a6 sago007 2008-08-29 14:32 1156
//text pop-up
89c4a3a6 sago007 2008-08-29 14:32 1157
class textMessage
89c4a3a6 sago007 2008-08-29 14:32 1158
{
89c4a3a6 sago007 2008-08-29 14:32 1159
private:
89c4a3a6 sago007 2008-08-29 14:32 1160
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1161
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1162
    char textt[10];
89c4a3a6 sago007 2008-08-29 14:32 1163
    unsigned long int time;
89c4a3a6 sago007 2008-08-29 14:32 1164
    unsigned long int placeTime; //Then the text was placed
89c4a3a6 sago007 2008-08-29 14:32 1165
public:
89c4a3a6 sago007 2008-08-29 14:32 1166
89c4a3a6 sago007 2008-08-29 14:32 1167
    textMessage()
89c4a3a6 sago007 2008-08-29 14:32 1168
    {}
89c4a3a6 sago007 2008-08-29 14:32 1169
89c4a3a6 sago007 2008-08-29 14:32 1170
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1171
    textMessage(int X, int Y,const char* Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1172
    {
89c4a3a6 sago007 2008-08-29 14:32 1173
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1174
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1175
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1176
        strncpy(textt,Text,10);
89c4a3a6 sago007 2008-08-29 14:32 1177
        textt[9]=0;
89c4a3a6 sago007 2008-08-29 14:32 1178
        time = Time;
89c4a3a6 sago007 2008-08-29 14:32 1179
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1180
89c4a3a6 sago007 2008-08-29 14:32 1181
    //true if the text has expired
89c4a3a6 sago007 2008-08-29 14:32 1182
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1183
    {
89c4a3a6 sago007 2008-08-29 14:32 1184
        return currentTime-placeTime>time;
89c4a3a6 sago007 2008-08-29 14:32 1185
    }
89c4a3a6 sago007 2008-08-29 14:32 1186
89c4a3a6 sago007 2008-08-29 14:32 1187
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1188
    {
89c4a3a6 sago007 2008-08-29 14:32 1189
        return x;
89c4a3a6 sago007 2008-08-29 14:32 1190
    }
89c4a3a6 sago007 2008-08-29 14:32 1191
89c4a3a6 sago007 2008-08-29 14:32 1192
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1193
    {
89c4a3a6 sago007 2008-08-29 14:32 1194
        return y;
89c4a3a6 sago007 2008-08-29 14:32 1195
    }
89c4a3a6 sago007 2008-08-29 14:32 1196
89c4a3a6 sago007 2008-08-29 14:32 1197
    char* getText()
89c4a3a6 sago007 2008-08-29 14:32 1198
    {
89c4a3a6 sago007 2008-08-29 14:32 1199
        return textt;
89c4a3a6 sago007 2008-08-29 14:32 1200
    }
89c4a3a6 sago007 2008-08-29 14:32 1201
};  //text popup
89c4a3a6 sago007 2008-08-29 14:32 1202
89c4a3a6 sago007 2008-08-29 14:32 1203
class textManeger
89c4a3a6 sago007 2008-08-29 14:32 1204
{
89c4a3a6 sago007 2008-08-29 14:32 1205
public:
89c4a3a6 sago007 2008-08-29 14:32 1206
    textMessage textArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1207
    bool textUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1208
    //The old text information is also saved so text can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1209
    textMessage oldTextArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1210
    bool oldTextUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1211
89c4a3a6 sago007 2008-08-29 14:32 1212
    textManeger()
89c4a3a6 sago007 2008-08-29 14:32 1213
    {
89c4a3a6 sago007 2008-08-29 14:32 1214
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1215
        {
89c4a3a6 sago007 2008-08-29 14:32 1216
            textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1217
            oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1218
        }
89c4a3a6 sago007 2008-08-29 14:32 1219
    }
89c4a3a6 sago007 2008-08-29 14:32 1220
89c4a3a6 sago007 2008-08-29 14:32 1221
    int addText(int x, int y,string Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1222
    {
89c4a3a6 sago007 2008-08-29 14:32 1223
        //cout << "Tries to add text" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1224
        int textNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1225
        while ((textNumber<maxNumberOfBalls)&&((textUsed[textNumber])||(oldTextUsed[textNumber])))
89c4a3a6 sago007 2008-08-29 14:32 1226
            textNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1227
        if (textNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1228
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1229
        //cout << "adding to: " << textNumber << ":" << textUsed[textNumber] << ":" << &textArray[textNumber] << endl;
89c4a3a6 sago007 2008-08-29 14:32 1230
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1231
        textArray[textNumber] = textMessage(x,y,Text.c_str(),Time);
89c4a3a6 sago007 2008-08-29 14:32 1232
        textUsed[textNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1233
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1234
    }  //addText
89c4a3a6 sago007 2008-08-29 14:32 1235
89c4a3a6 sago007 2008-08-29 14:32 1236
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1237
    {
89c4a3a6 sago007 2008-08-29 14:32 1238
        //cout << "Running update" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1239
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1240
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1241
        {
89c4a3a6 sago007 2008-08-29 14:32 1242
89c4a3a6 sago007 2008-08-29 14:32 1243
            if (textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1244
            {
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] = true;
89c4a3a6 sago007 2008-08-29 14:32 1248
                    oldTextArray[i] = textMessage(textArray[i]);
89c4a3a6 sago007 2008-08-29 14:32 1249
                }
89c4a3a6 sago007 2008-08-29 14:32 1250
                if (textArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1251
                {
89c4a3a6 sago007 2008-08-29 14:32 1252
                    textArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1253
                    textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1254
                }
89c4a3a6 sago007 2008-08-29 14:32 1255
            }
89c4a3a6 sago007 2008-08-29 14:32 1256
            else
89c4a3a6 sago007 2008-08-29 14:32 1257
                if (oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1258
                {
89c4a3a6 sago007 2008-08-29 14:32 1259
                    oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1260
                    oldTextArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1261
                }
89c4a3a6 sago007 2008-08-29 14:32 1262
        }
89c4a3a6 sago007 2008-08-29 14:32 1263
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1264
89c4a3a6 sago007 2008-08-29 14:32 1265
89c4a3a6 sago007 2008-08-29 14:32 1266
}; //textManeger
89c4a3a6 sago007 2008-08-29 14:32 1267
4b0c248f sago007 2010-11-10 21:13 1268
static textManeger theTextManeger;
89c4a3a6 sago007 2008-08-29 14:32 1269
89c4a3a6 sago007 2008-08-29 14:32 1270
//Here comes the Block Game object
89c4a3a6 sago007 2008-08-29 14:32 1271
#include "BlockGame.hpp"
17916a2e sago007 2010-11-07 11:26 1272
#include "BlockGame.cpp"
89c4a3a6 sago007 2008-08-29 14:32 1273
6b1dc7a6 sago007 2010-11-08 21:03 1274
class BlockGameSdl : public BlockGame {
6b1dc7a6 sago007 2010-11-08 21:03 1275
public:
6b1dc7a6 sago007 2010-11-08 21:03 1276
    SDL_Surface* sBoard;
6b1dc7a6 sago007 2010-11-08 21:03 1277
6b1dc7a6 sago007 2010-11-08 21:03 1278
    BlockGameSdl(int tx, int ty) {
6b1dc7a6 sago007 2010-11-08 21:03 1279
        tmp = IMG_Load2((char*)"gfx/BackBoard.png");
6b1dc7a6 sago007 2010-11-08 21:03 1280
        sBoard = SDL_DisplayFormat(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1281
        SDL_FreeSurface(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1282
        //BlockGame::BlockGame(tx,ty);
6b1dc7a6 sago007 2010-11-08 21:03 1283
        BlockGame::topx = tx;
6b1dc7a6 sago007 2010-11-08 21:03 1284
        BlockGame::topy = ty;
6b1dc7a6 sago007 2010-11-08 21:03 1285
    }
6b1dc7a6 sago007 2010-11-08 21:03 1286
    ~BlockGameSdl() {
6b1dc7a6 sago007 2010-11-08 21:03 1287
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1288
    }
6b1dc7a6 sago007 2010-11-08 21:03 1289
private:
6b1dc7a6 sago007 2010-11-08 21:03 1290
    void convertSurface() {
6b1dc7a6 sago007 2010-11-08 21:03 1291
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1292
        sBoard = SDL_DisplayFormat(backBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1293
    }
6b1dc7a6 sago007 2010-11-08 21:03 1294
    //Draws all the bricks to the board (including garbage)
6b1dc7a6 sago007 2010-11-08 21:03 1295
    void PaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1296
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1297
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1298
                if ((board[j][i]%10 != -1) && (board[j][i]%10 < 7) && ((board[j][i]/1000000)%10==0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1299
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1300
                    if ((board[j][i]/BLOCKWAIT)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1301
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1302
                    if ((board[j][i]/BLOCKHANG)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1303
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1304
6b1dc7a6 sago007 2010-11-08 21:03 1305
                }
6b1dc7a6 sago007 2010-11-08 21:03 1306
                if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1307
                    int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1308
                    int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1309
                    if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1310
                    else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1311
                    if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1312
                    else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1313
                    if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1314
                    else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1315
                    if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1316
                    else under = board[j][i-1];
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(garbageFill, 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(garbageL, 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(garbageR, 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(garbageT, 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(garbageB, 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(garbageTL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1329
                    if ((left != number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1330
                        DrawIMG(garbageBL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1331
                    if ((left == number)&&(right != number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1332
                        DrawIMG(garbageTR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1333
                    if ((left == number)&&(right != number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1334
                        DrawIMG(garbageBR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1335
                    if ((left == number)&&(right != number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1336
                        DrawIMG(garbageMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1337
                    if ((left == number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1338
                        DrawIMG(garbageM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1339
                    if ((left != number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1340
                        DrawIMG(garbageML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1341
                }
6b1dc7a6 sago007 2010-11-08 21:03 1342
                if ((board[j][i]/1000000)%10==2) {
6b1dc7a6 sago007 2010-11-08 21:03 1343
                    if (j==0)
6b1dc7a6 sago007 2010-11-08 21:03 1344
                        DrawIMG(garbageGML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1345
                    else
6b1dc7a6 sago007 2010-11-08 21:03 1346
                        if (j==5)
6b1dc7a6 sago007 2010-11-08 21:03 1347
                            DrawIMG(garbageGMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1348
                        else
6b1dc7a6 sago007 2010-11-08 21:03 1349
                            DrawIMG(garbageGM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1350
                }
6b1dc7a6 sago007 2010-11-08 21:03 1351
            }
6b1dc7a6 sago007 2010-11-08 21:03 1352
        const int j = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1353
6b1dc7a6 sago007 2010-11-08 21:03 1354
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1355
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1356
            if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1357
                int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1358
                int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1359
                if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1360
                else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1361
                if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1362
                else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1363
                if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1364
                else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1365
                if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1366
                else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1367
                if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1368
                    DrawIMG(smiley[board[j][i]%4], sBoard, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1369
                }
6b1dc7a6 sago007 2010-11-08 21:03 1370
                if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1371
                {
6b1dc7a6 sago007 2010-11-08 21:03 1372
                    garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1373
                }
6b1dc7a6 sago007 2010-11-08 21:03 1374
                else {
6b1dc7a6 sago007 2010-11-08 21:03 1375
                    //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1376
                    garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1377
                }
6b1dc7a6 sago007 2010-11-08 21:03 1378
6b1dc7a6 sago007 2010-11-08 21:03 1379
            }
6b1dc7a6 sago007 2010-11-08 21:03 1380
        }
6b1dc7a6 sago007 2010-11-08 21:03 1381
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1382
            if (board[i][0]!=-1)
6b1dc7a6 sago007 2010-11-08 21:03 1383
                DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant
6b1dc7a6 sago007 2010-11-08 21:03 1384
6b1dc7a6 sago007 2010-11-08 21:03 1385
    }
6b1dc7a6 sago007 2010-11-08 21:03 1386
    //Paints the bricks gotten from a replay/net package
6b1dc7a6 sago007 2010-11-08 21:03 1387
    void SimplePaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1388
        /*
6b1dc7a6 sago007 2010-11-08 21:03 1389
         * 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 1390
         */
6b1dc7a6 sago007 2010-11-08 21:03 1391
        bool bbomb[6][13]; //has a bomb on it!
6b1dc7a6 sago007 2010-11-08 21:03 1392
        bool falling[6][13]; //this is falling
6b1dc7a6 sago007 2010-11-08 21:03 1393
        bool getReady[6][13]; //getReady
6b1dc7a6 sago007 2010-11-08 21:03 1394
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1395
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1396
                bbomb[i][j]=false; //All false by default
6b1dc7a6 sago007 2010-11-08 21:03 1397
                falling[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1398
                if (board[i][j]>29)
6b1dc7a6 sago007 2010-11-08 21:03 1399
                    getReady[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1400
                else
6b1dc7a6 sago007 2010-11-08 21:03 1401
                    getReady[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1402
            }
6b1dc7a6 sago007 2010-11-08 21:03 1403
        //See that is falling
6b1dc7a6 sago007 2010-11-08 21:03 1404
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1405
            bool rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1406
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1407
                if (rowFalling)
6b1dc7a6 sago007 2010-11-08 21:03 1408
                    falling[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1409
                if ((!rowFalling)&&(board[i][j]%30==-1))
6b1dc7a6 sago007 2010-11-08 21:03 1410
                    rowFalling = true;
6b1dc7a6 sago007 2010-11-08 21:03 1411
                if ((rowFalling)&&(board[i][j]%30>6))
6b1dc7a6 sago007 2010-11-08 21:03 1412
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1413
                if (getReady[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1414
                    falling[i][j]=true; //getReady is the same as falling
6b1dc7a6 sago007 2010-11-08 21:03 1415
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1416
                }
6b1dc7a6 sago007 2010-11-08 21:03 1417
            }
6b1dc7a6 sago007 2010-11-08 21:03 1418
        }
6b1dc7a6 sago007 2010-11-08 21:03 1419
        //Now looking at rows:
6b1dc7a6 sago007 2010-11-08 21:03 1420
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1421
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1422
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1423
            for (int j=1;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1424
                if ((board[i][j]%30==color)&&(!falling[i][j]))
6b1dc7a6 sago007 2010-11-08 21:03 1425
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1426
                else
6b1dc7a6 sago007 2010-11-08 21:03 1427
                    if (falling[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1428
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1429
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1430
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1431
                        color=board[i][j]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1432
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1433
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1434
                if ((count>2)&&(color>-1)&&(color)<7) {
6b1dc7a6 sago007 2010-11-08 21:03 1435
                    bbomb[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1436
                    bbomb[i][j-1]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1437
                    bbomb[i][j-2]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1438
                }
6b1dc7a6 sago007 2010-11-08 21:03 1439
            }
6b1dc7a6 sago007 2010-11-08 21:03 1440
        }
6b1dc7a6 sago007 2010-11-08 21:03 1441
        //now looking for lines
6b1dc7a6 sago007 2010-11-08 21:03 1442
        for (int i=1;i<13;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1443
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1444
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1445
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1446
                if ((board[j][i]%30==color)&&(!falling[j][i]))
6b1dc7a6 sago007 2010-11-08 21:03 1447
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1448
                else
6b1dc7a6 sago007 2010-11-08 21:03 1449
                    if (falling[j][i]) {
6b1dc7a6 sago007 2010-11-08 21:03 1450
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1451
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1452
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1453
                        color=board[j][i]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1454
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1455
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1456
                if ((count>2)&&(color>-1)&&(color<7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1457
                    bbomb[j][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1458
                    bbomb[j-1][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1459
                    bbomb[j-2][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1460
                }
6b1dc7a6 sago007 2010-11-08 21:03 1461
            }
6b1dc7a6 sago007 2010-11-08 21:03 1462
        }
6b1dc7a6 sago007 2010-11-08 21:03 1463
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1464
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1465
                if ((board[j][i]%10 != -1) && (board[j][i]%30 < 7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1466
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1467
                    if (bbomb[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1468
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1469
                    if (getReady[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1470
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1471
                }
6b1dc7a6 sago007 2010-11-08 21:03 1472
                if (board[j][i]%30>6) {
6b1dc7a6 sago007 2010-11-08 21:03 1473
                    if (board[j][i]%30==7)
6b1dc7a6 sago007 2010-11-08 21:03 1474
                        DrawIMG(garbageR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1475
                    if (board[j][i]%30==9)
6b1dc7a6 sago007 2010-11-08 21:03 1476
                        DrawIMG(garbageML, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1477
                    if (board[j][i]%30==10)
6b1dc7a6 sago007 2010-11-08 21:03 1478
                        DrawIMG(garbageMR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1479
                    if (board[j][i]%30==11)
6b1dc7a6 sago007 2010-11-08 21:03 1480
                        DrawIMG(garbageTR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1481
                    if (board[j][i]%30==12)
6b1dc7a6 sago007 2010-11-08 21:03 1482
                        DrawIMG(garbageTL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1483
                    if (board[j][i]%30==13)
6b1dc7a6 sago007 2010-11-08 21:03 1484
                        DrawIMG(garbageBL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1485
                    if (board[j][i]%30==14)
6b1dc7a6 sago007 2010-11-08 21:03 1486
                        DrawIMG(garbageBR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1487
                    if (board[j][i]%30==15)
6b1dc7a6 sago007 2010-11-08 21:03 1488
                        DrawIMG(garbageM, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1489
                    if (board[j][i]%30==16)
6b1dc7a6 sago007 2010-11-08 21:03 1490
                        DrawIMG(garbageFill, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1491
                    if (board[j][i]%30==17)
6b1dc7a6 sago007 2010-11-08 21:03 1492
                        DrawIMG(garbageT, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1493
                    if (board[j][i]%30==18)
6b1dc7a6 sago007 2010-11-08 21:03 1494
                        DrawIMG(garbageB, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1495
                    if (board[j][i]%30==19)
6b1dc7a6 sago007 2010-11-08 21:03 1496
                        DrawIMG(garbageL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1497
                    if (board[j][i]%30==20)
6b1dc7a6 sago007 2010-11-08 21:03 1498
                        switch(j) {
6b1dc7a6 sago007 2010-11-08 21:03 1499
                            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1500
                                DrawIMG(garbageGML, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1501
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1502
                            case 5:
6b1dc7a6 sago007 2010-11-08 21:03 1503
                                DrawIMG(garbageGMR, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1504
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1505
                            default:
6b1dc7a6 sago007 2010-11-08 21:03 1506
                                DrawIMG(garbageGM, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1507
                        }
6b1dc7a6 sago007 2010-11-08 21:03 1508
                    //cout << "IS: " << board[j][i] << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1509
                }
6b1dc7a6 sago007 2010-11-08 21:03 1510
6b1dc7a6 sago007 2010-11-08 21:03 1511
6b1dc7a6 sago007 2010-11-08 21:03 1512
            }
6b1dc7a6 sago007 2010-11-08 21:03 1513
6b1dc7a6 sago007 2010-11-08 21:03 1514
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1515
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1516
            if ((board[0][i]%30==12)&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1517
                DrawIMG(smiley[0], sBoard, 2*bsize, bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1518
            }
6b1dc7a6 sago007 2010-11-08 21:03 1519
            if (board[0][i]%30!=19) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1520
            {
6b1dc7a6 sago007 2010-11-08 21:03 1521
                garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1522
            }
6b1dc7a6 sago007 2010-11-08 21:03 1523
            else {
6b1dc7a6 sago007 2010-11-08 21:03 1524
                //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1525
                garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1526
            }
6b1dc7a6 sago007 2010-11-08 21:03 1527
6b1dc7a6 sago007 2010-11-08 21:03 1528
        }
6b1dc7a6 sago007 2010-11-08 21:03 1529
    }
6b1dc7a6 sago007 2010-11-08 21:03 1530
public:
6b1dc7a6 sago007 2010-11-08 21:03 1531
    //Draws everything
6b1dc7a6 sago007 2010-11-08 21:03 1532
    void DoPaintJob() {
6b1dc7a6 sago007 2010-11-08 21:03 1533
        DrawIMG(backBoard, sBoard, 0, 0);
925b7e58 sago007 2011-04-25 16:35 1534
        nf_standard_blue_font.setDest(sBoard); //reset to screen at the end of this funciton!
6b1dc7a6 sago007 2010-11-08 21:03 1535
        #if NETWORK
6b1dc7a6 sago007 2010-11-08 21:03 1536
        if ((!bReplaying)&&(!bNetworkPlayer))
6b1dc7a6 sago007 2010-11-08 21:03 1537
        #else
6b1dc7a6 sago007 2010-11-08 21:03 1538
        if (!bReplaying)
6b1dc7a6 sago007 2010-11-08 21:03 1539
        #endif
6b1dc7a6 sago007 2010-11-08 21:03 1540
            PaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1541
        else
6b1dc7a6 sago007 2010-11-08 21:03 1542
            SimplePaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1543
        if (stageClear) DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1);
6b1dc7a6 sago007 2010-11-08 21:03 1544
        if (puzzleMode&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1545
            //We need to write nr. of moves left!
6b1dc7a6 sago007 2010-11-08 21:03 1546
            strHolder = "Moves left: " + itoa(MovesLeft);
925b7e58 sago007 2011-04-25 16:35 1547
            nf_standard_blue_font.draw(5,5,strHolder.c_str());
925b7e58 sago007 2011-04-25 16:35 1548
            
6b1dc7a6 sago007 2010-11-08 21:03 1549
        }
6b1dc7a6 sago007 2010-11-08 21:03 1550
        if(puzzleMode && stageButtonStatus == SBpuzzleMode)
6b1dc7a6 sago007 2010-11-08 21:03 1551
        {
6b1dc7a6 sago007 2010-11-08 21:03 1552
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1553
            if(Level<nrOfPuzzles-1)
6b1dc7a6 sago007 2010-11-08 21:03 1554
            {
6b1dc7a6 sago007 2010-11-08 21:03 1555
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1556
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1557
                else
6b1dc7a6 sago007 2010-11-08 21:03 1558
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1559
            }
6b1dc7a6 sago007 2010-11-08 21:03 1560
            else
6b1dc7a6 sago007 2010-11-08 21:03 1561
            {
6b1dc7a6 sago007 2010-11-08 21:03 1562
                strHolder = "Last puzzle";
925b7e58 sago007 2011-04-25 16:35 1563
                nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1564
            }
6b1dc7a6 sago007 2010-11-08 21:03 1565
        }
6b1dc7a6 sago007 2010-11-08 21:03 1566
        if(stageClear && stageButtonStatus == SBstageClear)
6b1dc7a6 sago007 2010-11-08 21:03 1567
        {
6b1dc7a6 sago007 2010-11-08 21:03 1568
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1569
            if(Level<50-1)
6b1dc7a6 sago007 2010-11-08 21:03 1570
            {
6b1dc7a6 sago007 2010-11-08 21:03 1571
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1572
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1573
                else
6b1dc7a6 sago007 2010-11-08 21:03 1574
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1575
            }
6b1dc7a6 sago007 2010-11-08 21:03 1576
            else
6b1dc7a6 sago007 2010-11-08 21:03 1577
            {
6b1dc7a6 sago007 2010-11-08 21:03 1578
                strHolder = "Last stage";
925b7e58 sago007 2011-04-25 16:35 1579
                nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1580
            }
6b1dc7a6 sago007 2010-11-08 21:03 1581
        }
6b1dc7a6 sago007 2010-11-08 21:03 1582
6b1dc7a6 sago007 2010-11-08 21:03 1583
#if DEBUG
6b1dc7a6 sago007 2010-11-08 21:03 1584
        if (AI_Enabled&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1585
            strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear);
925b7e58 sago007 2011-04-25 16:35 1586
            //NFont_Write(sBoard,   5, 5, strHolder.c_str());
925b7e58 sago007 2011-04-25 16:35 1587
            nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1588
        }
6b1dc7a6 sago007 2010-11-08 21:03 1589
#endif
6b1dc7a6 sago007 2010-11-08 21:03 1590
        if (!bGameOver)DrawIMG(cursor[(ticks/600)%2],sBoard,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
6b1dc7a6 sago007 2010-11-08 21:03 1591
        if (ticks<gameStartedAt)
6b1dc7a6 sago007 2010-11-08 21:03 1592
        {
6b1dc7a6 sago007 2010-11-08 21:03 1593
            int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1594
            if( (currentCounter!=lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1595
                Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1596
            lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1597
            switch (currentCounter) {
6b1dc7a6 sago007 2010-11-08 21:03 1598
            case 2:
6b1dc7a6 sago007 2010-11-08 21:03 1599
                DrawIMG(counter[2], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1600
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1601
            case 1:
6b1dc7a6 sago007 2010-11-08 21:03 1602
                DrawIMG(counter[1], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1603
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1604
            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1605
                DrawIMG(counter[0], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1606
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1607
            default:
6b1dc7a6 sago007 2010-11-08 21:03 1608
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1609
            }
6b1dc7a6 sago007 2010-11-08 21:03 1610
        }
6b1dc7a6 sago007 2010-11-08 21:03 1611
        else
6b1dc7a6 sago007 2010-11-08 21:03 1612
        {
6b1dc7a6 sago007 2010-11-08 21:03 1613
            if(SoundEnabled&&(!NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver))
6b1dc7a6 sago007 2010-11-08 21:03 1614
            {
6b1dc7a6 sago007 2010-11-08 21:03 1615
                int currentCounter = (ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1616
                if(currentCounter!=lastCounter)
6b1dc7a6 sago007 2010-11-08 21:03 1617
                {
6b1dc7a6 sago007 2010-11-08 21:03 1618
                    if(currentCounter>115 && currentCounter<120)
6b1dc7a6 sago007 2010-11-08 21:03 1619
                        Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1620
                }
6b1dc7a6 sago007 2010-11-08 21:03 1621
                lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1622
            }
6b1dc7a6 sago007 2010-11-08 21:03 1623
            else
6b1dc7a6 sago007 2010-11-08 21:03 1624
            {
6b1dc7a6 sago007 2010-11-08 21:03 1625
                if( (0==lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1626
                {
6b1dc7a6 sago007 2010-11-08 21:03 1627
                    Mix_PlayChannel(1,counterFinalChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1628
                }
6b1dc7a6 sago007 2010-11-08 21:03 1629
                lastCounter = -1;
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
        if ((bGameOver)&&(!editorMode))
6b1dc7a6 sago007 2010-11-08 21:03 1634
            if (hasWonTheGame)DrawIMG(iWinner, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1635
            else if (bDraw) DrawIMG(iDraw, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1636
            else
6b1dc7a6 sago007 2010-11-08 21:03 1637
                DrawIMG(iGameOver, sBoard, 0, 5*bsize);
925b7e58 sago007 2011-04-25 16:35 1638
            nf_standard_blue_font.setDest(screen);
6b1dc7a6 sago007 2010-11-08 21:03 1639
    }
6b1dc7a6 sago007 2010-11-08 21:03 1640
6b1dc7a6 sago007 2010-11-08 21:03 1641
6b1dc7a6 sago007 2010-11-08 21:03 1642
    void Update(int newtick) {
6b1dc7a6 sago007 2010-11-08 21:03 1643
        BlockGame::Update(newtick);
6b1dc7a6 sago007 2010-11-08 21:03 1644
        DoPaintJob();
6b1dc7a6 sago007 2010-11-08 21:03 1645
    }
6b1dc7a6 sago007 2010-11-08 21:03 1646
};
6b1dc7a6 sago007 2010-11-08 21:03 1647
6b1dc7a6 sago007 2010-11-08 21:03 1648
6b1dc7a6 sago007 2010-11-08 21:03 1649
6b1dc7a6 sago007 2010-11-08 21:03 1650
89c4a3a6 sago007 2008-08-29 14:32 1651
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
89c4a3a6 sago007 2008-08-29 14:32 1652
void writeScreenShot()
89c4a3a6 sago007 2008-08-29 14:32 1653
{
89c4a3a6 sago007 2008-08-29 14:32 1654
    cout << "Saving screenshot" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1655
    int rightNow = (int)time(NULL);
215ca7b3 sago007 2009-03-06 16:37 1656
/*#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 1657
    char buf[514];
89c4a3a6 sago007 2008-08-29 14:32 1658
    sprintf( buf, "%s/.gamesaves/blockattack/screenshots/screenshot%i.bmp", getenv("HOME"), rightNow );
91886cae sago007 2008-09-12 16:28 1659
#elif defined(__win32__)
89c4a3a6 sago007 2008-08-29 14:32 1660
    char buf[MAX_PATH];
89c4a3a6 sago007 2008-08-29 14:32 1661
    sprintf( buf, "%s\\My Games\\blockattack\\screenshots\\screenshot%i.bmp", (getMyDocumentsPath()).c_str(), rightNow );
91886cae sago007 2008-09-12 16:28 1662
#else
91886cae sago007 2008-09-12 16:28 1663
    char buf[MAX_PATH];
91886cae sago007 2008-09-12 16:28 1664
    sprintf( buf, "screenshot%i.bmp", rightNow );
215ca7b3 sago007 2009-03-06 16:37 1665
#endif*/
215ca7b3 sago007 2009-03-06 16:37 1666
#if defined(__unix__)
215ca7b3 sago007 2009-03-06 16:37 1667
    string buf = (string)getenv("HOME")+"/.gamesaves/blockattack/screenshots/screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1668
#elif defined(__win32__)
215ca7b3 sago007 2009-03-06 16:37 1669
    string buf = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots\\screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1670
#else
215ca7b3 sago007 2009-03-06 16:37 1671
    string buf = "screenshot"+itoa(rightNow)+".bmp";
89c4a3a6 sago007 2008-08-29 14:32 1672
#endif
215ca7b3 sago007 2009-03-06 16:37 1673
    SDL_SaveBMP( screen, buf.c_str() );
89c4a3a6 sago007 2008-08-29 14:32 1674
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 1675
        if (SoundEnabled)Mix_PlayChannel(1,photoClick,0);
89c4a3a6 sago007 2008-08-29 14:32 1676
}
89c4a3a6 sago007 2008-08-29 14:32 1677
89c4a3a6 sago007 2008-08-29 14:32 1678
//Function to return the name of a key, to be displayed...
215ca7b3 sago007 2009-03-06 16:37 1679
string getKeyName(SDLKey key)
89c4a3a6 sago007 2008-08-29 14:32 1680
{
4b0c248f sago007 2010-11-10 21:13 1681
    string keyname(SDL_GetKeyName(key));
215ca7b3 sago007 2009-03-06 16:37 1682
    return keyname;
89c4a3a6 sago007 2008-08-29 14:32 1683
}
89c4a3a6 sago007 2008-08-29 14:32 1684
89c4a3a6 sago007 2008-08-29 14:32 1685
void MakeBackground(int xsize,int ysize,BlockGame &theGame, BlockGame &theGame2);
89c4a3a6 sago007 2008-08-29 14:32 1686
89c4a3a6 sago007 2008-08-29 14:32 1687
int OpenControlsBox(int x, int y, int player)
89c4a3a6 sago007 2008-08-29 14:32 1688
{
89c4a3a6 sago007 2008-08-29 14:32 1689
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 1690
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 1691
    bool done =false;
215ca7b3 sago007 2009-03-06 16:37 1692
    string keyname;
27ae0175 sago007 2009-01-30 06:02 1693
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1694
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 1695
    {
89c4a3a6 sago007 2008-08-29 14:32 1696
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 1697
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1698
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 1699
        if (player == 0)
925b7e58 sago007 2011-04-25 16:35 1700
            NFont_Write(screen, x+40,y+2,"Player 1 keys");
89c4a3a6 sago007 2008-08-29 14:32 1701
        else
925b7e58 sago007 2011-04-25 16:35 1702
            NFont_Write(screen, x+40,y+2,"Player 2 keys");
925b7e58 sago007 2011-04-25 16:35 1703
        NFont_Write(screen, x+6,y+50,"Up");
89c4a3a6 sago007 2008-08-29 14:32 1704
        keyname = getKeyName(keySettings[player].up);
925b7e58 sago007 2011-04-25 16:35 1705
        NFont_Write(screen, x+200,y+50,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1706
        NFont_Write(screen, x+6,y+100,"Down");
89c4a3a6 sago007 2008-08-29 14:32 1707
        keyname = getKeyName(keySettings[player].down);
925b7e58 sago007 2011-04-25 16:35 1708
        NFont_Write(screen, x+200,y+100,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1709
        NFont_Write(screen, x+6,y+150,"Left");
89c4a3a6 sago007 2008-08-29 14:32 1710
        keyname = getKeyName(keySettings[player].left);
925b7e58 sago007 2011-04-25 16:35 1711
        NFont_Write(screen, x+200,y+150,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1712
        NFont_Write(screen, x+6,y+200,"Right");
89c4a3a6 sago007 2008-08-29 14:32 1713
        keyname = getKeyName(keySettings[player].right);
925b7e58 sago007 2011-04-25 16:35 1714
        NFont_Write(screen, x+200,y+200,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1715
        NFont_Write(screen, x+6,y+250,"Push");
89c4a3a6 sago007 2008-08-29 14:32 1716
        keyname = getKeyName(keySettings[player].push);
925b7e58 sago007 2011-04-25 16:35 1717
        NFont_Write(screen, x+200,y+250,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1718
        NFont_Write(screen, x+6,y+300,"Change");
89c4a3a6 sago007 2008-08-29 14:32 1719
        keyname = getKeyName(keySettings[player].change);
925b7e58 sago007 2011-04-25 16:35 1720
        NFont_Write(screen, x+200,y+300,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1721
        //Ask for mouse play
925b7e58 sago007 2011-04-25 16:35 1722
        NFont_Write(screen, x+6,y+350,"Mouse play?");
89c4a3a6 sago007 2008-08-29 14:32 1723
        DrawIMG(iLevelCheckBox,screen,x+220,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1724
        if (((player==0)&&(mouseplay1))||((player==2)&&(mouseplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1725
            DrawIMG(iLevelCheck,screen,x+220,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1726
        //Ask for joypad play
925b7e58 sago007 2011-04-25 16:35 1727
        NFont_Write(screen, x+300,y+350,"Joypad?");
89c4a3a6 sago007 2008-08-29 14:32 1728
        DrawIMG(iLevelCheckBox,screen,x+460,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1729
        if (((player==0)&&(joyplay1))||((player==2)&&(joyplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1730
            DrawIMG(iLevelCheck,screen,x+460,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1731
        for (int i=1; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 1732
            DrawIMG(bChange,screen,x+420,y+50*i);
89c4a3a6 sago007 2008-08-29 14:32 1733
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1734
89c4a3a6 sago007 2008-08-29 14:32 1735
        while (SDL_PollEvent(&event))
89c4a3a6 sago007 2008-08-29 14:32 1736
        {
89c4a3a6 sago007 2008-08-29 14:32 1737
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 1738
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1739
            }
89c4a3a6 sago007 2008-08-29 14:32 1740
89c4a3a6 sago007 2008-08-29 14:32 1741
            if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1742
            {
89c4a3a6 sago007 2008-08-29 14:32 1743
                if (event.key.keysym.sym == SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1744
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1745
            }
89c4a3a6 sago007 2008-08-29 14:32 1746
        }	//PollEvent
89c4a3a6 sago007 2008-08-29 14:32 1747
89c4a3a6 sago007 2008-08-29 14:32 1748
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1749
89c4a3a6 sago007 2008-08-29 14:32 1750
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 1751
89c4a3a6 sago007 2008-08-29 14:32 1752
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 1753
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 1754
        {
89c4a3a6 sago007 2008-08-29 14:32 1755
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 1756
        }
89c4a3a6 sago007 2008-08-29 14:32 1757
89c4a3a6 sago007 2008-08-29 14:32 1758
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 1759
        {
89c4a3a6 sago007 2008-08-29 14:32 1760
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 1761
89c4a3a6 sago007 2008-08-29 14:32 1762
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(50+y)) && (mousey<(90+y)))
89c4a3a6 sago007 2008-08-29 14:32 1763
            {
89c4a3a6 sago007 2008-08-29 14:32 1764
                //up
89c4a3a6 sago007 2008-08-29 14:32 1765
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1766
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1767
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1768
                    {
89c4a3a6 sago007 2008-08-29 14:32 1769
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1770
                        {
89c4a3a6 sago007 2008-08-29 14:32 1771
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1772
                                keySettings[player].up = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1773
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1774
                        }
89c4a3a6 sago007 2008-08-29 14:32 1775
                    }
89c4a3a6 sago007 2008-08-29 14:32 1776
            } //up
89c4a3a6 sago007 2008-08-29 14:32 1777
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(100+y)) && (mousey<(140+y)))
89c4a3a6 sago007 2008-08-29 14:32 1778
            {
89c4a3a6 sago007 2008-08-29 14:32 1779
                //down
89c4a3a6 sago007 2008-08-29 14:32 1780
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1781
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1782
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1783
                    {
89c4a3a6 sago007 2008-08-29 14:32 1784
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1785
                        {
89c4a3a6 sago007 2008-08-29 14:32 1786
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1787
                                keySettings[player].down = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1788
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1789
                        }
89c4a3a6 sago007 2008-08-29 14:32 1790
                    }
89c4a3a6 sago007 2008-08-29 14:32 1791
            } //down
89c4a3a6 sago007 2008-08-29 14:32 1792
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(150+y)) && (mousey<(190+y)))
89c4a3a6 sago007 2008-08-29 14:32 1793
            {
89c4a3a6 sago007 2008-08-29 14:32 1794
                //left
89c4a3a6 sago007 2008-08-29 14:32 1795
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1796
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1797
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1798
                    {
89c4a3a6 sago007 2008-08-29 14:32 1799
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1800
                        {
89c4a3a6 sago007 2008-08-29 14:32 1801
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1802
                                keySettings[player].left = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1803
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1804
                        }
89c4a3a6 sago007 2008-08-29 14:32 1805
                    }
89c4a3a6 sago007 2008-08-29 14:32 1806
            } //left
89c4a3a6 sago007 2008-08-29 14:32 1807
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(200+y)) && (mousey<(240+y)))
89c4a3a6 sago007 2008-08-29 14:32 1808
            {
89c4a3a6 sago007 2008-08-29 14:32 1809
                //right
89c4a3a6 sago007 2008-08-29 14:32 1810
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1811
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1812
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1813
                    {
89c4a3a6 sago007 2008-08-29 14:32 1814
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1815
                        {
89c4a3a6 sago007 2008-08-29 14:32 1816
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1817
                                keySettings[player].right = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1818
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1819
                        }
89c4a3a6 sago007 2008-08-29 14:32 1820
                    }
89c4a3a6 sago007 2008-08-29 14:32 1821
            } //right
89c4a3a6 sago007 2008-08-29 14:32 1822
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(250+y)) && (mousey<(290+y)))
89c4a3a6 sago007 2008-08-29 14:32 1823
            {
89c4a3a6 sago007 2008-08-29 14:32 1824
                //push
89c4a3a6 sago007 2008-08-29 14:32 1825
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1826
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1827
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1828
                    {
89c4a3a6 sago007 2008-08-29 14:32 1829
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1830
                        {
89c4a3a6 sago007 2008-08-29 14:32 1831
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1832
                                keySettings[player].push = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1833
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1834
                        }
89c4a3a6 sago007 2008-08-29 14:32 1835
                    }
89c4a3a6 sago007 2008-08-29 14:32 1836
            } //push
89c4a3a6 sago007 2008-08-29 14:32 1837
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(300+y)) && (mousey<(340+y)))
89c4a3a6 sago007 2008-08-29 14:32 1838
            {
89c4a3a6 sago007 2008-08-29 14:32 1839
                //change
89c4a3a6 sago007 2008-08-29 14:32 1840
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1841
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1842
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1843
                    {
89c4a3a6 sago007 2008-08-29 14:32 1844
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1845
                        {
89c4a3a6 sago007 2008-08-29 14:32 1846
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1847
                                keySettings[player].change = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1848
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1849
                        }
89c4a3a6 sago007 2008-08-29 14:32 1850
                    }
89c4a3a6 sago007 2008-08-29 14:32 1851
            } //change
89c4a3a6 sago007 2008-08-29 14:32 1852
            //mouseplay:
89c4a3a6 sago007 2008-08-29 14:32 1853
            if ((mousex>(220+x)) && (mousex<(262+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1854
            {
89c4a3a6 sago007 2008-08-29 14:32 1855
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1856
                {
89c4a3a6 sago007 2008-08-29 14:32 1857
                    mouseplay1 = !mouseplay1;
89c4a3a6 sago007 2008-08-29 14:32 1858
                }
89c4a3a6 sago007 2008-08-29 14:32 1859
                else
89c4a3a6 sago007 2008-08-29 14:32 1860
                {
89c4a3a6 sago007 2008-08-29 14:32 1861
                    mouseplay2 = !mouseplay2;
89c4a3a6 sago007 2008-08-29 14:32 1862
                }
89c4a3a6 sago007 2008-08-29 14:32 1863
            }
89c4a3a6 sago007 2008-08-29 14:32 1864
            //Joyplay:
89c4a3a6 sago007 2008-08-29 14:32 1865
            if ((mousex>(460+x)) && (mousex<(502+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1866
            {
89c4a3a6 sago007 2008-08-29 14:32 1867
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1868
                {
89c4a3a6 sago007 2008-08-29 14:32 1869
                    joyplay1 = !joyplay1;
89c4a3a6 sago007 2008-08-29 14:32 1870
                }
89c4a3a6 sago007 2008-08-29 14:32 1871
                else
89c4a3a6 sago007 2008-08-29 14:32 1872
                {
89c4a3a6 sago007 2008-08-29 14:32 1873
                    joyplay2 = !joyplay2;
89c4a3a6 sago007 2008-08-29 14:32 1874
                }
89c4a3a6 sago007 2008-08-29 14:32 1875
            }
89c4a3a6 sago007 2008-08-29 14:32 1876
        }	//get mouse state
89c4a3a6 sago007 2008-08-29 14:32 1877
8d488d32 sago007 2011-04-17 13:02 1878
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 1879
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 1880
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 1881
    }	//while !done
89c4a3a6 sago007 2008-08-29 14:32 1882
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1883
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 1884
}
89c4a3a6 sago007 2008-08-29 14:32 1885
89c4a3a6 sago007 2008-08-29 14:32 1886
89c4a3a6 sago007 2008-08-29 14:32 1887
//Dialogbox
89c4a3a6 sago007 2008-08-29 14:32 1888
bool OpenDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 1889
{
89c4a3a6 sago007 2008-08-29 14:32 1890
    bool done = false;     //We are done!
89c4a3a6 sago007 2008-08-29 14:32 1891
    bool accept = false;   //New name is accepted! (not Cancelled)
89c4a3a6 sago007 2008-08-29 14:32 1892
    bool repeating = false; //The key is being held (BACKSPACE)
89c4a3a6 sago007 2008-08-29 14:32 1893
    const int repeatDelay = 200;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 1894
    unsigned long time = 0;
89c4a3a6 sago007 2008-08-29 14:32 1895
    ReadKeyboard rk = ReadKeyboard(name);
89c4a3a6 sago007 2008-08-29 14:32 1896
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 1897
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 1898
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1899
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 1900
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 1901
    {
89c4a3a6 sago007 2008-08-29 14:32 1902
        DrawIMG(dialogBox,screen,x,y);
71181267 sago007 2011-04-29 19:22 1903
        NFont_Write(screen, x+40,y+76,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1904
        strHolder = rk.GetString();
89c4a3a6 sago007 2008-08-29 14:32 1905
        strHolder.erase((int)rk.CharsBeforeCursor());
89c4a3a6 sago007 2008-08-29 14:32 1906
89c4a3a6 sago007 2008-08-29 14:32 1907
        if (((SDL_GetTicks()/600)%2)==1)
71181267 sago007 2011-04-29 19:22 1908
            NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( strHolder.c_str()),y+76,"|");
89c4a3a6 sago007 2008-08-29 14:32 1909
89c4a3a6 sago007 2008-08-29 14:32 1910
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1911
89c4a3a6 sago007 2008-08-29 14:32 1912
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1913
        {
89c4a3a6 sago007 2008-08-29 14:32 1914
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 1915
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1916
                accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1917
            }
89c4a3a6 sago007 2008-08-29 14:32 1918
89c4a3a6 sago007 2008-08-29 14:32 1919
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 1920
            {
89c4a3a6 sago007 2008-08-29 14:32 1921
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
89c4a3a6 sago007 2008-08-29 14:32 1922
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1923
                    accept = true;
89c4a3a6 sago007 2008-08-29 14:32 1924
                }
89c4a3a6 sago007 2008-08-29 14:32 1925
                else
89c4a3a6 sago007 2008-08-29 14:32 1926
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 1927
                        done = true;
89c4a3a6 sago007 2008-08-29 14:32 1928
                        accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1929
                    }
89c4a3a6 sago007 2008-08-29 14:32 1930
                    else if (!(event.key.keysym.sym == SDLK_BACKSPACE)){
89c4a3a6 sago007 2008-08-29 14:32 1931
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1932
                    }
89c4a3a6 sago007 2008-08-29 14:32 1933
                    else if ((event.key.keysym.sym == SDLK_BACKSPACE)&&(!repeating)){
89c4a3a6 sago007 2008-08-29 14:32 1934
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1935
                        repeating = true;
89c4a3a6 sago007 2008-08-29 14:32 1936
                        time=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1937
                    }
89c4a3a6 sago007 2008-08-29 14:32 1938
            }
89c4a3a6 sago007 2008-08-29 14:32 1939
89c4a3a6 sago007 2008-08-29 14:32 1940
        }	//while(event)
89c4a3a6 sago007 2008-08-29 14:32 1941
89c4a3a6 sago007 2008-08-29 14:32 1942
        if (SDL_GetTicks()>(time+repeatDelay))
89c4a3a6 sago007 2008-08-29 14:32 1943
        {
89c4a3a6 sago007 2008-08-29 14:32 1944
            time = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1945
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1946
            if ( (keys[SDLK_BACKSPACE])&&(repeating) )
89c4a3a6 sago007 2008-08-29 14:32 1947
            {
89c4a3a6 sago007 2008-08-29 14:32 1948
                if ((rk.ReadKey(SDLK_BACKSPACE))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1949
            }
89c4a3a6 sago007 2008-08-29 14:32 1950
            else
89c4a3a6 sago007 2008-08-29 14:32 1951
                repeating = false;
89c4a3a6 sago007 2008-08-29 14:32 1952
        }
89c4a3a6 sago007 2008-08-29 14:32 1953
89c4a3a6 sago007 2008-08-29 14:32 1954
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 1955
    }	//while(!done)
89c4a3a6 sago007 2008-08-29 14:32 1956
    strcpy(name,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1957
    bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 1958
    showDialog = false;
89c4a3a6 sago007 2008-08-29 14:32 1959
    return accept;
89c4a3a6 sago007 2008-08-29 14:32 1960
}
89c4a3a6 sago007 2008-08-29 14:32 1961
47529580 sago007 2008-12-09 02:34 1962
//Draws the highscores
47529580 sago007 2008-12-09 02:34 1963
void DrawHighscores(int x, int y, bool endless)
47529580 sago007 2008-12-09 02:34 1964
{
27ae0175 sago007 2009-01-30 06:02 1965
    MakeBackground(xsize,ysize);
47529580 sago007 2008-12-09 02:34 1966
    DrawIMG(background,screen,0,0);
925b7e58 sago007 2011-04-25 16:35 1967
    if (endless) nf_standard_blue_font.draw(x+100,y+100,"Endless:");
925b7e58 sago007 2011-04-25 16:35 1968
    else nf_standard_blue_font.draw(x+100,y+100,"Time Trial:"); 
47529580 sago007 2008-12-09 02:34 1969
    for (int i =0;i<10;i++)
47529580 sago007 2008-12-09 02:34 1970
    {
47529580 sago007 2008-12-09 02:34 1971
        char playerScore[32];
47529580 sago007 2008-12-09 02:34 1972
        char playerName[32];
47529580 sago007 2008-12-09 02:34 1973
        if (endless)
47529580 sago007 2008-12-09 02:34 1974
        {
47529580 sago007 2008-12-09 02:34 1975
            sprintf(playerScore, "%i", theTopScoresEndless.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1976
        }
47529580 sago007 2008-12-09 02:34 1977
        else
47529580 sago007 2008-12-09 02:34 1978
        {
47529580 sago007 2008-12-09 02:34 1979
            sprintf(playerScore, "%i", theTopScoresTimeTrial.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1980
        }
47529580 sago007 2008-12-09 02:34 1981
        if (endless)
47529580 sago007 2008-12-09 02:34 1982
        {
47529580 sago007 2008-12-09 02:34 1983
            strcpy(playerName,theTopScoresEndless.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1984
        }
47529580 sago007 2008-12-09 02:34 1985
        else
47529580 sago007 2008-12-09 02:34 1986
        {
47529580 sago007 2008-12-09 02:34 1987
            strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1988
        }
925b7e58 sago007 2011-04-25 16:35 1989
        nf_standard_blue_font.draw(x+420,y+150+i*35,playerScore);
925b7e58 sago007 2011-04-25 16:35 1990
        nf_standard_blue_font.draw(x+60,y+150+i*35,playerName);
47529580 sago007 2008-12-09 02:34 1991
    }
47529580 sago007 2008-12-09 02:34 1992
}
47529580 sago007 2008-12-09 02:34 1993
47529580 sago007 2008-12-09 02:34 1994
void DrawStats()
81d9c25d sago007 2008-11-24 09:50 1995
{
27ae0175 sago007 2009-01-30 06:02 1996
    MakeBackground(xsize,ysize);
81d9c25d sago007 2008-11-24 09:50 1997
    DrawIMG(background,screen,0,0);
81d9c25d sago007 2008-11-24 09:50 1998
    int y = 5;
81d9c25d sago007 2008-11-24 09:50 1999
    const int y_spacing = 30;
925b7e58 sago007 2011-04-25 16:35 2000
    NFont_Write(screen, 10,y,"Stats");
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,"Chains");
81d9c25d sago007 2008-11-24 09:50 2003
    for(int i=2;i<13;i++)
81d9c25d sago007 2008-11-24 09:50 2004
    {
81d9c25d sago007 2008-11-24 09:50 2005
        y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2006
        NFont_Write(screen, 10,y,(itoa(i)+"X").c_str());
81d9c25d sago007 2008-11-24 09:50 2007
        string numberAsString = itoa(Stats::getInstance()->getNumberOf("chainX"+itoa(i)));
925b7e58 sago007 2011-04-25 16:35 2008
        NFont_Write(screen, 300,y,numberAsString.c_str());
81d9c25d sago007 2008-11-24 09:50 2009
    }
81d9c25d sago007 2008-11-24 09:50 2010
    y+=y_spacing*2;
925b7e58 sago007 2011-04-25 16:35 2011
    NFont_Write(screen, 10,y,"Lines Pushed: ");
81d9c25d sago007 2008-11-24 09:50 2012
    string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed"));
925b7e58 sago007 2011-04-25 16:35 2013
    NFont_Write(screen, 300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 2014
81d9c25d sago007 2008-11-24 09:50 2015
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2016
    NFont_Write(screen, 10,y,"Puzzles solved: ");
81d9c25d sago007 2008-11-24 09:50 2017
    numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved"));
925b7e58 sago007 2011-04-25 16:35 2018
    NFont_Write(screen, 300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 2019
d07b805e sago007 2009-01-27 13:15 2020
    y+=y_spacing*2;
925b7e58 sago007 2011-04-25 16:35 2021
    NFont_Write(screen, 10,y,"Run time: ");
cd12e0fe sago007 2009-01-29 08:47 2022
    commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
d07b805e sago007 2009-01-27 13:15 2023
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2024
    NFont_Write(screen, 10,y,((string)("Days: "+itoa(ct.days))).c_str());
d07b805e sago007 2009-01-27 13:15 2025
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2026
    NFont_Write(screen, 10,y,((string)("Hours: "+itoa(ct.hours))).c_str());
d07b805e sago007 2009-01-27 13:15 2027
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2028
    NFont_Write(screen, 10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
d07b805e sago007 2009-01-27 13:15 2029
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2030
    NFont_Write(screen, 10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
d07b805e sago007 2009-01-27 13:15 2031
cd12e0fe sago007 2009-01-29 08:47 2032
    y-=y_spacing*4; //Four rows back
27ae0175 sago007 2009-01-30 06:02 2033
    const int x_offset3 = xsize/3+10; //Ofset for three rows
925b7e58 sago007 2011-04-25 16:35 2034
    NFont_Write(screen, x_offset3,y,"Play time: ");
cd12e0fe sago007 2009-01-29 08:47 2035
    ct = TimeHandler::getTime("playTime");
cd12e0fe sago007 2009-01-29 08:47 2036
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2037
    NFont_Write(screen, x_offset3,y,((string)("Days: "+itoa(ct.days))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2038
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2039
    NFont_Write(screen, x_offset3,y,((string)("Hours: "+itoa(ct.hours))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2040
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2041
    NFont_Write(screen, x_offset3,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2042
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 2043
    NFont_Write(screen, x_offset3,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2044
27ae0175 sago007 2009-01-30 06:02 2045
    const int x_offset = xsize/2+10;
81d9c25d sago007 2008-11-24 09:50 2046
    y = 5+y_spacing*2;
925b7e58 sago007 2011-04-25 16:35 2047
    NFont_Write(screen, x_offset,y,"VS CPU (win/loss)");
81d9c25d sago007 2008-11-24 09:50 2048
    for(int i=0;i<7;i++)
81d9c25d sago007 2008-11-24 09:50 2049
    {
81d9c25d sago007 2008-11-24 09:50 2050
        y += y_spacing;
925b7e58 sago007 2011-04-25 16:35 2051
        NFont_Write(screen, x_offset,y,("AI "+itoa(i+1)).c_str());
81d9c25d sago007 2008-11-24 09:50 2052
        numberAsString = itoa(Stats::getInstance()->getNumberOf("defeatedAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2053
        string numberAsString2 = itoa(Stats::getInstance()->getNumberOf("defeatedByAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2054
        string toPrint = numberAsString + "/" + numberAsString2;
925b7e58 sago007 2011-04-25 16:35 2055
        NFont_Write(screen, x_offset+230,y,toPrint.c_str());
81d9c25d sago007 2008-11-24 09:50 2056
    }
47529580 sago007 2008-12-09 02:34 2057
}
47529580 sago007 2008-12-09 02:34 2058
47529580 sago007 2008-12-09 02:34 2059
void OpenScoresDisplay()
47529580 sago007 2008-12-09 02:34 2060
{
9050a50a sago007 2008-12-09 13:35 2061
    int mousex,mousey;
47529580 sago007 2008-12-09 02:34 2062
    bool done = false;     //We are done!
47529580 sago007 2008-12-09 02:34 2063
    int page = 0;
47529580 sago007 2008-12-09 02:34 2064
    const int numberOfPages = 3;
7ca669ac sago007 2008-12-09 16:30 2065
    //button coodinates:
7ca669ac sago007 2008-12-09 16:30 2066
    const int scoreX = buttonXsize*2;
7ca669ac sago007 2008-12-09 16:30 2067
    const int scoreY = 0;
7ca669ac sago007 2008-12-09 16:30 2068
    const int backX = 20;
7ca669ac sago007 2008-12-09 16:30 2069
    const int backY = ysize-buttonYsize-20;
7ca669ac sago007 2008-12-09 16:30 2070
    const int nextX = xsize-buttonXsize-20;
7ca669ac sago007 2008-12-09 16:30 2071
    const int nextY = backY;
81d9c25d sago007 2008-11-24 09:50 2072
    while (!done)
81d9c25d sago007 2008-11-24 09:50 2073
    {
47529580 sago007 2008-12-09 02:34 2074
        switch(page)
47529580 sago007 2008-12-09 02:34 2075
        {
47529580 sago007 2008-12-09 02:34 2076
            case 0:
47529580 sago007 2008-12-09 02:34 2077
                //Highscores, endless
47529580 sago007 2008-12-09 02:34 2078
                DrawHighscores(100,100,true);
47529580 sago007 2008-12-09 02:34 2079
                break;
47529580 sago007 2008-12-09 02:34 2080
            case 1:
47529580 sago007 2008-12-09 02:34 2081
                //Highscores, Time Trial
47529580 sago007 2008-12-09 02:34 2082
                DrawHighscores(100,100,false);
47529580 sago007 2008-12-09 02:34 2083
                break;
47529580 sago007 2008-12-09 02:34 2084
            case 2:
47529580 sago007 2008-12-09 02:34 2085
            default:
47529580 sago007 2008-12-09 02:34 2086
                DrawStats();
47529580 sago007 2008-12-09 02:34 2087
        };
47529580 sago007 2008-12-09 02:34 2088
7ca669ac sago007 2008-12-09 16:30 2089
        //Draw buttons:
7ca669ac sago007 2008-12-09 16:30 2090
        DrawIMG(bHighScore,screen,scoreX,scoreY);
7ca669ac sago007 2008-12-09 16:30 2091
        DrawIMG(bBack,screen,backX,backY);
7ca669ac sago007 2008-12-09 16:30 2092
        DrawIMG(bNext,screen,nextX,nextY);
7ca669ac sago007 2008-12-09 16:30 2093
7ca669ac sago007 2008-12-09 16:30 2094
        //Draw page number
7ca669ac sago007 2008-12-09 16:30 2095
        string pageXofY = ((string)"Page ")+itoa(page+1)+((string)" of ")+itoa(numberOfPages);
925b7e58 sago007 2011-04-25 16:35 2096
        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 2097
        
81d9c25d sago007 2008-11-24 09:50 2098
        SDL_Delay(10);
81d9c25d sago007 2008-11-24 09:50 2099
        SDL_Event event;
9050a50a sago007 2008-12-09 13:35 2100
9050a50a sago007 2008-12-09 13:35 2101
        SDL_GetMouseState(&mousex,&mousey);
81d9c25d sago007 2008-11-24 09:50 2102
        
81d9c25d sago007 2008-11-24 09:50 2103
        while ( SDL_PollEvent(&event) )
81d9c25d sago007 2008-11-24 09:50 2104
        {
9050a50a sago007 2008-12-09 13:35 2105
9050a50a sago007 2008-12-09 13:35 2106
81d9c25d sago007 2008-11-24 09:50 2107
            if ( event.type == SDL_QUIT )  {
81d9c25d sago007 2008-11-24 09:50 2108
                done = true;
81d9c25d sago007 2008-11-24 09:50 2109
            }
81d9c25d sago007 2008-11-24 09:50 2110
81d9c25d sago007 2008-11-24 09:50 2111
            if ( event.type == SDL_KEYDOWN )
81d9c25d sago007 2008-11-24 09:50 2112
            {
47529580 sago007 2008-12-09 02:34 2113
                if( (event.key.keysym.sym == SDLK_RIGHT))
47529580 sago007 2008-12-09 02:34 2114
                {
47529580 sago007 2008-12-09 02:34 2115
                    page++;
47529580 sago007 2008-12-09 02:34 2116
                    if(page>=numberOfPages)
47529580 sago007 2008-12-09 02:34 2117
                        page = 0;
47529580 sago007 2008-12-09 02:34 2118
                }
7ca669ac sago007 2008-12-09 16:30 2119
                else
47529580 sago007 2008-12-09 02:34 2120
                if( (event.key.keysym.sym == SDLK_LEFT))
47529580 sago007 2008-12-09 02:34 2121
                {
47529580 sago007 2008-12-09 02:34 2122
                    page--;
47529580 sago007 2008-12-09 02:34 2123
                    if(page<0)
47529580 sago007 2008-12-09 02:34 2124
                        page = numberOfPages-1;
47529580 sago007 2008-12-09 02:34 2125
                }
7ca669ac sago007 2008-12-09 16:30 2126
                else
7ca669ac sago007 2008-12-09 16:30 2127
                    done = true;
fcd5a134 sago007 2008-12-19 01:11 2128
                
fcd5a134 sago007 2008-12-19 01:11 2129
                if ( event.key.keysym.sym == SDLK_F9 ) {
fcd5a134 sago007 2008-12-19 01:11 2130
                    writeScreenShot();
fcd5a134 sago007 2008-12-19 01:11 2131
                }
47529580 sago007 2008-12-09 02:34 2132
81d9c25d sago007 2008-11-24 09:50 2133
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
81d9c25d sago007 2008-11-24 09:50 2134
                    done = true;
81d9c25d sago007 2008-11-24 09:50 2135
                }
81d9c25d sago007 2008-11-24 09:50 2136
                else
81d9c25d sago007 2008-11-24 09:50 2137
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
81d9c25d sago007 2008-11-24 09:50 2138
                        done = true;
81d9c25d sago007 2008-11-24 09:50 2139
                    }
81d9c25d sago007 2008-11-24 09:50 2140
            }
81d9c25d sago007 2008-11-24 09:50 2141
81d9c25d sago007 2008-11-24 09:50 2142
        }	//while(event)
7ca669ac sago007 2008-12-09 16:30 2143
7ca669ac sago007 2008-12-09 16:30 2144
        // If the mouse button is released, make bMouseUp equal true
7ca669ac sago007 2008-12-09 16:30 2145
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
7ca669ac sago007 2008-12-09 16:30 2146
        {
7ca669ac sago007 2008-12-09 16:30 2147
            bMouseUp=true;
7ca669ac sago007 2008-12-09 16:30 2148
        }
7ca669ac sago007 2008-12-09 16:30 2149
7ca669ac sago007 2008-12-09 16:30 2150
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
7ca669ac sago007 2008-12-09 16:30 2151
        {
7ca669ac sago007 2008-12-09 16:30 2152
            bMouseUp = false;
7ca669ac sago007 2008-12-09 16:30 2153
7ca669ac sago007 2008-12-09 16:30 2154
            //The Score button:
7ca669ac sago007 2008-12-09 16:30 2155
            if((mousex>scoreX) && (mousex<scoreX+buttonXsize) && (mousey>scoreY) && (mousey<scoreY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2156
                done =true;
7ca669ac sago007 2008-12-09 16:30 2157
7ca669ac sago007 2008-12-09 16:30 2158
            //The back button:
7ca669ac sago007 2008-12-09 16:30 2159
            if((mousex>backX) && (mousex<backX+buttonXsize) && (mousey>backY) && (mousey<backY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2160
            {
7ca669ac sago007 2008-12-09 16:30 2161
                page--;
7ca669ac sago007 2008-12-09 16:30 2162
                if(page<0)
7ca669ac sago007 2008-12-09 16:30 2163
                    page = numberOfPages-1;
7ca669ac sago007 2008-12-09 16:30 2164
            }
7ca669ac sago007 2008-12-09 16:30 2165
7ca669ac sago007 2008-12-09 16:30 2166
            //The next button:
7ca669ac sago007 2008-12-09 16:30 2167
            if((mousex>nextX) && (mousex<nextX+buttonXsize) && (mousey>nextY) && (mousey<nextY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2168
            {
7ca669ac sago007 2008-12-09 16:30 2169
                page++;
7ca669ac sago007 2008-12-09 16:30 2170
                if(page>=numberOfPages)
7ca669ac sago007 2008-12-09 16:30 2171
                    page = 0;
7ca669ac sago007 2008-12-09 16:30 2172
            }
7ca669ac sago007 2008-12-09 16:30 2173
        }
7ca669ac sago007 2008-12-09 16:30 2174
8d488d32 sago007 2011-04-17 13:02 2175
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2176
        mouse.PaintTo(screen,mousex,mousey);
9050a50a sago007 2008-12-09 13:35 2177
        SDL_Flip(screen); //Update screen
81d9c25d sago007 2008-11-24 09:50 2178
    }
6b1dc7a6 sago007 2010-11-08 21:03 2179
6b1dc7a6 sago007 2010-11-08 21:03 2180
81d9c25d sago007 2008-11-24 09:50 2181
}
81d9c25d sago007 2008-11-24 09:50 2182
89c4a3a6 sago007 2008-08-29 14:32 2183
89c4a3a6 sago007 2008-08-29 14:32 2184
//Open a puzzle file
89c4a3a6 sago007 2008-08-29 14:32 2185
bool OpenFileDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2186
{
89c4a3a6 sago007 2008-08-29 14:32 2187
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2188
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2189
    ListFiles lf = ListFiles();
aca2f4b0 sago007 2009-05-10 18:11 2190
    string folder = (string)SHAREDIR+(string)"/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2191
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2192
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2193
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2194
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2195
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2196
#endif
89c4a3a6 sago007 2008-08-29 14:32 2197
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2198
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2199
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2200
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2201
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2202
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2203
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2204
    {
89c4a3a6 sago007 2008-08-29 14:32 2205
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2206
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2207
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2208
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2209
        {
925b7e58 sago007 2011-04-25 16:35 2210
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2211
        }
89c4a3a6 sago007 2008-08-29 14:32 2212
89c4a3a6 sago007 2008-08-29 14:32 2213
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2214
89c4a3a6 sago007 2008-08-29 14:32 2215
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2216
        {
89c4a3a6 sago007 2008-08-29 14:32 2217
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2218
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2219
            }
89c4a3a6 sago007 2008-08-29 14:32 2220
89c4a3a6 sago007 2008-08-29 14:32 2221
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2222
            {
89c4a3a6 sago007 2008-08-29 14:32 2223
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2224
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2225
                }
89c4a3a6 sago007 2008-08-29 14:32 2226
89c4a3a6 sago007 2008-08-29 14:32 2227
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2228
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2229
                }
89c4a3a6 sago007 2008-08-29 14:32 2230
89c4a3a6 sago007 2008-08-29 14:32 2231
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2232
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2233
                }
89c4a3a6 sago007 2008-08-29 14:32 2234
            }
89c4a3a6 sago007 2008-08-29 14:32 2235
89c4a3a6 sago007 2008-08-29 14:32 2236
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2237
89c4a3a6 sago007 2008-08-29 14:32 2238
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2239
89c4a3a6 sago007 2008-08-29 14:32 2240
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2241
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2242
        {
89c4a3a6 sago007 2008-08-29 14:32 2243
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2244
        }
89c4a3a6 sago007 2008-08-29 14:32 2245
89c4a3a6 sago007 2008-08-29 14:32 2246
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2247
        {
89c4a3a6 sago007 2008-08-29 14:32 2248
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2249
89c4a3a6 sago007 2008-08-29 14:32 2250
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2251
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2252
            {
89c4a3a6 sago007 2008-08-29 14:32 2253
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2254
            }
89c4a3a6 sago007 2008-08-29 14:32 2255
89c4a3a6 sago007 2008-08-29 14:32 2256
            //The back button:
9050a50a sago007 2008-12-09 13:35 2257
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2258
            {
89c4a3a6 sago007 2008-08-29 14:32 2259
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2260
            }
89c4a3a6 sago007 2008-08-29 14:32 2261
89c4a3a6 sago007 2008-08-29 14:32 2262
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2263
            {
89c4a3a6 sago007 2008-08-29 14:32 2264
                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 2265
                {
89c4a3a6 sago007 2008-08-29 14:32 2266
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2267
                    {
89c4a3a6 sago007 2008-08-29 14:32 2268
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2269
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2270
                    }
89c4a3a6 sago007 2008-08-29 14:32 2271
                }
89c4a3a6 sago007 2008-08-29 14:32 2272
            }
89c4a3a6 sago007 2008-08-29 14:32 2273
        }
89c4a3a6 sago007 2008-08-29 14:32 2274
8d488d32 sago007 2011-04-17 13:02 2275
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2276
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2277
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2278
    }
89c4a3a6 sago007 2008-08-29 14:32 2279
}
89c4a3a6 sago007 2008-08-29 14:32 2280
89c4a3a6 sago007 2008-08-29 14:32 2281
//Slelect a theme
89c4a3a6 sago007 2008-08-29 14:32 2282
bool SelectThemeDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2283
{
89c4a3a6 sago007 2008-08-29 14:32 2284
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2285
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2286
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2287
    string folder = (string)SHAREDIR+(string)"/themes";
89c4a3a6 sago007 2008-08-29 14:32 2288
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2289
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2290
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2291
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/themes";
89c4a3a6 sago007 2008-08-29 14:32 2292
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2293
#endif
89c4a3a6 sago007 2008-08-29 14:32 2294
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2295
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2296
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2297
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2298
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2299
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2300
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2301
    {
89c4a3a6 sago007 2008-08-29 14:32 2302
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2303
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2304
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2305
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2306
        {
925b7e58 sago007 2011-04-25 16:35 2307
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2308
        }
89c4a3a6 sago007 2008-08-29 14:32 2309
89c4a3a6 sago007 2008-08-29 14:32 2310
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2311
89c4a3a6 sago007 2008-08-29 14:32 2312
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2313
        {
89c4a3a6 sago007 2008-08-29 14:32 2314
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2315
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2316
            }
89c4a3a6 sago007 2008-08-29 14:32 2317
89c4a3a6 sago007 2008-08-29 14:32 2318
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2319
            {
89c4a3a6 sago007 2008-08-29 14:32 2320
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2321
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2322
                }
89c4a3a6 sago007 2008-08-29 14:32 2323
89c4a3a6 sago007 2008-08-29 14:32 2324
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2325
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2326
                }
89c4a3a6 sago007 2008-08-29 14:32 2327
89c4a3a6 sago007 2008-08-29 14:32 2328
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2329
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2330
                }
89c4a3a6 sago007 2008-08-29 14:32 2331
            }
89c4a3a6 sago007 2008-08-29 14:32 2332
89c4a3a6 sago007 2008-08-29 14:32 2333
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2334
89c4a3a6 sago007 2008-08-29 14:32 2335
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2336
89c4a3a6 sago007 2008-08-29 14:32 2337
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2338
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2339
        {
89c4a3a6 sago007 2008-08-29 14:32 2340
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2341
        }
89c4a3a6 sago007 2008-08-29 14:32 2342
89c4a3a6 sago007 2008-08-29 14:32 2343
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2344
        {
89c4a3a6 sago007 2008-08-29 14:32 2345
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2346
89c4a3a6 sago007 2008-08-29 14:32 2347
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2348
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2349
            {
89c4a3a6 sago007 2008-08-29 14:32 2350
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2351
            }
89c4a3a6 sago007 2008-08-29 14:32 2352
89c4a3a6 sago007 2008-08-29 14:32 2353
            //The back button:
9050a50a sago007 2008-12-09 13:35 2354
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2355
            {
89c4a3a6 sago007 2008-08-29 14:32 2356
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2357
            }
89c4a3a6 sago007 2008-08-29 14:32 2358
89c4a3a6 sago007 2008-08-29 14:32 2359
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2360
            {
89c4a3a6 sago007 2008-08-29 14:32 2361
                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 2362
                {
89c4a3a6 sago007 2008-08-29 14:32 2363
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2364
                    {
89c4a3a6 sago007 2008-08-29 14:32 2365
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2366
                        loadTheme(lf.getFileName(i));
89c4a3a6 sago007 2008-08-29 14:32 2367
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2368
                    }
89c4a3a6 sago007 2008-08-29 14:32 2369
                }
89c4a3a6 sago007 2008-08-29 14:32 2370
            }
89c4a3a6 sago007 2008-08-29 14:32 2371
        }
89c4a3a6 sago007 2008-08-29 14:32 2372
8d488d32 sago007 2011-04-17 13:02 2373
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2374
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2375
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2376
    }
89c4a3a6 sago007 2008-08-29 14:32 2377
}
89c4a3a6 sago007 2008-08-29 14:32 2378
89c4a3a6 sago007 2008-08-29 14:32 2379
//Open a saved replay
89c4a3a6 sago007 2008-08-29 14:32 2380
bool OpenReplayDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2381
{
89c4a3a6 sago007 2008-08-29 14:32 2382
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2383
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2384
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2385
    cout << "Ready to set directory!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2386
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2387
    string directory = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2388
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 2389
    string directory = getMyDocumentsPath()+(string)"/My Games/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2390
#else
89c4a3a6 sago007 2008-08-29 14:32 2391
    string directory = "./replays";
89c4a3a6 sago007 2008-08-29 14:32 2392
#endif
89c4a3a6 sago007 2008-08-29 14:32 2393
    lf.setDirectory(directory);
89c4a3a6 sago007 2008-08-29 14:32 2394
    cout << "Directory sat" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2395
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2396
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2397
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2398
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2399
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2400
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2401
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2402
    {
89c4a3a6 sago007 2008-08-29 14:32 2403
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2404
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2405
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2406
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2407
        {
925b7e58 sago007 2011-04-25 16:35 2408
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2409
        }
89c4a3a6 sago007 2008-08-29 14:32 2410
89c4a3a6 sago007 2008-08-29 14:32 2411
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2412
89c4a3a6 sago007 2008-08-29 14:32 2413
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2414
        {
89c4a3a6 sago007 2008-08-29 14:32 2415
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2416
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2417
                return false;
89c4a3a6 sago007 2008-08-29 14:32 2418
            }
89c4a3a6 sago007 2008-08-29 14:32 2419
89c4a3a6 sago007 2008-08-29 14:32 2420
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2421
            {
89c4a3a6 sago007 2008-08-29 14:32 2422
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2423
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2424
                    return false;
89c4a3a6 sago007 2008-08-29 14:32 2425
                }
89c4a3a6 sago007 2008-08-29 14:32 2426
89c4a3a6 sago007 2008-08-29 14:32 2427
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2428
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2429
                }
89c4a3a6 sago007 2008-08-29 14:32 2430
89c4a3a6 sago007 2008-08-29 14:32 2431
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2432
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2433
                }
89c4a3a6 sago007 2008-08-29 14:32 2434
            }
89c4a3a6 sago007 2008-08-29 14:32 2435
89c4a3a6 sago007 2008-08-29 14:32 2436
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2437
89c4a3a6 sago007 2008-08-29 14:32 2438
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2439
89c4a3a6 sago007 2008-08-29 14:32 2440
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2441
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2442
        {
89c4a3a6 sago007 2008-08-29 14:32 2443
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2444
        }
89c4a3a6 sago007 2008-08-29 14:32 2445
89c4a3a6 sago007 2008-08-29 14:32 2446
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2447
        {
89c4a3a6 sago007 2008-08-29 14:32 2448
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2449
89c4a3a6 sago007 2008-08-29 14:32 2450
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2451
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2452
            {
89c4a3a6 sago007 2008-08-29 14:32 2453
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2454
            }
89c4a3a6 sago007 2008-08-29 14:32 2455
89c4a3a6 sago007 2008-08-29 14:32 2456
            //The back button:
9050a50a sago007 2008-12-09 13:35 2457
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2458
            {
89c4a3a6 sago007 2008-08-29 14:32 2459
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2460
            }
89c4a3a6 sago007 2008-08-29 14:32 2461
89c4a3a6 sago007 2008-08-29 14:32 2462
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2463
            {
89c4a3a6 sago007 2008-08-29 14:32 2464
                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 2465
                {
89c4a3a6 sago007 2008-08-29 14:32 2466
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2467
                    {
89c4a3a6 sago007 2008-08-29 14:32 2468
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2469
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2470
                        return true;
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
        }
89c4a3a6 sago007 2008-08-29 14:32 2475
8d488d32 sago007 2011-04-17 13:02 2476
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2477
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2478
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2479
    }
89c4a3a6 sago007 2008-08-29 14:32 2480
}
89c4a3a6 sago007 2008-08-29 14:32 2481
89c4a3a6 sago007 2008-08-29 14:32 2482
89c4a3a6 sago007 2008-08-29 14:32 2483
//draws options:
e1290bdf sago007 2010-10-25 19:56 2484
void DrawOptions(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 2485
{
9050a50a sago007 2008-12-09 13:35 2486
    if (MusicEnabled) DrawIMG(bOn,optionsBack,400,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2487
    else DrawIMG(bOff,optionsBack,400,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2488
    if (SoundEnabled) DrawIMG(bOn,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2489
    else DrawIMG(bOff,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2490
    if (bFullscreen) DrawIMG(bOn,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2491
    else DrawIMG(bOff,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2492
    DrawIMG(bChange,optionsBack,230,435);
89c4a3a6 sago007 2008-08-29 14:32 2493
    DrawIMG(bChange,optionsBack,410,435);
89c4a3a6 sago007 2008-08-29 14:32 2494
    DrawIMG(bChange,optionsBack,230,500);
89c4a3a6 sago007 2008-08-29 14:32 2495
    DrawIMG(bChange,optionsBack,410,500);
89c4a3a6 sago007 2008-08-29 14:32 2496
    DrawIMG(optionsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2497
}  //drawOptions
89c4a3a6 sago007 2008-08-29 14:32 2498
89c4a3a6 sago007 2008-08-29 14:32 2499
//Draws the balls and explosions
4b0c248f sago007 2010-11-10 21:13 2500
static void DrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2501
{
89c4a3a6 sago007 2008-08-29 14:32 2502
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2503
    {
89c4a3a6 sago007 2008-08-29 14:32 2504
        if (theBallManeger.ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2505
        {
89c4a3a6 sago007 2008-08-29 14:32 2506
            DrawIMG(balls[theBallManeger.ballArray[i].getColor()],screen,theBallManeger.ballArray[i].getX(),theBallManeger.ballArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2507
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2508
        if (theExplosionManeger.explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2509
        {
89c4a3a6 sago007 2008-08-29 14:32 2510
            DrawIMG(explosion[theExplosionManeger.explosionArray[i].getFrame()],screen,theExplosionManeger.explosionArray[i].getX(),theExplosionManeger.explosionArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2511
        }
89c4a3a6 sago007 2008-08-29 14:32 2512
        if (theTextManeger.textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2513
        {
89c4a3a6 sago007 2008-08-29 14:32 2514
            //cout << "Printing text: " << theTextManeger.textArray[i].getText() << endl;
925b7e58 sago007 2011-04-25 16:35 2515
            int x = theTextManeger.textArray[i].getX()-12;
925b7e58 sago007 2011-04-25 16:35 2516
            int y = theTextManeger.textArray[i].getY()-12;
89c4a3a6 sago007 2008-08-29 14:32 2517
            DrawIMG(iChainBack,screen,x,y);
925b7e58 sago007 2011-04-25 16:35 2518
            nf_standard_small_font.drawCenter(x+12,y+7,theTextManeger.textArray[i].getText());
89c4a3a6 sago007 2008-08-29 14:32 2519
        }
89c4a3a6 sago007 2008-08-29 14:32 2520
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2521
}    //DrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2522
89c4a3a6 sago007 2008-08-29 14:32 2523
//Removes the old balls
89c4a3a6 sago007 2008-08-29 14:32 2524
void UndrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2525
{
89c4a3a6 sago007 2008-08-29 14:32 2526
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2527
    {
89c4a3a6 sago007 2008-08-29 14:32 2528
        if (theBallManeger.oldBallUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2529
        {
89c4a3a6 sago007 2008-08-29 14:32 2530
            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 2531
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2532
        if (theExplosionManeger.oldExplosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2533
        {
89c4a3a6 sago007 2008-08-29 14:32 2534
            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 2535
        }
89c4a3a6 sago007 2008-08-29 14:32 2536
        if (theTextManeger.oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2537
        {
925b7e58 sago007 2011-04-25 16:35 2538
            int x = theTextManeger.oldTextArray[i].getX()-12;
925b7e58 sago007 2011-04-25 16:35 2539
            int y = theTextManeger.oldTextArray[i].getY()-12;
89c4a3a6 sago007 2008-08-29 14:32 2540
            DrawIMG(background,screen,x,y,25,25,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2541
        }
89c4a3a6 sago007 2008-08-29 14:32 2542
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2543
}   //UndrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2544
89c4a3a6 sago007 2008-08-29 14:32 2545
//draws everything
6b1dc7a6 sago007 2010-11-08 21:03 2546
void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2547
{
89c4a3a6 sago007 2008-08-29 14:32 2548
    SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 2549
    //draw background:
89c4a3a6 sago007 2008-08-29 14:32 2550
    if (forceredraw != 1)
89c4a3a6 sago007 2008-08-29 14:32 2551
    {
89c4a3a6 sago007 2008-08-29 14:32 2552
89c4a3a6 sago007 2008-08-29 14:32 2553
        UndrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2554
        DrawIMG(background,screen,oldMousex,oldMousey,32,32,oldMousex,oldMousey);
89c4a3a6 sago007 2008-08-29 14:32 2555
        DrawIMG(background,screen,oldBubleX,oldBubleY,140,50,oldBubleX,oldBubleY);
89c4a3a6 sago007 2008-08-29 14:32 2556
89c4a3a6 sago007 2008-08-29 14:32 2557
89c4a3a6 sago007 2008-08-29 14:32 2558
        DrawIMG(background,screen,350,200,120,200,350,200);
89c4a3a6 sago007 2008-08-29 14:32 2559
        DrawIMG(background,screen,830,200,120,200,830,200);
89c4a3a6 sago007 2008-08-29 14:32 2560
        DrawIMG(background,screen,800,0,140,50,800,0);
89c4a3a6 sago007 2008-08-29 14:32 2561
89c4a3a6 sago007 2008-08-29 14:32 2562
        DrawIMG(background,screen,50,60,300,50,50,60);
89c4a3a6 sago007 2008-08-29 14:32 2563
        DrawIMG(background,screen,510,60,300,50,510,60);
89c4a3a6 sago007 2008-08-29 14:32 2564
    }
89c4a3a6 sago007 2008-08-29 14:32 2565
    else
89c4a3a6 sago007 2008-08-29 14:32 2566
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2567
    //draw bottons (should be moves and drawn directly to background once)
89c4a3a6 sago007 2008-08-29 14:32 2568
    if (!editorMode)
2f30c381 sago007 2008-09-14 13:08 2569
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2570
        if (!networkActive) //We don't show the menu while running server or connected to a server
2f30c381 sago007 2008-09-14 13:08 2571
        #else
2f30c381 sago007 2008-09-14 13:08 2572
            if(true)
2f30c381 sago007 2008-09-14 13:08 2573
        #endif
89c4a3a6 sago007 2008-08-29 14:32 2574
        {
89c4a3a6 sago007 2008-08-29 14:32 2575
            //Here we draw the menu
43611709 sago007 2011-04-23 17:18 2576
            bNewGame.PaintTo(screen,0,0);
9050a50a sago007 2008-12-09 13:35 2577
            DrawIMG(bOptions, screen, buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2578
            DrawIMG(bHighScore, screen, 2*buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2579
            DrawIMG(bReplay,screen,3*buttonXsize,0);
89c4a3a6 sago007 2008-08-29 14:32 2580
        }
89c4a3a6 sago007 2008-08-29 14:32 2581
        else
89c4a3a6 sago007 2008-08-29 14:32 2582
        { //If network is active
89c4a3a6 sago007 2008-08-29 14:32 2583
            DrawIMG(bBack, screen, 0, 0); //Display a disconnect button
89c4a3a6 sago007 2008-08-29 14:32 2584
        }
89c4a3a6 sago007 2008-08-29 14:32 2585
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2586
        DrawIMG(bExit, screen, xsize-120,ysize-120);
e1290bdf sago007 2010-10-25 19:56 2587
    //DrawIMG(boardBackBack,screen,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2588
    DrawIMG(theGame->sBoard,screen,theGame->GetTopX(),theGame->GetTopY());
89c4a3a6 sago007 2008-08-29 14:32 2589
    string strHolder;
e1290bdf sago007 2010-10-25 19:56 2590
    strHolder = itoa(theGame->GetScore()+theGame->GetHandicap());
925b7e58 sago007 2011-04-25 16:35 2591
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2592
    if (theGame->GetAIenabled())
71181267 sago007 2011-04-29 19:22 2593
        NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2594
    else
89c4a3a6 sago007 2008-08-29 14:32 2595
        if (editorMode)
71181267 sago007 2011-04-29 19:22 2596
            NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,"Playing field");
89c4a3a6 sago007 2008-08-29 14:32 2597
        else
89c4a3a6 sago007 2008-08-29 14:32 2598
            if (!singlePuzzle)
71181267 sago007 2011-04-29 19:22 2599
                NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name);
e1290bdf sago007 2010-10-25 19:56 2600
    if (theGame->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2601
    {
e1290bdf sago007 2010-10-25 19:56 2602
        int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2603
        int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2604
        int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2605
        if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2606
        {
e1290bdf sago007 2010-10-25 19:56 2607
            minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2608
            seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2609
        }
89c4a3a6 sago007 2008-08-29 14:32 2610
        else
89c4a3a6 sago007 2008-08-29 14:32 2611
        {
e1290bdf sago007 2010-10-25 19:56 2612
            minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2613
            seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2614
        }
e1290bdf sago007 2010-10-25 19:56 2615
        if (theGame->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2616
        if (theGame->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2617
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2618
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2619
        else strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2620
        //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 2621
        NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2622
    }
89c4a3a6 sago007 2008-08-29 14:32 2623
    else
89c4a3a6 sago007 2008-08-29 14:32 2624
    {
e1290bdf sago007 2010-10-25 19:56 2625
        int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2626
        int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2627
        if (theGame->isGameOver()) minutes=(theGame->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2628
        if (theGame->isGameOver()) seconds=(theGame->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2629
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2630
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2631
        else
89c4a3a6 sago007 2008-08-29 14:32 2632
            strHolder = itoa(minutes)+":0"+itoa(seconds);
925b7e58 sago007 2011-04-25 16:35 2633
        NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2634
    }
e1290bdf sago007 2010-10-25 19:56 2635
    strHolder = itoa(theGame->GetChains());
925b7e58 sago007 2011-04-25 16:35 2636
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2637
    //drawspeedLevel:
e1290bdf sago007 2010-10-25 19:56 2638
    strHolder = itoa(theGame->GetSpeedLevel());
925b7e58 sago007 2011-04-25 16:35 2639
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2640
    if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY()))
89c4a3a6 sago007 2008-08-29 14:32 2641
    {
e1290bdf sago007 2010-10-25 19:56 2642
        oldBubleX = theGame->GetTopX()+280;
e1290bdf sago007 2010-10-25 19:56 2643
        oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1;
e1290bdf sago007 2010-10-25 19:56 2644
        DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
89c4a3a6 sago007 2008-08-29 14:32 2645
    }
89c4a3a6 sago007 2008-08-29 14:32 2646
    //player1 finnish, player2 start
e1290bdf sago007 2010-10-25 19:56 2647
    //DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2648
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2649
    {
f72abf8b sago007 2010-01-16 20:00 2650
        /*
f72abf8b sago007 2010-01-16 20:00 2651
         *If single player mode (and not VS)
f72abf8b sago007 2010-01-16 20:00 2652
         */
e1290bdf sago007 2010-10-25 19:56 2653
        if(!twoPlayers && !theGame->isGameOver())
e2de69cf sago007 2010-01-15 22:48 2654
        {
f72abf8b sago007 2010-01-16 20:00 2655
            //Blank player2's board:
e1290bdf sago007 2010-10-25 19:56 2656
            DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
f72abf8b sago007 2010-01-16 20:00 2657
            //Write a description:
e1290bdf sago007 2010-10-25 19:56 2658
            if(theGame->isTimeTrial())
f72abf8b sago007 2010-01-16 20:00 2659
            {
925b7e58 sago007 2011-04-25 16:35 2660
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial");
925b7e58 sago007 2011-04-25 16:35 2661
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2662
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much");
925b7e58 sago007 2011-04-25 16:35 2663
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "as possible in");
925b7e58 sago007 2011-04-25 16:35 2664
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"2 minutes");
e1290bdf sago007 2010-10-25 19:56 2665
            } else if(theGame->isStageClear())
f72abf8b sago007 2010-01-16 20:00 2666
            {
925b7e58 sago007 2011-04-25 16:35 2667
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear");
925b7e58 sago007 2011-04-25 16:35 2668
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2669
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "You must clear a");
925b7e58 sago007 2011-04-25 16:35 2670
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "number of lines.");
925b7e58 sago007 2011-04-25 16:35 2671
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"Speed is rapidly");
925b7e58 sago007 2011-04-25 16:35 2672
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"increased.");
e1290bdf sago007 2010-10-25 19:56 2673
            } else if(theGame->isPuzzleMode())
f72abf8b sago007 2010-01-16 20:00 2674
            {
925b7e58 sago007 2011-04-25 16:35 2675
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle");
925b7e58 sago007 2011-04-25 16:35 2676
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2677
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Clear the entire");
925b7e58 sago007 2011-04-25 16:35 2678
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "board with a");
925b7e58 sago007 2011-04-25 16:35 2679
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limited number of");
925b7e58 sago007 2011-04-25 16:35 2680
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"moves.");
f72abf8b sago007 2010-01-16 20:00 2681
            } else
f72abf8b sago007 2010-01-16 20:00 2682
            {
925b7e58 sago007 2011-04-25 16:35 2683
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless");
925b7e58 sago007 2011-04-25 16:35 2684
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2685
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much as");
925b7e58 sago007 2011-04-25 16:35 2686
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "possible. No time");
925b7e58 sago007 2011-04-25 16:35 2687
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limit.");
f72abf8b sago007 2010-01-16 20:00 2688
            }
f72abf8b sago007 2010-01-16 20:00 2689
f72abf8b sago007 2010-01-16 20:00 2690
            //Write the keys that are in use
e1290bdf sago007 2010-10-25 19:56 2691
            int y = theGame2->GetTopY()+400;
925b7e58 sago007 2011-04-25 16:35 2692
            NFont_Write(screen, theGame2->GetTopX()+7,y,"Movement keys:" );
925b7e58 sago007 2011-04-25 16:35 2693
            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 2694
            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 2695
            NFont_Write(screen, theGame2->GetTopX()+7,y+120,("Switch: "+getKeyName(keySettings[0].change) ).c_str() );
e1290bdf sago007 2010-10-25 19:56 2696
            if(theGame->isPuzzleMode())
925b7e58 sago007 2011-04-25 16:35 2697
                NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Restart: "+getKeyName(keySettings[0].push) ).c_str() );
f72abf8b sago007 2010-01-16 20:00 2698
            else
925b7e58 sago007 2011-04-25 16:35 2699
                NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Push line: "+getKeyName(keySettings[0].push) ).c_str() );
e2de69cf sago007 2010-01-15 22:48 2700
        }
e2de69cf sago007 2010-01-15 22:48 2701
        else
e1290bdf sago007 2010-10-25 19:56 2702
            DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
e1290bdf sago007 2010-10-25 19:56 2703
        strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap());
925b7e58 sago007 2011-04-25 16:35 2704
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2705
        if (theGame2->GetAIenabled())
71181267 sago007 2011-04-29 19:22 2706
            NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2707
        else
71181267 sago007 2011-04-29 19:22 2708
            NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name);
e1290bdf sago007 2010-10-25 19:56 2709
        if (theGame2->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2710
        {
e1290bdf sago007 2010-10-25 19:56 2711
            int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2712
            int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2713
            int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2714
            if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2715
            {
e1290bdf sago007 2010-10-25 19:56 2716
                minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2717
                seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2718
            }
89c4a3a6 sago007 2008-08-29 14:32 2719
            else
89c4a3a6 sago007 2008-08-29 14:32 2720
            {
e1290bdf sago007 2010-10-25 19:56 2721
                minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2722
                seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2723
            }
e1290bdf sago007 2010-10-25 19:56 2724
            if (theGame2->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2725
            if (theGame2->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2726
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2727
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2728
            else
89c4a3a6 sago007 2008-08-29 14:32 2729
                strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2730
            //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 2731
            NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2732
        }
89c4a3a6 sago007 2008-08-29 14:32 2733
        else
89c4a3a6 sago007 2008-08-29 14:32 2734
        {
e1290bdf sago007 2010-10-25 19:56 2735
            int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2736
            int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2737
            if (theGame2->isGameOver()) minutes=(theGame2->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2738
            if (theGame2->isGameOver()) seconds=(theGame2->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2739
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2740
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2741
            else
89c4a3a6 sago007 2008-08-29 14:32 2742
                strHolder = itoa(minutes)+":0"+itoa(seconds);
925b7e58 sago007 2011-04-25 16:35 2743
            NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2744
        }
e1290bdf sago007 2010-10-25 19:56 2745
        strHolder = itoa(theGame2->GetChains());
925b7e58 sago007 2011-04-25 16:35 2746
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2747
        strHolder = itoa(theGame2->GetSpeedLevel());
925b7e58 sago007 2011-04-25 16:35 2748
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2749
    }
89c4a3a6 sago007 2008-08-29 14:32 2750
    //player2 finnish
89c4a3a6 sago007 2008-08-29 14:32 2751
89c4a3a6 sago007 2008-08-29 14:32 2752
    if (bNewGameOpen)
89c4a3a6 sago007 2008-08-29 14:32 2753
    {
89c4a3a6 sago007 2008-08-29 14:32 2754
        DrawIMG(b1player,screen,0,40);
89c4a3a6 sago007 2008-08-29 14:32 2755
        DrawIMG(b2players,screen,0,80);
1572de2b sago007 2008-09-11 18:15 2756
#if NETWORK
9050a50a sago007 2008-12-09 13:35 2757
        DrawIMG(bNetwork,screen,0,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2758
#endif
89c4a3a6 sago007 2008-08-29 14:32 2759
        if (b1playerOpen)
89c4a3a6 sago007 2008-08-29 14:32 2760
        {
9050a50a sago007 2008-12-09 13:35 2761
            DrawIMG(bEndless,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2762
            DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2763
            DrawIMG(bStageClear,screen,buttonXsize,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2764
            DrawIMG(bPuzzle,screen,buttonXsize,160);
9050a50a sago007 2008-12-09 13:35 2765
            DrawIMG(bVsMode,screen,buttonXsize,200);
89c4a3a6 sago007 2008-08-29 14:32 2766
        }
89c4a3a6 sago007 2008-08-29 14:32 2767
        else
89c4a3a6 sago007 2008-08-29 14:32 2768
            if (b2playersOpen)
89c4a3a6 sago007 2008-08-29 14:32 2769
            {
9050a50a sago007 2008-12-09 13:35 2770
                DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2771
                DrawIMG(bVsMode,screen,buttonXsize,120);
89c4a3a6 sago007 2008-08-29 14:32 2772
            }
1572de2b sago007 2008-09-11 18:15 2773
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2774
            else
89c4a3a6 sago007 2008-08-29 14:32 2775
                if (bNetworkOpen)
89c4a3a6 sago007 2008-08-29 14:32 2776
                {
9050a50a sago007 2008-12-09 13:35 2777
                    DrawIMG(bHost,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2778
                    DrawIMG(bConnect,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2779
                }
89c4a3a6 sago007 2008-08-29 14:32 2780
#endif
89c4a3a6 sago007 2008-08-29 14:32 2781
    }
89c4a3a6 sago007 2008-08-29 14:32 2782
    if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 2783
    {
9050a50a sago007 2008-12-09 13:35 2784
        DrawIMG(bConfigure,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2785
        DrawIMG(bSelectPuzzle,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2786
        DrawIMG(bVsModeConfig,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2787
        DrawIMG(bTheme,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2788
    }
89c4a3a6 sago007 2008-08-29 14:32 2789
    if (bReplayOpen)
89c4a3a6 sago007 2008-08-29 14:32 2790
    {
89c4a3a6 sago007 2008-08-29 14:32 2791
        DrawIMG(bSave,screen,360,40);
89c4a3a6 sago007 2008-08-29 14:32 2792
        DrawIMG(bLoad,screen,360,80);
89c4a3a6 sago007 2008-08-29 14:32 2793
    }
89c4a3a6 sago007 2008-08-29 14:32 2794
    if (showOptions) DrawOptions(100,100);
89c4a3a6 sago007 2008-08-29 14:32 2795
89c4a3a6 sago007 2008-08-29 14:32 2796
    DrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2797
1572de2b sago007 2008-09-11 18:15 2798
#if DEBUG
89c4a3a6 sago007 2008-08-29 14:32 2799
    Frames++;
89c4a3a6 sago007 2008-08-29 14:32 2800
    if (SDL_GetTicks() >= Ticks + 1000)
89c4a3a6 sago007 2008-08-29 14:32 2801
    {
89c4a3a6 sago007 2008-08-29 14:32 2802
        if (Frames > 999) Frames=999;
78d03b38 sago007 2008-11-13 19:56 2803
        sprintf(FPS, "%lu fps", Frames);
89c4a3a6 sago007 2008-08-29 14:32 2804
        Frames = 0;
89c4a3a6 sago007 2008-08-29 14:32 2805
        Ticks = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2806
    }
89c4a3a6 sago007 2008-08-29 14:32 2807
925b7e58 sago007 2011-04-25 16:35 2808
    //NFont_Write(screen, 800,4,FPS);
925b7e58 sago007 2011-04-25 16:35 2809
    nf_standard_blue_font.draw(800,4,FPS);
89c4a3a6 sago007 2008-08-29 14:32 2810
#endif
89c4a3a6 sago007 2008-08-29 14:32 2811
89c4a3a6 sago007 2008-08-29 14:32 2812
    //SDL_Flip(screen); Update screen is now called outside DrawEvrything, bacause the mouse needs to be painted
89c4a3a6 sago007 2008-08-29 14:32 2813
89c4a3a6 sago007 2008-08-29 14:32 2814
}
89c4a3a6 sago007 2008-08-29 14:32 2815
89c4a3a6 sago007 2008-08-29 14:32 2816
//Generates the standard background
4b0c248f sago007 2010-11-10 21:13 2817
static void MakeBackground(int xsize,int ysize)
89c4a3a6 sago007 2008-08-29 14:32 2818
{
27ae0175 sago007 2009-01-30 06:02 2819
    int w = backgroundImage->w;
27ae0175 sago007 2009-01-30 06:02 2820
    int h = backgroundImage->h;
27ae0175 sago007 2009-01-30 06:02 2821
    for(int i=0;i*w<xsize;i++)
27ae0175 sago007 2009-01-30 06:02 2822
        for(int j=0;j*h<ysize;j++)
27ae0175 sago007 2009-01-30 06:02 2823
            DrawIMG(backgroundImage,background,i*w,j*h);
89c4a3a6 sago007 2008-08-29 14:32 2824
    standardBackground = true;
89c4a3a6 sago007 2008-08-29 14:32 2825
}
89c4a3a6 sago007 2008-08-29 14:32 2826
89c4a3a6 sago007 2008-08-29 14:32 2827
//Generates the background with red board backs
4b0c248f sago007 2010-11-10 21:13 2828
static void MakeBackground(int xsize,int ysize,BlockGame *theGame, BlockGame *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2829
{
27ae0175 sago007 2009-01-30 06:02 2830
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2831
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2832
    DrawIMG(boardBackBack,background,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2833
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2834
}
89c4a3a6 sago007 2008-08-29 14:32 2835
4b0c248f sago007 2010-11-10 21:13 2836
static void MakeBackground(int xsize, int ysize, BlockGame *theGame)
89c4a3a6 sago007 2008-08-29 14:32 2837
{
27ae0175 sago007 2009-01-30 06:02 2838
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2839
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2840
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2841
}
89c4a3a6 sago007 2008-08-29 14:32 2842
89c4a3a6 sago007 2008-08-29 14:32 2843
89c4a3a6 sago007 2008-08-29 14:32 2844
//The function that allows the player to choose PuzzleLevel
89c4a3a6 sago007 2008-08-29 14:32 2845
int PuzzleLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2846
{
89c4a3a6 sago007 2008-08-29 14:32 2847
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2848
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2849
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2850
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2851
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2852
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2853
89c4a3a6 sago007 2008-08-29 14:32 2854
    //Loads the levels, if they havn't been loaded:
89c4a3a6 sago007 2008-08-29 14:32 2855
    LoadPuzzleStages();
89c4a3a6 sago007 2008-08-29 14:32 2856
89c4a3a6 sago007 2008-08-29 14:32 2857
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2858
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2859
89c4a3a6 sago007 2008-08-29 14:32 2860
    ifstream puzzleFile(puzzleSavePath.c_str(),ios::binary);
27ae0175 sago007 2009-01-30 06:02 2861
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2862
    if (puzzleFile)
89c4a3a6 sago007 2008-08-29 14:32 2863
    {
89c4a3a6 sago007 2008-08-29 14:32 2864
        for (int i=0;(i<nrOfPuzzles)&&(!puzzleFile.eof()); i++)
89c4a3a6 sago007 2008-08-29 14:32 2865
        {
89c4a3a6 sago007 2008-08-29 14:32 2866
            puzzleFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2867
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2868
        }
89c4a3a6 sago007 2008-08-29 14:32 2869
        puzzleFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2870
    }
89c4a3a6 sago007 2008-08-29 14:32 2871
    else
89c4a3a6 sago007 2008-08-29 14:32 2872
    {
89c4a3a6 sago007 2008-08-29 14:32 2873
        tempBool = false;
89c4a3a6 sago007 2008-08-29 14:32 2874
        for (int i=0; i<nrOfPuzzles; i++)
89c4a3a6 sago007 2008-08-29 14:32 2875
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2876
    }
89c4a3a6 sago007 2008-08-29 14:32 2877
89c4a3a6 sago007 2008-08-29 14:32 2878
    do
89c4a3a6 sago007 2008-08-29 14:32 2879
    {
89c4a3a6 sago007 2008-08-29 14:32 2880
        nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2881
89c4a3a6 sago007 2008-08-29 14:32 2882
89c4a3a6 sago007 2008-08-29 14:32 2883
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2884
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 2885
        NFont_Write(screen, xplace+12,yplace+2,"Select Puzzle");
89c4a3a6 sago007 2008-08-29 14:32 2886
        //Now drow the fields you click in (and a V if clicked):
89c4a3a6 sago007 2008-08-29 14:32 2887
        for (int i = 0; i < nrOfPuzzles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2888
        {
89c4a3a6 sago007 2008-08-29 14:32 2889
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2890
            if (puzzleCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2891
        }
89c4a3a6 sago007 2008-08-29 14:32 2892
89c4a3a6 sago007 2008-08-29 14:32 2893
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2894
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2895
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2896
            {
89c4a3a6 sago007 2008-08-29 14:32 2897
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 2898
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 2899
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2900
                }
89c4a3a6 sago007 2008-08-29 14:32 2901
            }
89c4a3a6 sago007 2008-08-29 14:32 2902
89c4a3a6 sago007 2008-08-29 14:32 2903
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2904
89c4a3a6 sago007 2008-08-29 14:32 2905
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2906
89c4a3a6 sago007 2008-08-29 14:32 2907
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2908
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2909
        {
89c4a3a6 sago007 2008-08-29 14:32 2910
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2911
        }
89c4a3a6 sago007 2008-08-29 14:32 2912
89c4a3a6 sago007 2008-08-29 14:32 2913
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2914
        {
89c4a3a6 sago007 2008-08-29 14:32 2915
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2916
89c4a3a6 sago007 2008-08-29 14:32 2917
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 2918
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2919
            for (i = 0; (i<nrOfPuzzles/10)||((i<nrOfPuzzles/10+1)&&(nrOfPuzzles%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2920
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2921
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2922
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2923
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 2924
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2925
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2926
                    {
89c4a3a6 sago007 2008-08-29 14:32 2927
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 2928
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2929
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 2930
                    }
89c4a3a6 sago007 2008-08-29 14:32 2931
        }
89c4a3a6 sago007 2008-08-29 14:32 2932
8d488d32 sago007 2011-04-17 13:02 2933
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2934
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2935
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 2936
89c4a3a6 sago007 2008-08-29 14:32 2937
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 2938
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2939
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 2940
}
89c4a3a6 sago007 2008-08-29 14:32 2941
89c4a3a6 sago007 2008-08-29 14:32 2942
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 2943
int StageLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2944
{
89c4a3a6 sago007 2008-08-29 14:32 2945
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2946
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2947
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2948
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2949
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2950
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2951
    Uint32 tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2952
    Uint32 totalScore = 0;
89c4a3a6 sago007 2008-08-29 14:32 2953
    Uint32 totalTime = 0;
89c4a3a6 sago007 2008-08-29 14:32 2954
89c4a3a6 sago007 2008-08-29 14:32 2955
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2956
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2957
27ae0175 sago007 2009-01-30 06:02 2958
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2959
    ifstream stageFile(stageClearSavePath.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 2960
    if (stageFile)
89c4a3a6 sago007 2008-08-29 14:32 2961
    {
89c4a3a6 sago007 2008-08-29 14:32 2962
        for (int i = 0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2963
        {
89c4a3a6 sago007 2008-08-29 14:32 2964
            stageFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2965
            stageCleared[i]=tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2966
        }
89c4a3a6 sago007 2008-08-29 14:32 2967
        if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2968
        {
89c4a3a6 sago007 2008-08-29 14:32 2969
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2970
            {
89c4a3a6 sago007 2008-08-29 14:32 2971
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2972
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2973
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2974
                stageScores[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2975
                totalScore+=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2976
            }
89c4a3a6 sago007 2008-08-29 14:32 2977
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2978
            {
89c4a3a6 sago007 2008-08-29 14:32 2979
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2980
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2981
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2982
                stageTimes[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2983
                totalTime += tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2984
            }
89c4a3a6 sago007 2008-08-29 14:32 2985
        }
89c4a3a6 sago007 2008-08-29 14:32 2986
        else
89c4a3a6 sago007 2008-08-29 14:32 2987
        {
89c4a3a6 sago007 2008-08-29 14:32 2988
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2989
            {
89c4a3a6 sago007 2008-08-29 14:32 2990
                 stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2991
                 stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2992
            }
89c4a3a6 sago007 2008-08-29 14:32 2993
        }
89c4a3a6 sago007 2008-08-29 14:32 2994
        stageFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2995
    }
89c4a3a6 sago007 2008-08-29 14:32 2996
    else
89c4a3a6 sago007 2008-08-29 14:32 2997
    {
89c4a3a6 sago007 2008-08-29 14:32 2998
        for (int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2999
        {
89c4a3a6 sago007 2008-08-29 14:32 3000
            stageCleared[i]= false;
89c4a3a6 sago007 2008-08-29 14:32 3001
            stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3002
            stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3003
        }
89c4a3a6 sago007 2008-08-29 14:32 3004
    }
89c4a3a6 sago007 2008-08-29 14:32 3005
89c4a3a6 sago007 2008-08-29 14:32 3006
89c4a3a6 sago007 2008-08-29 14:32 3007
    do
89c4a3a6 sago007 2008-08-29 14:32 3008
    {
89c4a3a6 sago007 2008-08-29 14:32 3009
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3010
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3011
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 3012
        NFont_Write(screen, xplace+12,yplace+2,"Stage Clear Level Select");
89c4a3a6 sago007 2008-08-29 14:32 3013
        for (int i = 0; i < nrOfStageLevels;i++)
89c4a3a6 sago007 2008-08-29 14:32 3014
        {
89c4a3a6 sago007 2008-08-29 14:32 3015
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 3016
            if (stageCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 3017
        }
89c4a3a6 sago007 2008-08-29 14:32 3018
89c4a3a6 sago007 2008-08-29 14:32 3019
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3020
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3021
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3022
            {
89c4a3a6 sago007 2008-08-29 14:32 3023
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3024
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 3025
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 3026
                }
89c4a3a6 sago007 2008-08-29 14:32 3027
            }
89c4a3a6 sago007 2008-08-29 14:32 3028
89c4a3a6 sago007 2008-08-29 14:32 3029
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3030
89c4a3a6 sago007 2008-08-29 14:32 3031
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3032
89c4a3a6 sago007 2008-08-29 14:32 3033
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3034
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3035
        {
89c4a3a6 sago007 2008-08-29 14:32 3036
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3037
        }
89c4a3a6 sago007 2008-08-29 14:32 3038
89c4a3a6 sago007 2008-08-29 14:32 3039
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3040
        {
89c4a3a6 sago007 2008-08-29 14:32 3041
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3042
89c4a3a6 sago007 2008-08-29 14:32 3043
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 3044
            int i;
89c4a3a6 sago007 2008-08-29 14:32 3045
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 3046
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 3047
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 3048
            i++;
89c4a3a6 sago007 2008-08-29 14:32 3049
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 3050
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 3051
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 3052
                    {
89c4a3a6 sago007 2008-08-29 14:32 3053
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 3054
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 3055
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 3056
                    }
89c4a3a6 sago007 2008-08-29 14:32 3057
        }
89c4a3a6 sago007 2008-08-29 14:32 3058
        //Find what we are over:
89c4a3a6 sago007 2008-08-29 14:32 3059
            int overLevel = -1;
89c4a3a6 sago007 2008-08-29 14:32 3060
            int i;
89c4a3a6 sago007 2008-08-29 14:32 3061
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 3062
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 3063
                    overLevel = i*10;
89c4a3a6 sago007 2008-08-29 14:32 3064
            i++;
89c4a3a6 sago007 2008-08-29 14:32 3065
            if (overLevel != -1)
89c4a3a6 sago007 2008-08-29 14:32 3066
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 3067
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 3068
                    {
89c4a3a6 sago007 2008-08-29 14:32 3069
                        overLevel +=j;
89c4a3a6 sago007 2008-08-29 14:32 3070
                        string scoreString = "Best score: 0";
89c4a3a6 sago007 2008-08-29 14:32 3071
                        string timeString = "Time used: -- : --";
89c4a3a6 sago007 2008-08-29 14:32 3072
                        
89c4a3a6 sago007 2008-08-29 14:32 3073
                        if(stageScores.at(overLevel)>0)
89c4a3a6 sago007 2008-08-29 14:32 3074
                            scoreString = "Best score: "+itoa(stageScores[overLevel]);
89c4a3a6 sago007 2008-08-29 14:32 3075
                        if(stageTimes[overLevel]>0)
89c4a3a6 sago007 2008-08-29 14:32 3076
                            timeString = "Time used: "+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60);
89c4a3a6 sago007 2008-08-29 14:32 3077
                        
925b7e58 sago007 2011-04-25 16:35 3078
                        NFont_Write(screen, 200,200,scoreString.c_str());
925b7e58 sago007 2011-04-25 16:35 3079
                        NFont_Write(screen, 200,250,timeString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3080
                        
89c4a3a6 sago007 2008-08-29 14:32 3081
                        overLevel;
89c4a3a6 sago007 2008-08-29 14:32 3082
                    }
89c4a3a6 sago007 2008-08-29 14:32 3083
            string totalString = "Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60);
925b7e58 sago007 2011-04-25 16:35 3084
            NFont_Write(screen, 200,600,totalString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3085
8d488d32 sago007 2011-04-17 13:02 3086
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3087
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3088
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3089
89c4a3a6 sago007 2008-08-29 14:32 3090
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 3091
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3092
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 3093
}
89c4a3a6 sago007 2008-08-29 14:32 3094
89c4a3a6 sago007 2008-08-29 14:32 3095
//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 3096
int startSingleVs()
89c4a3a6 sago007 2008-08-29 14:32 3097
{
89c4a3a6 sago007 2008-08-29 14:32 3098
    //Where to place the windows
89c4a3a6 sago007 2008-08-29 14:32 3099
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3100
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3101
    Uint8 *keys;	//To take keyboard input
89c4a3a6 sago007 2008-08-29 14:32 3102
    int mousex, mousey;	//To allow mouse
89c4a3a6 sago007 2008-08-29 14:32 3103
    bool done = false;	//When are we done?
89c4a3a6 sago007 2008-08-29 14:32 3104
27ae0175 sago007 2009-01-30 06:02 3105
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3106
    DrawIMG(changeButtonsBack,background,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 3107
    NFont_Write(background, xplace+10,yplace+10,"1 : Very Easy");
925b7e58 sago007 2011-04-25 16:35 3108
    NFont_Write(background, xplace+10,yplace+40,"2 : Easy");
925b7e58 sago007 2011-04-25 16:35 3109
    NFont_Write(background, xplace+10,yplace+70,"3 : Below Normal");
925b7e58 sago007 2011-04-25 16:35 3110
    NFont_Write(background, xplace+10,yplace+100,"4 : Normal");
925b7e58 sago007 2011-04-25 16:35 3111
    NFont_Write(background, xplace+10,yplace+130,"5 : Above Normal");
925b7e58 sago007 2011-04-25 16:35 3112
    NFont_Write(background, xplace+10,yplace+160,"6 : Hard");
925b7e58 sago007 2011-04-25 16:35 3113
    NFont_Write(background, xplace+10,yplace+190,"7 : Hardest");
89c4a3a6 sago007 2008-08-29 14:32 3114
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3115
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3116
    do
89c4a3a6 sago007 2008-08-29 14:32 3117
    {
89c4a3a6 sago007 2008-08-29 14:32 3118
89c4a3a6 sago007 2008-08-29 14:32 3119
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3120
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3121
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3122
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3123
            {
4f1d27f1 sago007 2011-03-18 15:53 3124
                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 3125
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3126
                }
4f1d27f1 sago007 2011-03-18 15:53 3127
                if ( event.key.keysym.sym == SDLK_1 || event.key.keysym.sym == SDLK_KP1 ) {
89c4a3a6 sago007 2008-08-29 14:32 3128
                    return 0;
89c4a3a6 sago007 2008-08-29 14:32 3129
                }
4f1d27f1 sago007 2011-03-18 15:53 3130
                if ( event.key.keysym.sym == SDLK_2 || event.key.keysym.sym == SDLK_KP2 ) {
89c4a3a6 sago007 2008-08-29 14:32 3131
                    return 1;
89c4a3a6 sago007 2008-08-29 14:32 3132
                }
4f1d27f1 sago007 2011-03-18 15:53 3133
                if ( event.key.keysym.sym == SDLK_3 || event.key.keysym.sym == SDLK_KP3 ) {
89c4a3a6 sago007 2008-08-29 14:32 3134
                    return 2;
89c4a3a6 sago007 2008-08-29 14:32 3135
                }
4f1d27f1 sago007 2011-03-18 15:53 3136
                if ( event.key.keysym.sym == SDLK_4 || event.key.keysym.sym == SDLK_KP4 ) {
89c4a3a6 sago007 2008-08-29 14:32 3137
                    return 3;
89c4a3a6 sago007 2008-08-29 14:32 3138
                }
4f1d27f1 sago007 2011-03-18 15:53 3139
                if ( event.key.keysym.sym == SDLK_5 || event.key.keysym.sym == SDLK_KP5 ) {
89c4a3a6 sago007 2008-08-29 14:32 3140
                    return 4;
89c4a3a6 sago007 2008-08-29 14:32 3141
                }
4f1d27f1 sago007 2011-03-18 15:53 3142
                if ( event.key.keysym.sym == SDLK_6 || event.key.keysym.sym == SDLK_KP6 ) {
89c4a3a6 sago007 2008-08-29 14:32 3143
                    return 5;
89c4a3a6 sago007 2008-08-29 14:32 3144
                }
4f1d27f1 sago007 2011-03-18 15:53 3145
                if ( event.key.keysym.sym == SDLK_7 || event.key.keysym.sym == SDLK_KP7 ) {
89c4a3a6 sago007 2008-08-29 14:32 3146
                    return 6;
89c4a3a6 sago007 2008-08-29 14:32 3147
                }
89c4a3a6 sago007 2008-08-29 14:32 3148
            }
89c4a3a6 sago007 2008-08-29 14:32 3149
89c4a3a6 sago007 2008-08-29 14:32 3150
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3151
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3152
        {
89c4a3a6 sago007 2008-08-29 14:32 3153
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3154
        }
89c4a3a6 sago007 2008-08-29 14:32 3155
89c4a3a6 sago007 2008-08-29 14:32 3156
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3157
        {
89c4a3a6 sago007 2008-08-29 14:32 3158
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3159
89c4a3a6 sago007 2008-08-29 14:32 3160
            for (int i=0; i<7;i++)
89c4a3a6 sago007 2008-08-29 14:32 3161
            {
89c4a3a6 sago007 2008-08-29 14:32 3162
                if ((mousex>xplace+10)&&(mousex<xplace+410)&&(mousey>yplace+10+i*30)&&(mousey<yplace+38+i*30))
89c4a3a6 sago007 2008-08-29 14:32 3163
                    return i;
89c4a3a6 sago007 2008-08-29 14:32 3164
            }
89c4a3a6 sago007 2008-08-29 14:32 3165
        }
89c4a3a6 sago007 2008-08-29 14:32 3166
89c4a3a6 sago007 2008-08-29 14:32 3167
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3168
        DrawIMG(background, screen, 0, 0);
8d488d32 sago007 2011-04-17 13:02 3169
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3170
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3171
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3172
    }while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3173
89c4a3a6 sago007 2008-08-29 14:32 3174
89c4a3a6 sago007 2008-08-29 14:32 3175
    return 3; //Returns normal
89c4a3a6 sago007 2008-08-29 14:32 3176
}
89c4a3a6 sago007 2008-08-29 14:32 3177
89c4a3a6 sago007 2008-08-29 14:32 3178
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 3179
void startVsMenu()
89c4a3a6 sago007 2008-08-29 14:32 3180
{
89c4a3a6 sago007 2008-08-29 14:32 3181
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3182
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3183
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3184
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 3185
    bool done = false;
89c4a3a6 sago007 2008-08-29 14:32 3186
89c4a3a6 sago007 2008-08-29 14:32 3187
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3188
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3189
27ae0175 sago007 2009-01-30 06:02 3190
    MakeBackground(xsize,ysize);
925b7e58 sago007 2011-04-25 16:35 3191
    NFont_Write(background, 360,650,"Press ESC to accept");
27ae0175 sago007 2009-01-30 06:02 3192
    DrawIMG(bBack,background,xsize/2-120/2,600);
89c4a3a6 sago007 2008-08-29 14:32 3193
    do
89c4a3a6 sago007 2008-08-29 14:32 3194
    {
89c4a3a6 sago007 2008-08-29 14:32 3195
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3196
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3197
        DrawIMG(changeButtonsBack,screen,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 3198
        NFont_Write(screen, xplace+50,yplace+20,"Player 1");
925b7e58 sago007 2011-04-25 16:35 3199
        NFont_Write(screen, xplace+300+50,yplace+20,"Player 2");
925b7e58 sago007 2011-04-25 16:35 3200
        NFont_Write(screen, xplace+50,yplace+70,"Speed:");
925b7e58 sago007 2011-04-25 16:35 3201
        NFont_Write(screen, xplace+50+300,yplace+70,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 3202
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3203
        {
89c4a3a6 sago007 2008-08-29 14:32 3204
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3205
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3206
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3207
            NFont_Write(screen, xplace+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3208
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3209
            if (player1Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3210
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3211
        }
89c4a3a6 sago007 2008-08-29 14:32 3212
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3213
        {
89c4a3a6 sago007 2008-08-29 14:32 3214
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3215
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3216
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3217
            NFont_Write(screen, xplace+300+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3218
            DrawIMG(iLevelCheckBox,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3219
            if (player2Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3220
                DrawIMG(iLevelCheck,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3221
        }
925b7e58 sago007 2011-04-25 16:35 3222
        NFont_Write(screen, xplace+50,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3223
        DrawIMG(iLevelCheckBox,screen,xplace+50+70,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3224
        if (player1AI)
89c4a3a6 sago007 2008-08-29 14:32 3225
            DrawIMG(iLevelCheck,screen,xplace+50+70,yplace+200);
925b7e58 sago007 2011-04-25 16:35 3226
        NFont_Write(screen, xplace+50,yplace+250,"TT Handicap: ");
925b7e58 sago007 2011-04-25 16:35 3227
        NFont_Write(screen, xplace+50+300,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3228
        DrawIMG(iLevelCheckBox,screen,xplace+50+70+300,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3229
        if (player2AI)
89c4a3a6 sago007 2008-08-29 14:32 3230
            DrawIMG(iLevelCheck,screen,xplace+50+70+300,yplace+200);
925b7e58 sago007 2011-04-25 16:35 3231
        NFont_Write(screen, xplace+50+300,yplace+250,"TT Handicap: ");
89c4a3a6 sago007 2008-08-29 14:32 3232
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3233
        {
89c4a3a6 sago007 2008-08-29 14:32 3234
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3235
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3236
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3237
            NFont_Write(screen, xplace+50+i*40,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3238
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3239
            if (player1handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3240
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3241
        }
89c4a3a6 sago007 2008-08-29 14:32 3242
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3243
        {
89c4a3a6 sago007 2008-08-29 14:32 3244
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3245
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3246
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3247
            NFont_Write(screen, xplace+50+i*40+300,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3248
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3249
            if (player2handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3250
                DrawIMG(iLevelCheck,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3251
        }
89c4a3a6 sago007 2008-08-29 14:32 3252
89c4a3a6 sago007 2008-08-29 14:32 3253
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3254
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3255
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3256
            {
89c4a3a6 sago007 2008-08-29 14:32 3257
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3258
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3259
                }
89c4a3a6 sago007 2008-08-29 14:32 3260
                if ( event.key.keysym.sym == SDLK_RETURN ) {
89c4a3a6 sago007 2008-08-29 14:32 3261
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3262
                }
89c4a3a6 sago007 2008-08-29 14:32 3263
                if ( event.key.keysym.sym == SDLK_KP_ENTER ) {
89c4a3a6 sago007 2008-08-29 14:32 3264
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3265
                }
89c4a3a6 sago007 2008-08-29 14:32 3266
            }
89c4a3a6 sago007 2008-08-29 14:32 3267
89c4a3a6 sago007 2008-08-29 14:32 3268
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3269
89c4a3a6 sago007 2008-08-29 14:32 3270
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3271
89c4a3a6 sago007 2008-08-29 14:32 3272
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3273
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3274
        {
89c4a3a6 sago007 2008-08-29 14:32 3275
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3276
        }
89c4a3a6 sago007 2008-08-29 14:32 3277
89c4a3a6 sago007 2008-08-29 14:32 3278
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3279
        {
89c4a3a6 sago007 2008-08-29 14:32 3280
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3281
89c4a3a6 sago007 2008-08-29 14:32 3282
            if ((mousex>xplace+50+70)&&(mousey>yplace+200)&&(mousex<xplace+50+70+30)&&(mousey<yplace+200+30))
89c4a3a6 sago007 2008-08-29 14:32 3283
                player1AI=!player1AI;
89c4a3a6 sago007 2008-08-29 14:32 3284
            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 3285
                player2AI=!player2AI;
89c4a3a6 sago007 2008-08-29 14:32 3286
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3287
            {
89c4a3a6 sago007 2008-08-29 14:32 3288
                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 3289
                    player1Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3290
            }
89c4a3a6 sago007 2008-08-29 14:32 3291
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3292
            {
89c4a3a6 sago007 2008-08-29 14:32 3293
                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 3294
                    player2Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3295
            }
89c4a3a6 sago007 2008-08-29 14:32 3296
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3297
            {
89c4a3a6 sago007 2008-08-29 14:32 3298
                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 3299
                    player1handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3300
            }
89c4a3a6 sago007 2008-08-29 14:32 3301
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3302
            {
89c4a3a6 sago007 2008-08-29 14:32 3303
                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 3304
                    player2handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3305
            }
27ae0175 sago007 2009-01-30 06:02 3306
            if ((mousex>xsize/2-120/2)&&(mousex<xsize/2+120/2)&&(mousey>600)&&(mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 3307
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 3308
        }
89c4a3a6 sago007 2008-08-29 14:32 3309
8d488d32 sago007 2011-04-17 13:02 3310
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3311
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3312
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3313
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3314
89c4a3a6 sago007 2008-08-29 14:32 3315
    } while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3316
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3317
}
89c4a3a6 sago007 2008-08-29 14:32 3318
89c4a3a6 sago007 2008-08-29 14:32 3319
//This function will promt for the user to select another file for puzzle mode
89c4a3a6 sago007 2008-08-29 14:32 3320
void changePuzzleLevels()
89c4a3a6 sago007 2008-08-29 14:32 3321
{
89c4a3a6 sago007 2008-08-29 14:32 3322
    char theFileName[30];
89c4a3a6 sago007 2008-08-29 14:32 3323
    strcpy(theFileName,puzzleName.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3324
    for (int i=puzzleName.length();i<30;i++)
89c4a3a6 sago007 2008-08-29 14:32 3325
        theFileName[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 3326
    theFileName[29]=0;
89c4a3a6 sago007 2008-08-29 14:32 3327
    if (OpenFileDialogbox(200,100,theFileName))
89c4a3a6 sago007 2008-08-29 14:32 3328
    {
89c4a3a6 sago007 2008-08-29 14:32 3329
        for (int i=28;((theFileName[i]==' ')&&(i>0));i--)
89c4a3a6 sago007 2008-08-29 14:32 3330
            theFileName[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3331
        puzzleName = theFileName;
89c4a3a6 sago007 2008-08-29 14:32 3332
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3333
        string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3334
        puzzleSavePath = home+"/.gamesaves/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3335
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3336
        string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3337
        if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3338
        {
89c4a3a6 sago007 2008-08-29 14:32 3339
            puzzleSavePath = home+"/My Games/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3340
        }
89c4a3a6 sago007 2008-08-29 14:32 3341
        else
89c4a3a6 sago007 2008-08-29 14:32 3342
        {
89c4a3a6 sago007 2008-08-29 14:32 3343
            puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3344
        }
89c4a3a6 sago007 2008-08-29 14:32 3345
#else
89c4a3a6 sago007 2008-08-29 14:32 3346
        puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3347
#endif
89c4a3a6 sago007 2008-08-29 14:32 3348
    }
89c4a3a6 sago007 2008-08-29 14:32 3349
89c4a3a6 sago007 2008-08-29 14:32 3350
}
89c4a3a6 sago007 2008-08-29 14:32 3351
30f910dd sago007 2010-11-10 21:02 3352
static BlockGameSdl *player1;
30f910dd sago007 2010-11-10 21:02 3353
static BlockGameSdl *player2;
30f910dd sago007 2010-11-10 21:02 3354
30f910dd sago007 2010-11-10 21:02 3355
void StartSinglePlayerEndless() {
30f910dd sago007 2010-11-10 21:02 3356
    //1 player - endless
30f910dd sago007 2010-11-10 21:02 3357
    player1->NewGame(50,100,SDL_GetTicks());
30f910dd sago007 2010-11-10 21:02 3358
    player1->putStartBlocks(time(0));
30f910dd sago007 2010-11-10 21:02 3359
    bNewGameOpen = false;
30f910dd sago007 2010-11-10 21:02 3360
    b1playerOpen = false;
30f910dd sago007 2010-11-10 21:02 3361
    twoPlayers =false;
30f910dd sago007 2010-11-10 21:02 3362
    player2->SetGameOver();
30f910dd sago007 2010-11-10 21:02 3363
    showGame = true;
30f910dd sago007 2010-11-10 21:02 3364
    strcpy(player1->name, player1name);
30f910dd sago007 2010-11-10 21:02 3365
    strcpy(player2->name, player2name);
30f910dd sago007 2010-11-10 21:02 3366
}
30f910dd sago007 2010-11-10 21:02 3367
4f1d27f1 sago007 2011-03-18 15:53 3368
void StartSinglePlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3369
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3370
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3371
    twoPlayers =false;
4f1d27f1 sago007 2011-03-18 15:53 3372
    player2->SetGameOver();
4f1d27f1 sago007 2011-03-18 15:53 3373
    showGame = true;
4f1d27f1 sago007 2011-03-18 15:53 3374
    //vsMode = false;
4f1d27f1 sago007 2011-03-18 15:53 3375
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3376
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3377
}
4f1d27f1 sago007 2011-03-18 15:53 3378
b7590374 sago007 2011-05-19 16:15 3379
void StartSinglePlayerPuzzle() {
b7590374 sago007 2011-05-19 16:15 3380
    int myLevel = PuzzleLevelSelect();
b7590374 sago007 2011-05-19 16:15 3381
    player1->NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 3382
    MakeBackground(xsize,ysize,player1,player2);
b7590374 sago007 2011-05-19 16:15 3383
    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3384
    closeAllMenus();
b7590374 sago007 2011-05-19 16:15 3385
    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 3386
    player2->SetGameOver();
b7590374 sago007 2011-05-19 16:15 3387
    showGame = true;
b7590374 sago007 2011-05-19 16:15 3388
    //vsMode = true;
b7590374 sago007 2011-05-19 16:15 3389
    strcpy(player1->name, player1name);
b7590374 sago007 2011-05-19 16:15 3390
    strcpy(player2->name, player2name);
b7590374 sago007 2011-05-19 16:15 3391
}
b7590374 sago007 2011-05-19 16:15 3392
4f1d27f1 sago007 2011-03-18 15:53 3393
4f1d27f1 sago007 2011-03-18 15:53 3394
void StarTwoPlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3395
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3396
    player2->NewTimeTrialGame(xsize-500,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3397
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3398
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3399
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3400
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3401
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3402
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3403
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3404
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3405
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3406
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3407
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3408
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3409
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3410
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3411
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3412
}
4f1d27f1 sago007 2011-03-18 15:53 3413
4f1d27f1 sago007 2011-03-18 15:53 3414
void StartTwoPlayerVs() {
4f1d27f1 sago007 2011-03-18 15:53 3415
    //2 player - VsMode
4f1d27f1 sago007 2011-03-18 15:53 3416
    player1->NewVsGame(50,100,player2,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3417
    player2->NewVsGame(xsize-500,100,player1,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3418
    bNewGameOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3419
    //vsMode = true;
4f1d27f1 sago007 2011-03-18 15:53 3420
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3421
    b2playersOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3422
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3423
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3424
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3425
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3426
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3427
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3428
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3429
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3430
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3431
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3432
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3433
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3434
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3435
}
4f1d27f1 sago007 2011-03-18 15:53 3436
1572de2b sago007 2008-09-11 18:15 3437
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3438
#include "NetworkThing.hpp"
eec83b7d sago007 2009-03-29 15:46 3439
//#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 3440
#endif
89c4a3a6 sago007 2008-08-29 14:32 3441
89c4a3a6 sago007 2008-08-29 14:32 3442
//The main function, quite big... too big
89c4a3a6 sago007 2008-08-29 14:32 3443
int main(int argc, char *argv[])
89c4a3a6 sago007 2008-08-29 14:32 3444
{
89c4a3a6 sago007 2008-08-29 14:32 3445
    //We first create the folder there we will save (only on UNIX systems)
89c4a3a6 sago007 2008-08-29 14:32 3446
    //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 3447
#if defined(__unix__)
42f8ed5f sago007 2009-03-05 11:47 3448
    //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 3449
    if(system("mkdir -p ~/.gamesaves/blockattack/screenshots"))
42f8ed5f sago007 2009-03-05 11:47 3450
        cout << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl;
42f8ed5f sago007 2009-03-05 11:47 3451
    if(system("mkdir -p ~/.gamesaves/blockattack/replays"))
42f8ed5f sago007 2009-03-05 11:47 3452
        cout << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl;
42f8ed5f sago007 2009-03-05 11:47 3453
    if(system("mkdir -p ~/.gamesaves/blockattack/puzzles"))
42f8ed5f sago007 2009-03-05 11:47 3454
        cout << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3455
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3456
    //Now for Windows NT/2k/xp/2k3 etc.
89c4a3a6 sago007 2008-08-29 14:32 3457
    string tempA = getMyDocumentsPath()+"\\My Games";
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";
c325f4fa sago007 2009-05-09 18:33 3460
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3461
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays";
c325f4fa sago007 2009-05-09 18:33 3462
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3463
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots";
c325f4fa sago007 2009-05-09 18:33 3464
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3465
#endif
78d03b38 sago007 2008-11-13 19:56 3466
    highPriority = false;	//if true the game will take most resources, but increase framerate.
89c4a3a6 sago007 2008-08-29 14:32 3467
    bFullscreen = false;
2e57d791 sago007 2009-06-04 17:48 3468
    //Set default Config variables:
2e57d791 sago007 2009-06-04 17:48 3469
    Config::getInstance()->setDefault("themename","default");
89c4a3a6 sago007 2008-08-29 14:32 3470
    if (argc > 1)
89c4a3a6 sago007 2008-08-29 14:32 3471
    {
89c4a3a6 sago007 2008-08-29 14:32 3472
        int argumentNr = 1;
89c4a3a6 sago007 2008-08-29 14:32 3473
        forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3474
        while (argc>argumentNr)
89c4a3a6 sago007 2008-08-29 14:32 3475
        {
89c4a3a6 sago007 2008-08-29 14:32 3476
            char helpString[] = "--help";
89c4a3a6 sago007 2008-08-29 14:32 3477
            char priorityString[] = "-priority";
89c4a3a6 sago007 2008-08-29 14:32 3478
            char forceRedrawString[] = "-forceredraw";
89c4a3a6 sago007 2008-08-29 14:32 3479
            char forcepartdrawString[] = "-forcepartdraw";
89c4a3a6 sago007 2008-08-29 14:32 3480
            char singlePuzzleString[] = "-SP";
89c4a3a6 sago007 2008-08-29 14:32 3481
            char noSoundAtAll[] = "-nosound";
89c4a3a6 sago007 2008-08-29 14:32 3482
            char IntegratedEditor[] = "-editor";
2e57d791 sago007 2009-06-04 17:48 3483
            char selectTheme[] = "-theme";
89c4a3a6 sago007 2008-08-29 14:32 3484
            if (!(strncmp(argv[argumentNr],helpString,6)))
89c4a3a6 sago007 2008-08-29 14:32 3485
            {
89c4a3a6 sago007 2008-08-29 14:32 3486
                cout << "Block Attack Help" << endl << "--help Display this message" <<
89c4a3a6 sago007 2008-08-29 14:32 3487
                endl << "-priority  Starts game in high priority" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3488
                "-forceredraw  Redraw the whole screen every frame, prevents garbage" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3489
                "-forcepartdraw  Only draw what is changed, sometimes cause garbage" << endl <<
2e57d791 sago007 2009-06-04 17:48 3490
                "-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 3491
                "-theme <THEMENAME>  Changes to the theme <THEMENAME> on startup" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3492
                "-editor  Starts the build-in editor (not yet integrated)" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3493
#ifdef WIN32
89c4a3a6 sago007 2008-08-29 14:32 3494
                system("Pause");
89c4a3a6 sago007 2008-08-29 14:32 3495
#endif
89c4a3a6 sago007 2008-08-29 14:32 3496
                return 0;
89c4a3a6 sago007 2008-08-29 14:32 3497
            }
89c4a3a6 sago007 2008-08-29 14:32 3498
            if (!(strncmp(argv[argumentNr],priorityString,9)))
89c4a3a6 sago007 2008-08-29 14:32 3499
            {
89c4a3a6 sago007 2008-08-29 14:32 3500
                cout << "Priority mode" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3501
                highPriority = true;
89c4a3a6 sago007 2008-08-29 14:32 3502
            }
89c4a3a6 sago007 2008-08-29 14:32 3503
            if (!(strncmp(argv[argumentNr],forceRedrawString,12)))
89c4a3a6 sago007 2008-08-29 14:32 3504
            {
89c4a3a6 sago007 2008-08-29 14:32 3505
                forceredraw = 1;
89c4a3a6 sago007 2008-08-29 14:32 3506
            }
89c4a3a6 sago007 2008-08-29 14:32 3507
            if (!(strncmp(argv[argumentNr],forcepartdrawString,14)))
89c4a3a6 sago007 2008-08-29 14:32 3508
            {
89c4a3a6 sago007 2008-08-29 14:32 3509
                forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3510
            }
89c4a3a6 sago007 2008-08-29 14:32 3511
            if (!(strncmp(argv[argumentNr],singlePuzzleString,3)))
89c4a3a6 sago007 2008-08-29 14:32 3512
            {
89c4a3a6 sago007 2008-08-29 14:32 3513
                singlePuzzle = true; //We will just have one puzzle
89c4a3a6 sago007 2008-08-29 14:32 3514
                if (argv[argumentNr+1][1]!=0)
89c4a3a6 sago007 2008-08-29 14:32 3515
                    singlePuzzleNr = (argv[argumentNr+1][1]-'0')+(argv[argumentNr+1][0]-'0')*10;
89c4a3a6 sago007 2008-08-29 14:32 3516
                else
89c4a3a6 sago007 2008-08-29 14:32 3517
                    singlePuzzleNr = (argv[argumentNr+1][0]-'0');
89c4a3a6 sago007 2008-08-29 14:32 3518
                singlePuzzleFile = argv[argumentNr+2];
89c4a3a6 sago007 2008-08-29 14:32 3519
                argumentNr+=2;
89c4a3a6 sago007 2008-08-29 14:32 3520
                cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl;
89c4a3a6 sago007 2008-08-29 14:32 3521
            }
89c4a3a6 sago007 2008-08-29 14:32 3522
            if (!(strncmp(argv[argumentNr],noSoundAtAll,8)))
89c4a3a6 sago007 2008-08-29 14:32 3523
            {
89c4a3a6 sago007 2008-08-29 14:32 3524
                NoSound = true;
89c4a3a6 sago007 2008-08-29 14:32 3525
            }
89c4a3a6 sago007 2008-08-29 14:32 3526
            if (!(strncmp(argv[argumentNr],IntegratedEditor,7)))
89c4a3a6 sago007 2008-08-29 14:32 3527
            {
1572de2b sago007 2008-09-11 18:15 3528
                #if LEVELEDITOR
89c4a3a6 sago007 2008-08-29 14:32 3529
                editorMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3530
                cout << "Integrated Puzzle Editor Activated" << endl;
1572de2b sago007 2008-09-11 18:15 3531
                #else
1572de2b sago007 2008-09-11 18:15 3532
                cout << "Integrated Puzzle Editor was disabled at compile time" << endl;
2e57d791 sago007 2009-06-04 17:48 3533
                return -1;
1572de2b sago007 2008-09-11 18:15 3534
                #endif
89c4a3a6 sago007 2008-08-29 14:32 3535
            }
2e57d791 sago007 2009-06-04 17:48 3536
            if(!(strncmp(argv[argumentNr],selectTheme,6)))
2e57d791 sago007 2009-06-04 17:48 3537
            {
2e57d791 sago007 2009-06-04 17:48 3538
                argumentNr++; //Go to themename (the next argument)
2e57d791 sago007 2009-06-04 17:48 3539
                cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
2e57d791 sago007 2009-06-04 17:48 3540
                Config::getInstance()->setString("themename",argv[argumentNr]);
2e57d791 sago007 2009-06-04 17:48 3541
            }
89c4a3a6 sago007 2008-08-29 14:32 3542
            argumentNr++;
89c4a3a6 sago007 2008-08-29 14:32 3543
        }   //while
89c4a3a6 sago007 2008-08-29 14:32 3544
    }   //if
89c4a3a6 sago007 2008-08-29 14:32 3545
89c4a3a6 sago007 2008-08-29 14:32 3546
    SoundEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3547
    MusicEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3548
    int mousex, mousey;   //Mouse coordinates
89c4a3a6 sago007 2008-08-29 14:32 3549
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3550
    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3551
    b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3552
    bReplayOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3553
    bScreenLocked = false;
f72abf8b sago007 2010-01-16 20:00 3554
    twoPlayers = false;	//true if two players splitscreen
89c4a3a6 sago007 2008-08-29 14:32 3555
    bool vsMode = false;
89c4a3a6 sago007 2008-08-29 14:32 3556
    theTopScoresEndless = Highscore(1);
89c4a3a6 sago007 2008-08-29 14:32 3557
    theTopScoresTimeTrial = Highscore(2);
89c4a3a6 sago007 2008-08-29 14:32 3558
    drawBalls = true;
89c4a3a6 sago007 2008-08-29 14:32 3559
    puzzleLoaded = false;
89c4a3a6 sago007 2008-08-29 14:32 3560
    bool weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3561
89c4a3a6 sago007 2008-08-29 14:32 3562
    //Things used for repeating keystrokes:
30f910dd sago007 2010-11-10 21:02 3563
    bool repeatingS[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3564
    bool repeatingW[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3565
    bool repeatingN[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3566
    bool repeatingE[2] = {false,false};
89c4a3a6 sago007 2008-08-29 14:32 3567
    const int startRepeat = 200;
89c4a3a6 sago007 2008-08-29 14:32 3568
    const int repeatDelay = 100;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 3569
    unsigned long timeHeldP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3570
    unsigned long timeHeldP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3571
    unsigned long timeHeldP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3572
    unsigned long timeHeldP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3573
    unsigned long timeHeldP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3574
    unsigned long timeHeldP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3575
    unsigned long timeHeldP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3576
    unsigned long timeHeldP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3577
    unsigned long timesRepeatedP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3578
    unsigned long timesRepeatedP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3579
    unsigned long timesRepeatedP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3580
    unsigned long timesRepeatedP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3581
    unsigned long timesRepeatedP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3582
    unsigned long timesRepeatedP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3583
    unsigned long timesRepeatedP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3584
    unsigned long timesRepeatedP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3585
89c4a3a6 sago007 2008-08-29 14:32 3586
    theBallManeger = ballManeger();
89c4a3a6 sago007 2008-08-29 14:32 3587
    theExplosionManeger = explosionManeger();
89c4a3a6 sago007 2008-08-29 14:32 3588
89c4a3a6 sago007 2008-08-29 14:32 3589
//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 3590
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3591
    string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3592
    string optionsPath = home+"/.gamesaves/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3593
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3594
    string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3595
    string optionsPath;
89c4a3a6 sago007 2008-08-29 14:32 3596
    if (&home!=NULL) //Null if no APPDATA dir exists (win 9x)
89c4a3a6 sago007 2008-08-29 14:32 3597
        optionsPath = home+"/My Games/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3598
    else
89c4a3a6 sago007 2008-08-29 14:32 3599
        optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3600
#else
89c4a3a6 sago007 2008-08-29 14:32 3601
    string optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3602
#endif
89c4a3a6 sago007 2008-08-29 14:32 3603
89c4a3a6 sago007 2008-08-29 14:32 3604
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3605
    stageClearSavePath = home+"/.gamesaves/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3606
    puzzleSavePath = home+"/.gamesaves/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3607
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3608
    if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3609
    {
89c4a3a6 sago007 2008-08-29 14:32 3610
        stageClearSavePath = home+"/My Games/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3611
        puzzleSavePath = home+"/My Games/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3612
    }
89c4a3a6 sago007 2008-08-29 14:32 3613
    else
89c4a3a6 sago007 2008-08-29 14:32 3614
    {
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
    }
89c4a3a6 sago007 2008-08-29 14:32 3618
#else
89c4a3a6 sago007 2008-08-29 14:32 3619
    stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3620
    puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3621
#endif
89c4a3a6 sago007 2008-08-29 14:32 3622
    puzzleName="puzzle.levels";
89c4a3a6 sago007 2008-08-29 14:32 3623
89c4a3a6 sago007 2008-08-29 14:32 3624
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3625
866417ca sago007 2009-05-10 21:35 3626
95bc02ff sago007 2009-03-15 02:46 3627
89c4a3a6 sago007 2008-08-29 14:32 3628
    //Init SDL
89c4a3a6 sago007 2008-08-29 14:32 3629
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
89c4a3a6 sago007 2008-08-29 14:32 3630
    {
89c4a3a6 sago007 2008-08-29 14:32 3631
        cout << "Unable to init SDL: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3632
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3633
    }
89c4a3a6 sago007 2008-08-29 14:32 3634
    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 3635
    
89c4a3a6 sago007 2008-08-29 14:32 3636
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
89c4a3a6 sago007 2008-08-29 14:32 3637
89c4a3a6 sago007 2008-08-29 14:32 3638
    Joypad_init();    //Prepare the joysticks
89c4a3a6 sago007 2008-08-29 14:32 3639
89c4a3a6 sago007 2008-08-29 14:32 3640
    Joypad joypad1 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3641
    Joypad joypad2 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3642
89c4a3a6 sago007 2008-08-29 14:32 3643
    theTextManeger = textManeger();
89c4a3a6 sago007 2008-08-29 14:32 3644
89c4a3a6 sago007 2008-08-29 14:32 3645
    //Open Audio
89c4a3a6 sago007 2008-08-29 14:32 3646
    if (!NoSound) //If sound has not been disabled, then load the sound system
89c4a3a6 sago007 2008-08-29 14:32 3647
        if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
89c4a3a6 sago007 2008-08-29 14:32 3648
        {
89c4a3a6 sago007 2008-08-29 14:32 3649
            cout << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
89c4a3a6 sago007 2008-08-29 14:32 3650
            << "Sound will be disabled!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3651
            NoSound = true; //Tries to stop all sound from playing/loading
89c4a3a6 sago007 2008-08-29 14:32 3652
        }
89c4a3a6 sago007 2008-08-29 14:32 3653
89c4a3a6 sago007 2008-08-29 14:32 3654
    SDL_WM_SetCaption("Block Attack - Rise of the Blocks", NULL); //Sets title line
866417ca sago007 2009-05-10 21:35 3655
    
89c4a3a6 sago007 2008-08-29 14:32 3656
89c4a3a6 sago007 2008-08-29 14:32 3657
    //Copyright notice:
4f1d27f1 sago007 2011-03-18 15:53 3658
    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 3659
    "A SDL based game (see www.libsdl.org)" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3660
    "The game is availeble under the GPL, see COPYING for details." << endl;
89c4a3a6 sago007 2008-08-29 14:32 3661
#if defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3662
    cout << "Windows build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3663
#elif defined(__linux__)
89c4a3a6 sago007 2008-08-29 14:32 3664
    cout << "Linux build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3665
#elif defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3666
    cout << "Unix build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3667
#else
89c4a3a6 sago007 2008-08-29 14:32 3668
    cout << "Alternative build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3669
#endif
89c4a3a6 sago007 2008-08-29 14:32 3670
    cout << "-------------------------------------------" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3671
95bc02ff sago007 2009-03-15 02:46 3672
89c4a3a6 sago007 2008-08-29 14:32 3673
    keySettings[0].up= SDLK_UP;
89c4a3a6 sago007 2008-08-29 14:32 3674
    keySettings[0].down = SDLK_DOWN;
89c4a3a6 sago007 2008-08-29 14:32 3675
    keySettings[0].left = SDLK_LEFT;
89c4a3a6 sago007 2008-08-29 14:32 3676
    keySettings[0].right = SDLK_RIGHT;
6d48320c sago007 2009-03-28 17:06 3677
    keySettings[0].change = SDLK_RCTRL;
6d48320c sago007 2009-03-28 17:06 3678
    keySettings[0].push = SDLK_RSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3679
89c4a3a6 sago007 2008-08-29 14:32 3680
    keySettings[2].up= SDLK_w;
89c4a3a6 sago007 2008-08-29 14:32 3681
    keySettings[2].down = SDLK_s;
89c4a3a6 sago007 2008-08-29 14:32 3682
    keySettings[2].left = SDLK_a;
89c4a3a6 sago007 2008-08-29 14:32 3683
    keySettings[2].right = SDLK_d;
89c4a3a6 sago007 2008-08-29 14:32 3684
    keySettings[2].change = SDLK_LCTRL;
89c4a3a6 sago007 2008-08-29 14:32 3685
    keySettings[2].push = SDLK_LSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3686
89c4a3a6 sago007 2008-08-29 14:32 3687
    player1keys=0;
89c4a3a6 sago007 2008-08-29 14:32 3688
    player2keys=2;
89c4a3a6 sago007 2008-08-29 14:32 3689
89c4a3a6 sago007 2008-08-29 14:32 3690
    strcpy(player1name, "Player 1                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3691
    strcpy(player2name, "Player 2                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3692
769a41a0 sago007 2008-09-24 12:54 3693
    Config *configSettings = Config::getInstance();
769a41a0 sago007 2008-09-24 12:54 3694
    //configSettings->setString("aNumber"," A string");
769a41a0 sago007 2008-09-24 12:54 3695
    //configSettings->save();
769a41a0 sago007 2008-09-24 12:54 3696
    if(configSettings->exists("fullscreen")) //Test if an configFile exists
89c4a3a6 sago007 2008-08-29 14:32 3697
    {
769a41a0 sago007 2008-09-24 12:54 3698
        bFullscreen = (bool)configSettings->getInt("fullscreen");
769a41a0 sago007 2008-09-24 12:54 3699
        MusicEnabled = (bool)configSettings->getInt("musicenabled");
769a41a0 sago007 2008-09-24 12:54 3700
        SoundEnabled = (bool)configSettings->getInt("soundenabled");
769a41a0 sago007 2008-09-24 12:54 3701
        mouseplay1 = (bool)configSettings->getInt("mouseplay1");
769a41a0 sago007 2008-09-24 12:54 3702
        mouseplay2 = (bool)configSettings->getInt("mouseplay2");
769a41a0 sago007 2008-09-24 12:54 3703
        joyplay1 = (bool)configSettings->getInt("joypad1");
769a41a0 sago007 2008-09-24 12:54 3704
        joyplay2 = (bool)configSettings->getInt("joypad2");
769a41a0 sago007 2008-09-24 12:54 3705
        
769a41a0 sago007 2008-09-24 12:54 3706
        if(configSettings->exists("player1keyup")) keySettings[0].up = (SDLKey)configSettings->getInt("player1keyup");
769a41a0 sago007 2008-09-24 12:54 3707
        if(configSettings->exists("player1keydown")) keySettings[0].down = (SDLKey)configSettings->getInt("player1keydown");
769a41a0 sago007 2008-09-24 12:54 3708
        if(configSettings->exists("player1keyleft")) keySettings[0].left = (SDLKey)configSettings->getInt("player1keyleft");
769a41a0 sago007 2008-09-24 12:54 3709
        if(configSettings->exists("player1keyright")) keySettings[0].right = (SDLKey)configSettings->getInt("player1keyright");
769a41a0 sago007 2008-09-24 12:54 3710
        if(configSettings->exists("player1keychange")) keySettings[0].change = (SDLKey)configSettings->getInt("player1keychange");
769a41a0 sago007 2008-09-24 12:54 3711
        if(configSettings->exists("player1keypush")) keySettings[0].push = (SDLKey)configSettings->getInt("player1keypush");
769a41a0 sago007 2008-09-24 12:54 3712
        
769a41a0 sago007 2008-09-24 12:54 3713
        if(configSettings->exists("player2keyup")) keySettings[2].up = (SDLKey)configSettings->getInt("player2keyup");
769a41a0 sago007 2008-09-24 12:54 3714
        if(configSettings->exists("player2keydown")) keySettings[2].down = (SDLKey)configSettings->getInt("player2keydown");
769a41a0 sago007 2008-09-24 12:54 3715
        if(configSettings->exists("player2keyleft")) keySettings[2].left = (SDLKey)configSettings->getInt("player2keyleft");
769a41a0 sago007 2008-09-24 12:54 3716
        if(configSettings->exists("player2keyright")) keySettings[2].right = (SDLKey)configSettings->getInt("player2keyright");
769a41a0 sago007 2008-09-24 12:54 3717
        if(configSettings->exists("player2keychange")) keySettings[2].change = (SDLKey)configSettings->getInt("player2keychange");
769a41a0 sago007 2008-09-24 12:54 3718
        if(configSettings->exists("player2keypush")) keySettings[2].push = (SDLKey)configSettings->getInt("player2keypush");
769a41a0 sago007 2008-09-24 12:54 3719
        if(configSettings->exists("player1name"))
769a41a0 sago007 2008-09-24 12:54 3720
            strncpy(player1name,(configSettings->getString("player1name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3721
        if(configSettings->exists("player2name"))
769a41a0 sago007 2008-09-24 12:54 3722
            strncpy(player2name,(configSettings->getString("player2name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3723
        cout << "Data loaded from config file" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3724
    }
89c4a3a6 sago007 2008-08-29 14:32 3725
    else
89c4a3a6 sago007 2008-08-29 14:32 3726
    {
769a41a0 sago007 2008-09-24 12:54 3727
        //Reads options from file:
769a41a0 sago007 2008-09-24 12:54 3728
        ifstream optionsFile(optionsPath.c_str(), ios::binary);
769a41a0 sago007 2008-09-24 12:54 3729
        if (optionsFile)
769a41a0 sago007 2008-09-24 12:54 3730
        {
769a41a0 sago007 2008-09-24 12:54 3731
            //reads data: xsize,ysize,fullescreen, player1keys, player2keys, MusicEnabled, SoundEnabled,player1name,player2name
769a41a0 sago007 2008-09-24 12:54 3732
            optionsFile.read(reinterpret_cast<char*>(&xsize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3733
            optionsFile.read(reinterpret_cast<char*>(&ysize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3734
            optionsFile.read(reinterpret_cast<char*>(&bFullscreen), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3735
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3736
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3737
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3738
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3739
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3740
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3741
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3742
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3743
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3744
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3745
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3746
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3747
            optionsFile.read(reinterpret_cast<char*>(&MusicEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3748
            optionsFile.read(reinterpret_cast<char*>(&SoundEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3749
            optionsFile.read(player1name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3750
            optionsFile.read(player2name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3751
            //mouseplay?
769a41a0 sago007 2008-09-24 12:54 3752
            if (!optionsFile.eof())
769a41a0 sago007 2008-09-24 12:54 3753
            {
769a41a0 sago007 2008-09-24 12:54 3754
                optionsFile.read(reinterpret_cast<char*>(&mouseplay1), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3755
                optionsFile.read(reinterpret_cast<char*>(&mouseplay2), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3756
                optionsFile.read(reinterpret_cast<char*>(&joyplay1),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3757
                optionsFile.read(reinterpret_cast<char*>(&joyplay2),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3758
            }
769a41a0 sago007 2008-09-24 12:54 3759
            optionsFile.close();
769a41a0 sago007 2008-09-24 12:54 3760
            cout << "Data loaded from oldstyle options file" << endl;
769a41a0 sago007 2008-09-24 12:54 3761
        }
769a41a0 sago007 2008-09-24 12:54 3762
        else
769a41a0 sago007 2008-09-24 12:54 3763
        {
769a41a0 sago007 2008-09-24 12:54 3764
            cout << "Unable to load options file, using default values" << endl;
769a41a0 sago007 2008-09-24 12:54 3765
        }
89c4a3a6 sago007 2008-08-29 14:32 3766
    }
27ae0175 sago007 2009-01-30 06:02 3767
    
27ae0175 sago007 2009-01-30 06:02 3768
#if NETWORK
27ae0175 sago007 2009-01-30 06:02 3769
    strcpy(serverAddress, "192.168.0.2                 \0");
27ae0175 sago007 2009-01-30 06:02 3770
    if(configSettings->exists("address0"))
27ae0175 sago007 2009-01-30 06:02 3771
    {
27ae0175 sago007 2009-01-30 06:02 3772
        strcpy(serverAddress, "                            \0");
27ae0175 sago007 2009-01-30 06:02 3773
        strncpy(serverAddress,configSettings->getString("address0").c_str(),sizeof(serverAddress)-1);
27ae0175 sago007 2009-01-30 06:02 3774
    }
27ae0175 sago007 2009-01-30 06:02 3775
#endif
89c4a3a6 sago007 2008-08-29 14:32 3776
89c4a3a6 sago007 2008-08-29 14:32 3777
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3778
    {
89c4a3a6 sago007 2008-08-29 14:32 3779
        xsize=300;
89c4a3a6 sago007 2008-08-29 14:32 3780
        ysize=600;
89c4a3a6 sago007 2008-08-29 14:32 3781
    }
89c4a3a6 sago007 2008-08-29 14:32 3782
    
89c4a3a6 sago007 2008-08-29 14:32 3783
    
89c4a3a6 sago007 2008-08-29 14:32 3784
    //Open video
89c4a3a6 sago007 2008-08-29 14:32 3785
    if ((bFullscreen)&&(!singlePuzzle)) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3786
    else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3787
89c4a3a6 sago007 2008-08-29 14:32 3788
    if ( screen == NULL )
89c4a3a6 sago007 2008-08-29 14:32 3789
    {
89c4a3a6 sago007 2008-08-29 14:32 3790
        cout << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3791
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3792
    }
89c4a3a6 sago007 2008-08-29 14:32 3793
866417ca sago007 2009-05-10 21:35 3794
    //Init the file system abstraction layer
866417ca sago007 2009-05-10 21:35 3795
    PHYSFS_init(argv[0]);
866417ca sago007 2009-05-10 21:35 3796
    //Load default theme
2e57d791 sago007 2009-06-04 17:48 3797
    loadTheme(Config::getInstance()->getString("themename"));
866417ca sago007 2009-05-10 21:35 3798
    //Now sets the icon:
1f61db96 sago007 2010-11-15 20:12 3799
    SDL_Surface *icon = IMG_Load2("gfx/icon.png");
866417ca sago007 2009-05-10 21:35 3800
    SDL_WM_SetIcon(icon,NULL);
89c4a3a6 sago007 2008-08-29 14:32 3801
89c4a3a6 sago007 2008-08-29 14:32 3802
    cout << "Images loaded" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3803
78d03b38 sago007 2008-11-13 19:56 3804
    //InitMenues();
89c4a3a6 sago007 2008-08-29 14:32 3805
6b1dc7a6 sago007 2010-11-08 21:03 3806
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
6b1dc7a6 sago007 2010-11-08 21:03 3807
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
30f910dd sago007 2010-11-10 21:02 3808
    player1 = &theGame;
30f910dd sago007 2010-11-10 21:02 3809
    player2 = &theGame2;
e1290bdf sago007 2010-10-25 19:56 3810
    /*if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3811
    {
e1290bdf sago007 2010-10-25 19:56 3812
        theGame.GetTopY()=0;
e1290bdf sago007 2010-10-25 19:56 3813
        theGame.GetTopX()=0;
e1290bdf sago007 2010-10-25 19:56 3814
        theGame2.GetTopY()=10000;
e1290bdf sago007 2010-10-25 19:56 3815
        theGame2.GetTopX()=10000;
e1290bdf sago007 2010-10-25 19:56 3816
    }*/
89c4a3a6 sago007 2008-08-29 14:32 3817
    theGame.DoPaintJob();			//Makes sure what there is something to paint
89c4a3a6 sago007 2008-08-29 14:32 3818
    theGame2.DoPaintJob();
89c4a3a6 sago007 2008-08-29 14:32 3819
    theGame.SetGameOver();		//sets the game over in the beginning
89c4a3a6 sago007 2008-08-29 14:32 3820
    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 3821
89c4a3a6 sago007 2008-08-29 14:32 3822
89c4a3a6 sago007 2008-08-29 14:32 3823
    //Takes names from file instead
89c4a3a6 sago007 2008-08-29 14:32 3824
    strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 3825
    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 3826
89c4a3a6 sago007 2008-08-29 14:32 3827
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3828
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3829
89c4a3a6 sago007 2008-08-29 14:32 3830
1572de2b sago007 2008-09-11 18:15 3831
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3832
    NetworkThing nt = NetworkThing();
89c4a3a6 sago007 2008-08-29 14:32 3833
    nt.setBGpointers(&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3834
#endif
89c4a3a6 sago007 2008-08-29 14:32 3835
89c4a3a6 sago007 2008-08-29 14:32 3836
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3837
    {
89c4a3a6 sago007 2008-08-29 14:32 3838
        LoadPuzzleStages();
e1290bdf sago007 2010-10-25 19:56 3839
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3840
        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 3841
        vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3842
    }
89c4a3a6 sago007 2008-08-29 14:32 3843
    //Draws everything to screen
89c4a3a6 sago007 2008-08-29 14:32 3844
    if (!editorMode)
e1290bdf sago007 2010-10-25 19:56 3845
        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3846
    else
e1290bdf sago007 2010-10-25 19:56 3847
        MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 3848
    DrawIMG(background, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 3849
    DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3850
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3851
    //game loop
89c4a3a6 sago007 2008-08-29 14:32 3852
    int done = 0;
89c4a3a6 sago007 2008-08-29 14:32 3853
    cout << "Starting game loop" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3854
    while (done == 0)
89c4a3a6 sago007 2008-08-29 14:32 3855
    {
89c4a3a6 sago007 2008-08-29 14:32 3856
        if (!(highPriority)) SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3857
89c4a3a6 sago007 2008-08-29 14:32 3858
        if ((standardBackground)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3859
        {
e1290bdf sago007 2010-10-25 19:56 3860
            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3861
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3862
        }
89c4a3a6 sago007 2008-08-29 14:32 3863
89c4a3a6 sago007 2008-08-29 14:32 3864
        if ((standardBackground)&&(editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3865
        {
89c4a3a6 sago007 2008-08-29 14:32 3866
            DrawIMG(backgroundImage, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 3867
            MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 3868
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3869
        }
89c4a3a6 sago007 2008-08-29 14:32 3870
89c4a3a6 sago007 2008-08-29 14:32 3871
        //updates the balls and explosions:
89c4a3a6 sago007 2008-08-29 14:32 3872
        theBallManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3873
        theExplosionManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3874
        theTextManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3875
1572de2b sago007 2008-09-11 18:15 3876
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3877
        if (nt.isConnected())
89c4a3a6 sago007 2008-08-29 14:32 3878
        {
89c4a3a6 sago007 2008-08-29 14:32 3879
            nt.updateNetwork();
89c4a3a6 sago007 2008-08-29 14:32 3880
            networkActive = true;
89c4a3a6 sago007 2008-08-29 14:32 3881
            if (!nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 3882
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3883
        }
89c4a3a6 sago007 2008-08-29 14:32 3884
        else
89c4a3a6 sago007 2008-08-29 14:32 3885
            networkActive = false;
89c4a3a6 sago007 2008-08-29 14:32 3886
        if (nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 3887
        {
89c4a3a6 sago007 2008-08-29 14:32 3888
            networkPlay=true;
89c4a3a6 sago007 2008-08-29 14:32 3889
            if (!weWhereConnected) //We have just connected
89c4a3a6 sago007 2008-08-29 14:32 3890
            {
e1290bdf sago007 2010-10-25 19:56 3891
                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3892
                theGame.putStartBlocks(nt.theSeed);
e1290bdf sago007 2010-10-25 19:56 3893
                theGame2.playNetwork(xsize-500,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3894
                nt.theGameHasStarted();
89c4a3a6 sago007 2008-08-29 14:32 3895
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3896
            }
89c4a3a6 sago007 2008-08-29 14:32 3897
            weWhereConnected = true;
89c4a3a6 sago007 2008-08-29 14:32 3898
        }
89c4a3a6 sago007 2008-08-29 14:32 3899
        else
89c4a3a6 sago007 2008-08-29 14:32 3900
        {
89c4a3a6 sago007 2008-08-29 14:32 3901
            networkPlay=false;
89c4a3a6 sago007 2008-08-29 14:32 3902
            weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3903
        }
89c4a3a6 sago007 2008-08-29 14:32 3904
#endif
89c4a3a6 sago007 2008-08-29 14:32 3905
89c4a3a6 sago007 2008-08-29 14:32 3906
        if (!bScreenLocked)
89c4a3a6 sago007 2008-08-29 14:32 3907
        {
89c4a3a6 sago007 2008-08-29 14:32 3908
            SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3909
89c4a3a6 sago007 2008-08-29 14:32 3910
            while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3911
            {
89c4a3a6 sago007 2008-08-29 14:32 3912
                if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 3913
                    done = 1;
89c4a3a6 sago007 2008-08-29 14:32 3914
                }
89c4a3a6 sago007 2008-08-29 14:32 3915
89c4a3a6 sago007 2008-08-29 14:32 3916
                if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3917
                {
89c4a3a6 sago007 2008-08-29 14:32 3918
                    if ( event.key.keysym.sym == SDLK_ESCAPE )
89c4a3a6 sago007 2008-08-29 14:32 3919
                    {
89c4a3a6 sago007 2008-08-29 14:32 3920
                            if (showOptions)
89c4a3a6 sago007 2008-08-29 14:32 3921
                            {
89c4a3a6 sago007 2008-08-29 14:32 3922
                                showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3923
                            }
89c4a3a6 sago007 2008-08-29 14:32 3924
                            else
89c4a3a6 sago007 2008-08-29 14:32 3925
                                done=1;
89c4a3a6 sago007 2008-08-29 14:32 3926
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3927
89c4a3a6 sago007 2008-08-29 14:32 3928
                    }
e1290bdf sago007 2010-10-25 19:56 3929
                    if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled()))
89c4a3a6 sago007 2008-08-29 14:32 3930
                    {
89c4a3a6 sago007 2008-08-29 14:32 3931
                        //player1:
89c4a3a6 sago007 2008-08-29 14:32 3932
                        if ( event.key.keysym.sym == keySettings[player1keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 3933
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 3934
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3935
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3936
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 3937
                        }
89c4a3a6 sago007 2008-08-29 14:32 3938
                        if ( event.key.keysym.sym == keySettings[player1keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 3939
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 3940
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3941
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3942
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 3943
                        }
89c4a3a6 sago007 2008-08-29 14:32 3944
                        if ( (event.key.keysym.sym == keySettings[player1keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3945
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 3946
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3947
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3948
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 3949
                        }
89c4a3a6 sago007 2008-08-29 14:32 3950
                        if ( (event.key.keysym.sym == keySettings[player1keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3951
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 3952
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3953
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3954
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 3955
                        }
89c4a3a6 sago007 2008-08-29 14:32 3956
                        if ( event.key.keysym.sym == keySettings[player1keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 3957
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 3958
                        }
89c4a3a6 sago007 2008-08-29 14:32 3959
                        if ( event.key.keysym.sym == keySettings[player1keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 3960
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 3961
                        }
89c4a3a6 sago007 2008-08-29 14:32 3962
                    }
e1290bdf sago007 2010-10-25 19:56 3963
                    if (!editorMode && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 3964
                    {
89c4a3a6 sago007 2008-08-29 14:32 3965
                        //player2:
89c4a3a6 sago007 2008-08-29 14:32 3966
                        if ( event.key.keysym.sym == keySettings[player2keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 3967
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 3968
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3969
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3970
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 3971
                        }
89c4a3a6 sago007 2008-08-29 14:32 3972
                        if ( event.key.keysym.sym == keySettings[player2keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 3973
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 3974
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3975
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3976
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 3977
                        }
89c4a3a6 sago007 2008-08-29 14:32 3978
                        if ( (event.key.keysym.sym == keySettings[player2keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3979
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 3980
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3981
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3982
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 3983
                        }
89c4a3a6 sago007 2008-08-29 14:32 3984
                        if ( (event.key.keysym.sym == keySettings[player2keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3985
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 3986
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3987
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3988
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 3989
                        }
89c4a3a6 sago007 2008-08-29 14:32 3990
                        if ( event.key.keysym.sym == keySettings[player2keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 3991
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 3992
                        }
89c4a3a6 sago007 2008-08-29 14:32 3993
                        if ( event.key.keysym.sym == keySettings[player2keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 3994
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 3995
                        }
89c4a3a6 sago007 2008-08-29 14:32 3996
                    }
89c4a3a6 sago007 2008-08-29 14:32 3997
                    //common:
89c4a3a6 sago007 2008-08-29 14:32 3998
                    if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3999
                    {
89c4a3a6 sago007 2008-08-29 14:32 4000
                        if ( event.key.keysym.sym == SDLK_F2 ) {
2f30c381 sago007 2008-09-14 13:08 4001
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4002
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 4003
                            #else
47529580 sago007 2008-12-09 02:34 4004
                            if ((!showOptions)){
2f30c381 sago007 2008-09-14 13:08 4005
                            #endif
30f910dd sago007 2010-11-10 21:02 4006
                                StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 4007
                            }}
89c4a3a6 sago007 2008-08-29 14:32 4008
                        if ( event.key.keysym.sym == SDLK_F3 ) {
2f30c381 sago007 2008-09-14 13:08 4009
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4010
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 4011
                            #else
47529580 sago007 2008-12-09 02:34 4012
                            if ((!showOptions)){    
2f30c381 sago007 2008-09-14 13:08 4013
                            #endif
4f1d27f1 sago007 2011-03-18 15:53 4014
                                StartSinglePlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4015
                            }}
89c4a3a6 sago007 2008-08-29 14:32 4016
                        if ( event.key.keysym.sym == SDLK_F5 )
89c4a3a6 sago007 2008-08-29 14:32 4017
                        {
2f30c381 sago007 2008-09-14 13:08 4018
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4019
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4020
                            #else
47529580 sago007 2008-12-09 02:34 4021
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4022
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4023
                            {
89c4a3a6 sago007 2008-08-29 14:32 4024
                                int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4025
                                theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4026
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4027
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4028
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4029
                                twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4030
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4031
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4032
                                vsMode = false;
c96f480e sago007 2009-03-28 18:59 4033
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4034
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4035
                            }
89c4a3a6 sago007 2008-08-29 14:32 4036
                        }
89c4a3a6 sago007 2008-08-29 14:32 4037
                        if ( event.key.keysym.sym == SDLK_F6 )
89c4a3a6 sago007 2008-08-29 14:32 4038
                        {
2f30c381 sago007 2008-09-14 13:08 4039
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4040
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4041
                            #else
47529580 sago007 2008-12-09 02:34 4042
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4043
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4044
                            {
4f1d27f1 sago007 2011-03-18 15:53 4045
                                StartTwoPlayerVs();
89c4a3a6 sago007 2008-08-29 14:32 4046
                            }
89c4a3a6 sago007 2008-08-29 14:32 4047
                        }
89c4a3a6 sago007 2008-08-29 14:32 4048
                        if ( event.key.keysym.sym == SDLK_F4 )
89c4a3a6 sago007 2008-08-29 14:32 4049
                        {
2f30c381 sago007 2008-09-14 13:08 4050
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4051
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4052
                            #else
47529580 sago007 2008-12-09 02:34 4053
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4054
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4055
                            {
4f1d27f1 sago007 2011-03-18 15:53 4056
                                StarTwoPlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4057
                            }
89c4a3a6 sago007 2008-08-29 14:32 4058
                        }
89c4a3a6 sago007 2008-08-29 14:32 4059
                        if ( event.key.keysym.sym == SDLK_F7 )
89c4a3a6 sago007 2008-08-29 14:32 4060
                        {
2f30c381 sago007 2008-09-14 13:08 4061
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4062
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4063
                            #else
47529580 sago007 2008-12-09 02:34 4064
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4065
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4066
                            {
89c4a3a6 sago007 2008-08-29 14:32 4067
                                int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4068
                                theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4069
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4070
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4071
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4072
                                twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4073
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4074
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4075
                                vsMode = true;
c96f480e sago007 2009-03-28 18:59 4076
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4077
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4078
                            }
89c4a3a6 sago007 2008-08-29 14:32 4079
                        }
89c4a3a6 sago007 2008-08-29 14:32 4080
                        if ( event.key.keysym.sym == SDLK_F8 )
89c4a3a6 sago007 2008-08-29 14:32 4081
                        {
89c4a3a6 sago007 2008-08-29 14:32 4082
                        }
89c4a3a6 sago007 2008-08-29 14:32 4083
                        if ( event.key.keysym.sym == SDLK_F9 ) {
89c4a3a6 sago007 2008-08-29 14:32 4084
                            writeScreenShot();
89c4a3a6 sago007 2008-08-29 14:32 4085
                        }
89c4a3a6 sago007 2008-08-29 14:32 4086
                        if ( event.key.keysym.sym == SDLK_F11 ) {
89c4a3a6 sago007 2008-08-29 14:32 4087
                            /*This is the test place, place function to test here*/
89c4a3a6 sago007 2008-08-29 14:32 4088
89c4a3a6 sago007 2008-08-29 14:32 4089
                            //theGame.CreateGreyGarbage();
78d03b38 sago007 2008-11-13 19:56 4090
                            //char mitNavn[30];
78d03b38 sago007 2008-11-13 19:56 4091
                            //SelectThemeDialogbox(300,400,mitNavn);
b7590374 sago007 2011-05-19 16:15 4092
                           MainMenu();
b7590374 sago007 2011-05-19 16:15 4093
                            //OpenScoresDisplay();
89c4a3a6 sago007 2008-08-29 14:32 4094
                        } //F11
89c4a3a6 sago007 2008-08-29 14:32 4095
                    }
89c4a3a6 sago007 2008-08-29 14:32 4096
                    if ( event.key.keysym.sym == SDLK_F12 ) {
89c4a3a6 sago007 2008-08-29 14:32 4097
                        done=1;
89c4a3a6 sago007 2008-08-29 14:32 4098
                    }
89c4a3a6 sago007 2008-08-29 14:32 4099
                }
89c4a3a6 sago007 2008-08-29 14:32 4100
            } //while event PollEvent - read keys
89c4a3a6 sago007 2008-08-29 14:32 4101
89c4a3a6 sago007 2008-08-29 14:32 4102
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4103
            **************************** Repeating start **************************
89c4a3a6 sago007 2008-08-29 14:32 4104
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4105
89c4a3a6 sago007 2008-08-29 14:32 4106
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4107
//Also the joysticks:
89c4a3a6 sago007 2008-08-29 14:32 4108
//Repeating not implemented
89c4a3a6 sago007 2008-08-29 14:32 4109
89c4a3a6 sago007 2008-08-29 14:32 4110
//Player 1 start
89c4a3a6 sago007 2008-08-29 14:32 4111
            if (!(keys[keySettings[player1keys].up]))
30f910dd sago007 2010-11-10 21:02 4112
                repeatingN[0]=false;
30f910dd sago007 2010-11-10 21:02 4113
            while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4114
            {
89c4a3a6 sago007 2008-08-29 14:32 4115
                theGame.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4116
                timesRepeatedP1N++;
89c4a3a6 sago007 2008-08-29 14:32 4117
            }
89c4a3a6 sago007 2008-08-29 14:32 4118
89c4a3a6 sago007 2008-08-29 14:32 4119
            if (!(keys[keySettings[player1keys].down]))
30f910dd sago007 2010-11-10 21:02 4120
                repeatingS[0]=false;
30f910dd sago007 2010-11-10 21:02 4121
            while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4122
            {
89c4a3a6 sago007 2008-08-29 14:32 4123
                theGame.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4124
                timesRepeatedP1S++;
89c4a3a6 sago007 2008-08-29 14:32 4125
            }
89c4a3a6 sago007 2008-08-29 14:32 4126
89c4a3a6 sago007 2008-08-29 14:32 4127
            if (!(keys[keySettings[player1keys].left]))
30f910dd sago007 2010-11-10 21:02 4128
                repeatingW[0]=false;
30f910dd sago007 2010-11-10 21:02 4129
            while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4130
            {
89c4a3a6 sago007 2008-08-29 14:32 4131
                timesRepeatedP1W++;
89c4a3a6 sago007 2008-08-29 14:32 4132
                theGame.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4133
            }
89c4a3a6 sago007 2008-08-29 14:32 4134
89c4a3a6 sago007 2008-08-29 14:32 4135
            if (!(keys[keySettings[player1keys].right]))
30f910dd sago007 2010-11-10 21:02 4136
                repeatingE[0]=false;
30f910dd sago007 2010-11-10 21:02 4137
            while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4138
            {
89c4a3a6 sago007 2008-08-29 14:32 4139
                timesRepeatedP1E++;
89c4a3a6 sago007 2008-08-29 14:32 4140
                theGame.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4141
            }
89c4a3a6 sago007 2008-08-29 14:32 4142
89c4a3a6 sago007 2008-08-29 14:32 4143
//Player 1 end
89c4a3a6 sago007 2008-08-29 14:32 4144
89c4a3a6 sago007 2008-08-29 14:32 4145
//Player 2 start
89c4a3a6 sago007 2008-08-29 14:32 4146
            if (!(keys[keySettings[player2keys].up]))
30f910dd sago007 2010-11-10 21:02 4147
                repeatingN[1]=false;
30f910dd sago007 2010-11-10 21:02 4148
            while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4149
            {
89c4a3a6 sago007 2008-08-29 14:32 4150
                theGame2.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4151
                timesRepeatedP2N++;
89c4a3a6 sago007 2008-08-29 14:32 4152
            }
89c4a3a6 sago007 2008-08-29 14:32 4153
89c4a3a6 sago007 2008-08-29 14:32 4154
            if (!(keys[keySettings[player2keys].down]))
30f910dd sago007 2010-11-10 21:02 4155
                repeatingS[1]=false;
30f910dd sago007 2010-11-10 21:02 4156
            while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4157
            {
89c4a3a6 sago007 2008-08-29 14:32 4158
                theGame2.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4159
                timesRepeatedP2S++;
89c4a3a6 sago007 2008-08-29 14:32 4160
            }
89c4a3a6 sago007 2008-08-29 14:32 4161
89c4a3a6 sago007 2008-08-29 14:32 4162
            if (!(keys[keySettings[player2keys].left]))
30f910dd sago007 2010-11-10 21:02 4163
                repeatingW[1]=false;
30f910dd sago007 2010-11-10 21:02 4164
            while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4165
            {
89c4a3a6 sago007 2008-08-29 14:32 4166
                theGame2.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4167
                timesRepeatedP2W++;
89c4a3a6 sago007 2008-08-29 14:32 4168
            }
89c4a3a6 sago007 2008-08-29 14:32 4169
89c4a3a6 sago007 2008-08-29 14:32 4170
            if (!(keys[keySettings[player2keys].right]))
30f910dd sago007 2010-11-10 21:02 4171
                repeatingE[1]=false;
30f910dd sago007 2010-11-10 21:02 4172
            while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4173
            {
89c4a3a6 sago007 2008-08-29 14:32 4174
                theGame2.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4175
                timesRepeatedP2E++;
89c4a3a6 sago007 2008-08-29 14:32 4176
            }
89c4a3a6 sago007 2008-08-29 14:32 4177
89c4a3a6 sago007 2008-08-29 14:32 4178
//Player 2 end
89c4a3a6 sago007 2008-08-29 14:32 4179
89c4a3a6 sago007 2008-08-29 14:32 4180
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4181
            **************************** Repeating end ****************************
89c4a3a6 sago007 2008-08-29 14:32 4182
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4183
89c4a3a6 sago007 2008-08-29 14:32 4184
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4185
            ***************************** Joypad start ****************************
89c4a3a6 sago007 2008-08-29 14:32 4186
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4187
6d48320c sago007 2009-03-28 17:06 4188
            //Gameplay
89c4a3a6 sago007 2008-08-29 14:32 4189
            if (joyplay1||joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4190
            {
e1290bdf sago007 2010-10-25 19:56 4191
                if (joypad1.working && !theGame.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4192
                    if (joyplay1)
89c4a3a6 sago007 2008-08-29 14:32 4193
                    {
89c4a3a6 sago007 2008-08-29 14:32 4194
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4195
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4196
                        {
89c4a3a6 sago007 2008-08-29 14:32 4197
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4198
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4199
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4200
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4201
                        }
89c4a3a6 sago007 2008-08-29 14:32 4202
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4203
                        {
89c4a3a6 sago007 2008-08-29 14:32 4204
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4205
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4206
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4207
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4208
                        }
89c4a3a6 sago007 2008-08-29 14:32 4209
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4210
                        {
89c4a3a6 sago007 2008-08-29 14:32 4211
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4212
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4213
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4214
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4215
                        }
89c4a3a6 sago007 2008-08-29 14:32 4216
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4217
                        {
89c4a3a6 sago007 2008-08-29 14:32 4218
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4219
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4220
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4221
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4222
                        }
89c4a3a6 sago007 2008-08-29 14:32 4223
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4224
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4225
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4226
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4227
                    }
89c4a3a6 sago007 2008-08-29 14:32 4228
                    else
89c4a3a6 sago007 2008-08-29 14:32 4229
                    {
89c4a3a6 sago007 2008-08-29 14:32 4230
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4231
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4232
                        {
89c4a3a6 sago007 2008-08-29 14:32 4233
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4234
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4235
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4236
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4237
                        }
89c4a3a6 sago007 2008-08-29 14:32 4238
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4239
                        {
89c4a3a6 sago007 2008-08-29 14:32 4240
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4241
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4242
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4243
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4244
                        }
89c4a3a6 sago007 2008-08-29 14:32 4245
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4246
                        {
89c4a3a6 sago007 2008-08-29 14:32 4247
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4248
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4249
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4250
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4251
                        }
89c4a3a6 sago007 2008-08-29 14:32 4252
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4253
                        {
89c4a3a6 sago007 2008-08-29 14:32 4254
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4255
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4256
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4257
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4258
                        }
89c4a3a6 sago007 2008-08-29 14:32 4259
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4260
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4261
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4262
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4263
                    }
e1290bdf sago007 2010-10-25 19:56 4264
                if (joypad2.working && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4265
                    if (!joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4266
                    {
89c4a3a6 sago007 2008-08-29 14:32 4267
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4268
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4269
                        {
89c4a3a6 sago007 2008-08-29 14:32 4270
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4271
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4272
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4273
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4274
                        }
89c4a3a6 sago007 2008-08-29 14:32 4275
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4276
                        {
89c4a3a6 sago007 2008-08-29 14:32 4277
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4278
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4279
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4280
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4281
                        }
89c4a3a6 sago007 2008-08-29 14:32 4282
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4283
                        {
89c4a3a6 sago007 2008-08-29 14:32 4284
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4285
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4286
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4287
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4288
                        }
89c4a3a6 sago007 2008-08-29 14:32 4289
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4290
                        {
89c4a3a6 sago007 2008-08-29 14:32 4291
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4292
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4293
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4294
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4295
                        }
89c4a3a6 sago007 2008-08-29 14:32 4296
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4297
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4298
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4299
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4300
                    }
89c4a3a6 sago007 2008-08-29 14:32 4301
                    else
89c4a3a6 sago007 2008-08-29 14:32 4302
                    {
89c4a3a6 sago007 2008-08-29 14:32 4303
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4304
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4305
                        {
89c4a3a6 sago007 2008-08-29 14:32 4306
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4307
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4308
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4309
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4310
                        }
89c4a3a6 sago007 2008-08-29 14:32 4311
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4312
                        {
89c4a3a6 sago007 2008-08-29 14:32 4313
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4314
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4315
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4316
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4317
                        }
89c4a3a6 sago007 2008-08-29 14:32 4318
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4319
                        {
89c4a3a6 sago007 2008-08-29 14:32 4320
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4321
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4322
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4323
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4324
                        }
89c4a3a6 sago007 2008-08-29 14:32 4325
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4326
                        {
89c4a3a6 sago007 2008-08-29 14:32 4327
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4328
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4329
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4330
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4331
                        }
89c4a3a6 sago007 2008-08-29 14:32 4332
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4333
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4334
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4335
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4336
                    }
89c4a3a6 sago007 2008-08-29 14:32 4337
            }
89c4a3a6 sago007 2008-08-29 14:32 4338
89c4a3a6 sago007 2008-08-29 14:32 4339
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4340
            ***************************** Joypad end ******************************
89c4a3a6 sago007 2008-08-29 14:32 4341
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4342
89c4a3a6 sago007 2008-08-29 14:32 4343
89c4a3a6 sago007 2008-08-29 14:32 4344
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4345
b7590374 sago007 2011-05-19 16:15 4346
            SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 4347
89c4a3a6 sago007 2008-08-29 14:32 4348
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4349
            **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4350
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4351
e1290bdf sago007 2010-10-25 19:56 4352
            if ((mouseplay1)&&((!editorMode)&&(!theGame.GetAIenabled())||(editorModeTest))) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4353
                if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4354
                {
89c4a3a6 sago007 2008-08-29 14:32 4355
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4356
                    yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4357
                    xLine = (mousex-50+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4358
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4359
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4360
                    if ((yLine>10)&&(theGame.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4361
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4362
                    if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4363
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4364
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4365
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4366
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4367
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4368
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4369
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4370
                    theGame.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4371
                }
89c4a3a6 sago007 2008-08-29 14:32 4372
e1290bdf sago007 2010-10-25 19:56 4373
            if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4374
                if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4375
                {
89c4a3a6 sago007 2008-08-29 14:32 4376
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4377
                    yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4378
                    xLine = (mousex-(xsize-500)+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4379
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4380
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4381
                    if ((yLine>10)&&(theGame2.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4382
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4383
                    if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4384
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4385
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4386
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4387
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4388
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4389
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4390
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4391
                    theGame2.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4392
                }
89c4a3a6 sago007 2008-08-29 14:32 4393
89c4a3a6 sago007 2008-08-29 14:32 4394
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4395
            **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4396
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4397
89c4a3a6 sago007 2008-08-29 14:32 4398
            // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 4399
            if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 4400
            {
89c4a3a6 sago007 2008-08-29 14:32 4401
                bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 4402
            }
89c4a3a6 sago007 2008-08-29 14:32 4403
89c4a3a6 sago007 2008-08-29 14:32 4404
            // If the mouse button 2 is released, make bMouseUp2 equal true
89c4a3a6 sago007 2008-08-29 14:32 4405
            if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3))
89c4a3a6 sago007 2008-08-29 14:32 4406
            {
89c4a3a6 sago007 2008-08-29 14:32 4407
                bMouseUp2=true;
89c4a3a6 sago007 2008-08-29 14:32 4408
            }
89c4a3a6 sago007 2008-08-29 14:32 4409
89c4a3a6 sago007 2008-08-29 14:32 4410
            if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 4411
            {
89c4a3a6 sago007 2008-08-29 14:32 4412
                //read mouse events
89c4a3a6 sago007 2008-08-29 14:32 4413
                if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 4414
                {
89c4a3a6 sago007 2008-08-29 14:32 4415
                    bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 4416
                    DrawIMG(background, screen, 0, 0);
2f30c381 sago007 2008-09-14 13:08 4417
                    #if NETWORK
2f30c381 sago007 2008-09-14 13:08 4418
                    //Nothing
2f30c381 sago007 2008-09-14 13:08 4419
                    #else
2f30c381 sago007 2008-09-14 13:08 4420
                    bool networkActive=false;
2f30c381 sago007 2008-09-14 13:08 4421
                    #endif
9050a50a sago007 2008-12-09 13:35 4422
                    if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4423
                    {
89c4a3a6 sago007 2008-08-29 14:32 4424
                        //New game clicked
89c4a3a6 sago007 2008-08-29 14:32 4425
                        bool state = (!bNewGameOpen);
89c4a3a6 sago007 2008-08-29 14:32 4426
                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4427
                        bNewGameOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4428
                        showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4429
                    }
89c4a3a6 sago007 2008-08-29 14:32 4430
                    else
1572de2b sago007 2008-09-11 18:15 4431
#if NETWORK
9050a50a sago007 2008-12-09 13:35 4432
                        if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4433
                        {
89c4a3a6 sago007 2008-08-29 14:32 4434
                            //Disconnect clicked!
89c4a3a6 sago007 2008-08-29 14:32 4435
                            cout << "Disconnect clicked!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4436
                            nt.ntDisconnect();
89c4a3a6 sago007 2008-08-29 14:32 4437
                        }
89c4a3a6 sago007 2008-08-29 14:32 4438
                        else
89c4a3a6 sago007 2008-08-29 14:32 4439
#endif
9050a50a sago007 2008-12-09 13:35 4440
                            if ((0<mousex) && (mousex<buttonXsize) && (40<mousey) && (mousey<80) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4441
                            {
89c4a3a6 sago007 2008-08-29 14:32 4442
                                //1player
89c4a3a6 sago007 2008-08-29 14:32 4443
                                b1playerOpen = (!b1playerOpen);
89c4a3a6 sago007 2008-08-29 14:32 4444
                                b2playersOpen = false;
1572de2b sago007 2008-09-11 18:15 4445
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4446
                                bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4447
#endif
89c4a3a6 sago007 2008-08-29 14:32 4448
                            }
89c4a3a6 sago007 2008-08-29 14:32 4449
                            else
9050a50a sago007 2008-12-09 13:35 4450
                                if ((0<mousex) && (mousex<buttonXsize) && (80<mousey) && (mousey<120) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4451
                                {
89c4a3a6 sago007 2008-08-29 14:32 4452
                                    //2player
89c4a3a6 sago007 2008-08-29 14:32 4453
                                    b2playersOpen = (!b2playersOpen);
89c4a3a6 sago007 2008-08-29 14:32 4454
                                    b1playerOpen = false;
1572de2b sago007 2008-09-11 18:15 4455
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4456
                                    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4457
#endif
89c4a3a6 sago007 2008-08-29 14:32 4458
                                }
1572de2b sago007 2008-09-11 18:15 4459
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4460
                                else
9050a50a sago007 2008-12-09 13:35 4461
                                    if ((0<mousex) && (mousex<buttonXsize) && (120<mousey) && (mousey<160) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4462
                                    {
89c4a3a6 sago007 2008-08-29 14:32 4463
                                        //Network
89c4a3a6 sago007 2008-08-29 14:32 4464
                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4465
                                        b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4466
                                        bNetworkOpen = (!bNetworkOpen);
89c4a3a6 sago007 2008-08-29 14:32 4467
                                    }
89c4a3a6 sago007 2008-08-29 14:32 4468
#endif
89c4a3a6 sago007 2008-08-29 14:32 4469
                                    else
9050a50a sago007 2008-12-09 13:35 4470
                                        if ((buttonXsize<mousex) && (mousex<240) && (40<mousey) && (mousey<80) && (b1playerOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4471
                                        {
30f910dd sago007 2010-11-10 21:02 4472
                                            StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 4473
                                        }
89c4a3a6 sago007 2008-08-29 14:32 4474
                                        else
9050a50a sago007 2008-12-09 13:35 4475
                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b1playerOpen) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4476
                                            {
4f1d27f1 sago007 2011-03-18 15:53 4477
                                                StartSinglePlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4478
                                            }
89c4a3a6 sago007 2008-08-29 14:32 4479
                                            else
9050a50a sago007 2008-12-09 13:35 4480
                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b1playerOpen)&&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4481
                                                {
89c4a3a6 sago007 2008-08-29 14:32 4482
                                                    //1 player - stage clear
89c4a3a6 sago007 2008-08-29 14:32 4483
                                                    bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4484
                                                    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4485
                                                    int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4486
                                                    theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4487
                                                    MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4488
                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4489
                                                    twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4490
                                                    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4491
                                                    showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4492
                                                    vsMode = false;
c96f480e sago007 2009-03-28 18:59 4493
                                                    strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4494
                                                    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4495
                                                }
89c4a3a6 sago007 2008-08-29 14:32 4496
                                                else
9050a50a sago007 2008-12-09 13:35 4497
                                                    if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4498
                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4499
                                                        //1 player - puzzle
89c4a3a6 sago007 2008-08-29 14:32 4500
                                                        bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4501
                                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4502
                                                        int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4503
                                                        theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4504
                                                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4505
                                                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4506
                                                        twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4507
                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4508
                                                        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4509
                                                        vsMode = false;
c96f480e sago007 2009-03-28 18:59 4510
                                                        strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4511
                                                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4512
                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4513
                                                    else
9050a50a sago007 2008-12-09 13:35 4514
                                                        if ((buttonXsize<mousex) && (mousex<240) && (200<mousey) && (mousey<240) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4515
                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4516
                                                            //1 player - Vs mode
89c4a3a6 sago007 2008-08-29 14:32 4517
                                                            bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4518
                                                            b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4519
                                                            int theAIlevel = startSingleVs();
e1290bdf sago007 2010-10-25 19:56 4520
                                                            theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4521
                                                            theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4522
                                                            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4523
                                                            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4524
                                                            twoPlayers = true; //Single player, but AI plays
89c4a3a6 sago007 2008-08-29 14:32 4525
                                                            showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4526
                                                            vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 4527
                                                            theGame2.setAIlevel((Uint8)theAIlevel);
89c4a3a6 sago007 2008-08-29 14:32 4528
                                                            int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4529
                                                            theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4530
                                                            theGame2.putStartBlocks(theTime);
c96f480e sago007 2009-03-28 18:59 4531
                                                            strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4532
                                                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4533
                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4534
                                                        else
9050a50a sago007 2008-12-09 13:35 4535
                                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4536
                                                            {
4f1d27f1 sago007 2011-03-18 15:53 4537
                                                                StarTwoPlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4538
                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4539
                                                            else
9050a50a sago007 2008-12-09 13:35 4540
                                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4541
                                                                {
4f1d27f1 sago007 2011-03-18 15:53 4542
                                                                    StartTwoPlayerVs();
89c4a3a6 sago007 2008-08-29 14:32 4543
                                                                }
1572de2b sago007 2008-09-11 18:15 4544
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4545
                                                                else
9050a50a sago007 2008-12-09 13:35 4546
                                                                    if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4547
                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4548
                                                                        //Host
89c4a3a6 sago007 2008-08-29 14:32 4549
                                                                        cout << "Host" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4550
                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4551
                                                                        theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4552
                                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4553
                                                                        nt.startServer();
89c4a3a6 sago007 2008-08-29 14:32 4554
                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4555
                                                                    else
9050a50a sago007 2008-12-09 13:35 4556
                                                                        if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4557
                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4558
                                                                            //Connect
89c4a3a6 sago007 2008-08-29 14:32 4559
                                                                            cout << "Connect" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4560
                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4561
                                                                            theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4562
                                                                            theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4563
                                                                            if (OpenDialogbox(200,100,serverAddress))
89c4a3a6 sago007 2008-08-29 14:32 4564
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4565
                                                                                char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4566
                                                                                memcpy(buf,serverAddress,30);
89c4a3a6 sago007 2008-08-29 14:32 4567
                                                                                nt.connectToServer(strtok(buf," "));
89c4a3a6 sago007 2008-08-29 14:32 4568
                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4569
                                                                            while ( SDL_PollEvent(&event) ); //If the user have pressed ESC or the like
89c4a3a6 sago007 2008-08-29 14:32 4570
                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4571
#endif
89c4a3a6 sago007 2008-08-29 14:32 4572
                                                                        else
9050a50a sago007 2008-12-09 13:35 4573
                                                                            if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4574
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4575
                                                                                //options button clicked
89c4a3a6 sago007 2008-08-29 14:32 4576
                                                                                if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 4577
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4578
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4579
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4580
                                                                                else
89c4a3a6 sago007 2008-08-29 14:32 4581
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4582
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4583
                                                                                    bOptionsOpen = true;
89c4a3a6 sago007 2008-08-29 14:32 4584
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4585
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4586
                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4587
                                                                            else
9050a50a sago007 2008-12-09 13:35 4588
                                                                                if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (40<mousey) && (mousey<80) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4589
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4590
                                                                                    //Configure button clicked
89c4a3a6 sago007 2008-08-29 14:32 4591
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4592
                                                                                    if (!showOptions) {
89c4a3a6 sago007 2008-08-29 14:32 4593
                                                                                        showOptions = true;
89c4a3a6 sago007 2008-08-29 14:32 4594
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4595
                                                                                    else showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4596
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4597
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4598
                                                                                else
9050a50a sago007 2008-12-09 13:35 4599
                                                                                    if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (80<mousey) && (mousey<120) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4600
                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4601
                                                                                        //Configure button clicked
89c4a3a6 sago007 2008-08-29 14:32 4602
                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4603
                                                                                        changePuzzleLevels();
89c4a3a6 sago007 2008-08-29 14:32 4604
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4605
                                                                                    else
9050a50a sago007 2008-12-09 13:35 4606
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (120<mousey) && (mousey<160) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4607
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4608
                                                                                            //vsMode button clicked
89c4a3a6 sago007 2008-08-29 14:32 4609
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4610
                                                                                            startVsMenu();
89c4a3a6 sago007 2008-08-29 14:32 4611
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4612
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4613
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (160<mousey) && (mousey<200) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4614
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4615
                                                                                            //selectThemClicked
89c4a3a6 sago007 2008-08-29 14:32 4616
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4617
                                                                                            char temp[30];
89c4a3a6 sago007 2008-08-29 14:32 4618
                                                                                            SelectThemeDialogbox(200,100,temp);
89c4a3a6 sago007 2008-08-29 14:32 4619
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4620
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4621
                                                                                            if ((buttonXsize*2<mousex) && (mousex<3*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4622
                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4623
                                                                                                //highscore button clicked
47529580 sago007 2008-12-09 02:34 4624
                                                                                                OpenScoresDisplay();
47529580 sago007 2008-12-09 02:34 4625
89c4a3a6 sago007 2008-08-29 14:32 4626
                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4627
                                                                                            else
9050a50a sago007 2008-12-09 13:35 4628
                                                                                                if ((360<mousex) && (mousex<4*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4629
                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4630
                                                                                                    //Replay clicked!
89c4a3a6 sago007 2008-08-29 14:32 4631
                                                                                                    bool state = (!bReplayOpen);
89c4a3a6 sago007 2008-08-29 14:32 4632
                                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4633
                                                                                                    bReplayOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4634
                                                                                                    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4635
                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4636
                                                                                                else
9050a50a sago007 2008-12-09 13:35 4637
                                                                                                    if ((360<mousex) && (mousex<4*buttonXsize) && (40<mousey) && (mousey<80) &&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4638
                                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4639
                                                                                                        //Replay->Save clicked!
89c4a3a6 sago007 2008-08-29 14:32 4640
                                                                                                        //cout << "Replay->Save clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4641
                                                                                                        char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4642
                                                                                                        for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4643
                                                                                                        buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4644
                                                                                                        OpenDialogbox(200,100,buf);
89c4a3a6 sago007 2008-08-29 14:32 4645
                                                                                                        for (int i=28;buf[i]==' ';i--)
89c4a3a6 sago007 2008-08-29 14:32 4646
                                                                                                            buf[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 4647
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 4648
                                                                                                        string saveHere = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4649
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 4650
                                                                                                        string saveHere = home+(string)"/My Games/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4651
#else
89c4a3a6 sago007 2008-08-29 14:32 4652
                                                                                                        string saveHere = (string)"./replays"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4653
#endif
89c4a3a6 sago007 2008-08-29 14:32 4654
                                                                                                        if (lastNrOfPlayers<2)
89c4a3a6 sago007 2008-08-29 14:32 4655
                                                                                                            theGame.theReplay.saveReplay(saveHere);
89c4a3a6 sago007 2008-08-29 14:32 4656
                                                                                                        else
89c4a3a6 sago007 2008-08-29 14:32 4657
                                                                                                            theGame.theReplay.saveReplay(saveHere,theGame2.theReplay);
89c4a3a6 sago007 2008-08-29 14:32 4658
89c4a3a6 sago007 2008-08-29 14:32 4659
                                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4660
                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4661
                                                                                                    else
9050a50a sago007 2008-12-09 13:35 4662
                                                                                                        if ((360<mousex) && (mousex<4*buttonXsize) && (80<mousey) && (mousey<120)&&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4663
                                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4664
                                                                                                            //Replay->Load clicked!
89c4a3a6 sago007 2008-08-29 14:32 4665
                                                                                                            //cout << "Replay->Load clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4666
89c4a3a6 sago007 2008-08-29 14:32 4667
                                                                                                            char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4668
                                                                                                            for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4669
                                                                                                            buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4670
                                                                                                            if (OpenReplayDialogbox(50,100,buf))
89c4a3a6 sago007 2008-08-29 14:32 4671
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4672
                                                                                                                //cout << "Good way" << endl;
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 loadThis = (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 loadThis = 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 loadThis = (string)"./replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4681
#endif
89c4a3a6 sago007 2008-08-29 14:32 4682
                                                                                                                ifstream replayFileIn;
89c4a3a6 sago007 2008-08-29 14:32 4683
                                                                                                                replayFileIn.open(loadThis.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 4684
                                                                                                                bool play2 = false;
89c4a3a6 sago007 2008-08-29 14:32 4685
                                                                                                                if (replayFileIn)
89c4a3a6 sago007 2008-08-29 14:32 4686
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4687
                                                                                                                    Uint8 version = 0;
89c4a3a6 sago007 2008-08-29 14:32 4688
                                                                                                                    replayFileIn.read(reinterpret_cast<char*>(&version),sizeof(Uint8));                                                                                                                  replayFileIn.close();
89c4a3a6 sago007 2008-08-29 14:32 4689
                                                                                                                    Replay r1;
e03ae476 sago007 2009-03-06 22:49 4690
                                                                                                                    if(r1.loadReplay(loadThis))
89c4a3a6 sago007 2008-08-29 14:32 4691
                                                                                                                    {
e03ae476 sago007 2009-03-06 22:49 4692
                                                                                                                        Replay r2;
e03ae476 sago007 2009-03-06 22:49 4693
                                                                                                                        play2 = r2.loadReplay2(loadThis);
e1290bdf sago007 2010-10-25 19:56 4694
                                                                                                                        theGame.playReplay(50,100,SDL_GetTicks()); //Fejlen sker her
e03ae476 sago007 2009-03-06 22:49 4695
                                                                                                                        theGame.theReplay = r1;
e03ae476 sago007 2009-03-06 22:49 4696
                                                                                                                        if (play2)
e03ae476 sago007 2009-03-06 22:49 4697
                                                                                                                        {
e1290bdf sago007 2010-10-25 19:56 4698
                                                                                                                            theGame2.playReplay(xsize-500,100,SDL_GetTicks());
e03ae476 sago007 2009-03-06 22:49 4699
                                                                                                                            theGame2.theReplay = r2;
e03ae476 sago007 2009-03-06 22:49 4700
                                                                                                                        }
e03ae476 sago007 2009-03-06 22:49 4701
                                                                                                                        else
e03ae476 sago007 2009-03-06 22:49 4702
                                                                                                                            theGame2.SetGameOver();
e03ae476 sago007 2009-03-06 22:49 4703
                                                                                                                        cout << "Replay should have been read" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4704
                                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4705
                                                                                                                    else
e03ae476 sago007 2009-03-06 22:49 4706
                                                                                                                        cout << "Failed to read replay" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4707
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4708
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4709
                                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4710
                                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4711
                                                                                                        else
9050a50a sago007 2008-12-09 13:35 4712
                                                                                                            if ((xsize-120<mousex) && (xsize-20>mousex) && (ysize-buttonXsize<mousey) && (ysize-20>mousey))
89c4a3a6 sago007 2008-08-29 14:32 4713
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4714
                                                                                                                //Exit clicked
89c4a3a6 sago007 2008-08-29 14:32 4715
                                                                                                                done=1;
89c4a3a6 sago007 2008-08-29 14:32 4716
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4717
                                                                                                            else
89c4a3a6 sago007 2008-08-29 14:32 4718
                                                                                                                if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>220) && (mousey<260))
89c4a3a6 sago007 2008-08-29 14:32 4719
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4720
                                                                                                                    MusicEnabled = !MusicEnabled;
89c4a3a6 sago007 2008-08-29 14:32 4721
                                                                                                                    if (!MusicEnabled) Mix_FadeOutMusic(500);
89c4a3a6 sago007 2008-08-29 14:32 4722
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4723
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>270) && (mousey<310))
89c4a3a6 sago007 2008-08-29 14:32 4724
                    {
89c4a3a6 sago007 2008-08-29 14:32 4725
                        SoundEnabled = !SoundEnabled;
89c4a3a6 sago007 2008-08-29 14:32 4726
                    }
89c4a3a6 sago007 2008-08-29 14:32 4727
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>320) && (mousey<360))
89c4a3a6 sago007 2008-08-29 14:32 4728
                    {
89c4a3a6 sago007 2008-08-29 14:32 4729
                        //Fullscreen
89c4a3a6 sago007 2008-08-29 14:32 4730
                        bFullscreen = !bFullscreen;
89c4a3a6 sago007 2008-08-29 14:32 4731
#if defined(WIN32)
89c4a3a6 sago007 2008-08-29 14:32 4732
                        if (bFullscreen) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 4733
                        else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 4734
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4735
#else
89c4a3a6 sago007 2008-08-29 14:32 4736
                        SDL_WM_ToggleFullScreen(screen); //Will only work in Linux
89c4a3a6 sago007 2008-08-29 14:32 4737
#endif
89c4a3a6 sago007 2008-08-29 14:32 4738
                        SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 4739
                    }
89c4a3a6 sago007 2008-08-29 14:32 4740
89c4a3a6 sago007 2008-08-29 14:32 4741
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 4742
                    {
89c4a3a6 sago007 2008-08-29 14:32 4743
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 4744
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 4745
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 4746
                        strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 4747
                        if (OpenDialogbox(200,100,player1name))
89c4a3a6 sago007 2008-08-29 14:32 4748
                            strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 4749
                        else
89c4a3a6 sago007 2008-08-29 14:32 4750
                            strcpy(player1name,theGame.name);
89c4a3a6 sago007 2008-08-29 14:32 4751
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 4752
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 4753
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4754
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4755
                    }
89c4a3a6 sago007 2008-08-29 14:32 4756
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 4757
                    {
89c4a3a6 sago007 2008-08-29 14:32 4758
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 4759
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 4760
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 4761
                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4762
                        if (OpenDialogbox(200,100,player2name))
89c4a3a6 sago007 2008-08-29 14:32 4763
                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4764
                        else
89c4a3a6 sago007 2008-08-29 14:32 4765
                            strcpy(player2name,theGame2.name);
89c4a3a6 sago007 2008-08-29 14:32 4766
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 4767
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 4768
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4769
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4770
                    }
89c4a3a6 sago007 2008-08-29 14:32 4771
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 4772
                    {
89c4a3a6 sago007 2008-08-29 14:32 4773
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 4774
                        OpenControlsBox(200,100,0);
e1290bdf sago007 2010-10-25 19:56 4775
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4776
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4777
                    }
89c4a3a6 sago007 2008-08-29 14:32 4778
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 4779
                    {
89c4a3a6 sago007 2008-08-29 14:32 4780
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 4781
                        OpenControlsBox(200,100,2);
e1290bdf sago007 2010-10-25 19:56 4782
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4783
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4784
                    }
89c4a3a6 sago007 2008-08-29 14:32 4785
89c4a3a6 sago007 2008-08-29 14:32 4786
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4787
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4788
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 4789
                    if ((!showOptions))
89c4a3a6 sago007 2008-08-29 14:32 4790
                    {
e1290bdf sago007 2010-10-25 19:56 4791
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4792
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4793
                            {
89c4a3a6 sago007 2008-08-29 14:32 4794
                                theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4795
                            }
e1290bdf sago007 2010-10-25 19:56 4796
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4797
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4798
                            {
89c4a3a6 sago007 2008-08-29 14:32 4799
                                theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4800
                            }
89c4a3a6 sago007 2008-08-29 14:32 4801
                    }
89c4a3a6 sago007 2008-08-29 14:32 4802
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4803
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4804
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4805
e1290bdf sago007 2010-10-25 19:56 4806
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
e1290bdf sago007 2010-10-25 19:56 4807
                            &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
e1290bdf sago007 2010-10-25 19:56 4808
                            &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 4809
                    {
89c4a3a6 sago007 2008-08-29 14:32 4810
                        //Clicked the next button after a stage clear or puzzle
e1290bdf sago007 2010-10-25 19:56 4811
                        theGame.nextLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4812
                    }
e1290bdf sago007 2010-10-25 19:56 4813
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
e1290bdf sago007 2010-10-25 19:56 4814
                            &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
e1290bdf sago007 2010-10-25 19:56 4815
                            &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 4816
                    {
89c4a3a6 sago007 2008-08-29 14:32 4817
                        //Clicked the retry button
e1290bdf sago007 2010-10-25 19:56 4818
                        theGame.retryLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4819
                    }
89c4a3a6 sago007 2008-08-29 14:32 4820
                        
89c4a3a6 sago007 2008-08-29 14:32 4821
                    
89c4a3a6 sago007 2008-08-29 14:32 4822
                    //cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
89c4a3a6 sago007 2008-08-29 14:32 4823
                }
89c4a3a6 sago007 2008-08-29 14:32 4824
89c4a3a6 sago007 2008-08-29 14:32 4825
                //Mouse button 2:
89c4a3a6 sago007 2008-08-29 14:32 4826
                if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2)
89c4a3a6 sago007 2008-08-29 14:32 4827
                {
89c4a3a6 sago007 2008-08-29 14:32 4828
                    bMouseUp2=false; //The button is pressed
89c4a3a6 sago007 2008-08-29 14:32 4829
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4830
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4831
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 4832
                    if (!showOptions)
89c4a3a6 sago007 2008-08-29 14:32 4833
                    {
e1290bdf sago007 2010-10-25 19:56 4834
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4835
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4836
                            {
89c4a3a6 sago007 2008-08-29 14:32 4837
                                theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4838
                            }
e1290bdf sago007 2010-10-25 19:56 4839
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4840
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4841
                            {
89c4a3a6 sago007 2008-08-29 14:32 4842
                                theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4843
                            }
89c4a3a6 sago007 2008-08-29 14:32 4844
                    }
89c4a3a6 sago007 2008-08-29 14:32 4845
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4846
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4847
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4848
                }
89c4a3a6 sago007 2008-08-29 14:32 4849
            } //if !singlePuzzle
89c4a3a6 sago007 2008-08-29 14:32 4850
            else
89c4a3a6 sago007 2008-08-29 14:32 4851
            {
89c4a3a6 sago007 2008-08-29 14:32 4852
89c4a3a6 sago007 2008-08-29 14:32 4853
            }
89c4a3a6 sago007 2008-08-29 14:32 4854
        } //if !bScreenBocked;
89c4a3a6 sago007 2008-08-29 14:32 4855
89c4a3a6 sago007 2008-08-29 14:32 4856
89c4a3a6 sago007 2008-08-29 14:32 4857
        //Sees if music is stopped and if music is enabled
6d48320c sago007 2009-03-28 17:06 4858
        if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath))
89c4a3a6 sago007 2008-08-29 14:32 4859
        {
89c4a3a6 sago007 2008-08-29 14:32 4860
            // then starts playing it.
6d48320c sago007 2009-03-28 17:06 4861
            Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4862
            Mix_PlayMusic(bgMusic, -1); //music loop
89c4a3a6 sago007 2008-08-29 14:32 4863
        }
89c4a3a6 sago007 2008-08-29 14:32 4864
6d48320c sago007 2009-03-28 17:06 4865
        if(bNearDeath!=bNearDeathPrev)
6d48320c sago007 2009-03-28 17:06 4866
        {
6d48320c sago007 2009-03-28 17:06 4867
            if(bNearDeath)
6d48320c sago007 2009-03-28 17:06 4868
            {
6d48320c sago007 2009-03-28 17:06 4869
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 4870
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4871
                    Mix_PlayMusic(highbeatMusic, 1);
6d48320c sago007 2009-03-28 17:06 4872
                }
6d48320c sago007 2009-03-28 17:06 4873
            }
6d48320c sago007 2009-03-28 17:06 4874
            else
6d48320c sago007 2009-03-28 17:06 4875
            {
6d48320c sago007 2009-03-28 17:06 4876
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 4877
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4878
                    Mix_PlayMusic(bgMusic, -1);
6d48320c sago007 2009-03-28 17:06 4879
                }
6d48320c sago007 2009-03-28 17:06 4880
            }
6d48320c sago007 2009-03-28 17:06 4881
        }
6d48320c sago007 2009-03-28 17:06 4882
6d48320c sago007 2009-03-28 17:06 4883
        bNearDeathPrev = bNearDeath;
6d48320c sago007 2009-03-28 17:06 4884
6d48320c sago007 2009-03-28 17:06 4885
6d48320c sago007 2009-03-28 17:06 4886
        //set bNearDeath to false theGame*.Update() will change to true as needed
6d48320c sago007 2009-03-28 17:06 4887
        bNearDeath = false;
89c4a3a6 sago007 2008-08-29 14:32 4888
        //Updates the objects
e1290bdf sago007 2010-10-25 19:56 4889
        theGame.Update(SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4890
        theGame2.Update(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4891
89c4a3a6 sago007 2008-08-29 14:32 4892
//see if anyone has won (two players only)
2f30c381 sago007 2008-09-14 13:08 4893
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4894
        if (!networkPlay)
2f30c381 sago007 2008-09-14 13:08 4895
        #endif
89c4a3a6 sago007 2008-08-29 14:32 4896
            if (twoPlayers)
89c4a3a6 sago007 2008-08-29 14:32 4897
            {
89c4a3a6 sago007 2008-08-29 14:32 4898
                lastNrOfPlayers = 2;
e1290bdf sago007 2010-10-25 19:56 4899
                if ((theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4900
                {
e1290bdf sago007 2010-10-25 19:56 4901
                    if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 4902
                        theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4903
                    else
e1290bdf sago007 2010-10-25 19:56 4904
                        if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 4905
                            theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4906
                        else {
89c4a3a6 sago007 2008-08-29 14:32 4907
                            theGame.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 4908
                            theGame2.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 4909
                        }
89c4a3a6 sago007 2008-08-29 14:32 4910
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4911
                }
e1290bdf sago007 2010-10-25 19:56 4912
                if ((theGame.isGameOver()) && (!theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4913
                {
89c4a3a6 sago007 2008-08-29 14:32 4914
                    theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4915
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4916
                }
e1290bdf sago007 2010-10-25 19:56 4917
                if ((!theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4918
                {
89c4a3a6 sago007 2008-08-29 14:32 4919
                    theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4920
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4921
                }
89c4a3a6 sago007 2008-08-29 14:32 4922
            }
89c4a3a6 sago007 2008-08-29 14:32 4923
89c4a3a6 sago007 2008-08-29 14:32 4924
        //Once evrything has been checked, update graphics
e1290bdf sago007 2010-10-25 19:56 4925
        DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4926
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 4927
        //Remember mouse placement
89c4a3a6 sago007 2008-08-29 14:32 4928
        oldMousex = mousex;
89c4a3a6 sago007 2008-08-29 14:32 4929
        oldMousey = mousey;
89c4a3a6 sago007 2008-08-29 14:32 4930
        //Draw the mouse:
8d488d32 sago007 2011-04-17 13:02 4931
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 4932
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 4933
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 4934
    } //game loop
89c4a3a6 sago007 2008-08-29 14:32 4935
89c4a3a6 sago007 2008-08-29 14:32 4936
89c4a3a6 sago007 2008-08-29 14:32 4937
89c4a3a6 sago007 2008-08-29 14:32 4938
    //Saves options
89c4a3a6 sago007 2008-08-29 14:32 4939
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 4940
    {
769a41a0 sago007 2008-09-24 12:54 4941
        configSettings->setInt("fullscreen",(int)bFullscreen);
769a41a0 sago007 2008-09-24 12:54 4942
        configSettings->setInt("musicenabled",(int)MusicEnabled);
769a41a0 sago007 2008-09-24 12:54 4943
        configSettings->setInt("soundenabled",(int)SoundEnabled);
769a41a0 sago007 2008-09-24 12:54 4944
        configSettings->setInt("mouseplay1",(int)mouseplay1);
769a41a0 sago007 2008-09-24 12:54 4945
        configSettings->setInt("mouseplay2",(int)mouseplay2);
769a41a0 sago007 2008-09-24 12:54 4946
        configSettings->setInt("joypad1",(int)joyplay1);
769a41a0 sago007 2008-09-24 12:54 4947
        configSettings->setInt("joypad2",(int)joyplay2);
769a41a0 sago007 2008-09-24 12:54 4948
        
769a41a0 sago007 2008-09-24 12:54 4949
        configSettings->setInt("player1keyup",(int)keySettings[0].up);
769a41a0 sago007 2008-09-24 12:54 4950
        configSettings->setInt("player1keydown",(int)keySettings[0].down);
769a41a0 sago007 2008-09-24 12:54 4951
        configSettings->setInt("player1keyleft",(int)keySettings[0].left);
769a41a0 sago007 2008-09-24 12:54 4952
        configSettings->setInt("player1keyright",(int)keySettings[0].right);
769a41a0 sago007 2008-09-24 12:54 4953
        configSettings->setInt("player1keychange",(int)keySettings[0].change);
769a41a0 sago007 2008-09-24 12:54 4954
        configSettings->setInt("player1keypush",(int)keySettings[0].push);
769a41a0 sago007 2008-09-24 12:54 4955
        
769a41a0 sago007 2008-09-24 12:54 4956
        configSettings->setInt("player2keyup",(int)keySettings[2].up);
769a41a0 sago007 2008-09-24 12:54 4957
        configSettings->setInt("player2keydown",(int)keySettings[2].down);
769a41a0 sago007 2008-09-24 12:54 4958
        configSettings->setInt("player2keyleft",(int)keySettings[2].left);
769a41a0 sago007 2008-09-24 12:54 4959
        configSettings->setInt("player2keyright",(int)keySettings[2].right);
769a41a0 sago007 2008-09-24 12:54 4960
        configSettings->setInt("player2keychange",(int)keySettings[2].change);
769a41a0 sago007 2008-09-24 12:54 4961
        configSettings->setInt("player2keypush",(int)keySettings[2].push);
769a41a0 sago007 2008-09-24 12:54 4962
        
769a41a0 sago007 2008-09-24 12:54 4963
        configSettings->setString("player1name",player1name);
769a41a0 sago007 2008-09-24 12:54 4964
        configSettings->setString("player2name",player2name);
769a41a0 sago007 2008-09-24 12:54 4965
        configSettings->save();
89c4a3a6 sago007 2008-08-29 14:32 4966
    }
89c4a3a6 sago007 2008-08-29 14:32 4967
89c4a3a6 sago007 2008-08-29 14:32 4968
    //calculate uptime:
c09d0e4f sago007 2009-01-27 01:15 4969
    //int hours, mins, secs,
cd12e0fe sago007 2009-01-29 08:47 4970
    commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4971
89c4a3a6 sago007 2008-08-29 14:32 4972
    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 4973
cd12e0fe sago007 2009-01-29 08:47 4974
    ct = TimeHandler::addTime("totalTime",ct);
c09d0e4f sago007 2009-01-27 01:15 4975
89c4a3a6 sago007 2008-08-29 14:32 4976
    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 4977
c09d0e4f sago007 2009-01-27 01:15 4978
    Stats::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 4979
c09d0e4f sago007 2009-01-27 01:15 4980
    Config::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 4981
    
c09d0e4f sago007 2009-01-27 01:15 4982
    //Frees memory from music and fonts
c09d0e4f sago007 2009-01-27 01:15 4983
    //This is done after writing of configurations and stats since it often crashes the program :(
c09d0e4f sago007 2009-01-27 01:15 4984
    UnloadImages();
41f02ab2 sago007 2009-05-10 21:40 4985
      
91886cae sago007 2008-09-12 16:28 4986
    //Close file system Apstraction layer!
91886cae sago007 2008-09-12 16:28 4987
    PHYSFS_deinit();
89c4a3a6 sago007 2008-08-29 14:32 4988
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 4989
}
b7590374 sago007 2011-05-19 16:15 4990
b7590374 sago007 2011-05-19 16:15 4991
b7590374 sago007 2011-05-19 16:15 4992
void runGame(int gametype) {
b7590374 sago007 2011-05-19 16:15 4993
    Uint8 *keys;
b7590374 sago007 2011-05-19 16:15 4994
     int mousex, mousey;   //Mouse coordinates
b7590374 sago007 2011-05-19 16:15 4995
    showOptions = false;
b7590374 sago007 2011-05-19 16:15 4996
    b1playerOpen = false;
b7590374 sago007 2011-05-19 16:15 4997
    b2playersOpen = false;
b7590374 sago007 2011-05-19 16:15 4998
    bReplayOpen = false;
b7590374 sago007 2011-05-19 16:15 4999
    bScreenLocked = false;
b7590374 sago007 2011-05-19 16:15 5000
    bool vsMode = false;
b7590374 sago007 2011-05-19 16:15 5001
    theTopScoresEndless = Highscore(1);
b7590374 sago007 2011-05-19 16:15 5002
    theTopScoresTimeTrial = Highscore(2);
b7590374 sago007 2011-05-19 16:15 5003
    drawBalls = true;
b7590374 sago007 2011-05-19 16:15 5004
    puzzleLoaded = false;
b7590374 sago007 2011-05-19 16:15 5005
    bool weWhereConnected = false;
b7590374 sago007 2011-05-19 16:15 5006
b7590374 sago007 2011-05-19 16:15 5007
    //Things used for repeating keystrokes:
b7590374 sago007 2011-05-19 16:15 5008
    bool repeatingS[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 5009
    bool repeatingW[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 5010
    bool repeatingN[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 5011
    bool repeatingE[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 5012
    const int startRepeat = 200;
b7590374 sago007 2011-05-19 16:15 5013
    const int repeatDelay = 100;    //Repeating
b7590374 sago007 2011-05-19 16:15 5014
    unsigned long timeHeldP1N = 0;
b7590374 sago007 2011-05-19 16:15 5015
    unsigned long timeHeldP1S = 0;
b7590374 sago007 2011-05-19 16:15 5016
    unsigned long timeHeldP1E = 0;
b7590374 sago007 2011-05-19 16:15 5017
    unsigned long timeHeldP1W = 0;
b7590374 sago007 2011-05-19 16:15 5018
    unsigned long timeHeldP2N = 0;
b7590374 sago007 2011-05-19 16:15 5019
    unsigned long timeHeldP2S = 0;
b7590374 sago007 2011-05-19 16:15 5020
    unsigned long timeHeldP2E = 0;
b7590374 sago007 2011-05-19 16:15 5021
    unsigned long timeHeldP2W = 0;
b7590374 sago007 2011-05-19 16:15 5022
    unsigned long timesRepeatedP1N = 0;
b7590374 sago007 2011-05-19 16:15 5023
    unsigned long timesRepeatedP1S = 0;
b7590374 sago007 2011-05-19 16:15 5024
    unsigned long timesRepeatedP1E = 0;
b7590374 sago007 2011-05-19 16:15 5025
    unsigned long timesRepeatedP1W = 0;
b7590374 sago007 2011-05-19 16:15 5026
    unsigned long timesRepeatedP2N = 0;
b7590374 sago007 2011-05-19 16:15 5027
    unsigned long timesRepeatedP2S = 0;
b7590374 sago007 2011-05-19 16:15 5028
    unsigned long timesRepeatedP2E = 0;
b7590374 sago007 2011-05-19 16:15 5029
    unsigned long timesRepeatedP2W = 0;
b7590374 sago007 2011-05-19 16:15 5030
b7590374 sago007 2011-05-19 16:15 5031
    theBallManeger = ballManeger();
b7590374 sago007 2011-05-19 16:15 5032
    theExplosionManeger = explosionManeger();
b7590374 sago007 2011-05-19 16:15 5033
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
b7590374 sago007 2011-05-19 16:15 5034
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
b7590374 sago007 2011-05-19 16:15 5035
    player1 = &theGame;
b7590374 sago007 2011-05-19 16:15 5036
    player2 = &theGame2;
b7590374 sago007 2011-05-19 16:15 5037
    /*if (singlePuzzle)
b7590374 sago007 2011-05-19 16:15 5038
    {
b7590374 sago007 2011-05-19 16:15 5039
        theGame.GetTopY()=0;
b7590374 sago007 2011-05-19 16:15 5040
        theGame.GetTopX()=0;
b7590374 sago007 2011-05-19 16:15 5041
        theGame2.GetTopY()=10000;
b7590374 sago007 2011-05-19 16:15 5042
        theGame2.GetTopX()=10000;
b7590374 sago007 2011-05-19 16:15 5043
    }*/
b7590374 sago007 2011-05-19 16:15 5044
    theGame.DoPaintJob();			//Makes sure what there is something to paint
b7590374 sago007 2011-05-19 16:15 5045
    theGame2.DoPaintJob();
b7590374 sago007 2011-05-19 16:15 5046
    theGame.SetGameOver();		//sets the game over in the beginning
b7590374 sago007 2011-05-19 16:15 5047
    theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 5048
b7590374 sago007 2011-05-19 16:15 5049
b7590374 sago007 2011-05-19 16:15 5050
    //Takes names from file instead
b7590374 sago007 2011-05-19 16:15 5051
    strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5052
    strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5053
b7590374 sago007 2011-05-19 16:15 5054
b7590374 sago007 2011-05-19 16:15 5055
    Joypad joypad1 = Joypad();    //Creates a joypad
b7590374 sago007 2011-05-19 16:15 5056
    Joypad joypad2 = Joypad();    //Creates a joypad
b7590374 sago007 2011-05-19 16:15 5057
b7590374 sago007 2011-05-19 16:15 5058
    //Keeps track of background;
b7590374 sago007 2011-05-19 16:15 5059
    int nowTime=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5060
b7590374 sago007 2011-05-19 16:15 5061
b7590374 sago007 2011-05-19 16:15 5062
#if NETWORK
b7590374 sago007 2011-05-19 16:15 5063
    NetworkThing nt = NetworkThing();
b7590374 sago007 2011-05-19 16:15 5064
    nt.setBGpointers(&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5065
#endif
b7590374 sago007 2011-05-19 16:15 5066
b7590374 sago007 2011-05-19 16:15 5067
    if (singlePuzzle)
b7590374 sago007 2011-05-19 16:15 5068
    {
b7590374 sago007 2011-05-19 16:15 5069
        LoadPuzzleStages();
b7590374 sago007 2011-05-19 16:15 5070
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5071
        showGame = true;
b7590374 sago007 2011-05-19 16:15 5072
        vsMode = true;
b7590374 sago007 2011-05-19 16:15 5073
    }
b7590374 sago007 2011-05-19 16:15 5074
    //Draws everything to screen
b7590374 sago007 2011-05-19 16:15 5075
    if (!editorMode)
b7590374 sago007 2011-05-19 16:15 5076
        MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5077
    else
b7590374 sago007 2011-05-19 16:15 5078
        MakeBackground(xsize,ysize,&theGame);
b7590374 sago007 2011-05-19 16:15 5079
    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5080
    DrawEverything(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5081
    SDL_Flip(screen);
b7590374 sago007 2011-05-19 16:15 5082
    //game loop
b7590374 sago007 2011-05-19 16:15 5083
    int done = 0;
b7590374 sago007 2011-05-19 16:15 5084
    cout << "Starting game loop" << endl;
b7590374 sago007 2011-05-19 16:15 5085
b7590374 sago007 2011-05-19 16:15 5086
    switch(gametype) {
b7590374 sago007 2011-05-19 16:15 5087
        case 1:
b7590374 sago007 2011-05-19 16:15 5088
            StartSinglePlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 5089
            break;
b7590374 sago007 2011-05-19 16:15 5090
        case 3:
b7590374 sago007 2011-05-19 16:15 5091
            StartSinglePlayerPuzzle();
b7590374 sago007 2011-05-19 16:15 5092
            break;
b7590374 sago007 2011-05-19 16:15 5093
        case 4:
b7590374 sago007 2011-05-19 16:15 5094
        {
b7590374 sago007 2011-05-19 16:15 5095
            //1 player - Vs mode
b7590374 sago007 2011-05-19 16:15 5096
            bNewGameOpen = false;
b7590374 sago007 2011-05-19 16:15 5097
            b1playerOpen = false;
b7590374 sago007 2011-05-19 16:15 5098
            int theAIlevel = startSingleVs();
b7590374 sago007 2011-05-19 16:15 5099
            theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5100
            theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5101
            MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5102
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5103
            twoPlayers = true; //Single player, but AI plays
b7590374 sago007 2011-05-19 16:15 5104
            showGame = true;
b7590374 sago007 2011-05-19 16:15 5105
            vsMode = true;
b7590374 sago007 2011-05-19 16:15 5106
            theGame2.setAIlevel((Uint8)theAIlevel);
b7590374 sago007 2011-05-19 16:15 5107
            int theTime = time(0);
b7590374 sago007 2011-05-19 16:15 5108
            theGame.putStartBlocks(theTime);
b7590374 sago007 2011-05-19 16:15 5109
            theGame2.putStartBlocks(theTime);
b7590374 sago007 2011-05-19 16:15 5110
            strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5111
            strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5112
        }
b7590374 sago007 2011-05-19 16:15 5113
            break;
b7590374 sago007 2011-05-19 16:15 5114
        case 0:
b7590374 sago007 2011-05-19 16:15 5115
        default:
b7590374 sago007 2011-05-19 16:15 5116
            StartSinglePlayerEndless();
b7590374 sago007 2011-05-19 16:15 5117
            break;
b7590374 sago007 2011-05-19 16:15 5118
    };
b7590374 sago007 2011-05-19 16:15 5119
    while (done == 0)
b7590374 sago007 2011-05-19 16:15 5120
    {
b7590374 sago007 2011-05-19 16:15 5121
        if (!(highPriority)) SDL_Delay(10);
b7590374 sago007 2011-05-19 16:15 5122
b7590374 sago007 2011-05-19 16:15 5123
        if ((standardBackground)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 5124
        {
b7590374 sago007 2011-05-19 16:15 5125
            MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5126
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5127
        }
b7590374 sago007 2011-05-19 16:15 5128
b7590374 sago007 2011-05-19 16:15 5129
        if ((standardBackground)&&(editorMode))
b7590374 sago007 2011-05-19 16:15 5130
        {
b7590374 sago007 2011-05-19 16:15 5131
            DrawIMG(backgroundImage, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5132
            MakeBackground(xsize,ysize,&theGame);
b7590374 sago007 2011-05-19 16:15 5133
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5134
        }
b7590374 sago007 2011-05-19 16:15 5135
b7590374 sago007 2011-05-19 16:15 5136
        //updates the balls and explosions:
b7590374 sago007 2011-05-19 16:15 5137
        theBallManeger.update();
b7590374 sago007 2011-05-19 16:15 5138
        theExplosionManeger.update();
b7590374 sago007 2011-05-19 16:15 5139
        theTextManeger.update();
b7590374 sago007 2011-05-19 16:15 5140
b7590374 sago007 2011-05-19 16:15 5141
#if NETWORK
b7590374 sago007 2011-05-19 16:15 5142
        if (nt.isConnected())
b7590374 sago007 2011-05-19 16:15 5143
        {
b7590374 sago007 2011-05-19 16:15 5144
            nt.updateNetwork();
b7590374 sago007 2011-05-19 16:15 5145
            networkActive = true;
b7590374 sago007 2011-05-19 16:15 5146
            if (!nt.isConnectedToPeer())
b7590374 sago007 2011-05-19 16:15 5147
                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5148
        }
b7590374 sago007 2011-05-19 16:15 5149
        else
b7590374 sago007 2011-05-19 16:15 5150
            networkActive = false;
b7590374 sago007 2011-05-19 16:15 5151
        if (nt.isConnectedToPeer())
b7590374 sago007 2011-05-19 16:15 5152
        {
b7590374 sago007 2011-05-19 16:15 5153
            networkPlay=true;
b7590374 sago007 2011-05-19 16:15 5154
            if (!weWhereConnected) //We have just connected
b7590374 sago007 2011-05-19 16:15 5155
            {
b7590374 sago007 2011-05-19 16:15 5156
                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5157
                theGame.putStartBlocks(nt.theSeed);
b7590374 sago007 2011-05-19 16:15 5158
                theGame2.playNetwork(xsize-500,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5159
                nt.theGameHasStarted();
b7590374 sago007 2011-05-19 16:15 5160
                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5161
            }
b7590374 sago007 2011-05-19 16:15 5162
            weWhereConnected = true;
b7590374 sago007 2011-05-19 16:15 5163
        }
b7590374 sago007 2011-05-19 16:15 5164
        else
b7590374 sago007 2011-05-19 16:15 5165
        {
b7590374 sago007 2011-05-19 16:15 5166
            networkPlay=false;
b7590374 sago007 2011-05-19 16:15 5167
            weWhereConnected = false;
b7590374 sago007 2011-05-19 16:15 5168
        }
b7590374 sago007 2011-05-19 16:15 5169
#endif
b7590374 sago007 2011-05-19 16:15 5170
b7590374 sago007 2011-05-19 16:15 5171
        if (!bScreenLocked)
b7590374 sago007 2011-05-19 16:15 5172
        {
b7590374 sago007 2011-05-19 16:15 5173
            SDL_Event event;
b7590374 sago007 2011-05-19 16:15 5174
b7590374 sago007 2011-05-19 16:15 5175
            while ( SDL_PollEvent(&event) )
b7590374 sago007 2011-05-19 16:15 5176
            {
b7590374 sago007 2011-05-19 16:15 5177
                if ( event.type == SDL_QUIT )  {
b7590374 sago007 2011-05-19 16:15 5178
                    done = 1;
b7590374 sago007 2011-05-19 16:15 5179
                }
b7590374 sago007 2011-05-19 16:15 5180
b7590374 sago007 2011-05-19 16:15 5181
                if ( event.type == SDL_KEYDOWN )
b7590374 sago007 2011-05-19 16:15 5182
                {
b7590374 sago007 2011-05-19 16:15 5183
                    if ( event.key.keysym.sym == SDLK_ESCAPE )
b7590374 sago007 2011-05-19 16:15 5184
                    {
b7590374 sago007 2011-05-19 16:15 5185
                            if (showOptions)
b7590374 sago007 2011-05-19 16:15 5186
                            {
b7590374 sago007 2011-05-19 16:15 5187
                                showOptions = false;
b7590374 sago007 2011-05-19 16:15 5188
                            }
b7590374 sago007 2011-05-19 16:15 5189
                            else
b7590374 sago007 2011-05-19 16:15 5190
                                done=1;
b7590374 sago007 2011-05-19 16:15 5191
                        DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5192
b7590374 sago007 2011-05-19 16:15 5193
                    }
b7590374 sago007 2011-05-19 16:15 5194
                    if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled()))
b7590374 sago007 2011-05-19 16:15 5195
                    {
b7590374 sago007 2011-05-19 16:15 5196
                        //player1:
b7590374 sago007 2011-05-19 16:15 5197
                        if ( event.key.keysym.sym == keySettings[player1keys].up ) {
b7590374 sago007 2011-05-19 16:15 5198
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5199
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 5200
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5201
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 5202
                        }
b7590374 sago007 2011-05-19 16:15 5203
                        if ( event.key.keysym.sym == keySettings[player1keys].down ) {
b7590374 sago007 2011-05-19 16:15 5204
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5205
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 5206
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5207
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 5208
                        }
b7590374 sago007 2011-05-19 16:15 5209
                        if ( (event.key.keysym.sym == keySettings[player1keys].left) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5210
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5211
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 5212
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5213
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 5214
                        }
b7590374 sago007 2011-05-19 16:15 5215
                        if ( (event.key.keysym.sym == keySettings[player1keys].right) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5216
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5217
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 5218
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5219
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 5220
                        }
b7590374 sago007 2011-05-19 16:15 5221
                        if ( event.key.keysym.sym == keySettings[player1keys].push ) {
b7590374 sago007 2011-05-19 16:15 5222
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5223
                        }
b7590374 sago007 2011-05-19 16:15 5224
                        if ( event.key.keysym.sym == keySettings[player1keys].change ) {
b7590374 sago007 2011-05-19 16:15 5225
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5226
                        }
b7590374 sago007 2011-05-19 16:15 5227
                    }
b7590374 sago007 2011-05-19 16:15 5228
                    if (!editorMode && !theGame2.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 5229
                    {
b7590374 sago007 2011-05-19 16:15 5230
                        //player2:
b7590374 sago007 2011-05-19 16:15 5231
                        if ( event.key.keysym.sym == keySettings[player2keys].up ) {
b7590374 sago007 2011-05-19 16:15 5232
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5233
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 5234
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5235
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 5236
                        }
b7590374 sago007 2011-05-19 16:15 5237
                        if ( event.key.keysym.sym == keySettings[player2keys].down ) {
b7590374 sago007 2011-05-19 16:15 5238
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5239
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 5240
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5241
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 5242
                        }
b7590374 sago007 2011-05-19 16:15 5243
                        if ( (event.key.keysym.sym == keySettings[player2keys].left) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5244
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5245
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 5246
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5247
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 5248
                        }
b7590374 sago007 2011-05-19 16:15 5249
                        if ( (event.key.keysym.sym == keySettings[player2keys].right) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5250
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5251
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 5252
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5253
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 5254
                        }
b7590374 sago007 2011-05-19 16:15 5255
                        if ( event.key.keysym.sym == keySettings[player2keys].push ) {
b7590374 sago007 2011-05-19 16:15 5256
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5257
                        }
b7590374 sago007 2011-05-19 16:15 5258
                        if ( event.key.keysym.sym == keySettings[player2keys].change ) {
b7590374 sago007 2011-05-19 16:15 5259
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5260
                        }
b7590374 sago007 2011-05-19 16:15 5261
                    }
b7590374 sago007 2011-05-19 16:15 5262
                    //common:
b7590374 sago007 2011-05-19 16:15 5263
                    if ((!singlePuzzle)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 5264
                    {
b7590374 sago007 2011-05-19 16:15 5265
                        if ( event.key.keysym.sym == SDLK_F2 ) {
b7590374 sago007 2011-05-19 16:15 5266
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5267
                            if ((!showOptions)&&(!networkActive)){
b7590374 sago007 2011-05-19 16:15 5268
                            #else
b7590374 sago007 2011-05-19 16:15 5269
                            if ((!showOptions)){
b7590374 sago007 2011-05-19 16:15 5270
                            #endif
b7590374 sago007 2011-05-19 16:15 5271
                                StartSinglePlayerEndless();
b7590374 sago007 2011-05-19 16:15 5272
                            }}
b7590374 sago007 2011-05-19 16:15 5273
                        if ( event.key.keysym.sym == SDLK_F3 ) {
b7590374 sago007 2011-05-19 16:15 5274
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5275
                            if ((!showOptions)&&(!networkActive)){
b7590374 sago007 2011-05-19 16:15 5276
                            #else
b7590374 sago007 2011-05-19 16:15 5277
                            if ((!showOptions)){
b7590374 sago007 2011-05-19 16:15 5278
                            #endif
b7590374 sago007 2011-05-19 16:15 5279
                                StartSinglePlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 5280
                            }}
b7590374 sago007 2011-05-19 16:15 5281
                        if ( event.key.keysym.sym == SDLK_F5 )
b7590374 sago007 2011-05-19 16:15 5282
                        {
b7590374 sago007 2011-05-19 16:15 5283
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5284
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5285
                            #else
b7590374 sago007 2011-05-19 16:15 5286
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5287
                            #endif
b7590374 sago007 2011-05-19 16:15 5288
                            {
b7590374 sago007 2011-05-19 16:15 5289
                                int myLevel = StageLevelSelect();
b7590374 sago007 2011-05-19 16:15 5290
                                theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5291
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5292
                                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5293
                                closeAllMenus();
b7590374 sago007 2011-05-19 16:15 5294
                                twoPlayers =false;
b7590374 sago007 2011-05-19 16:15 5295
                                theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 5296
                                showGame = true;
b7590374 sago007 2011-05-19 16:15 5297
                                vsMode = false;
b7590374 sago007 2011-05-19 16:15 5298
                                strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5299
                                strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5300
                            }
b7590374 sago007 2011-05-19 16:15 5301
                        }
b7590374 sago007 2011-05-19 16:15 5302
                        if ( event.key.keysym.sym == SDLK_F6 )
b7590374 sago007 2011-05-19 16:15 5303
                        {
b7590374 sago007 2011-05-19 16:15 5304
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5305
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5306
                            #else
b7590374 sago007 2011-05-19 16:15 5307
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5308
                            #endif
b7590374 sago007 2011-05-19 16:15 5309
                            {
b7590374 sago007 2011-05-19 16:15 5310
                                StartTwoPlayerVs();
b7590374 sago007 2011-05-19 16:15 5311
                            }
b7590374 sago007 2011-05-19 16:15 5312
                        }
b7590374 sago007 2011-05-19 16:15 5313
                        if ( event.key.keysym.sym == SDLK_F4 )
b7590374 sago007 2011-05-19 16:15 5314
                        {
b7590374 sago007 2011-05-19 16:15 5315
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5316
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5317
                            #else
b7590374 sago007 2011-05-19 16:15 5318
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5319
                            #endif
b7590374 sago007 2011-05-19 16:15 5320
                            {
b7590374 sago007 2011-05-19 16:15 5321
                                StarTwoPlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 5322
                            }
b7590374 sago007 2011-05-19 16:15 5323
                        }
b7590374 sago007 2011-05-19 16:15 5324
                        if ( event.key.keysym.sym == SDLK_F7 )
b7590374 sago007 2011-05-19 16:15 5325
                        {
b7590374 sago007 2011-05-19 16:15 5326
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5327
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5328
                            #else
b7590374 sago007 2011-05-19 16:15 5329
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5330
                            #endif
b7590374 sago007 2011-05-19 16:15 5331
                            {
b7590374 sago007 2011-05-19 16:15 5332
                                int myLevel = PuzzleLevelSelect();
b7590374 sago007 2011-05-19 16:15 5333
                                theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5334
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5335
                                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5336
                                closeAllMenus();
b7590374 sago007 2011-05-19 16:15 5337
                                twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5338
                                theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 5339
                                showGame = true;
b7590374 sago007 2011-05-19 16:15 5340
                                vsMode = true;
b7590374 sago007 2011-05-19 16:15 5341
                                strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5342
                                strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5343
                            }
b7590374 sago007 2011-05-19 16:15 5344
                        }
b7590374 sago007 2011-05-19 16:15 5345
                        if ( event.key.keysym.sym == SDLK_F8 )
b7590374 sago007 2011-05-19 16:15 5346
                        {
b7590374 sago007 2011-05-19 16:15 5347
                        }
b7590374 sago007 2011-05-19 16:15 5348
                        if ( event.key.keysym.sym == SDLK_F9 ) {
b7590374 sago007 2011-05-19 16:15 5349
                            writeScreenShot();
b7590374 sago007 2011-05-19 16:15 5350
                        }
b7590374 sago007 2011-05-19 16:15 5351
                        if ( event.key.keysym.sym == SDLK_F11 ) {
b7590374 sago007 2011-05-19 16:15 5352
                            /*This is the test place, place function to test here*/
b7590374 sago007 2011-05-19 16:15 5353
b7590374 sago007 2011-05-19 16:15 5354
                            //theGame.CreateGreyGarbage();
b7590374 sago007 2011-05-19 16:15 5355
                            //char mitNavn[30];
b7590374 sago007 2011-05-19 16:15 5356
                            //SelectThemeDialogbox(300,400,mitNavn);
b7590374 sago007 2011-05-19 16:15 5357
                           MainMenu();
b7590374 sago007 2011-05-19 16:15 5358
                            //OpenScoresDisplay();
b7590374 sago007 2011-05-19 16:15 5359
                        } //F11
b7590374 sago007 2011-05-19 16:15 5360
                    }
b7590374 sago007 2011-05-19 16:15 5361
                    if ( event.key.keysym.sym == SDLK_F12 ) {
b7590374 sago007 2011-05-19 16:15 5362
                        done=1;
b7590374 sago007 2011-05-19 16:15 5363
                    }
b7590374 sago007 2011-05-19 16:15 5364
                }
b7590374 sago007 2011-05-19 16:15 5365
            } //while event PollEvent - read keys
b7590374 sago007 2011-05-19 16:15 5366
b7590374 sago007 2011-05-19 16:15 5367
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5368
            **************************** Repeating start **************************
b7590374 sago007 2011-05-19 16:15 5369
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5370
b7590374 sago007 2011-05-19 16:15 5371
            keys = SDL_GetKeyState(NULL);
b7590374 sago007 2011-05-19 16:15 5372
//Also the joysticks:
b7590374 sago007 2011-05-19 16:15 5373
//Repeating not implemented
b7590374 sago007 2011-05-19 16:15 5374
b7590374 sago007 2011-05-19 16:15 5375
//Player 1 start
b7590374 sago007 2011-05-19 16:15 5376
            if (!(keys[keySettings[player1keys].up]))
b7590374 sago007 2011-05-19 16:15 5377
                repeatingN[0]=false;
b7590374 sago007 2011-05-19 16:15 5378
            while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5379
            {
b7590374 sago007 2011-05-19 16:15 5380
                theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5381
                timesRepeatedP1N++;
b7590374 sago007 2011-05-19 16:15 5382
            }
b7590374 sago007 2011-05-19 16:15 5383
b7590374 sago007 2011-05-19 16:15 5384
            if (!(keys[keySettings[player1keys].down]))
b7590374 sago007 2011-05-19 16:15 5385
                repeatingS[0]=false;
b7590374 sago007 2011-05-19 16:15 5386
            while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5387
            {
b7590374 sago007 2011-05-19 16:15 5388
                theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5389
                timesRepeatedP1S++;
b7590374 sago007 2011-05-19 16:15 5390
            }
b7590374 sago007 2011-05-19 16:15 5391
b7590374 sago007 2011-05-19 16:15 5392
            if (!(keys[keySettings[player1keys].left]))
b7590374 sago007 2011-05-19 16:15 5393
                repeatingW[0]=false;
b7590374 sago007 2011-05-19 16:15 5394
            while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5395
            {
b7590374 sago007 2011-05-19 16:15 5396
                timesRepeatedP1W++;
b7590374 sago007 2011-05-19 16:15 5397
                theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5398
            }
b7590374 sago007 2011-05-19 16:15 5399
b7590374 sago007 2011-05-19 16:15 5400
            if (!(keys[keySettings[player1keys].right]))
b7590374 sago007 2011-05-19 16:15 5401
                repeatingE[0]=false;
b7590374 sago007 2011-05-19 16:15 5402
            while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5403
            {
b7590374 sago007 2011-05-19 16:15 5404
                timesRepeatedP1E++;
b7590374 sago007 2011-05-19 16:15 5405
                theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5406
            }
b7590374 sago007 2011-05-19 16:15 5407
b7590374 sago007 2011-05-19 16:15 5408
//Player 1 end
b7590374 sago007 2011-05-19 16:15 5409
b7590374 sago007 2011-05-19 16:15 5410
//Player 2 start
b7590374 sago007 2011-05-19 16:15 5411
            if (!(keys[keySettings[player2keys].up]))
b7590374 sago007 2011-05-19 16:15 5412
                repeatingN[1]=false;
b7590374 sago007 2011-05-19 16:15 5413
            while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5414
            {
b7590374 sago007 2011-05-19 16:15 5415
                theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5416
                timesRepeatedP2N++;
b7590374 sago007 2011-05-19 16:15 5417
            }
b7590374 sago007 2011-05-19 16:15 5418
b7590374 sago007 2011-05-19 16:15 5419
            if (!(keys[keySettings[player2keys].down]))
b7590374 sago007 2011-05-19 16:15 5420
                repeatingS[1]=false;
b7590374 sago007 2011-05-19 16:15 5421
            while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5422
            {
b7590374 sago007 2011-05-19 16:15 5423
                theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5424
                timesRepeatedP2S++;
b7590374 sago007 2011-05-19 16:15 5425
            }
b7590374 sago007 2011-05-19 16:15 5426
b7590374 sago007 2011-05-19 16:15 5427
            if (!(keys[keySettings[player2keys].left]))
b7590374 sago007 2011-05-19 16:15 5428
                repeatingW[1]=false;
b7590374 sago007 2011-05-19 16:15 5429
            while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5430
            {
b7590374 sago007 2011-05-19 16:15 5431
                theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5432
                timesRepeatedP2W++;
b7590374 sago007 2011-05-19 16:15 5433
            }
b7590374 sago007 2011-05-19 16:15 5434
b7590374 sago007 2011-05-19 16:15 5435
            if (!(keys[keySettings[player2keys].right]))
b7590374 sago007 2011-05-19 16:15 5436
                repeatingE[1]=false;
b7590374 sago007 2011-05-19 16:15 5437
            while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5438
            {
b7590374 sago007 2011-05-19 16:15 5439
                theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5440
                timesRepeatedP2E++;
b7590374 sago007 2011-05-19 16:15 5441
            }
b7590374 sago007 2011-05-19 16:15 5442
b7590374 sago007 2011-05-19 16:15 5443
//Player 2 end
b7590374 sago007 2011-05-19 16:15 5444
b7590374 sago007 2011-05-19 16:15 5445
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5446
            **************************** Repeating end ****************************
b7590374 sago007 2011-05-19 16:15 5447
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5448
b7590374 sago007 2011-05-19 16:15 5449
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5450
            ***************************** Joypad start ****************************
b7590374 sago007 2011-05-19 16:15 5451
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5452
b7590374 sago007 2011-05-19 16:15 5453
            //Gameplay
b7590374 sago007 2011-05-19 16:15 5454
            if (joyplay1||joyplay2)
b7590374 sago007 2011-05-19 16:15 5455
            {
b7590374 sago007 2011-05-19 16:15 5456
                if (joypad1.working && !theGame.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 5457
                    if (joyplay1)
b7590374 sago007 2011-05-19 16:15 5458
                    {
b7590374 sago007 2011-05-19 16:15 5459
                        joypad1.update();
b7590374 sago007 2011-05-19 16:15 5460
                        if (joypad1.up)
b7590374 sago007 2011-05-19 16:15 5461
                        {
b7590374 sago007 2011-05-19 16:15 5462
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5463
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 5464
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5465
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 5466
                        }
b7590374 sago007 2011-05-19 16:15 5467
                        if (joypad1.down)
b7590374 sago007 2011-05-19 16:15 5468
                        {
b7590374 sago007 2011-05-19 16:15 5469
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5470
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 5471
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5472
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 5473
                        }
b7590374 sago007 2011-05-19 16:15 5474
                        if (joypad1.left)
b7590374 sago007 2011-05-19 16:15 5475
                        {
b7590374 sago007 2011-05-19 16:15 5476
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5477
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 5478
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5479
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 5480
                        }
b7590374 sago007 2011-05-19 16:15 5481
                        if (joypad1.right)
b7590374 sago007 2011-05-19 16:15 5482
                        {
b7590374 sago007 2011-05-19 16:15 5483
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5484
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 5485
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5486
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 5487
                        }
b7590374 sago007 2011-05-19 16:15 5488
                        if (joypad1.but1)
b7590374 sago007 2011-05-19 16:15 5489
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5490
                        if (joypad1.but2)
b7590374 sago007 2011-05-19 16:15 5491
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5492
                    }
b7590374 sago007 2011-05-19 16:15 5493
                    else
b7590374 sago007 2011-05-19 16:15 5494
                    {
b7590374 sago007 2011-05-19 16:15 5495
                        joypad1.update();
b7590374 sago007 2011-05-19 16:15 5496
                        if (joypad1.up)
b7590374 sago007 2011-05-19 16:15 5497
                        {
b7590374 sago007 2011-05-19 16:15 5498
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5499
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 5500
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5501
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 5502
                        }
b7590374 sago007 2011-05-19 16:15 5503
                        if (joypad1.down)
b7590374 sago007 2011-05-19 16:15 5504
                        {
b7590374 sago007 2011-05-19 16:15 5505
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5506
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 5507
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5508
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 5509
                        }
b7590374 sago007 2011-05-19 16:15 5510
                        if (joypad1.left)
b7590374 sago007 2011-05-19 16:15 5511
                        {
b7590374 sago007 2011-05-19 16:15 5512
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5513
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 5514
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5515
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 5516
                        }
b7590374 sago007 2011-05-19 16:15 5517
                        if (joypad1.right)
b7590374 sago007 2011-05-19 16:15 5518
                        {
b7590374 sago007 2011-05-19 16:15 5519
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5520
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 5521
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5522
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 5523
                        }
b7590374 sago007 2011-05-19 16:15 5524
                        if (joypad1.but1)
b7590374 sago007 2011-05-19 16:15 5525
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5526
                        if (joypad1.but2)
b7590374 sago007 2011-05-19 16:15 5527
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5528
                    }
b7590374 sago007 2011-05-19 16:15 5529
                if (joypad2.working && !theGame2.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 5530
                    if (!joyplay2)
b7590374 sago007 2011-05-19 16:15 5531
                    {
b7590374 sago007 2011-05-19 16:15 5532
                        joypad2.update();
b7590374 sago007 2011-05-19 16:15 5533
                        if (joypad2.up)
b7590374 sago007 2011-05-19 16:15 5534
                        {
b7590374 sago007 2011-05-19 16:15 5535
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5536
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 5537
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5538
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 5539
                        }
b7590374 sago007 2011-05-19 16:15 5540
                        if (joypad2.down)
b7590374 sago007 2011-05-19 16:15 5541
                        {
b7590374 sago007 2011-05-19 16:15 5542
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5543
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 5544
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5545
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 5546
                        }
b7590374 sago007 2011-05-19 16:15 5547
                        if (joypad2.left)
b7590374 sago007 2011-05-19 16:15 5548
                        {
b7590374 sago007 2011-05-19 16:15 5549
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5550
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 5551
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5552
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 5553
                        }
b7590374 sago007 2011-05-19 16:15 5554
                        if (joypad2.right)
b7590374 sago007 2011-05-19 16:15 5555
                        {
b7590374 sago007 2011-05-19 16:15 5556
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5557
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 5558
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5559
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 5560
                        }
b7590374 sago007 2011-05-19 16:15 5561
                        if (joypad2.but1)
b7590374 sago007 2011-05-19 16:15 5562
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5563
                        if (joypad2.but2)
b7590374 sago007 2011-05-19 16:15 5564
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5565
                    }
b7590374 sago007 2011-05-19 16:15 5566
                    else
b7590374 sago007 2011-05-19 16:15 5567
                    {
b7590374 sago007 2011-05-19 16:15 5568
                        joypad2.update();
b7590374 sago007 2011-05-19 16:15 5569
                        if (joypad2.up)
b7590374 sago007 2011-05-19 16:15 5570
                        {
b7590374 sago007 2011-05-19 16:15 5571
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5572
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 5573
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5574
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 5575
                        }
b7590374 sago007 2011-05-19 16:15 5576
                        if (joypad2.down)
b7590374 sago007 2011-05-19 16:15 5577
                        {
b7590374 sago007 2011-05-19 16:15 5578
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5579
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 5580
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5581
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 5582
                        }
b7590374 sago007 2011-05-19 16:15 5583
                        if (joypad2.left)
b7590374 sago007 2011-05-19 16:15 5584
                        {
b7590374 sago007 2011-05-19 16:15 5585
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5586
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 5587
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5588
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 5589
                        }
b7590374 sago007 2011-05-19 16:15 5590
                        if (joypad2.right)
b7590374 sago007 2011-05-19 16:15 5591
                        {
b7590374 sago007 2011-05-19 16:15 5592
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5593
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 5594
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5595
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 5596
                        }
b7590374 sago007 2011-05-19 16:15 5597
                        if (joypad2.but1)
b7590374 sago007 2011-05-19 16:15 5598
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5599
                        if (joypad2.but2)
b7590374 sago007 2011-05-19 16:15 5600
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5601
                    }
b7590374 sago007 2011-05-19 16:15 5602
            }
b7590374 sago007 2011-05-19 16:15 5603
b7590374 sago007 2011-05-19 16:15 5604
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5605
            ***************************** Joypad end ******************************
b7590374 sago007 2011-05-19 16:15 5606
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5607
b7590374 sago007 2011-05-19 16:15 5608
b7590374 sago007 2011-05-19 16:15 5609
            keys = SDL_GetKeyState(NULL);
b7590374 sago007 2011-05-19 16:15 5610
b7590374 sago007 2011-05-19 16:15 5611
            SDL_GetMouseState(&mousex,&mousey);
b7590374 sago007 2011-05-19 16:15 5612
b7590374 sago007 2011-05-19 16:15 5613
            /********************************************************************
b7590374 sago007 2011-05-19 16:15 5614
            **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 5615
            ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5616
b7590374 sago007 2011-05-19 16:15 5617
            if ((mouseplay1)&&((!editorMode)&&(!theGame.GetAIenabled())||(editorModeTest))) //player 1
b7590374 sago007 2011-05-19 16:15 5618
                if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5619
                {
b7590374 sago007 2011-05-19 16:15 5620
                    int yLine, xLine;
b7590374 sago007 2011-05-19 16:15 5621
                    yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50;
b7590374 sago007 2011-05-19 16:15 5622
                    xLine = (mousex-50+25)/50;
b7590374 sago007 2011-05-19 16:15 5623
                    yLine-=2;
b7590374 sago007 2011-05-19 16:15 5624
                    xLine-=1;
b7590374 sago007 2011-05-19 16:15 5625
                    if ((yLine>10)&&(theGame.GetTowerHeight()<12))
b7590374 sago007 2011-05-19 16:15 5626
                        yLine=10;
b7590374 sago007 2011-05-19 16:15 5627
                    if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11))
b7590374 sago007 2011-05-19 16:15 5628
                        yLine=11;
b7590374 sago007 2011-05-19 16:15 5629
                    if (yLine<0)
b7590374 sago007 2011-05-19 16:15 5630
                        yLine=0;
b7590374 sago007 2011-05-19 16:15 5631
                    if (xLine<0)
b7590374 sago007 2011-05-19 16:15 5632
                        xLine=0;
b7590374 sago007 2011-05-19 16:15 5633
                    if (xLine>4)
b7590374 sago007 2011-05-19 16:15 5634
                        xLine=4;
b7590374 sago007 2011-05-19 16:15 5635
                    theGame.MoveCursorTo(xLine,yLine);
b7590374 sago007 2011-05-19 16:15 5636
                }
b7590374 sago007 2011-05-19 16:15 5637
b7590374 sago007 2011-05-19 16:15 5638
            if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2
b7590374 sago007 2011-05-19 16:15 5639
                if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5640
                {
b7590374 sago007 2011-05-19 16:15 5641
                    int yLine, xLine;
b7590374 sago007 2011-05-19 16:15 5642
                    yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50;
b7590374 sago007 2011-05-19 16:15 5643
                    xLine = (mousex-(xsize-500)+25)/50;
b7590374 sago007 2011-05-19 16:15 5644
                    yLine-=2;
b7590374 sago007 2011-05-19 16:15 5645
                    xLine-=1;
b7590374 sago007 2011-05-19 16:15 5646
                    if ((yLine>10)&&(theGame2.GetTowerHeight()<12))
b7590374 sago007 2011-05-19 16:15 5647
                        yLine=10;
b7590374 sago007 2011-05-19 16:15 5648
                    if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11))
b7590374 sago007 2011-05-19 16:15 5649
                        yLine=11;
b7590374 sago007 2011-05-19 16:15 5650
                    if (yLine<0)
b7590374 sago007 2011-05-19 16:15 5651
                        yLine=0;
b7590374 sago007 2011-05-19 16:15 5652
                    if (xLine<0)
b7590374 sago007 2011-05-19 16:15 5653
                        xLine=0;
b7590374 sago007 2011-05-19 16:15 5654
                    if (xLine>4)
b7590374 sago007 2011-05-19 16:15 5655
                        xLine=4;
b7590374 sago007 2011-05-19 16:15 5656
                    theGame2.MoveCursorTo(xLine,yLine);
b7590374 sago007 2011-05-19 16:15 5657
                }
b7590374 sago007 2011-05-19 16:15 5658
b7590374 sago007 2011-05-19 16:15 5659
            /********************************************************************
b7590374 sago007 2011-05-19 16:15 5660
            **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 5661
            ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5662
b7590374 sago007 2011-05-19 16:15 5663
            // If the mouse button is released, make bMouseUp equal true
b7590374 sago007 2011-05-19 16:15 5664
            if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
b7590374 sago007 2011-05-19 16:15 5665
            {
b7590374 sago007 2011-05-19 16:15 5666
                bMouseUp=true;
b7590374 sago007 2011-05-19 16:15 5667
            }
b7590374 sago007 2011-05-19 16:15 5668
b7590374 sago007 2011-05-19 16:15 5669
            // If the mouse button 2 is released, make bMouseUp2 equal true
b7590374 sago007 2011-05-19 16:15 5670
            if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3))
b7590374 sago007 2011-05-19 16:15 5671
            {
b7590374 sago007 2011-05-19 16:15 5672
                bMouseUp2=true;
b7590374 sago007 2011-05-19 16:15 5673
            }
b7590374 sago007 2011-05-19 16:15 5674
b7590374 sago007 2011-05-19 16:15 5675
            if ((!singlePuzzle)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 5676
            {
b7590374 sago007 2011-05-19 16:15 5677
                //read mouse events
b7590374 sago007 2011-05-19 16:15 5678
                if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
b7590374 sago007 2011-05-19 16:15 5679
                {
b7590374 sago007 2011-05-19 16:15 5680
                    bMouseUp = false;
b7590374 sago007 2011-05-19 16:15 5681
                    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5682
                    
b7590374 sago007 2011-05-19 16:15 5683
b7590374 sago007 2011-05-19 16:15 5684
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5685
                    **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 5686
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5687
                    if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5688
                    {
b7590374 sago007 2011-05-19 16:15 5689
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
b7590374 sago007 2011-05-19 16:15 5690
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5691
                            {
b7590374 sago007 2011-05-19 16:15 5692
                                theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5693
                            }
b7590374 sago007 2011-05-19 16:15 5694
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
b7590374 sago007 2011-05-19 16:15 5695
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5696
                            {
b7590374 sago007 2011-05-19 16:15 5697
                                theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5698
                            }
b7590374 sago007 2011-05-19 16:15 5699
                    }
b7590374 sago007 2011-05-19 16:15 5700
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5701
                    **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 5702
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5703
b7590374 sago007 2011-05-19 16:15 5704
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
b7590374 sago007 2011-05-19 16:15 5705
                            &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
b7590374 sago007 2011-05-19 16:15 5706
                            &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize))
b7590374 sago007 2011-05-19 16:15 5707
                    {
b7590374 sago007 2011-05-19 16:15 5708
                        //Clicked the next button after a stage clear or puzzle
b7590374 sago007 2011-05-19 16:15 5709
                        theGame.nextLevel(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5710
                    }
b7590374 sago007 2011-05-19 16:15 5711
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
b7590374 sago007 2011-05-19 16:15 5712
                            &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
b7590374 sago007 2011-05-19 16:15 5713
                            &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize))
b7590374 sago007 2011-05-19 16:15 5714
                    {
b7590374 sago007 2011-05-19 16:15 5715
                        //Clicked the retry button
b7590374 sago007 2011-05-19 16:15 5716
                        theGame.retryLevel(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5717
                    }
b7590374 sago007 2011-05-19 16:15 5718
b7590374 sago007 2011-05-19 16:15 5719
b7590374 sago007 2011-05-19 16:15 5720
                    //cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
b7590374 sago007 2011-05-19 16:15 5721
                }
b7590374 sago007 2011-05-19 16:15 5722
b7590374 sago007 2011-05-19 16:15 5723
                //Mouse button 2:
b7590374 sago007 2011-05-19 16:15 5724
                if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2)
b7590374 sago007 2011-05-19 16:15 5725
                {
b7590374 sago007 2011-05-19 16:15 5726
                    bMouseUp2=false; //The button is pressed
b7590374 sago007 2011-05-19 16:15 5727
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5728
                    **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 5729
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5730
                    if (!showOptions)
b7590374 sago007 2011-05-19 16:15 5731
                    {
b7590374 sago007 2011-05-19 16:15 5732
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
b7590374 sago007 2011-05-19 16:15 5733
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5734
                            {
b7590374 sago007 2011-05-19 16:15 5735
                                theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5736
                            }
b7590374 sago007 2011-05-19 16:15 5737
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
b7590374 sago007 2011-05-19 16:15 5738
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5739
                            {
b7590374 sago007 2011-05-19 16:15 5740
                                theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5741
                            }
b7590374 sago007 2011-05-19 16:15 5742
                    }
b7590374 sago007 2011-05-19 16:15 5743
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5744
                    **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 5745
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5746
                }
b7590374 sago007 2011-05-19 16:15 5747
            } //if !singlePuzzle
b7590374 sago007 2011-05-19 16:15 5748
            else
b7590374 sago007 2011-05-19 16:15 5749
            {
b7590374 sago007 2011-05-19 16:15 5750
b7590374 sago007 2011-05-19 16:15 5751
            }
b7590374 sago007 2011-05-19 16:15 5752
        } //if !bScreenBocked;
b7590374 sago007 2011-05-19 16:15 5753
b7590374 sago007 2011-05-19 16:15 5754
b7590374 sago007 2011-05-19 16:15 5755
        //Sees if music is stopped and if music is enabled
b7590374 sago007 2011-05-19 16:15 5756
        if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath))
b7590374 sago007 2011-05-19 16:15 5757
        {
b7590374 sago007 2011-05-19 16:15 5758
            // then starts playing it.
b7590374 sago007 2011-05-19 16:15 5759
            Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 5760
            Mix_PlayMusic(bgMusic, -1); //music loop
b7590374 sago007 2011-05-19 16:15 5761
        }
b7590374 sago007 2011-05-19 16:15 5762
b7590374 sago007 2011-05-19 16:15 5763
        if(bNearDeath!=bNearDeathPrev)
b7590374 sago007 2011-05-19 16:15 5764
        {
b7590374 sago007 2011-05-19 16:15 5765
            if(bNearDeath)
b7590374 sago007 2011-05-19 16:15 5766
            {
b7590374 sago007 2011-05-19 16:15 5767
                if(!NoSound &&(MusicEnabled)) {
b7590374 sago007 2011-05-19 16:15 5768
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 5769
                    Mix_PlayMusic(highbeatMusic, 1);
b7590374 sago007 2011-05-19 16:15 5770
                }
b7590374 sago007 2011-05-19 16:15 5771
            }
b7590374 sago007 2011-05-19 16:15 5772
            else
b7590374 sago007 2011-05-19 16:15 5773
            {
b7590374 sago007 2011-05-19 16:15 5774
                if(!NoSound &&(MusicEnabled)) {
b7590374 sago007 2011-05-19 16:15 5775
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 5776
                    Mix_PlayMusic(bgMusic, -1);
b7590374 sago007 2011-05-19 16:15 5777
                }
b7590374 sago007 2011-05-19 16:15 5778
            }
b7590374 sago007 2011-05-19 16:15 5779
        }
b7590374 sago007 2011-05-19 16:15 5780
b7590374 sago007 2011-05-19 16:15 5781
        bNearDeathPrev = bNearDeath;
b7590374 sago007 2011-05-19 16:15 5782
b7590374 sago007 2011-05-19 16:15 5783
b7590374 sago007 2011-05-19 16:15 5784
        //set bNearDeath to false theGame*.Update() will change to true as needed
b7590374 sago007 2011-05-19 16:15 5785
        bNearDeath = false;
b7590374 sago007 2011-05-19 16:15 5786
        //Updates the objects
b7590374 sago007 2011-05-19 16:15 5787
        theGame.Update(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5788
        theGame2.Update(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5789
b7590374 sago007 2011-05-19 16:15 5790
//see if anyone has won (two players only)
b7590374 sago007 2011-05-19 16:15 5791
        #if NETWORK
b7590374 sago007 2011-05-19 16:15 5792
        if (!networkPlay)
b7590374 sago007 2011-05-19 16:15 5793
        #endif
b7590374 sago007 2011-05-19 16:15 5794
            if (twoPlayers)
b7590374 sago007 2011-05-19 16:15 5795
            {
b7590374 sago007 2011-05-19 16:15 5796
                lastNrOfPlayers = 2;
b7590374 sago007 2011-05-19 16:15 5797
                if ((theGame.isGameOver()) && (theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 5798
                {
b7590374 sago007 2011-05-19 16:15 5799
                    if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap())
b7590374 sago007 2011-05-19 16:15 5800
                        theGame.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5801
                    else
b7590374 sago007 2011-05-19 16:15 5802
                        if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap())
b7590374 sago007 2011-05-19 16:15 5803
                            theGame2.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5804
                        else {
b7590374 sago007 2011-05-19 16:15 5805
                            theGame.setDraw();
b7590374 sago007 2011-05-19 16:15 5806
                            theGame2.setDraw();
b7590374 sago007 2011-05-19 16:15 5807
                        }
b7590374 sago007 2011-05-19 16:15 5808
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5809
                }
b7590374 sago007 2011-05-19 16:15 5810
                if ((theGame.isGameOver()) && (!theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 5811
                {
b7590374 sago007 2011-05-19 16:15 5812
                    theGame2.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5813
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5814
                }
b7590374 sago007 2011-05-19 16:15 5815
                if ((!theGame.isGameOver()) && (theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 5816
                {
b7590374 sago007 2011-05-19 16:15 5817
                    theGame.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5818
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5819
                }
b7590374 sago007 2011-05-19 16:15 5820
            }
b7590374 sago007 2011-05-19 16:15 5821
b7590374 sago007 2011-05-19 16:15 5822
        //Once evrything has been checked, update graphics
b7590374 sago007 2011-05-19 16:15 5823
        DrawEverything(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5824
        SDL_GetMouseState(&mousex,&mousey);
b7590374 sago007 2011-05-19 16:15 5825
        //Remember mouse placement
b7590374 sago007 2011-05-19 16:15 5826
        oldMousex = mousex;
b7590374 sago007 2011-05-19 16:15 5827
        oldMousey = mousey;
b7590374 sago007 2011-05-19 16:15 5828
        //Draw the mouse:
b7590374 sago007 2011-05-19 16:15 5829
        //DrawIMG(mouse,screen,mousex,mousey);
b7590374 sago007 2011-05-19 16:15 5830
        mouse.PaintTo(screen,mousex,mousey);
b7590374 sago007 2011-05-19 16:15 5831
        SDL_Flip(screen);
b7590374 sago007 2011-05-19 16:15 5832
    } //game loop
b7590374 sago007 2011-05-19 16:15 5833
}