git repos / blockattack-game

blame: source/code/main.cpp

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
89c4a3a6 sago007 2008-08-29 14:32 2
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
89c4a3a6 sago007 2008-08-29 14:32 3
Copyright (C) 2008 Poul Sander
89c4a3a6 sago007 2008-08-29 14:32 4
89c4a3a6 sago007 2008-08-29 14:32 5
    This program is free software; you can redistribute it and/or modify
89c4a3a6 sago007 2008-08-29 14:32 6
    it under the terms of the GNU General Public License as published by
89c4a3a6 sago007 2008-08-29 14:32 7
    the Free Software Foundation; either version 2 of the License, or
89c4a3a6 sago007 2008-08-29 14:32 8
    (at your option) any later version.
89c4a3a6 sago007 2008-08-29 14:32 9
89c4a3a6 sago007 2008-08-29 14:32 10
    This program is distributed in the hope that it will be useful,
89c4a3a6 sago007 2008-08-29 14:32 11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
89c4a3a6 sago007 2008-08-29 14:32 12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89c4a3a6 sago007 2008-08-29 14:32 13
    GNU General Public License for more details.
89c4a3a6 sago007 2008-08-29 14:32 14
89c4a3a6 sago007 2008-08-29 14:32 15
    You should have received a copy of the GNU General Public License
89c4a3a6 sago007 2008-08-29 14:32 16
    along with this program; if not, write to the Free Software
89c4a3a6 sago007 2008-08-29 14:32 17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
89c4a3a6 sago007 2008-08-29 14:32 18
89c4a3a6 sago007 2008-08-29 14:32 19
*/
89c4a3a6 sago007 2008-08-29 14:32 20
215ca7b3 sago007 2009-03-06 16:37 21
#include "common.h"
26ddb424 sago007 2011-06-09 20:06 22
#include "global.hpp"
215ca7b3 sago007 2009-03-06 16:37 23
27ae0175 sago007 2009-01-30 06:02 24
#include <string.h>
27ae0175 sago007 2009-01-30 06:02 25
27ae0175 sago007 2009-01-30 06:02 26
1572de2b sago007 2008-09-11 18:15 27
#ifndef VERSION_NUMBER
e2de69cf sago007 2010-01-15 22:48 28
    #define VERSION_NUMBER "version 1.4.2 BETA"
1572de2b sago007 2008-09-11 18:15 29
#endif
89c4a3a6 sago007 2008-08-29 14:32 30
89c4a3a6 sago007 2008-08-29 14:32 31
//If DEBUG is defined: AI info and FPS will be written to screen
1572de2b sago007 2008-09-11 18:15 32
#ifndef DEBUG
2f30c381 sago007 2008-09-14 13:08 33
    #define DEBUG 0
1572de2b sago007 2008-09-11 18:15 34
#endif
89c4a3a6 sago007 2008-08-29 14:32 35
89c4a3a6 sago007 2008-08-29 14:32 36
//If NETWORK id defined: enet will be used
1572de2b sago007 2008-09-11 18:15 37
#ifndef NETWORK
1572de2b sago007 2008-09-11 18:15 38
    #define NETWORK 1
1572de2b sago007 2008-09-11 18:15 39
#endif
1572de2b sago007 2008-09-11 18:15 40
1572de2b sago007 2008-09-11 18:15 41
//Build-in level editor is still experimental!
1572de2b sago007 2008-09-11 18:15 42
#ifndef LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 43
    #define LEVELEDITOR 0
1572de2b sago007 2008-09-11 18:15 44
#endif
89c4a3a6 sago007 2008-08-29 14:32 45
2e57d791 sago007 2009-06-04 17:48 46
#define WITH_SDL 1
2e57d791 sago007 2009-06-04 17:48 47
aca2f4b0 sago007 2009-05-10 18:11 48
//Macros to convert surfaces (ffor faster drawing)
89c4a3a6 sago007 2008-08-29 14:32 49
#define CONVERT(n) tmp = SDL_DisplayFormat(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 50
#define CONVERTA(n) tmp = SDL_DisplayFormatAlpha(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 51
89c4a3a6 sago007 2008-08-29 14:32 52
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 53
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 54
#include <time.h>           //Used for srand()
769a41a0 sago007 2008-09-24 12:54 55
#include <sstream>          //Still used by itoa2
89c4a3a6 sago007 2008-08-29 14:32 56
#include <string>
89c4a3a6 sago007 2008-08-29 14:32 57
#include "SDL.h"            //The SDL libary, used for most things
89c4a3a6 sago007 2008-08-29 14:32 58
#include <SDL_mixer.h>      //Used for sound & music
89c4a3a6 sago007 2008-08-29 14:32 59
#include <SDL_image.h>      //To load PNG images!
41f02ab2 sago007 2009-05-10 21:40 60
#include <physfs.h>         //Abstract file system. To use containers
41f02ab2 sago007 2009-05-10 21:40 61
#include "physfs_stream.hpp" //To use C++ style file streams
925b7e58 sago007 2011-04-25 16:35 62
#include "Libs/NFont.h"
47529580 sago007 2008-12-09 02:34 63
//#include "ttfont.h"        //To use True Type Fonts in SDL
89c4a3a6 sago007 2008-08-29 14:32 64
//#include "config.h"
89c4a3a6 sago007 2008-08-29 14:32 65
#include <vector>
95bc02ff sago007 2009-03-15 02:46 66
#include <SDL/SDL_timer.h>
925b7e58 sago007 2011-04-25 16:35 67
#include <SDL/SDL_video.h>
925b7e58 sago007 2011-04-25 16:35 68
#include <SDL/SDL_ttf.h>
8d488d32 sago007 2011-04-17 13:02 69
#include "CppSdl/CppSdlImageHolder.hpp"
b7590374 sago007 2011-05-19 16:15 70
#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 71
89c4a3a6 sago007 2008-08-29 14:32 72
//if SHAREDIR is not used we look in current directory
89c4a3a6 sago007 2008-08-29 14:32 73
#ifndef SHAREDIR
89c4a3a6 sago007 2008-08-29 14:32 74
#define SHAREDIR "."
89c4a3a6 sago007 2008-08-29 14:32 75
#endif
89c4a3a6 sago007 2008-08-29 14:32 76
89c4a3a6 sago007 2008-08-29 14:32 77
89c4a3a6 sago007 2008-08-29 14:32 78
89c4a3a6 sago007 2008-08-29 14:32 79
//enet things
1572de2b sago007 2008-09-11 18:15 80
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 81
#include "enet/enet.h"
89c4a3a6 sago007 2008-08-29 14:32 82
#endif
89c4a3a6 sago007 2008-08-29 14:32 83
//enet things end
89c4a3a6 sago007 2008-08-29 14:32 84
925b7e58 sago007 2011-04-25 16:35 85
//#include "SFont.h"          //Used to write on screen
89c4a3a6 sago007 2008-08-29 14:32 86
#include "highscore.h"      //Stores highscores
89c4a3a6 sago007 2008-08-29 14:32 87
#include "ReadKeyboard.h"   //Reads text from keyboard
89c4a3a6 sago007 2008-08-29 14:32 88
#include "joypad.h"         //Used for joypads
89c4a3a6 sago007 2008-08-29 14:32 89
#include "listFiles.h"	    //Used to show files on screen
89c4a3a6 sago007 2008-08-29 14:32 90
#include "replay.h"			//Used for replays
89c4a3a6 sago007 2008-08-29 14:32 91
#include "stats.h"          //Saves general stats 
1572de2b sago007 2008-09-11 18:15 92
#if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 93
#include "editor/editorMain.hpp" //The level editor
1572de2b sago007 2008-09-11 18:15 94
#endif
bc9ea011 sago007 2009-04-12 17:43 95
//#include "uploadReplay.h"   //Takes care of everything libcurl related
89c4a3a6 sago007 2008-08-29 14:32 96
89c4a3a6 sago007 2008-08-29 14:32 97
#include "common.h"
89c4a3a6 sago007 2008-08-29 14:32 98
89c4a3a6 sago007 2008-08-29 14:32 99
/*******************************************************************************
89c4a3a6 sago007 2008-08-29 14:32 100
* All variables and constant has been moved to mainVars.hpp for the overview.  *
89c4a3a6 sago007 2008-08-29 14:32 101
*******************************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 102
#include "mainVars.hpp"
89c4a3a6 sago007 2008-08-29 14:32 103
4b0c248f sago007 2010-11-10 21:13 104
static void MakeBackground(int,int);
89c4a3a6 sago007 2008-08-29 14:32 105
89c4a3a6 sago007 2008-08-29 14:32 106
void closeAllMenus()
89c4a3a6 sago007 2008-08-29 14:32 107
{
89c4a3a6 sago007 2008-08-29 14:32 108
    bNewGameOpen=false;          //show sub menues
89c4a3a6 sago007 2008-08-29 14:32 109
    bOptionsOpen=false;          //Show OptionsMenu (Configure and Select Puzzle)
89c4a3a6 sago007 2008-08-29 14:32 110
    b1playerOpen=false;			//show submenu
89c4a3a6 sago007 2008-08-29 14:32 111
    b2playersOpen=false;
89c4a3a6 sago007 2008-08-29 14:32 112
    bReplayOpen = false;
1572de2b sago007 2008-09-11 18:15 113
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 114
    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 115
#endif
89c4a3a6 sago007 2008-08-29 14:32 116
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 117
89c4a3a6 sago007 2008-08-29 14:32 118
}
89c4a3a6 sago007 2008-08-29 14:32 119
1f61db96 sago007 2010-11-15 20:12 120
SDL_Surface * IMG_Load2(string path)
64ea862c sago007 2009-05-05 02:45 121
{
1f61db96 sago007 2010-11-15 20:12 122
    if (!PHYSFS_exists(path.c_str()))
64ea862c sago007 2009-05-05 02:45 123
    {
64ea862c sago007 2009-05-05 02:45 124
        cout << "File not in blockattack.data: " << path << endl;
64ea862c sago007 2009-05-05 02:45 125
        return NULL; //file doesn't exist
64ea862c sago007 2009-05-05 02:45 126
    }
64ea862c sago007 2009-05-05 02:45 127
1f61db96 sago007 2010-11-15 20:12 128
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
64ea862c sago007 2009-05-05 02:45 129
64ea862c sago007 2009-05-05 02:45 130
    // Get the lenght of the file
64ea862c sago007 2009-05-05 02:45 131
    unsigned int m_size = PHYSFS_fileLength(myfile);
64ea862c sago007 2009-05-05 02:45 132
64ea862c sago007 2009-05-05 02:45 133
    // Get the file data.
64ea862c sago007 2009-05-05 02:45 134
    char *m_data = new char[m_size];
64ea862c sago007 2009-05-05 02:45 135
64ea862c sago007 2009-05-05 02:45 136
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
64ea862c sago007 2009-05-05 02:45 137
64ea862c sago007 2009-05-05 02:45 138
    if (length_read != (int)m_size)
64ea862c sago007 2009-05-05 02:45 139
    {
64ea862c sago007 2009-05-05 02:45 140
            delete [] m_data;
64ea862c sago007 2009-05-05 02:45 141
            m_data = 0;
64ea862c sago007 2009-05-05 02:45 142
            PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 143
            cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 144
            return NULL;
64ea862c sago007 2009-05-05 02:45 145
    }
89c4a3a6 sago007 2008-08-29 14:32 146
64ea862c sago007 2009-05-05 02:45 147
    PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 148
64ea862c sago007 2009-05-05 02:45 149
// And this is how you load an image from a memory buffer with SDL
64ea862c sago007 2009-05-05 02:45 150
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
64ea862c sago007 2009-05-05 02:45 151
64ea862c sago007 2009-05-05 02:45 152
    //The above might fail an return null.
64ea862c sago007 2009-05-05 02:45 153
    if(!rw)
64ea862c sago007 2009-05-05 02:45 154
    {
64ea862c sago007 2009-05-05 02:45 155
        delete [] m_data;
64ea862c sago007 2009-05-05 02:45 156
        m_data = 0;
64ea862c sago007 2009-05-05 02:45 157
        PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 158
        cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 159
        return NULL;
64ea862c sago007 2009-05-05 02:45 160
    }
64ea862c sago007 2009-05-05 02:45 161
adaf31bf sago007 2009-05-05 16:01 162
    SDL_Surface* surface = IMG_Load_RW(rw,true); //the second argument tells the function to three RWops
64ea862c sago007 2009-05-05 02:45 163
64ea862c sago007 2009-05-05 02:45 164
    return surface;
64ea862c sago007 2009-05-05 02:45 165
}
89c4a3a6 sago007 2008-08-29 14:32 166
8d488d32 sago007 2011-04-17 13:02 167
CppSdl::CppSdlImageHolder IMG_Load3(string path)
8d488d32 sago007 2011-04-17 13:02 168
{
8d488d32 sago007 2011-04-17 13:02 169
    if (!PHYSFS_exists(path.c_str()))
8d488d32 sago007 2011-04-17 13:02 170
    {
8d488d32 sago007 2011-04-17 13:02 171
        cout << "File not in blockattack.data: " << path << endl;
8d488d32 sago007 2011-04-17 13:02 172
        throw exception();
8d488d32 sago007 2011-04-17 13:02 173
    }
8d488d32 sago007 2011-04-17 13:02 174
8d488d32 sago007 2011-04-17 13:02 175
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
8d488d32 sago007 2011-04-17 13:02 176
8d488d32 sago007 2011-04-17 13:02 177
    // Get the lenght of the file
8d488d32 sago007 2011-04-17 13:02 178
    unsigned int m_size = PHYSFS_fileLength(myfile);
8d488d32 sago007 2011-04-17 13:02 179
8d488d32 sago007 2011-04-17 13:02 180
    // Get the file data.
8d488d32 sago007 2011-04-17 13:02 181
    char *m_data = new char[m_size];
8d488d32 sago007 2011-04-17 13:02 182
8d488d32 sago007 2011-04-17 13:02 183
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
8d488d32 sago007 2011-04-17 13:02 184
8d488d32 sago007 2011-04-17 13:02 185
    if (length_read != (int)m_size)
8d488d32 sago007 2011-04-17 13:02 186
    {
8d488d32 sago007 2011-04-17 13:02 187
            delete [] m_data;
8d488d32 sago007 2011-04-17 13:02 188
            m_data = 0;
8d488d32 sago007 2011-04-17 13:02 189
            PHYSFS_close(myfile);
8d488d32 sago007 2011-04-17 13:02 190
            cout << "Error. Curropt data file!" << endl;
8d488d32 sago007 2011-04-17 13:02 191
            throw exception();
8d488d32 sago007 2011-04-17 13:02 192
    }
8d488d32 sago007 2011-04-17 13:02 193
8d488d32 sago007 2011-04-17 13:02 194
    PHYSFS_close(myfile);
8d488d32 sago007 2011-04-17 13:02 195
8d488d32 sago007 2011-04-17 13:02 196
    CppSdl::CppSdlImageHolder surface(m_data, m_size);
8d488d32 sago007 2011-04-17 13:02 197
8d488d32 sago007 2011-04-17 13:02 198
    return surface;
8d488d32 sago007 2011-04-17 13:02 199
}
8d488d32 sago007 2011-04-17 13:02 200
4b0c248f sago007 2010-11-10 21:13 201
static void UnloadImages();
4b0c248f sago007 2010-11-10 21:13 202
static int InitImages();
866417ca sago007 2009-05-10 21:35 203
866417ca sago007 2009-05-10 21:35 204
static string oldThemePath = "default";
41f02ab2 sago007 2009-05-10 21:40 205
static bool loaded = false;
89c4a3a6 sago007 2008-08-29 14:32 206
89c4a3a6 sago007 2008-08-29 14:32 207
void loadTheme(string themeName)
89c4a3a6 sago007 2008-08-29 14:32 208
{
41f02ab2 sago007 2009-05-10 21:40 209
    if(loaded)
866417ca sago007 2009-05-10 21:35 210
        UnloadImages();
866417ca sago007 2009-05-10 21:35 211
#if defined(__unix__)
866417ca sago007 2009-05-10 21:35 212
    string home = (string)getenv("HOME")+(string)"/.gamesaves/blockattack";
866417ca sago007 2009-05-10 21:35 213
#elif defined(_WIN32)
866417ca sago007 2009-05-10 21:35 214
    string home = (string)getMyDocumentsPath()+(string)"/My Games/blockattack";
89c4a3a6 sago007 2008-08-29 14:32 215
#endif
866417ca sago007 2009-05-10 21:35 216
    //Remove old theme
866417ca sago007 2009-05-10 21:35 217
    PHYSFS_removeFromSearchPath(oldThemePath.c_str());
866417ca sago007 2009-05-10 21:35 218
    //Look in blockattack.data
866417ca sago007 2009-05-10 21:35 219
    PHYSFS_addToSearchPath(((string)SHAREDIR+"/blockattack.data").c_str(), 1);
866417ca sago007 2009-05-10 21:35 220
    //Look in folder
866417ca sago007 2009-05-10 21:35 221
    PHYSFS_addToSearchPath(SHAREDIR, 1);
866417ca sago007 2009-05-10 21:35 222
    //Look in home folder
866417ca sago007 2009-05-10 21:35 223
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 224
    PHYSFS_addToSearchPath(home.c_str(), 1);
866417ca sago007 2009-05-10 21:35 225
    #endif
2e57d791 sago007 2009-06-04 17:48 226
    if(themeName.compare(Config::getInstance()->getString("themename"))!=0)
2e57d791 sago007 2009-06-04 17:48 227
    {
2e57d791 sago007 2009-06-04 17:48 228
        //If this is a theme different from the saved one. Remember it!
2e57d791 sago007 2009-06-04 17:48 229
        Config::getInstance()->setString("themename",themeName);
2e57d791 sago007 2009-06-04 17:48 230
    }
866417ca sago007 2009-05-10 21:35 231
    if(themeName.compare("default")==0 || (themeName.compare("start")==0))
89c4a3a6 sago007 2008-08-29 14:32 232
    {
866417ca sago007 2009-05-10 21:35 233
        InitImages();
41f02ab2 sago007 2009-05-10 21:40 234
        loaded =true;
866417ca sago007 2009-05-10 21:35 235
        return; //Nothing more to do
89c4a3a6 sago007 2008-08-29 14:32 236
    }
866417ca sago007 2009-05-10 21:35 237
    oldThemePath = "themes/"+themeName;
866417ca sago007 2009-05-10 21:35 238
    PHYSFS_addToSearchPath(oldThemePath.c_str(),0);
866417ca sago007 2009-05-10 21:35 239
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 240
    PHYSFS_addToSearchPath((home+(string)"/"+oldThemePath).c_str(), 0);
89c4a3a6 sago007 2008-08-29 14:32 241
    #endif
866417ca sago007 2009-05-10 21:35 242
    InitImages();
41f02ab2 sago007 2009-05-10 21:40 243
    loaded = true;
89c4a3a6 sago007 2008-08-29 14:32 244
}
89c4a3a6 sago007 2008-08-29 14:32 245
89c4a3a6 sago007 2008-08-29 14:32 246
925b7e58 sago007 2011-04-25 16:35 247
long NFont_OpenFont(NFont *target, string path,int ptsize, SDL_Color color, int style=TTF_STYLE_NORMAL) {
925b7e58 sago007 2011-04-25 16:35 248
    if (!PHYSFS_exists(path.c_str()))
925b7e58 sago007 2011-04-25 16:35 249
    {
925b7e58 sago007 2011-04-25 16:35 250
        cout << "File not in blockattack.data: " << path << endl;
925b7e58 sago007 2011-04-25 16:35 251
        return -1; //file doesn't exist
925b7e58 sago007 2011-04-25 16:35 252
    }
925b7e58 sago007 2011-04-25 16:35 253
89c4a3a6 sago007 2008-08-29 14:32 254
    if(!(TTF_WasInit()))
89c4a3a6 sago007 2008-08-29 14:32 255
       TTF_Init();
925b7e58 sago007 2011-04-25 16:35 256
925b7e58 sago007 2011-04-25 16:35 257
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
925b7e58 sago007 2011-04-25 16:35 258
925b7e58 sago007 2011-04-25 16:35 259
    // Get the lenght of the file
925b7e58 sago007 2011-04-25 16:35 260
    unsigned int m_size = PHYSFS_fileLength(myfile);
925b7e58 sago007 2011-04-25 16:35 261
925b7e58 sago007 2011-04-25 16:35 262
    // Get the file data.
925b7e58 sago007 2011-04-25 16:35 263
    char *m_data = new char[m_size];
925b7e58 sago007 2011-04-25 16:35 264
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
925b7e58 sago007 2011-04-25 16:35 265
925b7e58 sago007 2011-04-25 16:35 266
    if (length_read != (int)m_size)
925b7e58 sago007 2011-04-25 16:35 267
    {
925b7e58 sago007 2011-04-25 16:35 268
            delete [] m_data;
925b7e58 sago007 2011-04-25 16:35 269
            m_data = 0;
925b7e58 sago007 2011-04-25 16:35 270
            PHYSFS_close(myfile);
925b7e58 sago007 2011-04-25 16:35 271
            cout << "Error. Curropt data file!" << endl;
593aeae4 sago007 2011-06-25 22:42 272
            return -3;
925b7e58 sago007 2011-04-25 16:35 273
    }
925b7e58 sago007 2011-04-25 16:35 274
925b7e58 sago007 2011-04-25 16:35 275
    PHYSFS_close(myfile);
925b7e58 sago007 2011-04-25 16:35 276
925b7e58 sago007 2011-04-25 16:35 277
// And this is how you load from a memory buffer with SDL
925b7e58 sago007 2011-04-25 16:35 278
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
925b7e58 sago007 2011-04-25 16:35 279
925b7e58 sago007 2011-04-25 16:35 280
    //The above might fail an return null.
925b7e58 sago007 2011-04-25 16:35 281
    if(!rw)
925b7e58 sago007 2011-04-25 16:35 282
    {
925b7e58 sago007 2011-04-25 16:35 283
        delete [] m_data;
925b7e58 sago007 2011-04-25 16:35 284
        m_data = 0;
925b7e58 sago007 2011-04-25 16:35 285
        PHYSFS_close(myfile);
925b7e58 sago007 2011-04-25 16:35 286
        cout << "Error. Curropt data file!" << endl;
925b7e58 sago007 2011-04-25 16:35 287
        return -2;
925b7e58 sago007 2011-04-25 16:35 288
    }
925b7e58 sago007 2011-04-25 16:35 289
925b7e58 sago007 2011-04-25 16:35 290
    TTF_Font *font;
925b7e58 sago007 2011-04-25 16:35 291
    font=TTF_OpenFontRW(rw, 1, ptsize);
925b7e58 sago007 2011-04-25 16:35 292
    TTF_SetFontStyle(font,style);
925b7e58 sago007 2011-04-25 16:35 293
925b7e58 sago007 2011-04-25 16:35 294
    target->load(font,color);
925b7e58 sago007 2011-04-25 16:35 295
925b7e58 sago007 2011-04-25 16:35 296
    TTF_CloseFont(font); //Once loaded we don't care anymore!
925b7e58 sago007 2011-04-25 16:35 297
925b7e58 sago007 2011-04-25 16:35 298
    return 0;
925b7e58 sago007 2011-04-25 16:35 299
}
89c4a3a6 sago007 2008-08-29 14:32 300
41f02ab2 sago007 2009-05-10 21:40 301
1f61db96 sago007 2010-11-15 20:12 302
Mix_Music * Mix_LoadMUS2(string path)
adaf31bf sago007 2009-05-05 16:01 303
{
1f61db96 sago007 2010-11-15 20:12 304
    if (!PHYSFS_exists(path.c_str()))
adaf31bf sago007 2009-05-05 16:01 305
    {
adaf31bf sago007 2009-05-05 16:01 306
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 307
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 308
    }
adaf31bf sago007 2009-05-05 16:01 309
1f61db96 sago007 2010-11-15 20:12 310
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
adaf31bf sago007 2009-05-05 16:01 311
adaf31bf sago007 2009-05-05 16:01 312
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 313
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 314
adaf31bf sago007 2009-05-05 16:01 315
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 316
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 317
adaf31bf sago007 2009-05-05 16:01 318
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 319
adaf31bf sago007 2009-05-05 16:01 320
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 321
    {
adaf31bf sago007 2009-05-05 16:01 322
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 323
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 324
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 325
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 326
            return NULL;
adaf31bf sago007 2009-05-05 16:01 327
    }
adaf31bf sago007 2009-05-05 16:01 328
adaf31bf sago007 2009-05-05 16:01 329
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 330
adaf31bf sago007 2009-05-05 16:01 331
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 332
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 333
adaf31bf sago007 2009-05-05 16:01 334
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 335
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 336
    {
adaf31bf sago007 2009-05-05 16:01 337
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 338
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 339
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 340
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 341
        return NULL;
adaf31bf sago007 2009-05-05 16:01 342
    }
adaf31bf sago007 2009-05-05 16:01 343
adaf31bf sago007 2009-05-05 16:01 344
    Mix_Music* ret = Mix_LoadMUS_RW(rw);
adaf31bf sago007 2009-05-05 16:01 345
adaf31bf sago007 2009-05-05 16:01 346
    return ret;
adaf31bf sago007 2009-05-05 16:01 347
}
89c4a3a6 sago007 2008-08-29 14:32 348
89c4a3a6 sago007 2008-08-29 14:32 349
adaf31bf sago007 2009-05-05 16:01 350
Mix_Chunk * Mix_LoadWAV2(char* path)
adaf31bf sago007 2009-05-05 16:01 351
{
adaf31bf sago007 2009-05-05 16:01 352
    if (!PHYSFS_exists(path))
adaf31bf sago007 2009-05-05 16:01 353
    {
adaf31bf sago007 2009-05-05 16:01 354
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 355
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 356
    }
adaf31bf sago007 2009-05-05 16:01 357
adaf31bf sago007 2009-05-05 16:01 358
    PHYSFS_file* myfile = PHYSFS_openRead(path);
adaf31bf sago007 2009-05-05 16:01 359
adaf31bf sago007 2009-05-05 16:01 360
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 361
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 362
adaf31bf sago007 2009-05-05 16:01 363
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 364
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 365
adaf31bf sago007 2009-05-05 16:01 366
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 367
adaf31bf sago007 2009-05-05 16:01 368
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 369
    {
adaf31bf sago007 2009-05-05 16:01 370
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 371
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 372
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 373
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 374
            return NULL;
adaf31bf sago007 2009-05-05 16:01 375
    }
adaf31bf sago007 2009-05-05 16:01 376
adaf31bf sago007 2009-05-05 16:01 377
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 378
adaf31bf sago007 2009-05-05 16:01 379
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 380
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 381
adaf31bf sago007 2009-05-05 16:01 382
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 383
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 384
    {
adaf31bf sago007 2009-05-05 16:01 385
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 386
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 387
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 388
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 389
        return NULL;
adaf31bf sago007 2009-05-05 16:01 390
    }
adaf31bf sago007 2009-05-05 16:01 391
adaf31bf sago007 2009-05-05 16:01 392
    Mix_Chunk* ret = Mix_LoadWAV_RW(rw,true); //the second argument tells the function to three RWops
adaf31bf sago007 2009-05-05 16:01 393
adaf31bf sago007 2009-05-05 16:01 394
    return ret;
adaf31bf sago007 2009-05-05 16:01 395
}
89c4a3a6 sago007 2008-08-29 14:32 396
89c4a3a6 sago007 2008-08-29 14:32 397
//Load all image files to memory
4b0c248f sago007 2010-11-10 21:13 398
static int InitImages()
89c4a3a6 sago007 2008-08-29 14:32 399
{
1f61db96 sago007 2010-11-15 20:12 400
    if (!((backgroundImage = IMG_Load2("gfx/background.png"))
1f61db96 sago007 2010-11-15 20:12 401
            && (background = IMG_Load2("gfx/blackBackGround.png"))
1f61db96 sago007 2010-11-15 20:12 402
            && (b1player = IMG_Load2("gfx/bOnePlayer.png"))
1f61db96 sago007 2010-11-15 20:12 403
            && (b2players = IMG_Load2("gfx/bTwoPlayers.png"))
1f61db96 sago007 2010-11-15 20:12 404
            && (bVsMode = IMG_Load2("gfx/bVsGame.png"))
1f61db96 sago007 2010-11-15 20:12 405
            && (bVsModeConfig = IMG_Load2("gfx/bVsGameConfig.png"))
89c4a3a6 sago007 2008-08-29 14:32 406
            && (bPuzzle = IMG_Load2((char*)"gfx/bPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 407
            && (bStageClear = IMG_Load2((char*)"gfx/bStageClear.png"))
89c4a3a6 sago007 2008-08-29 14:32 408
            && (bTimeTrial = IMG_Load2((char*)"gfx/bTimeTrial.png"))
89c4a3a6 sago007 2008-08-29 14:32 409
            && (bEndless = IMG_Load2((char*)"gfx/bEndless.png"))
89c4a3a6 sago007 2008-08-29 14:32 410
            && (bOptions = IMG_Load2((char*)"gfx/bOptions.png"))
89c4a3a6 sago007 2008-08-29 14:32 411
            && (bConfigure = IMG_Load2((char*)"gfx/bConfigure.png"))
89c4a3a6 sago007 2008-08-29 14:32 412
            && (bSelectPuzzle = IMG_Load2((char*)"gfx/bSelectPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 413
            && (bHighScore = IMG_Load2((char*)"gfx/bHighScore.png"))
89c4a3a6 sago007 2008-08-29 14:32 414
            && (bExit = IMG_Load2((char*)"gfx/bExit.png"))
89c4a3a6 sago007 2008-08-29 14:32 415
            && (bBack = IMG_Load2((char*)"gfx/bBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 416
            && (bForward = IMG_Load2((char*)"gfx/bForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 417
            && (bReplay = IMG_Load2((char*)"gfx/bReplays.png"))
89c4a3a6 sago007 2008-08-29 14:32 418
            && (bSave = IMG_Load2((char*)"gfx/bSave.png"))
89c4a3a6 sago007 2008-08-29 14:32 419
            && (bLoad = IMG_Load2((char*)"gfx/bLoad.png"))
1572de2b sago007 2008-09-11 18:15 420
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 421
            && (bNetwork = IMG_Load2((char*)"gfx/bNetwork.png"))
89c4a3a6 sago007 2008-08-29 14:32 422
            && (bHost = IMG_Load2((char*)"gfx/bHost.png"))
89c4a3a6 sago007 2008-08-29 14:32 423
            && (bConnect = IMG_Load2((char*)"gfx/bConnect.png"))
89c4a3a6 sago007 2008-08-29 14:32 424
#endif
89c4a3a6 sago007 2008-08-29 14:32 425
            && (blackLine = IMG_Load2((char*)"gfx/blackLine.png"))
89c4a3a6 sago007 2008-08-29 14:32 426
            && (stageBobble = IMG_Load2((char*)"gfx/iStageClearLimit.png"))
a039f5c4 sago007 2008-09-19 23:12 427
            && (bricks[0] = IMG_Load2((char*)"gfx/bricks/blue.png"))
a039f5c4 sago007 2008-09-19 23:12 428
            && (bricks[1] = IMG_Load2((char*)"gfx/bricks/green.png"))
a039f5c4 sago007 2008-09-19 23:12 429
            && (bricks[2] = IMG_Load2((char*)"gfx/bricks/purple.png"))
a039f5c4 sago007 2008-09-19 23:12 430
            && (bricks[3] = IMG_Load2((char*)"gfx/bricks/red.png"))
a039f5c4 sago007 2008-09-19 23:12 431
            && (bricks[4] = IMG_Load2((char*)"gfx/bricks/turkish.png"))
a039f5c4 sago007 2008-09-19 23:12 432
            && (bricks[5] = IMG_Load2((char*)"gfx/bricks/yellow.png"))
a039f5c4 sago007 2008-09-19 23:12 433
            && (bricks[6] = IMG_Load2((char*)"gfx/bricks/grey.png"))
89c4a3a6 sago007 2008-08-29 14:32 434
            && (crossover = IMG_Load2((char*)"gfx/crossover.png"))
89c4a3a6 sago007 2008-08-29 14:32 435
            && (balls[0] = IMG_Load2((char*)"gfx/balls/ballBlue.png"))
89c4a3a6 sago007 2008-08-29 14:32 436
            && (balls[1] = IMG_Load2((char*)"gfx/balls/ballGreen.png"))
89c4a3a6 sago007 2008-08-29 14:32 437
            && (balls[2] = IMG_Load2((char*)"gfx/balls/ballPurple.png"))
89c4a3a6 sago007 2008-08-29 14:32 438
            && (balls[3] = IMG_Load2((char*)"gfx/balls/ballRed.png"))
89c4a3a6 sago007 2008-08-29 14:32 439
            && (balls[4] = IMG_Load2((char*)"gfx/balls/ballTurkish.png"))
89c4a3a6 sago007 2008-08-29 14:32 440
            && (balls[5] = IMG_Load2((char*)"gfx/balls/ballYellow.png"))
89c4a3a6 sago007 2008-08-29 14:32 441
            && (balls[6] = IMG_Load2((char*)"gfx/balls/ballGray.png"))
89c4a3a6 sago007 2008-08-29 14:32 442
            && (cursor[0] = IMG_Load2((char*)"gfx/animations/cursor/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 443
            && (cursor[1] = IMG_Load2((char*)"gfx/animations/cursor/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 444
            && (bomb[0] = IMG_Load2((char*)"gfx/animations/bomb/bomb_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 445
            && (bomb[1] = IMG_Load2((char*)"gfx/animations/bomb/bomb_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 446
            && (ready[0] = IMG_Load2((char*)"gfx/animations/ready/ready_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 447
            && (ready[1] = IMG_Load2((char*)"gfx/animations/ready/ready_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 448
            && (explosion[0] = IMG_Load2((char*)"gfx/animations/explosion/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 449
            && (explosion[1] = IMG_Load2((char*)"gfx/animations/explosion/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 450
            && (explosion[2] = IMG_Load2((char*)"gfx/animations/explosion/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 451
            && (explosion[3] = IMG_Load2((char*)"gfx/animations/explosion/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 452
            && (counter[0] = IMG_Load2((char*)"gfx/counter/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 453
            && (counter[1] = IMG_Load2((char*)"gfx/counter/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 454
            && (counter[2] = IMG_Load2((char*)"gfx/counter/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 455
            && (backBoard = IMG_Load2((char*)"gfx/BackBoard.png")) //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 456
            && (iGameOver = IMG_Load2((char*)"gfx/iGameOver.png"))
89c4a3a6 sago007 2008-08-29 14:32 457
            && (iWinner = IMG_Load2((char*)"gfx/iWinner.png"))
89c4a3a6 sago007 2008-08-29 14:32 458
            && (iDraw = IMG_Load2((char*)"gfx/iDraw.png"))
89c4a3a6 sago007 2008-08-29 14:32 459
            && (iLoser = IMG_Load2((char*)"gfx/iLoser.png"))
89c4a3a6 sago007 2008-08-29 14:32 460
            && (iChainBack = IMG_Load2((char*)"gfx/chainFrame.png"))
89c4a3a6 sago007 2008-08-29 14:32 461
            && (optionsBack = IMG_Load2((char*)"gfx/options.png"))
89c4a3a6 sago007 2008-08-29 14:32 462
            && (bOn = IMG_Load2((char*)"gfx/bOn.png"))
89c4a3a6 sago007 2008-08-29 14:32 463
            && (bOff = IMG_Load2((char*)"gfx/bOff.png"))
89c4a3a6 sago007 2008-08-29 14:32 464
            && (bChange = IMG_Load2((char*)"gfx/bChange.png"))
89c4a3a6 sago007 2008-08-29 14:32 465
            && (b1024 = IMG_Load2((char*)"gfx/b1024.png"))
89c4a3a6 sago007 2008-08-29 14:32 466
            && (dialogBox = IMG_Load2((char*)"gfx/dialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 467
//	&& (fileDialogBox = IMG_Load2("gfx/fileDialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 468
            && (iLevelCheck = IMG_Load2((char*)"gfx/iLevelCheck.png"))
89c4a3a6 sago007 2008-08-29 14:32 469
            && (iLevelCheckBox = IMG_Load2((char*)"gfx/iLevelCheckBox.png"))
89c4a3a6 sago007 2008-08-29 14:32 470
            && (iCheckBoxArea = IMG_Load2((char*)"gfx/iCheckBoxArea.png"))
89c4a3a6 sago007 2008-08-29 14:32 471
            && (boardBackBack = IMG_Load2((char*)"gfx/boardBackBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 472
            && (changeButtonsBack = IMG_Load2((char*)"gfx/changeButtonsBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 473
            && (garbageTL = IMG_Load2((char*)"gfx/garbage/garbageTL.png"))
89c4a3a6 sago007 2008-08-29 14:32 474
            && (garbageT = IMG_Load2((char*)"gfx/garbage/garbageT.png"))
89c4a3a6 sago007 2008-08-29 14:32 475
            && (garbageTR = IMG_Load2((char*)"gfx/garbage/garbageTR.png"))
89c4a3a6 sago007 2008-08-29 14:32 476
            && (garbageR = IMG_Load2((char*)"gfx/garbage/garbageR.png"))
89c4a3a6 sago007 2008-08-29 14:32 477
            && (garbageBR = IMG_Load2((char*)"gfx/garbage/garbageBR.png"))
89c4a3a6 sago007 2008-08-29 14:32 478
            && (garbageB = IMG_Load2((char*)"gfx/garbage/garbageB.png"))
89c4a3a6 sago007 2008-08-29 14:32 479
            && (garbageBL = IMG_Load2((char*)"gfx/garbage/garbageBL.png"))
89c4a3a6 sago007 2008-08-29 14:32 480
            && (garbageL = IMG_Load2((char*)"gfx/garbage/garbageL.png"))
89c4a3a6 sago007 2008-08-29 14:32 481
            && (garbageFill = IMG_Load2((char*)"gfx/garbage/garbageFill.png"))
89c4a3a6 sago007 2008-08-29 14:32 482
            && (garbageML = IMG_Load2((char*)"gfx/garbage/garbageML.png"))
89c4a3a6 sago007 2008-08-29 14:32 483
            && (garbageM = IMG_Load2((char*)"gfx/garbage/garbageM.png"))
89c4a3a6 sago007 2008-08-29 14:32 484
            && (garbageMR = IMG_Load2((char*)"gfx/garbage/garbageMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 485
            && (garbageGM = IMG_Load2((char*)"gfx/garbage/garbageGM.png"))
89c4a3a6 sago007 2008-08-29 14:32 486
            && (garbageGML = IMG_Load2((char*)"gfx/garbage/garbageGML.png"))
89c4a3a6 sago007 2008-08-29 14:32 487
            && (garbageGMR = IMG_Load2((char*)"gfx/garbage/garbageGMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 488
            && (smiley[0] = IMG_Load2((char*)"gfx/smileys/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 489
            && (smiley[1] = IMG_Load2((char*)"gfx/smileys/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 490
            && (smiley[2] = IMG_Load2((char*)"gfx/smileys/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 491
            && (smiley[3] = IMG_Load2((char*)"gfx/smileys/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 492
            //new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 493
            && (transCover = IMG_Load2((char*)"gfx/transCover.png"))
1572de2b sago007 2008-09-11 18:15 494
            #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 495
            && (bCreateFile = IMG_Load2((char*)"gfx/editor/bCreateFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 496
            && (bDeletePuzzle = IMG_Load2((char*)"gfx/editor/bDeletePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 497
            && (bLoadFile = IMG_Load2((char*)"gfx/editor/bLoadFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 498
            && (bMoveBack = IMG_Load2((char*)"gfx/editor/bMoveBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 499
            && (bMoveDown = IMG_Load2((char*)"gfx/editor/bMoveDown.png"))
89c4a3a6 sago007 2008-08-29 14:32 500
            && (bMoveForward = IMG_Load2((char*)"gfx/editor/bMoveForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 501
            && (bMoveLeft = IMG_Load2((char*)"gfx/editor/bMoveLeft.png"))
89c4a3a6 sago007 2008-08-29 14:32 502
            && (bMoveRight = IMG_Load2((char*)"gfx/editor/bMoveRight.png"))
89c4a3a6 sago007 2008-08-29 14:32 503
            && (bMoveUp = IMG_Load2((char*)"gfx/editor/bMoveUp.png"))
89c4a3a6 sago007 2008-08-29 14:32 504
            && (bNewPuzzle = IMG_Load2((char*)"gfx/editor/bNewPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 505
            && (bSaveFileAs = IMG_Load2((char*)"gfx/editor/bSaveFileAs.png"))
89c4a3a6 sago007 2008-08-29 14:32 506
            && (bSavePuzzle = IMG_Load2((char*)"gfx/editor/bSavePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 507
            && (bSaveToFile = IMG_Load2((char*)"gfx/editor/bSaveToFile.png"))
1572de2b sago007 2008-09-11 18:15 508
            && (bTestPuzzle = IMG_Load2((char*)"gfx/editor/bTestPuzzle.png"))
1572de2b sago007 2008-09-11 18:15 509
            #endif
89c4a3a6 sago007 2008-08-29 14:32 510
            //end new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 511
            //new in 1.4.0
89c4a3a6 sago007 2008-08-29 14:32 512
            && (bTheme = IMG_Load2((char*)"gfx/bTheme.png"))
89c4a3a6 sago007 2008-08-29 14:32 513
            && (bSkip = IMG_Load2((char*)"gfx/bSkip.png"))
89c4a3a6 sago007 2008-08-29 14:32 514
            && (bNext = IMG_Load2((char*)"gfx/bNext.png"))
89c4a3a6 sago007 2008-08-29 14:32 515
            && (bRetry = IMG_Load2((char*)"gfx/bRetry.png"))
89c4a3a6 sago007 2008-08-29 14:32 516
         ))
89c4a3a6 sago007 2008-08-29 14:32 517
        //if there was a problem ie. "File not found"
89c4a3a6 sago007 2008-08-29 14:32 518
    {
89c4a3a6 sago007 2008-08-29 14:32 519
        cout << "Error loading image file: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 520
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 521
    }
8d488d32 sago007 2011-04-17 13:02 522
    try{
43611709 sago007 2011-04-23 17:18 523
        bNewGame = IMG_Load3("gfx/bNewGame.png");
8d488d32 sago007 2011-04-17 13:02 524
        mouse = IMG_Load3("gfx/mouse.png");
b7590374 sago007 2011-05-19 16:15 525
        menuMarked = IMG_Load3("gfx/menu/marked.png");
b7590374 sago007 2011-05-19 16:15 526
        menuUnmarked = IMG_Load3("gfx/menu/unmarked.png");
8d488d32 sago007 2011-04-17 13:02 527
    } catch (exception e) {
8d488d32 sago007 2011-04-17 13:02 528
        cout << e.what() << endl;
8d488d32 sago007 2011-04-17 13:02 529
        exit(1);
8d488d32 sago007 2011-04-17 13:02 530
    }
89c4a3a6 sago007 2008-08-29 14:32 531
89c4a3a6 sago007 2008-08-29 14:32 532
89c4a3a6 sago007 2008-08-29 14:32 533
    //Prepare for fast blittering!
89c4a3a6 sago007 2008-08-29 14:32 534
    CONVERT(background);
89c4a3a6 sago007 2008-08-29 14:32 535
    CONVERT(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 536
    CONVERT(b1player);
89c4a3a6 sago007 2008-08-29 14:32 537
    CONVERT(b2players);
89c4a3a6 sago007 2008-08-29 14:32 538
    CONVERT(bVsMode);
e3e0644e sago007 2008-09-25 14:00 539
    CONVERT(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 540
    CONVERT(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 541
    CONVERT(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 542
    CONVERT(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 543
    CONVERT(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 544
    CONVERT(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 545
    CONVERTA(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 546
    CONVERTA(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 547
    CONVERTA(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 548
    CONVERTA(bSave);
89c4a3a6 sago007 2008-08-29 14:32 549
    CONVERTA(bLoad);
89c4a3a6 sago007 2008-08-29 14:32 550
    CONVERTA(bTheme);
89c4a3a6 sago007 2008-08-29 14:32 551
    CONVERTA(bSkip);
89c4a3a6 sago007 2008-08-29 14:32 552
    CONVERTA(bRetry);
89c4a3a6 sago007 2008-08-29 14:32 553
    CONVERTA(bNext);
1572de2b sago007 2008-09-11 18:15 554
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 555
    CONVERTA(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 556
    CONVERTA(bHost);
89c4a3a6 sago007 2008-08-29 14:32 557
    CONVERTA(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 558
#endif
89c4a3a6 sago007 2008-08-29 14:32 559
    CONVERT(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 560
    CONVERTA(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 561
    CONVERT(backBoard);
89c4a3a6 sago007 2008-08-29 14:32 562
    CONVERT(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 563
    CONVERTA(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 564
    CONVERTA(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 565
    CONVERTA(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 566
    CONVERTA(counter[0]);
89c4a3a6 sago007 2008-08-29 14:32 567
    CONVERTA(counter[1]);
89c4a3a6 sago007 2008-08-29 14:32 568
    CONVERTA(counter[2]);
89c4a3a6 sago007 2008-08-29 14:32 569
    CONVERTA(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 570
    CONVERT(bExit);
89c4a3a6 sago007 2008-08-29 14:32 571
    CONVERT(bOn);
89c4a3a6 sago007 2008-08-29 14:32 572
    CONVERT(bOff);
89c4a3a6 sago007 2008-08-29 14:32 573
    CONVERT(bChange);
89c4a3a6 sago007 2008-08-29 14:32 574
    CONVERT(b1024);
89c4a3a6 sago007 2008-08-29 14:32 575
    CONVERTA(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 576
//	CONVERTA(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 577
    CONVERTA(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 578
    CONVERT(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 579
    CONVERTA(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 580
    for (int i = 0;i<4;i++)
89c4a3a6 sago007 2008-08-29 14:32 581
    {
89c4a3a6 sago007 2008-08-29 14:32 582
        CONVERTA(explosion[i]);
89c4a3a6 sago007 2008-08-29 14:32 583
    }
89c4a3a6 sago007 2008-08-29 14:32 584
    for (int i = 0; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 585
    {
89c4a3a6 sago007 2008-08-29 14:32 586
        CONVERTA(bricks[i]);
89c4a3a6 sago007 2008-08-29 14:32 587
        CONVERTA(balls[i]);
89c4a3a6 sago007 2008-08-29 14:32 588
    }
89c4a3a6 sago007 2008-08-29 14:32 589
    CONVERTA(crossover);
89c4a3a6 sago007 2008-08-29 14:32 590
    CONVERTA(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 591
    CONVERTA(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 592
    CONVERTA(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 593
    CONVERTA(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 594
    CONVERTA(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 595
    CONVERTA(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 596
    CONVERTA(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 597
    CONVERTA(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 598
    CONVERTA(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 599
    CONVERTA(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 600
    CONVERTA(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 601
    CONVERTA(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 602
    CONVERTA(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 603
    CONVERTA(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 604
    CONVERTA(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 605
    CONVERTA(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 606
    CONVERTA(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 607
    CONVERTA(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 608
    CONVERTA(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 609
    CONVERTA(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 610
    CONVERTA(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 611
    CONVERTA(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 612
    CONVERTA(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 613
    CONVERTA(iGameOver);
8d488d32 sago007 2011-04-17 13:02 614
    mouse.OptimizeForBlit(true);
43611709 sago007 2011-04-23 17:18 615
    bNewGame.OptimizeForBlit(true);
89c4a3a6 sago007 2008-08-29 14:32 616
    CONVERTA(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 617
    CONVERTA(transCover);
89c4a3a6 sago007 2008-08-29 14:32 618
    //Editor:
1572de2b sago007 2008-09-11 18:15 619
    #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 620
    CONVERTA(bCreateFile);
89c4a3a6 sago007 2008-08-29 14:32 621
    CONVERTA(bDeletePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 622
    CONVERTA(bLoadFile);
89c4a3a6 sago007 2008-08-29 14:32 623
    CONVERTA(bMoveBack);
89c4a3a6 sago007 2008-08-29 14:32 624
    CONVERTA(bMoveDown);
89c4a3a6 sago007 2008-08-29 14:32 625
    CONVERTA(bMoveForward);
89c4a3a6 sago007 2008-08-29 14:32 626
    CONVERTA(bMoveLeft);
89c4a3a6 sago007 2008-08-29 14:32 627
    CONVERTA(bMoveRight);
89c4a3a6 sago007 2008-08-29 14:32 628
    CONVERTA(bMoveUp);
89c4a3a6 sago007 2008-08-29 14:32 629
    CONVERTA(bNewPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 630
    CONVERTA(bSaveFileAs);
89c4a3a6 sago007 2008-08-29 14:32 631
    CONVERTA(bSavePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 632
    CONVERTA(bSaveToFile);
1572de2b sago007 2008-09-11 18:15 633
    CONVERTA(bTestPuzzle);
1572de2b sago007 2008-09-11 18:15 634
    #endif
1572de2b sago007 2008-09-11 18:15 635
    
925b7e58 sago007 2011-04-25 16:35 636
    SDL_Color nf_button_color, nf_standard_blue_color, nf_standard_small_color;
925b7e58 sago007 2011-04-25 16:35 637
    memset(&nf_button_color,0,sizeof(SDL_Color));
925b7e58 sago007 2011-04-25 16:35 638
    nf_button_color.b = 255; nf_button_color.g = 255; nf_button_color.r = 255;
925b7e58 sago007 2011-04-25 16:35 639
    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 640
    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 641
    NFont_OpenFont(&nf_button_font,"fonts/FreeSerif.ttf",24,nf_button_color);
925b7e58 sago007 2011-04-25 16:35 642
    nf_button_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 643
    NFont_OpenFont(&nf_standard_blue_font,"fonts/FreeSerif.ttf",30,nf_standard_blue_color);
925b7e58 sago007 2011-04-25 16:35 644
    nf_standard_blue_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 645
    NFont_OpenFont(&nf_standard_small_font,"fonts/FreeSerif.ttf",16,nf_standard_small_color);
925b7e58 sago007 2011-04-25 16:35 646
    nf_standard_small_font.setDest(screen);
71181267 sago007 2011-04-29 19:22 647
    NFont_OpenFont(&nf_scoreboard_font,"fonts/PenguinAttack.ttf",20,nf_button_color);
71181267 sago007 2011-04-29 19:22 648
    nf_scoreboard_font.setDest(boardBackBack);
71181267 sago007 2011-04-29 19:22 649
    nf_scoreboard_font.draw(370,148,"Score:");
71181267 sago007 2011-04-29 19:22 650
    nf_scoreboard_font.draw(370,197,"Time:");
71181267 sago007 2011-04-29 19:22 651
    nf_scoreboard_font.draw(370,246,"Chain:");
71181267 sago007 2011-04-29 19:22 652
    nf_scoreboard_font.draw(370,295,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 653
71181267 sago007 2011-04-29 19:22 654
    
89c4a3a6 sago007 2008-08-29 14:32 655
//Loads the sound if sound present
89c4a3a6 sago007 2008-08-29 14:32 656
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 657
    {
89c4a3a6 sago007 2008-08-29 14:32 658
        //And here the music:
89c4a3a6 sago007 2008-08-29 14:32 659
        bgMusic = Mix_LoadMUS2((char*)"music/bgMusic.ogg");
6d48320c sago007 2009-03-28 17:06 660
        highbeatMusic = Mix_LoadMUS2((char*)"music/highbeat.ogg");
89c4a3a6 sago007 2008-08-29 14:32 661
        //the music... we just hope it exists, else the user won't hear anything
89c4a3a6 sago007 2008-08-29 14:32 662
        //Same goes for the sounds
89c4a3a6 sago007 2008-08-29 14:32 663
        boing = Mix_LoadWAV2((char*)"sound/pop.ogg");
89c4a3a6 sago007 2008-08-29 14:32 664
        applause = Mix_LoadWAV2((char*)"sound/applause.ogg");
89c4a3a6 sago007 2008-08-29 14:32 665
        photoClick = Mix_LoadWAV2((char*)"sound/cameraclick.ogg");
89c4a3a6 sago007 2008-08-29 14:32 666
        typingChunk = Mix_LoadWAV2((char*)"sound/typing.ogg");
89c4a3a6 sago007 2008-08-29 14:32 667
        counterChunk = Mix_LoadWAV2((char*)"sound/counter.ogg");
24a6ea5f sago007 2008-11-13 22:28 668
        counterFinalChunk = Mix_LoadWAV2((char*)"sound/counterFinal.ogg");
89c4a3a6 sago007 2008-08-29 14:32 669
    } //All sound has been loaded or not
89c4a3a6 sago007 2008-08-29 14:32 670
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 671
} //InitImages()
89c4a3a6 sago007 2008-08-29 14:32 672
89c4a3a6 sago007 2008-08-29 14:32 673
89c4a3a6 sago007 2008-08-29 14:32 674
//Unload images and fonts and sounds
89c4a3a6 sago007 2008-08-29 14:32 675
void UnloadImages()
89c4a3a6 sago007 2008-08-29 14:32 676
{
866417ca sago007 2009-05-10 21:35 677
    cout << "Unloading data..." << endl;
89c4a3a6 sago007 2008-08-29 14:32 678
    if (!NoSound) //Only unload then it has been loaded!
89c4a3a6 sago007 2008-08-29 14:32 679
    {
866417ca sago007 2009-05-10 21:35 680
        Mix_HaltMusic();
89c4a3a6 sago007 2008-08-29 14:32 681
        Mix_FreeMusic(bgMusic);
6d48320c sago007 2009-03-28 17:06 682
        Mix_FreeMusic(highbeatMusic);
89c4a3a6 sago007 2008-08-29 14:32 683
        Mix_FreeChunk(boing);
89c4a3a6 sago007 2008-08-29 14:32 684
        Mix_FreeChunk(applause);
89c4a3a6 sago007 2008-08-29 14:32 685
        Mix_FreeChunk(photoClick);
89c4a3a6 sago007 2008-08-29 14:32 686
        Mix_FreeChunk(counterChunk);
24a6ea5f sago007 2008-11-13 22:28 687
        Mix_FreeChunk(counterFinalChunk);
89c4a3a6 sago007 2008-08-29 14:32 688
        Mix_FreeChunk(typingChunk);
89c4a3a6 sago007 2008-08-29 14:32 689
    }
89c4a3a6 sago007 2008-08-29 14:32 690
    //Free surfaces:
89c4a3a6 sago007 2008-08-29 14:32 691
    //I think this will crash, at least it happend to me...
866417ca sago007 2009-05-10 21:35 692
    //Chrashes no more. Caused by an undocumented double free
89c4a3a6 sago007 2008-08-29 14:32 693
    SDL_FreeSurface(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 694
    SDL_FreeSurface(background);
43611709 sago007 2011-04-23 17:18 695
    //SDL_FreeSurface(bNewGame);
89c4a3a6 sago007 2008-08-29 14:32 696
    SDL_FreeSurface(b1player);
89c4a3a6 sago007 2008-08-29 14:32 697
    SDL_FreeSurface(b2players);
89c4a3a6 sago007 2008-08-29 14:32 698
    SDL_FreeSurface(bVsMode);
e3e0644e sago007 2008-09-25 14:00 699
    SDL_FreeSurface(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 700
    SDL_FreeSurface(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 701
    SDL_FreeSurface(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 702
    SDL_FreeSurface(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 703
    SDL_FreeSurface(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 704
    SDL_FreeSurface(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 705
    SDL_FreeSurface(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 706
    SDL_FreeSurface(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 707
    SDL_FreeSurface(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 708
    SDL_FreeSurface(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 709
    SDL_FreeSurface(bSave);
89c4a3a6 sago007 2008-08-29 14:32 710
    SDL_FreeSurface(bLoad);
1572de2b sago007 2008-09-11 18:15 711
    #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 712
    SDL_FreeSurface(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 713
    SDL_FreeSurface(bHost);
89c4a3a6 sago007 2008-08-29 14:32 714
    SDL_FreeSurface(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 715
    #endif
89c4a3a6 sago007 2008-08-29 14:32 716
    SDL_FreeSurface(bExit);
89c4a3a6 sago007 2008-08-29 14:32 717
    SDL_FreeSurface(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 718
    SDL_FreeSurface(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 719
    SDL_FreeSurface(bricks[0]);
89c4a3a6 sago007 2008-08-29 14:32 720
    SDL_FreeSurface(bricks[1]);
89c4a3a6 sago007 2008-08-29 14:32 721
    SDL_FreeSurface(bricks[2]);
89c4a3a6 sago007 2008-08-29 14:32 722
    SDL_FreeSurface(bricks[3]);
89c4a3a6 sago007 2008-08-29 14:32 723
    SDL_FreeSurface(bricks[4]);
89c4a3a6 sago007 2008-08-29 14:32 724
    SDL_FreeSurface(bricks[5]);
89c4a3a6 sago007 2008-08-29 14:32 725
    SDL_FreeSurface(bricks[6]);
89c4a3a6 sago007 2008-08-29 14:32 726
    SDL_FreeSurface(crossover);
89c4a3a6 sago007 2008-08-29 14:32 727
    SDL_FreeSurface(balls[0]);
89c4a3a6 sago007 2008-08-29 14:32 728
    SDL_FreeSurface(balls[1]);
89c4a3a6 sago007 2008-08-29 14:32 729
    SDL_FreeSurface(balls[2]);
89c4a3a6 sago007 2008-08-29 14:32 730
    SDL_FreeSurface(balls[3]);
89c4a3a6 sago007 2008-08-29 14:32 731
    SDL_FreeSurface(balls[4]);
89c4a3a6 sago007 2008-08-29 14:32 732
    SDL_FreeSurface(balls[5]);
89c4a3a6 sago007 2008-08-29 14:32 733
    SDL_FreeSurface(balls[6]);
89c4a3a6 sago007 2008-08-29 14:32 734
    SDL_FreeSurface(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 735
    SDL_FreeSurface(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 736
    SDL_FreeSurface(backBoard); //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 737
    SDL_FreeSurface(iGameOver);
89c4a3a6 sago007 2008-08-29 14:32 738
    SDL_FreeSurface(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 739
    SDL_FreeSurface(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 740
    SDL_FreeSurface(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 741
    SDL_FreeSurface(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 742
    SDL_FreeSurface(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 743
    SDL_FreeSurface(bOn);
89c4a3a6 sago007 2008-08-29 14:32 744
    SDL_FreeSurface(bOff);
89c4a3a6 sago007 2008-08-29 14:32 745
    SDL_FreeSurface(bChange);
89c4a3a6 sago007 2008-08-29 14:32 746
    SDL_FreeSurface(b1024);
89c4a3a6 sago007 2008-08-29 14:32 747
    SDL_FreeSurface(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 748
    //SDL_FreeSurface(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 749
    SDL_FreeSurface(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 750
    SDL_FreeSurface(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 751
    SDL_FreeSurface(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 752
    SDL_FreeSurface(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 753
    SDL_FreeSurface(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 754
    SDL_FreeSurface(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 755
    SDL_FreeSurface(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 756
    SDL_FreeSurface(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 757
    SDL_FreeSurface(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 758
    SDL_FreeSurface(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 759
    SDL_FreeSurface(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 760
    SDL_FreeSurface(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 761
    SDL_FreeSurface(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 762
    SDL_FreeSurface(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 763
    SDL_FreeSurface(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 764
    SDL_FreeSurface(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 765
    SDL_FreeSurface(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 766
    SDL_FreeSurface(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 767
    SDL_FreeSurface(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 768
    SDL_FreeSurface(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 769
    SDL_FreeSurface(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 770
    SDL_FreeSurface(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 771
    SDL_FreeSurface(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 772
    SDL_FreeSurface(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 773
    SDL_FreeSurface(transCover);
8d488d32 sago007 2011-04-17 13:02 774
    mouse.MakeNull();
43611709 sago007 2011-04-23 17:18 775
    bNewGame.MakeNull();
89c4a3a6 sago007 2008-08-29 14:32 776
}
89c4a3a6 sago007 2008-08-29 14:32 777
89c4a3a6 sago007 2008-08-29 14:32 778
//Function to convert numbers to string
769a41a0 sago007 2008-09-24 12:54 779
/*string itoa(int num)
89c4a3a6 sago007 2008-08-29 14:32 780
{
89c4a3a6 sago007 2008-08-29 14:32 781
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 782
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 783
    return converter.str();
769a41a0 sago007 2008-09-24 12:54 784
}*/
89c4a3a6 sago007 2008-08-29 14:32 785
89c4a3a6 sago007 2008-08-29 14:32 786
//Function to convert numbers to string (2 diget)
4b0c248f sago007 2010-11-10 21:13 787
static string itoa2(int num)
89c4a3a6 sago007 2008-08-29 14:32 788
{
89c4a3a6 sago007 2008-08-29 14:32 789
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 790
    if(num<10)
89c4a3a6 sago007 2008-08-29 14:32 791
        converter << "0";
89c4a3a6 sago007 2008-08-29 14:32 792
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 793
    return converter.str();
89c4a3a6 sago007 2008-08-29 14:32 794
}
89c4a3a6 sago007 2008-08-29 14:32 795
89c4a3a6 sago007 2008-08-29 14:32 796
/*Loads all the puzzle levels*/
4b0c248f sago007 2010-11-10 21:13 797
static int LoadPuzzleStages()
89c4a3a6 sago007 2008-08-29 14:32 798
{
89c4a3a6 sago007 2008-08-29 14:32 799
    //if(puzzleLoaded)
89c4a3a6 sago007 2008-08-29 14:32 800
    //    return 1;
aca2f4b0 sago007 2009-05-10 18:11 801
    if (!PHYSFS_exists(("puzzles/"+puzzleName).c_str()))
aca2f4b0 sago007 2009-05-10 18:11 802
    {
aca2f4b0 sago007 2009-05-10 18:11 803
        cout << "File not in blockattack.data: " << ("puzzles/"+puzzleName) << endl;
aca2f4b0 sago007 2009-05-10 18:11 804
        return -1; //file doesn't exist
aca2f4b0 sago007 2009-05-10 18:11 805
    }
aca2f4b0 sago007 2009-05-10 18:11 806
    PhysFS::ifstream inFile(("puzzles/"+puzzleName).c_str());
aca2f4b0 sago007 2009-05-10 18:11 807
89c4a3a6 sago007 2008-08-29 14:32 808
    inFile >> nrOfPuzzles;
89c4a3a6 sago007 2008-08-29 14:32 809
    if (nrOfPuzzles>maxNrOfPuzzleStages)
89c4a3a6 sago007 2008-08-29 14:32 810
        nrOfPuzzles=maxNrOfPuzzleStages;
aca2f4b0 sago007 2009-05-10 18:11 811
    for (int k=0; (k<nrOfPuzzles) /*&&(!inFile.eof())*/ ; k++)
89c4a3a6 sago007 2008-08-29 14:32 812
    {
89c4a3a6 sago007 2008-08-29 14:32 813
        inFile >> nrOfMovesAllowed[k];
89c4a3a6 sago007 2008-08-29 14:32 814
        for (int i=11;i>=0;i--)
89c4a3a6 sago007 2008-08-29 14:32 815
            for (int j=0;j<6;j++)
89c4a3a6 sago007 2008-08-29 14:32 816
            {
89c4a3a6 sago007 2008-08-29 14:32 817
                inFile >> puzzleLevels[k][j][i];
89c4a3a6 sago007 2008-08-29 14:32 818
            }
89c4a3a6 sago007 2008-08-29 14:32 819
    }
89c4a3a6 sago007 2008-08-29 14:32 820
    puzzleLoaded = true;
89c4a3a6 sago007 2008-08-29 14:32 821
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 822
}
89c4a3a6 sago007 2008-08-29 14:32 823
89c4a3a6 sago007 2008-08-29 14:32 824
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
e1290bdf sago007 2010-10-25 19:56 825
void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 826
{
89c4a3a6 sago007 2008-08-29 14:32 827
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 828
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 829
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 830
    SDL_BlitSurface(img, NULL, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 831
}
89c4a3a6 sago007 2008-08-29 14:32 832
89c4a3a6 sago007 2008-08-29 14:32 833
/*Draws a part of an image on a surface of choice*/
89c4a3a6 sago007 2008-08-29 14:32 834
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 835
{
89c4a3a6 sago007 2008-08-29 14:32 836
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 837
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 838
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 839
    SDL_Rect dest2;
89c4a3a6 sago007 2008-08-29 14:32 840
    dest2.x = x2;
89c4a3a6 sago007 2008-08-29 14:32 841
    dest2.y = y2;
89c4a3a6 sago007 2008-08-29 14:32 842
    dest2.w = w;
89c4a3a6 sago007 2008-08-29 14:32 843
    dest2.h = h;
89c4a3a6 sago007 2008-08-29 14:32 844
    SDL_BlitSurface(img, &dest2, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 845
}
89c4a3a6 sago007 2008-08-29 14:32 846
925b7e58 sago007 2011-04-25 16:35 847
void NFont_Write(SDL_Surface *target,int x,int y,string text) {
925b7e58 sago007 2011-04-25 16:35 848
    nf_standard_blue_font.setDest(target);
925b7e58 sago007 2011-04-25 16:35 849
    nf_standard_blue_font.draw(x,y,text.c_str());
925b7e58 sago007 2011-04-25 16:35 850
    nf_standard_blue_font.setDest(screen);
925b7e58 sago007 2011-04-25 16:35 851
}
925b7e58 sago007 2011-04-25 16:35 852
26ddb424 sago007 2011-06-09 20:06 853
void ResetFullscreen(){
26ddb424 sago007 2011-06-09 20:06 854
#if defined(WIN32)
26ddb424 sago007 2011-06-09 20:06 855
                        if (bFullscreen) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
26ddb424 sago007 2011-06-09 20:06 856
                        else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
26ddb424 sago007 2011-06-09 20:06 857
                        DrawIMG(background, screen, 0, 0);
26ddb424 sago007 2011-06-09 20:06 858
#else
26ddb424 sago007 2011-06-09 20:06 859
                        SDL_WM_ToggleFullScreen(screen); //Will only work in Linux
26ddb424 sago007 2011-06-09 20:06 860
#endif
26ddb424 sago007 2011-06-09 20:06 861
                        SDL_ShowCursor(SDL_DISABLE);
78d03b38 sago007 2008-11-13 19:56 862
}
78d03b38 sago007 2008-11-13 19:56 863
78d03b38 sago007 2008-11-13 19:56 864
89c4a3a6 sago007 2008-08-29 14:32 865
//The small things that are faaling when you clear something
89c4a3a6 sago007 2008-08-29 14:32 866
class aBall
89c4a3a6 sago007 2008-08-29 14:32 867
{
89c4a3a6 sago007 2008-08-29 14:32 868
private:
89c4a3a6 sago007 2008-08-29 14:32 869
    double x;
89c4a3a6 sago007 2008-08-29 14:32 870
    double y;
89c4a3a6 sago007 2008-08-29 14:32 871
    double velocityY;
89c4a3a6 sago007 2008-08-29 14:32 872
    double velocityX;
89c4a3a6 sago007 2008-08-29 14:32 873
    int color;
89c4a3a6 sago007 2008-08-29 14:32 874
    unsigned long int lastTime;
89c4a3a6 sago007 2008-08-29 14:32 875
public:
89c4a3a6 sago007 2008-08-29 14:32 876
89c4a3a6 sago007 2008-08-29 14:32 877
    aBall()
89c4a3a6 sago007 2008-08-29 14:32 878
    {}
89c4a3a6 sago007 2008-08-29 14:32 879
89c4a3a6 sago007 2008-08-29 14:32 880
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 881
    aBall(int X, int Y, bool right, int coulor)
89c4a3a6 sago007 2008-08-29 14:32 882
    {
89c4a3a6 sago007 2008-08-29 14:32 883
        double tal = 1.0;
89c4a3a6 sago007 2008-08-29 14:32 884
        velocityY = -tal*startVelocityY;
89c4a3a6 sago007 2008-08-29 14:32 885
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 886
        x = (double)X;
89c4a3a6 sago007 2008-08-29 14:32 887
        y = (double)Y;
89c4a3a6 sago007 2008-08-29 14:32 888
        color = coulor;
89c4a3a6 sago007 2008-08-29 14:32 889
        if (right)
89c4a3a6 sago007 2008-08-29 14:32 890
            velocityX = tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 891
        else
89c4a3a6 sago007 2008-08-29 14:32 892
            velocityX = -tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 893
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 894
89c4a3a6 sago007 2008-08-29 14:32 895
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 896
    ~aBall()
89c4a3a6 sago007 2008-08-29 14:32 897
    {
89c4a3a6 sago007 2008-08-29 14:32 898
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 899
89c4a3a6 sago007 2008-08-29 14:32 900
    void update()
89c4a3a6 sago007 2008-08-29 14:32 901
    {
89c4a3a6 sago007 2008-08-29 14:32 902
        double timePassed = (((double)(currentTime-lastTime))/1000.0);  //time passed in seconds
89c4a3a6 sago007 2008-08-29 14:32 903
        x = x+timePassed*velocityX;
89c4a3a6 sago007 2008-08-29 14:32 904
        y = y+timePassed*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 905
        velocityY = velocityY + gravity*timePassed;
89c4a3a6 sago007 2008-08-29 14:32 906
        if (y<1.0)
89c4a3a6 sago007 2008-08-29 14:32 907
            velocityY=10.0;
89c4a3a6 sago007 2008-08-29 14:32 908
        if ((velocityY>minVelocity) && (y>(double)(768-ballSize)) && (y<768.0))
89c4a3a6 sago007 2008-08-29 14:32 909
        {
89c4a3a6 sago007 2008-08-29 14:32 910
            velocityY = -0.70*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 911
            y = 768.0-ballSize;
89c4a3a6 sago007 2008-08-29 14:32 912
        }
89c4a3a6 sago007 2008-08-29 14:32 913
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 914
    }
89c4a3a6 sago007 2008-08-29 14:32 915
89c4a3a6 sago007 2008-08-29 14:32 916
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 917
    {
89c4a3a6 sago007 2008-08-29 14:32 918
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 919
    }
89c4a3a6 sago007 2008-08-29 14:32 920
89c4a3a6 sago007 2008-08-29 14:32 921
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 922
    {
89c4a3a6 sago007 2008-08-29 14:32 923
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 924
    }
89c4a3a6 sago007 2008-08-29 14:32 925
89c4a3a6 sago007 2008-08-29 14:32 926
    int getColor()
89c4a3a6 sago007 2008-08-29 14:32 927
    {
89c4a3a6 sago007 2008-08-29 14:32 928
        return color;
89c4a3a6 sago007 2008-08-29 14:32 929
    }
89c4a3a6 sago007 2008-08-29 14:32 930
};  //aBall
89c4a3a6 sago007 2008-08-29 14:32 931
4b0c248f sago007 2010-11-10 21:13 932
static const int maxNumberOfBalls = 6*12*2*2;
89c4a3a6 sago007 2008-08-29 14:32 933
89c4a3a6 sago007 2008-08-29 14:32 934
class ballManeger
89c4a3a6 sago007 2008-08-29 14:32 935
{
89c4a3a6 sago007 2008-08-29 14:32 936
public:
89c4a3a6 sago007 2008-08-29 14:32 937
    aBall ballArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 938
    bool ballUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 939
    //The old ball information is also saved so balls can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 940
    aBall oldBallArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 941
    bool oldBallUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 942
89c4a3a6 sago007 2008-08-29 14:32 943
    ballManeger()
89c4a3a6 sago007 2008-08-29 14:32 944
    {
89c4a3a6 sago007 2008-08-29 14:32 945
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 946
        {
89c4a3a6 sago007 2008-08-29 14:32 947
            ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 948
            oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 949
        }
89c4a3a6 sago007 2008-08-29 14:32 950
    }
89c4a3a6 sago007 2008-08-29 14:32 951
6d48320c sago007 2009-03-28 17:06 952
    //Adds a ball to the screen at given coordiantes, traveling right or not with color
89c4a3a6 sago007 2008-08-29 14:32 953
    int addBall(int x, int y,bool right,int color)
89c4a3a6 sago007 2008-08-29 14:32 954
    {
89c4a3a6 sago007 2008-08-29 14:32 955
        int ballNumber = 0;
6d48320c sago007 2009-03-28 17:06 956
        //Find a free ball
89c4a3a6 sago007 2008-08-29 14:32 957
        while ((ballUsed[ballNumber])&&(ballNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 958
            ballNumber++;
6d48320c sago007 2009-03-28 17:06 959
        //Could not find a free ball, return -1
89c4a3a6 sago007 2008-08-29 14:32 960
        if (ballNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 961
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 962
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 963
        ballArray[ballNumber] = aBall(x,y,right,color);
89c4a3a6 sago007 2008-08-29 14:32 964
        ballUsed[ballNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 965
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 966
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 967
89c4a3a6 sago007 2008-08-29 14:32 968
    void update()
89c4a3a6 sago007 2008-08-29 14:32 969
    {
89c4a3a6 sago007 2008-08-29 14:32 970
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 971
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 972
        {
89c4a3a6 sago007 2008-08-29 14:32 973
89c4a3a6 sago007 2008-08-29 14:32 974
            if (ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 975
            {
89c4a3a6 sago007 2008-08-29 14:32 976
                oldBallUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 977
                oldBallArray[i] = ballArray[i];
89c4a3a6 sago007 2008-08-29 14:32 978
                ballArray[i].update();
6d48320c sago007 2009-03-28 17:06 979
                if (ballArray[i].getY()>800 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize)
89c4a3a6 sago007 2008-08-29 14:32 980
                {
89c4a3a6 sago007 2008-08-29 14:32 981
                    ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 982
                }
89c4a3a6 sago007 2008-08-29 14:32 983
            }
89c4a3a6 sago007 2008-08-29 14:32 984
            else
89c4a3a6 sago007 2008-08-29 14:32 985
            {
89c4a3a6 sago007 2008-08-29 14:32 986
                oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 987
            }
89c4a3a6 sago007 2008-08-29 14:32 988
        }
89c4a3a6 sago007 2008-08-29 14:32 989
    } //update
89c4a3a6 sago007 2008-08-29 14:32 990
89c4a3a6 sago007 2008-08-29 14:32 991
89c4a3a6 sago007 2008-08-29 14:32 992
}; //theBallManeger
89c4a3a6 sago007 2008-08-29 14:32 993
4b0c248f sago007 2010-11-10 21:13 994
static ballManeger theBallManeger;
89c4a3a6 sago007 2008-08-29 14:32 995
89c4a3a6 sago007 2008-08-29 14:32 996
//a explosions, non moving
89c4a3a6 sago007 2008-08-29 14:32 997
class anExplosion
89c4a3a6 sago007 2008-08-29 14:32 998
{
89c4a3a6 sago007 2008-08-29 14:32 999
private:
89c4a3a6 sago007 2008-08-29 14:32 1000
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1001
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1002
    Uint8 frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 1003
#define frameLength 80
89c4a3a6 sago007 2008-08-29 14:32 1004
    //How long an image in an animation should be showed
89c4a3a6 sago007 2008-08-29 14:32 1005
#define maxFrame 4
89c4a3a6 sago007 2008-08-29 14:32 1006
    //How many images there are in the animation
89c4a3a6 sago007 2008-08-29 14:32 1007
    unsigned long int placeTime; //Then the explosion occored
89c4a3a6 sago007 2008-08-29 14:32 1008
public:
89c4a3a6 sago007 2008-08-29 14:32 1009
89c4a3a6 sago007 2008-08-29 14:32 1010
    anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 1011
    {}
89c4a3a6 sago007 2008-08-29 14:32 1012
89c4a3a6 sago007 2008-08-29 14:32 1013
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1014
    anExplosion(int X, int Y)
89c4a3a6 sago007 2008-08-29 14:32 1015
    {
89c4a3a6 sago007 2008-08-29 14:32 1016
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1017
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1018
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1019
        frameNumber=0;
89c4a3a6 sago007 2008-08-29 14:32 1020
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1021
89c4a3a6 sago007 2008-08-29 14:32 1022
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1023
    ~anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 1024
    {
89c4a3a6 sago007 2008-08-29 14:32 1025
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1026
89c4a3a6 sago007 2008-08-29 14:32 1027
    //true if animation has played and object should be removed from the screen
89c4a3a6 sago007 2008-08-29 14:32 1028
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1029
    {
89c4a3a6 sago007 2008-08-29 14:32 1030
        frameNumber = (currentTime-placeTime)/frameLength;
89c4a3a6 sago007 2008-08-29 14:32 1031
        return (!(frameNumber<maxFrame));
89c4a3a6 sago007 2008-08-29 14:32 1032
    }
89c4a3a6 sago007 2008-08-29 14:32 1033
89c4a3a6 sago007 2008-08-29 14:32 1034
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1035
    {
89c4a3a6 sago007 2008-08-29 14:32 1036
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 1037
    }
89c4a3a6 sago007 2008-08-29 14:32 1038
89c4a3a6 sago007 2008-08-29 14:32 1039
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1040
    {
89c4a3a6 sago007 2008-08-29 14:32 1041
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 1042
    }
89c4a3a6 sago007 2008-08-29 14:32 1043
89c4a3a6 sago007 2008-08-29 14:32 1044
    int getFrame()
89c4a3a6 sago007 2008-08-29 14:32 1045
    {
89c4a3a6 sago007 2008-08-29 14:32 1046
        return frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 1047
    }
89c4a3a6 sago007 2008-08-29 14:32 1048
};  //nExplosion
89c4a3a6 sago007 2008-08-29 14:32 1049
89c4a3a6 sago007 2008-08-29 14:32 1050
class explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1051
{
89c4a3a6 sago007 2008-08-29 14:32 1052
public:
89c4a3a6 sago007 2008-08-29 14:32 1053
    anExplosion explosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1054
    bool explosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1055
    //The old explosion information is also saved so explosions can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1056
    anExplosion oldExplosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1057
    bool oldExplosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1058
89c4a3a6 sago007 2008-08-29 14:32 1059
    explosionManeger()
89c4a3a6 sago007 2008-08-29 14:32 1060
    {
89c4a3a6 sago007 2008-08-29 14:32 1061
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1062
        {
89c4a3a6 sago007 2008-08-29 14:32 1063
            explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1064
            oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1065
        }
89c4a3a6 sago007 2008-08-29 14:32 1066
    }
89c4a3a6 sago007 2008-08-29 14:32 1067
89c4a3a6 sago007 2008-08-29 14:32 1068
    int addExplosion(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 1069
    {
89c4a3a6 sago007 2008-08-29 14:32 1070
        //cout << "Tries to add an explosion" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1071
        int explosionNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1072
        while ((explosionUsed[explosionNumber])&&(explosionNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 1073
            explosionNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1074
        if (explosionNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1075
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1076
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1077
        explosionArray[explosionNumber] = anExplosion(x,y);
89c4a3a6 sago007 2008-08-29 14:32 1078
        explosionUsed[explosionNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1079
        //cout << "Explosion added" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1080
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1081
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 1082
89c4a3a6 sago007 2008-08-29 14:32 1083
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1084
    {
89c4a3a6 sago007 2008-08-29 14:32 1085
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1086
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1087
        {
89c4a3a6 sago007 2008-08-29 14:32 1088
89c4a3a6 sago007 2008-08-29 14:32 1089
            if (explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1090
            {
89c4a3a6 sago007 2008-08-29 14:32 1091
                oldExplosionUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1092
                oldExplosionArray[i] = explosionArray[i];
89c4a3a6 sago007 2008-08-29 14:32 1093
                if (explosionArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1094
                {
89c4a3a6 sago007 2008-08-29 14:32 1095
                    explosionArray[i].~anExplosion();
89c4a3a6 sago007 2008-08-29 14:32 1096
                    explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1097
                    //cout << "Explosion removed" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1098
                }
89c4a3a6 sago007 2008-08-29 14:32 1099
            }
89c4a3a6 sago007 2008-08-29 14:32 1100
            else
89c4a3a6 sago007 2008-08-29 14:32 1101
            {
89c4a3a6 sago007 2008-08-29 14:32 1102
                oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1103
            }
89c4a3a6 sago007 2008-08-29 14:32 1104
        }
89c4a3a6 sago007 2008-08-29 14:32 1105
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1106
89c4a3a6 sago007 2008-08-29 14:32 1107
89c4a3a6 sago007 2008-08-29 14:32 1108
}; //explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1109
4b0c248f sago007 2010-11-10 21:13 1110
static explosionManeger theExplosionManeger;
89c4a3a6 sago007 2008-08-29 14:32 1111
89c4a3a6 sago007 2008-08-29 14:32 1112
//text pop-up
89c4a3a6 sago007 2008-08-29 14:32 1113
class textMessage
89c4a3a6 sago007 2008-08-29 14:32 1114
{
89c4a3a6 sago007 2008-08-29 14:32 1115
private:
89c4a3a6 sago007 2008-08-29 14:32 1116
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1117
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1118
    char textt[10];
89c4a3a6 sago007 2008-08-29 14:32 1119
    unsigned long int time;
89c4a3a6 sago007 2008-08-29 14:32 1120
    unsigned long int placeTime; //Then the text was placed
89c4a3a6 sago007 2008-08-29 14:32 1121
public:
89c4a3a6 sago007 2008-08-29 14:32 1122
89c4a3a6 sago007 2008-08-29 14:32 1123
    textMessage()
89c4a3a6 sago007 2008-08-29 14:32 1124
    {}
89c4a3a6 sago007 2008-08-29 14:32 1125
89c4a3a6 sago007 2008-08-29 14:32 1126
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1127
    textMessage(int X, int Y,const char* Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1128
    {
89c4a3a6 sago007 2008-08-29 14:32 1129
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1130
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1131
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1132
        strncpy(textt,Text,10);
89c4a3a6 sago007 2008-08-29 14:32 1133
        textt[9]=0;
89c4a3a6 sago007 2008-08-29 14:32 1134
        time = Time;
89c4a3a6 sago007 2008-08-29 14:32 1135
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1136
89c4a3a6 sago007 2008-08-29 14:32 1137
    //true if the text has expired
89c4a3a6 sago007 2008-08-29 14:32 1138
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1139
    {
89c4a3a6 sago007 2008-08-29 14:32 1140
        return currentTime-placeTime>time;
89c4a3a6 sago007 2008-08-29 14:32 1141
    }
89c4a3a6 sago007 2008-08-29 14:32 1142
89c4a3a6 sago007 2008-08-29 14:32 1143
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1144
    {
89c4a3a6 sago007 2008-08-29 14:32 1145
        return x;
89c4a3a6 sago007 2008-08-29 14:32 1146
    }
89c4a3a6 sago007 2008-08-29 14:32 1147
89c4a3a6 sago007 2008-08-29 14:32 1148
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1149
    {
89c4a3a6 sago007 2008-08-29 14:32 1150
        return y;
89c4a3a6 sago007 2008-08-29 14:32 1151
    }
89c4a3a6 sago007 2008-08-29 14:32 1152
89c4a3a6 sago007 2008-08-29 14:32 1153
    char* getText()
89c4a3a6 sago007 2008-08-29 14:32 1154
    {
89c4a3a6 sago007 2008-08-29 14:32 1155
        return textt;
89c4a3a6 sago007 2008-08-29 14:32 1156
    }
89c4a3a6 sago007 2008-08-29 14:32 1157
};  //text popup
89c4a3a6 sago007 2008-08-29 14:32 1158
89c4a3a6 sago007 2008-08-29 14:32 1159
class textManeger
89c4a3a6 sago007 2008-08-29 14:32 1160
{
89c4a3a6 sago007 2008-08-29 14:32 1161
public:
89c4a3a6 sago007 2008-08-29 14:32 1162
    textMessage textArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1163
    bool textUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1164
    //The old text information is also saved so text can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1165
    textMessage oldTextArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1166
    bool oldTextUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1167
89c4a3a6 sago007 2008-08-29 14:32 1168
    textManeger()
89c4a3a6 sago007 2008-08-29 14:32 1169
    {
89c4a3a6 sago007 2008-08-29 14:32 1170
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1171
        {
89c4a3a6 sago007 2008-08-29 14:32 1172
            textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1173
            oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1174
        }
89c4a3a6 sago007 2008-08-29 14:32 1175
    }
89c4a3a6 sago007 2008-08-29 14:32 1176
89c4a3a6 sago007 2008-08-29 14:32 1177
    int addText(int x, int y,string Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1178
    {
89c4a3a6 sago007 2008-08-29 14:32 1179
        //cout << "Tries to add text" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1180
        int textNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1181
        while ((textNumber<maxNumberOfBalls)&&((textUsed[textNumber])||(oldTextUsed[textNumber])))
89c4a3a6 sago007 2008-08-29 14:32 1182
            textNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1183
        if (textNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1184
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1185
        //cout << "adding to: " << textNumber << ":" << textUsed[textNumber] << ":" << &textArray[textNumber] << endl;
89c4a3a6 sago007 2008-08-29 14:32 1186
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1187
        textArray[textNumber] = textMessage(x,y,Text.c_str(),Time);
89c4a3a6 sago007 2008-08-29 14:32 1188
        textUsed[textNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1189
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1190
    }  //addText
89c4a3a6 sago007 2008-08-29 14:32 1191
89c4a3a6 sago007 2008-08-29 14:32 1192
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1193
    {
89c4a3a6 sago007 2008-08-29 14:32 1194
        //cout << "Running update" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1195
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1196
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1197
        {
89c4a3a6 sago007 2008-08-29 14:32 1198
89c4a3a6 sago007 2008-08-29 14:32 1199
            if (textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1200
            {
89c4a3a6 sago007 2008-08-29 14:32 1201
                if (!oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1202
                {
89c4a3a6 sago007 2008-08-29 14:32 1203
                    oldTextUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1204
                    oldTextArray[i] = textMessage(textArray[i]);
89c4a3a6 sago007 2008-08-29 14:32 1205
                }
89c4a3a6 sago007 2008-08-29 14:32 1206
                if (textArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1207
                {
89c4a3a6 sago007 2008-08-29 14:32 1208
                    textArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1209
                    textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1210
                }
89c4a3a6 sago007 2008-08-29 14:32 1211
            }
89c4a3a6 sago007 2008-08-29 14:32 1212
            else
89c4a3a6 sago007 2008-08-29 14:32 1213
                if (oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1214
                {
89c4a3a6 sago007 2008-08-29 14:32 1215
                    oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1216
                    oldTextArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1217
                }
89c4a3a6 sago007 2008-08-29 14:32 1218
        }
89c4a3a6 sago007 2008-08-29 14:32 1219
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1220
89c4a3a6 sago007 2008-08-29 14:32 1221
89c4a3a6 sago007 2008-08-29 14:32 1222
}; //textManeger
89c4a3a6 sago007 2008-08-29 14:32 1223
4b0c248f sago007 2010-11-10 21:13 1224
static textManeger theTextManeger;
89c4a3a6 sago007 2008-08-29 14:32 1225
89c4a3a6 sago007 2008-08-29 14:32 1226
//Here comes the Block Game object
89c4a3a6 sago007 2008-08-29 14:32 1227
#include "BlockGame.hpp"
17916a2e sago007 2010-11-07 11:26 1228
#include "BlockGame.cpp"
89c4a3a6 sago007 2008-08-29 14:32 1229
6b1dc7a6 sago007 2010-11-08 21:03 1230
class BlockGameSdl : public BlockGame {
6b1dc7a6 sago007 2010-11-08 21:03 1231
public:
6b1dc7a6 sago007 2010-11-08 21:03 1232
    SDL_Surface* sBoard;
6b1dc7a6 sago007 2010-11-08 21:03 1233
6b1dc7a6 sago007 2010-11-08 21:03 1234
    BlockGameSdl(int tx, int ty) {
6b1dc7a6 sago007 2010-11-08 21:03 1235
        tmp = IMG_Load2((char*)"gfx/BackBoard.png");
6b1dc7a6 sago007 2010-11-08 21:03 1236
        sBoard = SDL_DisplayFormat(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1237
        SDL_FreeSurface(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1238
        //BlockGame::BlockGame(tx,ty);
6b1dc7a6 sago007 2010-11-08 21:03 1239
        BlockGame::topx = tx;
6b1dc7a6 sago007 2010-11-08 21:03 1240
        BlockGame::topy = ty;
6b1dc7a6 sago007 2010-11-08 21:03 1241
    }
6b1dc7a6 sago007 2010-11-08 21:03 1242
    ~BlockGameSdl() {
6b1dc7a6 sago007 2010-11-08 21:03 1243
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1244
    }
6b1dc7a6 sago007 2010-11-08 21:03 1245
private:
6b1dc7a6 sago007 2010-11-08 21:03 1246
    void convertSurface() {
6b1dc7a6 sago007 2010-11-08 21:03 1247
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1248
        sBoard = SDL_DisplayFormat(backBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1249
    }
6b1dc7a6 sago007 2010-11-08 21:03 1250
    //Draws all the bricks to the board (including garbage)
6b1dc7a6 sago007 2010-11-08 21:03 1251
    void PaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1252
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1253
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1254
                if ((board[j][i]%10 != -1) && (board[j][i]%10 < 7) && ((board[j][i]/1000000)%10==0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1255
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1256
                    if ((board[j][i]/BLOCKWAIT)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1257
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1258
                    if ((board[j][i]/BLOCKHANG)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1259
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1260
6b1dc7a6 sago007 2010-11-08 21:03 1261
                }
6b1dc7a6 sago007 2010-11-08 21:03 1262
                if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1263
                    int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1264
                    int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1265
                    if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1266
                    else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1267
                    if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1268
                    else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1269
                    if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1270
                    else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1271
                    if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1272
                    else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1273
                    if ((left == number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1274
                        DrawIMG(garbageFill, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1275
                    if ((left != number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1276
                        DrawIMG(garbageL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1277
                    if ((left == number)&&(right != number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1278
                        DrawIMG(garbageR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1279
                    if ((left == number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1280
                        DrawIMG(garbageT, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1281
                    if ((left == number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1282
                        DrawIMG(garbageB, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1283
                    if ((left != number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1284
                        DrawIMG(garbageTL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1285
                    if ((left != number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1286
                        DrawIMG(garbageBL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1287
                    if ((left == number)&&(right != number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1288
                        DrawIMG(garbageTR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1289
                    if ((left == number)&&(right != number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1290
                        DrawIMG(garbageBR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1291
                    if ((left == number)&&(right != number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1292
                        DrawIMG(garbageMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1293
                    if ((left == number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1294
                        DrawIMG(garbageM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1295
                    if ((left != number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1296
                        DrawIMG(garbageML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1297
                }
6b1dc7a6 sago007 2010-11-08 21:03 1298
                if ((board[j][i]/1000000)%10==2) {
6b1dc7a6 sago007 2010-11-08 21:03 1299
                    if (j==0)
6b1dc7a6 sago007 2010-11-08 21:03 1300
                        DrawIMG(garbageGML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1301
                    else
6b1dc7a6 sago007 2010-11-08 21:03 1302
                        if (j==5)
6b1dc7a6 sago007 2010-11-08 21:03 1303
                            DrawIMG(garbageGMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1304
                        else
6b1dc7a6 sago007 2010-11-08 21:03 1305
                            DrawIMG(garbageGM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1306
                }
6b1dc7a6 sago007 2010-11-08 21:03 1307
            }
6b1dc7a6 sago007 2010-11-08 21:03 1308
        const int j = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1309
6b1dc7a6 sago007 2010-11-08 21:03 1310
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1311
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1312
            if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1313
                int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1314
                int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1315
                if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1316
                else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1317
                if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1318
                else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1319
                if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1320
                else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1321
                if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1322
                else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1323
                if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1324
                    DrawIMG(smiley[board[j][i]%4], sBoard, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1325
                }
6b1dc7a6 sago007 2010-11-08 21:03 1326
                if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1327
                {
6b1dc7a6 sago007 2010-11-08 21:03 1328
                    garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1329
                }
6b1dc7a6 sago007 2010-11-08 21:03 1330
                else {
6b1dc7a6 sago007 2010-11-08 21:03 1331
                    //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1332
                    garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1333
                }
6b1dc7a6 sago007 2010-11-08 21:03 1334
6b1dc7a6 sago007 2010-11-08 21:03 1335
            }
6b1dc7a6 sago007 2010-11-08 21:03 1336
        }
6b1dc7a6 sago007 2010-11-08 21:03 1337
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1338
            if (board[i][0]!=-1)
6b1dc7a6 sago007 2010-11-08 21:03 1339
                DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant
6b1dc7a6 sago007 2010-11-08 21:03 1340
6b1dc7a6 sago007 2010-11-08 21:03 1341
    }
6b1dc7a6 sago007 2010-11-08 21:03 1342
    //Paints the bricks gotten from a replay/net package
6b1dc7a6 sago007 2010-11-08 21:03 1343
    void SimplePaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1344
        /*
6b1dc7a6 sago007 2010-11-08 21:03 1345
         * 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 1346
         */
6b1dc7a6 sago007 2010-11-08 21:03 1347
        bool bbomb[6][13]; //has a bomb on it!
6b1dc7a6 sago007 2010-11-08 21:03 1348
        bool falling[6][13]; //this is falling
6b1dc7a6 sago007 2010-11-08 21:03 1349
        bool getReady[6][13]; //getReady
6b1dc7a6 sago007 2010-11-08 21:03 1350
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1351
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1352
                bbomb[i][j]=false; //All false by default
6b1dc7a6 sago007 2010-11-08 21:03 1353
                falling[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1354
                if (board[i][j]>29)
6b1dc7a6 sago007 2010-11-08 21:03 1355
                    getReady[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1356
                else
6b1dc7a6 sago007 2010-11-08 21:03 1357
                    getReady[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1358
            }
6b1dc7a6 sago007 2010-11-08 21:03 1359
        //See that is falling
6b1dc7a6 sago007 2010-11-08 21:03 1360
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1361
            bool rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1362
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1363
                if (rowFalling)
6b1dc7a6 sago007 2010-11-08 21:03 1364
                    falling[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1365
                if ((!rowFalling)&&(board[i][j]%30==-1))
6b1dc7a6 sago007 2010-11-08 21:03 1366
                    rowFalling = true;
6b1dc7a6 sago007 2010-11-08 21:03 1367
                if ((rowFalling)&&(board[i][j]%30>6))
6b1dc7a6 sago007 2010-11-08 21:03 1368
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1369
                if (getReady[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1370
                    falling[i][j]=true; //getReady is the same as falling
6b1dc7a6 sago007 2010-11-08 21:03 1371
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1372
                }
6b1dc7a6 sago007 2010-11-08 21:03 1373
            }
6b1dc7a6 sago007 2010-11-08 21:03 1374
        }
6b1dc7a6 sago007 2010-11-08 21:03 1375
        //Now looking at rows:
6b1dc7a6 sago007 2010-11-08 21:03 1376
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1377
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1378
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1379
            for (int j=1;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1380
                if ((board[i][j]%30==color)&&(!falling[i][j]))
6b1dc7a6 sago007 2010-11-08 21:03 1381
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1382
                else
6b1dc7a6 sago007 2010-11-08 21:03 1383
                    if (falling[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1384
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1385
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1386
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1387
                        color=board[i][j]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1388
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1389
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1390
                if ((count>2)&&(color>-1)&&(color)<7) {
6b1dc7a6 sago007 2010-11-08 21:03 1391
                    bbomb[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1392
                    bbomb[i][j-1]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1393
                    bbomb[i][j-2]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1394
                }
6b1dc7a6 sago007 2010-11-08 21:03 1395
            }
6b1dc7a6 sago007 2010-11-08 21:03 1396
        }
6b1dc7a6 sago007 2010-11-08 21:03 1397
        //now looking for lines
6b1dc7a6 sago007 2010-11-08 21:03 1398
        for (int i=1;i<13;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1399
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1400
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1401
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1402
                if ((board[j][i]%30==color)&&(!falling[j][i]))
6b1dc7a6 sago007 2010-11-08 21:03 1403
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1404
                else
6b1dc7a6 sago007 2010-11-08 21:03 1405
                    if (falling[j][i]) {
6b1dc7a6 sago007 2010-11-08 21:03 1406
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1407
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1408
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1409
                        color=board[j][i]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1410
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1411
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1412
                if ((count>2)&&(color>-1)&&(color<7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1413
                    bbomb[j][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1414
                    bbomb[j-1][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1415
                    bbomb[j-2][i]=true;
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
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1420
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1421
                if ((board[j][i]%10 != -1) && (board[j][i]%30 < 7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1422
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1423
                    if (bbomb[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1424
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1425
                    if (getReady[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1426
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1427
                }
6b1dc7a6 sago007 2010-11-08 21:03 1428
                if (board[j][i]%30>6) {
6b1dc7a6 sago007 2010-11-08 21:03 1429
                    if (board[j][i]%30==7)
6b1dc7a6 sago007 2010-11-08 21:03 1430
                        DrawIMG(garbageR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1431
                    if (board[j][i]%30==9)
6b1dc7a6 sago007 2010-11-08 21:03 1432
                        DrawIMG(garbageML, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1433
                    if (board[j][i]%30==10)
6b1dc7a6 sago007 2010-11-08 21:03 1434
                        DrawIMG(garbageMR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1435
                    if (board[j][i]%30==11)
6b1dc7a6 sago007 2010-11-08 21:03 1436
                        DrawIMG(garbageTR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1437
                    if (board[j][i]%30==12)
6b1dc7a6 sago007 2010-11-08 21:03 1438
                        DrawIMG(garbageTL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1439
                    if (board[j][i]%30==13)
6b1dc7a6 sago007 2010-11-08 21:03 1440
                        DrawIMG(garbageBL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1441
                    if (board[j][i]%30==14)
6b1dc7a6 sago007 2010-11-08 21:03 1442
                        DrawIMG(garbageBR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1443
                    if (board[j][i]%30==15)
6b1dc7a6 sago007 2010-11-08 21:03 1444
                        DrawIMG(garbageM, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1445
                    if (board[j][i]%30==16)
6b1dc7a6 sago007 2010-11-08 21:03 1446
                        DrawIMG(garbageFill, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1447
                    if (board[j][i]%30==17)
6b1dc7a6 sago007 2010-11-08 21:03 1448
                        DrawIMG(garbageT, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1449
                    if (board[j][i]%30==18)
6b1dc7a6 sago007 2010-11-08 21:03 1450
                        DrawIMG(garbageB, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1451
                    if (board[j][i]%30==19)
6b1dc7a6 sago007 2010-11-08 21:03 1452
                        DrawIMG(garbageL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1453
                    if (board[j][i]%30==20)
6b1dc7a6 sago007 2010-11-08 21:03 1454
                        switch(j) {
6b1dc7a6 sago007 2010-11-08 21:03 1455
                            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1456
                                DrawIMG(garbageGML, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1457
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1458
                            case 5:
6b1dc7a6 sago007 2010-11-08 21:03 1459
                                DrawIMG(garbageGMR, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1460
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1461
                            default:
6b1dc7a6 sago007 2010-11-08 21:03 1462
                                DrawIMG(garbageGM, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1463
                        }
6b1dc7a6 sago007 2010-11-08 21:03 1464
                    //cout << "IS: " << board[j][i] << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1465
                }
6b1dc7a6 sago007 2010-11-08 21:03 1466
6b1dc7a6 sago007 2010-11-08 21:03 1467
6b1dc7a6 sago007 2010-11-08 21:03 1468
            }
6b1dc7a6 sago007 2010-11-08 21:03 1469
6b1dc7a6 sago007 2010-11-08 21:03 1470
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1471
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1472
            if ((board[0][i]%30==12)&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1473
                DrawIMG(smiley[0], sBoard, 2*bsize, bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1474
            }
6b1dc7a6 sago007 2010-11-08 21:03 1475
            if (board[0][i]%30!=19) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1476
            {
6b1dc7a6 sago007 2010-11-08 21:03 1477
                garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1478
            }
6b1dc7a6 sago007 2010-11-08 21:03 1479
            else {
6b1dc7a6 sago007 2010-11-08 21:03 1480
                //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1481
                garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1482
            }
6b1dc7a6 sago007 2010-11-08 21:03 1483
6b1dc7a6 sago007 2010-11-08 21:03 1484
        }
6b1dc7a6 sago007 2010-11-08 21:03 1485
    }
6b1dc7a6 sago007 2010-11-08 21:03 1486
public:
6b1dc7a6 sago007 2010-11-08 21:03 1487
    //Draws everything
6b1dc7a6 sago007 2010-11-08 21:03 1488
    void DoPaintJob() {
6b1dc7a6 sago007 2010-11-08 21:03 1489
        DrawIMG(backBoard, sBoard, 0, 0);
925b7e58 sago007 2011-04-25 16:35 1490
        nf_standard_blue_font.setDest(sBoard); //reset to screen at the end of this funciton!
6b1dc7a6 sago007 2010-11-08 21:03 1491
        #if NETWORK
6b1dc7a6 sago007 2010-11-08 21:03 1492
        if ((!bReplaying)&&(!bNetworkPlayer))
6b1dc7a6 sago007 2010-11-08 21:03 1493
        #else
6b1dc7a6 sago007 2010-11-08 21:03 1494
        if (!bReplaying)
6b1dc7a6 sago007 2010-11-08 21:03 1495
        #endif
6b1dc7a6 sago007 2010-11-08 21:03 1496
            PaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1497
        else
6b1dc7a6 sago007 2010-11-08 21:03 1498
            SimplePaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1499
        if (stageClear) DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1);
6b1dc7a6 sago007 2010-11-08 21:03 1500
        if (puzzleMode&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1501
            //We need to write nr. of moves left!
6b1dc7a6 sago007 2010-11-08 21:03 1502
            strHolder = "Moves left: " + itoa(MovesLeft);
925b7e58 sago007 2011-04-25 16:35 1503
            nf_standard_blue_font.draw(5,5,strHolder.c_str());
925b7e58 sago007 2011-04-25 16:35 1504
            
6b1dc7a6 sago007 2010-11-08 21:03 1505
        }
6b1dc7a6 sago007 2010-11-08 21:03 1506
        if(puzzleMode && stageButtonStatus == SBpuzzleMode)
6b1dc7a6 sago007 2010-11-08 21:03 1507
        {
6b1dc7a6 sago007 2010-11-08 21:03 1508
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1509
            if(Level<nrOfPuzzles-1)
6b1dc7a6 sago007 2010-11-08 21:03 1510
            {
6b1dc7a6 sago007 2010-11-08 21:03 1511
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1512
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1513
                else
6b1dc7a6 sago007 2010-11-08 21:03 1514
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1515
            }
6b1dc7a6 sago007 2010-11-08 21:03 1516
            else
6b1dc7a6 sago007 2010-11-08 21:03 1517
            {
6b1dc7a6 sago007 2010-11-08 21:03 1518
                strHolder = "Last puzzle";
925b7e58 sago007 2011-04-25 16:35 1519
                nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1520
            }
6b1dc7a6 sago007 2010-11-08 21:03 1521
        }
6b1dc7a6 sago007 2010-11-08 21:03 1522
        if(stageClear && stageButtonStatus == SBstageClear)
6b1dc7a6 sago007 2010-11-08 21:03 1523
        {
6b1dc7a6 sago007 2010-11-08 21:03 1524
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1525
            if(Level<50-1)
6b1dc7a6 sago007 2010-11-08 21:03 1526
            {
6b1dc7a6 sago007 2010-11-08 21:03 1527
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1528
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1529
                else
6b1dc7a6 sago007 2010-11-08 21:03 1530
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1531
            }
6b1dc7a6 sago007 2010-11-08 21:03 1532
            else
6b1dc7a6 sago007 2010-11-08 21:03 1533
            {
6b1dc7a6 sago007 2010-11-08 21:03 1534
                strHolder = "Last stage";
925b7e58 sago007 2011-04-25 16:35 1535
                nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1536
            }
6b1dc7a6 sago007 2010-11-08 21:03 1537
        }
6b1dc7a6 sago007 2010-11-08 21:03 1538
6b1dc7a6 sago007 2010-11-08 21:03 1539
#if DEBUG
6b1dc7a6 sago007 2010-11-08 21:03 1540
        if (AI_Enabled&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1541
            strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear);
925b7e58 sago007 2011-04-25 16:35 1542
            //NFont_Write(sBoard,   5, 5, strHolder.c_str());
925b7e58 sago007 2011-04-25 16:35 1543
            nf_standard_blue_font.draw(5,5,strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1544
        }
6b1dc7a6 sago007 2010-11-08 21:03 1545
#endif
6b1dc7a6 sago007 2010-11-08 21:03 1546
        if (!bGameOver)DrawIMG(cursor[(ticks/600)%2],sBoard,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
6b1dc7a6 sago007 2010-11-08 21:03 1547
        if (ticks<gameStartedAt)
6b1dc7a6 sago007 2010-11-08 21:03 1548
        {
6b1dc7a6 sago007 2010-11-08 21:03 1549
            int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1550
            if( (currentCounter!=lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1551
                Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1552
            lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1553
            switch (currentCounter) {
6b1dc7a6 sago007 2010-11-08 21:03 1554
            case 2:
6b1dc7a6 sago007 2010-11-08 21:03 1555
                DrawIMG(counter[2], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1556
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1557
            case 1:
6b1dc7a6 sago007 2010-11-08 21:03 1558
                DrawIMG(counter[1], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1559
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1560
            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1561
                DrawIMG(counter[0], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1562
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1563
            default:
6b1dc7a6 sago007 2010-11-08 21:03 1564
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1565
            }
6b1dc7a6 sago007 2010-11-08 21:03 1566
        }
6b1dc7a6 sago007 2010-11-08 21:03 1567
        else
6b1dc7a6 sago007 2010-11-08 21:03 1568
        {
6b1dc7a6 sago007 2010-11-08 21:03 1569
            if(SoundEnabled&&(!NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver))
6b1dc7a6 sago007 2010-11-08 21:03 1570
            {
6b1dc7a6 sago007 2010-11-08 21:03 1571
                int currentCounter = (ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1572
                if(currentCounter!=lastCounter)
6b1dc7a6 sago007 2010-11-08 21:03 1573
                {
6b1dc7a6 sago007 2010-11-08 21:03 1574
                    if(currentCounter>115 && currentCounter<120)
6b1dc7a6 sago007 2010-11-08 21:03 1575
                        Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1576
                }
6b1dc7a6 sago007 2010-11-08 21:03 1577
                lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1578
            }
6b1dc7a6 sago007 2010-11-08 21:03 1579
            else
6b1dc7a6 sago007 2010-11-08 21:03 1580
            {
6b1dc7a6 sago007 2010-11-08 21:03 1581
                if( (0==lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1582
                {
6b1dc7a6 sago007 2010-11-08 21:03 1583
                    Mix_PlayChannel(1,counterFinalChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1584
                }
6b1dc7a6 sago007 2010-11-08 21:03 1585
                lastCounter = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1586
            }
6b1dc7a6 sago007 2010-11-08 21:03 1587
        }
6b1dc7a6 sago007 2010-11-08 21:03 1588
6b1dc7a6 sago007 2010-11-08 21:03 1589
        if ((bGameOver)&&(!editorMode))
6b1dc7a6 sago007 2010-11-08 21:03 1590
            if (hasWonTheGame)DrawIMG(iWinner, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1591
            else if (bDraw) DrawIMG(iDraw, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1592
            else
6b1dc7a6 sago007 2010-11-08 21:03 1593
                DrawIMG(iGameOver, sBoard, 0, 5*bsize);
925b7e58 sago007 2011-04-25 16:35 1594
            nf_standard_blue_font.setDest(screen);
6b1dc7a6 sago007 2010-11-08 21:03 1595
    }
6b1dc7a6 sago007 2010-11-08 21:03 1596
6b1dc7a6 sago007 2010-11-08 21:03 1597
6b1dc7a6 sago007 2010-11-08 21:03 1598
    void Update(int newtick) {
6b1dc7a6 sago007 2010-11-08 21:03 1599
        BlockGame::Update(newtick);
6b1dc7a6 sago007 2010-11-08 21:03 1600
        DoPaintJob();
6b1dc7a6 sago007 2010-11-08 21:03 1601
    }
6b1dc7a6 sago007 2010-11-08 21:03 1602
};
6b1dc7a6 sago007 2010-11-08 21:03 1603
6b1dc7a6 sago007 2010-11-08 21:03 1604
6b1dc7a6 sago007 2010-11-08 21:03 1605
6b1dc7a6 sago007 2010-11-08 21:03 1606
89c4a3a6 sago007 2008-08-29 14:32 1607
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
89c4a3a6 sago007 2008-08-29 14:32 1608
void writeScreenShot()
89c4a3a6 sago007 2008-08-29 14:32 1609
{
89c4a3a6 sago007 2008-08-29 14:32 1610
    cout << "Saving screenshot" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1611
    int rightNow = (int)time(NULL);
215ca7b3 sago007 2009-03-06 16:37 1612
/*#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 1613
    char buf[514];
89c4a3a6 sago007 2008-08-29 14:32 1614
    sprintf( buf, "%s/.gamesaves/blockattack/screenshots/screenshot%i.bmp", getenv("HOME"), rightNow );
91886cae sago007 2008-09-12 16:28 1615
#elif defined(__win32__)
89c4a3a6 sago007 2008-08-29 14:32 1616
    char buf[MAX_PATH];
89c4a3a6 sago007 2008-08-29 14:32 1617
    sprintf( buf, "%s\\My Games\\blockattack\\screenshots\\screenshot%i.bmp", (getMyDocumentsPath()).c_str(), rightNow );
91886cae sago007 2008-09-12 16:28 1618
#else
91886cae sago007 2008-09-12 16:28 1619
    char buf[MAX_PATH];
91886cae sago007 2008-09-12 16:28 1620
    sprintf( buf, "screenshot%i.bmp", rightNow );
215ca7b3 sago007 2009-03-06 16:37 1621
#endif*/
215ca7b3 sago007 2009-03-06 16:37 1622
#if defined(__unix__)
215ca7b3 sago007 2009-03-06 16:37 1623
    string buf = (string)getenv("HOME")+"/.gamesaves/blockattack/screenshots/screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1624
#elif defined(__win32__)
215ca7b3 sago007 2009-03-06 16:37 1625
    string buf = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots\\screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1626
#else
215ca7b3 sago007 2009-03-06 16:37 1627
    string buf = "screenshot"+itoa(rightNow)+".bmp";
89c4a3a6 sago007 2008-08-29 14:32 1628
#endif
215ca7b3 sago007 2009-03-06 16:37 1629
    SDL_SaveBMP( screen, buf.c_str() );
89c4a3a6 sago007 2008-08-29 14:32 1630
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 1631
        if (SoundEnabled)Mix_PlayChannel(1,photoClick,0);
89c4a3a6 sago007 2008-08-29 14:32 1632
}
89c4a3a6 sago007 2008-08-29 14:32 1633
89c4a3a6 sago007 2008-08-29 14:32 1634
//Function to return the name of a key, to be displayed...
593aeae4 sago007 2011-06-25 22:42 1635
static string getKeyName(SDLKey key)
89c4a3a6 sago007 2008-08-29 14:32 1636
{
4b0c248f sago007 2010-11-10 21:13 1637
    string keyname(SDL_GetKeyName(key));
215ca7b3 sago007 2009-03-06 16:37 1638
    return keyname;
89c4a3a6 sago007 2008-08-29 14:32 1639
}
89c4a3a6 sago007 2008-08-29 14:32 1640
89c4a3a6 sago007 2008-08-29 14:32 1641
void MakeBackground(int xsize,int ysize,BlockGame &theGame, BlockGame &theGame2);
89c4a3a6 sago007 2008-08-29 14:32 1642
89c4a3a6 sago007 2008-08-29 14:32 1643
int OpenControlsBox(int x, int y, int player)
89c4a3a6 sago007 2008-08-29 14:32 1644
{
89c4a3a6 sago007 2008-08-29 14:32 1645
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 1646
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 1647
    bool done =false;
215ca7b3 sago007 2009-03-06 16:37 1648
    string keyname;
27ae0175 sago007 2009-01-30 06:02 1649
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1650
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 1651
    {
89c4a3a6 sago007 2008-08-29 14:32 1652
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 1653
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1654
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 1655
        if (player == 0)
925b7e58 sago007 2011-04-25 16:35 1656
            NFont_Write(screen, x+40,y+2,"Player 1 keys");
89c4a3a6 sago007 2008-08-29 14:32 1657
        else
925b7e58 sago007 2011-04-25 16:35 1658
            NFont_Write(screen, x+40,y+2,"Player 2 keys");
925b7e58 sago007 2011-04-25 16:35 1659
        NFont_Write(screen, x+6,y+50,"Up");
89c4a3a6 sago007 2008-08-29 14:32 1660
        keyname = getKeyName(keySettings[player].up);
925b7e58 sago007 2011-04-25 16:35 1661
        NFont_Write(screen, x+200,y+50,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1662
        NFont_Write(screen, x+6,y+100,"Down");
89c4a3a6 sago007 2008-08-29 14:32 1663
        keyname = getKeyName(keySettings[player].down);
925b7e58 sago007 2011-04-25 16:35 1664
        NFont_Write(screen, x+200,y+100,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1665
        NFont_Write(screen, x+6,y+150,"Left");
89c4a3a6 sago007 2008-08-29 14:32 1666
        keyname = getKeyName(keySettings[player].left);
925b7e58 sago007 2011-04-25 16:35 1667
        NFont_Write(screen, x+200,y+150,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1668
        NFont_Write(screen, x+6,y+200,"Right");
89c4a3a6 sago007 2008-08-29 14:32 1669
        keyname = getKeyName(keySettings[player].right);
925b7e58 sago007 2011-04-25 16:35 1670
        NFont_Write(screen, x+200,y+200,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1671
        NFont_Write(screen, x+6,y+250,"Push");
89c4a3a6 sago007 2008-08-29 14:32 1672
        keyname = getKeyName(keySettings[player].push);
925b7e58 sago007 2011-04-25 16:35 1673
        NFont_Write(screen, x+200,y+250,keyname.c_str());
925b7e58 sago007 2011-04-25 16:35 1674
        NFont_Write(screen, x+6,y+300,"Change");
89c4a3a6 sago007 2008-08-29 14:32 1675
        keyname = getKeyName(keySettings[player].change);
925b7e58 sago007 2011-04-25 16:35 1676
        NFont_Write(screen, x+200,y+300,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1677
        //Ask for mouse play
925b7e58 sago007 2011-04-25 16:35 1678
        NFont_Write(screen, x+6,y+350,"Mouse play?");
89c4a3a6 sago007 2008-08-29 14:32 1679
        DrawIMG(iLevelCheckBox,screen,x+220,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1680
        if (((player==0)&&(mouseplay1))||((player==2)&&(mouseplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1681
            DrawIMG(iLevelCheck,screen,x+220,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1682
        //Ask for joypad play
925b7e58 sago007 2011-04-25 16:35 1683
        NFont_Write(screen, x+300,y+350,"Joypad?");
89c4a3a6 sago007 2008-08-29 14:32 1684
        DrawIMG(iLevelCheckBox,screen,x+460,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1685
        if (((player==0)&&(joyplay1))||((player==2)&&(joyplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1686
            DrawIMG(iLevelCheck,screen,x+460,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1687
        for (int i=1; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 1688
            DrawIMG(bChange,screen,x+420,y+50*i);
89c4a3a6 sago007 2008-08-29 14:32 1689
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1690
89c4a3a6 sago007 2008-08-29 14:32 1691
        while (SDL_PollEvent(&event))
89c4a3a6 sago007 2008-08-29 14:32 1692
        {
89c4a3a6 sago007 2008-08-29 14:32 1693
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 1694
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1695
            }
89c4a3a6 sago007 2008-08-29 14:32 1696
89c4a3a6 sago007 2008-08-29 14:32 1697
            if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1698
            {
89c4a3a6 sago007 2008-08-29 14:32 1699
                if (event.key.keysym.sym == SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1700
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1701
            }
89c4a3a6 sago007 2008-08-29 14:32 1702
        }	//PollEvent
89c4a3a6 sago007 2008-08-29 14:32 1703
89c4a3a6 sago007 2008-08-29 14:32 1704
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1705
89c4a3a6 sago007 2008-08-29 14:32 1706
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 1707
89c4a3a6 sago007 2008-08-29 14:32 1708
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 1709
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 1710
        {
89c4a3a6 sago007 2008-08-29 14:32 1711
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 1712
        }
89c4a3a6 sago007 2008-08-29 14:32 1713
89c4a3a6 sago007 2008-08-29 14:32 1714
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 1715
        {
89c4a3a6 sago007 2008-08-29 14:32 1716
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 1717
89c4a3a6 sago007 2008-08-29 14:32 1718
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(50+y)) && (mousey<(90+y)))
89c4a3a6 sago007 2008-08-29 14:32 1719
            {
89c4a3a6 sago007 2008-08-29 14:32 1720
                //up
89c4a3a6 sago007 2008-08-29 14:32 1721
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1722
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1723
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1724
                    {
89c4a3a6 sago007 2008-08-29 14:32 1725
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1726
                        {
89c4a3a6 sago007 2008-08-29 14:32 1727
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1728
                                keySettings[player].up = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1729
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1730
                        }
89c4a3a6 sago007 2008-08-29 14:32 1731
                    }
89c4a3a6 sago007 2008-08-29 14:32 1732
            } //up
89c4a3a6 sago007 2008-08-29 14:32 1733
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(100+y)) && (mousey<(140+y)))
89c4a3a6 sago007 2008-08-29 14:32 1734
            {
89c4a3a6 sago007 2008-08-29 14:32 1735
                //down
89c4a3a6 sago007 2008-08-29 14:32 1736
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1737
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1738
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1739
                    {
89c4a3a6 sago007 2008-08-29 14:32 1740
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1741
                        {
89c4a3a6 sago007 2008-08-29 14:32 1742
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1743
                                keySettings[player].down = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1744
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1745
                        }
89c4a3a6 sago007 2008-08-29 14:32 1746
                    }
89c4a3a6 sago007 2008-08-29 14:32 1747
            } //down
89c4a3a6 sago007 2008-08-29 14:32 1748
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(150+y)) && (mousey<(190+y)))
89c4a3a6 sago007 2008-08-29 14:32 1749
            {
89c4a3a6 sago007 2008-08-29 14:32 1750
                //left
89c4a3a6 sago007 2008-08-29 14:32 1751
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1752
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1753
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1754
                    {
89c4a3a6 sago007 2008-08-29 14:32 1755
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1756
                        {
89c4a3a6 sago007 2008-08-29 14:32 1757
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1758
                                keySettings[player].left = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1759
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1760
                        }
89c4a3a6 sago007 2008-08-29 14:32 1761
                    }
89c4a3a6 sago007 2008-08-29 14:32 1762
            } //left
89c4a3a6 sago007 2008-08-29 14:32 1763
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(200+y)) && (mousey<(240+y)))
89c4a3a6 sago007 2008-08-29 14:32 1764
            {
89c4a3a6 sago007 2008-08-29 14:32 1765
                //right
89c4a3a6 sago007 2008-08-29 14:32 1766
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1767
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1768
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1769
                    {
89c4a3a6 sago007 2008-08-29 14:32 1770
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1771
                        {
89c4a3a6 sago007 2008-08-29 14:32 1772
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1773
                                keySettings[player].right = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1774
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1775
                        }
89c4a3a6 sago007 2008-08-29 14:32 1776
                    }
89c4a3a6 sago007 2008-08-29 14:32 1777
            } //right
89c4a3a6 sago007 2008-08-29 14:32 1778
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(250+y)) && (mousey<(290+y)))
89c4a3a6 sago007 2008-08-29 14:32 1779
            {
89c4a3a6 sago007 2008-08-29 14:32 1780
                //push
89c4a3a6 sago007 2008-08-29 14:32 1781
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1782
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1783
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1784
                    {
89c4a3a6 sago007 2008-08-29 14:32 1785
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1786
                        {
89c4a3a6 sago007 2008-08-29 14:32 1787
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1788
                                keySettings[player].push = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1789
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1790
                        }
89c4a3a6 sago007 2008-08-29 14:32 1791
                    }
89c4a3a6 sago007 2008-08-29 14:32 1792
            } //push
89c4a3a6 sago007 2008-08-29 14:32 1793
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(300+y)) && (mousey<(340+y)))
89c4a3a6 sago007 2008-08-29 14:32 1794
            {
89c4a3a6 sago007 2008-08-29 14:32 1795
                //change
89c4a3a6 sago007 2008-08-29 14:32 1796
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1797
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1798
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1799
                    {
89c4a3a6 sago007 2008-08-29 14:32 1800
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1801
                        {
89c4a3a6 sago007 2008-08-29 14:32 1802
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1803
                                keySettings[player].change = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1804
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1805
                        }
89c4a3a6 sago007 2008-08-29 14:32 1806
                    }
89c4a3a6 sago007 2008-08-29 14:32 1807
            } //change
89c4a3a6 sago007 2008-08-29 14:32 1808
            //mouseplay:
89c4a3a6 sago007 2008-08-29 14:32 1809
            if ((mousex>(220+x)) && (mousex<(262+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1810
            {
89c4a3a6 sago007 2008-08-29 14:32 1811
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1812
                {
89c4a3a6 sago007 2008-08-29 14:32 1813
                    mouseplay1 = !mouseplay1;
89c4a3a6 sago007 2008-08-29 14:32 1814
                }
89c4a3a6 sago007 2008-08-29 14:32 1815
                else
89c4a3a6 sago007 2008-08-29 14:32 1816
                {
89c4a3a6 sago007 2008-08-29 14:32 1817
                    mouseplay2 = !mouseplay2;
89c4a3a6 sago007 2008-08-29 14:32 1818
                }
89c4a3a6 sago007 2008-08-29 14:32 1819
            }
89c4a3a6 sago007 2008-08-29 14:32 1820
            //Joyplay:
89c4a3a6 sago007 2008-08-29 14:32 1821
            if ((mousex>(460+x)) && (mousex<(502+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1822
            {
89c4a3a6 sago007 2008-08-29 14:32 1823
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1824
                {
89c4a3a6 sago007 2008-08-29 14:32 1825
                    joyplay1 = !joyplay1;
89c4a3a6 sago007 2008-08-29 14:32 1826
                }
89c4a3a6 sago007 2008-08-29 14:32 1827
                else
89c4a3a6 sago007 2008-08-29 14:32 1828
                {
89c4a3a6 sago007 2008-08-29 14:32 1829
                    joyplay2 = !joyplay2;
89c4a3a6 sago007 2008-08-29 14:32 1830
                }
89c4a3a6 sago007 2008-08-29 14:32 1831
            }
89c4a3a6 sago007 2008-08-29 14:32 1832
        }	//get mouse state
89c4a3a6 sago007 2008-08-29 14:32 1833
8d488d32 sago007 2011-04-17 13:02 1834
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 1835
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 1836
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 1837
    }	//while !done
89c4a3a6 sago007 2008-08-29 14:32 1838
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1839
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 1840
}
89c4a3a6 sago007 2008-08-29 14:32 1841
89c4a3a6 sago007 2008-08-29 14:32 1842
89c4a3a6 sago007 2008-08-29 14:32 1843
//Dialogbox
89c4a3a6 sago007 2008-08-29 14:32 1844
bool OpenDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 1845
{
89c4a3a6 sago007 2008-08-29 14:32 1846
    bool done = false;     //We are done!
89c4a3a6 sago007 2008-08-29 14:32 1847
    bool accept = false;   //New name is accepted! (not Cancelled)
89c4a3a6 sago007 2008-08-29 14:32 1848
    bool repeating = false; //The key is being held (BACKSPACE)
89c4a3a6 sago007 2008-08-29 14:32 1849
    const int repeatDelay = 200;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 1850
    unsigned long time = 0;
89c4a3a6 sago007 2008-08-29 14:32 1851
    ReadKeyboard rk = ReadKeyboard(name);
89c4a3a6 sago007 2008-08-29 14:32 1852
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 1853
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 1854
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1855
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 1856
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 1857
    {
89c4a3a6 sago007 2008-08-29 14:32 1858
        DrawIMG(dialogBox,screen,x,y);
71181267 sago007 2011-04-29 19:22 1859
        NFont_Write(screen, x+40,y+76,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1860
        strHolder = rk.GetString();
89c4a3a6 sago007 2008-08-29 14:32 1861
        strHolder.erase((int)rk.CharsBeforeCursor());
89c4a3a6 sago007 2008-08-29 14:32 1862
89c4a3a6 sago007 2008-08-29 14:32 1863
        if (((SDL_GetTicks()/600)%2)==1)
71181267 sago007 2011-04-29 19:22 1864
            NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( strHolder.c_str()),y+76,"|");
89c4a3a6 sago007 2008-08-29 14:32 1865
89c4a3a6 sago007 2008-08-29 14:32 1866
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1867
89c4a3a6 sago007 2008-08-29 14:32 1868
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1869
        {
89c4a3a6 sago007 2008-08-29 14:32 1870
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 1871
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1872
                accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1873
            }
89c4a3a6 sago007 2008-08-29 14:32 1874
89c4a3a6 sago007 2008-08-29 14:32 1875
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 1876
            {
89c4a3a6 sago007 2008-08-29 14:32 1877
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
89c4a3a6 sago007 2008-08-29 14:32 1878
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1879
                    accept = true;
89c4a3a6 sago007 2008-08-29 14:32 1880
                }
89c4a3a6 sago007 2008-08-29 14:32 1881
                else
89c4a3a6 sago007 2008-08-29 14:32 1882
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 1883
                        done = true;
89c4a3a6 sago007 2008-08-29 14:32 1884
                        accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1885
                    }
89c4a3a6 sago007 2008-08-29 14:32 1886
                    else if (!(event.key.keysym.sym == SDLK_BACKSPACE)){
89c4a3a6 sago007 2008-08-29 14:32 1887
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1888
                    }
89c4a3a6 sago007 2008-08-29 14:32 1889
                    else if ((event.key.keysym.sym == SDLK_BACKSPACE)&&(!repeating)){
89c4a3a6 sago007 2008-08-29 14:32 1890
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1891
                        repeating = true;
89c4a3a6 sago007 2008-08-29 14:32 1892
                        time=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1893
                    }
89c4a3a6 sago007 2008-08-29 14:32 1894
            }
89c4a3a6 sago007 2008-08-29 14:32 1895
89c4a3a6 sago007 2008-08-29 14:32 1896
        }	//while(event)
89c4a3a6 sago007 2008-08-29 14:32 1897
89c4a3a6 sago007 2008-08-29 14:32 1898
        if (SDL_GetTicks()>(time+repeatDelay))
89c4a3a6 sago007 2008-08-29 14:32 1899
        {
89c4a3a6 sago007 2008-08-29 14:32 1900
            time = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1901
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1902
            if ( (keys[SDLK_BACKSPACE])&&(repeating) )
89c4a3a6 sago007 2008-08-29 14:32 1903
            {
89c4a3a6 sago007 2008-08-29 14:32 1904
                if ((rk.ReadKey(SDLK_BACKSPACE))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1905
            }
89c4a3a6 sago007 2008-08-29 14:32 1906
            else
89c4a3a6 sago007 2008-08-29 14:32 1907
                repeating = false;
89c4a3a6 sago007 2008-08-29 14:32 1908
        }
89c4a3a6 sago007 2008-08-29 14:32 1909
89c4a3a6 sago007 2008-08-29 14:32 1910
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 1911
    }	//while(!done)
89c4a3a6 sago007 2008-08-29 14:32 1912
    strcpy(name,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1913
    bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 1914
    showDialog = false;
89c4a3a6 sago007 2008-08-29 14:32 1915
    return accept;
89c4a3a6 sago007 2008-08-29 14:32 1916
}
89c4a3a6 sago007 2008-08-29 14:32 1917
47529580 sago007 2008-12-09 02:34 1918
//Draws the highscores
47529580 sago007 2008-12-09 02:34 1919
void DrawHighscores(int x, int y, bool endless)
47529580 sago007 2008-12-09 02:34 1920
{
27ae0175 sago007 2009-01-30 06:02 1921
    MakeBackground(xsize,ysize);
47529580 sago007 2008-12-09 02:34 1922
    DrawIMG(background,screen,0,0);
925b7e58 sago007 2011-04-25 16:35 1923
    if (endless) nf_standard_blue_font.draw(x+100,y+100,"Endless:");
925b7e58 sago007 2011-04-25 16:35 1924
    else nf_standard_blue_font.draw(x+100,y+100,"Time Trial:"); 
47529580 sago007 2008-12-09 02:34 1925
    for (int i =0;i<10;i++)
47529580 sago007 2008-12-09 02:34 1926
    {
47529580 sago007 2008-12-09 02:34 1927
        char playerScore[32];
47529580 sago007 2008-12-09 02:34 1928
        char playerName[32];
47529580 sago007 2008-12-09 02:34 1929
        if (endless)
47529580 sago007 2008-12-09 02:34 1930
        {
47529580 sago007 2008-12-09 02:34 1931
            sprintf(playerScore, "%i", theTopScoresEndless.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1932
        }
47529580 sago007 2008-12-09 02:34 1933
        else
47529580 sago007 2008-12-09 02:34 1934
        {
47529580 sago007 2008-12-09 02:34 1935
            sprintf(playerScore, "%i", theTopScoresTimeTrial.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1936
        }
47529580 sago007 2008-12-09 02:34 1937
        if (endless)
47529580 sago007 2008-12-09 02:34 1938
        {
47529580 sago007 2008-12-09 02:34 1939
            strcpy(playerName,theTopScoresEndless.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1940
        }
47529580 sago007 2008-12-09 02:34 1941
        else
47529580 sago007 2008-12-09 02:34 1942
        {
47529580 sago007 2008-12-09 02:34 1943
            strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1944
        }
925b7e58 sago007 2011-04-25 16:35 1945
        nf_standard_blue_font.draw(x+420,y+150+i*35,playerScore);
925b7e58 sago007 2011-04-25 16:35 1946
        nf_standard_blue_font.draw(x+60,y+150+i*35,playerName);
47529580 sago007 2008-12-09 02:34 1947
    }
47529580 sago007 2008-12-09 02:34 1948
}
47529580 sago007 2008-12-09 02:34 1949
47529580 sago007 2008-12-09 02:34 1950
void DrawStats()
81d9c25d sago007 2008-11-24 09:50 1951
{
27ae0175 sago007 2009-01-30 06:02 1952
    MakeBackground(xsize,ysize);
81d9c25d sago007 2008-11-24 09:50 1953
    DrawIMG(background,screen,0,0);
81d9c25d sago007 2008-11-24 09:50 1954
    int y = 5;
81d9c25d sago007 2008-11-24 09:50 1955
    const int y_spacing = 30;
925b7e58 sago007 2011-04-25 16:35 1956
    NFont_Write(screen, 10,y,"Stats");
81d9c25d sago007 2008-11-24 09:50 1957
    y+=y_spacing*2;
925b7e58 sago007 2011-04-25 16:35 1958
    NFont_Write(screen, 10,y,"Chains");
81d9c25d sago007 2008-11-24 09:50 1959
    for(int i=2;i<13;i++)
81d9c25d sago007 2008-11-24 09:50 1960
    {
81d9c25d sago007 2008-11-24 09:50 1961
        y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1962
        NFont_Write(screen, 10,y,(itoa(i)+"X").c_str());
81d9c25d sago007 2008-11-24 09:50 1963
        string numberAsString = itoa(Stats::getInstance()->getNumberOf("chainX"+itoa(i)));
925b7e58 sago007 2011-04-25 16:35 1964
        NFont_Write(screen, 300,y,numberAsString.c_str());
81d9c25d sago007 2008-11-24 09:50 1965
    }
81d9c25d sago007 2008-11-24 09:50 1966
    y+=y_spacing*2;
925b7e58 sago007 2011-04-25 16:35 1967
    NFont_Write(screen, 10,y,"Lines Pushed: ");
81d9c25d sago007 2008-11-24 09:50 1968
    string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed"));
925b7e58 sago007 2011-04-25 16:35 1969
    NFont_Write(screen, 300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 1970
81d9c25d sago007 2008-11-24 09:50 1971
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1972
    NFont_Write(screen, 10,y,"Puzzles solved: ");
81d9c25d sago007 2008-11-24 09:50 1973
    numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved"));
925b7e58 sago007 2011-04-25 16:35 1974
    NFont_Write(screen, 300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 1975
d07b805e sago007 2009-01-27 13:15 1976
    y+=y_spacing*2;
925b7e58 sago007 2011-04-25 16:35 1977
    NFont_Write(screen, 10,y,"Run time: ");
cd12e0fe sago007 2009-01-29 08:47 1978
    commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
d07b805e sago007 2009-01-27 13:15 1979
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1980
    NFont_Write(screen, 10,y,((string)("Days: "+itoa(ct.days))).c_str());
d07b805e sago007 2009-01-27 13:15 1981
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1982
    NFont_Write(screen, 10,y,((string)("Hours: "+itoa(ct.hours))).c_str());
d07b805e sago007 2009-01-27 13:15 1983
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1984
    NFont_Write(screen, 10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
d07b805e sago007 2009-01-27 13:15 1985
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1986
    NFont_Write(screen, 10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
d07b805e sago007 2009-01-27 13:15 1987
cd12e0fe sago007 2009-01-29 08:47 1988
    y-=y_spacing*4; //Four rows back
27ae0175 sago007 2009-01-30 06:02 1989
    const int x_offset3 = xsize/3+10; //Ofset for three rows
925b7e58 sago007 2011-04-25 16:35 1990
    NFont_Write(screen, x_offset3,y,"Play time: ");
cd12e0fe sago007 2009-01-29 08:47 1991
    ct = TimeHandler::getTime("playTime");
cd12e0fe sago007 2009-01-29 08:47 1992
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1993
    NFont_Write(screen, x_offset3,y,((string)("Days: "+itoa(ct.days))).c_str());
cd12e0fe sago007 2009-01-29 08:47 1994
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1995
    NFont_Write(screen, x_offset3,y,((string)("Hours: "+itoa(ct.hours))).c_str());
cd12e0fe sago007 2009-01-29 08:47 1996
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1997
    NFont_Write(screen, x_offset3,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
cd12e0fe sago007 2009-01-29 08:47 1998
    y+=y_spacing;
925b7e58 sago007 2011-04-25 16:35 1999
    NFont_Write(screen, x_offset3,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
cd12e0fe sago007 2009-01-29 08:47 2000
27ae0175 sago007 2009-01-30 06:02 2001
    const int x_offset = xsize/2+10;
81d9c25d sago007 2008-11-24 09:50 2002
    y = 5+y_spacing*2;
925b7e58 sago007 2011-04-25 16:35 2003
    NFont_Write(screen, x_offset,y,"VS CPU (win/loss)");
81d9c25d sago007 2008-11-24 09:50 2004
    for(int i=0;i<7;i++)
81d9c25d sago007 2008-11-24 09:50 2005
    {
81d9c25d sago007 2008-11-24 09:50 2006
        y += y_spacing;
925b7e58 sago007 2011-04-25 16:35 2007
        NFont_Write(screen, x_offset,y,("AI "+itoa(i+1)).c_str());
81d9c25d sago007 2008-11-24 09:50 2008
        numberAsString = itoa(Stats::getInstance()->getNumberOf("defeatedAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2009
        string numberAsString2 = itoa(Stats::getInstance()->getNumberOf("defeatedByAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 2010
        string toPrint = numberAsString + "/" + numberAsString2;
925b7e58 sago007 2011-04-25 16:35 2011
        NFont_Write(screen, x_offset+230,y,toPrint.c_str());
81d9c25d sago007 2008-11-24 09:50 2012
    }
47529580 sago007 2008-12-09 02:34 2013
}
47529580 sago007 2008-12-09 02:34 2014
47529580 sago007 2008-12-09 02:34 2015
void OpenScoresDisplay()
47529580 sago007 2008-12-09 02:34 2016
{
9050a50a sago007 2008-12-09 13:35 2017
    int mousex,mousey;
47529580 sago007 2008-12-09 02:34 2018
    bool done = false;     //We are done!
47529580 sago007 2008-12-09 02:34 2019
    int page = 0;
47529580 sago007 2008-12-09 02:34 2020
    const int numberOfPages = 3;
7ca669ac sago007 2008-12-09 16:30 2021
    //button coodinates:
7ca669ac sago007 2008-12-09 16:30 2022
    const int scoreX = buttonXsize*2;
7ca669ac sago007 2008-12-09 16:30 2023
    const int scoreY = 0;
7ca669ac sago007 2008-12-09 16:30 2024
    const int backX = 20;
7ca669ac sago007 2008-12-09 16:30 2025
    const int backY = ysize-buttonYsize-20;
7ca669ac sago007 2008-12-09 16:30 2026
    const int nextX = xsize-buttonXsize-20;
7ca669ac sago007 2008-12-09 16:30 2027
    const int nextY = backY;
81d9c25d sago007 2008-11-24 09:50 2028
    while (!done)
81d9c25d sago007 2008-11-24 09:50 2029
    {
47529580 sago007 2008-12-09 02:34 2030
        switch(page)
47529580 sago007 2008-12-09 02:34 2031
        {
47529580 sago007 2008-12-09 02:34 2032
            case 0:
47529580 sago007 2008-12-09 02:34 2033
                //Highscores, endless
47529580 sago007 2008-12-09 02:34 2034
                DrawHighscores(100,100,true);
47529580 sago007 2008-12-09 02:34 2035
                break;
47529580 sago007 2008-12-09 02:34 2036
            case 1:
47529580 sago007 2008-12-09 02:34 2037
                //Highscores, Time Trial
47529580 sago007 2008-12-09 02:34 2038
                DrawHighscores(100,100,false);
47529580 sago007 2008-12-09 02:34 2039
                break;
47529580 sago007 2008-12-09 02:34 2040
            case 2:
47529580 sago007 2008-12-09 02:34 2041
            default:
47529580 sago007 2008-12-09 02:34 2042
                DrawStats();
47529580 sago007 2008-12-09 02:34 2043
        };
47529580 sago007 2008-12-09 02:34 2044
7ca669ac sago007 2008-12-09 16:30 2045
        //Draw buttons:
7ca669ac sago007 2008-12-09 16:30 2046
        DrawIMG(bHighScore,screen,scoreX,scoreY);
7ca669ac sago007 2008-12-09 16:30 2047
        DrawIMG(bBack,screen,backX,backY);
7ca669ac sago007 2008-12-09 16:30 2048
        DrawIMG(bNext,screen,nextX,nextY);
7ca669ac sago007 2008-12-09 16:30 2049
7ca669ac sago007 2008-12-09 16:30 2050
        //Draw page number
7ca669ac sago007 2008-12-09 16:30 2051
        string pageXofY = ((string)"Page ")+itoa(page+1)+((string)" of ")+itoa(numberOfPages);
925b7e58 sago007 2011-04-25 16:35 2052
        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 2053
        
81d9c25d sago007 2008-11-24 09:50 2054
        SDL_Delay(10);
81d9c25d sago007 2008-11-24 09:50 2055
        SDL_Event event;
9050a50a sago007 2008-12-09 13:35 2056
9050a50a sago007 2008-12-09 13:35 2057
        SDL_GetMouseState(&mousex,&mousey);
81d9c25d sago007 2008-11-24 09:50 2058
        
81d9c25d sago007 2008-11-24 09:50 2059
        while ( SDL_PollEvent(&event) )
81d9c25d sago007 2008-11-24 09:50 2060
        {
9050a50a sago007 2008-12-09 13:35 2061
9050a50a sago007 2008-12-09 13:35 2062
81d9c25d sago007 2008-11-24 09:50 2063
            if ( event.type == SDL_QUIT )  {
81d9c25d sago007 2008-11-24 09:50 2064
                done = true;
81d9c25d sago007 2008-11-24 09:50 2065
            }
81d9c25d sago007 2008-11-24 09:50 2066
81d9c25d sago007 2008-11-24 09:50 2067
            if ( event.type == SDL_KEYDOWN )
81d9c25d sago007 2008-11-24 09:50 2068
            {
47529580 sago007 2008-12-09 02:34 2069
                if( (event.key.keysym.sym == SDLK_RIGHT))
47529580 sago007 2008-12-09 02:34 2070
                {
47529580 sago007 2008-12-09 02:34 2071
                    page++;
47529580 sago007 2008-12-09 02:34 2072
                    if(page>=numberOfPages)
47529580 sago007 2008-12-09 02:34 2073
                        page = 0;
47529580 sago007 2008-12-09 02:34 2074
                }
7ca669ac sago007 2008-12-09 16:30 2075
                else
47529580 sago007 2008-12-09 02:34 2076
                if( (event.key.keysym.sym == SDLK_LEFT))
47529580 sago007 2008-12-09 02:34 2077
                {
47529580 sago007 2008-12-09 02:34 2078
                    page--;
47529580 sago007 2008-12-09 02:34 2079
                    if(page<0)
47529580 sago007 2008-12-09 02:34 2080
                        page = numberOfPages-1;
47529580 sago007 2008-12-09 02:34 2081
                }
7ca669ac sago007 2008-12-09 16:30 2082
                else
7ca669ac sago007 2008-12-09 16:30 2083
                    done = true;
fcd5a134 sago007 2008-12-19 01:11 2084
                
fcd5a134 sago007 2008-12-19 01:11 2085
                if ( event.key.keysym.sym == SDLK_F9 ) {
fcd5a134 sago007 2008-12-19 01:11 2086
                    writeScreenShot();
fcd5a134 sago007 2008-12-19 01:11 2087
                }
47529580 sago007 2008-12-09 02:34 2088
81d9c25d sago007 2008-11-24 09:50 2089
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
81d9c25d sago007 2008-11-24 09:50 2090
                    done = true;
81d9c25d sago007 2008-11-24 09:50 2091
                }
81d9c25d sago007 2008-11-24 09:50 2092
                else
81d9c25d sago007 2008-11-24 09:50 2093
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
81d9c25d sago007 2008-11-24 09:50 2094
                        done = true;
81d9c25d sago007 2008-11-24 09:50 2095
                    }
81d9c25d sago007 2008-11-24 09:50 2096
            }
81d9c25d sago007 2008-11-24 09:50 2097
81d9c25d sago007 2008-11-24 09:50 2098
        }	//while(event)
7ca669ac sago007 2008-12-09 16:30 2099
7ca669ac sago007 2008-12-09 16:30 2100
        // If the mouse button is released, make bMouseUp equal true
7ca669ac sago007 2008-12-09 16:30 2101
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
7ca669ac sago007 2008-12-09 16:30 2102
        {
7ca669ac sago007 2008-12-09 16:30 2103
            bMouseUp=true;
7ca669ac sago007 2008-12-09 16:30 2104
        }
7ca669ac sago007 2008-12-09 16:30 2105
7ca669ac sago007 2008-12-09 16:30 2106
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
7ca669ac sago007 2008-12-09 16:30 2107
        {
7ca669ac sago007 2008-12-09 16:30 2108
            bMouseUp = false;
7ca669ac sago007 2008-12-09 16:30 2109
7ca669ac sago007 2008-12-09 16:30 2110
            //The Score button:
7ca669ac sago007 2008-12-09 16:30 2111
            if((mousex>scoreX) && (mousex<scoreX+buttonXsize) && (mousey>scoreY) && (mousey<scoreY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2112
                done =true;
7ca669ac sago007 2008-12-09 16:30 2113
7ca669ac sago007 2008-12-09 16:30 2114
            //The back button:
7ca669ac sago007 2008-12-09 16:30 2115
            if((mousex>backX) && (mousex<backX+buttonXsize) && (mousey>backY) && (mousey<backY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2116
            {
7ca669ac sago007 2008-12-09 16:30 2117
                page--;
7ca669ac sago007 2008-12-09 16:30 2118
                if(page<0)
7ca669ac sago007 2008-12-09 16:30 2119
                    page = numberOfPages-1;
7ca669ac sago007 2008-12-09 16:30 2120
            }
7ca669ac sago007 2008-12-09 16:30 2121
7ca669ac sago007 2008-12-09 16:30 2122
            //The next button:
7ca669ac sago007 2008-12-09 16:30 2123
            if((mousex>nextX) && (mousex<nextX+buttonXsize) && (mousey>nextY) && (mousey<nextY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2124
            {
7ca669ac sago007 2008-12-09 16:30 2125
                page++;
7ca669ac sago007 2008-12-09 16:30 2126
                if(page>=numberOfPages)
7ca669ac sago007 2008-12-09 16:30 2127
                    page = 0;
7ca669ac sago007 2008-12-09 16:30 2128
            }
7ca669ac sago007 2008-12-09 16:30 2129
        }
7ca669ac sago007 2008-12-09 16:30 2130
8d488d32 sago007 2011-04-17 13:02 2131
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2132
        mouse.PaintTo(screen,mousex,mousey);
9050a50a sago007 2008-12-09 13:35 2133
        SDL_Flip(screen); //Update screen
81d9c25d sago007 2008-11-24 09:50 2134
    }
6b1dc7a6 sago007 2010-11-08 21:03 2135
6b1dc7a6 sago007 2010-11-08 21:03 2136
81d9c25d sago007 2008-11-24 09:50 2137
}
81d9c25d sago007 2008-11-24 09:50 2138
89c4a3a6 sago007 2008-08-29 14:32 2139
89c4a3a6 sago007 2008-08-29 14:32 2140
//Open a puzzle file
89c4a3a6 sago007 2008-08-29 14:32 2141
bool OpenFileDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2142
{
89c4a3a6 sago007 2008-08-29 14:32 2143
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2144
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2145
    ListFiles lf = ListFiles();
aca2f4b0 sago007 2009-05-10 18:11 2146
    string folder = (string)SHAREDIR+(string)"/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2147
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2148
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2149
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2150
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2151
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2152
#endif
89c4a3a6 sago007 2008-08-29 14:32 2153
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2154
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2155
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2156
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2157
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2158
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2159
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2160
    {
89c4a3a6 sago007 2008-08-29 14:32 2161
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2162
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2163
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2164
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2165
        {
925b7e58 sago007 2011-04-25 16:35 2166
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2167
        }
89c4a3a6 sago007 2008-08-29 14:32 2168
89c4a3a6 sago007 2008-08-29 14:32 2169
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2170
89c4a3a6 sago007 2008-08-29 14:32 2171
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2172
        {
89c4a3a6 sago007 2008-08-29 14:32 2173
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2174
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2175
            }
89c4a3a6 sago007 2008-08-29 14:32 2176
89c4a3a6 sago007 2008-08-29 14:32 2177
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2178
            {
89c4a3a6 sago007 2008-08-29 14:32 2179
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2180
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2181
                }
89c4a3a6 sago007 2008-08-29 14:32 2182
89c4a3a6 sago007 2008-08-29 14:32 2183
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2184
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2185
                }
89c4a3a6 sago007 2008-08-29 14:32 2186
89c4a3a6 sago007 2008-08-29 14:32 2187
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2188
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2189
                }
89c4a3a6 sago007 2008-08-29 14:32 2190
            }
89c4a3a6 sago007 2008-08-29 14:32 2191
89c4a3a6 sago007 2008-08-29 14:32 2192
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2193
89c4a3a6 sago007 2008-08-29 14:32 2194
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2195
89c4a3a6 sago007 2008-08-29 14:32 2196
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2197
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2198
        {
89c4a3a6 sago007 2008-08-29 14:32 2199
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2200
        }
89c4a3a6 sago007 2008-08-29 14:32 2201
89c4a3a6 sago007 2008-08-29 14:32 2202
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2203
        {
89c4a3a6 sago007 2008-08-29 14:32 2204
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2205
89c4a3a6 sago007 2008-08-29 14:32 2206
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2207
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2208
            {
89c4a3a6 sago007 2008-08-29 14:32 2209
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2210
            }
89c4a3a6 sago007 2008-08-29 14:32 2211
89c4a3a6 sago007 2008-08-29 14:32 2212
            //The back button:
9050a50a sago007 2008-12-09 13:35 2213
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2214
            {
89c4a3a6 sago007 2008-08-29 14:32 2215
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2216
            }
89c4a3a6 sago007 2008-08-29 14:32 2217
89c4a3a6 sago007 2008-08-29 14:32 2218
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2219
            {
89c4a3a6 sago007 2008-08-29 14:32 2220
                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 2221
                {
89c4a3a6 sago007 2008-08-29 14:32 2222
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2223
                    {
89c4a3a6 sago007 2008-08-29 14:32 2224
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2225
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2226
                    }
89c4a3a6 sago007 2008-08-29 14:32 2227
                }
89c4a3a6 sago007 2008-08-29 14:32 2228
            }
89c4a3a6 sago007 2008-08-29 14:32 2229
        }
89c4a3a6 sago007 2008-08-29 14:32 2230
8d488d32 sago007 2011-04-17 13:02 2231
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2232
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2233
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2234
    }
89c4a3a6 sago007 2008-08-29 14:32 2235
}
89c4a3a6 sago007 2008-08-29 14:32 2236
89c4a3a6 sago007 2008-08-29 14:32 2237
//Slelect a theme
89c4a3a6 sago007 2008-08-29 14:32 2238
bool SelectThemeDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2239
{
89c4a3a6 sago007 2008-08-29 14:32 2240
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2241
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2242
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2243
    string folder = (string)SHAREDIR+(string)"/themes";
89c4a3a6 sago007 2008-08-29 14:32 2244
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2245
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2246
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2247
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/themes";
89c4a3a6 sago007 2008-08-29 14:32 2248
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2249
#endif
89c4a3a6 sago007 2008-08-29 14:32 2250
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2251
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2252
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2253
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2254
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2255
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2256
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2257
    {
89c4a3a6 sago007 2008-08-29 14:32 2258
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2259
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2260
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2261
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2262
        {
925b7e58 sago007 2011-04-25 16:35 2263
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2264
        }
89c4a3a6 sago007 2008-08-29 14:32 2265
89c4a3a6 sago007 2008-08-29 14:32 2266
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2267
89c4a3a6 sago007 2008-08-29 14:32 2268
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2269
        {
89c4a3a6 sago007 2008-08-29 14:32 2270
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2271
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2272
            }
89c4a3a6 sago007 2008-08-29 14:32 2273
89c4a3a6 sago007 2008-08-29 14:32 2274
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2275
            {
89c4a3a6 sago007 2008-08-29 14:32 2276
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2277
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2278
                }
89c4a3a6 sago007 2008-08-29 14:32 2279
89c4a3a6 sago007 2008-08-29 14:32 2280
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2281
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2282
                }
89c4a3a6 sago007 2008-08-29 14:32 2283
89c4a3a6 sago007 2008-08-29 14:32 2284
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2285
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2286
                }
89c4a3a6 sago007 2008-08-29 14:32 2287
            }
89c4a3a6 sago007 2008-08-29 14:32 2288
89c4a3a6 sago007 2008-08-29 14:32 2289
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2290
89c4a3a6 sago007 2008-08-29 14:32 2291
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2292
89c4a3a6 sago007 2008-08-29 14:32 2293
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2294
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2295
        {
89c4a3a6 sago007 2008-08-29 14:32 2296
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2297
        }
89c4a3a6 sago007 2008-08-29 14:32 2298
89c4a3a6 sago007 2008-08-29 14:32 2299
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2300
        {
89c4a3a6 sago007 2008-08-29 14:32 2301
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2302
89c4a3a6 sago007 2008-08-29 14:32 2303
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2304
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2305
            {
89c4a3a6 sago007 2008-08-29 14:32 2306
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2307
            }
89c4a3a6 sago007 2008-08-29 14:32 2308
89c4a3a6 sago007 2008-08-29 14:32 2309
            //The back button:
9050a50a sago007 2008-12-09 13:35 2310
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2311
            {
89c4a3a6 sago007 2008-08-29 14:32 2312
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2313
            }
89c4a3a6 sago007 2008-08-29 14:32 2314
89c4a3a6 sago007 2008-08-29 14:32 2315
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2316
            {
89c4a3a6 sago007 2008-08-29 14:32 2317
                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 2318
                {
89c4a3a6 sago007 2008-08-29 14:32 2319
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2320
                    {
89c4a3a6 sago007 2008-08-29 14:32 2321
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2322
                        loadTheme(lf.getFileName(i));
89c4a3a6 sago007 2008-08-29 14:32 2323
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2324
                    }
89c4a3a6 sago007 2008-08-29 14:32 2325
                }
89c4a3a6 sago007 2008-08-29 14:32 2326
            }
89c4a3a6 sago007 2008-08-29 14:32 2327
        }
89c4a3a6 sago007 2008-08-29 14:32 2328
8d488d32 sago007 2011-04-17 13:02 2329
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2330
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2331
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2332
    }
89c4a3a6 sago007 2008-08-29 14:32 2333
}
89c4a3a6 sago007 2008-08-29 14:32 2334
89c4a3a6 sago007 2008-08-29 14:32 2335
//Open a saved replay
89c4a3a6 sago007 2008-08-29 14:32 2336
bool OpenReplayDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2337
{
89c4a3a6 sago007 2008-08-29 14:32 2338
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2339
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2340
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2341
    cout << "Ready to set directory!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2342
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2343
    string directory = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2344
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 2345
    string directory = getMyDocumentsPath()+(string)"/My Games/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2346
#else
89c4a3a6 sago007 2008-08-29 14:32 2347
    string directory = "./replays";
89c4a3a6 sago007 2008-08-29 14:32 2348
#endif
89c4a3a6 sago007 2008-08-29 14:32 2349
    lf.setDirectory(directory);
89c4a3a6 sago007 2008-08-29 14:32 2350
    cout << "Directory sat" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2351
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2352
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2353
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2354
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2355
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2356
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2357
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2358
    {
89c4a3a6 sago007 2008-08-29 14:32 2359
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2360
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2361
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2362
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2363
        {
925b7e58 sago007 2011-04-25 16:35 2364
            NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2365
        }
89c4a3a6 sago007 2008-08-29 14:32 2366
89c4a3a6 sago007 2008-08-29 14:32 2367
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2368
89c4a3a6 sago007 2008-08-29 14:32 2369
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2370
        {
89c4a3a6 sago007 2008-08-29 14:32 2371
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2372
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2373
                return false;
89c4a3a6 sago007 2008-08-29 14:32 2374
            }
89c4a3a6 sago007 2008-08-29 14:32 2375
89c4a3a6 sago007 2008-08-29 14:32 2376
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2377
            {
89c4a3a6 sago007 2008-08-29 14:32 2378
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2379
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2380
                    return false;
89c4a3a6 sago007 2008-08-29 14:32 2381
                }
89c4a3a6 sago007 2008-08-29 14:32 2382
89c4a3a6 sago007 2008-08-29 14:32 2383
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2384
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2385
                }
89c4a3a6 sago007 2008-08-29 14:32 2386
89c4a3a6 sago007 2008-08-29 14:32 2387
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2388
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2389
                }
89c4a3a6 sago007 2008-08-29 14:32 2390
            }
89c4a3a6 sago007 2008-08-29 14:32 2391
89c4a3a6 sago007 2008-08-29 14:32 2392
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2393
89c4a3a6 sago007 2008-08-29 14:32 2394
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2395
89c4a3a6 sago007 2008-08-29 14:32 2396
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2397
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2398
        {
89c4a3a6 sago007 2008-08-29 14:32 2399
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2400
        }
89c4a3a6 sago007 2008-08-29 14:32 2401
89c4a3a6 sago007 2008-08-29 14:32 2402
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2403
        {
89c4a3a6 sago007 2008-08-29 14:32 2404
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2405
89c4a3a6 sago007 2008-08-29 14:32 2406
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2407
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2408
            {
89c4a3a6 sago007 2008-08-29 14:32 2409
                lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2410
            }
89c4a3a6 sago007 2008-08-29 14:32 2411
89c4a3a6 sago007 2008-08-29 14:32 2412
            //The back button:
9050a50a sago007 2008-12-09 13:35 2413
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2414
            {
89c4a3a6 sago007 2008-08-29 14:32 2415
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2416
            }
89c4a3a6 sago007 2008-08-29 14:32 2417
89c4a3a6 sago007 2008-08-29 14:32 2418
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2419
            {
89c4a3a6 sago007 2008-08-29 14:32 2420
                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 2421
                {
89c4a3a6 sago007 2008-08-29 14:32 2422
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2423
                    {
89c4a3a6 sago007 2008-08-29 14:32 2424
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2425
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2426
                        return true;
89c4a3a6 sago007 2008-08-29 14:32 2427
                    }
89c4a3a6 sago007 2008-08-29 14:32 2428
                }
89c4a3a6 sago007 2008-08-29 14:32 2429
            }
89c4a3a6 sago007 2008-08-29 14:32 2430
        }
89c4a3a6 sago007 2008-08-29 14:32 2431
8d488d32 sago007 2011-04-17 13:02 2432
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2433
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2434
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2435
    }
89c4a3a6 sago007 2008-08-29 14:32 2436
}
89c4a3a6 sago007 2008-08-29 14:32 2437
89c4a3a6 sago007 2008-08-29 14:32 2438
89c4a3a6 sago007 2008-08-29 14:32 2439
//draws options:
e1290bdf sago007 2010-10-25 19:56 2440
void DrawOptions(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 2441
{
9050a50a sago007 2008-12-09 13:35 2442
    if (MusicEnabled) DrawIMG(bOn,optionsBack,400,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2443
    else DrawIMG(bOff,optionsBack,400,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2444
    if (SoundEnabled) DrawIMG(bOn,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2445
    else DrawIMG(bOff,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2446
    if (bFullscreen) DrawIMG(bOn,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2447
    else DrawIMG(bOff,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2448
    DrawIMG(bChange,optionsBack,230,435);
89c4a3a6 sago007 2008-08-29 14:32 2449
    DrawIMG(bChange,optionsBack,410,435);
89c4a3a6 sago007 2008-08-29 14:32 2450
    DrawIMG(bChange,optionsBack,230,500);
89c4a3a6 sago007 2008-08-29 14:32 2451
    DrawIMG(bChange,optionsBack,410,500);
89c4a3a6 sago007 2008-08-29 14:32 2452
    DrawIMG(optionsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2453
}  //drawOptions
89c4a3a6 sago007 2008-08-29 14:32 2454
89c4a3a6 sago007 2008-08-29 14:32 2455
//Draws the balls and explosions
4b0c248f sago007 2010-11-10 21:13 2456
static void DrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2457
{
89c4a3a6 sago007 2008-08-29 14:32 2458
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2459
    {
89c4a3a6 sago007 2008-08-29 14:32 2460
        if (theBallManeger.ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2461
        {
89c4a3a6 sago007 2008-08-29 14:32 2462
            DrawIMG(balls[theBallManeger.ballArray[i].getColor()],screen,theBallManeger.ballArray[i].getX(),theBallManeger.ballArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2463
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2464
        if (theExplosionManeger.explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2465
        {
89c4a3a6 sago007 2008-08-29 14:32 2466
            DrawIMG(explosion[theExplosionManeger.explosionArray[i].getFrame()],screen,theExplosionManeger.explosionArray[i].getX(),theExplosionManeger.explosionArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2467
        }
89c4a3a6 sago007 2008-08-29 14:32 2468
        if (theTextManeger.textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2469
        {
89c4a3a6 sago007 2008-08-29 14:32 2470
            //cout << "Printing text: " << theTextManeger.textArray[i].getText() << endl;
925b7e58 sago007 2011-04-25 16:35 2471
            int x = theTextManeger.textArray[i].getX()-12;
925b7e58 sago007 2011-04-25 16:35 2472
            int y = theTextManeger.textArray[i].getY()-12;
89c4a3a6 sago007 2008-08-29 14:32 2473
            DrawIMG(iChainBack,screen,x,y);
925b7e58 sago007 2011-04-25 16:35 2474
            nf_standard_small_font.drawCenter(x+12,y+7,theTextManeger.textArray[i].getText());
89c4a3a6 sago007 2008-08-29 14:32 2475
        }
89c4a3a6 sago007 2008-08-29 14:32 2476
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2477
}    //DrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2478
89c4a3a6 sago007 2008-08-29 14:32 2479
//Removes the old balls
89c4a3a6 sago007 2008-08-29 14:32 2480
void UndrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2481
{
89c4a3a6 sago007 2008-08-29 14:32 2482
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2483
    {
89c4a3a6 sago007 2008-08-29 14:32 2484
        if (theBallManeger.oldBallUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2485
        {
89c4a3a6 sago007 2008-08-29 14:32 2486
            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 2487
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2488
        if (theExplosionManeger.oldExplosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2489
        {
89c4a3a6 sago007 2008-08-29 14:32 2490
            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 2491
        }
89c4a3a6 sago007 2008-08-29 14:32 2492
        if (theTextManeger.oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2493
        {
925b7e58 sago007 2011-04-25 16:35 2494
            int x = theTextManeger.oldTextArray[i].getX()-12;
925b7e58 sago007 2011-04-25 16:35 2495
            int y = theTextManeger.oldTextArray[i].getY()-12;
89c4a3a6 sago007 2008-08-29 14:32 2496
            DrawIMG(background,screen,x,y,25,25,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2497
        }
89c4a3a6 sago007 2008-08-29 14:32 2498
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2499
}   //UndrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2500
89c4a3a6 sago007 2008-08-29 14:32 2501
//draws everything
6b1dc7a6 sago007 2010-11-08 21:03 2502
void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2503
{
89c4a3a6 sago007 2008-08-29 14:32 2504
    SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 2505
    //draw background:
89c4a3a6 sago007 2008-08-29 14:32 2506
    if (forceredraw != 1)
89c4a3a6 sago007 2008-08-29 14:32 2507
    {
89c4a3a6 sago007 2008-08-29 14:32 2508
89c4a3a6 sago007 2008-08-29 14:32 2509
        UndrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2510
        DrawIMG(background,screen,oldMousex,oldMousey,32,32,oldMousex,oldMousey);
89c4a3a6 sago007 2008-08-29 14:32 2511
        DrawIMG(background,screen,oldBubleX,oldBubleY,140,50,oldBubleX,oldBubleY);
89c4a3a6 sago007 2008-08-29 14:32 2512
89c4a3a6 sago007 2008-08-29 14:32 2513
89c4a3a6 sago007 2008-08-29 14:32 2514
        DrawIMG(background,screen,350,200,120,200,350,200);
89c4a3a6 sago007 2008-08-29 14:32 2515
        DrawIMG(background,screen,830,200,120,200,830,200);
89c4a3a6 sago007 2008-08-29 14:32 2516
        DrawIMG(background,screen,800,0,140,50,800,0);
89c4a3a6 sago007 2008-08-29 14:32 2517
89c4a3a6 sago007 2008-08-29 14:32 2518
        DrawIMG(background,screen,50,60,300,50,50,60);
89c4a3a6 sago007 2008-08-29 14:32 2519
        DrawIMG(background,screen,510,60,300,50,510,60);
89c4a3a6 sago007 2008-08-29 14:32 2520
    }
89c4a3a6 sago007 2008-08-29 14:32 2521
    else
89c4a3a6 sago007 2008-08-29 14:32 2522
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2523
    //draw bottons (should be moves and drawn directly to background once)
89c4a3a6 sago007 2008-08-29 14:32 2524
    if (!editorMode)
2f30c381 sago007 2008-09-14 13:08 2525
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2526
        if (!networkActive) //We don't show the menu while running server or connected to a server
2f30c381 sago007 2008-09-14 13:08 2527
        #else
2f30c381 sago007 2008-09-14 13:08 2528
            if(true)
2f30c381 sago007 2008-09-14 13:08 2529
        #endif
89c4a3a6 sago007 2008-08-29 14:32 2530
        {
89c4a3a6 sago007 2008-08-29 14:32 2531
            //Here we draw the menu
43611709 sago007 2011-04-23 17:18 2532
            bNewGame.PaintTo(screen,0,0);
9050a50a sago007 2008-12-09 13:35 2533
            DrawIMG(bOptions, screen, buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2534
            DrawIMG(bHighScore, screen, 2*buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2535
            DrawIMG(bReplay,screen,3*buttonXsize,0);
89c4a3a6 sago007 2008-08-29 14:32 2536
        }
89c4a3a6 sago007 2008-08-29 14:32 2537
        else
89c4a3a6 sago007 2008-08-29 14:32 2538
        { //If network is active
89c4a3a6 sago007 2008-08-29 14:32 2539
            DrawIMG(bBack, screen, 0, 0); //Display a disconnect button
89c4a3a6 sago007 2008-08-29 14:32 2540
        }
89c4a3a6 sago007 2008-08-29 14:32 2541
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2542
        DrawIMG(bExit, screen, xsize-120,ysize-120);
e1290bdf sago007 2010-10-25 19:56 2543
    //DrawIMG(boardBackBack,screen,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2544
    DrawIMG(theGame->sBoard,screen,theGame->GetTopX(),theGame->GetTopY());
89c4a3a6 sago007 2008-08-29 14:32 2545
    string strHolder;
e1290bdf sago007 2010-10-25 19:56 2546
    strHolder = itoa(theGame->GetScore()+theGame->GetHandicap());
925b7e58 sago007 2011-04-25 16:35 2547
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2548
    if (theGame->GetAIenabled())
71181267 sago007 2011-04-29 19:22 2549
        NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2550
    else
89c4a3a6 sago007 2008-08-29 14:32 2551
        if (editorMode)
71181267 sago007 2011-04-29 19:22 2552
            NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,"Playing field");
89c4a3a6 sago007 2008-08-29 14:32 2553
        else
89c4a3a6 sago007 2008-08-29 14:32 2554
            if (!singlePuzzle)
71181267 sago007 2011-04-29 19:22 2555
                NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name);
e1290bdf sago007 2010-10-25 19:56 2556
    if (theGame->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2557
    {
e1290bdf sago007 2010-10-25 19:56 2558
        int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2559
        int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2560
        int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2561
        if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2562
        {
e1290bdf sago007 2010-10-25 19:56 2563
            minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2564
            seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2565
        }
89c4a3a6 sago007 2008-08-29 14:32 2566
        else
89c4a3a6 sago007 2008-08-29 14:32 2567
        {
e1290bdf sago007 2010-10-25 19:56 2568
            minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2569
            seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2570
        }
e1290bdf sago007 2010-10-25 19:56 2571
        if (theGame->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2572
        if (theGame->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2573
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2574
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2575
        else strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2576
        //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 2577
        NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2578
    }
89c4a3a6 sago007 2008-08-29 14:32 2579
    else
89c4a3a6 sago007 2008-08-29 14:32 2580
    {
e1290bdf sago007 2010-10-25 19:56 2581
        int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2582
        int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2583
        if (theGame->isGameOver()) minutes=(theGame->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2584
        if (theGame->isGameOver()) seconds=(theGame->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2585
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2586
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2587
        else
89c4a3a6 sago007 2008-08-29 14:32 2588
            strHolder = itoa(minutes)+":0"+itoa(seconds);
925b7e58 sago007 2011-04-25 16:35 2589
        NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2590
    }
e1290bdf sago007 2010-10-25 19:56 2591
    strHolder = itoa(theGame->GetChains());
925b7e58 sago007 2011-04-25 16:35 2592
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2593
    //drawspeedLevel:
e1290bdf sago007 2010-10-25 19:56 2594
    strHolder = itoa(theGame->GetSpeedLevel());
925b7e58 sago007 2011-04-25 16:35 2595
    NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2596
    if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY()))
89c4a3a6 sago007 2008-08-29 14:32 2597
    {
e1290bdf sago007 2010-10-25 19:56 2598
        oldBubleX = theGame->GetTopX()+280;
e1290bdf sago007 2010-10-25 19:56 2599
        oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1;
e1290bdf sago007 2010-10-25 19:56 2600
        DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
89c4a3a6 sago007 2008-08-29 14:32 2601
    }
89c4a3a6 sago007 2008-08-29 14:32 2602
    //player1 finnish, player2 start
e1290bdf sago007 2010-10-25 19:56 2603
    //DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2604
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2605
    {
f72abf8b sago007 2010-01-16 20:00 2606
        /*
f72abf8b sago007 2010-01-16 20:00 2607
         *If single player mode (and not VS)
f72abf8b sago007 2010-01-16 20:00 2608
         */
e1290bdf sago007 2010-10-25 19:56 2609
        if(!twoPlayers && !theGame->isGameOver())
e2de69cf sago007 2010-01-15 22:48 2610
        {
f72abf8b sago007 2010-01-16 20:00 2611
            //Blank player2's board:
e1290bdf sago007 2010-10-25 19:56 2612
            DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
f72abf8b sago007 2010-01-16 20:00 2613
            //Write a description:
e1290bdf sago007 2010-10-25 19:56 2614
            if(theGame->isTimeTrial())
f72abf8b sago007 2010-01-16 20:00 2615
            {
925b7e58 sago007 2011-04-25 16:35 2616
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial");
925b7e58 sago007 2011-04-25 16:35 2617
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2618
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much");
925b7e58 sago007 2011-04-25 16:35 2619
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "as possible in");
925b7e58 sago007 2011-04-25 16:35 2620
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"2 minutes");
e1290bdf sago007 2010-10-25 19:56 2621
            } else if(theGame->isStageClear())
f72abf8b sago007 2010-01-16 20:00 2622
            {
925b7e58 sago007 2011-04-25 16:35 2623
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear");
925b7e58 sago007 2011-04-25 16:35 2624
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2625
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "You must clear a");
925b7e58 sago007 2011-04-25 16:35 2626
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "number of lines.");
925b7e58 sago007 2011-04-25 16:35 2627
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"Speed is rapidly");
925b7e58 sago007 2011-04-25 16:35 2628
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"increased.");
e1290bdf sago007 2010-10-25 19:56 2629
            } else if(theGame->isPuzzleMode())
f72abf8b sago007 2010-01-16 20:00 2630
            {
925b7e58 sago007 2011-04-25 16:35 2631
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle");
925b7e58 sago007 2011-04-25 16:35 2632
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2633
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Clear the entire");
925b7e58 sago007 2011-04-25 16:35 2634
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "board with a");
925b7e58 sago007 2011-04-25 16:35 2635
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limited number of");
925b7e58 sago007 2011-04-25 16:35 2636
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"moves.");
f72abf8b sago007 2010-01-16 20:00 2637
            } else
f72abf8b sago007 2010-01-16 20:00 2638
            {
925b7e58 sago007 2011-04-25 16:35 2639
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless");
925b7e58 sago007 2011-04-25 16:35 2640
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
925b7e58 sago007 2011-04-25 16:35 2641
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much as");
925b7e58 sago007 2011-04-25 16:35 2642
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "possible. No time");
925b7e58 sago007 2011-04-25 16:35 2643
                NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limit.");
f72abf8b sago007 2010-01-16 20:00 2644
            }
f72abf8b sago007 2010-01-16 20:00 2645
f72abf8b sago007 2010-01-16 20:00 2646
            //Write the keys that are in use
e1290bdf sago007 2010-10-25 19:56 2647
            int y = theGame2->GetTopY()+400;
925b7e58 sago007 2011-04-25 16:35 2648
            NFont_Write(screen, theGame2->GetTopX()+7,y,"Movement keys:" );
925b7e58 sago007 2011-04-25 16:35 2649
            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 2650
            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 2651
            NFont_Write(screen, theGame2->GetTopX()+7,y+120,("Switch: "+getKeyName(keySettings[0].change) ).c_str() );
e1290bdf sago007 2010-10-25 19:56 2652
            if(theGame->isPuzzleMode())
925b7e58 sago007 2011-04-25 16:35 2653
                NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Restart: "+getKeyName(keySettings[0].push) ).c_str() );
f72abf8b sago007 2010-01-16 20:00 2654
            else
925b7e58 sago007 2011-04-25 16:35 2655
                NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Push line: "+getKeyName(keySettings[0].push) ).c_str() );
e2de69cf sago007 2010-01-15 22:48 2656
        }
e2de69cf sago007 2010-01-15 22:48 2657
        else
e1290bdf sago007 2010-10-25 19:56 2658
            DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
e1290bdf sago007 2010-10-25 19:56 2659
        strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap());
925b7e58 sago007 2011-04-25 16:35 2660
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2661
        if (theGame2->GetAIenabled())
71181267 sago007 2011-04-29 19:22 2662
            NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2663
        else
71181267 sago007 2011-04-29 19:22 2664
            NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name);
e1290bdf sago007 2010-10-25 19:56 2665
        if (theGame2->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2666
        {
e1290bdf sago007 2010-10-25 19:56 2667
            int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2668
            int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2669
            int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2670
            if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2671
            {
e1290bdf sago007 2010-10-25 19:56 2672
                minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2673
                seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2674
            }
89c4a3a6 sago007 2008-08-29 14:32 2675
            else
89c4a3a6 sago007 2008-08-29 14:32 2676
            {
e1290bdf sago007 2010-10-25 19:56 2677
                minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2678
                seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2679
            }
e1290bdf sago007 2010-10-25 19:56 2680
            if (theGame2->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2681
            if (theGame2->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2682
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2683
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2684
            else
89c4a3a6 sago007 2008-08-29 14:32 2685
                strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2686
            //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 2687
            NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2688
        }
89c4a3a6 sago007 2008-08-29 14:32 2689
        else
89c4a3a6 sago007 2008-08-29 14:32 2690
        {
e1290bdf sago007 2010-10-25 19:56 2691
            int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2692
            int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2693
            if (theGame2->isGameOver()) minutes=(theGame2->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2694
            if (theGame2->isGameOver()) seconds=(theGame2->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2695
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2696
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2697
            else
89c4a3a6 sago007 2008-08-29 14:32 2698
                strHolder = itoa(minutes)+":0"+itoa(seconds);
925b7e58 sago007 2011-04-25 16:35 2699
            NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2700
        }
e1290bdf sago007 2010-10-25 19:56 2701
        strHolder = itoa(theGame2->GetChains());
925b7e58 sago007 2011-04-25 16:35 2702
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2703
        strHolder = itoa(theGame2->GetSpeedLevel());
925b7e58 sago007 2011-04-25 16:35 2704
        NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2705
    }
89c4a3a6 sago007 2008-08-29 14:32 2706
    //player2 finnish
89c4a3a6 sago007 2008-08-29 14:32 2707
89c4a3a6 sago007 2008-08-29 14:32 2708
    if (bNewGameOpen)
89c4a3a6 sago007 2008-08-29 14:32 2709
    {
89c4a3a6 sago007 2008-08-29 14:32 2710
        DrawIMG(b1player,screen,0,40);
89c4a3a6 sago007 2008-08-29 14:32 2711
        DrawIMG(b2players,screen,0,80);
1572de2b sago007 2008-09-11 18:15 2712
#if NETWORK
9050a50a sago007 2008-12-09 13:35 2713
        DrawIMG(bNetwork,screen,0,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2714
#endif
89c4a3a6 sago007 2008-08-29 14:32 2715
        if (b1playerOpen)
89c4a3a6 sago007 2008-08-29 14:32 2716
        {
9050a50a sago007 2008-12-09 13:35 2717
            DrawIMG(bEndless,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2718
            DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2719
            DrawIMG(bStageClear,screen,buttonXsize,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2720
            DrawIMG(bPuzzle,screen,buttonXsize,160);
9050a50a sago007 2008-12-09 13:35 2721
            DrawIMG(bVsMode,screen,buttonXsize,200);
89c4a3a6 sago007 2008-08-29 14:32 2722
        }
89c4a3a6 sago007 2008-08-29 14:32 2723
        else
89c4a3a6 sago007 2008-08-29 14:32 2724
            if (b2playersOpen)
89c4a3a6 sago007 2008-08-29 14:32 2725
            {
9050a50a sago007 2008-12-09 13:35 2726
                DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2727
                DrawIMG(bVsMode,screen,buttonXsize,120);
89c4a3a6 sago007 2008-08-29 14:32 2728
            }
1572de2b sago007 2008-09-11 18:15 2729
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2730
            else
89c4a3a6 sago007 2008-08-29 14:32 2731
                if (bNetworkOpen)
89c4a3a6 sago007 2008-08-29 14:32 2732
                {
9050a50a sago007 2008-12-09 13:35 2733
                    DrawIMG(bHost,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2734
                    DrawIMG(bConnect,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2735
                }
89c4a3a6 sago007 2008-08-29 14:32 2736
#endif
89c4a3a6 sago007 2008-08-29 14:32 2737
    }
89c4a3a6 sago007 2008-08-29 14:32 2738
    if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 2739
    {
9050a50a sago007 2008-12-09 13:35 2740
        DrawIMG(bConfigure,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2741
        DrawIMG(bSelectPuzzle,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2742
        DrawIMG(bVsModeConfig,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2743
        DrawIMG(bTheme,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2744
    }
89c4a3a6 sago007 2008-08-29 14:32 2745
    if (bReplayOpen)
89c4a3a6 sago007 2008-08-29 14:32 2746
    {
89c4a3a6 sago007 2008-08-29 14:32 2747
        DrawIMG(bSave,screen,360,40);
89c4a3a6 sago007 2008-08-29 14:32 2748
        DrawIMG(bLoad,screen,360,80);
89c4a3a6 sago007 2008-08-29 14:32 2749
    }
89c4a3a6 sago007 2008-08-29 14:32 2750
    if (showOptions) DrawOptions(100,100);
89c4a3a6 sago007 2008-08-29 14:32 2751
89c4a3a6 sago007 2008-08-29 14:32 2752
    DrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2753
1572de2b sago007 2008-09-11 18:15 2754
#if DEBUG
89c4a3a6 sago007 2008-08-29 14:32 2755
    Frames++;
89c4a3a6 sago007 2008-08-29 14:32 2756
    if (SDL_GetTicks() >= Ticks + 1000)
89c4a3a6 sago007 2008-08-29 14:32 2757
    {
89c4a3a6 sago007 2008-08-29 14:32 2758
        if (Frames > 999) Frames=999;
78d03b38 sago007 2008-11-13 19:56 2759
        sprintf(FPS, "%lu fps", Frames);
89c4a3a6 sago007 2008-08-29 14:32 2760
        Frames = 0;
89c4a3a6 sago007 2008-08-29 14:32 2761
        Ticks = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2762
    }
89c4a3a6 sago007 2008-08-29 14:32 2763
925b7e58 sago007 2011-04-25 16:35 2764
    //NFont_Write(screen, 800,4,FPS);
925b7e58 sago007 2011-04-25 16:35 2765
    nf_standard_blue_font.draw(800,4,FPS);
89c4a3a6 sago007 2008-08-29 14:32 2766
#endif
89c4a3a6 sago007 2008-08-29 14:32 2767
89c4a3a6 sago007 2008-08-29 14:32 2768
    //SDL_Flip(screen); Update screen is now called outside DrawEvrything, bacause the mouse needs to be painted
89c4a3a6 sago007 2008-08-29 14:32 2769
89c4a3a6 sago007 2008-08-29 14:32 2770
}
89c4a3a6 sago007 2008-08-29 14:32 2771
89c4a3a6 sago007 2008-08-29 14:32 2772
//Generates the standard background
4b0c248f sago007 2010-11-10 21:13 2773
static void MakeBackground(int xsize,int ysize)
89c4a3a6 sago007 2008-08-29 14:32 2774
{
27ae0175 sago007 2009-01-30 06:02 2775
    int w = backgroundImage->w;
27ae0175 sago007 2009-01-30 06:02 2776
    int h = backgroundImage->h;
27ae0175 sago007 2009-01-30 06:02 2777
    for(int i=0;i*w<xsize;i++)
27ae0175 sago007 2009-01-30 06:02 2778
        for(int j=0;j*h<ysize;j++)
27ae0175 sago007 2009-01-30 06:02 2779
            DrawIMG(backgroundImage,background,i*w,j*h);
89c4a3a6 sago007 2008-08-29 14:32 2780
    standardBackground = true;
89c4a3a6 sago007 2008-08-29 14:32 2781
}
89c4a3a6 sago007 2008-08-29 14:32 2782
89c4a3a6 sago007 2008-08-29 14:32 2783
//Generates the background with red board backs
4b0c248f sago007 2010-11-10 21:13 2784
static void MakeBackground(int xsize,int ysize,BlockGame *theGame, BlockGame *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2785
{
27ae0175 sago007 2009-01-30 06:02 2786
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2787
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2788
    DrawIMG(boardBackBack,background,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2789
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2790
}
89c4a3a6 sago007 2008-08-29 14:32 2791
4b0c248f sago007 2010-11-10 21:13 2792
static void MakeBackground(int xsize, int ysize, BlockGame *theGame)
89c4a3a6 sago007 2008-08-29 14:32 2793
{
27ae0175 sago007 2009-01-30 06:02 2794
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2795
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2796
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2797
}
89c4a3a6 sago007 2008-08-29 14:32 2798
89c4a3a6 sago007 2008-08-29 14:32 2799
89c4a3a6 sago007 2008-08-29 14:32 2800
//The function that allows the player to choose PuzzleLevel
89c4a3a6 sago007 2008-08-29 14:32 2801
int PuzzleLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2802
{
89c4a3a6 sago007 2008-08-29 14:32 2803
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2804
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2805
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2806
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2807
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2808
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2809
89c4a3a6 sago007 2008-08-29 14:32 2810
    //Loads the levels, if they havn't been loaded:
89c4a3a6 sago007 2008-08-29 14:32 2811
    LoadPuzzleStages();
89c4a3a6 sago007 2008-08-29 14:32 2812
89c4a3a6 sago007 2008-08-29 14:32 2813
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2814
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2815
89c4a3a6 sago007 2008-08-29 14:32 2816
    ifstream puzzleFile(puzzleSavePath.c_str(),ios::binary);
27ae0175 sago007 2009-01-30 06:02 2817
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2818
    if (puzzleFile)
89c4a3a6 sago007 2008-08-29 14:32 2819
    {
89c4a3a6 sago007 2008-08-29 14:32 2820
        for (int i=0;(i<nrOfPuzzles)&&(!puzzleFile.eof()); i++)
89c4a3a6 sago007 2008-08-29 14:32 2821
        {
89c4a3a6 sago007 2008-08-29 14:32 2822
            puzzleFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2823
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2824
        }
89c4a3a6 sago007 2008-08-29 14:32 2825
        puzzleFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2826
    }
89c4a3a6 sago007 2008-08-29 14:32 2827
    else
89c4a3a6 sago007 2008-08-29 14:32 2828
    {
89c4a3a6 sago007 2008-08-29 14:32 2829
        tempBool = false;
89c4a3a6 sago007 2008-08-29 14:32 2830
        for (int i=0; i<nrOfPuzzles; i++)
89c4a3a6 sago007 2008-08-29 14:32 2831
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2832
    }
89c4a3a6 sago007 2008-08-29 14:32 2833
89c4a3a6 sago007 2008-08-29 14:32 2834
    do
89c4a3a6 sago007 2008-08-29 14:32 2835
    {
89c4a3a6 sago007 2008-08-29 14:32 2836
        nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2837
89c4a3a6 sago007 2008-08-29 14:32 2838
89c4a3a6 sago007 2008-08-29 14:32 2839
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2840
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 2841
        NFont_Write(screen, xplace+12,yplace+2,"Select Puzzle");
89c4a3a6 sago007 2008-08-29 14:32 2842
        //Now drow the fields you click in (and a V if clicked):
89c4a3a6 sago007 2008-08-29 14:32 2843
        for (int i = 0; i < nrOfPuzzles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2844
        {
89c4a3a6 sago007 2008-08-29 14:32 2845
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2846
            if (puzzleCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2847
        }
89c4a3a6 sago007 2008-08-29 14:32 2848
89c4a3a6 sago007 2008-08-29 14:32 2849
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2850
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2851
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2852
            {
89c4a3a6 sago007 2008-08-29 14:32 2853
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 2854
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 2855
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2856
                }
89c4a3a6 sago007 2008-08-29 14:32 2857
            }
89c4a3a6 sago007 2008-08-29 14:32 2858
89c4a3a6 sago007 2008-08-29 14:32 2859
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2860
89c4a3a6 sago007 2008-08-29 14:32 2861
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2862
89c4a3a6 sago007 2008-08-29 14:32 2863
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2864
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2865
        {
89c4a3a6 sago007 2008-08-29 14:32 2866
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2867
        }
89c4a3a6 sago007 2008-08-29 14:32 2868
89c4a3a6 sago007 2008-08-29 14:32 2869
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2870
        {
89c4a3a6 sago007 2008-08-29 14:32 2871
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2872
89c4a3a6 sago007 2008-08-29 14:32 2873
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 2874
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2875
            for (i = 0; (i<nrOfPuzzles/10)||((i<nrOfPuzzles/10+1)&&(nrOfPuzzles%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2876
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2877
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2878
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2879
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 2880
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2881
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2882
                    {
89c4a3a6 sago007 2008-08-29 14:32 2883
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 2884
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2885
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 2886
                    }
89c4a3a6 sago007 2008-08-29 14:32 2887
        }
89c4a3a6 sago007 2008-08-29 14:32 2888
8d488d32 sago007 2011-04-17 13:02 2889
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2890
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2891
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 2892
89c4a3a6 sago007 2008-08-29 14:32 2893
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 2894
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2895
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 2896
}
89c4a3a6 sago007 2008-08-29 14:32 2897
89c4a3a6 sago007 2008-08-29 14:32 2898
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 2899
int StageLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2900
{
89c4a3a6 sago007 2008-08-29 14:32 2901
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2902
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2903
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2904
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2905
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2906
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2907
    Uint32 tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2908
    Uint32 totalScore = 0;
89c4a3a6 sago007 2008-08-29 14:32 2909
    Uint32 totalTime = 0;
89c4a3a6 sago007 2008-08-29 14:32 2910
89c4a3a6 sago007 2008-08-29 14:32 2911
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2912
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2913
27ae0175 sago007 2009-01-30 06:02 2914
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2915
    ifstream stageFile(stageClearSavePath.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 2916
    if (stageFile)
89c4a3a6 sago007 2008-08-29 14:32 2917
    {
89c4a3a6 sago007 2008-08-29 14:32 2918
        for (int i = 0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2919
        {
89c4a3a6 sago007 2008-08-29 14:32 2920
            stageFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2921
            stageCleared[i]=tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2922
        }
89c4a3a6 sago007 2008-08-29 14:32 2923
        if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2924
        {
89c4a3a6 sago007 2008-08-29 14:32 2925
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2926
            {
89c4a3a6 sago007 2008-08-29 14:32 2927
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2928
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2929
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2930
                stageScores[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2931
                totalScore+=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2932
            }
89c4a3a6 sago007 2008-08-29 14:32 2933
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2934
            {
89c4a3a6 sago007 2008-08-29 14:32 2935
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2936
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2937
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2938
                stageTimes[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2939
                totalTime += tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2940
            }
89c4a3a6 sago007 2008-08-29 14:32 2941
        }
89c4a3a6 sago007 2008-08-29 14:32 2942
        else
89c4a3a6 sago007 2008-08-29 14:32 2943
        {
89c4a3a6 sago007 2008-08-29 14:32 2944
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2945
            {
89c4a3a6 sago007 2008-08-29 14:32 2946
                 stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2947
                 stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2948
            }
89c4a3a6 sago007 2008-08-29 14:32 2949
        }
89c4a3a6 sago007 2008-08-29 14:32 2950
        stageFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2951
    }
89c4a3a6 sago007 2008-08-29 14:32 2952
    else
89c4a3a6 sago007 2008-08-29 14:32 2953
    {
89c4a3a6 sago007 2008-08-29 14:32 2954
        for (int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2955
        {
89c4a3a6 sago007 2008-08-29 14:32 2956
            stageCleared[i]= false;
89c4a3a6 sago007 2008-08-29 14:32 2957
            stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2958
            stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2959
        }
89c4a3a6 sago007 2008-08-29 14:32 2960
    }
89c4a3a6 sago007 2008-08-29 14:32 2961
89c4a3a6 sago007 2008-08-29 14:32 2962
89c4a3a6 sago007 2008-08-29 14:32 2963
    do
89c4a3a6 sago007 2008-08-29 14:32 2964
    {
89c4a3a6 sago007 2008-08-29 14:32 2965
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2966
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2967
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 2968
        NFont_Write(screen, xplace+12,yplace+2,"Stage Clear Level Select");
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
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2972
            if (stageCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2973
        }
89c4a3a6 sago007 2008-08-29 14:32 2974
89c4a3a6 sago007 2008-08-29 14:32 2975
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2976
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2977
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2978
            {
89c4a3a6 sago007 2008-08-29 14:32 2979
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 2980
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 2981
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2982
                }
89c4a3a6 sago007 2008-08-29 14:32 2983
            }
89c4a3a6 sago007 2008-08-29 14:32 2984
89c4a3a6 sago007 2008-08-29 14:32 2985
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2986
89c4a3a6 sago007 2008-08-29 14:32 2987
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2988
89c4a3a6 sago007 2008-08-29 14:32 2989
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2990
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2991
        {
89c4a3a6 sago007 2008-08-29 14:32 2992
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2993
        }
89c4a3a6 sago007 2008-08-29 14:32 2994
89c4a3a6 sago007 2008-08-29 14:32 2995
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2996
        {
89c4a3a6 sago007 2008-08-29 14:32 2997
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2998
89c4a3a6 sago007 2008-08-29 14:32 2999
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 3000
            int i;
89c4a3a6 sago007 2008-08-29 14:32 3001
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 3002
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 3003
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 3004
            i++;
89c4a3a6 sago007 2008-08-29 14:32 3005
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 3006
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 3007
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 3008
                    {
89c4a3a6 sago007 2008-08-29 14:32 3009
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 3010
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 3011
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 3012
                    }
89c4a3a6 sago007 2008-08-29 14:32 3013
        }
89c4a3a6 sago007 2008-08-29 14:32 3014
        //Find what we are over:
89c4a3a6 sago007 2008-08-29 14:32 3015
            int overLevel = -1;
89c4a3a6 sago007 2008-08-29 14:32 3016
            int i;
89c4a3a6 sago007 2008-08-29 14:32 3017
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 3018
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 3019
                    overLevel = i*10;
89c4a3a6 sago007 2008-08-29 14:32 3020
            i++;
89c4a3a6 sago007 2008-08-29 14:32 3021
            if (overLevel != -1)
89c4a3a6 sago007 2008-08-29 14:32 3022
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 3023
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 3024
                    {
89c4a3a6 sago007 2008-08-29 14:32 3025
                        overLevel +=j;
89c4a3a6 sago007 2008-08-29 14:32 3026
                        string scoreString = "Best score: 0";
89c4a3a6 sago007 2008-08-29 14:32 3027
                        string timeString = "Time used: -- : --";
89c4a3a6 sago007 2008-08-29 14:32 3028
                        
89c4a3a6 sago007 2008-08-29 14:32 3029
                        if(stageScores.at(overLevel)>0)
89c4a3a6 sago007 2008-08-29 14:32 3030
                            scoreString = "Best score: "+itoa(stageScores[overLevel]);
89c4a3a6 sago007 2008-08-29 14:32 3031
                        if(stageTimes[overLevel]>0)
89c4a3a6 sago007 2008-08-29 14:32 3032
                            timeString = "Time used: "+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60);
89c4a3a6 sago007 2008-08-29 14:32 3033
                        
925b7e58 sago007 2011-04-25 16:35 3034
                        NFont_Write(screen, 200,200,scoreString.c_str());
925b7e58 sago007 2011-04-25 16:35 3035
                        NFont_Write(screen, 200,250,timeString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3036
                        
89c4a3a6 sago007 2008-08-29 14:32 3037
                        overLevel;
89c4a3a6 sago007 2008-08-29 14:32 3038
                    }
89c4a3a6 sago007 2008-08-29 14:32 3039
            string totalString = "Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60);
925b7e58 sago007 2011-04-25 16:35 3040
            NFont_Write(screen, 200,600,totalString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3041
8d488d32 sago007 2011-04-17 13:02 3042
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3043
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3044
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3045
89c4a3a6 sago007 2008-08-29 14:32 3046
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 3047
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3048
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 3049
}
89c4a3a6 sago007 2008-08-29 14:32 3050
89c4a3a6 sago007 2008-08-29 14:32 3051
//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 3052
int startSingleVs()
89c4a3a6 sago007 2008-08-29 14:32 3053
{
89c4a3a6 sago007 2008-08-29 14:32 3054
    //Where to place the windows
89c4a3a6 sago007 2008-08-29 14:32 3055
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3056
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3057
    Uint8 *keys;	//To take keyboard input
89c4a3a6 sago007 2008-08-29 14:32 3058
    int mousex, mousey;	//To allow mouse
89c4a3a6 sago007 2008-08-29 14:32 3059
    bool done = false;	//When are we done?
89c4a3a6 sago007 2008-08-29 14:32 3060
27ae0175 sago007 2009-01-30 06:02 3061
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3062
    DrawIMG(changeButtonsBack,background,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 3063
    NFont_Write(background, xplace+10,yplace+10,"1 : Very Easy");
925b7e58 sago007 2011-04-25 16:35 3064
    NFont_Write(background, xplace+10,yplace+40,"2 : Easy");
925b7e58 sago007 2011-04-25 16:35 3065
    NFont_Write(background, xplace+10,yplace+70,"3 : Below Normal");
925b7e58 sago007 2011-04-25 16:35 3066
    NFont_Write(background, xplace+10,yplace+100,"4 : Normal");
925b7e58 sago007 2011-04-25 16:35 3067
    NFont_Write(background, xplace+10,yplace+130,"5 : Above Normal");
925b7e58 sago007 2011-04-25 16:35 3068
    NFont_Write(background, xplace+10,yplace+160,"6 : Hard");
925b7e58 sago007 2011-04-25 16:35 3069
    NFont_Write(background, xplace+10,yplace+190,"7 : Hardest");
89c4a3a6 sago007 2008-08-29 14:32 3070
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3071
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3072
    do
89c4a3a6 sago007 2008-08-29 14:32 3073
    {
89c4a3a6 sago007 2008-08-29 14:32 3074
89c4a3a6 sago007 2008-08-29 14:32 3075
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3076
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3077
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3078
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3079
            {
4f1d27f1 sago007 2011-03-18 15:53 3080
                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 3081
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3082
                }
4f1d27f1 sago007 2011-03-18 15:53 3083
                if ( event.key.keysym.sym == SDLK_1 || event.key.keysym.sym == SDLK_KP1 ) {
89c4a3a6 sago007 2008-08-29 14:32 3084
                    return 0;
89c4a3a6 sago007 2008-08-29 14:32 3085
                }
4f1d27f1 sago007 2011-03-18 15:53 3086
                if ( event.key.keysym.sym == SDLK_2 || event.key.keysym.sym == SDLK_KP2 ) {
89c4a3a6 sago007 2008-08-29 14:32 3087
                    return 1;
89c4a3a6 sago007 2008-08-29 14:32 3088
                }
4f1d27f1 sago007 2011-03-18 15:53 3089
                if ( event.key.keysym.sym == SDLK_3 || event.key.keysym.sym == SDLK_KP3 ) {
89c4a3a6 sago007 2008-08-29 14:32 3090
                    return 2;
89c4a3a6 sago007 2008-08-29 14:32 3091
                }
4f1d27f1 sago007 2011-03-18 15:53 3092
                if ( event.key.keysym.sym == SDLK_4 || event.key.keysym.sym == SDLK_KP4 ) {
89c4a3a6 sago007 2008-08-29 14:32 3093
                    return 3;
89c4a3a6 sago007 2008-08-29 14:32 3094
                }
4f1d27f1 sago007 2011-03-18 15:53 3095
                if ( event.key.keysym.sym == SDLK_5 || event.key.keysym.sym == SDLK_KP5 ) {
89c4a3a6 sago007 2008-08-29 14:32 3096
                    return 4;
89c4a3a6 sago007 2008-08-29 14:32 3097
                }
4f1d27f1 sago007 2011-03-18 15:53 3098
                if ( event.key.keysym.sym == SDLK_6 || event.key.keysym.sym == SDLK_KP6 ) {
89c4a3a6 sago007 2008-08-29 14:32 3099
                    return 5;
89c4a3a6 sago007 2008-08-29 14:32 3100
                }
4f1d27f1 sago007 2011-03-18 15:53 3101
                if ( event.key.keysym.sym == SDLK_7 || event.key.keysym.sym == SDLK_KP7 ) {
89c4a3a6 sago007 2008-08-29 14:32 3102
                    return 6;
89c4a3a6 sago007 2008-08-29 14:32 3103
                }
89c4a3a6 sago007 2008-08-29 14:32 3104
            }
89c4a3a6 sago007 2008-08-29 14:32 3105
89c4a3a6 sago007 2008-08-29 14:32 3106
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3107
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3108
        {
89c4a3a6 sago007 2008-08-29 14:32 3109
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3110
        }
89c4a3a6 sago007 2008-08-29 14:32 3111
89c4a3a6 sago007 2008-08-29 14:32 3112
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3113
        {
89c4a3a6 sago007 2008-08-29 14:32 3114
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3115
89c4a3a6 sago007 2008-08-29 14:32 3116
            for (int i=0; i<7;i++)
89c4a3a6 sago007 2008-08-29 14:32 3117
            {
89c4a3a6 sago007 2008-08-29 14:32 3118
                if ((mousex>xplace+10)&&(mousex<xplace+410)&&(mousey>yplace+10+i*30)&&(mousey<yplace+38+i*30))
89c4a3a6 sago007 2008-08-29 14:32 3119
                    return i;
89c4a3a6 sago007 2008-08-29 14:32 3120
            }
89c4a3a6 sago007 2008-08-29 14:32 3121
        }
89c4a3a6 sago007 2008-08-29 14:32 3122
89c4a3a6 sago007 2008-08-29 14:32 3123
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3124
        DrawIMG(background, screen, 0, 0);
8d488d32 sago007 2011-04-17 13:02 3125
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3126
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3127
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3128
    }while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3129
89c4a3a6 sago007 2008-08-29 14:32 3130
89c4a3a6 sago007 2008-08-29 14:32 3131
    return 3; //Returns normal
89c4a3a6 sago007 2008-08-29 14:32 3132
}
89c4a3a6 sago007 2008-08-29 14:32 3133
89c4a3a6 sago007 2008-08-29 14:32 3134
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 3135
void startVsMenu()
89c4a3a6 sago007 2008-08-29 14:32 3136
{
89c4a3a6 sago007 2008-08-29 14:32 3137
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3138
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3139
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3140
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 3141
    bool done = false;
89c4a3a6 sago007 2008-08-29 14:32 3142
89c4a3a6 sago007 2008-08-29 14:32 3143
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3144
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3145
27ae0175 sago007 2009-01-30 06:02 3146
    MakeBackground(xsize,ysize);
925b7e58 sago007 2011-04-25 16:35 3147
    NFont_Write(background, 360,650,"Press ESC to accept");
27ae0175 sago007 2009-01-30 06:02 3148
    DrawIMG(bBack,background,xsize/2-120/2,600);
89c4a3a6 sago007 2008-08-29 14:32 3149
    do
89c4a3a6 sago007 2008-08-29 14:32 3150
    {
89c4a3a6 sago007 2008-08-29 14:32 3151
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3152
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3153
        DrawIMG(changeButtonsBack,screen,xplace,yplace);
925b7e58 sago007 2011-04-25 16:35 3154
        NFont_Write(screen, xplace+50,yplace+20,"Player 1");
925b7e58 sago007 2011-04-25 16:35 3155
        NFont_Write(screen, xplace+300+50,yplace+20,"Player 2");
925b7e58 sago007 2011-04-25 16:35 3156
        NFont_Write(screen, xplace+50,yplace+70,"Speed:");
925b7e58 sago007 2011-04-25 16:35 3157
        NFont_Write(screen, xplace+50+300,yplace+70,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 3158
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3159
        {
89c4a3a6 sago007 2008-08-29 14:32 3160
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3161
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3162
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3163
            NFont_Write(screen, xplace+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3164
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3165
            if (player1Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3166
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3167
        }
89c4a3a6 sago007 2008-08-29 14:32 3168
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3169
        {
89c4a3a6 sago007 2008-08-29 14:32 3170
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3171
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3172
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3173
            NFont_Write(screen, xplace+300+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3174
            DrawIMG(iLevelCheckBox,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3175
            if (player2Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3176
                DrawIMG(iLevelCheck,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3177
        }
925b7e58 sago007 2011-04-25 16:35 3178
        NFont_Write(screen, xplace+50,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3179
        DrawIMG(iLevelCheckBox,screen,xplace+50+70,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3180
        if (player1AI)
89c4a3a6 sago007 2008-08-29 14:32 3181
            DrawIMG(iLevelCheck,screen,xplace+50+70,yplace+200);
925b7e58 sago007 2011-04-25 16:35 3182
        NFont_Write(screen, xplace+50,yplace+250,"TT Handicap: ");
925b7e58 sago007 2011-04-25 16:35 3183
        NFont_Write(screen, xplace+50+300,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3184
        DrawIMG(iLevelCheckBox,screen,xplace+50+70+300,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3185
        if (player2AI)
89c4a3a6 sago007 2008-08-29 14:32 3186
            DrawIMG(iLevelCheck,screen,xplace+50+70+300,yplace+200);
925b7e58 sago007 2011-04-25 16:35 3187
        NFont_Write(screen, xplace+50+300,yplace+250,"TT Handicap: ");
89c4a3a6 sago007 2008-08-29 14:32 3188
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3189
        {
89c4a3a6 sago007 2008-08-29 14:32 3190
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3191
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3192
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3193
            NFont_Write(screen, xplace+50+i*40,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3194
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3195
            if (player1handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3196
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3197
        }
89c4a3a6 sago007 2008-08-29 14:32 3198
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3199
        {
89c4a3a6 sago007 2008-08-29 14:32 3200
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3201
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3202
            levelS[1]=0;
925b7e58 sago007 2011-04-25 16:35 3203
            NFont_Write(screen, xplace+50+i*40+300,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3204
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3205
            if (player2handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3206
                DrawIMG(iLevelCheck,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3207
        }
89c4a3a6 sago007 2008-08-29 14:32 3208
89c4a3a6 sago007 2008-08-29 14:32 3209
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3210
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3211
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3212
            {
89c4a3a6 sago007 2008-08-29 14:32 3213
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3214
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3215
                }
89c4a3a6 sago007 2008-08-29 14:32 3216
                if ( event.key.keysym.sym == SDLK_RETURN ) {
89c4a3a6 sago007 2008-08-29 14:32 3217
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3218
                }
89c4a3a6 sago007 2008-08-29 14:32 3219
                if ( event.key.keysym.sym == SDLK_KP_ENTER ) {
89c4a3a6 sago007 2008-08-29 14:32 3220
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3221
                }
89c4a3a6 sago007 2008-08-29 14:32 3222
            }
89c4a3a6 sago007 2008-08-29 14:32 3223
89c4a3a6 sago007 2008-08-29 14:32 3224
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3225
89c4a3a6 sago007 2008-08-29 14:32 3226
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3227
89c4a3a6 sago007 2008-08-29 14:32 3228
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3229
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3230
        {
89c4a3a6 sago007 2008-08-29 14:32 3231
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3232
        }
89c4a3a6 sago007 2008-08-29 14:32 3233
89c4a3a6 sago007 2008-08-29 14:32 3234
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3235
        {
89c4a3a6 sago007 2008-08-29 14:32 3236
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3237
89c4a3a6 sago007 2008-08-29 14:32 3238
            if ((mousex>xplace+50+70)&&(mousey>yplace+200)&&(mousex<xplace+50+70+30)&&(mousey<yplace+200+30))
89c4a3a6 sago007 2008-08-29 14:32 3239
                player1AI=!player1AI;
89c4a3a6 sago007 2008-08-29 14:32 3240
            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 3241
                player2AI=!player2AI;
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
                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 3245
                    player1Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3246
            }
89c4a3a6 sago007 2008-08-29 14:32 3247
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3248
            {
89c4a3a6 sago007 2008-08-29 14:32 3249
                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 3250
                    player2Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3251
            }
89c4a3a6 sago007 2008-08-29 14:32 3252
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3253
            {
89c4a3a6 sago007 2008-08-29 14:32 3254
                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 3255
                    player1handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3256
            }
89c4a3a6 sago007 2008-08-29 14:32 3257
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3258
            {
89c4a3a6 sago007 2008-08-29 14:32 3259
                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 3260
                    player2handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3261
            }
27ae0175 sago007 2009-01-30 06:02 3262
            if ((mousex>xsize/2-120/2)&&(mousex<xsize/2+120/2)&&(mousey>600)&&(mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 3263
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 3264
        }
89c4a3a6 sago007 2008-08-29 14:32 3265
8d488d32 sago007 2011-04-17 13:02 3266
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3267
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3268
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3269
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3270
89c4a3a6 sago007 2008-08-29 14:32 3271
    } while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3272
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3273
}
89c4a3a6 sago007 2008-08-29 14:32 3274
89c4a3a6 sago007 2008-08-29 14:32 3275
//This function will promt for the user to select another file for puzzle mode
89c4a3a6 sago007 2008-08-29 14:32 3276
void changePuzzleLevels()
89c4a3a6 sago007 2008-08-29 14:32 3277
{
89c4a3a6 sago007 2008-08-29 14:32 3278
    char theFileName[30];
89c4a3a6 sago007 2008-08-29 14:32 3279
    strcpy(theFileName,puzzleName.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3280
    for (int i=puzzleName.length();i<30;i++)
89c4a3a6 sago007 2008-08-29 14:32 3281
        theFileName[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 3282
    theFileName[29]=0;
89c4a3a6 sago007 2008-08-29 14:32 3283
    if (OpenFileDialogbox(200,100,theFileName))
89c4a3a6 sago007 2008-08-29 14:32 3284
    {
89c4a3a6 sago007 2008-08-29 14:32 3285
        for (int i=28;((theFileName[i]==' ')&&(i>0));i--)
89c4a3a6 sago007 2008-08-29 14:32 3286
            theFileName[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3287
        puzzleName = theFileName;
89c4a3a6 sago007 2008-08-29 14:32 3288
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3289
        string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3290
        puzzleSavePath = home+"/.gamesaves/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3291
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3292
        string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3293
        if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3294
        {
89c4a3a6 sago007 2008-08-29 14:32 3295
            puzzleSavePath = home+"/My Games/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3296
        }
89c4a3a6 sago007 2008-08-29 14:32 3297
        else
89c4a3a6 sago007 2008-08-29 14:32 3298
        {
89c4a3a6 sago007 2008-08-29 14:32 3299
            puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3300
        }
89c4a3a6 sago007 2008-08-29 14:32 3301
#else
89c4a3a6 sago007 2008-08-29 14:32 3302
        puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3303
#endif
89c4a3a6 sago007 2008-08-29 14:32 3304
    }
89c4a3a6 sago007 2008-08-29 14:32 3305
89c4a3a6 sago007 2008-08-29 14:32 3306
}
89c4a3a6 sago007 2008-08-29 14:32 3307
30f910dd sago007 2010-11-10 21:02 3308
static BlockGameSdl *player1;
30f910dd sago007 2010-11-10 21:02 3309
static BlockGameSdl *player2;
30f910dd sago007 2010-11-10 21:02 3310
30f910dd sago007 2010-11-10 21:02 3311
void StartSinglePlayerEndless() {
30f910dd sago007 2010-11-10 21:02 3312
    //1 player - endless
30f910dd sago007 2010-11-10 21:02 3313
    player1->NewGame(50,100,SDL_GetTicks());
30f910dd sago007 2010-11-10 21:02 3314
    player1->putStartBlocks(time(0));
30f910dd sago007 2010-11-10 21:02 3315
    bNewGameOpen = false;
30f910dd sago007 2010-11-10 21:02 3316
    b1playerOpen = false;
30f910dd sago007 2010-11-10 21:02 3317
    twoPlayers =false;
30f910dd sago007 2010-11-10 21:02 3318
    player2->SetGameOver();
30f910dd sago007 2010-11-10 21:02 3319
    showGame = true;
30f910dd sago007 2010-11-10 21:02 3320
    strcpy(player1->name, player1name);
30f910dd sago007 2010-11-10 21:02 3321
    strcpy(player2->name, player2name);
30f910dd sago007 2010-11-10 21:02 3322
}
30f910dd sago007 2010-11-10 21:02 3323
4f1d27f1 sago007 2011-03-18 15:53 3324
void StartSinglePlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3325
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3326
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3327
    twoPlayers =false;
4f1d27f1 sago007 2011-03-18 15:53 3328
    player2->SetGameOver();
4f1d27f1 sago007 2011-03-18 15:53 3329
    showGame = true;
4f1d27f1 sago007 2011-03-18 15:53 3330
    //vsMode = false;
4f1d27f1 sago007 2011-03-18 15:53 3331
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3332
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3333
}
4f1d27f1 sago007 2011-03-18 15:53 3334
b7590374 sago007 2011-05-19 16:15 3335
void StartSinglePlayerPuzzle() {
b7590374 sago007 2011-05-19 16:15 3336
    int myLevel = PuzzleLevelSelect();
b7590374 sago007 2011-05-19 16:15 3337
    player1->NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 3338
    MakeBackground(xsize,ysize,player1,player2);
b7590374 sago007 2011-05-19 16:15 3339
    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 3340
    closeAllMenus();
b7590374 sago007 2011-05-19 16:15 3341
    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 3342
    player2->SetGameOver();
b7590374 sago007 2011-05-19 16:15 3343
    showGame = true;
b7590374 sago007 2011-05-19 16:15 3344
    //vsMode = true;
b7590374 sago007 2011-05-19 16:15 3345
    strcpy(player1->name, player1name);
b7590374 sago007 2011-05-19 16:15 3346
    strcpy(player2->name, player2name);
b7590374 sago007 2011-05-19 16:15 3347
}
b7590374 sago007 2011-05-19 16:15 3348
4f1d27f1 sago007 2011-03-18 15:53 3349
4f1d27f1 sago007 2011-03-18 15:53 3350
void StarTwoPlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3351
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3352
    player2->NewTimeTrialGame(xsize-500,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3353
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3354
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3355
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3356
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3357
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3358
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3359
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3360
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3361
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3362
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3363
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3364
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3365
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3366
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3367
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3368
}
4f1d27f1 sago007 2011-03-18 15:53 3369
4f1d27f1 sago007 2011-03-18 15:53 3370
void StartTwoPlayerVs() {
4f1d27f1 sago007 2011-03-18 15:53 3371
    //2 player - VsMode
4f1d27f1 sago007 2011-03-18 15:53 3372
    player1->NewVsGame(50,100,player2,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3373
    player2->NewVsGame(xsize-500,100,player1,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3374
    bNewGameOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3375
    //vsMode = true;
4f1d27f1 sago007 2011-03-18 15:53 3376
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3377
    b2playersOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3378
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3379
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3380
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3381
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3382
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3383
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3384
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3385
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3386
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3387
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3388
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3389
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3390
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3391
}
4f1d27f1 sago007 2011-03-18 15:53 3392
1572de2b sago007 2008-09-11 18:15 3393
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3394
#include "NetworkThing.hpp"
eec83b7d sago007 2009-03-29 15:46 3395
//#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 3396
#endif
89c4a3a6 sago007 2008-08-29 14:32 3397
89c4a3a6 sago007 2008-08-29 14:32 3398
//The main function, quite big... too big
89c4a3a6 sago007 2008-08-29 14:32 3399
int main(int argc, char *argv[])
89c4a3a6 sago007 2008-08-29 14:32 3400
{
89c4a3a6 sago007 2008-08-29 14:32 3401
    //We first create the folder there we will save (only on UNIX systems)
89c4a3a6 sago007 2008-08-29 14:32 3402
    //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 3403
#if defined(__unix__)
42f8ed5f sago007 2009-03-05 11:47 3404
    //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 3405
    if(system("mkdir -p ~/.gamesaves/blockattack/screenshots"))
42f8ed5f sago007 2009-03-05 11:47 3406
        cout << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl;
42f8ed5f sago007 2009-03-05 11:47 3407
    if(system("mkdir -p ~/.gamesaves/blockattack/replays"))
42f8ed5f sago007 2009-03-05 11:47 3408
        cout << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl;
42f8ed5f sago007 2009-03-05 11:47 3409
    if(system("mkdir -p ~/.gamesaves/blockattack/puzzles"))
42f8ed5f sago007 2009-03-05 11:47 3410
        cout << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3411
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3412
    //Now for Windows NT/2k/xp/2k3 etc.
89c4a3a6 sago007 2008-08-29 14:32 3413
    string tempA = getMyDocumentsPath()+"\\My Games";
c325f4fa sago007 2009-05-09 18:33 3414
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3415
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack";
c325f4fa sago007 2009-05-09 18:33 3416
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3417
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays";
c325f4fa sago007 2009-05-09 18:33 3418
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3419
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots";
c325f4fa sago007 2009-05-09 18:33 3420
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3421
#endif
78d03b38 sago007 2008-11-13 19:56 3422
    highPriority = false;	//if true the game will take most resources, but increase framerate.
89c4a3a6 sago007 2008-08-29 14:32 3423
    bFullscreen = false;
2e57d791 sago007 2009-06-04 17:48 3424
    //Set default Config variables:
2e57d791 sago007 2009-06-04 17:48 3425
    Config::getInstance()->setDefault("themename","default");
89c4a3a6 sago007 2008-08-29 14:32 3426
    if (argc > 1)
89c4a3a6 sago007 2008-08-29 14:32 3427
    {
89c4a3a6 sago007 2008-08-29 14:32 3428
        int argumentNr = 1;
89c4a3a6 sago007 2008-08-29 14:32 3429
        forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3430
        while (argc>argumentNr)
89c4a3a6 sago007 2008-08-29 14:32 3431
        {
89c4a3a6 sago007 2008-08-29 14:32 3432
            char helpString[] = "--help";
89c4a3a6 sago007 2008-08-29 14:32 3433
            char priorityString[] = "-priority";
89c4a3a6 sago007 2008-08-29 14:32 3434
            char forceRedrawString[] = "-forceredraw";
89c4a3a6 sago007 2008-08-29 14:32 3435
            char forcepartdrawString[] = "-forcepartdraw";
89c4a3a6 sago007 2008-08-29 14:32 3436
            char singlePuzzleString[] = "-SP";
89c4a3a6 sago007 2008-08-29 14:32 3437
            char noSoundAtAll[] = "-nosound";
89c4a3a6 sago007 2008-08-29 14:32 3438
            char IntegratedEditor[] = "-editor";
2e57d791 sago007 2009-06-04 17:48 3439
            char selectTheme[] = "-theme";
89c4a3a6 sago007 2008-08-29 14:32 3440
            if (!(strncmp(argv[argumentNr],helpString,6)))
89c4a3a6 sago007 2008-08-29 14:32 3441
            {
89c4a3a6 sago007 2008-08-29 14:32 3442
                cout << "Block Attack Help" << endl << "--help Display this message" <<
89c4a3a6 sago007 2008-08-29 14:32 3443
                endl << "-priority  Starts game in high priority" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3444
                "-forceredraw  Redraw the whole screen every frame, prevents garbage" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3445
                "-forcepartdraw  Only draw what is changed, sometimes cause garbage" << endl <<
2e57d791 sago007 2009-06-04 17:48 3446
                "-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 3447
                "-theme <THEMENAME>  Changes to the theme <THEMENAME> on startup" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3448
                "-editor  Starts the build-in editor (not yet integrated)" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3449
#ifdef WIN32
89c4a3a6 sago007 2008-08-29 14:32 3450
                system("Pause");
89c4a3a6 sago007 2008-08-29 14:32 3451
#endif
89c4a3a6 sago007 2008-08-29 14:32 3452
                return 0;
89c4a3a6 sago007 2008-08-29 14:32 3453
            }
89c4a3a6 sago007 2008-08-29 14:32 3454
            if (!(strncmp(argv[argumentNr],priorityString,9)))
89c4a3a6 sago007 2008-08-29 14:32 3455
            {
89c4a3a6 sago007 2008-08-29 14:32 3456
                cout << "Priority mode" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3457
                highPriority = true;
89c4a3a6 sago007 2008-08-29 14:32 3458
            }
89c4a3a6 sago007 2008-08-29 14:32 3459
            if (!(strncmp(argv[argumentNr],forceRedrawString,12)))
89c4a3a6 sago007 2008-08-29 14:32 3460
            {
89c4a3a6 sago007 2008-08-29 14:32 3461
                forceredraw = 1;
89c4a3a6 sago007 2008-08-29 14:32 3462
            }
89c4a3a6 sago007 2008-08-29 14:32 3463
            if (!(strncmp(argv[argumentNr],forcepartdrawString,14)))
89c4a3a6 sago007 2008-08-29 14:32 3464
            {
89c4a3a6 sago007 2008-08-29 14:32 3465
                forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3466
            }
89c4a3a6 sago007 2008-08-29 14:32 3467
            if (!(strncmp(argv[argumentNr],singlePuzzleString,3)))
89c4a3a6 sago007 2008-08-29 14:32 3468
            {
89c4a3a6 sago007 2008-08-29 14:32 3469
                singlePuzzle = true; //We will just have one puzzle
89c4a3a6 sago007 2008-08-29 14:32 3470
                if (argv[argumentNr+1][1]!=0)
89c4a3a6 sago007 2008-08-29 14:32 3471
                    singlePuzzleNr = (argv[argumentNr+1][1]-'0')+(argv[argumentNr+1][0]-'0')*10;
89c4a3a6 sago007 2008-08-29 14:32 3472
                else
89c4a3a6 sago007 2008-08-29 14:32 3473
                    singlePuzzleNr = (argv[argumentNr+1][0]-'0');
89c4a3a6 sago007 2008-08-29 14:32 3474
                singlePuzzleFile = argv[argumentNr+2];
89c4a3a6 sago007 2008-08-29 14:32 3475
                argumentNr+=2;
89c4a3a6 sago007 2008-08-29 14:32 3476
                cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl;
89c4a3a6 sago007 2008-08-29 14:32 3477
            }
89c4a3a6 sago007 2008-08-29 14:32 3478
            if (!(strncmp(argv[argumentNr],noSoundAtAll,8)))
89c4a3a6 sago007 2008-08-29 14:32 3479
            {
89c4a3a6 sago007 2008-08-29 14:32 3480
                NoSound = true;
89c4a3a6 sago007 2008-08-29 14:32 3481
            }
89c4a3a6 sago007 2008-08-29 14:32 3482
            if (!(strncmp(argv[argumentNr],IntegratedEditor,7)))
89c4a3a6 sago007 2008-08-29 14:32 3483
            {
1572de2b sago007 2008-09-11 18:15 3484
                #if LEVELEDITOR
89c4a3a6 sago007 2008-08-29 14:32 3485
                editorMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3486
                cout << "Integrated Puzzle Editor Activated" << endl;
1572de2b sago007 2008-09-11 18:15 3487
                #else
1572de2b sago007 2008-09-11 18:15 3488
                cout << "Integrated Puzzle Editor was disabled at compile time" << endl;
2e57d791 sago007 2009-06-04 17:48 3489
                return -1;
1572de2b sago007 2008-09-11 18:15 3490
                #endif
89c4a3a6 sago007 2008-08-29 14:32 3491
            }
2e57d791 sago007 2009-06-04 17:48 3492
            if(!(strncmp(argv[argumentNr],selectTheme,6)))
2e57d791 sago007 2009-06-04 17:48 3493
            {
2e57d791 sago007 2009-06-04 17:48 3494
                argumentNr++; //Go to themename (the next argument)
2e57d791 sago007 2009-06-04 17:48 3495
                cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
2e57d791 sago007 2009-06-04 17:48 3496
                Config::getInstance()->setString("themename",argv[argumentNr]);
2e57d791 sago007 2009-06-04 17:48 3497
            }
89c4a3a6 sago007 2008-08-29 14:32 3498
            argumentNr++;
89c4a3a6 sago007 2008-08-29 14:32 3499
        }   //while
89c4a3a6 sago007 2008-08-29 14:32 3500
    }   //if
89c4a3a6 sago007 2008-08-29 14:32 3501
89c4a3a6 sago007 2008-08-29 14:32 3502
    SoundEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3503
    MusicEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3504
    int mousex, mousey;   //Mouse coordinates
89c4a3a6 sago007 2008-08-29 14:32 3505
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3506
    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3507
    b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3508
    bReplayOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3509
    bScreenLocked = false;
f72abf8b sago007 2010-01-16 20:00 3510
    twoPlayers = false;	//true if two players splitscreen
89c4a3a6 sago007 2008-08-29 14:32 3511
    bool vsMode = false;
89c4a3a6 sago007 2008-08-29 14:32 3512
    theTopScoresEndless = Highscore(1);
89c4a3a6 sago007 2008-08-29 14:32 3513
    theTopScoresTimeTrial = Highscore(2);
89c4a3a6 sago007 2008-08-29 14:32 3514
    drawBalls = true;
89c4a3a6 sago007 2008-08-29 14:32 3515
    puzzleLoaded = false;
89c4a3a6 sago007 2008-08-29 14:32 3516
    bool weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3517
89c4a3a6 sago007 2008-08-29 14:32 3518
    //Things used for repeating keystrokes:
30f910dd sago007 2010-11-10 21:02 3519
    bool repeatingS[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3520
    bool repeatingW[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3521
    bool repeatingN[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3522
    bool repeatingE[2] = {false,false};
89c4a3a6 sago007 2008-08-29 14:32 3523
    const int startRepeat = 200;
89c4a3a6 sago007 2008-08-29 14:32 3524
    const int repeatDelay = 100;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 3525
    unsigned long timeHeldP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3526
    unsigned long timeHeldP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3527
    unsigned long timeHeldP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3528
    unsigned long timeHeldP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3529
    unsigned long timeHeldP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3530
    unsigned long timeHeldP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3531
    unsigned long timeHeldP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3532
    unsigned long timeHeldP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3533
    unsigned long timesRepeatedP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3534
    unsigned long timesRepeatedP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3535
    unsigned long timesRepeatedP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3536
    unsigned long timesRepeatedP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3537
    unsigned long timesRepeatedP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3538
    unsigned long timesRepeatedP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3539
    unsigned long timesRepeatedP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3540
    unsigned long timesRepeatedP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3541
89c4a3a6 sago007 2008-08-29 14:32 3542
    theBallManeger = ballManeger();
89c4a3a6 sago007 2008-08-29 14:32 3543
    theExplosionManeger = explosionManeger();
89c4a3a6 sago007 2008-08-29 14:32 3544
89c4a3a6 sago007 2008-08-29 14:32 3545
//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 3546
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3547
    string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3548
    string optionsPath = home+"/.gamesaves/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3549
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3550
    string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3551
    string optionsPath;
89c4a3a6 sago007 2008-08-29 14:32 3552
    if (&home!=NULL) //Null if no APPDATA dir exists (win 9x)
89c4a3a6 sago007 2008-08-29 14:32 3553
        optionsPath = home+"/My Games/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3554
    else
89c4a3a6 sago007 2008-08-29 14:32 3555
        optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3556
#else
89c4a3a6 sago007 2008-08-29 14:32 3557
    string optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3558
#endif
89c4a3a6 sago007 2008-08-29 14:32 3559
89c4a3a6 sago007 2008-08-29 14:32 3560
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3561
    stageClearSavePath = home+"/.gamesaves/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3562
    puzzleSavePath = home+"/.gamesaves/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3563
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3564
    if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3565
    {
89c4a3a6 sago007 2008-08-29 14:32 3566
        stageClearSavePath = home+"/My Games/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3567
        puzzleSavePath = home+"/My Games/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3568
    }
89c4a3a6 sago007 2008-08-29 14:32 3569
    else
89c4a3a6 sago007 2008-08-29 14:32 3570
    {
89c4a3a6 sago007 2008-08-29 14:32 3571
        stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3572
        puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3573
    }
89c4a3a6 sago007 2008-08-29 14:32 3574
#else
89c4a3a6 sago007 2008-08-29 14:32 3575
    stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3576
    puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3577
#endif
89c4a3a6 sago007 2008-08-29 14:32 3578
    puzzleName="puzzle.levels";
89c4a3a6 sago007 2008-08-29 14:32 3579
89c4a3a6 sago007 2008-08-29 14:32 3580
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3581
866417ca sago007 2009-05-10 21:35 3582
95bc02ff sago007 2009-03-15 02:46 3583
89c4a3a6 sago007 2008-08-29 14:32 3584
    //Init SDL
89c4a3a6 sago007 2008-08-29 14:32 3585
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
89c4a3a6 sago007 2008-08-29 14:32 3586
    {
89c4a3a6 sago007 2008-08-29 14:32 3587
        cout << "Unable to init SDL: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3588
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3589
    }
89c4a3a6 sago007 2008-08-29 14:32 3590
    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 3591
    
89c4a3a6 sago007 2008-08-29 14:32 3592
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
89c4a3a6 sago007 2008-08-29 14:32 3593
89c4a3a6 sago007 2008-08-29 14:32 3594
    Joypad_init();    //Prepare the joysticks
89c4a3a6 sago007 2008-08-29 14:32 3595
89c4a3a6 sago007 2008-08-29 14:32 3596
    Joypad joypad1 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3597
    Joypad joypad2 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3598
89c4a3a6 sago007 2008-08-29 14:32 3599
    theTextManeger = textManeger();
89c4a3a6 sago007 2008-08-29 14:32 3600
89c4a3a6 sago007 2008-08-29 14:32 3601
    //Open Audio
89c4a3a6 sago007 2008-08-29 14:32 3602
    if (!NoSound) //If sound has not been disabled, then load the sound system
89c4a3a6 sago007 2008-08-29 14:32 3603
        if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
89c4a3a6 sago007 2008-08-29 14:32 3604
        {
89c4a3a6 sago007 2008-08-29 14:32 3605
            cout << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
89c4a3a6 sago007 2008-08-29 14:32 3606
            << "Sound will be disabled!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3607
            NoSound = true; //Tries to stop all sound from playing/loading
89c4a3a6 sago007 2008-08-29 14:32 3608
        }
89c4a3a6 sago007 2008-08-29 14:32 3609
89c4a3a6 sago007 2008-08-29 14:32 3610
    SDL_WM_SetCaption("Block Attack - Rise of the Blocks", NULL); //Sets title line
866417ca sago007 2009-05-10 21:35 3611
    
89c4a3a6 sago007 2008-08-29 14:32 3612
89c4a3a6 sago007 2008-08-29 14:32 3613
    //Copyright notice:
4f1d27f1 sago007 2011-03-18 15:53 3614
    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 3615
    "A SDL based game (see www.libsdl.org)" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3616
    "The game is availeble under the GPL, see COPYING for details." << endl;
89c4a3a6 sago007 2008-08-29 14:32 3617
#if defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3618
    cout << "Windows build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3619
#elif defined(__linux__)
89c4a3a6 sago007 2008-08-29 14:32 3620
    cout << "Linux build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3621
#elif defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3622
    cout << "Unix build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3623
#else
89c4a3a6 sago007 2008-08-29 14:32 3624
    cout << "Alternative build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3625
#endif
89c4a3a6 sago007 2008-08-29 14:32 3626
    cout << "-------------------------------------------" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3627
95bc02ff sago007 2009-03-15 02:46 3628
89c4a3a6 sago007 2008-08-29 14:32 3629
    keySettings[0].up= SDLK_UP;
89c4a3a6 sago007 2008-08-29 14:32 3630
    keySettings[0].down = SDLK_DOWN;
89c4a3a6 sago007 2008-08-29 14:32 3631
    keySettings[0].left = SDLK_LEFT;
89c4a3a6 sago007 2008-08-29 14:32 3632
    keySettings[0].right = SDLK_RIGHT;
6d48320c sago007 2009-03-28 17:06 3633
    keySettings[0].change = SDLK_RCTRL;
6d48320c sago007 2009-03-28 17:06 3634
    keySettings[0].push = SDLK_RSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3635
89c4a3a6 sago007 2008-08-29 14:32 3636
    keySettings[2].up= SDLK_w;
89c4a3a6 sago007 2008-08-29 14:32 3637
    keySettings[2].down = SDLK_s;
89c4a3a6 sago007 2008-08-29 14:32 3638
    keySettings[2].left = SDLK_a;
89c4a3a6 sago007 2008-08-29 14:32 3639
    keySettings[2].right = SDLK_d;
89c4a3a6 sago007 2008-08-29 14:32 3640
    keySettings[2].change = SDLK_LCTRL;
89c4a3a6 sago007 2008-08-29 14:32 3641
    keySettings[2].push = SDLK_LSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3642
89c4a3a6 sago007 2008-08-29 14:32 3643
    player1keys=0;
89c4a3a6 sago007 2008-08-29 14:32 3644
    player2keys=2;
89c4a3a6 sago007 2008-08-29 14:32 3645
89c4a3a6 sago007 2008-08-29 14:32 3646
    strcpy(player1name, "Player 1                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3647
    strcpy(player2name, "Player 2                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3648
769a41a0 sago007 2008-09-24 12:54 3649
    Config *configSettings = Config::getInstance();
769a41a0 sago007 2008-09-24 12:54 3650
    //configSettings->setString("aNumber"," A string");
769a41a0 sago007 2008-09-24 12:54 3651
    //configSettings->save();
769a41a0 sago007 2008-09-24 12:54 3652
    if(configSettings->exists("fullscreen")) //Test if an configFile exists
89c4a3a6 sago007 2008-08-29 14:32 3653
    {
769a41a0 sago007 2008-09-24 12:54 3654
        bFullscreen = (bool)configSettings->getInt("fullscreen");
769a41a0 sago007 2008-09-24 12:54 3655
        MusicEnabled = (bool)configSettings->getInt("musicenabled");
769a41a0 sago007 2008-09-24 12:54 3656
        SoundEnabled = (bool)configSettings->getInt("soundenabled");
769a41a0 sago007 2008-09-24 12:54 3657
        mouseplay1 = (bool)configSettings->getInt("mouseplay1");
769a41a0 sago007 2008-09-24 12:54 3658
        mouseplay2 = (bool)configSettings->getInt("mouseplay2");
769a41a0 sago007 2008-09-24 12:54 3659
        joyplay1 = (bool)configSettings->getInt("joypad1");
769a41a0 sago007 2008-09-24 12:54 3660
        joyplay2 = (bool)configSettings->getInt("joypad2");
769a41a0 sago007 2008-09-24 12:54 3661
        
769a41a0 sago007 2008-09-24 12:54 3662
        if(configSettings->exists("player1keyup")) keySettings[0].up = (SDLKey)configSettings->getInt("player1keyup");
769a41a0 sago007 2008-09-24 12:54 3663
        if(configSettings->exists("player1keydown")) keySettings[0].down = (SDLKey)configSettings->getInt("player1keydown");
769a41a0 sago007 2008-09-24 12:54 3664
        if(configSettings->exists("player1keyleft")) keySettings[0].left = (SDLKey)configSettings->getInt("player1keyleft");
769a41a0 sago007 2008-09-24 12:54 3665
        if(configSettings->exists("player1keyright")) keySettings[0].right = (SDLKey)configSettings->getInt("player1keyright");
769a41a0 sago007 2008-09-24 12:54 3666
        if(configSettings->exists("player1keychange")) keySettings[0].change = (SDLKey)configSettings->getInt("player1keychange");
769a41a0 sago007 2008-09-24 12:54 3667
        if(configSettings->exists("player1keypush")) keySettings[0].push = (SDLKey)configSettings->getInt("player1keypush");
769a41a0 sago007 2008-09-24 12:54 3668
        
769a41a0 sago007 2008-09-24 12:54 3669
        if(configSettings->exists("player2keyup")) keySettings[2].up = (SDLKey)configSettings->getInt("player2keyup");
769a41a0 sago007 2008-09-24 12:54 3670
        if(configSettings->exists("player2keydown")) keySettings[2].down = (SDLKey)configSettings->getInt("player2keydown");
769a41a0 sago007 2008-09-24 12:54 3671
        if(configSettings->exists("player2keyleft")) keySettings[2].left = (SDLKey)configSettings->getInt("player2keyleft");
769a41a0 sago007 2008-09-24 12:54 3672
        if(configSettings->exists("player2keyright")) keySettings[2].right = (SDLKey)configSettings->getInt("player2keyright");
769a41a0 sago007 2008-09-24 12:54 3673
        if(configSettings->exists("player2keychange")) keySettings[2].change = (SDLKey)configSettings->getInt("player2keychange");
769a41a0 sago007 2008-09-24 12:54 3674
        if(configSettings->exists("player2keypush")) keySettings[2].push = (SDLKey)configSettings->getInt("player2keypush");
769a41a0 sago007 2008-09-24 12:54 3675
        if(configSettings->exists("player1name"))
769a41a0 sago007 2008-09-24 12:54 3676
            strncpy(player1name,(configSettings->getString("player1name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3677
        if(configSettings->exists("player2name"))
769a41a0 sago007 2008-09-24 12:54 3678
            strncpy(player2name,(configSettings->getString("player2name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3679
        cout << "Data loaded from config file" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3680
    }
89c4a3a6 sago007 2008-08-29 14:32 3681
    else
89c4a3a6 sago007 2008-08-29 14:32 3682
    {
769a41a0 sago007 2008-09-24 12:54 3683
        //Reads options from file:
769a41a0 sago007 2008-09-24 12:54 3684
        ifstream optionsFile(optionsPath.c_str(), ios::binary);
769a41a0 sago007 2008-09-24 12:54 3685
        if (optionsFile)
769a41a0 sago007 2008-09-24 12:54 3686
        {
769a41a0 sago007 2008-09-24 12:54 3687
            //reads data: xsize,ysize,fullescreen, player1keys, player2keys, MusicEnabled, SoundEnabled,player1name,player2name
769a41a0 sago007 2008-09-24 12:54 3688
            optionsFile.read(reinterpret_cast<char*>(&xsize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3689
            optionsFile.read(reinterpret_cast<char*>(&ysize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3690
            optionsFile.read(reinterpret_cast<char*>(&bFullscreen), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3691
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3692
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3693
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3694
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3695
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3696
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3697
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3698
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3699
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3700
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3701
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3702
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3703
            optionsFile.read(reinterpret_cast<char*>(&MusicEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3704
            optionsFile.read(reinterpret_cast<char*>(&SoundEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3705
            optionsFile.read(player1name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3706
            optionsFile.read(player2name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3707
            //mouseplay?
769a41a0 sago007 2008-09-24 12:54 3708
            if (!optionsFile.eof())
769a41a0 sago007 2008-09-24 12:54 3709
            {
769a41a0 sago007 2008-09-24 12:54 3710
                optionsFile.read(reinterpret_cast<char*>(&mouseplay1), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3711
                optionsFile.read(reinterpret_cast<char*>(&mouseplay2), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3712
                optionsFile.read(reinterpret_cast<char*>(&joyplay1),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3713
                optionsFile.read(reinterpret_cast<char*>(&joyplay2),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3714
            }
769a41a0 sago007 2008-09-24 12:54 3715
            optionsFile.close();
769a41a0 sago007 2008-09-24 12:54 3716
            cout << "Data loaded from oldstyle options file" << endl;
769a41a0 sago007 2008-09-24 12:54 3717
        }
769a41a0 sago007 2008-09-24 12:54 3718
        else
769a41a0 sago007 2008-09-24 12:54 3719
        {
769a41a0 sago007 2008-09-24 12:54 3720
            cout << "Unable to load options file, using default values" << endl;
769a41a0 sago007 2008-09-24 12:54 3721
        }
89c4a3a6 sago007 2008-08-29 14:32 3722
    }
27ae0175 sago007 2009-01-30 06:02 3723
    
27ae0175 sago007 2009-01-30 06:02 3724
#if NETWORK
27ae0175 sago007 2009-01-30 06:02 3725
    strcpy(serverAddress, "192.168.0.2                 \0");
27ae0175 sago007 2009-01-30 06:02 3726
    if(configSettings->exists("address0"))
27ae0175 sago007 2009-01-30 06:02 3727
    {
27ae0175 sago007 2009-01-30 06:02 3728
        strcpy(serverAddress, "                            \0");
27ae0175 sago007 2009-01-30 06:02 3729
        strncpy(serverAddress,configSettings->getString("address0").c_str(),sizeof(serverAddress)-1);
27ae0175 sago007 2009-01-30 06:02 3730
    }
27ae0175 sago007 2009-01-30 06:02 3731
#endif
89c4a3a6 sago007 2008-08-29 14:32 3732
89c4a3a6 sago007 2008-08-29 14:32 3733
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3734
    {
89c4a3a6 sago007 2008-08-29 14:32 3735
        xsize=300;
89c4a3a6 sago007 2008-08-29 14:32 3736
        ysize=600;
89c4a3a6 sago007 2008-08-29 14:32 3737
    }
89c4a3a6 sago007 2008-08-29 14:32 3738
    
89c4a3a6 sago007 2008-08-29 14:32 3739
    
89c4a3a6 sago007 2008-08-29 14:32 3740
    //Open video
89c4a3a6 sago007 2008-08-29 14:32 3741
    if ((bFullscreen)&&(!singlePuzzle)) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3742
    else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3743
89c4a3a6 sago007 2008-08-29 14:32 3744
    if ( screen == NULL )
89c4a3a6 sago007 2008-08-29 14:32 3745
    {
89c4a3a6 sago007 2008-08-29 14:32 3746
        cout << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3747
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3748
    }
89c4a3a6 sago007 2008-08-29 14:32 3749
866417ca sago007 2009-05-10 21:35 3750
    //Init the file system abstraction layer
866417ca sago007 2009-05-10 21:35 3751
    PHYSFS_init(argv[0]);
866417ca sago007 2009-05-10 21:35 3752
    //Load default theme
2e57d791 sago007 2009-06-04 17:48 3753
    loadTheme(Config::getInstance()->getString("themename"));
866417ca sago007 2009-05-10 21:35 3754
    //Now sets the icon:
1f61db96 sago007 2010-11-15 20:12 3755
    SDL_Surface *icon = IMG_Load2("gfx/icon.png");
866417ca sago007 2009-05-10 21:35 3756
    SDL_WM_SetIcon(icon,NULL);
89c4a3a6 sago007 2008-08-29 14:32 3757
89c4a3a6 sago007 2008-08-29 14:32 3758
    cout << "Images loaded" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3759
78d03b38 sago007 2008-11-13 19:56 3760
    //InitMenues();
89c4a3a6 sago007 2008-08-29 14:32 3761
6b1dc7a6 sago007 2010-11-08 21:03 3762
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
6b1dc7a6 sago007 2010-11-08 21:03 3763
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
30f910dd sago007 2010-11-10 21:02 3764
    player1 = &theGame;
30f910dd sago007 2010-11-10 21:02 3765
    player2 = &theGame2;
e1290bdf sago007 2010-10-25 19:56 3766
    /*if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3767
    {
e1290bdf sago007 2010-10-25 19:56 3768
        theGame.GetTopY()=0;
e1290bdf sago007 2010-10-25 19:56 3769
        theGame.GetTopX()=0;
e1290bdf sago007 2010-10-25 19:56 3770
        theGame2.GetTopY()=10000;
e1290bdf sago007 2010-10-25 19:56 3771
        theGame2.GetTopX()=10000;
e1290bdf sago007 2010-10-25 19:56 3772
    }*/
89c4a3a6 sago007 2008-08-29 14:32 3773
    theGame.DoPaintJob();			//Makes sure what there is something to paint
89c4a3a6 sago007 2008-08-29 14:32 3774
    theGame2.DoPaintJob();
89c4a3a6 sago007 2008-08-29 14:32 3775
    theGame.SetGameOver();		//sets the game over in the beginning
89c4a3a6 sago007 2008-08-29 14:32 3776
    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 3777
89c4a3a6 sago007 2008-08-29 14:32 3778
89c4a3a6 sago007 2008-08-29 14:32 3779
    //Takes names from file instead
89c4a3a6 sago007 2008-08-29 14:32 3780
    strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 3781
    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 3782
89c4a3a6 sago007 2008-08-29 14:32 3783
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3784
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3785
89c4a3a6 sago007 2008-08-29 14:32 3786
1572de2b sago007 2008-09-11 18:15 3787
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3788
    NetworkThing nt = NetworkThing();
89c4a3a6 sago007 2008-08-29 14:32 3789
    nt.setBGpointers(&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3790
#endif
89c4a3a6 sago007 2008-08-29 14:32 3791
89c4a3a6 sago007 2008-08-29 14:32 3792
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3793
    {
89c4a3a6 sago007 2008-08-29 14:32 3794
        LoadPuzzleStages();
e1290bdf sago007 2010-10-25 19:56 3795
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3796
        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 3797
        vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3798
    }
89c4a3a6 sago007 2008-08-29 14:32 3799
    //Draws everything to screen
89c4a3a6 sago007 2008-08-29 14:32 3800
    if (!editorMode)
e1290bdf sago007 2010-10-25 19:56 3801
        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3802
    else
e1290bdf sago007 2010-10-25 19:56 3803
        MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 3804
    DrawIMG(background, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 3805
    DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3806
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3807
    //game loop
89c4a3a6 sago007 2008-08-29 14:32 3808
    int done = 0;
89c4a3a6 sago007 2008-08-29 14:32 3809
    cout << "Starting game loop" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3810
    while (done == 0)
89c4a3a6 sago007 2008-08-29 14:32 3811
    {
89c4a3a6 sago007 2008-08-29 14:32 3812
        if (!(highPriority)) SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3813
89c4a3a6 sago007 2008-08-29 14:32 3814
        if ((standardBackground)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3815
        {
e1290bdf sago007 2010-10-25 19:56 3816
            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3817
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3818
        }
89c4a3a6 sago007 2008-08-29 14:32 3819
89c4a3a6 sago007 2008-08-29 14:32 3820
        if ((standardBackground)&&(editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3821
        {
89c4a3a6 sago007 2008-08-29 14:32 3822
            DrawIMG(backgroundImage, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 3823
            MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 3824
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3825
        }
89c4a3a6 sago007 2008-08-29 14:32 3826
89c4a3a6 sago007 2008-08-29 14:32 3827
        //updates the balls and explosions:
89c4a3a6 sago007 2008-08-29 14:32 3828
        theBallManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3829
        theExplosionManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3830
        theTextManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3831
1572de2b sago007 2008-09-11 18:15 3832
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3833
        if (nt.isConnected())
89c4a3a6 sago007 2008-08-29 14:32 3834
        {
89c4a3a6 sago007 2008-08-29 14:32 3835
            nt.updateNetwork();
89c4a3a6 sago007 2008-08-29 14:32 3836
            networkActive = true;
89c4a3a6 sago007 2008-08-29 14:32 3837
            if (!nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 3838
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3839
        }
89c4a3a6 sago007 2008-08-29 14:32 3840
        else
89c4a3a6 sago007 2008-08-29 14:32 3841
            networkActive = false;
89c4a3a6 sago007 2008-08-29 14:32 3842
        if (nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 3843
        {
89c4a3a6 sago007 2008-08-29 14:32 3844
            networkPlay=true;
89c4a3a6 sago007 2008-08-29 14:32 3845
            if (!weWhereConnected) //We have just connected
89c4a3a6 sago007 2008-08-29 14:32 3846
            {
e1290bdf sago007 2010-10-25 19:56 3847
                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3848
                theGame.putStartBlocks(nt.theSeed);
e1290bdf sago007 2010-10-25 19:56 3849
                theGame2.playNetwork(xsize-500,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3850
                nt.theGameHasStarted();
89c4a3a6 sago007 2008-08-29 14:32 3851
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3852
            }
89c4a3a6 sago007 2008-08-29 14:32 3853
            weWhereConnected = true;
89c4a3a6 sago007 2008-08-29 14:32 3854
        }
89c4a3a6 sago007 2008-08-29 14:32 3855
        else
89c4a3a6 sago007 2008-08-29 14:32 3856
        {
89c4a3a6 sago007 2008-08-29 14:32 3857
            networkPlay=false;
89c4a3a6 sago007 2008-08-29 14:32 3858
            weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3859
        }
89c4a3a6 sago007 2008-08-29 14:32 3860
#endif
89c4a3a6 sago007 2008-08-29 14:32 3861
89c4a3a6 sago007 2008-08-29 14:32 3862
        if (!bScreenLocked)
89c4a3a6 sago007 2008-08-29 14:32 3863
        {
89c4a3a6 sago007 2008-08-29 14:32 3864
            SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3865
89c4a3a6 sago007 2008-08-29 14:32 3866
            while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3867
            {
89c4a3a6 sago007 2008-08-29 14:32 3868
                if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 3869
                    done = 1;
89c4a3a6 sago007 2008-08-29 14:32 3870
                }
89c4a3a6 sago007 2008-08-29 14:32 3871
89c4a3a6 sago007 2008-08-29 14:32 3872
                if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3873
                {
89c4a3a6 sago007 2008-08-29 14:32 3874
                    if ( event.key.keysym.sym == SDLK_ESCAPE )
89c4a3a6 sago007 2008-08-29 14:32 3875
                    {
89c4a3a6 sago007 2008-08-29 14:32 3876
                            if (showOptions)
89c4a3a6 sago007 2008-08-29 14:32 3877
                            {
89c4a3a6 sago007 2008-08-29 14:32 3878
                                showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3879
                            }
89c4a3a6 sago007 2008-08-29 14:32 3880
                            else
89c4a3a6 sago007 2008-08-29 14:32 3881
                                done=1;
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
                    }
e1290bdf sago007 2010-10-25 19:56 3885
                    if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled()))
89c4a3a6 sago007 2008-08-29 14:32 3886
                    {
89c4a3a6 sago007 2008-08-29 14:32 3887
                        //player1:
89c4a3a6 sago007 2008-08-29 14:32 3888
                        if ( event.key.keysym.sym == keySettings[player1keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 3889
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 3890
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3891
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3892
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 3893
                        }
89c4a3a6 sago007 2008-08-29 14:32 3894
                        if ( event.key.keysym.sym == keySettings[player1keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 3895
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 3896
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3897
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3898
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 3899
                        }
89c4a3a6 sago007 2008-08-29 14:32 3900
                        if ( (event.key.keysym.sym == keySettings[player1keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3901
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 3902
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3903
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3904
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 3905
                        }
89c4a3a6 sago007 2008-08-29 14:32 3906
                        if ( (event.key.keysym.sym == keySettings[player1keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3907
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 3908
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3909
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3910
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 3911
                        }
89c4a3a6 sago007 2008-08-29 14:32 3912
                        if ( event.key.keysym.sym == keySettings[player1keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 3913
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 3914
                        }
89c4a3a6 sago007 2008-08-29 14:32 3915
                        if ( event.key.keysym.sym == keySettings[player1keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 3916
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 3917
                        }
89c4a3a6 sago007 2008-08-29 14:32 3918
                    }
e1290bdf sago007 2010-10-25 19:56 3919
                    if (!editorMode && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 3920
                    {
89c4a3a6 sago007 2008-08-29 14:32 3921
                        //player2:
89c4a3a6 sago007 2008-08-29 14:32 3922
                        if ( event.key.keysym.sym == keySettings[player2keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 3923
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 3924
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3925
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3926
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 3927
                        }
89c4a3a6 sago007 2008-08-29 14:32 3928
                        if ( event.key.keysym.sym == keySettings[player2keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 3929
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 3930
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3931
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3932
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 3933
                        }
89c4a3a6 sago007 2008-08-29 14:32 3934
                        if ( (event.key.keysym.sym == keySettings[player2keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3935
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 3936
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3937
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3938
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 3939
                        }
89c4a3a6 sago007 2008-08-29 14:32 3940
                        if ( (event.key.keysym.sym == keySettings[player2keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3941
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 3942
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3943
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3944
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 3945
                        }
89c4a3a6 sago007 2008-08-29 14:32 3946
                        if ( event.key.keysym.sym == keySettings[player2keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 3947
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 3948
                        }
89c4a3a6 sago007 2008-08-29 14:32 3949
                        if ( event.key.keysym.sym == keySettings[player2keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 3950
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 3951
                        }
89c4a3a6 sago007 2008-08-29 14:32 3952
                    }
89c4a3a6 sago007 2008-08-29 14:32 3953
                    //common:
89c4a3a6 sago007 2008-08-29 14:32 3954
                    if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3955
                    {
89c4a3a6 sago007 2008-08-29 14:32 3956
                        if ( event.key.keysym.sym == SDLK_F2 ) {
2f30c381 sago007 2008-09-14 13:08 3957
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3958
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 3959
                            #else
47529580 sago007 2008-12-09 02:34 3960
                            if ((!showOptions)){
2f30c381 sago007 2008-09-14 13:08 3961
                            #endif
30f910dd sago007 2010-11-10 21:02 3962
                                StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 3963
                            }}
89c4a3a6 sago007 2008-08-29 14:32 3964
                        if ( event.key.keysym.sym == SDLK_F3 ) {
2f30c381 sago007 2008-09-14 13:08 3965
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3966
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 3967
                            #else
47529580 sago007 2008-12-09 02:34 3968
                            if ((!showOptions)){    
2f30c381 sago007 2008-09-14 13:08 3969
                            #endif
4f1d27f1 sago007 2011-03-18 15:53 3970
                                StartSinglePlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 3971
                            }}
89c4a3a6 sago007 2008-08-29 14:32 3972
                        if ( event.key.keysym.sym == SDLK_F5 )
89c4a3a6 sago007 2008-08-29 14:32 3973
                        {
2f30c381 sago007 2008-09-14 13:08 3974
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3975
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 3976
                            #else
47529580 sago007 2008-12-09 02:34 3977
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 3978
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 3979
                            {
89c4a3a6 sago007 2008-08-29 14:32 3980
                                int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 3981
                                theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 3982
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3983
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3984
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 3985
                                twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 3986
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 3987
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 3988
                                vsMode = false;
c96f480e sago007 2009-03-28 18:59 3989
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 3990
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 3991
                            }
89c4a3a6 sago007 2008-08-29 14:32 3992
                        }
89c4a3a6 sago007 2008-08-29 14:32 3993
                        if ( event.key.keysym.sym == SDLK_F6 )
89c4a3a6 sago007 2008-08-29 14:32 3994
                        {
2f30c381 sago007 2008-09-14 13:08 3995
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3996
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 3997
                            #else
47529580 sago007 2008-12-09 02:34 3998
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 3999
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4000
                            {
4f1d27f1 sago007 2011-03-18 15:53 4001
                                StartTwoPlayerVs();
89c4a3a6 sago007 2008-08-29 14:32 4002
                            }
89c4a3a6 sago007 2008-08-29 14:32 4003
                        }
89c4a3a6 sago007 2008-08-29 14:32 4004
                        if ( event.key.keysym.sym == SDLK_F4 )
89c4a3a6 sago007 2008-08-29 14:32 4005
                        {
2f30c381 sago007 2008-09-14 13:08 4006
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4007
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4008
                            #else
47529580 sago007 2008-12-09 02:34 4009
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4010
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4011
                            {
4f1d27f1 sago007 2011-03-18 15:53 4012
                                StarTwoPlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4013
                            }
89c4a3a6 sago007 2008-08-29 14:32 4014
                        }
89c4a3a6 sago007 2008-08-29 14:32 4015
                        if ( event.key.keysym.sym == SDLK_F7 )
89c4a3a6 sago007 2008-08-29 14:32 4016
                        {
2f30c381 sago007 2008-09-14 13:08 4017
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4018
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4019
                            #else
47529580 sago007 2008-12-09 02:34 4020
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4021
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4022
                            {
89c4a3a6 sago007 2008-08-29 14:32 4023
                                int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4024
                                theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4025
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4026
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4027
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4028
                                twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4029
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4030
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4031
                                vsMode = true;
c96f480e sago007 2009-03-28 18:59 4032
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4033
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4034
                            }
89c4a3a6 sago007 2008-08-29 14:32 4035
                        }
89c4a3a6 sago007 2008-08-29 14:32 4036
                        if ( event.key.keysym.sym == SDLK_F8 )
89c4a3a6 sago007 2008-08-29 14:32 4037
                        {
89c4a3a6 sago007 2008-08-29 14:32 4038
                        }
89c4a3a6 sago007 2008-08-29 14:32 4039
                        if ( event.key.keysym.sym == SDLK_F9 ) {
89c4a3a6 sago007 2008-08-29 14:32 4040
                            writeScreenShot();
89c4a3a6 sago007 2008-08-29 14:32 4041
                        }
89c4a3a6 sago007 2008-08-29 14:32 4042
                        if ( event.key.keysym.sym == SDLK_F11 ) {
89c4a3a6 sago007 2008-08-29 14:32 4043
                            /*This is the test place, place function to test here*/
89c4a3a6 sago007 2008-08-29 14:32 4044
89c4a3a6 sago007 2008-08-29 14:32 4045
                            //theGame.CreateGreyGarbage();
78d03b38 sago007 2008-11-13 19:56 4046
                            //char mitNavn[30];
78d03b38 sago007 2008-11-13 19:56 4047
                            //SelectThemeDialogbox(300,400,mitNavn);
b7590374 sago007 2011-05-19 16:15 4048
                           MainMenu();
b7590374 sago007 2011-05-19 16:15 4049
                            //OpenScoresDisplay();
89c4a3a6 sago007 2008-08-29 14:32 4050
                        } //F11
89c4a3a6 sago007 2008-08-29 14:32 4051
                    }
89c4a3a6 sago007 2008-08-29 14:32 4052
                    if ( event.key.keysym.sym == SDLK_F12 ) {
89c4a3a6 sago007 2008-08-29 14:32 4053
                        done=1;
89c4a3a6 sago007 2008-08-29 14:32 4054
                    }
89c4a3a6 sago007 2008-08-29 14:32 4055
                }
89c4a3a6 sago007 2008-08-29 14:32 4056
            } //while event PollEvent - read keys
89c4a3a6 sago007 2008-08-29 14:32 4057
89c4a3a6 sago007 2008-08-29 14:32 4058
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4059
            **************************** Repeating start **************************
89c4a3a6 sago007 2008-08-29 14:32 4060
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4061
89c4a3a6 sago007 2008-08-29 14:32 4062
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4063
//Also the joysticks:
89c4a3a6 sago007 2008-08-29 14:32 4064
//Repeating not implemented
89c4a3a6 sago007 2008-08-29 14:32 4065
89c4a3a6 sago007 2008-08-29 14:32 4066
//Player 1 start
89c4a3a6 sago007 2008-08-29 14:32 4067
            if (!(keys[keySettings[player1keys].up]))
30f910dd sago007 2010-11-10 21:02 4068
                repeatingN[0]=false;
30f910dd sago007 2010-11-10 21:02 4069
            while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4070
            {
89c4a3a6 sago007 2008-08-29 14:32 4071
                theGame.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4072
                timesRepeatedP1N++;
89c4a3a6 sago007 2008-08-29 14:32 4073
            }
89c4a3a6 sago007 2008-08-29 14:32 4074
89c4a3a6 sago007 2008-08-29 14:32 4075
            if (!(keys[keySettings[player1keys].down]))
30f910dd sago007 2010-11-10 21:02 4076
                repeatingS[0]=false;
30f910dd sago007 2010-11-10 21:02 4077
            while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4078
            {
89c4a3a6 sago007 2008-08-29 14:32 4079
                theGame.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4080
                timesRepeatedP1S++;
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 (!(keys[keySettings[player1keys].left]))
30f910dd sago007 2010-11-10 21:02 4084
                repeatingW[0]=false;
30f910dd sago007 2010-11-10 21:02 4085
            while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4086
            {
89c4a3a6 sago007 2008-08-29 14:32 4087
                timesRepeatedP1W++;
89c4a3a6 sago007 2008-08-29 14:32 4088
                theGame.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4089
            }
89c4a3a6 sago007 2008-08-29 14:32 4090
89c4a3a6 sago007 2008-08-29 14:32 4091
            if (!(keys[keySettings[player1keys].right]))
30f910dd sago007 2010-11-10 21:02 4092
                repeatingE[0]=false;
30f910dd sago007 2010-11-10 21:02 4093
            while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4094
            {
89c4a3a6 sago007 2008-08-29 14:32 4095
                timesRepeatedP1E++;
89c4a3a6 sago007 2008-08-29 14:32 4096
                theGame.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4097
            }
89c4a3a6 sago007 2008-08-29 14:32 4098
89c4a3a6 sago007 2008-08-29 14:32 4099
//Player 1 end
89c4a3a6 sago007 2008-08-29 14:32 4100
89c4a3a6 sago007 2008-08-29 14:32 4101
//Player 2 start
89c4a3a6 sago007 2008-08-29 14:32 4102
            if (!(keys[keySettings[player2keys].up]))
30f910dd sago007 2010-11-10 21:02 4103
                repeatingN[1]=false;
30f910dd sago007 2010-11-10 21:02 4104
            while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4105
            {
89c4a3a6 sago007 2008-08-29 14:32 4106
                theGame2.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4107
                timesRepeatedP2N++;
89c4a3a6 sago007 2008-08-29 14:32 4108
            }
89c4a3a6 sago007 2008-08-29 14:32 4109
89c4a3a6 sago007 2008-08-29 14:32 4110
            if (!(keys[keySettings[player2keys].down]))
30f910dd sago007 2010-11-10 21:02 4111
                repeatingS[1]=false;
30f910dd sago007 2010-11-10 21:02 4112
            while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4113
            {
89c4a3a6 sago007 2008-08-29 14:32 4114
                theGame2.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4115
                timesRepeatedP2S++;
89c4a3a6 sago007 2008-08-29 14:32 4116
            }
89c4a3a6 sago007 2008-08-29 14:32 4117
89c4a3a6 sago007 2008-08-29 14:32 4118
            if (!(keys[keySettings[player2keys].left]))
30f910dd sago007 2010-11-10 21:02 4119
                repeatingW[1]=false;
30f910dd sago007 2010-11-10 21:02 4120
            while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4121
            {
89c4a3a6 sago007 2008-08-29 14:32 4122
                theGame2.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4123
                timesRepeatedP2W++;
89c4a3a6 sago007 2008-08-29 14:32 4124
            }
89c4a3a6 sago007 2008-08-29 14:32 4125
89c4a3a6 sago007 2008-08-29 14:32 4126
            if (!(keys[keySettings[player2keys].right]))
30f910dd sago007 2010-11-10 21:02 4127
                repeatingE[1]=false;
30f910dd sago007 2010-11-10 21:02 4128
            while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4129
            {
89c4a3a6 sago007 2008-08-29 14:32 4130
                theGame2.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4131
                timesRepeatedP2E++;
89c4a3a6 sago007 2008-08-29 14:32 4132
            }
89c4a3a6 sago007 2008-08-29 14:32 4133
89c4a3a6 sago007 2008-08-29 14:32 4134
//Player 2 end
89c4a3a6 sago007 2008-08-29 14:32 4135
89c4a3a6 sago007 2008-08-29 14:32 4136
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4137
            **************************** Repeating end ****************************
89c4a3a6 sago007 2008-08-29 14:32 4138
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4139
89c4a3a6 sago007 2008-08-29 14:32 4140
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4141
            ***************************** Joypad start ****************************
89c4a3a6 sago007 2008-08-29 14:32 4142
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4143
6d48320c sago007 2009-03-28 17:06 4144
            //Gameplay
89c4a3a6 sago007 2008-08-29 14:32 4145
            if (joyplay1||joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4146
            {
e1290bdf sago007 2010-10-25 19:56 4147
                if (joypad1.working && !theGame.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4148
                    if (joyplay1)
89c4a3a6 sago007 2008-08-29 14:32 4149
                    {
89c4a3a6 sago007 2008-08-29 14:32 4150
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4151
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4152
                        {
89c4a3a6 sago007 2008-08-29 14:32 4153
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4154
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4155
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4156
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4157
                        }
89c4a3a6 sago007 2008-08-29 14:32 4158
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4159
                        {
89c4a3a6 sago007 2008-08-29 14:32 4160
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4161
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4162
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4163
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4164
                        }
89c4a3a6 sago007 2008-08-29 14:32 4165
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4166
                        {
89c4a3a6 sago007 2008-08-29 14:32 4167
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4168
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4169
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4170
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4171
                        }
89c4a3a6 sago007 2008-08-29 14:32 4172
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4173
                        {
89c4a3a6 sago007 2008-08-29 14:32 4174
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4175
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4176
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4177
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4178
                        }
89c4a3a6 sago007 2008-08-29 14:32 4179
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4180
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4181
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4182
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4183
                    }
89c4a3a6 sago007 2008-08-29 14:32 4184
                    else
89c4a3a6 sago007 2008-08-29 14:32 4185
                    {
89c4a3a6 sago007 2008-08-29 14:32 4186
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4187
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4188
                        {
89c4a3a6 sago007 2008-08-29 14:32 4189
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4190
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4191
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4192
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4193
                        }
89c4a3a6 sago007 2008-08-29 14:32 4194
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4195
                        {
89c4a3a6 sago007 2008-08-29 14:32 4196
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4197
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4198
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4199
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4200
                        }
89c4a3a6 sago007 2008-08-29 14:32 4201
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4202
                        {
89c4a3a6 sago007 2008-08-29 14:32 4203
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4204
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4205
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4206
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4207
                        }
89c4a3a6 sago007 2008-08-29 14:32 4208
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4209
                        {
89c4a3a6 sago007 2008-08-29 14:32 4210
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4211
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4212
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4213
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4214
                        }
89c4a3a6 sago007 2008-08-29 14:32 4215
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4216
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4217
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4218
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4219
                    }
e1290bdf sago007 2010-10-25 19:56 4220
                if (joypad2.working && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4221
                    if (!joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4222
                    {
89c4a3a6 sago007 2008-08-29 14:32 4223
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4224
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4225
                        {
89c4a3a6 sago007 2008-08-29 14:32 4226
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4227
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4228
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4229
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4230
                        }
89c4a3a6 sago007 2008-08-29 14:32 4231
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4232
                        {
89c4a3a6 sago007 2008-08-29 14:32 4233
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4234
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4235
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4236
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4237
                        }
89c4a3a6 sago007 2008-08-29 14:32 4238
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4239
                        {
89c4a3a6 sago007 2008-08-29 14:32 4240
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4241
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4242
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4243
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4244
                        }
89c4a3a6 sago007 2008-08-29 14:32 4245
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4246
                        {
89c4a3a6 sago007 2008-08-29 14:32 4247
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4248
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4249
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4250
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4251
                        }
89c4a3a6 sago007 2008-08-29 14:32 4252
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4253
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4254
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4255
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4256
                    }
89c4a3a6 sago007 2008-08-29 14:32 4257
                    else
89c4a3a6 sago007 2008-08-29 14:32 4258
                    {
89c4a3a6 sago007 2008-08-29 14:32 4259
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4260
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4261
                        {
89c4a3a6 sago007 2008-08-29 14:32 4262
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4263
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4264
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4265
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4266
                        }
89c4a3a6 sago007 2008-08-29 14:32 4267
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4268
                        {
89c4a3a6 sago007 2008-08-29 14:32 4269
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4270
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4271
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4272
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4273
                        }
89c4a3a6 sago007 2008-08-29 14:32 4274
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4275
                        {
89c4a3a6 sago007 2008-08-29 14:32 4276
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4277
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4278
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4279
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4280
                        }
89c4a3a6 sago007 2008-08-29 14:32 4281
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4282
                        {
89c4a3a6 sago007 2008-08-29 14:32 4283
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4284
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4285
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4286
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4287
                        }
89c4a3a6 sago007 2008-08-29 14:32 4288
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4289
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4290
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4291
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4292
                    }
89c4a3a6 sago007 2008-08-29 14:32 4293
            }
89c4a3a6 sago007 2008-08-29 14:32 4294
89c4a3a6 sago007 2008-08-29 14:32 4295
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4296
            ***************************** Joypad end ******************************
89c4a3a6 sago007 2008-08-29 14:32 4297
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4298
89c4a3a6 sago007 2008-08-29 14:32 4299
89c4a3a6 sago007 2008-08-29 14:32 4300
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4301
b7590374 sago007 2011-05-19 16:15 4302
            SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 4303
89c4a3a6 sago007 2008-08-29 14:32 4304
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4305
            **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4306
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4307
e1290bdf sago007 2010-10-25 19:56 4308
            if ((mouseplay1)&&((!editorMode)&&(!theGame.GetAIenabled())||(editorModeTest))) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4309
                if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4310
                {
89c4a3a6 sago007 2008-08-29 14:32 4311
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4312
                    yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4313
                    xLine = (mousex-50+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4314
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4315
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4316
                    if ((yLine>10)&&(theGame.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4317
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4318
                    if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4319
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4320
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4321
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4322
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4323
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4324
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4325
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4326
                    theGame.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4327
                }
89c4a3a6 sago007 2008-08-29 14:32 4328
e1290bdf sago007 2010-10-25 19:56 4329
            if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4330
                if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4331
                {
89c4a3a6 sago007 2008-08-29 14:32 4332
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4333
                    yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4334
                    xLine = (mousex-(xsize-500)+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4335
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4336
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4337
                    if ((yLine>10)&&(theGame2.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4338
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4339
                    if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4340
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4341
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4342
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4343
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4344
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4345
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4346
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4347
                    theGame2.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4348
                }
89c4a3a6 sago007 2008-08-29 14:32 4349
89c4a3a6 sago007 2008-08-29 14:32 4350
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4351
            **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4352
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4353
89c4a3a6 sago007 2008-08-29 14:32 4354
            // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 4355
            if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 4356
            {
89c4a3a6 sago007 2008-08-29 14:32 4357
                bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 4358
            }
89c4a3a6 sago007 2008-08-29 14:32 4359
89c4a3a6 sago007 2008-08-29 14:32 4360
            // If the mouse button 2 is released, make bMouseUp2 equal true
89c4a3a6 sago007 2008-08-29 14:32 4361
            if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3))
89c4a3a6 sago007 2008-08-29 14:32 4362
            {
89c4a3a6 sago007 2008-08-29 14:32 4363
                bMouseUp2=true;
89c4a3a6 sago007 2008-08-29 14:32 4364
            }
89c4a3a6 sago007 2008-08-29 14:32 4365
89c4a3a6 sago007 2008-08-29 14:32 4366
            if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 4367
            {
89c4a3a6 sago007 2008-08-29 14:32 4368
                //read mouse events
89c4a3a6 sago007 2008-08-29 14:32 4369
                if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 4370
                {
89c4a3a6 sago007 2008-08-29 14:32 4371
                    bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 4372
                    DrawIMG(background, screen, 0, 0);
2f30c381 sago007 2008-09-14 13:08 4373
                    #if NETWORK
2f30c381 sago007 2008-09-14 13:08 4374
                    //Nothing
2f30c381 sago007 2008-09-14 13:08 4375
                    #else
2f30c381 sago007 2008-09-14 13:08 4376
                    bool networkActive=false;
2f30c381 sago007 2008-09-14 13:08 4377
                    #endif
9050a50a sago007 2008-12-09 13:35 4378
                    if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4379
                    {
89c4a3a6 sago007 2008-08-29 14:32 4380
                        //New game clicked
89c4a3a6 sago007 2008-08-29 14:32 4381
                        bool state = (!bNewGameOpen);
89c4a3a6 sago007 2008-08-29 14:32 4382
                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4383
                        bNewGameOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4384
                        showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4385
                    }
89c4a3a6 sago007 2008-08-29 14:32 4386
                    else
1572de2b sago007 2008-09-11 18:15 4387
#if NETWORK
9050a50a sago007 2008-12-09 13:35 4388
                        if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4389
                        {
89c4a3a6 sago007 2008-08-29 14:32 4390
                            //Disconnect clicked!
89c4a3a6 sago007 2008-08-29 14:32 4391
                            cout << "Disconnect clicked!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4392
                            nt.ntDisconnect();
89c4a3a6 sago007 2008-08-29 14:32 4393
                        }
89c4a3a6 sago007 2008-08-29 14:32 4394
                        else
89c4a3a6 sago007 2008-08-29 14:32 4395
#endif
9050a50a sago007 2008-12-09 13:35 4396
                            if ((0<mousex) && (mousex<buttonXsize) && (40<mousey) && (mousey<80) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4397
                            {
89c4a3a6 sago007 2008-08-29 14:32 4398
                                //1player
89c4a3a6 sago007 2008-08-29 14:32 4399
                                b1playerOpen = (!b1playerOpen);
89c4a3a6 sago007 2008-08-29 14:32 4400
                                b2playersOpen = false;
1572de2b sago007 2008-09-11 18:15 4401
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4402
                                bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4403
#endif
89c4a3a6 sago007 2008-08-29 14:32 4404
                            }
89c4a3a6 sago007 2008-08-29 14:32 4405
                            else
9050a50a sago007 2008-12-09 13:35 4406
                                if ((0<mousex) && (mousex<buttonXsize) && (80<mousey) && (mousey<120) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4407
                                {
89c4a3a6 sago007 2008-08-29 14:32 4408
                                    //2player
89c4a3a6 sago007 2008-08-29 14:32 4409
                                    b2playersOpen = (!b2playersOpen);
89c4a3a6 sago007 2008-08-29 14:32 4410
                                    b1playerOpen = false;
1572de2b sago007 2008-09-11 18:15 4411
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4412
                                    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4413
#endif
89c4a3a6 sago007 2008-08-29 14:32 4414
                                }
1572de2b sago007 2008-09-11 18:15 4415
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4416
                                else
9050a50a sago007 2008-12-09 13:35 4417
                                    if ((0<mousex) && (mousex<buttonXsize) && (120<mousey) && (mousey<160) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4418
                                    {
89c4a3a6 sago007 2008-08-29 14:32 4419
                                        //Network
89c4a3a6 sago007 2008-08-29 14:32 4420
                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4421
                                        b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4422
                                        bNetworkOpen = (!bNetworkOpen);
89c4a3a6 sago007 2008-08-29 14:32 4423
                                    }
89c4a3a6 sago007 2008-08-29 14:32 4424
#endif
89c4a3a6 sago007 2008-08-29 14:32 4425
                                    else
9050a50a sago007 2008-12-09 13:35 4426
                                        if ((buttonXsize<mousex) && (mousex<240) && (40<mousey) && (mousey<80) && (b1playerOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4427
                                        {
30f910dd sago007 2010-11-10 21:02 4428
                                            StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 4429
                                        }
89c4a3a6 sago007 2008-08-29 14:32 4430
                                        else
9050a50a sago007 2008-12-09 13:35 4431
                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b1playerOpen) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4432
                                            {
4f1d27f1 sago007 2011-03-18 15:53 4433
                                                StartSinglePlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4434
                                            }
89c4a3a6 sago007 2008-08-29 14:32 4435
                                            else
9050a50a sago007 2008-12-09 13:35 4436
                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b1playerOpen)&&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4437
                                                {
89c4a3a6 sago007 2008-08-29 14:32 4438
                                                    //1 player - stage clear
89c4a3a6 sago007 2008-08-29 14:32 4439
                                                    bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4440
                                                    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4441
                                                    int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4442
                                                    theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4443
                                                    MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4444
                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4445
                                                    twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4446
                                                    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4447
                                                    showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4448
                                                    vsMode = false;
c96f480e sago007 2009-03-28 18:59 4449
                                                    strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4450
                                                    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4451
                                                }
89c4a3a6 sago007 2008-08-29 14:32 4452
                                                else
9050a50a sago007 2008-12-09 13:35 4453
                                                    if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4454
                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4455
                                                        //1 player - puzzle
89c4a3a6 sago007 2008-08-29 14:32 4456
                                                        bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4457
                                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4458
                                                        int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4459
                                                        theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4460
                                                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4461
                                                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4462
                                                        twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4463
                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4464
                                                        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4465
                                                        vsMode = false;
c96f480e sago007 2009-03-28 18:59 4466
                                                        strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4467
                                                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4468
                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4469
                                                    else
9050a50a sago007 2008-12-09 13:35 4470
                                                        if ((buttonXsize<mousex) && (mousex<240) && (200<mousey) && (mousey<240) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4471
                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4472
                                                            //1 player - Vs mode
89c4a3a6 sago007 2008-08-29 14:32 4473
                                                            bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4474
                                                            b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4475
                                                            int theAIlevel = startSingleVs();
e1290bdf sago007 2010-10-25 19:56 4476
                                                            theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4477
                                                            theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4478
                                                            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4479
                                                            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4480
                                                            twoPlayers = true; //Single player, but AI plays
89c4a3a6 sago007 2008-08-29 14:32 4481
                                                            showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4482
                                                            vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 4483
                                                            theGame2.setAIlevel((Uint8)theAIlevel);
89c4a3a6 sago007 2008-08-29 14:32 4484
                                                            int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4485
                                                            theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4486
                                                            theGame2.putStartBlocks(theTime);
c96f480e sago007 2009-03-28 18:59 4487
                                                            strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4488
                                                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4489
                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4490
                                                        else
9050a50a sago007 2008-12-09 13:35 4491
                                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4492
                                                            {
4f1d27f1 sago007 2011-03-18 15:53 4493
                                                                StarTwoPlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4494
                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4495
                                                            else
9050a50a sago007 2008-12-09 13:35 4496
                                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4497
                                                                {
4f1d27f1 sago007 2011-03-18 15:53 4498
                                                                    StartTwoPlayerVs();
89c4a3a6 sago007 2008-08-29 14:32 4499
                                                                }
1572de2b sago007 2008-09-11 18:15 4500
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4501
                                                                else
9050a50a sago007 2008-12-09 13:35 4502
                                                                    if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4503
                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4504
                                                                        //Host
89c4a3a6 sago007 2008-08-29 14:32 4505
                                                                        cout << "Host" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4506
                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4507
                                                                        theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4508
                                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4509
                                                                        nt.startServer();
89c4a3a6 sago007 2008-08-29 14:32 4510
                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4511
                                                                    else
9050a50a sago007 2008-12-09 13:35 4512
                                                                        if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4513
                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4514
                                                                            //Connect
89c4a3a6 sago007 2008-08-29 14:32 4515
                                                                            cout << "Connect" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4516
                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4517
                                                                            theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4518
                                                                            theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4519
                                                                            if (OpenDialogbox(200,100,serverAddress))
89c4a3a6 sago007 2008-08-29 14:32 4520
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4521
                                                                                char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4522
                                                                                memcpy(buf,serverAddress,30);
89c4a3a6 sago007 2008-08-29 14:32 4523
                                                                                nt.connectToServer(strtok(buf," "));
89c4a3a6 sago007 2008-08-29 14:32 4524
                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4525
                                                                            while ( SDL_PollEvent(&event) ); //If the user have pressed ESC or the like
89c4a3a6 sago007 2008-08-29 14:32 4526
                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4527
#endif
89c4a3a6 sago007 2008-08-29 14:32 4528
                                                                        else
9050a50a sago007 2008-12-09 13:35 4529
                                                                            if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4530
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4531
                                                                                //options button clicked
89c4a3a6 sago007 2008-08-29 14:32 4532
                                                                                if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 4533
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4534
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4535
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4536
                                                                                else
89c4a3a6 sago007 2008-08-29 14:32 4537
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4538
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4539
                                                                                    bOptionsOpen = true;
89c4a3a6 sago007 2008-08-29 14:32 4540
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4541
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4542
                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4543
                                                                            else
9050a50a sago007 2008-12-09 13:35 4544
                                                                                if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (40<mousey) && (mousey<80) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4545
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4546
                                                                                    //Configure button clicked
89c4a3a6 sago007 2008-08-29 14:32 4547
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4548
                                                                                    if (!showOptions) {
89c4a3a6 sago007 2008-08-29 14:32 4549
                                                                                        showOptions = true;
89c4a3a6 sago007 2008-08-29 14:32 4550
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4551
                                                                                    else showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4552
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4553
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4554
                                                                                else
9050a50a sago007 2008-12-09 13:35 4555
                                                                                    if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (80<mousey) && (mousey<120) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4556
                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4557
                                                                                        //Configure button clicked
89c4a3a6 sago007 2008-08-29 14:32 4558
                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4559
                                                                                        changePuzzleLevels();
89c4a3a6 sago007 2008-08-29 14:32 4560
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4561
                                                                                    else
9050a50a sago007 2008-12-09 13:35 4562
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (120<mousey) && (mousey<160) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4563
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4564
                                                                                            //vsMode button clicked
89c4a3a6 sago007 2008-08-29 14:32 4565
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4566
                                                                                            startVsMenu();
89c4a3a6 sago007 2008-08-29 14:32 4567
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4568
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4569
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (160<mousey) && (mousey<200) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4570
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4571
                                                                                            //selectThemClicked
89c4a3a6 sago007 2008-08-29 14:32 4572
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4573
                                                                                            char temp[30];
89c4a3a6 sago007 2008-08-29 14:32 4574
                                                                                            SelectThemeDialogbox(200,100,temp);
89c4a3a6 sago007 2008-08-29 14:32 4575
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4576
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4577
                                                                                            if ((buttonXsize*2<mousex) && (mousex<3*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4578
                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4579
                                                                                                //highscore button clicked
47529580 sago007 2008-12-09 02:34 4580
                                                                                                OpenScoresDisplay();
47529580 sago007 2008-12-09 02:34 4581
89c4a3a6 sago007 2008-08-29 14:32 4582
                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4583
                                                                                            else
9050a50a sago007 2008-12-09 13:35 4584
                                                                                                if ((360<mousex) && (mousex<4*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4585
                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4586
                                                                                                    //Replay clicked!
89c4a3a6 sago007 2008-08-29 14:32 4587
                                                                                                    bool state = (!bReplayOpen);
89c4a3a6 sago007 2008-08-29 14:32 4588
                                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4589
                                                                                                    bReplayOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4590
                                                                                                    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4591
                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4592
                                                                                                else
9050a50a sago007 2008-12-09 13:35 4593
                                                                                                    if ((360<mousex) && (mousex<4*buttonXsize) && (40<mousey) && (mousey<80) &&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4594
                                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4595
                                                                                                        //Replay->Save clicked!
89c4a3a6 sago007 2008-08-29 14:32 4596
                                                                                                        //cout << "Replay->Save clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4597
                                                                                                        char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4598
                                                                                                        for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4599
                                                                                                        buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4600
                                                                                                        OpenDialogbox(200,100,buf);
89c4a3a6 sago007 2008-08-29 14:32 4601
                                                                                                        for (int i=28;buf[i]==' ';i--)
89c4a3a6 sago007 2008-08-29 14:32 4602
                                                                                                            buf[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 4603
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 4604
                                                                                                        string saveHere = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4605
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 4606
                                                                                                        string saveHere = home+(string)"/My Games/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4607
#else
89c4a3a6 sago007 2008-08-29 14:32 4608
                                                                                                        string saveHere = (string)"./replays"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4609
#endif
89c4a3a6 sago007 2008-08-29 14:32 4610
                                                                                                        if (lastNrOfPlayers<2)
89c4a3a6 sago007 2008-08-29 14:32 4611
                                                                                                            theGame.theReplay.saveReplay(saveHere);
89c4a3a6 sago007 2008-08-29 14:32 4612
                                                                                                        else
89c4a3a6 sago007 2008-08-29 14:32 4613
                                                                                                            theGame.theReplay.saveReplay(saveHere,theGame2.theReplay);
89c4a3a6 sago007 2008-08-29 14:32 4614
89c4a3a6 sago007 2008-08-29 14:32 4615
                                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4616
                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4617
                                                                                                    else
9050a50a sago007 2008-12-09 13:35 4618
                                                                                                        if ((360<mousex) && (mousex<4*buttonXsize) && (80<mousey) && (mousey<120)&&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4619
                                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4620
                                                                                                            //Replay->Load clicked!
89c4a3a6 sago007 2008-08-29 14:32 4621
                                                                                                            //cout << "Replay->Load clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4622
89c4a3a6 sago007 2008-08-29 14:32 4623
                                                                                                            char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4624
                                                                                                            for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4625
                                                                                                            buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4626
                                                                                                            if (OpenReplayDialogbox(50,100,buf))
89c4a3a6 sago007 2008-08-29 14:32 4627
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4628
                                                                                                                //cout << "Good way" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4629
                                                                                                                for (int i=28;buf[i]==' ';i--)
89c4a3a6 sago007 2008-08-29 14:32 4630
                                                                                                                    buf[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 4631
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 4632
                                                                                                                string loadThis = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4633
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 4634
                                                                                                                string loadThis = home+(string)"/My Games/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4635
#else
89c4a3a6 sago007 2008-08-29 14:32 4636
                                                                                                                string loadThis = (string)"./replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4637
#endif
89c4a3a6 sago007 2008-08-29 14:32 4638
                                                                                                                ifstream replayFileIn;
89c4a3a6 sago007 2008-08-29 14:32 4639
                                                                                                                replayFileIn.open(loadThis.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 4640
                                                                                                                bool play2 = false;
89c4a3a6 sago007 2008-08-29 14:32 4641
                                                                                                                if (replayFileIn)
89c4a3a6 sago007 2008-08-29 14:32 4642
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4643
                                                                                                                    Uint8 version = 0;
89c4a3a6 sago007 2008-08-29 14:32 4644
                                                                                                                    replayFileIn.read(reinterpret_cast<char*>(&version),sizeof(Uint8));                                                                                                                  replayFileIn.close();
89c4a3a6 sago007 2008-08-29 14:32 4645
                                                                                                                    Replay r1;
e03ae476 sago007 2009-03-06 22:49 4646
                                                                                                                    if(r1.loadReplay(loadThis))
89c4a3a6 sago007 2008-08-29 14:32 4647
                                                                                                                    {
e03ae476 sago007 2009-03-06 22:49 4648
                                                                                                                        Replay r2;
e03ae476 sago007 2009-03-06 22:49 4649
                                                                                                                        play2 = r2.loadReplay2(loadThis);
e1290bdf sago007 2010-10-25 19:56 4650
                                                                                                                        theGame.playReplay(50,100,SDL_GetTicks()); //Fejlen sker her
e03ae476 sago007 2009-03-06 22:49 4651
                                                                                                                        theGame.theReplay = r1;
e03ae476 sago007 2009-03-06 22:49 4652
                                                                                                                        if (play2)
e03ae476 sago007 2009-03-06 22:49 4653
                                                                                                                        {
e1290bdf sago007 2010-10-25 19:56 4654
                                                                                                                            theGame2.playReplay(xsize-500,100,SDL_GetTicks());
e03ae476 sago007 2009-03-06 22:49 4655
                                                                                                                            theGame2.theReplay = r2;
e03ae476 sago007 2009-03-06 22:49 4656
                                                                                                                        }
e03ae476 sago007 2009-03-06 22:49 4657
                                                                                                                        else
e03ae476 sago007 2009-03-06 22:49 4658
                                                                                                                            theGame2.SetGameOver();
e03ae476 sago007 2009-03-06 22:49 4659
                                                                                                                        cout << "Replay should have been read" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4660
                                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4661
                                                                                                                    else
e03ae476 sago007 2009-03-06 22:49 4662
                                                                                                                        cout << "Failed to read replay" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4663
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4664
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4665
                                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4666
                                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4667
                                                                                                        else
9050a50a sago007 2008-12-09 13:35 4668
                                                                                                            if ((xsize-120<mousex) && (xsize-20>mousex) && (ysize-buttonXsize<mousey) && (ysize-20>mousey))
89c4a3a6 sago007 2008-08-29 14:32 4669
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4670
                                                                                                                //Exit clicked
89c4a3a6 sago007 2008-08-29 14:32 4671
                                                                                                                done=1;
89c4a3a6 sago007 2008-08-29 14:32 4672
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4673
                                                                                                            else
89c4a3a6 sago007 2008-08-29 14:32 4674
                                                                                                                if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>220) && (mousey<260))
89c4a3a6 sago007 2008-08-29 14:32 4675
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4676
                                                                                                                    MusicEnabled = !MusicEnabled;
89c4a3a6 sago007 2008-08-29 14:32 4677
                                                                                                                    if (!MusicEnabled) Mix_FadeOutMusic(500);
89c4a3a6 sago007 2008-08-29 14:32 4678
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4679
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>270) && (mousey<310))
89c4a3a6 sago007 2008-08-29 14:32 4680
                    {
89c4a3a6 sago007 2008-08-29 14:32 4681
                        SoundEnabled = !SoundEnabled;
89c4a3a6 sago007 2008-08-29 14:32 4682
                    }
89c4a3a6 sago007 2008-08-29 14:32 4683
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>320) && (mousey<360))
89c4a3a6 sago007 2008-08-29 14:32 4684
                    {
89c4a3a6 sago007 2008-08-29 14:32 4685
                        //Fullscreen
89c4a3a6 sago007 2008-08-29 14:32 4686
                        bFullscreen = !bFullscreen;
26ddb424 sago007 2011-06-09 20:06 4687
                        ResetFullscreen();
89c4a3a6 sago007 2008-08-29 14:32 4688
                    }
89c4a3a6 sago007 2008-08-29 14:32 4689
89c4a3a6 sago007 2008-08-29 14:32 4690
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 4691
                    {
89c4a3a6 sago007 2008-08-29 14:32 4692
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 4693
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 4694
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 4695
                        strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 4696
                        if (OpenDialogbox(200,100,player1name))
89c4a3a6 sago007 2008-08-29 14:32 4697
                            strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 4698
                        else
89c4a3a6 sago007 2008-08-29 14:32 4699
                            strcpy(player1name,theGame.name);
89c4a3a6 sago007 2008-08-29 14:32 4700
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 4701
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 4702
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4703
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4704
                    }
89c4a3a6 sago007 2008-08-29 14:32 4705
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 4706
                    {
89c4a3a6 sago007 2008-08-29 14:32 4707
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 4708
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 4709
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 4710
                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4711
                        if (OpenDialogbox(200,100,player2name))
89c4a3a6 sago007 2008-08-29 14:32 4712
                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4713
                        else
89c4a3a6 sago007 2008-08-29 14:32 4714
                            strcpy(player2name,theGame2.name);
89c4a3a6 sago007 2008-08-29 14:32 4715
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 4716
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 4717
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4718
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4719
                    }
89c4a3a6 sago007 2008-08-29 14:32 4720
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 4721
                    {
89c4a3a6 sago007 2008-08-29 14:32 4722
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 4723
                        OpenControlsBox(200,100,0);
e1290bdf sago007 2010-10-25 19:56 4724
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4725
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4726
                    }
89c4a3a6 sago007 2008-08-29 14:32 4727
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 4728
                    {
89c4a3a6 sago007 2008-08-29 14:32 4729
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 4730
                        OpenControlsBox(200,100,2);
e1290bdf sago007 2010-10-25 19:56 4731
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4732
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4733
                    }
89c4a3a6 sago007 2008-08-29 14:32 4734
89c4a3a6 sago007 2008-08-29 14:32 4735
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4736
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4737
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 4738
                    if ((!showOptions))
89c4a3a6 sago007 2008-08-29 14:32 4739
                    {
e1290bdf sago007 2010-10-25 19:56 4740
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4741
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4742
                            {
89c4a3a6 sago007 2008-08-29 14:32 4743
                                theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4744
                            }
e1290bdf sago007 2010-10-25 19:56 4745
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4746
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4747
                            {
89c4a3a6 sago007 2008-08-29 14:32 4748
                                theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4749
                            }
89c4a3a6 sago007 2008-08-29 14:32 4750
                    }
89c4a3a6 sago007 2008-08-29 14:32 4751
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4752
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4753
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4754
e1290bdf sago007 2010-10-25 19:56 4755
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
e1290bdf sago007 2010-10-25 19:56 4756
                            &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
e1290bdf sago007 2010-10-25 19:56 4757
                            &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 4758
                    {
89c4a3a6 sago007 2008-08-29 14:32 4759
                        //Clicked the next button after a stage clear or puzzle
e1290bdf sago007 2010-10-25 19:56 4760
                        theGame.nextLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4761
                    }
e1290bdf sago007 2010-10-25 19:56 4762
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
e1290bdf sago007 2010-10-25 19:56 4763
                            &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
e1290bdf sago007 2010-10-25 19:56 4764
                            &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 4765
                    {
89c4a3a6 sago007 2008-08-29 14:32 4766
                        //Clicked the retry button
e1290bdf sago007 2010-10-25 19:56 4767
                        theGame.retryLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4768
                    }
89c4a3a6 sago007 2008-08-29 14:32 4769
                        
89c4a3a6 sago007 2008-08-29 14:32 4770
                    
89c4a3a6 sago007 2008-08-29 14:32 4771
                    //cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
89c4a3a6 sago007 2008-08-29 14:32 4772
                }
89c4a3a6 sago007 2008-08-29 14:32 4773
89c4a3a6 sago007 2008-08-29 14:32 4774
                //Mouse button 2:
89c4a3a6 sago007 2008-08-29 14:32 4775
                if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2)
89c4a3a6 sago007 2008-08-29 14:32 4776
                {
89c4a3a6 sago007 2008-08-29 14:32 4777
                    bMouseUp2=false; //The button is pressed
89c4a3a6 sago007 2008-08-29 14:32 4778
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4779
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4780
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 4781
                    if (!showOptions)
89c4a3a6 sago007 2008-08-29 14:32 4782
                    {
e1290bdf sago007 2010-10-25 19:56 4783
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4784
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4785
                            {
89c4a3a6 sago007 2008-08-29 14:32 4786
                                theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4787
                            }
e1290bdf sago007 2010-10-25 19:56 4788
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4789
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4790
                            {
89c4a3a6 sago007 2008-08-29 14:32 4791
                                theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4792
                            }
89c4a3a6 sago007 2008-08-29 14:32 4793
                    }
89c4a3a6 sago007 2008-08-29 14:32 4794
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4795
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4796
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4797
                }
89c4a3a6 sago007 2008-08-29 14:32 4798
            } //if !singlePuzzle
89c4a3a6 sago007 2008-08-29 14:32 4799
            else
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
        } //if !bScreenBocked;
89c4a3a6 sago007 2008-08-29 14:32 4804
89c4a3a6 sago007 2008-08-29 14:32 4805
89c4a3a6 sago007 2008-08-29 14:32 4806
        //Sees if music is stopped and if music is enabled
6d48320c sago007 2009-03-28 17:06 4807
        if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath))
89c4a3a6 sago007 2008-08-29 14:32 4808
        {
89c4a3a6 sago007 2008-08-29 14:32 4809
            // then starts playing it.
6d48320c sago007 2009-03-28 17:06 4810
            Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4811
            Mix_PlayMusic(bgMusic, -1); //music loop
89c4a3a6 sago007 2008-08-29 14:32 4812
        }
89c4a3a6 sago007 2008-08-29 14:32 4813
6d48320c sago007 2009-03-28 17:06 4814
        if(bNearDeath!=bNearDeathPrev)
6d48320c sago007 2009-03-28 17:06 4815
        {
6d48320c sago007 2009-03-28 17:06 4816
            if(bNearDeath)
6d48320c sago007 2009-03-28 17:06 4817
            {
6d48320c sago007 2009-03-28 17:06 4818
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 4819
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4820
                    Mix_PlayMusic(highbeatMusic, 1);
6d48320c sago007 2009-03-28 17:06 4821
                }
6d48320c sago007 2009-03-28 17:06 4822
            }
6d48320c sago007 2009-03-28 17:06 4823
            else
6d48320c sago007 2009-03-28 17:06 4824
            {
6d48320c sago007 2009-03-28 17:06 4825
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 4826
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4827
                    Mix_PlayMusic(bgMusic, -1);
6d48320c sago007 2009-03-28 17:06 4828
                }
6d48320c sago007 2009-03-28 17:06 4829
            }
6d48320c sago007 2009-03-28 17:06 4830
        }
6d48320c sago007 2009-03-28 17:06 4831
6d48320c sago007 2009-03-28 17:06 4832
        bNearDeathPrev = bNearDeath;
6d48320c sago007 2009-03-28 17:06 4833
6d48320c sago007 2009-03-28 17:06 4834
6d48320c sago007 2009-03-28 17:06 4835
        //set bNearDeath to false theGame*.Update() will change to true as needed
6d48320c sago007 2009-03-28 17:06 4836
        bNearDeath = false;
89c4a3a6 sago007 2008-08-29 14:32 4837
        //Updates the objects
e1290bdf sago007 2010-10-25 19:56 4838
        theGame.Update(SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4839
        theGame2.Update(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4840
89c4a3a6 sago007 2008-08-29 14:32 4841
//see if anyone has won (two players only)
2f30c381 sago007 2008-09-14 13:08 4842
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4843
        if (!networkPlay)
2f30c381 sago007 2008-09-14 13:08 4844
        #endif
89c4a3a6 sago007 2008-08-29 14:32 4845
            if (twoPlayers)
89c4a3a6 sago007 2008-08-29 14:32 4846
            {
89c4a3a6 sago007 2008-08-29 14:32 4847
                lastNrOfPlayers = 2;
e1290bdf sago007 2010-10-25 19:56 4848
                if ((theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4849
                {
e1290bdf sago007 2010-10-25 19:56 4850
                    if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 4851
                        theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4852
                    else
e1290bdf sago007 2010-10-25 19:56 4853
                        if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 4854
                            theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4855
                        else {
89c4a3a6 sago007 2008-08-29 14:32 4856
                            theGame.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 4857
                            theGame2.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 4858
                        }
89c4a3a6 sago007 2008-08-29 14:32 4859
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4860
                }
e1290bdf sago007 2010-10-25 19:56 4861
                if ((theGame.isGameOver()) && (!theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4862
                {
89c4a3a6 sago007 2008-08-29 14:32 4863
                    theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4864
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4865
                }
e1290bdf sago007 2010-10-25 19:56 4866
                if ((!theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4867
                {
89c4a3a6 sago007 2008-08-29 14:32 4868
                    theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4869
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4870
                }
89c4a3a6 sago007 2008-08-29 14:32 4871
            }
89c4a3a6 sago007 2008-08-29 14:32 4872
89c4a3a6 sago007 2008-08-29 14:32 4873
        //Once evrything has been checked, update graphics
e1290bdf sago007 2010-10-25 19:56 4874
        DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4875
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 4876
        //Remember mouse placement
89c4a3a6 sago007 2008-08-29 14:32 4877
        oldMousex = mousex;
89c4a3a6 sago007 2008-08-29 14:32 4878
        oldMousey = mousey;
89c4a3a6 sago007 2008-08-29 14:32 4879
        //Draw the mouse:
8d488d32 sago007 2011-04-17 13:02 4880
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 4881
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 4882
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 4883
    } //game loop
89c4a3a6 sago007 2008-08-29 14:32 4884
89c4a3a6 sago007 2008-08-29 14:32 4885
89c4a3a6 sago007 2008-08-29 14:32 4886
89c4a3a6 sago007 2008-08-29 14:32 4887
    //Saves options
89c4a3a6 sago007 2008-08-29 14:32 4888
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 4889
    {
769a41a0 sago007 2008-09-24 12:54 4890
        configSettings->setInt("fullscreen",(int)bFullscreen);
769a41a0 sago007 2008-09-24 12:54 4891
        configSettings->setInt("musicenabled",(int)MusicEnabled);
769a41a0 sago007 2008-09-24 12:54 4892
        configSettings->setInt("soundenabled",(int)SoundEnabled);
769a41a0 sago007 2008-09-24 12:54 4893
        configSettings->setInt("mouseplay1",(int)mouseplay1);
769a41a0 sago007 2008-09-24 12:54 4894
        configSettings->setInt("mouseplay2",(int)mouseplay2);
769a41a0 sago007 2008-09-24 12:54 4895
        configSettings->setInt("joypad1",(int)joyplay1);
769a41a0 sago007 2008-09-24 12:54 4896
        configSettings->setInt("joypad2",(int)joyplay2);
769a41a0 sago007 2008-09-24 12:54 4897
        
769a41a0 sago007 2008-09-24 12:54 4898
        configSettings->setInt("player1keyup",(int)keySettings[0].up);
769a41a0 sago007 2008-09-24 12:54 4899
        configSettings->setInt("player1keydown",(int)keySettings[0].down);
769a41a0 sago007 2008-09-24 12:54 4900
        configSettings->setInt("player1keyleft",(int)keySettings[0].left);
769a41a0 sago007 2008-09-24 12:54 4901
        configSettings->setInt("player1keyright",(int)keySettings[0].right);
769a41a0 sago007 2008-09-24 12:54 4902
        configSettings->setInt("player1keychange",(int)keySettings[0].change);
769a41a0 sago007 2008-09-24 12:54 4903
        configSettings->setInt("player1keypush",(int)keySettings[0].push);
769a41a0 sago007 2008-09-24 12:54 4904
        
769a41a0 sago007 2008-09-24 12:54 4905
        configSettings->setInt("player2keyup",(int)keySettings[2].up);
769a41a0 sago007 2008-09-24 12:54 4906
        configSettings->setInt("player2keydown",(int)keySettings[2].down);
769a41a0 sago007 2008-09-24 12:54 4907
        configSettings->setInt("player2keyleft",(int)keySettings[2].left);
769a41a0 sago007 2008-09-24 12:54 4908
        configSettings->setInt("player2keyright",(int)keySettings[2].right);
769a41a0 sago007 2008-09-24 12:54 4909
        configSettings->setInt("player2keychange",(int)keySettings[2].change);
769a41a0 sago007 2008-09-24 12:54 4910
        configSettings->setInt("player2keypush",(int)keySettings[2].push);
769a41a0 sago007 2008-09-24 12:54 4911
        
769a41a0 sago007 2008-09-24 12:54 4912
        configSettings->setString("player1name",player1name);
769a41a0 sago007 2008-09-24 12:54 4913
        configSettings->setString("player2name",player2name);
769a41a0 sago007 2008-09-24 12:54 4914
        configSettings->save();
89c4a3a6 sago007 2008-08-29 14:32 4915
    }
89c4a3a6 sago007 2008-08-29 14:32 4916
89c4a3a6 sago007 2008-08-29 14:32 4917
    //calculate uptime:
c09d0e4f sago007 2009-01-27 01:15 4918
    //int hours, mins, secs,
cd12e0fe sago007 2009-01-29 08:47 4919
    commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4920
89c4a3a6 sago007 2008-08-29 14:32 4921
    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 4922
cd12e0fe sago007 2009-01-29 08:47 4923
    ct = TimeHandler::addTime("totalTime",ct);
c09d0e4f sago007 2009-01-27 01:15 4924
89c4a3a6 sago007 2008-08-29 14:32 4925
    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 4926
c09d0e4f sago007 2009-01-27 01:15 4927
    Stats::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 4928
c09d0e4f sago007 2009-01-27 01:15 4929
    Config::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 4930
    
c09d0e4f sago007 2009-01-27 01:15 4931
    //Frees memory from music and fonts
c09d0e4f sago007 2009-01-27 01:15 4932
    //This is done after writing of configurations and stats since it often crashes the program :(
c09d0e4f sago007 2009-01-27 01:15 4933
    UnloadImages();
41f02ab2 sago007 2009-05-10 21:40 4934
      
91886cae sago007 2008-09-12 16:28 4935
    //Close file system Apstraction layer!
91886cae sago007 2008-09-12 16:28 4936
    PHYSFS_deinit();
89c4a3a6 sago007 2008-08-29 14:32 4937
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 4938
}
b7590374 sago007 2011-05-19 16:15 4939
b7590374 sago007 2011-05-19 16:15 4940
b7590374 sago007 2011-05-19 16:15 4941
void runGame(int gametype) {
b7590374 sago007 2011-05-19 16:15 4942
    Uint8 *keys;
b7590374 sago007 2011-05-19 16:15 4943
     int mousex, mousey;   //Mouse coordinates
b7590374 sago007 2011-05-19 16:15 4944
    showOptions = false;
b7590374 sago007 2011-05-19 16:15 4945
    b1playerOpen = false;
b7590374 sago007 2011-05-19 16:15 4946
    b2playersOpen = false;
b7590374 sago007 2011-05-19 16:15 4947
    bReplayOpen = false;
b7590374 sago007 2011-05-19 16:15 4948
    bScreenLocked = false;
b7590374 sago007 2011-05-19 16:15 4949
    bool vsMode = false;
b7590374 sago007 2011-05-19 16:15 4950
    theTopScoresEndless = Highscore(1);
b7590374 sago007 2011-05-19 16:15 4951
    theTopScoresTimeTrial = Highscore(2);
b7590374 sago007 2011-05-19 16:15 4952
    drawBalls = true;
b7590374 sago007 2011-05-19 16:15 4953
    puzzleLoaded = false;
b7590374 sago007 2011-05-19 16:15 4954
    bool weWhereConnected = false;
b7590374 sago007 2011-05-19 16:15 4955
b7590374 sago007 2011-05-19 16:15 4956
    //Things used for repeating keystrokes:
b7590374 sago007 2011-05-19 16:15 4957
    bool repeatingS[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 4958
    bool repeatingW[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 4959
    bool repeatingN[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 4960
    bool repeatingE[2] = {false,false};
b7590374 sago007 2011-05-19 16:15 4961
    const int startRepeat = 200;
b7590374 sago007 2011-05-19 16:15 4962
    const int repeatDelay = 100;    //Repeating
b7590374 sago007 2011-05-19 16:15 4963
    unsigned long timeHeldP1N = 0;
b7590374 sago007 2011-05-19 16:15 4964
    unsigned long timeHeldP1S = 0;
b7590374 sago007 2011-05-19 16:15 4965
    unsigned long timeHeldP1E = 0;
b7590374 sago007 2011-05-19 16:15 4966
    unsigned long timeHeldP1W = 0;
b7590374 sago007 2011-05-19 16:15 4967
    unsigned long timeHeldP2N = 0;
b7590374 sago007 2011-05-19 16:15 4968
    unsigned long timeHeldP2S = 0;
b7590374 sago007 2011-05-19 16:15 4969
    unsigned long timeHeldP2E = 0;
b7590374 sago007 2011-05-19 16:15 4970
    unsigned long timeHeldP2W = 0;
b7590374 sago007 2011-05-19 16:15 4971
    unsigned long timesRepeatedP1N = 0;
b7590374 sago007 2011-05-19 16:15 4972
    unsigned long timesRepeatedP1S = 0;
b7590374 sago007 2011-05-19 16:15 4973
    unsigned long timesRepeatedP1E = 0;
b7590374 sago007 2011-05-19 16:15 4974
    unsigned long timesRepeatedP1W = 0;
b7590374 sago007 2011-05-19 16:15 4975
    unsigned long timesRepeatedP2N = 0;
b7590374 sago007 2011-05-19 16:15 4976
    unsigned long timesRepeatedP2S = 0;
b7590374 sago007 2011-05-19 16:15 4977
    unsigned long timesRepeatedP2E = 0;
b7590374 sago007 2011-05-19 16:15 4978
    unsigned long timesRepeatedP2W = 0;
b7590374 sago007 2011-05-19 16:15 4979
b7590374 sago007 2011-05-19 16:15 4980
    theBallManeger = ballManeger();
b7590374 sago007 2011-05-19 16:15 4981
    theExplosionManeger = explosionManeger();
b7590374 sago007 2011-05-19 16:15 4982
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
b7590374 sago007 2011-05-19 16:15 4983
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
b7590374 sago007 2011-05-19 16:15 4984
    player1 = &theGame;
b7590374 sago007 2011-05-19 16:15 4985
    player2 = &theGame2;
b7590374 sago007 2011-05-19 16:15 4986
    /*if (singlePuzzle)
b7590374 sago007 2011-05-19 16:15 4987
    {
b7590374 sago007 2011-05-19 16:15 4988
        theGame.GetTopY()=0;
b7590374 sago007 2011-05-19 16:15 4989
        theGame.GetTopX()=0;
b7590374 sago007 2011-05-19 16:15 4990
        theGame2.GetTopY()=10000;
b7590374 sago007 2011-05-19 16:15 4991
        theGame2.GetTopX()=10000;
b7590374 sago007 2011-05-19 16:15 4992
    }*/
b7590374 sago007 2011-05-19 16:15 4993
    theGame.DoPaintJob();			//Makes sure what there is something to paint
b7590374 sago007 2011-05-19 16:15 4994
    theGame2.DoPaintJob();
b7590374 sago007 2011-05-19 16:15 4995
    theGame.SetGameOver();		//sets the game over in the beginning
b7590374 sago007 2011-05-19 16:15 4996
    theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 4997
b7590374 sago007 2011-05-19 16:15 4998
b7590374 sago007 2011-05-19 16:15 4999
    //Takes names from file instead
b7590374 sago007 2011-05-19 16:15 5000
    strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5001
    strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5002
b7590374 sago007 2011-05-19 16:15 5003
b7590374 sago007 2011-05-19 16:15 5004
    Joypad joypad1 = Joypad();    //Creates a joypad
b7590374 sago007 2011-05-19 16:15 5005
    Joypad joypad2 = Joypad();    //Creates a joypad
b7590374 sago007 2011-05-19 16:15 5006
b7590374 sago007 2011-05-19 16:15 5007
    //Keeps track of background;
b7590374 sago007 2011-05-19 16:15 5008
    int nowTime=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5009
b7590374 sago007 2011-05-19 16:15 5010
b7590374 sago007 2011-05-19 16:15 5011
#if NETWORK
b7590374 sago007 2011-05-19 16:15 5012
    NetworkThing nt = NetworkThing();
b7590374 sago007 2011-05-19 16:15 5013
    nt.setBGpointers(&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5014
#endif
b7590374 sago007 2011-05-19 16:15 5015
b7590374 sago007 2011-05-19 16:15 5016
    if (singlePuzzle)
b7590374 sago007 2011-05-19 16:15 5017
    {
b7590374 sago007 2011-05-19 16:15 5018
        LoadPuzzleStages();
b7590374 sago007 2011-05-19 16:15 5019
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5020
        showGame = true;
b7590374 sago007 2011-05-19 16:15 5021
        vsMode = true;
b7590374 sago007 2011-05-19 16:15 5022
    }
b7590374 sago007 2011-05-19 16:15 5023
    //Draws everything to screen
b7590374 sago007 2011-05-19 16:15 5024
    if (!editorMode)
b7590374 sago007 2011-05-19 16:15 5025
        MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5026
    else
b7590374 sago007 2011-05-19 16:15 5027
        MakeBackground(xsize,ysize,&theGame);
b7590374 sago007 2011-05-19 16:15 5028
    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5029
    DrawEverything(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5030
    SDL_Flip(screen);
b7590374 sago007 2011-05-19 16:15 5031
    //game loop
b7590374 sago007 2011-05-19 16:15 5032
    int done = 0;
b7590374 sago007 2011-05-19 16:15 5033
    cout << "Starting game loop" << endl;
b7590374 sago007 2011-05-19 16:15 5034
b7590374 sago007 2011-05-19 16:15 5035
    switch(gametype) {
b7590374 sago007 2011-05-19 16:15 5036
        case 1:
b7590374 sago007 2011-05-19 16:15 5037
            StartSinglePlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 5038
            break;
b7590374 sago007 2011-05-19 16:15 5039
        case 3:
b7590374 sago007 2011-05-19 16:15 5040
            StartSinglePlayerPuzzle();
b7590374 sago007 2011-05-19 16:15 5041
            break;
b7590374 sago007 2011-05-19 16:15 5042
        case 4:
b7590374 sago007 2011-05-19 16:15 5043
        {
b7590374 sago007 2011-05-19 16:15 5044
            //1 player - Vs mode
b7590374 sago007 2011-05-19 16:15 5045
            bNewGameOpen = false;
b7590374 sago007 2011-05-19 16:15 5046
            b1playerOpen = false;
b7590374 sago007 2011-05-19 16:15 5047
            int theAIlevel = startSingleVs();
b7590374 sago007 2011-05-19 16:15 5048
            theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5049
            theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5050
            MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5051
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5052
            twoPlayers = true; //Single player, but AI plays
b7590374 sago007 2011-05-19 16:15 5053
            showGame = true;
b7590374 sago007 2011-05-19 16:15 5054
            vsMode = true;
b7590374 sago007 2011-05-19 16:15 5055
            theGame2.setAIlevel((Uint8)theAIlevel);
b7590374 sago007 2011-05-19 16:15 5056
            int theTime = time(0);
b7590374 sago007 2011-05-19 16:15 5057
            theGame.putStartBlocks(theTime);
b7590374 sago007 2011-05-19 16:15 5058
            theGame2.putStartBlocks(theTime);
b7590374 sago007 2011-05-19 16:15 5059
            strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5060
            strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5061
        }
b7590374 sago007 2011-05-19 16:15 5062
            break;
b7590374 sago007 2011-05-19 16:15 5063
        case 0:
b7590374 sago007 2011-05-19 16:15 5064
        default:
b7590374 sago007 2011-05-19 16:15 5065
            StartSinglePlayerEndless();
b7590374 sago007 2011-05-19 16:15 5066
            break;
b7590374 sago007 2011-05-19 16:15 5067
    };
b7590374 sago007 2011-05-19 16:15 5068
    while (done == 0)
b7590374 sago007 2011-05-19 16:15 5069
    {
b7590374 sago007 2011-05-19 16:15 5070
        if (!(highPriority)) SDL_Delay(10);
b7590374 sago007 2011-05-19 16:15 5071
b7590374 sago007 2011-05-19 16:15 5072
        if ((standardBackground)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 5073
        {
b7590374 sago007 2011-05-19 16:15 5074
            MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5075
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5076
        }
b7590374 sago007 2011-05-19 16:15 5077
b7590374 sago007 2011-05-19 16:15 5078
        if ((standardBackground)&&(editorMode))
b7590374 sago007 2011-05-19 16:15 5079
        {
b7590374 sago007 2011-05-19 16:15 5080
            DrawIMG(backgroundImage, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5081
            MakeBackground(xsize,ysize,&theGame);
b7590374 sago007 2011-05-19 16:15 5082
            DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5083
        }
b7590374 sago007 2011-05-19 16:15 5084
b7590374 sago007 2011-05-19 16:15 5085
        //updates the balls and explosions:
b7590374 sago007 2011-05-19 16:15 5086
        theBallManeger.update();
b7590374 sago007 2011-05-19 16:15 5087
        theExplosionManeger.update();
b7590374 sago007 2011-05-19 16:15 5088
        theTextManeger.update();
b7590374 sago007 2011-05-19 16:15 5089
b7590374 sago007 2011-05-19 16:15 5090
#if NETWORK
b7590374 sago007 2011-05-19 16:15 5091
        if (nt.isConnected())
b7590374 sago007 2011-05-19 16:15 5092
        {
b7590374 sago007 2011-05-19 16:15 5093
            nt.updateNetwork();
b7590374 sago007 2011-05-19 16:15 5094
            networkActive = true;
b7590374 sago007 2011-05-19 16:15 5095
            if (!nt.isConnectedToPeer())
b7590374 sago007 2011-05-19 16:15 5096
                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5097
        }
b7590374 sago007 2011-05-19 16:15 5098
        else
b7590374 sago007 2011-05-19 16:15 5099
            networkActive = false;
b7590374 sago007 2011-05-19 16:15 5100
        if (nt.isConnectedToPeer())
b7590374 sago007 2011-05-19 16:15 5101
        {
b7590374 sago007 2011-05-19 16:15 5102
            networkPlay=true;
b7590374 sago007 2011-05-19 16:15 5103
            if (!weWhereConnected) //We have just connected
b7590374 sago007 2011-05-19 16:15 5104
            {
b7590374 sago007 2011-05-19 16:15 5105
                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5106
                theGame.putStartBlocks(nt.theSeed);
b7590374 sago007 2011-05-19 16:15 5107
                theGame2.playNetwork(xsize-500,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5108
                nt.theGameHasStarted();
b7590374 sago007 2011-05-19 16:15 5109
                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5110
            }
b7590374 sago007 2011-05-19 16:15 5111
            weWhereConnected = true;
b7590374 sago007 2011-05-19 16:15 5112
        }
b7590374 sago007 2011-05-19 16:15 5113
        else
b7590374 sago007 2011-05-19 16:15 5114
        {
b7590374 sago007 2011-05-19 16:15 5115
            networkPlay=false;
b7590374 sago007 2011-05-19 16:15 5116
            weWhereConnected = false;
b7590374 sago007 2011-05-19 16:15 5117
        }
b7590374 sago007 2011-05-19 16:15 5118
#endif
b7590374 sago007 2011-05-19 16:15 5119
b7590374 sago007 2011-05-19 16:15 5120
        if (!bScreenLocked)
b7590374 sago007 2011-05-19 16:15 5121
        {
b7590374 sago007 2011-05-19 16:15 5122
            SDL_Event event;
b7590374 sago007 2011-05-19 16:15 5123
b7590374 sago007 2011-05-19 16:15 5124
            while ( SDL_PollEvent(&event) )
b7590374 sago007 2011-05-19 16:15 5125
            {
b7590374 sago007 2011-05-19 16:15 5126
                if ( event.type == SDL_QUIT )  {
b7590374 sago007 2011-05-19 16:15 5127
                    done = 1;
b7590374 sago007 2011-05-19 16:15 5128
                }
b7590374 sago007 2011-05-19 16:15 5129
b7590374 sago007 2011-05-19 16:15 5130
                if ( event.type == SDL_KEYDOWN )
b7590374 sago007 2011-05-19 16:15 5131
                {
b7590374 sago007 2011-05-19 16:15 5132
                    if ( event.key.keysym.sym == SDLK_ESCAPE )
b7590374 sago007 2011-05-19 16:15 5133
                    {
b7590374 sago007 2011-05-19 16:15 5134
                            if (showOptions)
b7590374 sago007 2011-05-19 16:15 5135
                            {
b7590374 sago007 2011-05-19 16:15 5136
                                showOptions = false;
b7590374 sago007 2011-05-19 16:15 5137
                            }
b7590374 sago007 2011-05-19 16:15 5138
                            else
b7590374 sago007 2011-05-19 16:15 5139
                                done=1;
b7590374 sago007 2011-05-19 16:15 5140
                        DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5141
b7590374 sago007 2011-05-19 16:15 5142
                    }
b7590374 sago007 2011-05-19 16:15 5143
                    if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled()))
b7590374 sago007 2011-05-19 16:15 5144
                    {
b7590374 sago007 2011-05-19 16:15 5145
                        //player1:
b7590374 sago007 2011-05-19 16:15 5146
                        if ( event.key.keysym.sym == keySettings[player1keys].up ) {
b7590374 sago007 2011-05-19 16:15 5147
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5148
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 5149
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5150
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 5151
                        }
b7590374 sago007 2011-05-19 16:15 5152
                        if ( event.key.keysym.sym == keySettings[player1keys].down ) {
b7590374 sago007 2011-05-19 16:15 5153
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5154
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 5155
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5156
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 5157
                        }
b7590374 sago007 2011-05-19 16:15 5158
                        if ( (event.key.keysym.sym == keySettings[player1keys].left) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5159
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5160
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 5161
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5162
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 5163
                        }
b7590374 sago007 2011-05-19 16:15 5164
                        if ( (event.key.keysym.sym == keySettings[player1keys].right) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5165
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5166
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 5167
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5168
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 5169
                        }
b7590374 sago007 2011-05-19 16:15 5170
                        if ( event.key.keysym.sym == keySettings[player1keys].push ) {
b7590374 sago007 2011-05-19 16:15 5171
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5172
                        }
b7590374 sago007 2011-05-19 16:15 5173
                        if ( event.key.keysym.sym == keySettings[player1keys].change ) {
b7590374 sago007 2011-05-19 16:15 5174
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5175
                        }
b7590374 sago007 2011-05-19 16:15 5176
                    }
b7590374 sago007 2011-05-19 16:15 5177
                    if (!editorMode && !theGame2.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 5178
                    {
b7590374 sago007 2011-05-19 16:15 5179
                        //player2:
b7590374 sago007 2011-05-19 16:15 5180
                        if ( event.key.keysym.sym == keySettings[player2keys].up ) {
b7590374 sago007 2011-05-19 16:15 5181
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5182
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 5183
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5184
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 5185
                        }
b7590374 sago007 2011-05-19 16:15 5186
                        if ( event.key.keysym.sym == keySettings[player2keys].down ) {
b7590374 sago007 2011-05-19 16:15 5187
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5188
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 5189
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5190
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 5191
                        }
b7590374 sago007 2011-05-19 16:15 5192
                        if ( (event.key.keysym.sym == keySettings[player2keys].left) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5193
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5194
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 5195
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5196
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 5197
                        }
b7590374 sago007 2011-05-19 16:15 5198
                        if ( (event.key.keysym.sym == keySettings[player2keys].right) && (showGame) ) {
b7590374 sago007 2011-05-19 16:15 5199
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5200
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 5201
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5202
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 5203
                        }
b7590374 sago007 2011-05-19 16:15 5204
                        if ( event.key.keysym.sym == keySettings[player2keys].push ) {
b7590374 sago007 2011-05-19 16:15 5205
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5206
                        }
b7590374 sago007 2011-05-19 16:15 5207
                        if ( event.key.keysym.sym == keySettings[player2keys].change ) {
b7590374 sago007 2011-05-19 16:15 5208
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5209
                        }
b7590374 sago007 2011-05-19 16:15 5210
                    }
b7590374 sago007 2011-05-19 16:15 5211
                    //common:
b7590374 sago007 2011-05-19 16:15 5212
                    if ((!singlePuzzle)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 5213
                    {
b7590374 sago007 2011-05-19 16:15 5214
                        if ( event.key.keysym.sym == SDLK_F2 ) {
b7590374 sago007 2011-05-19 16:15 5215
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5216
                            if ((!showOptions)&&(!networkActive)){
b7590374 sago007 2011-05-19 16:15 5217
                            #else
b7590374 sago007 2011-05-19 16:15 5218
                            if ((!showOptions)){
b7590374 sago007 2011-05-19 16:15 5219
                            #endif
b7590374 sago007 2011-05-19 16:15 5220
                                StartSinglePlayerEndless();
b7590374 sago007 2011-05-19 16:15 5221
                            }}
b7590374 sago007 2011-05-19 16:15 5222
                        if ( event.key.keysym.sym == SDLK_F3 ) {
b7590374 sago007 2011-05-19 16:15 5223
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5224
                            if ((!showOptions)&&(!networkActive)){
b7590374 sago007 2011-05-19 16:15 5225
                            #else
b7590374 sago007 2011-05-19 16:15 5226
                            if ((!showOptions)){
b7590374 sago007 2011-05-19 16:15 5227
                            #endif
b7590374 sago007 2011-05-19 16:15 5228
                                StartSinglePlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 5229
                            }}
b7590374 sago007 2011-05-19 16:15 5230
                        if ( event.key.keysym.sym == SDLK_F5 )
b7590374 sago007 2011-05-19 16:15 5231
                        {
b7590374 sago007 2011-05-19 16:15 5232
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5233
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5234
                            #else
b7590374 sago007 2011-05-19 16:15 5235
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5236
                            #endif
b7590374 sago007 2011-05-19 16:15 5237
                            {
b7590374 sago007 2011-05-19 16:15 5238
                                int myLevel = StageLevelSelect();
b7590374 sago007 2011-05-19 16:15 5239
                                theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5240
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5241
                                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5242
                                closeAllMenus();
b7590374 sago007 2011-05-19 16:15 5243
                                twoPlayers =false;
b7590374 sago007 2011-05-19 16:15 5244
                                theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 5245
                                showGame = true;
b7590374 sago007 2011-05-19 16:15 5246
                                vsMode = false;
b7590374 sago007 2011-05-19 16:15 5247
                                strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5248
                                strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5249
                            }
b7590374 sago007 2011-05-19 16:15 5250
                        }
b7590374 sago007 2011-05-19 16:15 5251
                        if ( event.key.keysym.sym == SDLK_F6 )
b7590374 sago007 2011-05-19 16:15 5252
                        {
b7590374 sago007 2011-05-19 16:15 5253
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5254
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5255
                            #else
b7590374 sago007 2011-05-19 16:15 5256
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5257
                            #endif
b7590374 sago007 2011-05-19 16:15 5258
                            {
b7590374 sago007 2011-05-19 16:15 5259
                                StartTwoPlayerVs();
b7590374 sago007 2011-05-19 16:15 5260
                            }
b7590374 sago007 2011-05-19 16:15 5261
                        }
b7590374 sago007 2011-05-19 16:15 5262
                        if ( event.key.keysym.sym == SDLK_F4 )
b7590374 sago007 2011-05-19 16:15 5263
                        {
b7590374 sago007 2011-05-19 16:15 5264
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5265
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5266
                            #else
b7590374 sago007 2011-05-19 16:15 5267
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5268
                            #endif
b7590374 sago007 2011-05-19 16:15 5269
                            {
b7590374 sago007 2011-05-19 16:15 5270
                                StarTwoPlayerTimeTrial();
b7590374 sago007 2011-05-19 16:15 5271
                            }
b7590374 sago007 2011-05-19 16:15 5272
                        }
b7590374 sago007 2011-05-19 16:15 5273
                        if ( event.key.keysym.sym == SDLK_F7 )
b7590374 sago007 2011-05-19 16:15 5274
                        {
b7590374 sago007 2011-05-19 16:15 5275
                            #if NETWORK
b7590374 sago007 2011-05-19 16:15 5276
                            if ((!showOptions)&&(!networkActive))
b7590374 sago007 2011-05-19 16:15 5277
                            #else
b7590374 sago007 2011-05-19 16:15 5278
                            if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5279
                            #endif
b7590374 sago007 2011-05-19 16:15 5280
                            {
b7590374 sago007 2011-05-19 16:15 5281
                                int myLevel = PuzzleLevelSelect();
b7590374 sago007 2011-05-19 16:15 5282
                                theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5283
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5284
                                DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5285
                                closeAllMenus();
b7590374 sago007 2011-05-19 16:15 5286
                                twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5287
                                theGame2.SetGameOver();
b7590374 sago007 2011-05-19 16:15 5288
                                showGame = true;
b7590374 sago007 2011-05-19 16:15 5289
                                vsMode = true;
b7590374 sago007 2011-05-19 16:15 5290
                                strcpy(theGame.name, player1name);
b7590374 sago007 2011-05-19 16:15 5291
                                strcpy(theGame2.name, player2name);
b7590374 sago007 2011-05-19 16:15 5292
                            }
b7590374 sago007 2011-05-19 16:15 5293
                        }
b7590374 sago007 2011-05-19 16:15 5294
                        if ( event.key.keysym.sym == SDLK_F8 )
b7590374 sago007 2011-05-19 16:15 5295
                        {
b7590374 sago007 2011-05-19 16:15 5296
                        }
b7590374 sago007 2011-05-19 16:15 5297
                        if ( event.key.keysym.sym == SDLK_F9 ) {
b7590374 sago007 2011-05-19 16:15 5298
                            writeScreenShot();
b7590374 sago007 2011-05-19 16:15 5299
                        }
b7590374 sago007 2011-05-19 16:15 5300
                        if ( event.key.keysym.sym == SDLK_F11 ) {
b7590374 sago007 2011-05-19 16:15 5301
                            /*This is the test place, place function to test here*/
b7590374 sago007 2011-05-19 16:15 5302
b7590374 sago007 2011-05-19 16:15 5303
                            //theGame.CreateGreyGarbage();
b7590374 sago007 2011-05-19 16:15 5304
                            //char mitNavn[30];
b7590374 sago007 2011-05-19 16:15 5305
                            //SelectThemeDialogbox(300,400,mitNavn);
b7590374 sago007 2011-05-19 16:15 5306
                           MainMenu();
b7590374 sago007 2011-05-19 16:15 5307
                            //OpenScoresDisplay();
b7590374 sago007 2011-05-19 16:15 5308
                        } //F11
b7590374 sago007 2011-05-19 16:15 5309
                    }
b7590374 sago007 2011-05-19 16:15 5310
                    if ( event.key.keysym.sym == SDLK_F12 ) {
b7590374 sago007 2011-05-19 16:15 5311
                        done=1;
b7590374 sago007 2011-05-19 16:15 5312
                    }
b7590374 sago007 2011-05-19 16:15 5313
                }
b7590374 sago007 2011-05-19 16:15 5314
            } //while event PollEvent - read keys
b7590374 sago007 2011-05-19 16:15 5315
b7590374 sago007 2011-05-19 16:15 5316
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5317
            **************************** Repeating start **************************
b7590374 sago007 2011-05-19 16:15 5318
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5319
b7590374 sago007 2011-05-19 16:15 5320
            keys = SDL_GetKeyState(NULL);
b7590374 sago007 2011-05-19 16:15 5321
//Also the joysticks:
b7590374 sago007 2011-05-19 16:15 5322
//Repeating not implemented
b7590374 sago007 2011-05-19 16:15 5323
b7590374 sago007 2011-05-19 16:15 5324
//Player 1 start
b7590374 sago007 2011-05-19 16:15 5325
            if (!(keys[keySettings[player1keys].up]))
b7590374 sago007 2011-05-19 16:15 5326
                repeatingN[0]=false;
b7590374 sago007 2011-05-19 16:15 5327
            while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5328
            {
b7590374 sago007 2011-05-19 16:15 5329
                theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5330
                timesRepeatedP1N++;
b7590374 sago007 2011-05-19 16:15 5331
            }
b7590374 sago007 2011-05-19 16:15 5332
b7590374 sago007 2011-05-19 16:15 5333
            if (!(keys[keySettings[player1keys].down]))
b7590374 sago007 2011-05-19 16:15 5334
                repeatingS[0]=false;
b7590374 sago007 2011-05-19 16:15 5335
            while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5336
            {
b7590374 sago007 2011-05-19 16:15 5337
                theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5338
                timesRepeatedP1S++;
b7590374 sago007 2011-05-19 16:15 5339
            }
b7590374 sago007 2011-05-19 16:15 5340
b7590374 sago007 2011-05-19 16:15 5341
            if (!(keys[keySettings[player1keys].left]))
b7590374 sago007 2011-05-19 16:15 5342
                repeatingW[0]=false;
b7590374 sago007 2011-05-19 16:15 5343
            while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5344
            {
b7590374 sago007 2011-05-19 16:15 5345
                timesRepeatedP1W++;
b7590374 sago007 2011-05-19 16:15 5346
                theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5347
            }
b7590374 sago007 2011-05-19 16:15 5348
b7590374 sago007 2011-05-19 16:15 5349
            if (!(keys[keySettings[player1keys].right]))
b7590374 sago007 2011-05-19 16:15 5350
                repeatingE[0]=false;
b7590374 sago007 2011-05-19 16:15 5351
            while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5352
            {
b7590374 sago007 2011-05-19 16:15 5353
                timesRepeatedP1E++;
b7590374 sago007 2011-05-19 16:15 5354
                theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5355
            }
b7590374 sago007 2011-05-19 16:15 5356
b7590374 sago007 2011-05-19 16:15 5357
//Player 1 end
b7590374 sago007 2011-05-19 16:15 5358
b7590374 sago007 2011-05-19 16:15 5359
//Player 2 start
b7590374 sago007 2011-05-19 16:15 5360
            if (!(keys[keySettings[player2keys].up]))
b7590374 sago007 2011-05-19 16:15 5361
                repeatingN[1]=false;
b7590374 sago007 2011-05-19 16:15 5362
            while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5363
            {
b7590374 sago007 2011-05-19 16:15 5364
                theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5365
                timesRepeatedP2N++;
b7590374 sago007 2011-05-19 16:15 5366
            }
b7590374 sago007 2011-05-19 16:15 5367
b7590374 sago007 2011-05-19 16:15 5368
            if (!(keys[keySettings[player2keys].down]))
b7590374 sago007 2011-05-19 16:15 5369
                repeatingS[1]=false;
b7590374 sago007 2011-05-19 16:15 5370
            while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5371
            {
b7590374 sago007 2011-05-19 16:15 5372
                theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5373
                timesRepeatedP2S++;
b7590374 sago007 2011-05-19 16:15 5374
            }
b7590374 sago007 2011-05-19 16:15 5375
b7590374 sago007 2011-05-19 16:15 5376
            if (!(keys[keySettings[player2keys].left]))
b7590374 sago007 2011-05-19 16:15 5377
                repeatingW[1]=false;
b7590374 sago007 2011-05-19 16:15 5378
            while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5379
            {
b7590374 sago007 2011-05-19 16:15 5380
                theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5381
                timesRepeatedP2W++;
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[player2keys].right]))
b7590374 sago007 2011-05-19 16:15 5385
                repeatingE[1]=false;
b7590374 sago007 2011-05-19 16:15 5386
            while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat))
b7590374 sago007 2011-05-19 16:15 5387
            {
b7590374 sago007 2011-05-19 16:15 5388
                theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5389
                timesRepeatedP2E++;
b7590374 sago007 2011-05-19 16:15 5390
            }
b7590374 sago007 2011-05-19 16:15 5391
b7590374 sago007 2011-05-19 16:15 5392
//Player 2 end
b7590374 sago007 2011-05-19 16:15 5393
b7590374 sago007 2011-05-19 16:15 5394
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5395
            **************************** Repeating end ****************************
b7590374 sago007 2011-05-19 16:15 5396
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5397
b7590374 sago007 2011-05-19 16:15 5398
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5399
            ***************************** Joypad start ****************************
b7590374 sago007 2011-05-19 16:15 5400
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5401
b7590374 sago007 2011-05-19 16:15 5402
            //Gameplay
b7590374 sago007 2011-05-19 16:15 5403
            if (joyplay1||joyplay2)
b7590374 sago007 2011-05-19 16:15 5404
            {
b7590374 sago007 2011-05-19 16:15 5405
                if (joypad1.working && !theGame.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 5406
                    if (joyplay1)
b7590374 sago007 2011-05-19 16:15 5407
                    {
b7590374 sago007 2011-05-19 16:15 5408
                        joypad1.update();
b7590374 sago007 2011-05-19 16:15 5409
                        if (joypad1.up)
b7590374 sago007 2011-05-19 16:15 5410
                        {
b7590374 sago007 2011-05-19 16:15 5411
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5412
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 5413
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5414
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 5415
                        }
b7590374 sago007 2011-05-19 16:15 5416
                        if (joypad1.down)
b7590374 sago007 2011-05-19 16:15 5417
                        {
b7590374 sago007 2011-05-19 16:15 5418
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5419
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 5420
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5421
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 5422
                        }
b7590374 sago007 2011-05-19 16:15 5423
                        if (joypad1.left)
b7590374 sago007 2011-05-19 16:15 5424
                        {
b7590374 sago007 2011-05-19 16:15 5425
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5426
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 5427
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5428
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 5429
                        }
b7590374 sago007 2011-05-19 16:15 5430
                        if (joypad1.right)
b7590374 sago007 2011-05-19 16:15 5431
                        {
b7590374 sago007 2011-05-19 16:15 5432
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5433
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 5434
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5435
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 5436
                        }
b7590374 sago007 2011-05-19 16:15 5437
                        if (joypad1.but1)
b7590374 sago007 2011-05-19 16:15 5438
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5439
                        if (joypad1.but2)
b7590374 sago007 2011-05-19 16:15 5440
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5441
                    }
b7590374 sago007 2011-05-19 16:15 5442
                    else
b7590374 sago007 2011-05-19 16:15 5443
                    {
b7590374 sago007 2011-05-19 16:15 5444
                        joypad1.update();
b7590374 sago007 2011-05-19 16:15 5445
                        if (joypad1.up)
b7590374 sago007 2011-05-19 16:15 5446
                        {
b7590374 sago007 2011-05-19 16:15 5447
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5448
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 5449
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5450
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 5451
                        }
b7590374 sago007 2011-05-19 16:15 5452
                        if (joypad1.down)
b7590374 sago007 2011-05-19 16:15 5453
                        {
b7590374 sago007 2011-05-19 16:15 5454
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5455
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 5456
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5457
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 5458
                        }
b7590374 sago007 2011-05-19 16:15 5459
                        if (joypad1.left)
b7590374 sago007 2011-05-19 16:15 5460
                        {
b7590374 sago007 2011-05-19 16:15 5461
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5462
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 5463
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5464
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 5465
                        }
b7590374 sago007 2011-05-19 16:15 5466
                        if (joypad1.right)
b7590374 sago007 2011-05-19 16:15 5467
                        {
b7590374 sago007 2011-05-19 16:15 5468
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5469
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 5470
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5471
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 5472
                        }
b7590374 sago007 2011-05-19 16:15 5473
                        if (joypad1.but1)
b7590374 sago007 2011-05-19 16:15 5474
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5475
                        if (joypad1.but2)
b7590374 sago007 2011-05-19 16:15 5476
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5477
                    }
b7590374 sago007 2011-05-19 16:15 5478
                if (joypad2.working && !theGame2.GetAIenabled())
b7590374 sago007 2011-05-19 16:15 5479
                    if (!joyplay2)
b7590374 sago007 2011-05-19 16:15 5480
                    {
b7590374 sago007 2011-05-19 16:15 5481
                        joypad2.update();
b7590374 sago007 2011-05-19 16:15 5482
                        if (joypad2.up)
b7590374 sago007 2011-05-19 16:15 5483
                        {
b7590374 sago007 2011-05-19 16:15 5484
                            theGame.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5485
                            repeatingN[0]=true;
b7590374 sago007 2011-05-19 16:15 5486
                            timeHeldP1N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5487
                            timesRepeatedP1N=0;
b7590374 sago007 2011-05-19 16:15 5488
                        }
b7590374 sago007 2011-05-19 16:15 5489
                        if (joypad2.down)
b7590374 sago007 2011-05-19 16:15 5490
                        {
b7590374 sago007 2011-05-19 16:15 5491
                            theGame.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5492
                            repeatingS[0]=true;
b7590374 sago007 2011-05-19 16:15 5493
                            timeHeldP1S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5494
                            timesRepeatedP1S=0;
b7590374 sago007 2011-05-19 16:15 5495
                        }
b7590374 sago007 2011-05-19 16:15 5496
                        if (joypad2.left)
b7590374 sago007 2011-05-19 16:15 5497
                        {
b7590374 sago007 2011-05-19 16:15 5498
                            theGame.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5499
                            repeatingW[0]=true;
b7590374 sago007 2011-05-19 16:15 5500
                            timeHeldP1W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5501
                            timesRepeatedP1W=0;
b7590374 sago007 2011-05-19 16:15 5502
                        }
b7590374 sago007 2011-05-19 16:15 5503
                        if (joypad2.right)
b7590374 sago007 2011-05-19 16:15 5504
                        {
b7590374 sago007 2011-05-19 16:15 5505
                            theGame.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5506
                            repeatingE[0]=true;
b7590374 sago007 2011-05-19 16:15 5507
                            timeHeldP1E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5508
                            timesRepeatedP1E=0;
b7590374 sago007 2011-05-19 16:15 5509
                        }
b7590374 sago007 2011-05-19 16:15 5510
                        if (joypad2.but1)
b7590374 sago007 2011-05-19 16:15 5511
                            theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5512
                        if (joypad2.but2)
b7590374 sago007 2011-05-19 16:15 5513
                            theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5514
                    }
b7590374 sago007 2011-05-19 16:15 5515
                    else
b7590374 sago007 2011-05-19 16:15 5516
                    {
b7590374 sago007 2011-05-19 16:15 5517
                        joypad2.update();
b7590374 sago007 2011-05-19 16:15 5518
                        if (joypad2.up)
b7590374 sago007 2011-05-19 16:15 5519
                        {
b7590374 sago007 2011-05-19 16:15 5520
                            theGame2.MoveCursor('N');
b7590374 sago007 2011-05-19 16:15 5521
                            repeatingN[1]=true;
b7590374 sago007 2011-05-19 16:15 5522
                            timeHeldP2N=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5523
                            timesRepeatedP2N=0;
b7590374 sago007 2011-05-19 16:15 5524
                        }
b7590374 sago007 2011-05-19 16:15 5525
                        if (joypad2.down)
b7590374 sago007 2011-05-19 16:15 5526
                        {
b7590374 sago007 2011-05-19 16:15 5527
                            theGame2.MoveCursor('S');
b7590374 sago007 2011-05-19 16:15 5528
                            repeatingS[1]=true;
b7590374 sago007 2011-05-19 16:15 5529
                            timeHeldP2S=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5530
                            timesRepeatedP2S=0;
b7590374 sago007 2011-05-19 16:15 5531
                        }
b7590374 sago007 2011-05-19 16:15 5532
                        if (joypad2.left)
b7590374 sago007 2011-05-19 16:15 5533
                        {
b7590374 sago007 2011-05-19 16:15 5534
                            theGame2.MoveCursor('W');
b7590374 sago007 2011-05-19 16:15 5535
                            repeatingW[1]=true;
b7590374 sago007 2011-05-19 16:15 5536
                            timeHeldP2W=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5537
                            timesRepeatedP2W=0;
b7590374 sago007 2011-05-19 16:15 5538
                        }
b7590374 sago007 2011-05-19 16:15 5539
                        if (joypad2.right)
b7590374 sago007 2011-05-19 16:15 5540
                        {
b7590374 sago007 2011-05-19 16:15 5541
                            theGame2.MoveCursor('E');
b7590374 sago007 2011-05-19 16:15 5542
                            repeatingE[1]=true;
b7590374 sago007 2011-05-19 16:15 5543
                            timeHeldP2E=SDL_GetTicks();
b7590374 sago007 2011-05-19 16:15 5544
                            timesRepeatedP2E=0;
b7590374 sago007 2011-05-19 16:15 5545
                        }
b7590374 sago007 2011-05-19 16:15 5546
                        if (joypad2.but1)
b7590374 sago007 2011-05-19 16:15 5547
                            theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5548
                        if (joypad2.but2)
b7590374 sago007 2011-05-19 16:15 5549
                            theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5550
                    }
b7590374 sago007 2011-05-19 16:15 5551
            }
b7590374 sago007 2011-05-19 16:15 5552
b7590374 sago007 2011-05-19 16:15 5553
            /**********************************************************************
b7590374 sago007 2011-05-19 16:15 5554
            ***************************** Joypad end ******************************
b7590374 sago007 2011-05-19 16:15 5555
            **********************************************************************/
b7590374 sago007 2011-05-19 16:15 5556
b7590374 sago007 2011-05-19 16:15 5557
b7590374 sago007 2011-05-19 16:15 5558
            keys = SDL_GetKeyState(NULL);
b7590374 sago007 2011-05-19 16:15 5559
b7590374 sago007 2011-05-19 16:15 5560
            SDL_GetMouseState(&mousex,&mousey);
b7590374 sago007 2011-05-19 16:15 5561
b7590374 sago007 2011-05-19 16:15 5562
            /********************************************************************
b7590374 sago007 2011-05-19 16:15 5563
            **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 5564
            ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5565
b7590374 sago007 2011-05-19 16:15 5566
            if ((mouseplay1)&&((!editorMode)&&(!theGame.GetAIenabled())||(editorModeTest))) //player 1
b7590374 sago007 2011-05-19 16:15 5567
                if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5568
                {
b7590374 sago007 2011-05-19 16:15 5569
                    int yLine, xLine;
b7590374 sago007 2011-05-19 16:15 5570
                    yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50;
b7590374 sago007 2011-05-19 16:15 5571
                    xLine = (mousex-50+25)/50;
b7590374 sago007 2011-05-19 16:15 5572
                    yLine-=2;
b7590374 sago007 2011-05-19 16:15 5573
                    xLine-=1;
b7590374 sago007 2011-05-19 16:15 5574
                    if ((yLine>10)&&(theGame.GetTowerHeight()<12))
b7590374 sago007 2011-05-19 16:15 5575
                        yLine=10;
b7590374 sago007 2011-05-19 16:15 5576
                    if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11))
b7590374 sago007 2011-05-19 16:15 5577
                        yLine=11;
b7590374 sago007 2011-05-19 16:15 5578
                    if (yLine<0)
b7590374 sago007 2011-05-19 16:15 5579
                        yLine=0;
b7590374 sago007 2011-05-19 16:15 5580
                    if (xLine<0)
b7590374 sago007 2011-05-19 16:15 5581
                        xLine=0;
b7590374 sago007 2011-05-19 16:15 5582
                    if (xLine>4)
b7590374 sago007 2011-05-19 16:15 5583
                        xLine=4;
b7590374 sago007 2011-05-19 16:15 5584
                    theGame.MoveCursorTo(xLine,yLine);
b7590374 sago007 2011-05-19 16:15 5585
                }
b7590374 sago007 2011-05-19 16:15 5586
b7590374 sago007 2011-05-19 16:15 5587
            if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2
b7590374 sago007 2011-05-19 16:15 5588
                if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5589
                {
b7590374 sago007 2011-05-19 16:15 5590
                    int yLine, xLine;
b7590374 sago007 2011-05-19 16:15 5591
                    yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50;
b7590374 sago007 2011-05-19 16:15 5592
                    xLine = (mousex-(xsize-500)+25)/50;
b7590374 sago007 2011-05-19 16:15 5593
                    yLine-=2;
b7590374 sago007 2011-05-19 16:15 5594
                    xLine-=1;
b7590374 sago007 2011-05-19 16:15 5595
                    if ((yLine>10)&&(theGame2.GetTowerHeight()<12))
b7590374 sago007 2011-05-19 16:15 5596
                        yLine=10;
b7590374 sago007 2011-05-19 16:15 5597
                    if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11))
b7590374 sago007 2011-05-19 16:15 5598
                        yLine=11;
b7590374 sago007 2011-05-19 16:15 5599
                    if (yLine<0)
b7590374 sago007 2011-05-19 16:15 5600
                        yLine=0;
b7590374 sago007 2011-05-19 16:15 5601
                    if (xLine<0)
b7590374 sago007 2011-05-19 16:15 5602
                        xLine=0;
b7590374 sago007 2011-05-19 16:15 5603
                    if (xLine>4)
b7590374 sago007 2011-05-19 16:15 5604
                        xLine=4;
b7590374 sago007 2011-05-19 16:15 5605
                    theGame2.MoveCursorTo(xLine,yLine);
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
            **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 5610
            ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5611
b7590374 sago007 2011-05-19 16:15 5612
            // If the mouse button is released, make bMouseUp equal true
b7590374 sago007 2011-05-19 16:15 5613
            if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
b7590374 sago007 2011-05-19 16:15 5614
            {
b7590374 sago007 2011-05-19 16:15 5615
                bMouseUp=true;
b7590374 sago007 2011-05-19 16:15 5616
            }
b7590374 sago007 2011-05-19 16:15 5617
b7590374 sago007 2011-05-19 16:15 5618
            // If the mouse button 2 is released, make bMouseUp2 equal true
b7590374 sago007 2011-05-19 16:15 5619
            if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3))
b7590374 sago007 2011-05-19 16:15 5620
            {
b7590374 sago007 2011-05-19 16:15 5621
                bMouseUp2=true;
b7590374 sago007 2011-05-19 16:15 5622
            }
b7590374 sago007 2011-05-19 16:15 5623
b7590374 sago007 2011-05-19 16:15 5624
            if ((!singlePuzzle)&&(!editorMode))
b7590374 sago007 2011-05-19 16:15 5625
            {
b7590374 sago007 2011-05-19 16:15 5626
                //read mouse events
b7590374 sago007 2011-05-19 16:15 5627
                if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
b7590374 sago007 2011-05-19 16:15 5628
                {
b7590374 sago007 2011-05-19 16:15 5629
                    bMouseUp = false;
b7590374 sago007 2011-05-19 16:15 5630
                    DrawIMG(background, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 5631
                    
b7590374 sago007 2011-05-19 16:15 5632
b7590374 sago007 2011-05-19 16:15 5633
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5634
                    **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 5635
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5636
                    if ((!showOptions))
b7590374 sago007 2011-05-19 16:15 5637
                    {
b7590374 sago007 2011-05-19 16:15 5638
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
b7590374 sago007 2011-05-19 16:15 5639
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5640
                            {
b7590374 sago007 2011-05-19 16:15 5641
                                theGame.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5642
                            }
b7590374 sago007 2011-05-19 16:15 5643
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
b7590374 sago007 2011-05-19 16:15 5644
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5645
                            {
b7590374 sago007 2011-05-19 16:15 5646
                                theGame2.SwitchAtCursor();
b7590374 sago007 2011-05-19 16:15 5647
                            }
b7590374 sago007 2011-05-19 16:15 5648
                    }
b7590374 sago007 2011-05-19 16:15 5649
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5650
                    **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 5651
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5652
b7590374 sago007 2011-05-19 16:15 5653
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
b7590374 sago007 2011-05-19 16:15 5654
                            &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
b7590374 sago007 2011-05-19 16:15 5655
                            &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize))
b7590374 sago007 2011-05-19 16:15 5656
                    {
b7590374 sago007 2011-05-19 16:15 5657
                        //Clicked the next button after a stage clear or puzzle
b7590374 sago007 2011-05-19 16:15 5658
                        theGame.nextLevel(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5659
                    }
b7590374 sago007 2011-05-19 16:15 5660
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
b7590374 sago007 2011-05-19 16:15 5661
                            &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
b7590374 sago007 2011-05-19 16:15 5662
                            &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize))
b7590374 sago007 2011-05-19 16:15 5663
                    {
b7590374 sago007 2011-05-19 16:15 5664
                        //Clicked the retry button
b7590374 sago007 2011-05-19 16:15 5665
                        theGame.retryLevel(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5666
                    }
b7590374 sago007 2011-05-19 16:15 5667
b7590374 sago007 2011-05-19 16:15 5668
b7590374 sago007 2011-05-19 16:15 5669
                    //cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
b7590374 sago007 2011-05-19 16:15 5670
                }
b7590374 sago007 2011-05-19 16:15 5671
b7590374 sago007 2011-05-19 16:15 5672
                //Mouse button 2:
b7590374 sago007 2011-05-19 16:15 5673
                if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2)
b7590374 sago007 2011-05-19 16:15 5674
                {
b7590374 sago007 2011-05-19 16:15 5675
                    bMouseUp2=false; //The button is pressed
b7590374 sago007 2011-05-19 16:15 5676
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5677
                    **************** Here comes mouse play ******************************
b7590374 sago007 2011-05-19 16:15 5678
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5679
                    if (!showOptions)
b7590374 sago007 2011-05-19 16:15 5680
                    {
b7590374 sago007 2011-05-19 16:15 5681
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
b7590374 sago007 2011-05-19 16:15 5682
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5683
                            {
b7590374 sago007 2011-05-19 16:15 5684
                                theGame.PushLine();
b7590374 sago007 2011-05-19 16:15 5685
                            }
b7590374 sago007 2011-05-19 16:15 5686
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
b7590374 sago007 2011-05-19 16:15 5687
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
b7590374 sago007 2011-05-19 16:15 5688
                            {
b7590374 sago007 2011-05-19 16:15 5689
                                theGame2.PushLine();
b7590374 sago007 2011-05-19 16:15 5690
                            }
b7590374 sago007 2011-05-19 16:15 5691
                    }
b7590374 sago007 2011-05-19 16:15 5692
                    /********************************************************************
b7590374 sago007 2011-05-19 16:15 5693
                    **************** Here ends mouse play *******************************
b7590374 sago007 2011-05-19 16:15 5694
                    ********************************************************************/
b7590374 sago007 2011-05-19 16:15 5695
                }
b7590374 sago007 2011-05-19 16:15 5696
            } //if !singlePuzzle
b7590374 sago007 2011-05-19 16:15 5697
            else
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
        } //if !bScreenBocked;
b7590374 sago007 2011-05-19 16:15 5702
b7590374 sago007 2011-05-19 16:15 5703
b7590374 sago007 2011-05-19 16:15 5704
        //Sees if music is stopped and if music is enabled
b7590374 sago007 2011-05-19 16:15 5705
        if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath))
b7590374 sago007 2011-05-19 16:15 5706
        {
b7590374 sago007 2011-05-19 16:15 5707
            // then starts playing it.
b7590374 sago007 2011-05-19 16:15 5708
            Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 5709
            Mix_PlayMusic(bgMusic, -1); //music loop
b7590374 sago007 2011-05-19 16:15 5710
        }
b7590374 sago007 2011-05-19 16:15 5711
b7590374 sago007 2011-05-19 16:15 5712
        if(bNearDeath!=bNearDeathPrev)
b7590374 sago007 2011-05-19 16:15 5713
        {
b7590374 sago007 2011-05-19 16:15 5714
            if(bNearDeath)
b7590374 sago007 2011-05-19 16:15 5715
            {
b7590374 sago007 2011-05-19 16:15 5716
                if(!NoSound &&(MusicEnabled)) {
b7590374 sago007 2011-05-19 16:15 5717
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 5718
                    Mix_PlayMusic(highbeatMusic, 1);
b7590374 sago007 2011-05-19 16:15 5719
                }
b7590374 sago007 2011-05-19 16:15 5720
            }
b7590374 sago007 2011-05-19 16:15 5721
            else
b7590374 sago007 2011-05-19 16:15 5722
            {
b7590374 sago007 2011-05-19 16:15 5723
                if(!NoSound &&(MusicEnabled)) {
b7590374 sago007 2011-05-19 16:15 5724
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
b7590374 sago007 2011-05-19 16:15 5725
                    Mix_PlayMusic(bgMusic, -1);
b7590374 sago007 2011-05-19 16:15 5726
                }
b7590374 sago007 2011-05-19 16:15 5727
            }
b7590374 sago007 2011-05-19 16:15 5728
        }
b7590374 sago007 2011-05-19 16:15 5729
b7590374 sago007 2011-05-19 16:15 5730
        bNearDeathPrev = bNearDeath;
b7590374 sago007 2011-05-19 16:15 5731
b7590374 sago007 2011-05-19 16:15 5732
b7590374 sago007 2011-05-19 16:15 5733
        //set bNearDeath to false theGame*.Update() will change to true as needed
b7590374 sago007 2011-05-19 16:15 5734
        bNearDeath = false;
b7590374 sago007 2011-05-19 16:15 5735
        //Updates the objects
b7590374 sago007 2011-05-19 16:15 5736
        theGame.Update(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5737
        theGame2.Update(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 5738
b7590374 sago007 2011-05-19 16:15 5739
//see if anyone has won (two players only)
b7590374 sago007 2011-05-19 16:15 5740
        #if NETWORK
b7590374 sago007 2011-05-19 16:15 5741
        if (!networkPlay)
b7590374 sago007 2011-05-19 16:15 5742
        #endif
b7590374 sago007 2011-05-19 16:15 5743
            if (twoPlayers)
b7590374 sago007 2011-05-19 16:15 5744
            {
b7590374 sago007 2011-05-19 16:15 5745
                lastNrOfPlayers = 2;
b7590374 sago007 2011-05-19 16:15 5746
                if ((theGame.isGameOver()) && (theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 5747
                {
b7590374 sago007 2011-05-19 16:15 5748
                    if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap())
b7590374 sago007 2011-05-19 16:15 5749
                        theGame.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5750
                    else
b7590374 sago007 2011-05-19 16:15 5751
                        if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap())
b7590374 sago007 2011-05-19 16:15 5752
                            theGame2.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5753
                        else {
b7590374 sago007 2011-05-19 16:15 5754
                            theGame.setDraw();
b7590374 sago007 2011-05-19 16:15 5755
                            theGame2.setDraw();
b7590374 sago007 2011-05-19 16:15 5756
                        }
b7590374 sago007 2011-05-19 16:15 5757
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5758
                }
b7590374 sago007 2011-05-19 16:15 5759
                if ((theGame.isGameOver()) && (!theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 5760
                {
b7590374 sago007 2011-05-19 16:15 5761
                    theGame2.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5762
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5763
                }
b7590374 sago007 2011-05-19 16:15 5764
                if ((!theGame.isGameOver()) && (theGame2.isGameOver()))
b7590374 sago007 2011-05-19 16:15 5765
                {
b7590374 sago007 2011-05-19 16:15 5766
                    theGame.setPlayerWon();
b7590374 sago007 2011-05-19 16:15 5767
                    twoPlayers = false;
b7590374 sago007 2011-05-19 16:15 5768
                }
b7590374 sago007 2011-05-19 16:15 5769
            }
b7590374 sago007 2011-05-19 16:15 5770
b7590374 sago007 2011-05-19 16:15 5771
        //Once evrything has been checked, update graphics
b7590374 sago007 2011-05-19 16:15 5772
        DrawEverything(xsize,ysize,&theGame,&theGame2);
b7590374 sago007 2011-05-19 16:15 5773
        SDL_GetMouseState(&mousex,&mousey);
b7590374 sago007 2011-05-19 16:15 5774
        //Remember mouse placement
b7590374 sago007 2011-05-19 16:15 5775
        oldMousex = mousex;
b7590374 sago007 2011-05-19 16:15 5776
        oldMousey = mousey;
b7590374 sago007 2011-05-19 16:15 5777
        //Draw the mouse:
b7590374 sago007 2011-05-19 16:15 5778
        //DrawIMG(mouse,screen,mousex,mousey);
b7590374 sago007 2011-05-19 16:15 5779
        mouse.PaintTo(screen,mousex,mousey);
b7590374 sago007 2011-05-19 16:15 5780
        SDL_Flip(screen);
b7590374 sago007 2011-05-19 16:15 5781
    } //game loop
b7590374 sago007 2011-05-19 16:15 5782
}