git repos / blockattack-game

blame: source/code/main.cpp

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
89c4a3a6 sago007 2008-08-29 14:32 2
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
89c4a3a6 sago007 2008-08-29 14:32 3
Copyright (C) 2008 Poul Sander
89c4a3a6 sago007 2008-08-29 14:32 4
89c4a3a6 sago007 2008-08-29 14:32 5
    This program is free software; you can redistribute it and/or modify
89c4a3a6 sago007 2008-08-29 14:32 6
    it under the terms of the GNU General Public License as published by
89c4a3a6 sago007 2008-08-29 14:32 7
    the Free Software Foundation; either version 2 of the License, or
89c4a3a6 sago007 2008-08-29 14:32 8
    (at your option) any later version.
89c4a3a6 sago007 2008-08-29 14:32 9
89c4a3a6 sago007 2008-08-29 14:32 10
    This program is distributed in the hope that it will be useful,
89c4a3a6 sago007 2008-08-29 14:32 11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
89c4a3a6 sago007 2008-08-29 14:32 12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89c4a3a6 sago007 2008-08-29 14:32 13
    GNU General Public License for more details.
89c4a3a6 sago007 2008-08-29 14:32 14
89c4a3a6 sago007 2008-08-29 14:32 15
    You should have received a copy of the GNU General Public License
89c4a3a6 sago007 2008-08-29 14:32 16
    along with this program; if not, write to the Free Software
89c4a3a6 sago007 2008-08-29 14:32 17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
89c4a3a6 sago007 2008-08-29 14:32 18
89c4a3a6 sago007 2008-08-29 14:32 19
    Poul Sander
89c4a3a6 sago007 2008-08-29 14:32 20
    R�vehjvej 36, V. 1111
89c4a3a6 sago007 2008-08-29 14:32 21
    2800 Kgs. Lyngby
89c4a3a6 sago007 2008-08-29 14:32 22
    DENMARK
89c4a3a6 sago007 2008-08-29 14:32 23
    blockattack@poulsander.com
89c4a3a6 sago007 2008-08-29 14:32 24
    http://blockattack.sf.net
89c4a3a6 sago007 2008-08-29 14:32 25
*/
89c4a3a6 sago007 2008-08-29 14:32 26
215ca7b3 sago007 2009-03-06 16:37 27
#include "common.h"
215ca7b3 sago007 2009-03-06 16:37 28
215ca7b3 sago007 2009-03-06 16:37 29
27ae0175 sago007 2009-01-30 06:02 30
#include <string.h>
27ae0175 sago007 2009-01-30 06:02 31
27ae0175 sago007 2009-01-30 06:02 32
1572de2b sago007 2008-09-11 18:15 33
#ifndef VERSION_NUMBER
e2de69cf sago007 2010-01-15 22:48 34
    #define VERSION_NUMBER "version 1.4.2 BETA"
1572de2b sago007 2008-09-11 18:15 35
#endif
89c4a3a6 sago007 2008-08-29 14:32 36
89c4a3a6 sago007 2008-08-29 14:32 37
//If DEBUG is defined: AI info and FPS will be written to screen
1572de2b sago007 2008-09-11 18:15 38
#ifndef DEBUG
2f30c381 sago007 2008-09-14 13:08 39
    #define DEBUG 0
1572de2b sago007 2008-09-11 18:15 40
#endif
89c4a3a6 sago007 2008-08-29 14:32 41
89c4a3a6 sago007 2008-08-29 14:32 42
//If NETWORK id defined: enet will be used
1572de2b sago007 2008-09-11 18:15 43
#ifndef NETWORK
1572de2b sago007 2008-09-11 18:15 44
    #define NETWORK 1
1572de2b sago007 2008-09-11 18:15 45
#endif
1572de2b sago007 2008-09-11 18:15 46
1572de2b sago007 2008-09-11 18:15 47
//Build-in level editor is still experimental!
1572de2b sago007 2008-09-11 18:15 48
#ifndef LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 49
    #define LEVELEDITOR 0
1572de2b sago007 2008-09-11 18:15 50
#endif
89c4a3a6 sago007 2008-08-29 14:32 51
2e57d791 sago007 2009-06-04 17:48 52
#define WITH_SDL 1
2e57d791 sago007 2009-06-04 17:48 53
aca2f4b0 sago007 2009-05-10 18:11 54
//Macros to convert surfaces (ffor faster drawing)
89c4a3a6 sago007 2008-08-29 14:32 55
#define CONVERT(n) tmp = SDL_DisplayFormat(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 56
#define CONVERTA(n) tmp = SDL_DisplayFormatAlpha(n); SDL_FreeSurface(n); n = tmp
89c4a3a6 sago007 2008-08-29 14:32 57
89c4a3a6 sago007 2008-08-29 14:32 58
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 59
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 60
#include <time.h>           //Used for srand()
769a41a0 sago007 2008-09-24 12:54 61
#include <sstream>          //Still used by itoa2
89c4a3a6 sago007 2008-08-29 14:32 62
#include <string>
89c4a3a6 sago007 2008-08-29 14:32 63
#include "SDL.h"            //The SDL libary, used for most things
89c4a3a6 sago007 2008-08-29 14:32 64
#include <SDL_mixer.h>      //Used for sound & music
89c4a3a6 sago007 2008-08-29 14:32 65
#include <SDL_image.h>      //To load PNG images!
41f02ab2 sago007 2009-05-10 21:40 66
#include <physfs.h>         //Abstract file system. To use containers
41f02ab2 sago007 2009-05-10 21:40 67
#include "physfs_stream.hpp" //To use C++ style file streams
47529580 sago007 2008-12-09 02:34 68
//#include "ttfont.h"        //To use True Type Fonts in SDL
89c4a3a6 sago007 2008-08-29 14:32 69
//#include "config.h"
89c4a3a6 sago007 2008-08-29 14:32 70
#include <vector>
95bc02ff sago007 2009-03-15 02:46 71
#include <SDL/SDL_timer.h>
8d488d32 sago007 2011-04-17 13:02 72
#include "CppSdl/CppSdlImageHolder.hpp"
78d03b38 sago007 2008-11-13 19:56 73
//#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 74
89c4a3a6 sago007 2008-08-29 14:32 75
//if SHAREDIR is not used we look in current directory
89c4a3a6 sago007 2008-08-29 14:32 76
#ifndef SHAREDIR
89c4a3a6 sago007 2008-08-29 14:32 77
#define SHAREDIR "."
89c4a3a6 sago007 2008-08-29 14:32 78
#endif
89c4a3a6 sago007 2008-08-29 14:32 79
89c4a3a6 sago007 2008-08-29 14:32 80
89c4a3a6 sago007 2008-08-29 14:32 81
89c4a3a6 sago007 2008-08-29 14:32 82
//enet things
1572de2b sago007 2008-09-11 18:15 83
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 84
#include "enet/enet.h"
89c4a3a6 sago007 2008-08-29 14:32 85
#endif
89c4a3a6 sago007 2008-08-29 14:32 86
//enet things end
89c4a3a6 sago007 2008-08-29 14:32 87
89c4a3a6 sago007 2008-08-29 14:32 88
#include "SFont.h"          //Used to write on screen
89c4a3a6 sago007 2008-08-29 14:32 89
#include "highscore.h"      //Stores highscores
89c4a3a6 sago007 2008-08-29 14:32 90
#include "ReadKeyboard.h"   //Reads text from keyboard
89c4a3a6 sago007 2008-08-29 14:32 91
#include "joypad.h"         //Used for joypads
89c4a3a6 sago007 2008-08-29 14:32 92
#include "listFiles.h"	    //Used to show files on screen
89c4a3a6 sago007 2008-08-29 14:32 93
#include "replay.h"			//Used for replays
89c4a3a6 sago007 2008-08-29 14:32 94
#include "stats.h"          //Saves general stats 
1572de2b sago007 2008-09-11 18:15 95
#if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 96
#include "editor/editorMain.hpp" //The level editor
1572de2b sago007 2008-09-11 18:15 97
#endif
bc9ea011 sago007 2009-04-12 17:43 98
//#include "uploadReplay.h"   //Takes care of everything libcurl related
89c4a3a6 sago007 2008-08-29 14:32 99
89c4a3a6 sago007 2008-08-29 14:32 100
#include "common.h"
89c4a3a6 sago007 2008-08-29 14:32 101
89c4a3a6 sago007 2008-08-29 14:32 102
/*******************************************************************************
89c4a3a6 sago007 2008-08-29 14:32 103
* All variables and constant has been moved to mainVars.hpp for the overview.  *
89c4a3a6 sago007 2008-08-29 14:32 104
*******************************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 105
#include "mainVars.hpp"
89c4a3a6 sago007 2008-08-29 14:32 106
4b0c248f sago007 2010-11-10 21:13 107
static void MakeBackground(int,int);
89c4a3a6 sago007 2008-08-29 14:32 108
89c4a3a6 sago007 2008-08-29 14:32 109
void closeAllMenus()
89c4a3a6 sago007 2008-08-29 14:32 110
{
89c4a3a6 sago007 2008-08-29 14:32 111
    bNewGameOpen=false;          //show sub menues
89c4a3a6 sago007 2008-08-29 14:32 112
    bOptionsOpen=false;          //Show OptionsMenu (Configure and Select Puzzle)
89c4a3a6 sago007 2008-08-29 14:32 113
    b1playerOpen=false;			//show submenu
89c4a3a6 sago007 2008-08-29 14:32 114
    b2playersOpen=false;
89c4a3a6 sago007 2008-08-29 14:32 115
    bReplayOpen = false;
1572de2b sago007 2008-09-11 18:15 116
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 117
    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 118
#endif
89c4a3a6 sago007 2008-08-29 14:32 119
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 120
89c4a3a6 sago007 2008-08-29 14:32 121
}
89c4a3a6 sago007 2008-08-29 14:32 122
1f61db96 sago007 2010-11-15 20:12 123
SDL_Surface * IMG_Load2(string path)
64ea862c sago007 2009-05-05 02:45 124
{
1f61db96 sago007 2010-11-15 20:12 125
    if (!PHYSFS_exists(path.c_str()))
64ea862c sago007 2009-05-05 02:45 126
    {
64ea862c sago007 2009-05-05 02:45 127
        cout << "File not in blockattack.data: " << path << endl;
64ea862c sago007 2009-05-05 02:45 128
        return NULL; //file doesn't exist
64ea862c sago007 2009-05-05 02:45 129
    }
64ea862c sago007 2009-05-05 02:45 130
1f61db96 sago007 2010-11-15 20:12 131
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
64ea862c sago007 2009-05-05 02:45 132
64ea862c sago007 2009-05-05 02:45 133
    // Get the lenght of the file
64ea862c sago007 2009-05-05 02:45 134
    unsigned int m_size = PHYSFS_fileLength(myfile);
64ea862c sago007 2009-05-05 02:45 135
64ea862c sago007 2009-05-05 02:45 136
    // Get the file data.
64ea862c sago007 2009-05-05 02:45 137
    char *m_data = new char[m_size];
64ea862c sago007 2009-05-05 02:45 138
64ea862c sago007 2009-05-05 02:45 139
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
64ea862c sago007 2009-05-05 02:45 140
64ea862c sago007 2009-05-05 02:45 141
    if (length_read != (int)m_size)
64ea862c sago007 2009-05-05 02:45 142
    {
64ea862c sago007 2009-05-05 02:45 143
            delete [] m_data;
64ea862c sago007 2009-05-05 02:45 144
            m_data = 0;
64ea862c sago007 2009-05-05 02:45 145
            PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 146
            cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 147
            return NULL;
64ea862c sago007 2009-05-05 02:45 148
    }
89c4a3a6 sago007 2008-08-29 14:32 149
64ea862c sago007 2009-05-05 02:45 150
    PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 151
64ea862c sago007 2009-05-05 02:45 152
// And this is how you load an image from a memory buffer with SDL
64ea862c sago007 2009-05-05 02:45 153
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
64ea862c sago007 2009-05-05 02:45 154
64ea862c sago007 2009-05-05 02:45 155
    //The above might fail an return null.
64ea862c sago007 2009-05-05 02:45 156
    if(!rw)
64ea862c sago007 2009-05-05 02:45 157
    {
64ea862c sago007 2009-05-05 02:45 158
        delete [] m_data;
64ea862c sago007 2009-05-05 02:45 159
        m_data = 0;
64ea862c sago007 2009-05-05 02:45 160
        PHYSFS_close(myfile);
64ea862c sago007 2009-05-05 02:45 161
        cout << "Error. Curropt data file!" << endl;
64ea862c sago007 2009-05-05 02:45 162
        return NULL;
64ea862c sago007 2009-05-05 02:45 163
    }
64ea862c sago007 2009-05-05 02:45 164
adaf31bf sago007 2009-05-05 16:01 165
    SDL_Surface* surface = IMG_Load_RW(rw,true); //the second argument tells the function to three RWops
64ea862c sago007 2009-05-05 02:45 166
64ea862c sago007 2009-05-05 02:45 167
    return surface;
64ea862c sago007 2009-05-05 02:45 168
}
89c4a3a6 sago007 2008-08-29 14:32 169
8d488d32 sago007 2011-04-17 13:02 170
CppSdl::CppSdlImageHolder IMG_Load3(string path)
8d488d32 sago007 2011-04-17 13:02 171
{
8d488d32 sago007 2011-04-17 13:02 172
    if (!PHYSFS_exists(path.c_str()))
8d488d32 sago007 2011-04-17 13:02 173
    {
8d488d32 sago007 2011-04-17 13:02 174
        cout << "File not in blockattack.data: " << path << endl;
8d488d32 sago007 2011-04-17 13:02 175
        throw exception();
8d488d32 sago007 2011-04-17 13:02 176
    }
8d488d32 sago007 2011-04-17 13:02 177
8d488d32 sago007 2011-04-17 13:02 178
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
8d488d32 sago007 2011-04-17 13:02 179
8d488d32 sago007 2011-04-17 13:02 180
    // Get the lenght of the file
8d488d32 sago007 2011-04-17 13:02 181
    unsigned int m_size = PHYSFS_fileLength(myfile);
8d488d32 sago007 2011-04-17 13:02 182
8d488d32 sago007 2011-04-17 13:02 183
    // Get the file data.
8d488d32 sago007 2011-04-17 13:02 184
    char *m_data = new char[m_size];
8d488d32 sago007 2011-04-17 13:02 185
8d488d32 sago007 2011-04-17 13:02 186
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
8d488d32 sago007 2011-04-17 13:02 187
8d488d32 sago007 2011-04-17 13:02 188
    if (length_read != (int)m_size)
8d488d32 sago007 2011-04-17 13:02 189
    {
8d488d32 sago007 2011-04-17 13:02 190
            delete [] m_data;
8d488d32 sago007 2011-04-17 13:02 191
            m_data = 0;
8d488d32 sago007 2011-04-17 13:02 192
            PHYSFS_close(myfile);
8d488d32 sago007 2011-04-17 13:02 193
            cout << "Error. Curropt data file!" << endl;
8d488d32 sago007 2011-04-17 13:02 194
            throw exception();
8d488d32 sago007 2011-04-17 13:02 195
    }
8d488d32 sago007 2011-04-17 13:02 196
8d488d32 sago007 2011-04-17 13:02 197
    PHYSFS_close(myfile);
8d488d32 sago007 2011-04-17 13:02 198
8d488d32 sago007 2011-04-17 13:02 199
    CppSdl::CppSdlImageHolder surface(m_data, m_size);
8d488d32 sago007 2011-04-17 13:02 200
8d488d32 sago007 2011-04-17 13:02 201
    return surface;
8d488d32 sago007 2011-04-17 13:02 202
}
8d488d32 sago007 2011-04-17 13:02 203
4b0c248f sago007 2010-11-10 21:13 204
static void UnloadImages();
4b0c248f sago007 2010-11-10 21:13 205
static int InitImages();
866417ca sago007 2009-05-10 21:35 206
866417ca sago007 2009-05-10 21:35 207
static string oldThemePath = "default";
41f02ab2 sago007 2009-05-10 21:40 208
static bool loaded = false;
89c4a3a6 sago007 2008-08-29 14:32 209
89c4a3a6 sago007 2008-08-29 14:32 210
void loadTheme(string themeName)
89c4a3a6 sago007 2008-08-29 14:32 211
{
41f02ab2 sago007 2009-05-10 21:40 212
    if(loaded)
866417ca sago007 2009-05-10 21:35 213
        UnloadImages();
866417ca sago007 2009-05-10 21:35 214
#if defined(__unix__)
866417ca sago007 2009-05-10 21:35 215
    string home = (string)getenv("HOME")+(string)"/.gamesaves/blockattack";
866417ca sago007 2009-05-10 21:35 216
#elif defined(_WIN32)
866417ca sago007 2009-05-10 21:35 217
    string home = (string)getMyDocumentsPath()+(string)"/My Games/blockattack";
89c4a3a6 sago007 2008-08-29 14:32 218
#endif
866417ca sago007 2009-05-10 21:35 219
    //Remove old theme
866417ca sago007 2009-05-10 21:35 220
    PHYSFS_removeFromSearchPath(oldThemePath.c_str());
866417ca sago007 2009-05-10 21:35 221
    //Look in blockattack.data
866417ca sago007 2009-05-10 21:35 222
    PHYSFS_addToSearchPath(((string)SHAREDIR+"/blockattack.data").c_str(), 1);
866417ca sago007 2009-05-10 21:35 223
    //Look in folder
866417ca sago007 2009-05-10 21:35 224
    PHYSFS_addToSearchPath(SHAREDIR, 1);
866417ca sago007 2009-05-10 21:35 225
    //Look in home folder
866417ca sago007 2009-05-10 21:35 226
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 227
    PHYSFS_addToSearchPath(home.c_str(), 1);
866417ca sago007 2009-05-10 21:35 228
    #endif
2e57d791 sago007 2009-06-04 17:48 229
    if(themeName.compare(Config::getInstance()->getString("themename"))!=0)
2e57d791 sago007 2009-06-04 17:48 230
    {
2e57d791 sago007 2009-06-04 17:48 231
        //If this is a theme different from the saved one. Remember it!
2e57d791 sago007 2009-06-04 17:48 232
        Config::getInstance()->setString("themename",themeName);
2e57d791 sago007 2009-06-04 17:48 233
    }
866417ca sago007 2009-05-10 21:35 234
    if(themeName.compare("default")==0 || (themeName.compare("start")==0))
89c4a3a6 sago007 2008-08-29 14:32 235
    {
866417ca sago007 2009-05-10 21:35 236
        InitImages();
41f02ab2 sago007 2009-05-10 21:40 237
        loaded =true;
866417ca sago007 2009-05-10 21:35 238
        return; //Nothing more to do
89c4a3a6 sago007 2008-08-29 14:32 239
    }
866417ca sago007 2009-05-10 21:35 240
    oldThemePath = "themes/"+themeName;
866417ca sago007 2009-05-10 21:35 241
    PHYSFS_addToSearchPath(oldThemePath.c_str(),0);
866417ca sago007 2009-05-10 21:35 242
    #if defined(__unix__) || defined(_WIN32)
866417ca sago007 2009-05-10 21:35 243
    PHYSFS_addToSearchPath((home+(string)"/"+oldThemePath).c_str(), 0);
89c4a3a6 sago007 2008-08-29 14:32 244
    #endif
866417ca sago007 2009-05-10 21:35 245
    InitImages();
41f02ab2 sago007 2009-05-10 21:40 246
    loaded = true;
89c4a3a6 sago007 2008-08-29 14:32 247
}
89c4a3a6 sago007 2008-08-29 14:32 248
47529580 sago007 2008-12-09 02:34 249
/*TTF_Font * TTF_OpenFont2(char* path, int ptsize) {
89c4a3a6 sago007 2008-08-29 14:32 250
89c4a3a6 sago007 2008-08-29 14:32 251
    char * tmp;
89c4a3a6 sago007 2008-08-29 14:32 252
    TTF_Font * ret=NULL;
89c4a3a6 sago007 2008-08-29 14:32 253
    tmp = (char*)malloc (sizeof(char)*(strlen(path)+strlen(sharedir)+2));
89c4a3a6 sago007 2008-08-29 14:32 254
    strcpy(tmp, sharedir);
89c4a3a6 sago007 2008-08-29 14:32 255
    strcat(tmp, "/");
89c4a3a6 sago007 2008-08-29 14:32 256
    strcat(tmp, path);
1572de2b sago007 2008-09-11 18:15 257
#if DEBUG
89c4a3a6 sago007 2008-08-29 14:32 258
    printf("loading %s\n",tmp);
89c4a3a6 sago007 2008-08-29 14:32 259
#endif
89c4a3a6 sago007 2008-08-29 14:32 260
    if(!(TTF_WasInit()))
89c4a3a6 sago007 2008-08-29 14:32 261
       TTF_Init();
89c4a3a6 sago007 2008-08-29 14:32 262
    if (!(ret = TTF_OpenFont(tmp, ptsize)))
89c4a3a6 sago007 2008-08-29 14:32 263
        ret = TTF_OpenFont(path, ptsize);
89c4a3a6 sago007 2008-08-29 14:32 264
    if(!ret)
89c4a3a6 sago007 2008-08-29 14:32 265
        cout << "failed to load font: " << TTF_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 266
    free(tmp);
89c4a3a6 sago007 2008-08-29 14:32 267
    return ret;
47529580 sago007 2008-12-09 02:34 268
}*/
89c4a3a6 sago007 2008-08-29 14:32 269
41f02ab2 sago007 2009-05-10 21:40 270
1f61db96 sago007 2010-11-15 20:12 271
Mix_Music * Mix_LoadMUS2(string path)
adaf31bf sago007 2009-05-05 16:01 272
{
1f61db96 sago007 2010-11-15 20:12 273
    if (!PHYSFS_exists(path.c_str()))
adaf31bf sago007 2009-05-05 16:01 274
    {
adaf31bf sago007 2009-05-05 16:01 275
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 276
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 277
    }
adaf31bf sago007 2009-05-05 16:01 278
1f61db96 sago007 2010-11-15 20:12 279
    PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
adaf31bf sago007 2009-05-05 16:01 280
adaf31bf sago007 2009-05-05 16:01 281
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 282
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 283
adaf31bf sago007 2009-05-05 16:01 284
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 285
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 286
adaf31bf sago007 2009-05-05 16:01 287
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 288
adaf31bf sago007 2009-05-05 16:01 289
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 290
    {
adaf31bf sago007 2009-05-05 16:01 291
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 292
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 293
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 294
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 295
            return NULL;
adaf31bf sago007 2009-05-05 16:01 296
    }
adaf31bf sago007 2009-05-05 16:01 297
adaf31bf sago007 2009-05-05 16:01 298
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 299
adaf31bf sago007 2009-05-05 16:01 300
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 301
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 302
adaf31bf sago007 2009-05-05 16:01 303
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 304
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 305
    {
adaf31bf sago007 2009-05-05 16:01 306
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 307
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 308
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 309
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 310
        return NULL;
adaf31bf sago007 2009-05-05 16:01 311
    }
adaf31bf sago007 2009-05-05 16:01 312
adaf31bf sago007 2009-05-05 16:01 313
    Mix_Music* ret = Mix_LoadMUS_RW(rw);
adaf31bf sago007 2009-05-05 16:01 314
adaf31bf sago007 2009-05-05 16:01 315
    return ret;
adaf31bf sago007 2009-05-05 16:01 316
}
89c4a3a6 sago007 2008-08-29 14:32 317
89c4a3a6 sago007 2008-08-29 14:32 318
adaf31bf sago007 2009-05-05 16:01 319
Mix_Chunk * Mix_LoadWAV2(char* path)
adaf31bf sago007 2009-05-05 16:01 320
{
adaf31bf sago007 2009-05-05 16:01 321
    if (!PHYSFS_exists(path))
adaf31bf sago007 2009-05-05 16:01 322
    {
adaf31bf sago007 2009-05-05 16:01 323
        cout << "File not in blockattack.data: " << path << endl;
adaf31bf sago007 2009-05-05 16:01 324
        return NULL; //file doesn't exist
adaf31bf sago007 2009-05-05 16:01 325
    }
adaf31bf sago007 2009-05-05 16:01 326
adaf31bf sago007 2009-05-05 16:01 327
    PHYSFS_file* myfile = PHYSFS_openRead(path);
adaf31bf sago007 2009-05-05 16:01 328
adaf31bf sago007 2009-05-05 16:01 329
    // Get the lenght of the file
adaf31bf sago007 2009-05-05 16:01 330
    unsigned int m_size = PHYSFS_fileLength(myfile);
adaf31bf sago007 2009-05-05 16:01 331
adaf31bf sago007 2009-05-05 16:01 332
    // Get the file data.
adaf31bf sago007 2009-05-05 16:01 333
    char *m_data = new char[m_size];
adaf31bf sago007 2009-05-05 16:01 334
adaf31bf sago007 2009-05-05 16:01 335
    int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
adaf31bf sago007 2009-05-05 16:01 336
adaf31bf sago007 2009-05-05 16:01 337
    if (length_read != (int)m_size)
adaf31bf sago007 2009-05-05 16:01 338
    {
adaf31bf sago007 2009-05-05 16:01 339
            delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 340
            m_data = 0;
adaf31bf sago007 2009-05-05 16:01 341
            PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 342
            cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 343
            return NULL;
adaf31bf sago007 2009-05-05 16:01 344
    }
adaf31bf sago007 2009-05-05 16:01 345
adaf31bf sago007 2009-05-05 16:01 346
    PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 347
adaf31bf sago007 2009-05-05 16:01 348
// And this is how you load from a memory buffer with SDL
adaf31bf sago007 2009-05-05 16:01 349
    SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
adaf31bf sago007 2009-05-05 16:01 350
adaf31bf sago007 2009-05-05 16:01 351
    //The above might fail an return null.
adaf31bf sago007 2009-05-05 16:01 352
    if(!rw)
adaf31bf sago007 2009-05-05 16:01 353
    {
adaf31bf sago007 2009-05-05 16:01 354
        delete [] m_data;
adaf31bf sago007 2009-05-05 16:01 355
        m_data = 0;
adaf31bf sago007 2009-05-05 16:01 356
        PHYSFS_close(myfile);
adaf31bf sago007 2009-05-05 16:01 357
        cout << "Error. Curropt data file!" << endl;
adaf31bf sago007 2009-05-05 16:01 358
        return NULL;
adaf31bf sago007 2009-05-05 16:01 359
    }
adaf31bf sago007 2009-05-05 16:01 360
adaf31bf sago007 2009-05-05 16:01 361
    Mix_Chunk* ret = Mix_LoadWAV_RW(rw,true); //the second argument tells the function to three RWops
adaf31bf sago007 2009-05-05 16:01 362
adaf31bf sago007 2009-05-05 16:01 363
    return ret;
adaf31bf sago007 2009-05-05 16:01 364
}
89c4a3a6 sago007 2008-08-29 14:32 365
89c4a3a6 sago007 2008-08-29 14:32 366
//Load all image files to memory
4b0c248f sago007 2010-11-10 21:13 367
static int InitImages()
89c4a3a6 sago007 2008-08-29 14:32 368
{
1f61db96 sago007 2010-11-15 20:12 369
    if (!((backgroundImage = IMG_Load2("gfx/background.png"))
1f61db96 sago007 2010-11-15 20:12 370
            && (background = IMG_Load2("gfx/blackBackGround.png"))
1f61db96 sago007 2010-11-15 20:12 371
            && (b1player = IMG_Load2("gfx/bOnePlayer.png"))
1f61db96 sago007 2010-11-15 20:12 372
            && (b2players = IMG_Load2("gfx/bTwoPlayers.png"))
1f61db96 sago007 2010-11-15 20:12 373
            && (bVsMode = IMG_Load2("gfx/bVsGame.png"))
1f61db96 sago007 2010-11-15 20:12 374
            && (bVsModeConfig = IMG_Load2("gfx/bVsGameConfig.png"))
89c4a3a6 sago007 2008-08-29 14:32 375
            && (bPuzzle = IMG_Load2((char*)"gfx/bPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 376
            && (bStageClear = IMG_Load2((char*)"gfx/bStageClear.png"))
89c4a3a6 sago007 2008-08-29 14:32 377
            && (bTimeTrial = IMG_Load2((char*)"gfx/bTimeTrial.png"))
89c4a3a6 sago007 2008-08-29 14:32 378
            && (bEndless = IMG_Load2((char*)"gfx/bEndless.png"))
89c4a3a6 sago007 2008-08-29 14:32 379
            && (bOptions = IMG_Load2((char*)"gfx/bOptions.png"))
89c4a3a6 sago007 2008-08-29 14:32 380
            && (bConfigure = IMG_Load2((char*)"gfx/bConfigure.png"))
89c4a3a6 sago007 2008-08-29 14:32 381
            && (bSelectPuzzle = IMG_Load2((char*)"gfx/bSelectPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 382
            && (bHighScore = IMG_Load2((char*)"gfx/bHighScore.png"))
89c4a3a6 sago007 2008-08-29 14:32 383
            && (bExit = IMG_Load2((char*)"gfx/bExit.png"))
89c4a3a6 sago007 2008-08-29 14:32 384
            && (bBack = IMG_Load2((char*)"gfx/bBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 385
            && (bForward = IMG_Load2((char*)"gfx/bForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 386
            && (bReplay = IMG_Load2((char*)"gfx/bReplays.png"))
89c4a3a6 sago007 2008-08-29 14:32 387
            && (bSave = IMG_Load2((char*)"gfx/bSave.png"))
89c4a3a6 sago007 2008-08-29 14:32 388
            && (bLoad = IMG_Load2((char*)"gfx/bLoad.png"))
1572de2b sago007 2008-09-11 18:15 389
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 390
            && (bNetwork = IMG_Load2((char*)"gfx/bNetwork.png"))
89c4a3a6 sago007 2008-08-29 14:32 391
            && (bHost = IMG_Load2((char*)"gfx/bHost.png"))
89c4a3a6 sago007 2008-08-29 14:32 392
            && (bConnect = IMG_Load2((char*)"gfx/bConnect.png"))
89c4a3a6 sago007 2008-08-29 14:32 393
#endif
89c4a3a6 sago007 2008-08-29 14:32 394
            && (blackLine = IMG_Load2((char*)"gfx/blackLine.png"))
89c4a3a6 sago007 2008-08-29 14:32 395
            && (stageBobble = IMG_Load2((char*)"gfx/iStageClearLimit.png"))
a039f5c4 sago007 2008-09-19 23:12 396
            && (bricks[0] = IMG_Load2((char*)"gfx/bricks/blue.png"))
a039f5c4 sago007 2008-09-19 23:12 397
            && (bricks[1] = IMG_Load2((char*)"gfx/bricks/green.png"))
a039f5c4 sago007 2008-09-19 23:12 398
            && (bricks[2] = IMG_Load2((char*)"gfx/bricks/purple.png"))
a039f5c4 sago007 2008-09-19 23:12 399
            && (bricks[3] = IMG_Load2((char*)"gfx/bricks/red.png"))
a039f5c4 sago007 2008-09-19 23:12 400
            && (bricks[4] = IMG_Load2((char*)"gfx/bricks/turkish.png"))
a039f5c4 sago007 2008-09-19 23:12 401
            && (bricks[5] = IMG_Load2((char*)"gfx/bricks/yellow.png"))
a039f5c4 sago007 2008-09-19 23:12 402
            && (bricks[6] = IMG_Load2((char*)"gfx/bricks/grey.png"))
89c4a3a6 sago007 2008-08-29 14:32 403
            && (crossover = IMG_Load2((char*)"gfx/crossover.png"))
89c4a3a6 sago007 2008-08-29 14:32 404
            && (balls[0] = IMG_Load2((char*)"gfx/balls/ballBlue.png"))
89c4a3a6 sago007 2008-08-29 14:32 405
            && (balls[1] = IMG_Load2((char*)"gfx/balls/ballGreen.png"))
89c4a3a6 sago007 2008-08-29 14:32 406
            && (balls[2] = IMG_Load2((char*)"gfx/balls/ballPurple.png"))
89c4a3a6 sago007 2008-08-29 14:32 407
            && (balls[3] = IMG_Load2((char*)"gfx/balls/ballRed.png"))
89c4a3a6 sago007 2008-08-29 14:32 408
            && (balls[4] = IMG_Load2((char*)"gfx/balls/ballTurkish.png"))
89c4a3a6 sago007 2008-08-29 14:32 409
            && (balls[5] = IMG_Load2((char*)"gfx/balls/ballYellow.png"))
89c4a3a6 sago007 2008-08-29 14:32 410
            && (balls[6] = IMG_Load2((char*)"gfx/balls/ballGray.png"))
89c4a3a6 sago007 2008-08-29 14:32 411
            && (cursor[0] = IMG_Load2((char*)"gfx/animations/cursor/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 412
            && (cursor[1] = IMG_Load2((char*)"gfx/animations/cursor/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 413
            && (bomb[0] = IMG_Load2((char*)"gfx/animations/bomb/bomb_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 414
            && (bomb[1] = IMG_Load2((char*)"gfx/animations/bomb/bomb_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 415
            && (ready[0] = IMG_Load2((char*)"gfx/animations/ready/ready_1.png"))
89c4a3a6 sago007 2008-08-29 14:32 416
            && (ready[1] = IMG_Load2((char*)"gfx/animations/ready/ready_2.png"))
89c4a3a6 sago007 2008-08-29 14:32 417
            && (explosion[0] = IMG_Load2((char*)"gfx/animations/explosion/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 418
            && (explosion[1] = IMG_Load2((char*)"gfx/animations/explosion/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 419
            && (explosion[2] = IMG_Load2((char*)"gfx/animations/explosion/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 420
            && (explosion[3] = IMG_Load2((char*)"gfx/animations/explosion/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 421
            && (counter[0] = IMG_Load2((char*)"gfx/counter/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 422
            && (counter[1] = IMG_Load2((char*)"gfx/counter/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 423
            && (counter[2] = IMG_Load2((char*)"gfx/counter/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 424
            && (backBoard = IMG_Load2((char*)"gfx/BackBoard.png")) //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 425
            && (iGameOver = IMG_Load2((char*)"gfx/iGameOver.png"))
89c4a3a6 sago007 2008-08-29 14:32 426
            && (iWinner = IMG_Load2((char*)"gfx/iWinner.png"))
89c4a3a6 sago007 2008-08-29 14:32 427
            && (iDraw = IMG_Load2((char*)"gfx/iDraw.png"))
89c4a3a6 sago007 2008-08-29 14:32 428
            && (iLoser = IMG_Load2((char*)"gfx/iLoser.png"))
89c4a3a6 sago007 2008-08-29 14:32 429
            && (iChainBack = IMG_Load2((char*)"gfx/chainFrame.png"))
89c4a3a6 sago007 2008-08-29 14:32 430
            && (iBlueFont = IMG_Load2((char*)"gfx/24P_Arial_Blue.png"))
89c4a3a6 sago007 2008-08-29 14:32 431
            && (iSmallFont = IMG_Load2((char*)"gfx/14P_Arial_Angle_Red.png"))
89c4a3a6 sago007 2008-08-29 14:32 432
            && (optionsBack = IMG_Load2((char*)"gfx/options.png"))
89c4a3a6 sago007 2008-08-29 14:32 433
            && (bOn = IMG_Load2((char*)"gfx/bOn.png"))
89c4a3a6 sago007 2008-08-29 14:32 434
            && (bOff = IMG_Load2((char*)"gfx/bOff.png"))
89c4a3a6 sago007 2008-08-29 14:32 435
            && (bChange = IMG_Load2((char*)"gfx/bChange.png"))
89c4a3a6 sago007 2008-08-29 14:32 436
            && (b1024 = IMG_Load2((char*)"gfx/b1024.png"))
89c4a3a6 sago007 2008-08-29 14:32 437
            && (dialogBox = IMG_Load2((char*)"gfx/dialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 438
//	&& (fileDialogBox = IMG_Load2("gfx/fileDialogbox.png"))
89c4a3a6 sago007 2008-08-29 14:32 439
            && (iLevelCheck = IMG_Load2((char*)"gfx/iLevelCheck.png"))
89c4a3a6 sago007 2008-08-29 14:32 440
            && (iLevelCheckBox = IMG_Load2((char*)"gfx/iLevelCheckBox.png"))
89c4a3a6 sago007 2008-08-29 14:32 441
            && (iCheckBoxArea = IMG_Load2((char*)"gfx/iCheckBoxArea.png"))
89c4a3a6 sago007 2008-08-29 14:32 442
            && (boardBackBack = IMG_Load2((char*)"gfx/boardBackBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 443
            && (changeButtonsBack = IMG_Load2((char*)"gfx/changeButtonsBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 444
            && (garbageTL = IMG_Load2((char*)"gfx/garbage/garbageTL.png"))
89c4a3a6 sago007 2008-08-29 14:32 445
            && (garbageT = IMG_Load2((char*)"gfx/garbage/garbageT.png"))
89c4a3a6 sago007 2008-08-29 14:32 446
            && (garbageTR = IMG_Load2((char*)"gfx/garbage/garbageTR.png"))
89c4a3a6 sago007 2008-08-29 14:32 447
            && (garbageR = IMG_Load2((char*)"gfx/garbage/garbageR.png"))
89c4a3a6 sago007 2008-08-29 14:32 448
            && (garbageBR = IMG_Load2((char*)"gfx/garbage/garbageBR.png"))
89c4a3a6 sago007 2008-08-29 14:32 449
            && (garbageB = IMG_Load2((char*)"gfx/garbage/garbageB.png"))
89c4a3a6 sago007 2008-08-29 14:32 450
            && (garbageBL = IMG_Load2((char*)"gfx/garbage/garbageBL.png"))
89c4a3a6 sago007 2008-08-29 14:32 451
            && (garbageL = IMG_Load2((char*)"gfx/garbage/garbageL.png"))
89c4a3a6 sago007 2008-08-29 14:32 452
            && (garbageFill = IMG_Load2((char*)"gfx/garbage/garbageFill.png"))
89c4a3a6 sago007 2008-08-29 14:32 453
            && (garbageML = IMG_Load2((char*)"gfx/garbage/garbageML.png"))
89c4a3a6 sago007 2008-08-29 14:32 454
            && (garbageM = IMG_Load2((char*)"gfx/garbage/garbageM.png"))
89c4a3a6 sago007 2008-08-29 14:32 455
            && (garbageMR = IMG_Load2((char*)"gfx/garbage/garbageMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 456
            && (garbageGM = IMG_Load2((char*)"gfx/garbage/garbageGM.png"))
89c4a3a6 sago007 2008-08-29 14:32 457
            && (garbageGML = IMG_Load2((char*)"gfx/garbage/garbageGML.png"))
89c4a3a6 sago007 2008-08-29 14:32 458
            && (garbageGMR = IMG_Load2((char*)"gfx/garbage/garbageGMR.png"))
89c4a3a6 sago007 2008-08-29 14:32 459
            && (smiley[0] = IMG_Load2((char*)"gfx/smileys/0.png"))
89c4a3a6 sago007 2008-08-29 14:32 460
            && (smiley[1] = IMG_Load2((char*)"gfx/smileys/1.png"))
89c4a3a6 sago007 2008-08-29 14:32 461
            && (smiley[2] = IMG_Load2((char*)"gfx/smileys/2.png"))
89c4a3a6 sago007 2008-08-29 14:32 462
            && (smiley[3] = IMG_Load2((char*)"gfx/smileys/3.png"))
89c4a3a6 sago007 2008-08-29 14:32 463
            //new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 464
            && (transCover = IMG_Load2((char*)"gfx/transCover.png"))
1572de2b sago007 2008-09-11 18:15 465
            #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 466
            && (bCreateFile = IMG_Load2((char*)"gfx/editor/bCreateFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 467
            && (bDeletePuzzle = IMG_Load2((char*)"gfx/editor/bDeletePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 468
            && (bLoadFile = IMG_Load2((char*)"gfx/editor/bLoadFile.png"))
89c4a3a6 sago007 2008-08-29 14:32 469
            && (bMoveBack = IMG_Load2((char*)"gfx/editor/bMoveBack.png"))
89c4a3a6 sago007 2008-08-29 14:32 470
            && (bMoveDown = IMG_Load2((char*)"gfx/editor/bMoveDown.png"))
89c4a3a6 sago007 2008-08-29 14:32 471
            && (bMoveForward = IMG_Load2((char*)"gfx/editor/bMoveForward.png"))
89c4a3a6 sago007 2008-08-29 14:32 472
            && (bMoveLeft = IMG_Load2((char*)"gfx/editor/bMoveLeft.png"))
89c4a3a6 sago007 2008-08-29 14:32 473
            && (bMoveRight = IMG_Load2((char*)"gfx/editor/bMoveRight.png"))
89c4a3a6 sago007 2008-08-29 14:32 474
            && (bMoveUp = IMG_Load2((char*)"gfx/editor/bMoveUp.png"))
89c4a3a6 sago007 2008-08-29 14:32 475
            && (bNewPuzzle = IMG_Load2((char*)"gfx/editor/bNewPuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 476
            && (bSaveFileAs = IMG_Load2((char*)"gfx/editor/bSaveFileAs.png"))
89c4a3a6 sago007 2008-08-29 14:32 477
            && (bSavePuzzle = IMG_Load2((char*)"gfx/editor/bSavePuzzle.png"))
89c4a3a6 sago007 2008-08-29 14:32 478
            && (bSaveToFile = IMG_Load2((char*)"gfx/editor/bSaveToFile.png"))
1572de2b sago007 2008-09-11 18:15 479
            && (bTestPuzzle = IMG_Load2((char*)"gfx/editor/bTestPuzzle.png"))
1572de2b sago007 2008-09-11 18:15 480
            #endif
89c4a3a6 sago007 2008-08-29 14:32 481
            //end new in 1.3.2
89c4a3a6 sago007 2008-08-29 14:32 482
            //new in 1.4.0
89c4a3a6 sago007 2008-08-29 14:32 483
            && (bTheme = IMG_Load2((char*)"gfx/bTheme.png"))
89c4a3a6 sago007 2008-08-29 14:32 484
            && (bSkip = IMG_Load2((char*)"gfx/bSkip.png"))
89c4a3a6 sago007 2008-08-29 14:32 485
            && (bNext = IMG_Load2((char*)"gfx/bNext.png"))
89c4a3a6 sago007 2008-08-29 14:32 486
            && (bRetry = IMG_Load2((char*)"gfx/bRetry.png"))
78d03b38 sago007 2008-11-13 19:56 487
            //&& (menuMarked = IMG_Load2((char*)"gfx/menu/marked.png"))
78d03b38 sago007 2008-11-13 19:56 488
            //&& (menuUnmarked = IMG_Load2((char*)"gfx/menu/unmarked.png"))
89c4a3a6 sago007 2008-08-29 14:32 489
            //end new in 1.4.0
8d488d32 sago007 2011-04-17 13:02 490
            //&& (mouse = IMG_Load2((char*)"gfx/mouse.png"))
89c4a3a6 sago007 2008-08-29 14:32 491
         ))
89c4a3a6 sago007 2008-08-29 14:32 492
        //if there was a problem ie. "File not found"
89c4a3a6 sago007 2008-08-29 14:32 493
    {
89c4a3a6 sago007 2008-08-29 14:32 494
        cout << "Error loading image file: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 495
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 496
    }
8d488d32 sago007 2011-04-17 13:02 497
    try{
43611709 sago007 2011-04-23 17:18 498
        bNewGame = IMG_Load3("gfx/bNewGame.png");
8d488d32 sago007 2011-04-17 13:02 499
        mouse = IMG_Load3("gfx/mouse.png");
8d488d32 sago007 2011-04-17 13:02 500
    } catch (exception e) {
8d488d32 sago007 2011-04-17 13:02 501
        cout << e.what() << endl;
8d488d32 sago007 2011-04-17 13:02 502
        exit(1);
8d488d32 sago007 2011-04-17 13:02 503
    }
89c4a3a6 sago007 2008-08-29 14:32 504
89c4a3a6 sago007 2008-08-29 14:32 505
89c4a3a6 sago007 2008-08-29 14:32 506
    //Prepare for fast blittering!
89c4a3a6 sago007 2008-08-29 14:32 507
    CONVERT(background);
89c4a3a6 sago007 2008-08-29 14:32 508
    CONVERT(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 509
    CONVERT(b1player);
89c4a3a6 sago007 2008-08-29 14:32 510
    CONVERT(b2players);
89c4a3a6 sago007 2008-08-29 14:32 511
    CONVERT(bVsMode);
e3e0644e sago007 2008-09-25 14:00 512
    CONVERT(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 513
    CONVERT(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 514
    CONVERT(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 515
    CONVERT(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 516
    CONVERT(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 517
    CONVERT(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 518
    CONVERTA(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 519
    CONVERTA(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 520
    CONVERTA(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 521
    CONVERTA(bSave);
89c4a3a6 sago007 2008-08-29 14:32 522
    CONVERTA(bLoad);
89c4a3a6 sago007 2008-08-29 14:32 523
    CONVERTA(bTheme);
89c4a3a6 sago007 2008-08-29 14:32 524
    CONVERTA(bSkip);
89c4a3a6 sago007 2008-08-29 14:32 525
    CONVERTA(bRetry);
89c4a3a6 sago007 2008-08-29 14:32 526
    CONVERTA(bNext);
78d03b38 sago007 2008-11-13 19:56 527
    //CONVERTA(menuMarked);
78d03b38 sago007 2008-11-13 19:56 528
    //CONVERTA(menuUnmarked);
1572de2b sago007 2008-09-11 18:15 529
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 530
    CONVERTA(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 531
    CONVERTA(bHost);
89c4a3a6 sago007 2008-08-29 14:32 532
    CONVERTA(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 533
#endif
89c4a3a6 sago007 2008-08-29 14:32 534
    CONVERT(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 535
    CONVERTA(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 536
    CONVERT(backBoard);
89c4a3a6 sago007 2008-08-29 14:32 537
    CONVERT(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 538
    CONVERTA(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 539
    CONVERTA(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 540
    CONVERTA(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 541
    CONVERTA(counter[0]);
89c4a3a6 sago007 2008-08-29 14:32 542
    CONVERTA(counter[1]);
89c4a3a6 sago007 2008-08-29 14:32 543
    CONVERTA(counter[2]);
89c4a3a6 sago007 2008-08-29 14:32 544
    CONVERTA(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 545
    CONVERT(bExit);
89c4a3a6 sago007 2008-08-29 14:32 546
    CONVERT(bOn);
89c4a3a6 sago007 2008-08-29 14:32 547
    CONVERT(bOff);
89c4a3a6 sago007 2008-08-29 14:32 548
    CONVERT(bChange);
89c4a3a6 sago007 2008-08-29 14:32 549
    CONVERT(b1024);
89c4a3a6 sago007 2008-08-29 14:32 550
    CONVERTA(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 551
//	CONVERTA(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 552
    CONVERTA(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 553
    CONVERT(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 554
    CONVERTA(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 555
    for (int i = 0;i<4;i++)
89c4a3a6 sago007 2008-08-29 14:32 556
    {
89c4a3a6 sago007 2008-08-29 14:32 557
        CONVERTA(explosion[i]);
89c4a3a6 sago007 2008-08-29 14:32 558
    }
89c4a3a6 sago007 2008-08-29 14:32 559
    for (int i = 0; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 560
    {
89c4a3a6 sago007 2008-08-29 14:32 561
        CONVERTA(bricks[i]);
89c4a3a6 sago007 2008-08-29 14:32 562
        CONVERTA(balls[i]);
89c4a3a6 sago007 2008-08-29 14:32 563
    }
89c4a3a6 sago007 2008-08-29 14:32 564
    CONVERTA(crossover);
89c4a3a6 sago007 2008-08-29 14:32 565
    CONVERTA(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 566
    CONVERTA(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 567
    CONVERTA(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 568
    CONVERTA(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 569
    CONVERTA(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 570
    CONVERTA(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 571
    CONVERTA(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 572
    CONVERTA(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 573
    CONVERTA(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 574
    CONVERTA(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 575
    CONVERTA(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 576
    CONVERTA(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 577
    CONVERTA(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 578
    CONVERTA(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 579
    CONVERTA(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 580
    CONVERTA(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 581
    CONVERTA(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 582
    CONVERTA(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 583
    CONVERTA(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 584
    CONVERTA(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 585
    CONVERTA(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 586
    CONVERTA(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 587
    CONVERTA(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 588
    CONVERTA(iBlueFont);
89c4a3a6 sago007 2008-08-29 14:32 589
    CONVERTA(iSmallFont);
89c4a3a6 sago007 2008-08-29 14:32 590
    CONVERTA(iGameOver);
8d488d32 sago007 2011-04-17 13:02 591
//    CONVERTA(mouse);
8d488d32 sago007 2011-04-17 13:02 592
    mouse.OptimizeForBlit(true);
43611709 sago007 2011-04-23 17:18 593
    bNewGame.OptimizeForBlit(true);
89c4a3a6 sago007 2008-08-29 14:32 594
    CONVERTA(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 595
    CONVERTA(transCover);
89c4a3a6 sago007 2008-08-29 14:32 596
    //Editor:
1572de2b sago007 2008-09-11 18:15 597
    #if LEVELEDITOR
1572de2b sago007 2008-09-11 18:15 598
    CONVERTA(bCreateFile);
89c4a3a6 sago007 2008-08-29 14:32 599
    CONVERTA(bDeletePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 600
    CONVERTA(bLoadFile);
89c4a3a6 sago007 2008-08-29 14:32 601
    CONVERTA(bMoveBack);
89c4a3a6 sago007 2008-08-29 14:32 602
    CONVERTA(bMoveDown);
89c4a3a6 sago007 2008-08-29 14:32 603
    CONVERTA(bMoveForward);
89c4a3a6 sago007 2008-08-29 14:32 604
    CONVERTA(bMoveLeft);
89c4a3a6 sago007 2008-08-29 14:32 605
    CONVERTA(bMoveRight);
89c4a3a6 sago007 2008-08-29 14:32 606
    CONVERTA(bMoveUp);
89c4a3a6 sago007 2008-08-29 14:32 607
    CONVERTA(bNewPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 608
    CONVERTA(bSaveFileAs);
89c4a3a6 sago007 2008-08-29 14:32 609
    CONVERTA(bSavePuzzle);
89c4a3a6 sago007 2008-08-29 14:32 610
    CONVERTA(bSaveToFile);
1572de2b sago007 2008-09-11 18:15 611
    CONVERTA(bTestPuzzle);
1572de2b sago007 2008-09-11 18:15 612
    #endif
1572de2b sago007 2008-09-11 18:15 613
    
89c4a3a6 sago007 2008-08-29 14:32 614
    //Here comes the fonts:
89c4a3a6 sago007 2008-08-29 14:32 615
    fBlueFont = SFont_InitFont(iBlueFont);
89c4a3a6 sago007 2008-08-29 14:32 616
    fSmallFont = SFont_InitFont(iSmallFont);
89c4a3a6 sago007 2008-08-29 14:32 617
    
89c4a3a6 sago007 2008-08-29 14:32 618
    //And the ttf font:
78d03b38 sago007 2008-11-13 19:56 619
    /*TTF_Font *ttFont1 = TTF_OpenFont2((char*)"fonts/FreeSerif.ttf", 24);
78d03b38 sago007 2008-11-13 19:56 620
    TTF_SetFontStyle(ttFont1,TTF_STYLE_BOLD);
78d03b38 sago007 2008-11-13 19:56 621
    ttfont = TTFont(ttFont1);*/
89c4a3a6 sago007 2008-08-29 14:32 622
89c4a3a6 sago007 2008-08-29 14:32 623
//Loads the sound if sound present
89c4a3a6 sago007 2008-08-29 14:32 624
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 625
    {
89c4a3a6 sago007 2008-08-29 14:32 626
        //And here the music:
89c4a3a6 sago007 2008-08-29 14:32 627
        bgMusic = Mix_LoadMUS2((char*)"music/bgMusic.ogg");
6d48320c sago007 2009-03-28 17:06 628
        highbeatMusic = Mix_LoadMUS2((char*)"music/highbeat.ogg");
89c4a3a6 sago007 2008-08-29 14:32 629
        //the music... we just hope it exists, else the user won't hear anything
89c4a3a6 sago007 2008-08-29 14:32 630
        //Same goes for the sounds
89c4a3a6 sago007 2008-08-29 14:32 631
        boing = Mix_LoadWAV2((char*)"sound/pop.ogg");
89c4a3a6 sago007 2008-08-29 14:32 632
        applause = Mix_LoadWAV2((char*)"sound/applause.ogg");
89c4a3a6 sago007 2008-08-29 14:32 633
        photoClick = Mix_LoadWAV2((char*)"sound/cameraclick.ogg");
89c4a3a6 sago007 2008-08-29 14:32 634
        typingChunk = Mix_LoadWAV2((char*)"sound/typing.ogg");
89c4a3a6 sago007 2008-08-29 14:32 635
        counterChunk = Mix_LoadWAV2((char*)"sound/counter.ogg");
24a6ea5f sago007 2008-11-13 22:28 636
        counterFinalChunk = Mix_LoadWAV2((char*)"sound/counterFinal.ogg");
89c4a3a6 sago007 2008-08-29 14:32 637
    } //All sound has been loaded or not
89c4a3a6 sago007 2008-08-29 14:32 638
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 639
} //InitImages()
89c4a3a6 sago007 2008-08-29 14:32 640
89c4a3a6 sago007 2008-08-29 14:32 641
89c4a3a6 sago007 2008-08-29 14:32 642
//Unload images and fonts and sounds
89c4a3a6 sago007 2008-08-29 14:32 643
void UnloadImages()
89c4a3a6 sago007 2008-08-29 14:32 644
{
866417ca sago007 2009-05-10 21:35 645
    cout << "Unloading data..." << endl;
89c4a3a6 sago007 2008-08-29 14:32 646
    //Fonts and Sounds needs to be freed
89c4a3a6 sago007 2008-08-29 14:32 647
    SFont_FreeFont(fBlueFont);
89c4a3a6 sago007 2008-08-29 14:32 648
    SFont_FreeFont(fSmallFont);
89c4a3a6 sago007 2008-08-29 14:32 649
    if (!NoSound) //Only unload then it has been loaded!
89c4a3a6 sago007 2008-08-29 14:32 650
    {
866417ca sago007 2009-05-10 21:35 651
        Mix_HaltMusic();
89c4a3a6 sago007 2008-08-29 14:32 652
        Mix_FreeMusic(bgMusic);
6d48320c sago007 2009-03-28 17:06 653
        Mix_FreeMusic(highbeatMusic);
89c4a3a6 sago007 2008-08-29 14:32 654
        Mix_FreeChunk(boing);
89c4a3a6 sago007 2008-08-29 14:32 655
        Mix_FreeChunk(applause);
89c4a3a6 sago007 2008-08-29 14:32 656
        Mix_FreeChunk(photoClick);
89c4a3a6 sago007 2008-08-29 14:32 657
        Mix_FreeChunk(counterChunk);
24a6ea5f sago007 2008-11-13 22:28 658
        Mix_FreeChunk(counterFinalChunk);
89c4a3a6 sago007 2008-08-29 14:32 659
        Mix_FreeChunk(typingChunk);
89c4a3a6 sago007 2008-08-29 14:32 660
    }
89c4a3a6 sago007 2008-08-29 14:32 661
    //Free surfaces:
89c4a3a6 sago007 2008-08-29 14:32 662
    //I think this will crash, at least it happend to me...
866417ca sago007 2009-05-10 21:35 663
    //Chrashes no more. Caused by an undocumented double free
89c4a3a6 sago007 2008-08-29 14:32 664
    SDL_FreeSurface(backgroundImage);
89c4a3a6 sago007 2008-08-29 14:32 665
    SDL_FreeSurface(background);
43611709 sago007 2011-04-23 17:18 666
    //SDL_FreeSurface(bNewGame);
89c4a3a6 sago007 2008-08-29 14:32 667
    SDL_FreeSurface(b1player);
89c4a3a6 sago007 2008-08-29 14:32 668
    SDL_FreeSurface(b2players);
89c4a3a6 sago007 2008-08-29 14:32 669
    SDL_FreeSurface(bVsMode);
e3e0644e sago007 2008-09-25 14:00 670
    SDL_FreeSurface(bVsModeConfig);
89c4a3a6 sago007 2008-08-29 14:32 671
    SDL_FreeSurface(bPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 672
    SDL_FreeSurface(bStageClear);
89c4a3a6 sago007 2008-08-29 14:32 673
    SDL_FreeSurface(bTimeTrial);
89c4a3a6 sago007 2008-08-29 14:32 674
    SDL_FreeSurface(bEndless);
89c4a3a6 sago007 2008-08-29 14:32 675
    SDL_FreeSurface(bOptions);
89c4a3a6 sago007 2008-08-29 14:32 676
    SDL_FreeSurface(bConfigure);
89c4a3a6 sago007 2008-08-29 14:32 677
    SDL_FreeSurface(bSelectPuzzle);
89c4a3a6 sago007 2008-08-29 14:32 678
    SDL_FreeSurface(bHighScore);
89c4a3a6 sago007 2008-08-29 14:32 679
    SDL_FreeSurface(bReplay);
89c4a3a6 sago007 2008-08-29 14:32 680
    SDL_FreeSurface(bSave);
89c4a3a6 sago007 2008-08-29 14:32 681
    SDL_FreeSurface(bLoad);
1572de2b sago007 2008-09-11 18:15 682
    #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 683
    SDL_FreeSurface(bNetwork);
89c4a3a6 sago007 2008-08-29 14:32 684
    SDL_FreeSurface(bHost);
89c4a3a6 sago007 2008-08-29 14:32 685
    SDL_FreeSurface(bConnect);
89c4a3a6 sago007 2008-08-29 14:32 686
    #endif
89c4a3a6 sago007 2008-08-29 14:32 687
    SDL_FreeSurface(bExit);
89c4a3a6 sago007 2008-08-29 14:32 688
    SDL_FreeSurface(blackLine);
89c4a3a6 sago007 2008-08-29 14:32 689
    SDL_FreeSurface(stageBobble);
89c4a3a6 sago007 2008-08-29 14:32 690
    SDL_FreeSurface(bricks[0]);
89c4a3a6 sago007 2008-08-29 14:32 691
    SDL_FreeSurface(bricks[1]);
89c4a3a6 sago007 2008-08-29 14:32 692
    SDL_FreeSurface(bricks[2]);
89c4a3a6 sago007 2008-08-29 14:32 693
    SDL_FreeSurface(bricks[3]);
89c4a3a6 sago007 2008-08-29 14:32 694
    SDL_FreeSurface(bricks[4]);
89c4a3a6 sago007 2008-08-29 14:32 695
    SDL_FreeSurface(bricks[5]);
89c4a3a6 sago007 2008-08-29 14:32 696
    SDL_FreeSurface(bricks[6]);
89c4a3a6 sago007 2008-08-29 14:32 697
    SDL_FreeSurface(crossover);
89c4a3a6 sago007 2008-08-29 14:32 698
    SDL_FreeSurface(balls[0]);
89c4a3a6 sago007 2008-08-29 14:32 699
    SDL_FreeSurface(balls[1]);
89c4a3a6 sago007 2008-08-29 14:32 700
    SDL_FreeSurface(balls[2]);
89c4a3a6 sago007 2008-08-29 14:32 701
    SDL_FreeSurface(balls[3]);
89c4a3a6 sago007 2008-08-29 14:32 702
    SDL_FreeSurface(balls[4]);
89c4a3a6 sago007 2008-08-29 14:32 703
    SDL_FreeSurface(balls[5]);
89c4a3a6 sago007 2008-08-29 14:32 704
    SDL_FreeSurface(balls[6]);
89c4a3a6 sago007 2008-08-29 14:32 705
    SDL_FreeSurface(cursor[0]);
89c4a3a6 sago007 2008-08-29 14:32 706
    SDL_FreeSurface(cursor[1]);
89c4a3a6 sago007 2008-08-29 14:32 707
    SDL_FreeSurface(backBoard); //not used, we just test if it exists :)
89c4a3a6 sago007 2008-08-29 14:32 708
    SDL_FreeSurface(iGameOver);
89c4a3a6 sago007 2008-08-29 14:32 709
    SDL_FreeSurface(iWinner);
89c4a3a6 sago007 2008-08-29 14:32 710
    SDL_FreeSurface(iDraw);
89c4a3a6 sago007 2008-08-29 14:32 711
    SDL_FreeSurface(iLoser);
89c4a3a6 sago007 2008-08-29 14:32 712
    SDL_FreeSurface(iChainBack);
89c4a3a6 sago007 2008-08-29 14:32 713
    //SDL_FreeSurface(iBlueFont); //Segfault
89c4a3a6 sago007 2008-08-29 14:32 714
    //SDL_FreeSurface(iSmallFont); //Segfault
89c4a3a6 sago007 2008-08-29 14:32 715
    SDL_FreeSurface(optionsBack);
89c4a3a6 sago007 2008-08-29 14:32 716
    SDL_FreeSurface(bOn);
89c4a3a6 sago007 2008-08-29 14:32 717
    SDL_FreeSurface(bOff);
89c4a3a6 sago007 2008-08-29 14:32 718
    SDL_FreeSurface(bChange);
89c4a3a6 sago007 2008-08-29 14:32 719
    SDL_FreeSurface(b1024);
89c4a3a6 sago007 2008-08-29 14:32 720
    SDL_FreeSurface(dialogBox);
89c4a3a6 sago007 2008-08-29 14:32 721
    //SDL_FreeSurface(fileDialogBox);
89c4a3a6 sago007 2008-08-29 14:32 722
    SDL_FreeSurface(iLevelCheck);
89c4a3a6 sago007 2008-08-29 14:32 723
    SDL_FreeSurface(iLevelCheckBox);
89c4a3a6 sago007 2008-08-29 14:32 724
    SDL_FreeSurface(iCheckBoxArea);
89c4a3a6 sago007 2008-08-29 14:32 725
    SDL_FreeSurface(boardBackBack);
89c4a3a6 sago007 2008-08-29 14:32 726
    SDL_FreeSurface(changeButtonsBack);
89c4a3a6 sago007 2008-08-29 14:32 727
    SDL_FreeSurface(garbageTL);
89c4a3a6 sago007 2008-08-29 14:32 728
    SDL_FreeSurface(garbageT);
89c4a3a6 sago007 2008-08-29 14:32 729
    SDL_FreeSurface(garbageTR);
89c4a3a6 sago007 2008-08-29 14:32 730
    SDL_FreeSurface(garbageR);
89c4a3a6 sago007 2008-08-29 14:32 731
    SDL_FreeSurface(garbageBR);
89c4a3a6 sago007 2008-08-29 14:32 732
    SDL_FreeSurface(garbageB);
89c4a3a6 sago007 2008-08-29 14:32 733
    SDL_FreeSurface(garbageBL);
89c4a3a6 sago007 2008-08-29 14:32 734
    SDL_FreeSurface(garbageL);
89c4a3a6 sago007 2008-08-29 14:32 735
    SDL_FreeSurface(garbageFill);
89c4a3a6 sago007 2008-08-29 14:32 736
    SDL_FreeSurface(garbageML);
89c4a3a6 sago007 2008-08-29 14:32 737
    SDL_FreeSurface(garbageM);
89c4a3a6 sago007 2008-08-29 14:32 738
    SDL_FreeSurface(garbageMR);
89c4a3a6 sago007 2008-08-29 14:32 739
    SDL_FreeSurface(garbageGML);
89c4a3a6 sago007 2008-08-29 14:32 740
    SDL_FreeSurface(garbageGM);
89c4a3a6 sago007 2008-08-29 14:32 741
    SDL_FreeSurface(garbageGMR);
89c4a3a6 sago007 2008-08-29 14:32 742
    SDL_FreeSurface(smiley[0]);
89c4a3a6 sago007 2008-08-29 14:32 743
    SDL_FreeSurface(smiley[1]);
89c4a3a6 sago007 2008-08-29 14:32 744
    SDL_FreeSurface(smiley[2]);
89c4a3a6 sago007 2008-08-29 14:32 745
    SDL_FreeSurface(smiley[3]);
89c4a3a6 sago007 2008-08-29 14:32 746
    SDL_FreeSurface(transCover);
8d488d32 sago007 2011-04-17 13:02 747
    //SDL_FreeSurface(mouse);
8d488d32 sago007 2011-04-17 13:02 748
    mouse.MakeNull();
43611709 sago007 2011-04-23 17:18 749
    bNewGame.MakeNull();
89c4a3a6 sago007 2008-08-29 14:32 750
}
89c4a3a6 sago007 2008-08-29 14:32 751
89c4a3a6 sago007 2008-08-29 14:32 752
//Function to convert numbers to string
769a41a0 sago007 2008-09-24 12:54 753
/*string itoa(int num)
89c4a3a6 sago007 2008-08-29 14:32 754
{
89c4a3a6 sago007 2008-08-29 14:32 755
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 756
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 757
    return converter.str();
769a41a0 sago007 2008-09-24 12:54 758
}*/
89c4a3a6 sago007 2008-08-29 14:32 759
89c4a3a6 sago007 2008-08-29 14:32 760
//Function to convert numbers to string (2 diget)
4b0c248f sago007 2010-11-10 21:13 761
static string itoa2(int num)
89c4a3a6 sago007 2008-08-29 14:32 762
{
89c4a3a6 sago007 2008-08-29 14:32 763
    stringstream converter;
89c4a3a6 sago007 2008-08-29 14:32 764
    if(num<10)
89c4a3a6 sago007 2008-08-29 14:32 765
        converter << "0";
89c4a3a6 sago007 2008-08-29 14:32 766
    converter << num;
89c4a3a6 sago007 2008-08-29 14:32 767
    return converter.str();
89c4a3a6 sago007 2008-08-29 14:32 768
}
89c4a3a6 sago007 2008-08-29 14:32 769
89c4a3a6 sago007 2008-08-29 14:32 770
/*Loads all the puzzle levels*/
4b0c248f sago007 2010-11-10 21:13 771
static int LoadPuzzleStages()
89c4a3a6 sago007 2008-08-29 14:32 772
{
89c4a3a6 sago007 2008-08-29 14:32 773
    //if(puzzleLoaded)
89c4a3a6 sago007 2008-08-29 14:32 774
    //    return 1;
aca2f4b0 sago007 2009-05-10 18:11 775
    if (!PHYSFS_exists(("puzzles/"+puzzleName).c_str()))
aca2f4b0 sago007 2009-05-10 18:11 776
    {
aca2f4b0 sago007 2009-05-10 18:11 777
        cout << "File not in blockattack.data: " << ("puzzles/"+puzzleName) << endl;
aca2f4b0 sago007 2009-05-10 18:11 778
        return -1; //file doesn't exist
aca2f4b0 sago007 2009-05-10 18:11 779
    }
aca2f4b0 sago007 2009-05-10 18:11 780
    PhysFS::ifstream inFile(("puzzles/"+puzzleName).c_str());
aca2f4b0 sago007 2009-05-10 18:11 781
89c4a3a6 sago007 2008-08-29 14:32 782
    inFile >> nrOfPuzzles;
89c4a3a6 sago007 2008-08-29 14:32 783
    if (nrOfPuzzles>maxNrOfPuzzleStages)
89c4a3a6 sago007 2008-08-29 14:32 784
        nrOfPuzzles=maxNrOfPuzzleStages;
aca2f4b0 sago007 2009-05-10 18:11 785
    for (int k=0; (k<nrOfPuzzles) /*&&(!inFile.eof())*/ ; k++)
89c4a3a6 sago007 2008-08-29 14:32 786
    {
89c4a3a6 sago007 2008-08-29 14:32 787
        inFile >> nrOfMovesAllowed[k];
89c4a3a6 sago007 2008-08-29 14:32 788
        for (int i=11;i>=0;i--)
89c4a3a6 sago007 2008-08-29 14:32 789
            for (int j=0;j<6;j++)
89c4a3a6 sago007 2008-08-29 14:32 790
            {
89c4a3a6 sago007 2008-08-29 14:32 791
                inFile >> puzzleLevels[k][j][i];
89c4a3a6 sago007 2008-08-29 14:32 792
            }
89c4a3a6 sago007 2008-08-29 14:32 793
    }
89c4a3a6 sago007 2008-08-29 14:32 794
    puzzleLoaded = true;
89c4a3a6 sago007 2008-08-29 14:32 795
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 796
}
89c4a3a6 sago007 2008-08-29 14:32 797
89c4a3a6 sago007 2008-08-29 14:32 798
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
e1290bdf sago007 2010-10-25 19:56 799
void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 800
{
89c4a3a6 sago007 2008-08-29 14:32 801
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 802
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 803
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 804
    SDL_BlitSurface(img, NULL, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 805
}
89c4a3a6 sago007 2008-08-29 14:32 806
89c4a3a6 sago007 2008-08-29 14:32 807
/*Draws a part of an image on a surface of choice*/
89c4a3a6 sago007 2008-08-29 14:32 808
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 809
{
89c4a3a6 sago007 2008-08-29 14:32 810
    SDL_Rect dest;
89c4a3a6 sago007 2008-08-29 14:32 811
    dest.x = x;
89c4a3a6 sago007 2008-08-29 14:32 812
    dest.y = y;
89c4a3a6 sago007 2008-08-29 14:32 813
    SDL_Rect dest2;
89c4a3a6 sago007 2008-08-29 14:32 814
    dest2.x = x2;
89c4a3a6 sago007 2008-08-29 14:32 815
    dest2.y = y2;
89c4a3a6 sago007 2008-08-29 14:32 816
    dest2.w = w;
89c4a3a6 sago007 2008-08-29 14:32 817
    dest2.h = h;
89c4a3a6 sago007 2008-08-29 14:32 818
    SDL_BlitSurface(img, &dest2, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 819
}
89c4a3a6 sago007 2008-08-29 14:32 820
78d03b38 sago007 2008-11-13 19:56 821
//Menu
78d03b38 sago007 2008-11-13 19:56 822
/*void PrintHi()
78d03b38 sago007 2008-11-13 19:56 823
{
78d03b38 sago007 2008-11-13 19:56 824
    cout << "Hi" <<endl;
78d03b38 sago007 2008-11-13 19:56 825
}
78d03b38 sago007 2008-11-13 19:56 826
78d03b38 sago007 2008-11-13 19:56 827
void InitMenues()
78d03b38 sago007 2008-11-13 19:56 828
{
78d03b38 sago007 2008-11-13 19:56 829
    ButtonGfx::setSurfaces(&menuMarked,&menuUnmarked);
78d03b38 sago007 2008-11-13 19:56 830
    ButtonGfx::ttf = &ttfont;
78d03b38 sago007 2008-11-13 19:56 831
}
78d03b38 sago007 2008-11-13 19:56 832
78d03b38 sago007 2008-11-13 19:56 833
void MainMenu()
78d03b38 sago007 2008-11-13 19:56 834
{
78d03b38 sago007 2008-11-13 19:56 835
    Menu m(&screen,true);
78d03b38 sago007 2008-11-13 19:56 836
    Button bHi;
78d03b38 sago007 2008-11-13 19:56 837
    bHi.setLabel("Write hi");
78d03b38 sago007 2008-11-13 19:56 838
    bHi.setAction(PrintHi);
78d03b38 sago007 2008-11-13 19:56 839
    m.addButton(bHi);
78d03b38 sago007 2008-11-13 19:56 840
    m.run();
78d03b38 sago007 2008-11-13 19:56 841
}*/
78d03b38 sago007 2008-11-13 19:56 842
89c4a3a6 sago007 2008-08-29 14:32 843
//The small things that are faaling when you clear something
89c4a3a6 sago007 2008-08-29 14:32 844
class aBall
89c4a3a6 sago007 2008-08-29 14:32 845
{
89c4a3a6 sago007 2008-08-29 14:32 846
private:
89c4a3a6 sago007 2008-08-29 14:32 847
    double x;
89c4a3a6 sago007 2008-08-29 14:32 848
    double y;
89c4a3a6 sago007 2008-08-29 14:32 849
    double velocityY;
89c4a3a6 sago007 2008-08-29 14:32 850
    double velocityX;
89c4a3a6 sago007 2008-08-29 14:32 851
    int color;
89c4a3a6 sago007 2008-08-29 14:32 852
    unsigned long int lastTime;
89c4a3a6 sago007 2008-08-29 14:32 853
public:
89c4a3a6 sago007 2008-08-29 14:32 854
89c4a3a6 sago007 2008-08-29 14:32 855
    aBall()
89c4a3a6 sago007 2008-08-29 14:32 856
    {}
89c4a3a6 sago007 2008-08-29 14:32 857
89c4a3a6 sago007 2008-08-29 14:32 858
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 859
    aBall(int X, int Y, bool right, int coulor)
89c4a3a6 sago007 2008-08-29 14:32 860
    {
89c4a3a6 sago007 2008-08-29 14:32 861
        double tal = 1.0;
89c4a3a6 sago007 2008-08-29 14:32 862
        velocityY = -tal*startVelocityY;
89c4a3a6 sago007 2008-08-29 14:32 863
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 864
        x = (double)X;
89c4a3a6 sago007 2008-08-29 14:32 865
        y = (double)Y;
89c4a3a6 sago007 2008-08-29 14:32 866
        color = coulor;
89c4a3a6 sago007 2008-08-29 14:32 867
        if (right)
89c4a3a6 sago007 2008-08-29 14:32 868
            velocityX = tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 869
        else
89c4a3a6 sago007 2008-08-29 14:32 870
            velocityX = -tal*VelocityX;
89c4a3a6 sago007 2008-08-29 14:32 871
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 872
89c4a3a6 sago007 2008-08-29 14:32 873
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 874
    ~aBall()
89c4a3a6 sago007 2008-08-29 14:32 875
    {
89c4a3a6 sago007 2008-08-29 14:32 876
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 877
89c4a3a6 sago007 2008-08-29 14:32 878
    void update()
89c4a3a6 sago007 2008-08-29 14:32 879
    {
89c4a3a6 sago007 2008-08-29 14:32 880
        double timePassed = (((double)(currentTime-lastTime))/1000.0);  //time passed in seconds
89c4a3a6 sago007 2008-08-29 14:32 881
        x = x+timePassed*velocityX;
89c4a3a6 sago007 2008-08-29 14:32 882
        y = y+timePassed*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 883
        velocityY = velocityY + gravity*timePassed;
89c4a3a6 sago007 2008-08-29 14:32 884
        if (y<1.0)
89c4a3a6 sago007 2008-08-29 14:32 885
            velocityY=10.0;
89c4a3a6 sago007 2008-08-29 14:32 886
        if ((velocityY>minVelocity) && (y>(double)(768-ballSize)) && (y<768.0))
89c4a3a6 sago007 2008-08-29 14:32 887
        {
89c4a3a6 sago007 2008-08-29 14:32 888
            velocityY = -0.70*velocityY;
89c4a3a6 sago007 2008-08-29 14:32 889
            y = 768.0-ballSize;
89c4a3a6 sago007 2008-08-29 14:32 890
        }
89c4a3a6 sago007 2008-08-29 14:32 891
        lastTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 892
    }
89c4a3a6 sago007 2008-08-29 14:32 893
89c4a3a6 sago007 2008-08-29 14:32 894
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 895
    {
89c4a3a6 sago007 2008-08-29 14:32 896
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 897
    }
89c4a3a6 sago007 2008-08-29 14:32 898
89c4a3a6 sago007 2008-08-29 14:32 899
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 900
    {
89c4a3a6 sago007 2008-08-29 14:32 901
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 902
    }
89c4a3a6 sago007 2008-08-29 14:32 903
89c4a3a6 sago007 2008-08-29 14:32 904
    int getColor()
89c4a3a6 sago007 2008-08-29 14:32 905
    {
89c4a3a6 sago007 2008-08-29 14:32 906
        return color;
89c4a3a6 sago007 2008-08-29 14:32 907
    }
89c4a3a6 sago007 2008-08-29 14:32 908
};  //aBall
89c4a3a6 sago007 2008-08-29 14:32 909
4b0c248f sago007 2010-11-10 21:13 910
static const int maxNumberOfBalls = 6*12*2*2;
89c4a3a6 sago007 2008-08-29 14:32 911
89c4a3a6 sago007 2008-08-29 14:32 912
class ballManeger
89c4a3a6 sago007 2008-08-29 14:32 913
{
89c4a3a6 sago007 2008-08-29 14:32 914
public:
89c4a3a6 sago007 2008-08-29 14:32 915
    aBall ballArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 916
    bool ballUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 917
    //The old ball information is also saved so balls can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 918
    aBall oldBallArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 919
    bool oldBallUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 920
89c4a3a6 sago007 2008-08-29 14:32 921
    ballManeger()
89c4a3a6 sago007 2008-08-29 14:32 922
    {
89c4a3a6 sago007 2008-08-29 14:32 923
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 924
        {
89c4a3a6 sago007 2008-08-29 14:32 925
            ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 926
            oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 927
        }
89c4a3a6 sago007 2008-08-29 14:32 928
    }
89c4a3a6 sago007 2008-08-29 14:32 929
6d48320c sago007 2009-03-28 17:06 930
    //Adds a ball to the screen at given coordiantes, traveling right or not with color
89c4a3a6 sago007 2008-08-29 14:32 931
    int addBall(int x, int y,bool right,int color)
89c4a3a6 sago007 2008-08-29 14:32 932
    {
89c4a3a6 sago007 2008-08-29 14:32 933
        int ballNumber = 0;
6d48320c sago007 2009-03-28 17:06 934
        //Find a free ball
89c4a3a6 sago007 2008-08-29 14:32 935
        while ((ballUsed[ballNumber])&&(ballNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 936
            ballNumber++;
6d48320c sago007 2009-03-28 17:06 937
        //Could not find a free ball, return -1
89c4a3a6 sago007 2008-08-29 14:32 938
        if (ballNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 939
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 940
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 941
        ballArray[ballNumber] = aBall(x,y,right,color);
89c4a3a6 sago007 2008-08-29 14:32 942
        ballUsed[ballNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 943
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 944
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 945
89c4a3a6 sago007 2008-08-29 14:32 946
    void update()
89c4a3a6 sago007 2008-08-29 14:32 947
    {
89c4a3a6 sago007 2008-08-29 14:32 948
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 949
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 950
        {
89c4a3a6 sago007 2008-08-29 14:32 951
89c4a3a6 sago007 2008-08-29 14:32 952
            if (ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 953
            {
89c4a3a6 sago007 2008-08-29 14:32 954
                oldBallUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 955
                oldBallArray[i] = ballArray[i];
89c4a3a6 sago007 2008-08-29 14:32 956
                ballArray[i].update();
6d48320c sago007 2009-03-28 17:06 957
                if (ballArray[i].getY()>800 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize)
89c4a3a6 sago007 2008-08-29 14:32 958
                {
89c4a3a6 sago007 2008-08-29 14:32 959
                    ballUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 960
                }
89c4a3a6 sago007 2008-08-29 14:32 961
            }
89c4a3a6 sago007 2008-08-29 14:32 962
            else
89c4a3a6 sago007 2008-08-29 14:32 963
            {
89c4a3a6 sago007 2008-08-29 14:32 964
                oldBallUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 965
            }
89c4a3a6 sago007 2008-08-29 14:32 966
        }
89c4a3a6 sago007 2008-08-29 14:32 967
    } //update
89c4a3a6 sago007 2008-08-29 14:32 968
89c4a3a6 sago007 2008-08-29 14:32 969
89c4a3a6 sago007 2008-08-29 14:32 970
}; //theBallManeger
89c4a3a6 sago007 2008-08-29 14:32 971
4b0c248f sago007 2010-11-10 21:13 972
static ballManeger theBallManeger;
89c4a3a6 sago007 2008-08-29 14:32 973
89c4a3a6 sago007 2008-08-29 14:32 974
//a explosions, non moving
89c4a3a6 sago007 2008-08-29 14:32 975
class anExplosion
89c4a3a6 sago007 2008-08-29 14:32 976
{
89c4a3a6 sago007 2008-08-29 14:32 977
private:
89c4a3a6 sago007 2008-08-29 14:32 978
    int x;
89c4a3a6 sago007 2008-08-29 14:32 979
    int y;
89c4a3a6 sago007 2008-08-29 14:32 980
    Uint8 frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 981
#define frameLength 80
89c4a3a6 sago007 2008-08-29 14:32 982
    //How long an image in an animation should be showed
89c4a3a6 sago007 2008-08-29 14:32 983
#define maxFrame 4
89c4a3a6 sago007 2008-08-29 14:32 984
    //How many images there are in the animation
89c4a3a6 sago007 2008-08-29 14:32 985
    unsigned long int placeTime; //Then the explosion occored
89c4a3a6 sago007 2008-08-29 14:32 986
public:
89c4a3a6 sago007 2008-08-29 14:32 987
89c4a3a6 sago007 2008-08-29 14:32 988
    anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 989
    {}
89c4a3a6 sago007 2008-08-29 14:32 990
89c4a3a6 sago007 2008-08-29 14:32 991
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 992
    anExplosion(int X, int Y)
89c4a3a6 sago007 2008-08-29 14:32 993
    {
89c4a3a6 sago007 2008-08-29 14:32 994
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 995
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 996
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 997
        frameNumber=0;
89c4a3a6 sago007 2008-08-29 14:32 998
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 999
89c4a3a6 sago007 2008-08-29 14:32 1000
    //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1001
    ~anExplosion()
89c4a3a6 sago007 2008-08-29 14:32 1002
    {
89c4a3a6 sago007 2008-08-29 14:32 1003
    }   //Deconstructor
89c4a3a6 sago007 2008-08-29 14:32 1004
89c4a3a6 sago007 2008-08-29 14:32 1005
    //true if animation has played and object should be removed from the screen
89c4a3a6 sago007 2008-08-29 14:32 1006
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1007
    {
89c4a3a6 sago007 2008-08-29 14:32 1008
        frameNumber = (currentTime-placeTime)/frameLength;
89c4a3a6 sago007 2008-08-29 14:32 1009
        return (!(frameNumber<maxFrame));
89c4a3a6 sago007 2008-08-29 14:32 1010
    }
89c4a3a6 sago007 2008-08-29 14:32 1011
89c4a3a6 sago007 2008-08-29 14:32 1012
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1013
    {
89c4a3a6 sago007 2008-08-29 14:32 1014
        return (int)x;
89c4a3a6 sago007 2008-08-29 14:32 1015
    }
89c4a3a6 sago007 2008-08-29 14:32 1016
89c4a3a6 sago007 2008-08-29 14:32 1017
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1018
    {
89c4a3a6 sago007 2008-08-29 14:32 1019
        return (int)y;
89c4a3a6 sago007 2008-08-29 14:32 1020
    }
89c4a3a6 sago007 2008-08-29 14:32 1021
89c4a3a6 sago007 2008-08-29 14:32 1022
    int getFrame()
89c4a3a6 sago007 2008-08-29 14:32 1023
    {
89c4a3a6 sago007 2008-08-29 14:32 1024
        return frameNumber;
89c4a3a6 sago007 2008-08-29 14:32 1025
    }
89c4a3a6 sago007 2008-08-29 14:32 1026
};  //nExplosion
89c4a3a6 sago007 2008-08-29 14:32 1027
89c4a3a6 sago007 2008-08-29 14:32 1028
class explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1029
{
89c4a3a6 sago007 2008-08-29 14:32 1030
public:
89c4a3a6 sago007 2008-08-29 14:32 1031
    anExplosion explosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1032
    bool explosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1033
    //The old explosion information is also saved so explosions can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1034
    anExplosion oldExplosionArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1035
    bool oldExplosionUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1036
89c4a3a6 sago007 2008-08-29 14:32 1037
    explosionManeger()
89c4a3a6 sago007 2008-08-29 14:32 1038
    {
89c4a3a6 sago007 2008-08-29 14:32 1039
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1040
        {
89c4a3a6 sago007 2008-08-29 14:32 1041
            explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1042
            oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1043
        }
89c4a3a6 sago007 2008-08-29 14:32 1044
    }
89c4a3a6 sago007 2008-08-29 14:32 1045
89c4a3a6 sago007 2008-08-29 14:32 1046
    int addExplosion(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 1047
    {
89c4a3a6 sago007 2008-08-29 14:32 1048
        //cout << "Tries to add an explosion" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1049
        int explosionNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1050
        while ((explosionUsed[explosionNumber])&&(explosionNumber<maxNumberOfBalls))
89c4a3a6 sago007 2008-08-29 14:32 1051
            explosionNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1052
        if (explosionNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1053
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1054
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1055
        explosionArray[explosionNumber] = anExplosion(x,y);
89c4a3a6 sago007 2008-08-29 14:32 1056
        explosionUsed[explosionNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1057
        //cout << "Explosion added" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1058
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1059
    }  //addBall
89c4a3a6 sago007 2008-08-29 14:32 1060
89c4a3a6 sago007 2008-08-29 14:32 1061
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1062
    {
89c4a3a6 sago007 2008-08-29 14:32 1063
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1064
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1065
        {
89c4a3a6 sago007 2008-08-29 14:32 1066
89c4a3a6 sago007 2008-08-29 14:32 1067
            if (explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1068
            {
89c4a3a6 sago007 2008-08-29 14:32 1069
                oldExplosionUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1070
                oldExplosionArray[i] = explosionArray[i];
89c4a3a6 sago007 2008-08-29 14:32 1071
                if (explosionArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1072
                {
89c4a3a6 sago007 2008-08-29 14:32 1073
                    explosionArray[i].~anExplosion();
89c4a3a6 sago007 2008-08-29 14:32 1074
                    explosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1075
                    //cout << "Explosion removed" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1076
                }
89c4a3a6 sago007 2008-08-29 14:32 1077
            }
89c4a3a6 sago007 2008-08-29 14:32 1078
            else
89c4a3a6 sago007 2008-08-29 14:32 1079
            {
89c4a3a6 sago007 2008-08-29 14:32 1080
                oldExplosionUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1081
            }
89c4a3a6 sago007 2008-08-29 14:32 1082
        }
89c4a3a6 sago007 2008-08-29 14:32 1083
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1084
89c4a3a6 sago007 2008-08-29 14:32 1085
89c4a3a6 sago007 2008-08-29 14:32 1086
}; //explosionManeger
89c4a3a6 sago007 2008-08-29 14:32 1087
4b0c248f sago007 2010-11-10 21:13 1088
static explosionManeger theExplosionManeger;
89c4a3a6 sago007 2008-08-29 14:32 1089
89c4a3a6 sago007 2008-08-29 14:32 1090
//text pop-up
89c4a3a6 sago007 2008-08-29 14:32 1091
class textMessage
89c4a3a6 sago007 2008-08-29 14:32 1092
{
89c4a3a6 sago007 2008-08-29 14:32 1093
private:
89c4a3a6 sago007 2008-08-29 14:32 1094
    int x;
89c4a3a6 sago007 2008-08-29 14:32 1095
    int y;
89c4a3a6 sago007 2008-08-29 14:32 1096
    char textt[10];
89c4a3a6 sago007 2008-08-29 14:32 1097
    unsigned long int time;
89c4a3a6 sago007 2008-08-29 14:32 1098
    unsigned long int placeTime; //Then the text was placed
89c4a3a6 sago007 2008-08-29 14:32 1099
public:
89c4a3a6 sago007 2008-08-29 14:32 1100
89c4a3a6 sago007 2008-08-29 14:32 1101
    textMessage()
89c4a3a6 sago007 2008-08-29 14:32 1102
    {}
89c4a3a6 sago007 2008-08-29 14:32 1103
89c4a3a6 sago007 2008-08-29 14:32 1104
    //constructor:
89c4a3a6 sago007 2008-08-29 14:32 1105
    textMessage(int X, int Y,const char* Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1106
    {
89c4a3a6 sago007 2008-08-29 14:32 1107
        placeTime = currentTime;
89c4a3a6 sago007 2008-08-29 14:32 1108
        x = X;
89c4a3a6 sago007 2008-08-29 14:32 1109
        y = Y;
89c4a3a6 sago007 2008-08-29 14:32 1110
        strncpy(textt,Text,10);
89c4a3a6 sago007 2008-08-29 14:32 1111
        textt[9]=0;
89c4a3a6 sago007 2008-08-29 14:32 1112
        time = Time;
89c4a3a6 sago007 2008-08-29 14:32 1113
    }  //constructor
89c4a3a6 sago007 2008-08-29 14:32 1114
89c4a3a6 sago007 2008-08-29 14:32 1115
    //true if the text has expired
89c4a3a6 sago007 2008-08-29 14:32 1116
    bool removeMe()
89c4a3a6 sago007 2008-08-29 14:32 1117
    {
89c4a3a6 sago007 2008-08-29 14:32 1118
        return currentTime-placeTime>time;
89c4a3a6 sago007 2008-08-29 14:32 1119
    }
89c4a3a6 sago007 2008-08-29 14:32 1120
89c4a3a6 sago007 2008-08-29 14:32 1121
    int getX()
89c4a3a6 sago007 2008-08-29 14:32 1122
    {
89c4a3a6 sago007 2008-08-29 14:32 1123
        return x;
89c4a3a6 sago007 2008-08-29 14:32 1124
    }
89c4a3a6 sago007 2008-08-29 14:32 1125
89c4a3a6 sago007 2008-08-29 14:32 1126
    int getY()
89c4a3a6 sago007 2008-08-29 14:32 1127
    {
89c4a3a6 sago007 2008-08-29 14:32 1128
        return y;
89c4a3a6 sago007 2008-08-29 14:32 1129
    }
89c4a3a6 sago007 2008-08-29 14:32 1130
89c4a3a6 sago007 2008-08-29 14:32 1131
    char* getText()
89c4a3a6 sago007 2008-08-29 14:32 1132
    {
89c4a3a6 sago007 2008-08-29 14:32 1133
        return textt;
89c4a3a6 sago007 2008-08-29 14:32 1134
    }
89c4a3a6 sago007 2008-08-29 14:32 1135
};  //text popup
89c4a3a6 sago007 2008-08-29 14:32 1136
89c4a3a6 sago007 2008-08-29 14:32 1137
class textManeger
89c4a3a6 sago007 2008-08-29 14:32 1138
{
89c4a3a6 sago007 2008-08-29 14:32 1139
public:
89c4a3a6 sago007 2008-08-29 14:32 1140
    textMessage textArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1141
    bool textUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1142
    //The old text information is also saved so text can be deleted!
89c4a3a6 sago007 2008-08-29 14:32 1143
    textMessage oldTextArray[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1144
    bool oldTextUsed[maxNumberOfBalls];
89c4a3a6 sago007 2008-08-29 14:32 1145
89c4a3a6 sago007 2008-08-29 14:32 1146
    textManeger()
89c4a3a6 sago007 2008-08-29 14:32 1147
    {
89c4a3a6 sago007 2008-08-29 14:32 1148
        for (int i=0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1149
        {
89c4a3a6 sago007 2008-08-29 14:32 1150
            textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1151
            oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1152
        }
89c4a3a6 sago007 2008-08-29 14:32 1153
    }
89c4a3a6 sago007 2008-08-29 14:32 1154
89c4a3a6 sago007 2008-08-29 14:32 1155
    int addText(int x, int y,string Text,unsigned int Time)
89c4a3a6 sago007 2008-08-29 14:32 1156
    {
89c4a3a6 sago007 2008-08-29 14:32 1157
        //cout << "Tries to add text" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1158
        int textNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 1159
        while ((textNumber<maxNumberOfBalls)&&((textUsed[textNumber])||(oldTextUsed[textNumber])))
89c4a3a6 sago007 2008-08-29 14:32 1160
            textNumber++;
89c4a3a6 sago007 2008-08-29 14:32 1161
        if (textNumber==maxNumberOfBalls)
89c4a3a6 sago007 2008-08-29 14:32 1162
            return -1;
89c4a3a6 sago007 2008-08-29 14:32 1163
        //cout << "adding to: " << textNumber << ":" << textUsed[textNumber] << ":" << &textArray[textNumber] << endl;
89c4a3a6 sago007 2008-08-29 14:32 1164
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1165
        textArray[textNumber] = textMessage(x,y,Text.c_str(),Time);
89c4a3a6 sago007 2008-08-29 14:32 1166
        textUsed[textNumber] = true;
89c4a3a6 sago007 2008-08-29 14:32 1167
        return 1;
89c4a3a6 sago007 2008-08-29 14:32 1168
    }  //addText
89c4a3a6 sago007 2008-08-29 14:32 1169
89c4a3a6 sago007 2008-08-29 14:32 1170
    void update()
89c4a3a6 sago007 2008-08-29 14:32 1171
    {
89c4a3a6 sago007 2008-08-29 14:32 1172
        //cout << "Running update" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1173
        currentTime = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1174
        for (int i = 0; i<maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 1175
        {
89c4a3a6 sago007 2008-08-29 14:32 1176
89c4a3a6 sago007 2008-08-29 14:32 1177
            if (textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1178
            {
89c4a3a6 sago007 2008-08-29 14:32 1179
                if (!oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1180
                {
89c4a3a6 sago007 2008-08-29 14:32 1181
                    oldTextUsed[i] = true;
89c4a3a6 sago007 2008-08-29 14:32 1182
                    oldTextArray[i] = textMessage(textArray[i]);
89c4a3a6 sago007 2008-08-29 14:32 1183
                }
89c4a3a6 sago007 2008-08-29 14:32 1184
                if (textArray[i].removeMe())
89c4a3a6 sago007 2008-08-29 14:32 1185
                {
89c4a3a6 sago007 2008-08-29 14:32 1186
                    textArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1187
                    textUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1188
                }
89c4a3a6 sago007 2008-08-29 14:32 1189
            }
89c4a3a6 sago007 2008-08-29 14:32 1190
            else
89c4a3a6 sago007 2008-08-29 14:32 1191
                if (oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 1192
                {
89c4a3a6 sago007 2008-08-29 14:32 1193
                    oldTextUsed[i] = false;
89c4a3a6 sago007 2008-08-29 14:32 1194
                    oldTextArray[i].~textMessage();
89c4a3a6 sago007 2008-08-29 14:32 1195
                }
89c4a3a6 sago007 2008-08-29 14:32 1196
        }
89c4a3a6 sago007 2008-08-29 14:32 1197
    } //update
89c4a3a6 sago007 2008-08-29 14:32 1198
89c4a3a6 sago007 2008-08-29 14:32 1199
89c4a3a6 sago007 2008-08-29 14:32 1200
}; //textManeger
89c4a3a6 sago007 2008-08-29 14:32 1201
4b0c248f sago007 2010-11-10 21:13 1202
static textManeger theTextManeger;
89c4a3a6 sago007 2008-08-29 14:32 1203
89c4a3a6 sago007 2008-08-29 14:32 1204
//Here comes the Block Game object
89c4a3a6 sago007 2008-08-29 14:32 1205
#include "BlockGame.hpp"
17916a2e sago007 2010-11-07 11:26 1206
#include "BlockGame.cpp"
7ca669ac sago007 2008-12-09 16:30 1207
#include "SFont.h"
89c4a3a6 sago007 2008-08-29 14:32 1208
6b1dc7a6 sago007 2010-11-08 21:03 1209
class BlockGameSdl : public BlockGame {
6b1dc7a6 sago007 2010-11-08 21:03 1210
public:
6b1dc7a6 sago007 2010-11-08 21:03 1211
    SDL_Surface* sBoard;
6b1dc7a6 sago007 2010-11-08 21:03 1212
6b1dc7a6 sago007 2010-11-08 21:03 1213
    BlockGameSdl(int tx, int ty) {
6b1dc7a6 sago007 2010-11-08 21:03 1214
        tmp = IMG_Load2((char*)"gfx/BackBoard.png");
6b1dc7a6 sago007 2010-11-08 21:03 1215
        sBoard = SDL_DisplayFormat(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1216
        SDL_FreeSurface(tmp);
6b1dc7a6 sago007 2010-11-08 21:03 1217
        //BlockGame::BlockGame(tx,ty);
6b1dc7a6 sago007 2010-11-08 21:03 1218
        BlockGame::topx = tx;
6b1dc7a6 sago007 2010-11-08 21:03 1219
        BlockGame::topy = ty;
6b1dc7a6 sago007 2010-11-08 21:03 1220
    }
6b1dc7a6 sago007 2010-11-08 21:03 1221
    ~BlockGameSdl() {
6b1dc7a6 sago007 2010-11-08 21:03 1222
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1223
    }
6b1dc7a6 sago007 2010-11-08 21:03 1224
private:
6b1dc7a6 sago007 2010-11-08 21:03 1225
    void convertSurface() {
6b1dc7a6 sago007 2010-11-08 21:03 1226
        SDL_FreeSurface(sBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1227
        sBoard = SDL_DisplayFormat(backBoard);
6b1dc7a6 sago007 2010-11-08 21:03 1228
    }
6b1dc7a6 sago007 2010-11-08 21:03 1229
    //Draws all the bricks to the board (including garbage)
6b1dc7a6 sago007 2010-11-08 21:03 1230
    void PaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1231
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1232
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1233
                if ((board[j][i]%10 != -1) && (board[j][i]%10 < 7) && ((board[j][i]/1000000)%10==0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1234
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1235
                    if ((board[j][i]/BLOCKWAIT)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1236
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1237
                    if ((board[j][i]/BLOCKHANG)%10==1)
6b1dc7a6 sago007 2010-11-08 21:03 1238
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1239
6b1dc7a6 sago007 2010-11-08 21:03 1240
                }
6b1dc7a6 sago007 2010-11-08 21:03 1241
                if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1242
                    int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1243
                    int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1244
                    if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1245
                    else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1246
                    if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1247
                    else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1248
                    if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1249
                    else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1250
                    if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1251
                    else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1252
                    if ((left == number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1253
                        DrawIMG(garbageFill, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1254
                    if ((left != number)&&(right == number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1255
                        DrawIMG(garbageL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1256
                    if ((left == number)&&(right != number)&&(over == number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1257
                        DrawIMG(garbageR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1258
                    if ((left == number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1259
                        DrawIMG(garbageT, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1260
                    if ((left == number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1261
                        DrawIMG(garbageB, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1262
                    if ((left != number)&&(right == number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1263
                        DrawIMG(garbageTL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1264
                    if ((left != number)&&(right == number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1265
                        DrawIMG(garbageBL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1266
                    if ((left == number)&&(right != number)&&(over != number)&&(under == number))
6b1dc7a6 sago007 2010-11-08 21:03 1267
                        DrawIMG(garbageTR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1268
                    if ((left == number)&&(right != number)&&(over == number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1269
                        DrawIMG(garbageBR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1270
                    if ((left == number)&&(right != number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1271
                        DrawIMG(garbageMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1272
                    if ((left == number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1273
                        DrawIMG(garbageM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1274
                    if ((left != number)&&(right == number)&&(over != number)&&(under != number))
6b1dc7a6 sago007 2010-11-08 21:03 1275
                        DrawIMG(garbageML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1276
                }
6b1dc7a6 sago007 2010-11-08 21:03 1277
                if ((board[j][i]/1000000)%10==2) {
6b1dc7a6 sago007 2010-11-08 21:03 1278
                    if (j==0)
6b1dc7a6 sago007 2010-11-08 21:03 1279
                        DrawIMG(garbageGML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1280
                    else
6b1dc7a6 sago007 2010-11-08 21:03 1281
                        if (j==5)
6b1dc7a6 sago007 2010-11-08 21:03 1282
                            DrawIMG(garbageGMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1283
                        else
6b1dc7a6 sago007 2010-11-08 21:03 1284
                            DrawIMG(garbageGM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1285
                }
6b1dc7a6 sago007 2010-11-08 21:03 1286
            }
6b1dc7a6 sago007 2010-11-08 21:03 1287
        const int j = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1288
6b1dc7a6 sago007 2010-11-08 21:03 1289
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1290
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1291
            if ((board[j][i]/1000000)%10==1) {
6b1dc7a6 sago007 2010-11-08 21:03 1292
                int left, right, over, under;
6b1dc7a6 sago007 2010-11-08 21:03 1293
                int number = board[j][i];
6b1dc7a6 sago007 2010-11-08 21:03 1294
                if (j<1) left = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1295
                else left = board[j-1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1296
                if (j>5) right = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1297
                else right = board[j+1][i];
6b1dc7a6 sago007 2010-11-08 21:03 1298
                if (i>28) over = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1299
                else over = board[j][i+1];
6b1dc7a6 sago007 2010-11-08 21:03 1300
                if (i<1) under = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1301
                else under = board[j][i-1];
6b1dc7a6 sago007 2010-11-08 21:03 1302
                if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1303
                    DrawIMG(smiley[board[j][i]%4], sBoard, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1304
                }
6b1dc7a6 sago007 2010-11-08 21:03 1305
                if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1306
                {
6b1dc7a6 sago007 2010-11-08 21:03 1307
                    garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1308
                }
6b1dc7a6 sago007 2010-11-08 21:03 1309
                else {
6b1dc7a6 sago007 2010-11-08 21:03 1310
                    //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1311
                    garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1312
                }
6b1dc7a6 sago007 2010-11-08 21:03 1313
6b1dc7a6 sago007 2010-11-08 21:03 1314
            }
6b1dc7a6 sago007 2010-11-08 21:03 1315
        }
6b1dc7a6 sago007 2010-11-08 21:03 1316
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1317
            if (board[i][0]!=-1)
6b1dc7a6 sago007 2010-11-08 21:03 1318
                DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant
6b1dc7a6 sago007 2010-11-08 21:03 1319
6b1dc7a6 sago007 2010-11-08 21:03 1320
    }
6b1dc7a6 sago007 2010-11-08 21:03 1321
    //Paints the bricks gotten from a replay/net package
6b1dc7a6 sago007 2010-11-08 21:03 1322
    void SimplePaintBricks() {
6b1dc7a6 sago007 2010-11-08 21:03 1323
        /*
6b1dc7a6 sago007 2010-11-08 21:03 1324
         * 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 1325
         */
6b1dc7a6 sago007 2010-11-08 21:03 1326
        bool bbomb[6][13]; //has a bomb on it!
6b1dc7a6 sago007 2010-11-08 21:03 1327
        bool falling[6][13]; //this is falling
6b1dc7a6 sago007 2010-11-08 21:03 1328
        bool getReady[6][13]; //getReady
6b1dc7a6 sago007 2010-11-08 21:03 1329
        for (int i=0;i<6;i++)
6b1dc7a6 sago007 2010-11-08 21:03 1330
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1331
                bbomb[i][j]=false; //All false by default
6b1dc7a6 sago007 2010-11-08 21:03 1332
                falling[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1333
                if (board[i][j]>29)
6b1dc7a6 sago007 2010-11-08 21:03 1334
                    getReady[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1335
                else
6b1dc7a6 sago007 2010-11-08 21:03 1336
                    getReady[i][j]=false;
6b1dc7a6 sago007 2010-11-08 21:03 1337
            }
6b1dc7a6 sago007 2010-11-08 21:03 1338
        //See that is falling
6b1dc7a6 sago007 2010-11-08 21:03 1339
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1340
            bool rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1341
            for (int j=0;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1342
                if (rowFalling)
6b1dc7a6 sago007 2010-11-08 21:03 1343
                    falling[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1344
                if ((!rowFalling)&&(board[i][j]%30==-1))
6b1dc7a6 sago007 2010-11-08 21:03 1345
                    rowFalling = true;
6b1dc7a6 sago007 2010-11-08 21:03 1346
                if ((rowFalling)&&(board[i][j]%30>6))
6b1dc7a6 sago007 2010-11-08 21:03 1347
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1348
                if (getReady[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1349
                    falling[i][j]=true; //getReady is the same as falling
6b1dc7a6 sago007 2010-11-08 21:03 1350
                    rowFalling = false;
6b1dc7a6 sago007 2010-11-08 21:03 1351
                }
6b1dc7a6 sago007 2010-11-08 21:03 1352
            }
6b1dc7a6 sago007 2010-11-08 21:03 1353
        }
6b1dc7a6 sago007 2010-11-08 21:03 1354
        //Now looking at rows:
6b1dc7a6 sago007 2010-11-08 21:03 1355
        for (int i=0;i<6;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1356
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1357
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1358
            for (int j=1;j<13;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1359
                if ((board[i][j]%30==color)&&(!falling[i][j]))
6b1dc7a6 sago007 2010-11-08 21:03 1360
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1361
                else
6b1dc7a6 sago007 2010-11-08 21:03 1362
                    if (falling[i][j]) {
6b1dc7a6 sago007 2010-11-08 21:03 1363
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1364
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1365
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1366
                        color=board[i][j]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1367
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1368
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1369
                if ((count>2)&&(color>-1)&&(color)<7) {
6b1dc7a6 sago007 2010-11-08 21:03 1370
                    bbomb[i][j]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1371
                    bbomb[i][j-1]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1372
                    bbomb[i][j-2]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1373
                }
6b1dc7a6 sago007 2010-11-08 21:03 1374
            }
6b1dc7a6 sago007 2010-11-08 21:03 1375
        }
6b1dc7a6 sago007 2010-11-08 21:03 1376
        //now looking for lines
6b1dc7a6 sago007 2010-11-08 21:03 1377
        for (int i=1;i<13;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1378
            int count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1379
            int color = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1380
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1381
                if ((board[j][i]%30==color)&&(!falling[j][i]))
6b1dc7a6 sago007 2010-11-08 21:03 1382
                    count++;
6b1dc7a6 sago007 2010-11-08 21:03 1383
                else
6b1dc7a6 sago007 2010-11-08 21:03 1384
                    if (falling[j][i]) {
6b1dc7a6 sago007 2010-11-08 21:03 1385
                        count = 0;
6b1dc7a6 sago007 2010-11-08 21:03 1386
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1387
                    else {
6b1dc7a6 sago007 2010-11-08 21:03 1388
                        color=board[j][i]%30;
6b1dc7a6 sago007 2010-11-08 21:03 1389
                        count=1;
6b1dc7a6 sago007 2010-11-08 21:03 1390
                    }
6b1dc7a6 sago007 2010-11-08 21:03 1391
                if ((count>2)&&(color>-1)&&(color<7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1392
                    bbomb[j][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1393
                    bbomb[j-1][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1394
                    bbomb[j-2][i]=true;
6b1dc7a6 sago007 2010-11-08 21:03 1395
                }
6b1dc7a6 sago007 2010-11-08 21:03 1396
            }
6b1dc7a6 sago007 2010-11-08 21:03 1397
        }
6b1dc7a6 sago007 2010-11-08 21:03 1398
        for (int i=0;((i<13)&&(i<30));i++)
6b1dc7a6 sago007 2010-11-08 21:03 1399
            for (int j=0;j<6;j++) {
6b1dc7a6 sago007 2010-11-08 21:03 1400
                if ((board[j][i]%10 != -1) && (board[j][i]%30 < 7)) {
6b1dc7a6 sago007 2010-11-08 21:03 1401
                    DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1402
                    if (bbomb[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1403
                        DrawIMG(bomb[(ticks/BOMBTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1404
                    if (getReady[j][i])
6b1dc7a6 sago007 2010-11-08 21:03 1405
                        DrawIMG(ready[(ticks/READYTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1406
                }
6b1dc7a6 sago007 2010-11-08 21:03 1407
                if (board[j][i]%30>6) {
6b1dc7a6 sago007 2010-11-08 21:03 1408
                    if (board[j][i]%30==7)
6b1dc7a6 sago007 2010-11-08 21:03 1409
                        DrawIMG(garbageR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1410
                    if (board[j][i]%30==9)
6b1dc7a6 sago007 2010-11-08 21:03 1411
                        DrawIMG(garbageML, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1412
                    if (board[j][i]%30==10)
6b1dc7a6 sago007 2010-11-08 21:03 1413
                        DrawIMG(garbageMR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1414
                    if (board[j][i]%30==11)
6b1dc7a6 sago007 2010-11-08 21:03 1415
                        DrawIMG(garbageTR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1416
                    if (board[j][i]%30==12)
6b1dc7a6 sago007 2010-11-08 21:03 1417
                        DrawIMG(garbageTL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1418
                    if (board[j][i]%30==13)
6b1dc7a6 sago007 2010-11-08 21:03 1419
                        DrawIMG(garbageBL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1420
                    if (board[j][i]%30==14)
6b1dc7a6 sago007 2010-11-08 21:03 1421
                        DrawIMG(garbageBR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1422
                    if (board[j][i]%30==15)
6b1dc7a6 sago007 2010-11-08 21:03 1423
                        DrawIMG(garbageM, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1424
                    if (board[j][i]%30==16)
6b1dc7a6 sago007 2010-11-08 21:03 1425
                        DrawIMG(garbageFill, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1426
                    if (board[j][i]%30==17)
6b1dc7a6 sago007 2010-11-08 21:03 1427
                        DrawIMG(garbageT, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1428
                    if (board[j][i]%30==18)
6b1dc7a6 sago007 2010-11-08 21:03 1429
                        DrawIMG(garbageB, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1430
                    if (board[j][i]%30==19)
6b1dc7a6 sago007 2010-11-08 21:03 1431
                        DrawIMG(garbageL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
6b1dc7a6 sago007 2010-11-08 21:03 1432
                    if (board[j][i]%30==20)
6b1dc7a6 sago007 2010-11-08 21:03 1433
                        switch(j) {
6b1dc7a6 sago007 2010-11-08 21:03 1434
                            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1435
                                DrawIMG(garbageGML, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1436
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1437
                            case 5:
6b1dc7a6 sago007 2010-11-08 21:03 1438
                                DrawIMG(garbageGMR, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1439
                                break;
6b1dc7a6 sago007 2010-11-08 21:03 1440
                            default:
6b1dc7a6 sago007 2010-11-08 21:03 1441
                                DrawIMG(garbageGM, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
6b1dc7a6 sago007 2010-11-08 21:03 1442
                        }
6b1dc7a6 sago007 2010-11-08 21:03 1443
                    //cout << "IS: " << board[j][i] << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1444
                }
6b1dc7a6 sago007 2010-11-08 21:03 1445
6b1dc7a6 sago007 2010-11-08 21:03 1446
6b1dc7a6 sago007 2010-11-08 21:03 1447
            }
6b1dc7a6 sago007 2010-11-08 21:03 1448
6b1dc7a6 sago007 2010-11-08 21:03 1449
        int garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1450
        for (int i=0;i<20;i++) {
6b1dc7a6 sago007 2010-11-08 21:03 1451
            if ((board[0][i]%30==12)&&(garbageSize>0)) {
6b1dc7a6 sago007 2010-11-08 21:03 1452
                DrawIMG(smiley[0], sBoard, 2*bsize, bsize-i*bsize-pixels+(bsize/2)*garbageSize);
6b1dc7a6 sago007 2010-11-08 21:03 1453
            }
6b1dc7a6 sago007 2010-11-08 21:03 1454
            if (board[0][i]%30!=19) //not in garbage
6b1dc7a6 sago007 2010-11-08 21:03 1455
            {
6b1dc7a6 sago007 2010-11-08 21:03 1456
                garbageSize=0;
6b1dc7a6 sago007 2010-11-08 21:03 1457
            }
6b1dc7a6 sago007 2010-11-08 21:03 1458
            else {
6b1dc7a6 sago007 2010-11-08 21:03 1459
                //cout << "In garbage" << endl;
6b1dc7a6 sago007 2010-11-08 21:03 1460
                garbageSize++;
6b1dc7a6 sago007 2010-11-08 21:03 1461
            }
6b1dc7a6 sago007 2010-11-08 21:03 1462
6b1dc7a6 sago007 2010-11-08 21:03 1463
        }
6b1dc7a6 sago007 2010-11-08 21:03 1464
    }
6b1dc7a6 sago007 2010-11-08 21:03 1465
public:
6b1dc7a6 sago007 2010-11-08 21:03 1466
    //Draws everything
6b1dc7a6 sago007 2010-11-08 21:03 1467
    void DoPaintJob() {
6b1dc7a6 sago007 2010-11-08 21:03 1468
        DrawIMG(backBoard, sBoard, 0, 0);
6b1dc7a6 sago007 2010-11-08 21:03 1469
        #if NETWORK
6b1dc7a6 sago007 2010-11-08 21:03 1470
        if ((!bReplaying)&&(!bNetworkPlayer))
6b1dc7a6 sago007 2010-11-08 21:03 1471
        #else
6b1dc7a6 sago007 2010-11-08 21:03 1472
        if (!bReplaying)
6b1dc7a6 sago007 2010-11-08 21:03 1473
        #endif
6b1dc7a6 sago007 2010-11-08 21:03 1474
            PaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1475
        else
6b1dc7a6 sago007 2010-11-08 21:03 1476
            SimplePaintBricks();
6b1dc7a6 sago007 2010-11-08 21:03 1477
        if (stageClear) DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1);
6b1dc7a6 sago007 2010-11-08 21:03 1478
        if (puzzleMode&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1479
            //We need to write nr. of moves left!
6b1dc7a6 sago007 2010-11-08 21:03 1480
            strHolder = "Moves left: " + itoa(MovesLeft);
6b1dc7a6 sago007 2010-11-08 21:03 1481
            SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1482
        }
6b1dc7a6 sago007 2010-11-08 21:03 1483
        if(puzzleMode && stageButtonStatus == SBpuzzleMode)
6b1dc7a6 sago007 2010-11-08 21:03 1484
        {
6b1dc7a6 sago007 2010-11-08 21:03 1485
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1486
            if(Level<nrOfPuzzles-1)
6b1dc7a6 sago007 2010-11-08 21:03 1487
            {
6b1dc7a6 sago007 2010-11-08 21:03 1488
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1489
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1490
                else
6b1dc7a6 sago007 2010-11-08 21:03 1491
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1492
            }
6b1dc7a6 sago007 2010-11-08 21:03 1493
            else
6b1dc7a6 sago007 2010-11-08 21:03 1494
            {
6b1dc7a6 sago007 2010-11-08 21:03 1495
                strHolder = "Last puzzle";
6b1dc7a6 sago007 2010-11-08 21:03 1496
                SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1497
            }
6b1dc7a6 sago007 2010-11-08 21:03 1498
        }
6b1dc7a6 sago007 2010-11-08 21:03 1499
        if(stageClear && stageButtonStatus == SBstageClear)
6b1dc7a6 sago007 2010-11-08 21:03 1500
        {
6b1dc7a6 sago007 2010-11-08 21:03 1501
            DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1502
            if(Level<50-1)
6b1dc7a6 sago007 2010-11-08 21:03 1503
            {
6b1dc7a6 sago007 2010-11-08 21:03 1504
                if(hasWonTheGame)
6b1dc7a6 sago007 2010-11-08 21:03 1505
                    DrawIMG(bNext,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1506
                else
6b1dc7a6 sago007 2010-11-08 21:03 1507
                    DrawIMG(bSkip,sBoard,cordNextButton.x, cordNextButton.y);
6b1dc7a6 sago007 2010-11-08 21:03 1508
            }
6b1dc7a6 sago007 2010-11-08 21:03 1509
            else
6b1dc7a6 sago007 2010-11-08 21:03 1510
            {
6b1dc7a6 sago007 2010-11-08 21:03 1511
                strHolder = "Last stage";
6b1dc7a6 sago007 2010-11-08 21:03 1512
                SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1513
            }
6b1dc7a6 sago007 2010-11-08 21:03 1514
        }
6b1dc7a6 sago007 2010-11-08 21:03 1515
6b1dc7a6 sago007 2010-11-08 21:03 1516
#if DEBUG
6b1dc7a6 sago007 2010-11-08 21:03 1517
        if (AI_Enabled&&(!bGameOver)) {
6b1dc7a6 sago007 2010-11-08 21:03 1518
            strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear);
6b1dc7a6 sago007 2010-11-08 21:03 1519
            SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
6b1dc7a6 sago007 2010-11-08 21:03 1520
        }
6b1dc7a6 sago007 2010-11-08 21:03 1521
#endif
6b1dc7a6 sago007 2010-11-08 21:03 1522
        if (!bGameOver)DrawIMG(cursor[(ticks/600)%2],sBoard,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
6b1dc7a6 sago007 2010-11-08 21:03 1523
        if (ticks<gameStartedAt)
6b1dc7a6 sago007 2010-11-08 21:03 1524
        {
6b1dc7a6 sago007 2010-11-08 21:03 1525
            int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1526
            if( (currentCounter!=lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1527
                Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1528
            lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1529
            switch (currentCounter) {
6b1dc7a6 sago007 2010-11-08 21:03 1530
            case 2:
6b1dc7a6 sago007 2010-11-08 21:03 1531
                DrawIMG(counter[2], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1532
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1533
            case 1:
6b1dc7a6 sago007 2010-11-08 21:03 1534
                DrawIMG(counter[1], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1535
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1536
            case 0:
6b1dc7a6 sago007 2010-11-08 21:03 1537
                DrawIMG(counter[0], sBoard, 2*bsize, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1538
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1539
            default:
6b1dc7a6 sago007 2010-11-08 21:03 1540
                break;
6b1dc7a6 sago007 2010-11-08 21:03 1541
            }
6b1dc7a6 sago007 2010-11-08 21:03 1542
        }
6b1dc7a6 sago007 2010-11-08 21:03 1543
        else
6b1dc7a6 sago007 2010-11-08 21:03 1544
        {
6b1dc7a6 sago007 2010-11-08 21:03 1545
            if(SoundEnabled&&(!NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver))
6b1dc7a6 sago007 2010-11-08 21:03 1546
            {
6b1dc7a6 sago007 2010-11-08 21:03 1547
                int currentCounter = (ticks-(int)gameStartedAt)/1000;
6b1dc7a6 sago007 2010-11-08 21:03 1548
                if(currentCounter!=lastCounter)
6b1dc7a6 sago007 2010-11-08 21:03 1549
                {
6b1dc7a6 sago007 2010-11-08 21:03 1550
                    if(currentCounter>115 && currentCounter<120)
6b1dc7a6 sago007 2010-11-08 21:03 1551
                        Mix_PlayChannel(1,counterChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1552
                }
6b1dc7a6 sago007 2010-11-08 21:03 1553
                lastCounter = currentCounter;
6b1dc7a6 sago007 2010-11-08 21:03 1554
            }
6b1dc7a6 sago007 2010-11-08 21:03 1555
            else
6b1dc7a6 sago007 2010-11-08 21:03 1556
            {
6b1dc7a6 sago007 2010-11-08 21:03 1557
                if( (0==lastCounter) && (SoundEnabled)&&(!NoSound))
6b1dc7a6 sago007 2010-11-08 21:03 1558
                {
6b1dc7a6 sago007 2010-11-08 21:03 1559
                    Mix_PlayChannel(1,counterFinalChunk,0);
6b1dc7a6 sago007 2010-11-08 21:03 1560
                }
6b1dc7a6 sago007 2010-11-08 21:03 1561
                lastCounter = -1;
6b1dc7a6 sago007 2010-11-08 21:03 1562
            }
6b1dc7a6 sago007 2010-11-08 21:03 1563
        }
6b1dc7a6 sago007 2010-11-08 21:03 1564
6b1dc7a6 sago007 2010-11-08 21:03 1565
        if ((bGameOver)&&(!editorMode))
6b1dc7a6 sago007 2010-11-08 21:03 1566
            if (hasWonTheGame)DrawIMG(iWinner, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1567
            else if (bDraw) DrawIMG(iDraw, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1568
            else
6b1dc7a6 sago007 2010-11-08 21:03 1569
                DrawIMG(iGameOver, sBoard, 0, 5*bsize);
6b1dc7a6 sago007 2010-11-08 21:03 1570
    }
6b1dc7a6 sago007 2010-11-08 21:03 1571
6b1dc7a6 sago007 2010-11-08 21:03 1572
6b1dc7a6 sago007 2010-11-08 21:03 1573
    void Update(int newtick) {
6b1dc7a6 sago007 2010-11-08 21:03 1574
        BlockGame::Update(newtick);
6b1dc7a6 sago007 2010-11-08 21:03 1575
        DoPaintJob();
6b1dc7a6 sago007 2010-11-08 21:03 1576
    }
6b1dc7a6 sago007 2010-11-08 21:03 1577
};
6b1dc7a6 sago007 2010-11-08 21:03 1578
6b1dc7a6 sago007 2010-11-08 21:03 1579
6b1dc7a6 sago007 2010-11-08 21:03 1580
6b1dc7a6 sago007 2010-11-08 21:03 1581
89c4a3a6 sago007 2008-08-29 14:32 1582
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
89c4a3a6 sago007 2008-08-29 14:32 1583
void writeScreenShot()
89c4a3a6 sago007 2008-08-29 14:32 1584
{
89c4a3a6 sago007 2008-08-29 14:32 1585
    cout << "Saving screenshot" << endl;
89c4a3a6 sago007 2008-08-29 14:32 1586
    int rightNow = (int)time(NULL);
215ca7b3 sago007 2009-03-06 16:37 1587
/*#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 1588
    char buf[514];
89c4a3a6 sago007 2008-08-29 14:32 1589
    sprintf( buf, "%s/.gamesaves/blockattack/screenshots/screenshot%i.bmp", getenv("HOME"), rightNow );
91886cae sago007 2008-09-12 16:28 1590
#elif defined(__win32__)
89c4a3a6 sago007 2008-08-29 14:32 1591
    char buf[MAX_PATH];
89c4a3a6 sago007 2008-08-29 14:32 1592
    sprintf( buf, "%s\\My Games\\blockattack\\screenshots\\screenshot%i.bmp", (getMyDocumentsPath()).c_str(), rightNow );
91886cae sago007 2008-09-12 16:28 1593
#else
91886cae sago007 2008-09-12 16:28 1594
    char buf[MAX_PATH];
91886cae sago007 2008-09-12 16:28 1595
    sprintf( buf, "screenshot%i.bmp", rightNow );
215ca7b3 sago007 2009-03-06 16:37 1596
#endif*/
215ca7b3 sago007 2009-03-06 16:37 1597
#if defined(__unix__)
215ca7b3 sago007 2009-03-06 16:37 1598
    string buf = (string)getenv("HOME")+"/.gamesaves/blockattack/screenshots/screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1599
#elif defined(__win32__)
215ca7b3 sago007 2009-03-06 16:37 1600
    string buf = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots\\screenshot"+itoa(rightNow)+".bmp";
215ca7b3 sago007 2009-03-06 16:37 1601
#else
215ca7b3 sago007 2009-03-06 16:37 1602
    string buf = "screenshot"+itoa(rightNow)+".bmp";
89c4a3a6 sago007 2008-08-29 14:32 1603
#endif
215ca7b3 sago007 2009-03-06 16:37 1604
    SDL_SaveBMP( screen, buf.c_str() );
89c4a3a6 sago007 2008-08-29 14:32 1605
    if (!NoSound)
89c4a3a6 sago007 2008-08-29 14:32 1606
        if (SoundEnabled)Mix_PlayChannel(1,photoClick,0);
89c4a3a6 sago007 2008-08-29 14:32 1607
}
89c4a3a6 sago007 2008-08-29 14:32 1608
89c4a3a6 sago007 2008-08-29 14:32 1609
//Function to return the name of a key, to be displayed...
215ca7b3 sago007 2009-03-06 16:37 1610
string getKeyName(SDLKey key)
89c4a3a6 sago007 2008-08-29 14:32 1611
{
4b0c248f sago007 2010-11-10 21:13 1612
    string keyname(SDL_GetKeyName(key));
215ca7b3 sago007 2009-03-06 16:37 1613
    return keyname;
89c4a3a6 sago007 2008-08-29 14:32 1614
}
89c4a3a6 sago007 2008-08-29 14:32 1615
89c4a3a6 sago007 2008-08-29 14:32 1616
void MakeBackground(int xsize,int ysize,BlockGame &theGame, BlockGame &theGame2);
89c4a3a6 sago007 2008-08-29 14:32 1617
89c4a3a6 sago007 2008-08-29 14:32 1618
int OpenControlsBox(int x, int y, int player)
89c4a3a6 sago007 2008-08-29 14:32 1619
{
89c4a3a6 sago007 2008-08-29 14:32 1620
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 1621
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 1622
    bool done =false;
215ca7b3 sago007 2009-03-06 16:37 1623
    string keyname;
27ae0175 sago007 2009-01-30 06:02 1624
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1625
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 1626
    {
89c4a3a6 sago007 2008-08-29 14:32 1627
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 1628
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1629
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 1630
        if (player == 0)
89c4a3a6 sago007 2008-08-29 14:32 1631
            SFont_Write(screen,fBlueFont,x+40,y+2,"Player 1 keys");
89c4a3a6 sago007 2008-08-29 14:32 1632
        else
89c4a3a6 sago007 2008-08-29 14:32 1633
            SFont_Write(screen,fBlueFont,x+40,y+2,"Player 2 keys");
89c4a3a6 sago007 2008-08-29 14:32 1634
        SFont_Write(screen,fBlueFont,x+6,y+50,"Up");
89c4a3a6 sago007 2008-08-29 14:32 1635
        keyname = getKeyName(keySettings[player].up);
215ca7b3 sago007 2009-03-06 16:37 1636
        SFont_Write(screen,fBlueFont,x+200,y+50,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1637
        SFont_Write(screen,fBlueFont,x+6,y+100,"Down");
89c4a3a6 sago007 2008-08-29 14:32 1638
        keyname = getKeyName(keySettings[player].down);
215ca7b3 sago007 2009-03-06 16:37 1639
        SFont_Write(screen,fBlueFont,x+200,y+100,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1640
        SFont_Write(screen,fBlueFont,x+6,y+150,"Left");
89c4a3a6 sago007 2008-08-29 14:32 1641
        keyname = getKeyName(keySettings[player].left);
215ca7b3 sago007 2009-03-06 16:37 1642
        SFont_Write(screen,fBlueFont,x+200,y+150,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1643
        SFont_Write(screen,fBlueFont,x+6,y+200,"Right");
89c4a3a6 sago007 2008-08-29 14:32 1644
        keyname = getKeyName(keySettings[player].right);
215ca7b3 sago007 2009-03-06 16:37 1645
        SFont_Write(screen,fBlueFont,x+200,y+200,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1646
        SFont_Write(screen,fBlueFont,x+6,y+250,"Push");
89c4a3a6 sago007 2008-08-29 14:32 1647
        keyname = getKeyName(keySettings[player].push);
215ca7b3 sago007 2009-03-06 16:37 1648
        SFont_Write(screen,fBlueFont,x+200,y+250,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1649
        SFont_Write(screen,fBlueFont,x+6,y+300,"Change");
89c4a3a6 sago007 2008-08-29 14:32 1650
        keyname = getKeyName(keySettings[player].change);
215ca7b3 sago007 2009-03-06 16:37 1651
        SFont_Write(screen,fBlueFont,x+200,y+300,keyname.c_str());
89c4a3a6 sago007 2008-08-29 14:32 1652
        //Ask for mouse play
89c4a3a6 sago007 2008-08-29 14:32 1653
        SFont_Write(screen,fBlueFont,x+6,y+350,"Mouse play?");
89c4a3a6 sago007 2008-08-29 14:32 1654
        DrawIMG(iLevelCheckBox,screen,x+220,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1655
        if (((player==0)&&(mouseplay1))||((player==2)&&(mouseplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1656
            DrawIMG(iLevelCheck,screen,x+220,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1657
        //Ask for joypad play
89c4a3a6 sago007 2008-08-29 14:32 1658
        SFont_Write(screen,fBlueFont,x+300,y+350,"Joypad?");
89c4a3a6 sago007 2008-08-29 14:32 1659
        DrawIMG(iLevelCheckBox,screen,x+460,y+350);
89c4a3a6 sago007 2008-08-29 14:32 1660
        if (((player==0)&&(joyplay1))||((player==2)&&(joyplay2)))
89c4a3a6 sago007 2008-08-29 14:32 1661
            DrawIMG(iLevelCheck,screen,x+460,y+350); //iLevelCheck witdh is 42
89c4a3a6 sago007 2008-08-29 14:32 1662
        for (int i=1; i<7; i++)
89c4a3a6 sago007 2008-08-29 14:32 1663
            DrawIMG(bChange,screen,x+420,y+50*i);
89c4a3a6 sago007 2008-08-29 14:32 1664
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1665
89c4a3a6 sago007 2008-08-29 14:32 1666
        while (SDL_PollEvent(&event))
89c4a3a6 sago007 2008-08-29 14:32 1667
        {
89c4a3a6 sago007 2008-08-29 14:32 1668
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 1669
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1670
            }
89c4a3a6 sago007 2008-08-29 14:32 1671
89c4a3a6 sago007 2008-08-29 14:32 1672
            if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1673
            {
89c4a3a6 sago007 2008-08-29 14:32 1674
                if (event.key.keysym.sym == SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1675
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1676
            }
89c4a3a6 sago007 2008-08-29 14:32 1677
        }	//PollEvent
89c4a3a6 sago007 2008-08-29 14:32 1678
89c4a3a6 sago007 2008-08-29 14:32 1679
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1680
89c4a3a6 sago007 2008-08-29 14:32 1681
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 1682
89c4a3a6 sago007 2008-08-29 14:32 1683
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 1684
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 1685
        {
89c4a3a6 sago007 2008-08-29 14:32 1686
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 1687
        }
89c4a3a6 sago007 2008-08-29 14:32 1688
89c4a3a6 sago007 2008-08-29 14:32 1689
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 1690
        {
89c4a3a6 sago007 2008-08-29 14:32 1691
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 1692
89c4a3a6 sago007 2008-08-29 14:32 1693
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(50+y)) && (mousey<(90+y)))
89c4a3a6 sago007 2008-08-29 14:32 1694
            {
89c4a3a6 sago007 2008-08-29 14:32 1695
                //up
89c4a3a6 sago007 2008-08-29 14:32 1696
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1697
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1698
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1699
                    {
89c4a3a6 sago007 2008-08-29 14:32 1700
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1701
                        {
89c4a3a6 sago007 2008-08-29 14:32 1702
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1703
                                keySettings[player].up = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1704
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1705
                        }
89c4a3a6 sago007 2008-08-29 14:32 1706
                    }
89c4a3a6 sago007 2008-08-29 14:32 1707
            } //up
89c4a3a6 sago007 2008-08-29 14:32 1708
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(100+y)) && (mousey<(140+y)))
89c4a3a6 sago007 2008-08-29 14:32 1709
            {
89c4a3a6 sago007 2008-08-29 14:32 1710
                //down
89c4a3a6 sago007 2008-08-29 14:32 1711
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1712
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1713
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1714
                    {
89c4a3a6 sago007 2008-08-29 14:32 1715
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1716
                        {
89c4a3a6 sago007 2008-08-29 14:32 1717
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1718
                                keySettings[player].down = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1719
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1720
                        }
89c4a3a6 sago007 2008-08-29 14:32 1721
                    }
89c4a3a6 sago007 2008-08-29 14:32 1722
            } //down
89c4a3a6 sago007 2008-08-29 14:32 1723
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(150+y)) && (mousey<(190+y)))
89c4a3a6 sago007 2008-08-29 14:32 1724
            {
89c4a3a6 sago007 2008-08-29 14:32 1725
                //left
89c4a3a6 sago007 2008-08-29 14:32 1726
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1727
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1728
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1729
                    {
89c4a3a6 sago007 2008-08-29 14:32 1730
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1731
                        {
89c4a3a6 sago007 2008-08-29 14:32 1732
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1733
                                keySettings[player].left = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1734
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1735
                        }
89c4a3a6 sago007 2008-08-29 14:32 1736
                    }
89c4a3a6 sago007 2008-08-29 14:32 1737
            } //left
89c4a3a6 sago007 2008-08-29 14:32 1738
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(200+y)) && (mousey<(240+y)))
89c4a3a6 sago007 2008-08-29 14:32 1739
            {
89c4a3a6 sago007 2008-08-29 14:32 1740
                //right
89c4a3a6 sago007 2008-08-29 14:32 1741
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1742
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1743
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1744
                    {
89c4a3a6 sago007 2008-08-29 14:32 1745
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1746
                        {
89c4a3a6 sago007 2008-08-29 14:32 1747
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1748
                                keySettings[player].right = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1749
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1750
                        }
89c4a3a6 sago007 2008-08-29 14:32 1751
                    }
89c4a3a6 sago007 2008-08-29 14:32 1752
            } //right
89c4a3a6 sago007 2008-08-29 14:32 1753
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(250+y)) && (mousey<(290+y)))
89c4a3a6 sago007 2008-08-29 14:32 1754
            {
89c4a3a6 sago007 2008-08-29 14:32 1755
                //push
89c4a3a6 sago007 2008-08-29 14:32 1756
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1757
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1758
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1759
                    {
89c4a3a6 sago007 2008-08-29 14:32 1760
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1761
                        {
89c4a3a6 sago007 2008-08-29 14:32 1762
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1763
                                keySettings[player].push = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1764
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1765
                        }
89c4a3a6 sago007 2008-08-29 14:32 1766
                    }
89c4a3a6 sago007 2008-08-29 14:32 1767
            } //push
89c4a3a6 sago007 2008-08-29 14:32 1768
            if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(300+y)) && (mousey<(340+y)))
89c4a3a6 sago007 2008-08-29 14:32 1769
            {
89c4a3a6 sago007 2008-08-29 14:32 1770
                //change
89c4a3a6 sago007 2008-08-29 14:32 1771
                bool finnish = false;
89c4a3a6 sago007 2008-08-29 14:32 1772
                while (!finnish)
89c4a3a6 sago007 2008-08-29 14:32 1773
                    while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1774
                    {
89c4a3a6 sago007 2008-08-29 14:32 1775
                        if (event.type == SDL_KEYDOWN)
89c4a3a6 sago007 2008-08-29 14:32 1776
                        {
89c4a3a6 sago007 2008-08-29 14:32 1777
                            if (event.key.keysym.sym != SDLK_ESCAPE)
89c4a3a6 sago007 2008-08-29 14:32 1778
                                keySettings[player].change = event.key.keysym.sym;
89c4a3a6 sago007 2008-08-29 14:32 1779
                            finnish = true;
89c4a3a6 sago007 2008-08-29 14:32 1780
                        }
89c4a3a6 sago007 2008-08-29 14:32 1781
                    }
89c4a3a6 sago007 2008-08-29 14:32 1782
            } //change
89c4a3a6 sago007 2008-08-29 14:32 1783
            //mouseplay:
89c4a3a6 sago007 2008-08-29 14:32 1784
            if ((mousex>(220+x)) && (mousex<(262+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1785
            {
89c4a3a6 sago007 2008-08-29 14:32 1786
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1787
                {
89c4a3a6 sago007 2008-08-29 14:32 1788
                    mouseplay1 = !mouseplay1;
89c4a3a6 sago007 2008-08-29 14:32 1789
                }
89c4a3a6 sago007 2008-08-29 14:32 1790
                else
89c4a3a6 sago007 2008-08-29 14:32 1791
                {
89c4a3a6 sago007 2008-08-29 14:32 1792
                    mouseplay2 = !mouseplay2;
89c4a3a6 sago007 2008-08-29 14:32 1793
                }
89c4a3a6 sago007 2008-08-29 14:32 1794
            }
89c4a3a6 sago007 2008-08-29 14:32 1795
            //Joyplay:
89c4a3a6 sago007 2008-08-29 14:32 1796
            if ((mousex>(460+x)) && (mousex<(502+x)) && (mousey>(350+y)) && (mousey<(392+y)))
89c4a3a6 sago007 2008-08-29 14:32 1797
            {
89c4a3a6 sago007 2008-08-29 14:32 1798
                if (player==0)
89c4a3a6 sago007 2008-08-29 14:32 1799
                {
89c4a3a6 sago007 2008-08-29 14:32 1800
                    joyplay1 = !joyplay1;
89c4a3a6 sago007 2008-08-29 14:32 1801
                }
89c4a3a6 sago007 2008-08-29 14:32 1802
                else
89c4a3a6 sago007 2008-08-29 14:32 1803
                {
89c4a3a6 sago007 2008-08-29 14:32 1804
                    joyplay2 = !joyplay2;
89c4a3a6 sago007 2008-08-29 14:32 1805
                }
89c4a3a6 sago007 2008-08-29 14:32 1806
            }
89c4a3a6 sago007 2008-08-29 14:32 1807
        }	//get mouse state
89c4a3a6 sago007 2008-08-29 14:32 1808
8d488d32 sago007 2011-04-17 13:02 1809
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 1810
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 1811
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 1812
    }	//while !done
89c4a3a6 sago007 2008-08-29 14:32 1813
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 1814
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 1815
}
89c4a3a6 sago007 2008-08-29 14:32 1816
89c4a3a6 sago007 2008-08-29 14:32 1817
89c4a3a6 sago007 2008-08-29 14:32 1818
//Dialogbox
89c4a3a6 sago007 2008-08-29 14:32 1819
bool OpenDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 1820
{
89c4a3a6 sago007 2008-08-29 14:32 1821
    bool done = false;     //We are done!
89c4a3a6 sago007 2008-08-29 14:32 1822
    bool accept = false;   //New name is accepted! (not Cancelled)
89c4a3a6 sago007 2008-08-29 14:32 1823
    bool repeating = false; //The key is being held (BACKSPACE)
89c4a3a6 sago007 2008-08-29 14:32 1824
    const int repeatDelay = 200;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 1825
    unsigned long time = 0;
89c4a3a6 sago007 2008-08-29 14:32 1826
    ReadKeyboard rk = ReadKeyboard(name);
89c4a3a6 sago007 2008-08-29 14:32 1827
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 1828
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 1829
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 1830
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 1831
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 1832
    {
89c4a3a6 sago007 2008-08-29 14:32 1833
        DrawIMG(dialogBox,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 1834
        SFont_Write(screen,fBlueFont,x+40,y+72,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1835
        strHolder = rk.GetString();
89c4a3a6 sago007 2008-08-29 14:32 1836
        strHolder.erase((int)rk.CharsBeforeCursor());
89c4a3a6 sago007 2008-08-29 14:32 1837
89c4a3a6 sago007 2008-08-29 14:32 1838
        if (((SDL_GetTicks()/600)%2)==1)
89c4a3a6 sago007 2008-08-29 14:32 1839
            SFont_Write(screen,fBlueFont,x+40+SFont_TextWidth(fBlueFont,strHolder.c_str()),y+69,"|");
89c4a3a6 sago007 2008-08-29 14:32 1840
89c4a3a6 sago007 2008-08-29 14:32 1841
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 1842
89c4a3a6 sago007 2008-08-29 14:32 1843
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 1844
        {
89c4a3a6 sago007 2008-08-29 14:32 1845
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 1846
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 1847
                accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1848
            }
89c4a3a6 sago007 2008-08-29 14:32 1849
89c4a3a6 sago007 2008-08-29 14:32 1850
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 1851
            {
89c4a3a6 sago007 2008-08-29 14:32 1852
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
89c4a3a6 sago007 2008-08-29 14:32 1853
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 1854
                    accept = true;
89c4a3a6 sago007 2008-08-29 14:32 1855
                }
89c4a3a6 sago007 2008-08-29 14:32 1856
                else
89c4a3a6 sago007 2008-08-29 14:32 1857
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 1858
                        done = true;
89c4a3a6 sago007 2008-08-29 14:32 1859
                        accept = false;
89c4a3a6 sago007 2008-08-29 14:32 1860
                    }
89c4a3a6 sago007 2008-08-29 14:32 1861
                    else if (!(event.key.keysym.sym == SDLK_BACKSPACE)){
89c4a3a6 sago007 2008-08-29 14:32 1862
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1863
                    }
89c4a3a6 sago007 2008-08-29 14:32 1864
                    else if ((event.key.keysym.sym == SDLK_BACKSPACE)&&(!repeating)){
89c4a3a6 sago007 2008-08-29 14:32 1865
                        if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
89c4a3a6 sago007 2008-08-29 14:32 1866
                        repeating = true;
89c4a3a6 sago007 2008-08-29 14:32 1867
                        time=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1868
                    }
89c4a3a6 sago007 2008-08-29 14:32 1869
            }
89c4a3a6 sago007 2008-08-29 14:32 1870
89c4a3a6 sago007 2008-08-29 14:32 1871
        }	//while(event)
89c4a3a6 sago007 2008-08-29 14:32 1872
89c4a3a6 sago007 2008-08-29 14:32 1873
        if (SDL_GetTicks()>(time+repeatDelay))
89c4a3a6 sago007 2008-08-29 14:32 1874
        {
89c4a3a6 sago007 2008-08-29 14:32 1875
            time = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 1876
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 1877
            if ( (keys[SDLK_BACKSPACE])&&(repeating) )
89c4a3a6 sago007 2008-08-29 14:32 1878
            {
89c4a3a6 sago007 2008-08-29 14:32 1879
                if ((rk.ReadKey(SDLK_BACKSPACE))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0);
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
                repeating = false;
89c4a3a6 sago007 2008-08-29 14:32 1883
        }
89c4a3a6 sago007 2008-08-29 14:32 1884
89c4a3a6 sago007 2008-08-29 14:32 1885
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 1886
    }	//while(!done)
89c4a3a6 sago007 2008-08-29 14:32 1887
    strcpy(name,rk.GetString());
89c4a3a6 sago007 2008-08-29 14:32 1888
    bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 1889
    showDialog = false;
89c4a3a6 sago007 2008-08-29 14:32 1890
    return accept;
89c4a3a6 sago007 2008-08-29 14:32 1891
}
89c4a3a6 sago007 2008-08-29 14:32 1892
47529580 sago007 2008-12-09 02:34 1893
//Draws the highscores
47529580 sago007 2008-12-09 02:34 1894
void DrawHighscores(int x, int y, bool endless)
47529580 sago007 2008-12-09 02:34 1895
{
27ae0175 sago007 2009-01-30 06:02 1896
    MakeBackground(xsize,ysize);
47529580 sago007 2008-12-09 02:34 1897
    DrawIMG(background,screen,0,0);
47529580 sago007 2008-12-09 02:34 1898
    if (endless) SFont_Write(screen,fBlueFont,x+100,y+100,"Endless:");
47529580 sago007 2008-12-09 02:34 1899
    else SFont_Write(screen,fBlueFont,x+100,y+100,"Time Trial:");
47529580 sago007 2008-12-09 02:34 1900
    for (int i =0;i<10;i++)
47529580 sago007 2008-12-09 02:34 1901
    {
47529580 sago007 2008-12-09 02:34 1902
        char playerScore[32];
47529580 sago007 2008-12-09 02:34 1903
        char playerName[32];
47529580 sago007 2008-12-09 02:34 1904
        if (endless)
47529580 sago007 2008-12-09 02:34 1905
        {
47529580 sago007 2008-12-09 02:34 1906
            sprintf(playerScore, "%i", theTopScoresEndless.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1907
        }
47529580 sago007 2008-12-09 02:34 1908
        else
47529580 sago007 2008-12-09 02:34 1909
        {
47529580 sago007 2008-12-09 02:34 1910
            sprintf(playerScore, "%i", theTopScoresTimeTrial.getScoreNumber(i));
47529580 sago007 2008-12-09 02:34 1911
        }
47529580 sago007 2008-12-09 02:34 1912
        if (endless)
47529580 sago007 2008-12-09 02:34 1913
        {
47529580 sago007 2008-12-09 02:34 1914
            strcpy(playerName,theTopScoresEndless.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1915
        }
47529580 sago007 2008-12-09 02:34 1916
        else
47529580 sago007 2008-12-09 02:34 1917
        {
47529580 sago007 2008-12-09 02:34 1918
            strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
47529580 sago007 2008-12-09 02:34 1919
        }
47529580 sago007 2008-12-09 02:34 1920
        SFont_Write(screen,fBlueFont,x+420,y+150+i*35,playerScore);
47529580 sago007 2008-12-09 02:34 1921
        SFont_Write(screen,fBlueFont,x+60,y+150+i*35,playerName);
47529580 sago007 2008-12-09 02:34 1922
    }
47529580 sago007 2008-12-09 02:34 1923
}
47529580 sago007 2008-12-09 02:34 1924
47529580 sago007 2008-12-09 02:34 1925
void DrawStats()
81d9c25d sago007 2008-11-24 09:50 1926
{
27ae0175 sago007 2009-01-30 06:02 1927
    MakeBackground(xsize,ysize);
81d9c25d sago007 2008-11-24 09:50 1928
    DrawIMG(background,screen,0,0);
81d9c25d sago007 2008-11-24 09:50 1929
    int y = 5;
81d9c25d sago007 2008-11-24 09:50 1930
    const int y_spacing = 30;
81d9c25d sago007 2008-11-24 09:50 1931
    SFont_Write(screen,fBlueFont,10,y,"Stats");
81d9c25d sago007 2008-11-24 09:50 1932
    y+=y_spacing*2;
81d9c25d sago007 2008-11-24 09:50 1933
    SFont_Write(screen,fBlueFont,10,y,"Chains");
81d9c25d sago007 2008-11-24 09:50 1934
    for(int i=2;i<13;i++)
81d9c25d sago007 2008-11-24 09:50 1935
    {
81d9c25d sago007 2008-11-24 09:50 1936
        y+=y_spacing;
81d9c25d sago007 2008-11-24 09:50 1937
        SFont_Write(screen,fBlueFont,10,y,(itoa(i)+"X").c_str());
81d9c25d sago007 2008-11-24 09:50 1938
        string numberAsString = itoa(Stats::getInstance()->getNumberOf("chainX"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 1939
        SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
81d9c25d sago007 2008-11-24 09:50 1940
    }
81d9c25d sago007 2008-11-24 09:50 1941
    y+=y_spacing*2;
81d9c25d sago007 2008-11-24 09:50 1942
    SFont_Write(screen,fBlueFont,10,y,"Lines Pushed: ");
81d9c25d sago007 2008-11-24 09:50 1943
    string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed"));
81d9c25d sago007 2008-11-24 09:50 1944
    SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 1945
81d9c25d sago007 2008-11-24 09:50 1946
    y+=y_spacing;
81d9c25d sago007 2008-11-24 09:50 1947
    SFont_Write(screen,fBlueFont,10,y,"Puzzles solved: ");
81d9c25d sago007 2008-11-24 09:50 1948
    numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved"));
81d9c25d sago007 2008-11-24 09:50 1949
    SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
47529580 sago007 2008-12-09 02:34 1950
d07b805e sago007 2009-01-27 13:15 1951
    y+=y_spacing*2;
d07b805e sago007 2009-01-27 13:15 1952
    SFont_Write(screen,fBlueFont,10,y,"Run time: ");
cd12e0fe sago007 2009-01-29 08:47 1953
    commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
d07b805e sago007 2009-01-27 13:15 1954
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 1955
    SFont_Write(screen,fBlueFont,10,y,((string)("Days: "+itoa(ct.days))).c_str());
d07b805e sago007 2009-01-27 13:15 1956
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 1957
    SFont_Write(screen,fBlueFont,10,y,((string)("Hours: "+itoa(ct.hours))).c_str());
d07b805e sago007 2009-01-27 13:15 1958
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 1959
    SFont_Write(screen,fBlueFont,10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
d07b805e sago007 2009-01-27 13:15 1960
    y+=y_spacing;
d07b805e sago007 2009-01-27 13:15 1961
    SFont_Write(screen,fBlueFont,10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
d07b805e sago007 2009-01-27 13:15 1962
cd12e0fe sago007 2009-01-29 08:47 1963
    y-=y_spacing*4; //Four rows back
27ae0175 sago007 2009-01-30 06:02 1964
    const int x_offset3 = xsize/3+10; //Ofset for three rows
cd12e0fe sago007 2009-01-29 08:47 1965
    SFont_Write(screen,fBlueFont,x_offset3,y,"Play time: ");
cd12e0fe sago007 2009-01-29 08:47 1966
    ct = TimeHandler::getTime("playTime");
cd12e0fe sago007 2009-01-29 08:47 1967
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 1968
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Days: "+itoa(ct.days))).c_str());
cd12e0fe sago007 2009-01-29 08:47 1969
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 1970
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Hours: "+itoa(ct.hours))).c_str());
cd12e0fe sago007 2009-01-29 08:47 1971
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 1972
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
cd12e0fe sago007 2009-01-29 08:47 1973
    y+=y_spacing;
cd12e0fe sago007 2009-01-29 08:47 1974
    SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
cd12e0fe sago007 2009-01-29 08:47 1975
27ae0175 sago007 2009-01-30 06:02 1976
    const int x_offset = xsize/2+10;
81d9c25d sago007 2008-11-24 09:50 1977
    y = 5+y_spacing*2;
81d9c25d sago007 2008-11-24 09:50 1978
    SFont_Write(screen,fBlueFont,x_offset,y,"VS CPU (win/loss)");
81d9c25d sago007 2008-11-24 09:50 1979
    for(int i=0;i<7;i++)
81d9c25d sago007 2008-11-24 09:50 1980
    {
81d9c25d sago007 2008-11-24 09:50 1981
        y += y_spacing;
81d9c25d sago007 2008-11-24 09:50 1982
        SFont_Write(screen,fBlueFont,x_offset,y,("AI "+itoa(i+1)).c_str());
81d9c25d sago007 2008-11-24 09:50 1983
        numberAsString = itoa(Stats::getInstance()->getNumberOf("defeatedAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 1984
        string numberAsString2 = itoa(Stats::getInstance()->getNumberOf("defeatedByAI"+itoa(i)));
81d9c25d sago007 2008-11-24 09:50 1985
        string toPrint = numberAsString + "/" + numberAsString2;
81d9c25d sago007 2008-11-24 09:50 1986
        SFont_Write(screen,fBlueFont,x_offset+230,y,toPrint.c_str());
81d9c25d sago007 2008-11-24 09:50 1987
    }
47529580 sago007 2008-12-09 02:34 1988
}
47529580 sago007 2008-12-09 02:34 1989
47529580 sago007 2008-12-09 02:34 1990
void OpenScoresDisplay()
47529580 sago007 2008-12-09 02:34 1991
{
9050a50a sago007 2008-12-09 13:35 1992
    int mousex,mousey;
47529580 sago007 2008-12-09 02:34 1993
    bool done = false;     //We are done!
47529580 sago007 2008-12-09 02:34 1994
    int page = 0;
47529580 sago007 2008-12-09 02:34 1995
    const int numberOfPages = 3;
7ca669ac sago007 2008-12-09 16:30 1996
    //button coodinates:
7ca669ac sago007 2008-12-09 16:30 1997
    const int scoreX = buttonXsize*2;
7ca669ac sago007 2008-12-09 16:30 1998
    const int scoreY = 0;
7ca669ac sago007 2008-12-09 16:30 1999
    const int backX = 20;
7ca669ac sago007 2008-12-09 16:30 2000
    const int backY = ysize-buttonYsize-20;
7ca669ac sago007 2008-12-09 16:30 2001
    const int nextX = xsize-buttonXsize-20;
7ca669ac sago007 2008-12-09 16:30 2002
    const int nextY = backY;
81d9c25d sago007 2008-11-24 09:50 2003
    while (!done)
81d9c25d sago007 2008-11-24 09:50 2004
    {
47529580 sago007 2008-12-09 02:34 2005
        switch(page)
47529580 sago007 2008-12-09 02:34 2006
        {
47529580 sago007 2008-12-09 02:34 2007
            case 0:
47529580 sago007 2008-12-09 02:34 2008
                //Highscores, endless
47529580 sago007 2008-12-09 02:34 2009
                DrawHighscores(100,100,true);
47529580 sago007 2008-12-09 02:34 2010
                break;
47529580 sago007 2008-12-09 02:34 2011
            case 1:
47529580 sago007 2008-12-09 02:34 2012
                //Highscores, Time Trial
47529580 sago007 2008-12-09 02:34 2013
                DrawHighscores(100,100,false);
47529580 sago007 2008-12-09 02:34 2014
                break;
47529580 sago007 2008-12-09 02:34 2015
            case 2:
47529580 sago007 2008-12-09 02:34 2016
            default:
47529580 sago007 2008-12-09 02:34 2017
                DrawStats();
47529580 sago007 2008-12-09 02:34 2018
        };
47529580 sago007 2008-12-09 02:34 2019
7ca669ac sago007 2008-12-09 16:30 2020
        //Draw buttons:
7ca669ac sago007 2008-12-09 16:30 2021
        DrawIMG(bHighScore,screen,scoreX,scoreY);
7ca669ac sago007 2008-12-09 16:30 2022
        DrawIMG(bBack,screen,backX,backY);
7ca669ac sago007 2008-12-09 16:30 2023
        DrawIMG(bNext,screen,nextX,nextY);
7ca669ac sago007 2008-12-09 16:30 2024
7ca669ac sago007 2008-12-09 16:30 2025
        //Draw page number
7ca669ac sago007 2008-12-09 16:30 2026
        string pageXofY = ((string)"Page ")+itoa(page+1)+((string)" of ")+itoa(numberOfPages);
7ca669ac sago007 2008-12-09 16:30 2027
        SFont_Write(screen,fBlueFont,xsize/2-SFont_TextWidth(fBlueFont,pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
9050a50a sago007 2008-12-09 13:35 2028
        
81d9c25d sago007 2008-11-24 09:50 2029
        SDL_Delay(10);
81d9c25d sago007 2008-11-24 09:50 2030
        SDL_Event event;
9050a50a sago007 2008-12-09 13:35 2031
9050a50a sago007 2008-12-09 13:35 2032
        SDL_GetMouseState(&mousex,&mousey);
81d9c25d sago007 2008-11-24 09:50 2033
        
81d9c25d sago007 2008-11-24 09:50 2034
        while ( SDL_PollEvent(&event) )
81d9c25d sago007 2008-11-24 09:50 2035
        {
9050a50a sago007 2008-12-09 13:35 2036
9050a50a sago007 2008-12-09 13:35 2037
81d9c25d sago007 2008-11-24 09:50 2038
            if ( event.type == SDL_QUIT )  {
81d9c25d sago007 2008-11-24 09:50 2039
                done = true;
81d9c25d sago007 2008-11-24 09:50 2040
            }
81d9c25d sago007 2008-11-24 09:50 2041
81d9c25d sago007 2008-11-24 09:50 2042
            if ( event.type == SDL_KEYDOWN )
81d9c25d sago007 2008-11-24 09:50 2043
            {
47529580 sago007 2008-12-09 02:34 2044
                if( (event.key.keysym.sym == SDLK_RIGHT))
47529580 sago007 2008-12-09 02:34 2045
                {
47529580 sago007 2008-12-09 02:34 2046
                    page++;
47529580 sago007 2008-12-09 02:34 2047
                    if(page>=numberOfPages)
47529580 sago007 2008-12-09 02:34 2048
                        page = 0;
47529580 sago007 2008-12-09 02:34 2049
                }
7ca669ac sago007 2008-12-09 16:30 2050
                else
47529580 sago007 2008-12-09 02:34 2051
                if( (event.key.keysym.sym == SDLK_LEFT))
47529580 sago007 2008-12-09 02:34 2052
                {
47529580 sago007 2008-12-09 02:34 2053
                    page--;
47529580 sago007 2008-12-09 02:34 2054
                    if(page<0)
47529580 sago007 2008-12-09 02:34 2055
                        page = numberOfPages-1;
47529580 sago007 2008-12-09 02:34 2056
                }
7ca669ac sago007 2008-12-09 16:30 2057
                else
7ca669ac sago007 2008-12-09 16:30 2058
                    done = true;
fcd5a134 sago007 2008-12-19 01:11 2059
                
fcd5a134 sago007 2008-12-19 01:11 2060
                if ( event.key.keysym.sym == SDLK_F9 ) {
fcd5a134 sago007 2008-12-19 01:11 2061
                    writeScreenShot();
fcd5a134 sago007 2008-12-19 01:11 2062
                }
47529580 sago007 2008-12-09 02:34 2063
81d9c25d sago007 2008-11-24 09:50 2064
                if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
81d9c25d sago007 2008-11-24 09:50 2065
                    done = true;
81d9c25d sago007 2008-11-24 09:50 2066
                }
81d9c25d sago007 2008-11-24 09:50 2067
                else
81d9c25d sago007 2008-11-24 09:50 2068
                    if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
81d9c25d sago007 2008-11-24 09:50 2069
                        done = true;
81d9c25d sago007 2008-11-24 09:50 2070
                    }
81d9c25d sago007 2008-11-24 09:50 2071
            }
81d9c25d sago007 2008-11-24 09:50 2072
81d9c25d sago007 2008-11-24 09:50 2073
        }	//while(event)
7ca669ac sago007 2008-12-09 16:30 2074
7ca669ac sago007 2008-12-09 16:30 2075
        // If the mouse button is released, make bMouseUp equal true
7ca669ac sago007 2008-12-09 16:30 2076
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
7ca669ac sago007 2008-12-09 16:30 2077
        {
7ca669ac sago007 2008-12-09 16:30 2078
            bMouseUp=true;
7ca669ac sago007 2008-12-09 16:30 2079
        }
7ca669ac sago007 2008-12-09 16:30 2080
7ca669ac sago007 2008-12-09 16:30 2081
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
7ca669ac sago007 2008-12-09 16:30 2082
        {
7ca669ac sago007 2008-12-09 16:30 2083
            bMouseUp = false;
7ca669ac sago007 2008-12-09 16:30 2084
7ca669ac sago007 2008-12-09 16:30 2085
            //The Score button:
7ca669ac sago007 2008-12-09 16:30 2086
            if((mousex>scoreX) && (mousex<scoreX+buttonXsize) && (mousey>scoreY) && (mousey<scoreY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2087
                done =true;
7ca669ac sago007 2008-12-09 16:30 2088
7ca669ac sago007 2008-12-09 16:30 2089
            //The back button:
7ca669ac sago007 2008-12-09 16:30 2090
            if((mousex>backX) && (mousex<backX+buttonXsize) && (mousey>backY) && (mousey<backY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2091
            {
7ca669ac sago007 2008-12-09 16:30 2092
                page--;
7ca669ac sago007 2008-12-09 16:30 2093
                if(page<0)
7ca669ac sago007 2008-12-09 16:30 2094
                    page = numberOfPages-1;
7ca669ac sago007 2008-12-09 16:30 2095
            }
7ca669ac sago007 2008-12-09 16:30 2096
7ca669ac sago007 2008-12-09 16:30 2097
            //The next button:
7ca669ac sago007 2008-12-09 16:30 2098
            if((mousex>nextX) && (mousex<nextX+buttonXsize) && (mousey>nextY) && (mousey<nextY+buttonYsize))
7ca669ac sago007 2008-12-09 16:30 2099
            {
7ca669ac sago007 2008-12-09 16:30 2100
                page++;
7ca669ac sago007 2008-12-09 16:30 2101
                if(page>=numberOfPages)
7ca669ac sago007 2008-12-09 16:30 2102
                    page = 0;
7ca669ac sago007 2008-12-09 16:30 2103
            }
7ca669ac sago007 2008-12-09 16:30 2104
        }
7ca669ac sago007 2008-12-09 16:30 2105
8d488d32 sago007 2011-04-17 13:02 2106
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2107
        mouse.PaintTo(screen,mousex,mousey);
9050a50a sago007 2008-12-09 13:35 2108
        SDL_Flip(screen); //Update screen
81d9c25d sago007 2008-11-24 09:50 2109
    }
6b1dc7a6 sago007 2010-11-08 21:03 2110
6b1dc7a6 sago007 2010-11-08 21:03 2111
81d9c25d sago007 2008-11-24 09:50 2112
}
81d9c25d sago007 2008-11-24 09:50 2113
89c4a3a6 sago007 2008-08-29 14:32 2114
89c4a3a6 sago007 2008-08-29 14:32 2115
//Open a puzzle file
89c4a3a6 sago007 2008-08-29 14:32 2116
bool OpenFileDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2117
{
89c4a3a6 sago007 2008-08-29 14:32 2118
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2119
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2120
    ListFiles lf = ListFiles();
aca2f4b0 sago007 2009-05-10 18:11 2121
    string folder = (string)SHAREDIR+(string)"/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2122
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2123
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2124
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2125
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles";
89c4a3a6 sago007 2008-08-29 14:32 2126
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2127
#endif
89c4a3a6 sago007 2008-08-29 14:32 2128
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2129
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2130
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2131
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2132
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2133
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2134
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2135
    {
89c4a3a6 sago007 2008-08-29 14:32 2136
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2137
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2138
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2139
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2140
        {
89c4a3a6 sago007 2008-08-29 14:32 2141
            SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2142
        }
89c4a3a6 sago007 2008-08-29 14:32 2143
89c4a3a6 sago007 2008-08-29 14:32 2144
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2145
89c4a3a6 sago007 2008-08-29 14:32 2146
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2147
        {
89c4a3a6 sago007 2008-08-29 14:32 2148
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2149
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2150
            }
89c4a3a6 sago007 2008-08-29 14:32 2151
89c4a3a6 sago007 2008-08-29 14:32 2152
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2153
            {
89c4a3a6 sago007 2008-08-29 14:32 2154
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2155
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2156
                }
89c4a3a6 sago007 2008-08-29 14:32 2157
89c4a3a6 sago007 2008-08-29 14:32 2158
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2159
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2160
                }
89c4a3a6 sago007 2008-08-29 14:32 2161
89c4a3a6 sago007 2008-08-29 14:32 2162
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2163
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2164
                }
89c4a3a6 sago007 2008-08-29 14:32 2165
            }
89c4a3a6 sago007 2008-08-29 14:32 2166
89c4a3a6 sago007 2008-08-29 14:32 2167
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2168
89c4a3a6 sago007 2008-08-29 14:32 2169
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2170
89c4a3a6 sago007 2008-08-29 14:32 2171
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2172
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2173
        {
89c4a3a6 sago007 2008-08-29 14:32 2174
            bMouseUp=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 (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2178
        {
89c4a3a6 sago007 2008-08-29 14:32 2179
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2180
89c4a3a6 sago007 2008-08-29 14:32 2181
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2182
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2183
            {
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
            //The back button:
9050a50a sago007 2008-12-09 13:35 2188
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2189
            {
89c4a3a6 sago007 2008-08-29 14:32 2190
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2191
            }
89c4a3a6 sago007 2008-08-29 14:32 2192
89c4a3a6 sago007 2008-08-29 14:32 2193
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2194
            {
89c4a3a6 sago007 2008-08-29 14:32 2195
                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 2196
                {
89c4a3a6 sago007 2008-08-29 14:32 2197
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2198
                    {
89c4a3a6 sago007 2008-08-29 14:32 2199
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2200
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2201
                    }
89c4a3a6 sago007 2008-08-29 14:32 2202
                }
89c4a3a6 sago007 2008-08-29 14:32 2203
            }
89c4a3a6 sago007 2008-08-29 14:32 2204
        }
89c4a3a6 sago007 2008-08-29 14:32 2205
8d488d32 sago007 2011-04-17 13:02 2206
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2207
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2208
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2209
    }
89c4a3a6 sago007 2008-08-29 14:32 2210
}
89c4a3a6 sago007 2008-08-29 14:32 2211
89c4a3a6 sago007 2008-08-29 14:32 2212
//Slelect a theme
89c4a3a6 sago007 2008-08-29 14:32 2213
bool SelectThemeDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2214
{
89c4a3a6 sago007 2008-08-29 14:32 2215
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2216
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2217
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2218
    string folder = (string)SHAREDIR+(string)"/themes";
89c4a3a6 sago007 2008-08-29 14:32 2219
    cout << "Looking in " << folder << endl;
89c4a3a6 sago007 2008-08-29 14:32 2220
    lf.setDirectory(folder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2221
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2222
    string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/themes";
89c4a3a6 sago007 2008-08-29 14:32 2223
    lf.setDirectory2(homeFolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2224
#endif
89c4a3a6 sago007 2008-08-29 14:32 2225
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2226
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2227
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2228
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2229
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2230
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2231
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2232
    {
89c4a3a6 sago007 2008-08-29 14:32 2233
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2234
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2235
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2236
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2237
        {
89c4a3a6 sago007 2008-08-29 14:32 2238
            SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2239
        }
89c4a3a6 sago007 2008-08-29 14:32 2240
89c4a3a6 sago007 2008-08-29 14:32 2241
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2242
89c4a3a6 sago007 2008-08-29 14:32 2243
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2244
        {
89c4a3a6 sago007 2008-08-29 14:32 2245
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2246
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2247
            }
89c4a3a6 sago007 2008-08-29 14:32 2248
89c4a3a6 sago007 2008-08-29 14:32 2249
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2250
            {
89c4a3a6 sago007 2008-08-29 14:32 2251
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2252
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2253
                }
89c4a3a6 sago007 2008-08-29 14:32 2254
89c4a3a6 sago007 2008-08-29 14:32 2255
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2256
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2257
                }
89c4a3a6 sago007 2008-08-29 14:32 2258
89c4a3a6 sago007 2008-08-29 14:32 2259
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2260
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2261
                }
89c4a3a6 sago007 2008-08-29 14:32 2262
            }
89c4a3a6 sago007 2008-08-29 14:32 2263
89c4a3a6 sago007 2008-08-29 14:32 2264
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2265
89c4a3a6 sago007 2008-08-29 14:32 2266
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2267
89c4a3a6 sago007 2008-08-29 14:32 2268
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2269
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2270
        {
89c4a3a6 sago007 2008-08-29 14:32 2271
            bMouseUp=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 (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2275
        {
89c4a3a6 sago007 2008-08-29 14:32 2276
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2277
89c4a3a6 sago007 2008-08-29 14:32 2278
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2279
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2280
            {
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
            //The back button:
9050a50a sago007 2008-12-09 13:35 2285
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2286
            {
89c4a3a6 sago007 2008-08-29 14:32 2287
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2288
            }
89c4a3a6 sago007 2008-08-29 14:32 2289
89c4a3a6 sago007 2008-08-29 14:32 2290
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2291
            {
89c4a3a6 sago007 2008-08-29 14:32 2292
                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 2293
                {
89c4a3a6 sago007 2008-08-29 14:32 2294
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2295
                    {
89c4a3a6 sago007 2008-08-29 14:32 2296
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2297
                        loadTheme(lf.getFileName(i));
89c4a3a6 sago007 2008-08-29 14:32 2298
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2299
                    }
89c4a3a6 sago007 2008-08-29 14:32 2300
                }
89c4a3a6 sago007 2008-08-29 14:32 2301
            }
89c4a3a6 sago007 2008-08-29 14:32 2302
        }
89c4a3a6 sago007 2008-08-29 14:32 2303
8d488d32 sago007 2011-04-17 13:02 2304
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2305
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2306
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2307
    }
89c4a3a6 sago007 2008-08-29 14:32 2308
}
89c4a3a6 sago007 2008-08-29 14:32 2309
89c4a3a6 sago007 2008-08-29 14:32 2310
//Open a saved replay
89c4a3a6 sago007 2008-08-29 14:32 2311
bool OpenReplayDialogbox(int x, int y, char *name)
89c4a3a6 sago007 2008-08-29 14:32 2312
{
89c4a3a6 sago007 2008-08-29 14:32 2313
    bool done = false;	//We are done!
89c4a3a6 sago007 2008-08-29 14:32 2314
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2315
    ListFiles lf = ListFiles();
89c4a3a6 sago007 2008-08-29 14:32 2316
    cout << "Ready to set directory!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2317
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 2318
    string directory = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2319
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 2320
    string directory = getMyDocumentsPath()+(string)"/My Games/blockattack/replays";
89c4a3a6 sago007 2008-08-29 14:32 2321
#else
89c4a3a6 sago007 2008-08-29 14:32 2322
    string directory = "./replays";
89c4a3a6 sago007 2008-08-29 14:32 2323
#endif
89c4a3a6 sago007 2008-08-29 14:32 2324
    lf.setDirectory(directory);
89c4a3a6 sago007 2008-08-29 14:32 2325
    cout << "Directory sat" << endl;
89c4a3a6 sago007 2008-08-29 14:32 2326
    Uint8* keys;
89c4a3a6 sago007 2008-08-29 14:32 2327
    string strHolder;
27ae0175 sago007 2009-01-30 06:02 2328
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2329
    DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2330
    DrawIMG(bForward,background,x+460,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2331
    DrawIMG(bBack,background,x+20,y+420);
89c4a3a6 sago007 2008-08-29 14:32 2332
    while (!done)
89c4a3a6 sago007 2008-08-29 14:32 2333
    {
89c4a3a6 sago007 2008-08-29 14:32 2334
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2335
        const int nrOfFiles = 10;
89c4a3a6 sago007 2008-08-29 14:32 2336
        DrawIMG(changeButtonsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2337
        for (int i=0;i<nrOfFiles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2338
        {
89c4a3a6 sago007 2008-08-29 14:32 2339
            SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
89c4a3a6 sago007 2008-08-29 14:32 2340
        }
89c4a3a6 sago007 2008-08-29 14:32 2341
89c4a3a6 sago007 2008-08-29 14:32 2342
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2343
89c4a3a6 sago007 2008-08-29 14:32 2344
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2345
        {
89c4a3a6 sago007 2008-08-29 14:32 2346
            if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 2347
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 2348
                return false;
89c4a3a6 sago007 2008-08-29 14:32 2349
            }
89c4a3a6 sago007 2008-08-29 14:32 2350
89c4a3a6 sago007 2008-08-29 14:32 2351
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2352
            {
89c4a3a6 sago007 2008-08-29 14:32 2353
                if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
89c4a3a6 sago007 2008-08-29 14:32 2354
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 2355
                    return false;
89c4a3a6 sago007 2008-08-29 14:32 2356
                }
89c4a3a6 sago007 2008-08-29 14:32 2357
89c4a3a6 sago007 2008-08-29 14:32 2358
                if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2359
                    lf.forward();
89c4a3a6 sago007 2008-08-29 14:32 2360
                }
89c4a3a6 sago007 2008-08-29 14:32 2361
89c4a3a6 sago007 2008-08-29 14:32 2362
                if ( (event.key.keysym.sym == SDLK_LEFT) ) {
89c4a3a6 sago007 2008-08-29 14:32 2363
                    lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2364
                }
89c4a3a6 sago007 2008-08-29 14:32 2365
            }
89c4a3a6 sago007 2008-08-29 14:32 2366
89c4a3a6 sago007 2008-08-29 14:32 2367
        } //while(event)
89c4a3a6 sago007 2008-08-29 14:32 2368
89c4a3a6 sago007 2008-08-29 14:32 2369
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2370
89c4a3a6 sago007 2008-08-29 14:32 2371
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2372
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2373
        {
89c4a3a6 sago007 2008-08-29 14:32 2374
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2375
        }
89c4a3a6 sago007 2008-08-29 14:32 2376
89c4a3a6 sago007 2008-08-29 14:32 2377
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2378
        {
89c4a3a6 sago007 2008-08-29 14:32 2379
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2380
89c4a3a6 sago007 2008-08-29 14:32 2381
            //The Forward Button:
9050a50a sago007 2008-12-09 13:35 2382
            if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2383
            {
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
            //The back button:
9050a50a sago007 2008-12-09 13:35 2388
            if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) )
89c4a3a6 sago007 2008-08-29 14:32 2389
            {
89c4a3a6 sago007 2008-08-29 14:32 2390
                lf.back();
89c4a3a6 sago007 2008-08-29 14:32 2391
            }
89c4a3a6 sago007 2008-08-29 14:32 2392
89c4a3a6 sago007 2008-08-29 14:32 2393
            for (int i=0;i<10;i++)
89c4a3a6 sago007 2008-08-29 14:32 2394
            {
89c4a3a6 sago007 2008-08-29 14:32 2395
                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 2396
                {
89c4a3a6 sago007 2008-08-29 14:32 2397
                    if (lf.fileExists(i))
89c4a3a6 sago007 2008-08-29 14:32 2398
                    {
89c4a3a6 sago007 2008-08-29 14:32 2399
                        strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
89c4a3a6 sago007 2008-08-29 14:32 2400
                        done=true; //The user have, clicked the purpose of this function is now complete
89c4a3a6 sago007 2008-08-29 14:32 2401
                        return true;
89c4a3a6 sago007 2008-08-29 14:32 2402
                    }
89c4a3a6 sago007 2008-08-29 14:32 2403
                }
89c4a3a6 sago007 2008-08-29 14:32 2404
            }
89c4a3a6 sago007 2008-08-29 14:32 2405
        }
89c4a3a6 sago007 2008-08-29 14:32 2406
8d488d32 sago007 2011-04-17 13:02 2407
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2408
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2409
        SDL_Flip(screen); //Update screen
89c4a3a6 sago007 2008-08-29 14:32 2410
    }
89c4a3a6 sago007 2008-08-29 14:32 2411
}
89c4a3a6 sago007 2008-08-29 14:32 2412
89c4a3a6 sago007 2008-08-29 14:32 2413
89c4a3a6 sago007 2008-08-29 14:32 2414
//draws options:
e1290bdf sago007 2010-10-25 19:56 2415
void DrawOptions(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 2416
{
9050a50a sago007 2008-12-09 13:35 2417
    if (MusicEnabled) DrawIMG(bOn,optionsBack,400,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2418
    else DrawIMG(bOff,optionsBack,400,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2419
    if (SoundEnabled) DrawIMG(bOn,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2420
    else DrawIMG(bOff,optionsBack,400,170);
89c4a3a6 sago007 2008-08-29 14:32 2421
    if (bFullscreen) DrawIMG(bOn,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2422
    else DrawIMG(bOff,optionsBack,400,220);
89c4a3a6 sago007 2008-08-29 14:32 2423
    DrawIMG(bChange,optionsBack,230,435);
89c4a3a6 sago007 2008-08-29 14:32 2424
    DrawIMG(bChange,optionsBack,410,435);
89c4a3a6 sago007 2008-08-29 14:32 2425
    DrawIMG(bChange,optionsBack,230,500);
89c4a3a6 sago007 2008-08-29 14:32 2426
    DrawIMG(bChange,optionsBack,410,500);
89c4a3a6 sago007 2008-08-29 14:32 2427
    DrawIMG(optionsBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2428
}  //drawOptions
89c4a3a6 sago007 2008-08-29 14:32 2429
89c4a3a6 sago007 2008-08-29 14:32 2430
//Draws the balls and explosions
4b0c248f sago007 2010-11-10 21:13 2431
static void DrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2432
{
89c4a3a6 sago007 2008-08-29 14:32 2433
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2434
    {
89c4a3a6 sago007 2008-08-29 14:32 2435
        if (theBallManeger.ballUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2436
        {
89c4a3a6 sago007 2008-08-29 14:32 2437
            DrawIMG(balls[theBallManeger.ballArray[i].getColor()],screen,theBallManeger.ballArray[i].getX(),theBallManeger.ballArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2438
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2439
        if (theExplosionManeger.explosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2440
        {
89c4a3a6 sago007 2008-08-29 14:32 2441
            DrawIMG(explosion[theExplosionManeger.explosionArray[i].getFrame()],screen,theExplosionManeger.explosionArray[i].getX(),theExplosionManeger.explosionArray[i].getY());
89c4a3a6 sago007 2008-08-29 14:32 2442
        }
89c4a3a6 sago007 2008-08-29 14:32 2443
        if (theTextManeger.textUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2444
        {
89c4a3a6 sago007 2008-08-29 14:32 2445
            //cout << "Printing text: " << theTextManeger.textArray[i].getText() << endl;
89c4a3a6 sago007 2008-08-29 14:32 2446
            int x = theTextManeger.textArray[i].getX()-SFont_TextWidth(fSmallFont,theTextManeger.textArray[i].getText())/2;
89c4a3a6 sago007 2008-08-29 14:32 2447
            int y = theTextManeger.textArray[i].getY()-SFont_TextHeight(fSmallFont)/2;
89c4a3a6 sago007 2008-08-29 14:32 2448
            DrawIMG(iChainBack,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2449
            SFont_Write(screen,fSmallFont,x+(25-SFont_TextWidth(fSmallFont,theTextManeger.textArray[i].getText()))/2,y+(25-SFont_TextHeight(fSmallFont))/2,theTextManeger.textArray[i].getText());
89c4a3a6 sago007 2008-08-29 14:32 2450
        }
89c4a3a6 sago007 2008-08-29 14:32 2451
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2452
}    //DrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2453
89c4a3a6 sago007 2008-08-29 14:32 2454
//Removes the old balls
89c4a3a6 sago007 2008-08-29 14:32 2455
void UndrawBalls()
89c4a3a6 sago007 2008-08-29 14:32 2456
{
89c4a3a6 sago007 2008-08-29 14:32 2457
    for (int i = 0; i< maxNumberOfBalls; i++)
89c4a3a6 sago007 2008-08-29 14:32 2458
    {
89c4a3a6 sago007 2008-08-29 14:32 2459
        if (theBallManeger.oldBallUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2460
        {
89c4a3a6 sago007 2008-08-29 14:32 2461
            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 2462
        } //if used
89c4a3a6 sago007 2008-08-29 14:32 2463
        if (theExplosionManeger.oldExplosionUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2464
        {
89c4a3a6 sago007 2008-08-29 14:32 2465
            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 2466
        }
89c4a3a6 sago007 2008-08-29 14:32 2467
        if (theTextManeger.oldTextUsed[i])
89c4a3a6 sago007 2008-08-29 14:32 2468
        {
89c4a3a6 sago007 2008-08-29 14:32 2469
            int x = theTextManeger.oldTextArray[i].getX()-SFont_TextWidth(fSmallFont,theTextManeger.oldTextArray[i].getText())/2;
89c4a3a6 sago007 2008-08-29 14:32 2470
            int y = theTextManeger.oldTextArray[i].getY()-SFont_TextHeight(fSmallFont)/2;
89c4a3a6 sago007 2008-08-29 14:32 2471
            DrawIMG(background,screen,x,y,25,25,x,y);
89c4a3a6 sago007 2008-08-29 14:32 2472
        }
89c4a3a6 sago007 2008-08-29 14:32 2473
    } //for
89c4a3a6 sago007 2008-08-29 14:32 2474
}   //UndrawBalls
89c4a3a6 sago007 2008-08-29 14:32 2475
89c4a3a6 sago007 2008-08-29 14:32 2476
//draws everything
6b1dc7a6 sago007 2010-11-08 21:03 2477
void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2478
{
89c4a3a6 sago007 2008-08-29 14:32 2479
    SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 2480
    //draw background:
89c4a3a6 sago007 2008-08-29 14:32 2481
    if (forceredraw != 1)
89c4a3a6 sago007 2008-08-29 14:32 2482
    {
89c4a3a6 sago007 2008-08-29 14:32 2483
89c4a3a6 sago007 2008-08-29 14:32 2484
        UndrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2485
        DrawIMG(background,screen,oldMousex,oldMousey,32,32,oldMousex,oldMousey);
89c4a3a6 sago007 2008-08-29 14:32 2486
        DrawIMG(background,screen,oldBubleX,oldBubleY,140,50,oldBubleX,oldBubleY);
89c4a3a6 sago007 2008-08-29 14:32 2487
89c4a3a6 sago007 2008-08-29 14:32 2488
89c4a3a6 sago007 2008-08-29 14:32 2489
        DrawIMG(background,screen,350,200,120,200,350,200);
89c4a3a6 sago007 2008-08-29 14:32 2490
        DrawIMG(background,screen,830,200,120,200,830,200);
89c4a3a6 sago007 2008-08-29 14:32 2491
        DrawIMG(background,screen,800,0,140,50,800,0);
89c4a3a6 sago007 2008-08-29 14:32 2492
89c4a3a6 sago007 2008-08-29 14:32 2493
        DrawIMG(background,screen,50,60,300,50,50,60);
89c4a3a6 sago007 2008-08-29 14:32 2494
        DrawIMG(background,screen,510,60,300,50,510,60);
89c4a3a6 sago007 2008-08-29 14:32 2495
    }
89c4a3a6 sago007 2008-08-29 14:32 2496
    else
89c4a3a6 sago007 2008-08-29 14:32 2497
        DrawIMG(background,screen,0,0);
89c4a3a6 sago007 2008-08-29 14:32 2498
    //draw bottons (should be moves and drawn directly to background once)
89c4a3a6 sago007 2008-08-29 14:32 2499
    if (!editorMode)
2f30c381 sago007 2008-09-14 13:08 2500
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2501
        if (!networkActive) //We don't show the menu while running server or connected to a server
2f30c381 sago007 2008-09-14 13:08 2502
        #else
2f30c381 sago007 2008-09-14 13:08 2503
            if(true)
2f30c381 sago007 2008-09-14 13:08 2504
        #endif
89c4a3a6 sago007 2008-08-29 14:32 2505
        {
89c4a3a6 sago007 2008-08-29 14:32 2506
            //Here we draw the menu
43611709 sago007 2011-04-23 17:18 2507
            bNewGame.PaintTo(screen,0,0);
9050a50a sago007 2008-12-09 13:35 2508
            DrawIMG(bOptions, screen, buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2509
            DrawIMG(bHighScore, screen, 2*buttonXsize,0);
9050a50a sago007 2008-12-09 13:35 2510
            DrawIMG(bReplay,screen,3*buttonXsize,0);
89c4a3a6 sago007 2008-08-29 14:32 2511
        }
89c4a3a6 sago007 2008-08-29 14:32 2512
        else
89c4a3a6 sago007 2008-08-29 14:32 2513
        { //If network is active
89c4a3a6 sago007 2008-08-29 14:32 2514
            DrawIMG(bBack, screen, 0, 0); //Display a disconnect button
89c4a3a6 sago007 2008-08-29 14:32 2515
        }
89c4a3a6 sago007 2008-08-29 14:32 2516
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2517
        DrawIMG(bExit, screen, xsize-120,ysize-120);
e1290bdf sago007 2010-10-25 19:56 2518
    //DrawIMG(boardBackBack,screen,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2519
    DrawIMG(theGame->sBoard,screen,theGame->GetTopX(),theGame->GetTopY());
89c4a3a6 sago007 2008-08-29 14:32 2520
    string strHolder;
e1290bdf sago007 2010-10-25 19:56 2521
    strHolder = itoa(theGame->GetScore()+theGame->GetHandicap());
e1290bdf sago007 2010-10-25 19:56 2522
    SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2523
    if (theGame->GetAIenabled())
e1290bdf sago007 2010-10-25 19:56 2524
        SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2525
    else
89c4a3a6 sago007 2008-08-29 14:32 2526
        if (editorMode)
e1290bdf sago007 2010-10-25 19:56 2527
            SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,"Playing field");
89c4a3a6 sago007 2008-08-29 14:32 2528
        else
89c4a3a6 sago007 2008-08-29 14:32 2529
            if (!singlePuzzle)
e1290bdf sago007 2010-10-25 19:56 2530
                SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,player1name);
e1290bdf sago007 2010-10-25 19:56 2531
    if (theGame->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2532
    {
e1290bdf sago007 2010-10-25 19:56 2533
        int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2534
        int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2535
        int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2536
        if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2537
        {
e1290bdf sago007 2010-10-25 19:56 2538
            minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2539
            seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2540
        }
89c4a3a6 sago007 2008-08-29 14:32 2541
        else
89c4a3a6 sago007 2008-08-29 14:32 2542
        {
e1290bdf sago007 2010-10-25 19:56 2543
            minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2544
            seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2545
        }
e1290bdf sago007 2010-10-25 19:56 2546
        if (theGame->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2547
        if (theGame->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2548
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2549
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2550
        else strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2551
        //if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
e1290bdf sago007 2010-10-25 19:56 2552
        SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2553
    }
89c4a3a6 sago007 2008-08-29 14:32 2554
    else
89c4a3a6 sago007 2008-08-29 14:32 2555
    {
e1290bdf sago007 2010-10-25 19:56 2556
        int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2557
        int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2558
        if (theGame->isGameOver()) minutes=(theGame->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2559
        if (theGame->isGameOver()) seconds=(theGame->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2560
        if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2561
            strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2562
        else
89c4a3a6 sago007 2008-08-29 14:32 2563
            strHolder = itoa(minutes)+":0"+itoa(seconds);
e1290bdf sago007 2010-10-25 19:56 2564
        SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2565
    }
e1290bdf sago007 2010-10-25 19:56 2566
    strHolder = itoa(theGame->GetChains());
e1290bdf sago007 2010-10-25 19:56 2567
    SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2568
    //drawspeedLevel:
e1290bdf sago007 2010-10-25 19:56 2569
    strHolder = itoa(theGame->GetSpeedLevel());
e1290bdf sago007 2010-10-25 19:56 2570
    SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2571
    if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY()))
89c4a3a6 sago007 2008-08-29 14:32 2572
    {
e1290bdf sago007 2010-10-25 19:56 2573
        oldBubleX = theGame->GetTopX()+280;
e1290bdf sago007 2010-10-25 19:56 2574
        oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1;
e1290bdf sago007 2010-10-25 19:56 2575
        DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
89c4a3a6 sago007 2008-08-29 14:32 2576
    }
89c4a3a6 sago007 2008-08-29 14:32 2577
    //player1 finnish, player2 start
e1290bdf sago007 2010-10-25 19:56 2578
    //DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2579
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 2580
    {
f72abf8b sago007 2010-01-16 20:00 2581
        /*
f72abf8b sago007 2010-01-16 20:00 2582
         *If single player mode (and not VS)
f72abf8b sago007 2010-01-16 20:00 2583
         */
e1290bdf sago007 2010-10-25 19:56 2584
        if(!twoPlayers && !theGame->isGameOver())
e2de69cf sago007 2010-01-15 22:48 2585
        {
f72abf8b sago007 2010-01-16 20:00 2586
            //Blank player2's board:
e1290bdf sago007 2010-10-25 19:56 2587
            DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
f72abf8b sago007 2010-01-16 20:00 2588
            //Write a description:
e1290bdf sago007 2010-10-25 19:56 2589
            if(theGame->isTimeTrial())
f72abf8b sago007 2010-01-16 20:00 2590
            {
e1290bdf sago007 2010-10-25 19:56 2591
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial");
e1290bdf sago007 2010-10-25 19:56 2592
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2593
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much");
e1290bdf sago007 2010-10-25 19:56 2594
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "as possible in");
e1290bdf sago007 2010-10-25 19:56 2595
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"2 minutes");
e1290bdf sago007 2010-10-25 19:56 2596
            } else if(theGame->isStageClear())
f72abf8b sago007 2010-01-16 20:00 2597
            {
e1290bdf sago007 2010-10-25 19:56 2598
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear");
e1290bdf sago007 2010-10-25 19:56 2599
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2600
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "You must clear a");
e1290bdf sago007 2010-10-25 19:56 2601
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "number of lines.");
e1290bdf sago007 2010-10-25 19:56 2602
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"Speed is rapidly");
e1290bdf sago007 2010-10-25 19:56 2603
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"increased.");
e1290bdf sago007 2010-10-25 19:56 2604
            } else if(theGame->isPuzzleMode())
f72abf8b sago007 2010-01-16 20:00 2605
            {
e1290bdf sago007 2010-10-25 19:56 2606
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle");
e1290bdf sago007 2010-10-25 19:56 2607
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2608
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Clear the entire");
e1290bdf sago007 2010-10-25 19:56 2609
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "board with a");
e1290bdf sago007 2010-10-25 19:56 2610
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limited number of");
e1290bdf sago007 2010-10-25 19:56 2611
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"moves.");
f72abf8b sago007 2010-01-16 20:00 2612
            } else
f72abf8b sago007 2010-01-16 20:00 2613
            {
e1290bdf sago007 2010-10-25 19:56 2614
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless");
e1290bdf sago007 2010-10-25 19:56 2615
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
e1290bdf sago007 2010-10-25 19:56 2616
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,     "Score as much as");
e1290bdf sago007 2010-10-25 19:56 2617
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28,  "possible. No time");
e1290bdf sago007 2010-10-25 19:56 2618
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limit.");
f72abf8b sago007 2010-01-16 20:00 2619
            }
f72abf8b sago007 2010-01-16 20:00 2620
f72abf8b sago007 2010-01-16 20:00 2621
            //Write the keys that are in use
e1290bdf sago007 2010-10-25 19:56 2622
            int y = theGame2->GetTopY()+400;
e1290bdf sago007 2010-10-25 19:56 2623
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y,"Movement keys:" );
e1290bdf sago007 2010-10-25 19:56 2624
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
e1290bdf sago007 2010-10-25 19:56 2625
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
e1290bdf sago007 2010-10-25 19:56 2626
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+120,("Switch: "+getKeyName(keySettings[0].change) ).c_str() );
e1290bdf sago007 2010-10-25 19:56 2627
            if(theGame->isPuzzleMode())
e1290bdf sago007 2010-10-25 19:56 2628
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+160,("Restart: "+getKeyName(keySettings[0].push) ).c_str() );
f72abf8b sago007 2010-01-16 20:00 2629
            else
e1290bdf sago007 2010-10-25 19:56 2630
                SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+160,("Push line: "+getKeyName(keySettings[0].push) ).c_str() );
e2de69cf sago007 2010-01-15 22:48 2631
        }
e2de69cf sago007 2010-01-15 22:48 2632
        else
e1290bdf sago007 2010-10-25 19:56 2633
            DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
e1290bdf sago007 2010-10-25 19:56 2634
        strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap());
e1290bdf sago007 2010-10-25 19:56 2635
        SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2636
        if (theGame2->GetAIenabled())
e1290bdf sago007 2010-10-25 19:56 2637
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+10,theGame2->GetTopY()-40,"CPU");
89c4a3a6 sago007 2008-08-29 14:32 2638
        else
e1290bdf sago007 2010-10-25 19:56 2639
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+10,theGame2->GetTopY()-40,theGame2->name);
e1290bdf sago007 2010-10-25 19:56 2640
        if (theGame2->isTimeTrial())
89c4a3a6 sago007 2008-08-29 14:32 2641
        {
e1290bdf sago007 2010-10-25 19:56 2642
            int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
89c4a3a6 sago007 2008-08-29 14:32 2643
            int minutes;
89c4a3a6 sago007 2008-08-29 14:32 2644
            int seconds;
89c4a3a6 sago007 2008-08-29 14:32 2645
            if (tid>=0)
89c4a3a6 sago007 2008-08-29 14:32 2646
            {
e1290bdf sago007 2010-10-25 19:56 2647
                minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2648
                seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2649
            }
89c4a3a6 sago007 2008-08-29 14:32 2650
            else
89c4a3a6 sago007 2008-08-29 14:32 2651
            {
e1290bdf sago007 2010-10-25 19:56 2652
                minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2653
                seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
89c4a3a6 sago007 2008-08-29 14:32 2654
            }
e1290bdf sago007 2010-10-25 19:56 2655
            if (theGame2->isGameOver()) minutes=0;
e1290bdf sago007 2010-10-25 19:56 2656
            if (theGame2->isGameOver()) seconds=0;
89c4a3a6 sago007 2008-08-29 14:32 2657
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2658
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2659
            else
89c4a3a6 sago007 2008-08-29 14:32 2660
                strHolder = itoa(minutes)+":0"+itoa(seconds);
6d48320c sago007 2009-03-28 17:06 2661
            //if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
e1290bdf sago007 2010-10-25 19:56 2662
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2663
        }
89c4a3a6 sago007 2008-08-29 14:32 2664
        else
89c4a3a6 sago007 2008-08-29 14:32 2665
        {
e1290bdf sago007 2010-10-25 19:56 2666
            int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000;
e1290bdf sago007 2010-10-25 19:56 2667
            int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000;
e1290bdf sago007 2010-10-25 19:56 2668
            if (theGame2->isGameOver()) minutes=(theGame2->GetGameEndedAt()/1000/60)%100;
e1290bdf sago007 2010-10-25 19:56 2669
            if (theGame2->isGameOver()) seconds=(theGame2->GetGameEndedAt()/1000)%60;
89c4a3a6 sago007 2008-08-29 14:32 2670
            if (seconds>9)
89c4a3a6 sago007 2008-08-29 14:32 2671
                strHolder = itoa(minutes)+":"+itoa(seconds);
89c4a3a6 sago007 2008-08-29 14:32 2672
            else
89c4a3a6 sago007 2008-08-29 14:32 2673
                strHolder = itoa(minutes)+":0"+itoa(seconds);
e1290bdf sago007 2010-10-25 19:56 2674
            SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2675
        }
e1290bdf sago007 2010-10-25 19:56 2676
        strHolder = itoa(theGame2->GetChains());
e1290bdf sago007 2010-10-25 19:56 2677
        SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
e1290bdf sago007 2010-10-25 19:56 2678
        strHolder = itoa(theGame2->GetSpeedLevel());
e1290bdf sago007 2010-10-25 19:56 2679
        SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
89c4a3a6 sago007 2008-08-29 14:32 2680
    }
89c4a3a6 sago007 2008-08-29 14:32 2681
    //player2 finnish
89c4a3a6 sago007 2008-08-29 14:32 2682
89c4a3a6 sago007 2008-08-29 14:32 2683
    if (bNewGameOpen)
89c4a3a6 sago007 2008-08-29 14:32 2684
    {
89c4a3a6 sago007 2008-08-29 14:32 2685
        DrawIMG(b1player,screen,0,40);
89c4a3a6 sago007 2008-08-29 14:32 2686
        DrawIMG(b2players,screen,0,80);
1572de2b sago007 2008-09-11 18:15 2687
#if NETWORK
9050a50a sago007 2008-12-09 13:35 2688
        DrawIMG(bNetwork,screen,0,buttonXsize);
89c4a3a6 sago007 2008-08-29 14:32 2689
#endif
89c4a3a6 sago007 2008-08-29 14:32 2690
        if (b1playerOpen)
89c4a3a6 sago007 2008-08-29 14:32 2691
        {
9050a50a sago007 2008-12-09 13:35 2692
            DrawIMG(bEndless,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2693
            DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2694
            DrawIMG(bStageClear,screen,buttonXsize,buttonXsize);
9050a50a sago007 2008-12-09 13:35 2695
            DrawIMG(bPuzzle,screen,buttonXsize,160);
9050a50a sago007 2008-12-09 13:35 2696
            DrawIMG(bVsMode,screen,buttonXsize,200);
89c4a3a6 sago007 2008-08-29 14:32 2697
        }
89c4a3a6 sago007 2008-08-29 14:32 2698
        else
89c4a3a6 sago007 2008-08-29 14:32 2699
            if (b2playersOpen)
89c4a3a6 sago007 2008-08-29 14:32 2700
            {
9050a50a sago007 2008-12-09 13:35 2701
                DrawIMG(bTimeTrial,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2702
                DrawIMG(bVsMode,screen,buttonXsize,120);
89c4a3a6 sago007 2008-08-29 14:32 2703
            }
1572de2b sago007 2008-09-11 18:15 2704
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 2705
            else
89c4a3a6 sago007 2008-08-29 14:32 2706
                if (bNetworkOpen)
89c4a3a6 sago007 2008-08-29 14:32 2707
                {
9050a50a sago007 2008-12-09 13:35 2708
                    DrawIMG(bHost,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2709
                    DrawIMG(bConnect,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2710
                }
89c4a3a6 sago007 2008-08-29 14:32 2711
#endif
89c4a3a6 sago007 2008-08-29 14:32 2712
    }
89c4a3a6 sago007 2008-08-29 14:32 2713
    if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 2714
    {
9050a50a sago007 2008-12-09 13:35 2715
        DrawIMG(bConfigure,screen,buttonXsize,40);
9050a50a sago007 2008-12-09 13:35 2716
        DrawIMG(bSelectPuzzle,screen,buttonXsize,80);
9050a50a sago007 2008-12-09 13:35 2717
        DrawIMG(bVsModeConfig,screen,buttonXsize,120);
9050a50a sago007 2008-12-09 13:35 2718
        DrawIMG(bTheme,screen,buttonXsize,160);
89c4a3a6 sago007 2008-08-29 14:32 2719
    }
89c4a3a6 sago007 2008-08-29 14:32 2720
    if (bReplayOpen)
89c4a3a6 sago007 2008-08-29 14:32 2721
    {
89c4a3a6 sago007 2008-08-29 14:32 2722
        DrawIMG(bSave,screen,360,40);
89c4a3a6 sago007 2008-08-29 14:32 2723
        DrawIMG(bLoad,screen,360,80);
89c4a3a6 sago007 2008-08-29 14:32 2724
    }
89c4a3a6 sago007 2008-08-29 14:32 2725
    if (showOptions) DrawOptions(100,100);
89c4a3a6 sago007 2008-08-29 14:32 2726
89c4a3a6 sago007 2008-08-29 14:32 2727
    DrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 2728
1572de2b sago007 2008-09-11 18:15 2729
#if DEBUG
89c4a3a6 sago007 2008-08-29 14:32 2730
    Frames++;
89c4a3a6 sago007 2008-08-29 14:32 2731
    if (SDL_GetTicks() >= Ticks + 1000)
89c4a3a6 sago007 2008-08-29 14:32 2732
    {
89c4a3a6 sago007 2008-08-29 14:32 2733
        if (Frames > 999) Frames=999;
78d03b38 sago007 2008-11-13 19:56 2734
        sprintf(FPS, "%lu fps", Frames);
89c4a3a6 sago007 2008-08-29 14:32 2735
        Frames = 0;
89c4a3a6 sago007 2008-08-29 14:32 2736
        Ticks = SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2737
    }
89c4a3a6 sago007 2008-08-29 14:32 2738
89c4a3a6 sago007 2008-08-29 14:32 2739
    SFont_Write(screen,fBlueFont,800,4,FPS);
89c4a3a6 sago007 2008-08-29 14:32 2740
#endif
89c4a3a6 sago007 2008-08-29 14:32 2741
89c4a3a6 sago007 2008-08-29 14:32 2742
    //SDL_Flip(screen); Update screen is now called outside DrawEvrything, bacause the mouse needs to be painted
89c4a3a6 sago007 2008-08-29 14:32 2743
89c4a3a6 sago007 2008-08-29 14:32 2744
}
89c4a3a6 sago007 2008-08-29 14:32 2745
89c4a3a6 sago007 2008-08-29 14:32 2746
//Generates the standard background
4b0c248f sago007 2010-11-10 21:13 2747
static void MakeBackground(int xsize,int ysize)
89c4a3a6 sago007 2008-08-29 14:32 2748
{
27ae0175 sago007 2009-01-30 06:02 2749
    int w = backgroundImage->w;
27ae0175 sago007 2009-01-30 06:02 2750
    int h = backgroundImage->h;
27ae0175 sago007 2009-01-30 06:02 2751
    for(int i=0;i*w<xsize;i++)
27ae0175 sago007 2009-01-30 06:02 2752
        for(int j=0;j*h<ysize;j++)
27ae0175 sago007 2009-01-30 06:02 2753
            DrawIMG(backgroundImage,background,i*w,j*h);
89c4a3a6 sago007 2008-08-29 14:32 2754
    standardBackground = true;
89c4a3a6 sago007 2008-08-29 14:32 2755
}
89c4a3a6 sago007 2008-08-29 14:32 2756
89c4a3a6 sago007 2008-08-29 14:32 2757
//Generates the background with red board backs
4b0c248f sago007 2010-11-10 21:13 2758
static void MakeBackground(int xsize,int ysize,BlockGame *theGame, BlockGame *theGame2)
89c4a3a6 sago007 2008-08-29 14:32 2759
{
27ae0175 sago007 2009-01-30 06:02 2760
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2761
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
e1290bdf sago007 2010-10-25 19:56 2762
    DrawIMG(boardBackBack,background,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2763
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2764
}
89c4a3a6 sago007 2008-08-29 14:32 2765
4b0c248f sago007 2010-11-10 21:13 2766
static void MakeBackground(int xsize, int ysize, BlockGame *theGame)
89c4a3a6 sago007 2008-08-29 14:32 2767
{
27ae0175 sago007 2009-01-30 06:02 2768
    MakeBackground(xsize,ysize);
e1290bdf sago007 2010-10-25 19:56 2769
    DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68);
89c4a3a6 sago007 2008-08-29 14:32 2770
    standardBackground = false;
89c4a3a6 sago007 2008-08-29 14:32 2771
}
89c4a3a6 sago007 2008-08-29 14:32 2772
89c4a3a6 sago007 2008-08-29 14:32 2773
89c4a3a6 sago007 2008-08-29 14:32 2774
//The function that allows the player to choose PuzzleLevel
89c4a3a6 sago007 2008-08-29 14:32 2775
int PuzzleLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2776
{
89c4a3a6 sago007 2008-08-29 14:32 2777
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2778
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2779
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2780
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2781
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2782
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2783
89c4a3a6 sago007 2008-08-29 14:32 2784
    //Loads the levels, if they havn't been loaded:
89c4a3a6 sago007 2008-08-29 14:32 2785
    LoadPuzzleStages();
89c4a3a6 sago007 2008-08-29 14:32 2786
89c4a3a6 sago007 2008-08-29 14:32 2787
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2788
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2789
89c4a3a6 sago007 2008-08-29 14:32 2790
    ifstream puzzleFile(puzzleSavePath.c_str(),ios::binary);
27ae0175 sago007 2009-01-30 06:02 2791
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2792
    if (puzzleFile)
89c4a3a6 sago007 2008-08-29 14:32 2793
    {
89c4a3a6 sago007 2008-08-29 14:32 2794
        for (int i=0;(i<nrOfPuzzles)&&(!puzzleFile.eof()); i++)
89c4a3a6 sago007 2008-08-29 14:32 2795
        {
89c4a3a6 sago007 2008-08-29 14:32 2796
            puzzleFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2797
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2798
        }
89c4a3a6 sago007 2008-08-29 14:32 2799
        puzzleFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2800
    }
89c4a3a6 sago007 2008-08-29 14:32 2801
    else
89c4a3a6 sago007 2008-08-29 14:32 2802
    {
89c4a3a6 sago007 2008-08-29 14:32 2803
        tempBool = false;
89c4a3a6 sago007 2008-08-29 14:32 2804
        for (int i=0; i<nrOfPuzzles; i++)
89c4a3a6 sago007 2008-08-29 14:32 2805
            puzzleCleared[i] = tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2806
    }
89c4a3a6 sago007 2008-08-29 14:32 2807
89c4a3a6 sago007 2008-08-29 14:32 2808
    do
89c4a3a6 sago007 2008-08-29 14:32 2809
    {
89c4a3a6 sago007 2008-08-29 14:32 2810
        nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2811
89c4a3a6 sago007 2008-08-29 14:32 2812
89c4a3a6 sago007 2008-08-29 14:32 2813
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2814
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 2815
        SFont_Write(screen,fBlueFont,xplace+12,yplace+2,"Select Puzzle");
89c4a3a6 sago007 2008-08-29 14:32 2816
        //Now drow the fields you click in (and a V if clicked):
89c4a3a6 sago007 2008-08-29 14:32 2817
        for (int i = 0; i < nrOfPuzzles;i++)
89c4a3a6 sago007 2008-08-29 14:32 2818
        {
89c4a3a6 sago007 2008-08-29 14:32 2819
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2820
            if (puzzleCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2821
        }
89c4a3a6 sago007 2008-08-29 14:32 2822
89c4a3a6 sago007 2008-08-29 14:32 2823
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2824
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2825
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2826
            {
89c4a3a6 sago007 2008-08-29 14:32 2827
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 2828
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 2829
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2830
                }
89c4a3a6 sago007 2008-08-29 14:32 2831
            }
89c4a3a6 sago007 2008-08-29 14:32 2832
89c4a3a6 sago007 2008-08-29 14:32 2833
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2834
89c4a3a6 sago007 2008-08-29 14:32 2835
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2836
89c4a3a6 sago007 2008-08-29 14:32 2837
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2838
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2839
        {
89c4a3a6 sago007 2008-08-29 14:32 2840
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2841
        }
89c4a3a6 sago007 2008-08-29 14:32 2842
89c4a3a6 sago007 2008-08-29 14:32 2843
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2844
        {
89c4a3a6 sago007 2008-08-29 14:32 2845
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2846
89c4a3a6 sago007 2008-08-29 14:32 2847
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 2848
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2849
            for (i = 0; (i<nrOfPuzzles/10)||((i<nrOfPuzzles/10+1)&&(nrOfPuzzles%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2850
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2851
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2852
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2853
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 2854
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2855
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2856
                    {
89c4a3a6 sago007 2008-08-29 14:32 2857
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 2858
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2859
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 2860
                    }
89c4a3a6 sago007 2008-08-29 14:32 2861
        }
89c4a3a6 sago007 2008-08-29 14:32 2862
8d488d32 sago007 2011-04-17 13:02 2863
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 2864
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 2865
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 2866
89c4a3a6 sago007 2008-08-29 14:32 2867
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 2868
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2869
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 2870
}
89c4a3a6 sago007 2008-08-29 14:32 2871
89c4a3a6 sago007 2008-08-29 14:32 2872
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 2873
int StageLevelSelect()
89c4a3a6 sago007 2008-08-29 14:32 2874
{
89c4a3a6 sago007 2008-08-29 14:32 2875
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 2876
    const int yplace = 300;
89c4a3a6 sago007 2008-08-29 14:32 2877
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 2878
    int levelNr, mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 2879
    bool levelSelected = false;
89c4a3a6 sago007 2008-08-29 14:32 2880
    bool tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2881
    Uint32 tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2882
    Uint32 totalScore = 0;
89c4a3a6 sago007 2008-08-29 14:32 2883
    Uint32 totalTime = 0;
89c4a3a6 sago007 2008-08-29 14:32 2884
89c4a3a6 sago007 2008-08-29 14:32 2885
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 2886
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2887
27ae0175 sago007 2009-01-30 06:02 2888
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 2889
    ifstream stageFile(stageClearSavePath.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 2890
    if (stageFile)
89c4a3a6 sago007 2008-08-29 14:32 2891
    {
89c4a3a6 sago007 2008-08-29 14:32 2892
        for (int i = 0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2893
        {
89c4a3a6 sago007 2008-08-29 14:32 2894
            stageFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
89c4a3a6 sago007 2008-08-29 14:32 2895
            stageCleared[i]=tempBool;
89c4a3a6 sago007 2008-08-29 14:32 2896
        }
89c4a3a6 sago007 2008-08-29 14:32 2897
        if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2898
        {
89c4a3a6 sago007 2008-08-29 14:32 2899
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2900
            {
89c4a3a6 sago007 2008-08-29 14:32 2901
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2902
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2903
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2904
                stageScores[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2905
                totalScore+=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2906
            }
89c4a3a6 sago007 2008-08-29 14:32 2907
            for(int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2908
            {
89c4a3a6 sago007 2008-08-29 14:32 2909
                tempUInt32 = 0;
89c4a3a6 sago007 2008-08-29 14:32 2910
                if(!stageFile.eof())
89c4a3a6 sago007 2008-08-29 14:32 2911
                    stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
89c4a3a6 sago007 2008-08-29 14:32 2912
                stageTimes[i]=tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2913
                totalTime += tempUInt32;
89c4a3a6 sago007 2008-08-29 14:32 2914
            }
89c4a3a6 sago007 2008-08-29 14:32 2915
        }
89c4a3a6 sago007 2008-08-29 14:32 2916
        else
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
                 stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2921
                 stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2922
            }
89c4a3a6 sago007 2008-08-29 14:32 2923
        }
89c4a3a6 sago007 2008-08-29 14:32 2924
        stageFile.close();
89c4a3a6 sago007 2008-08-29 14:32 2925
    }
89c4a3a6 sago007 2008-08-29 14:32 2926
    else
89c4a3a6 sago007 2008-08-29 14:32 2927
    {
89c4a3a6 sago007 2008-08-29 14:32 2928
        for (int i=0; i<nrOfStageLevels; i++)
89c4a3a6 sago007 2008-08-29 14:32 2929
        {
89c4a3a6 sago007 2008-08-29 14:32 2930
            stageCleared[i]= false;
89c4a3a6 sago007 2008-08-29 14:32 2931
            stageScores[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2932
            stageTimes[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 2933
        }
89c4a3a6 sago007 2008-08-29 14:32 2934
    }
89c4a3a6 sago007 2008-08-29 14:32 2935
89c4a3a6 sago007 2008-08-29 14:32 2936
89c4a3a6 sago007 2008-08-29 14:32 2937
    do
89c4a3a6 sago007 2008-08-29 14:32 2938
    {
89c4a3a6 sago007 2008-08-29 14:32 2939
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 2940
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 2941
        DrawIMG(iCheckBoxArea,screen,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 2942
        SFont_Write(screen,fBlueFont,xplace+12,yplace+2,"Stage Clear Level Select");
89c4a3a6 sago007 2008-08-29 14:32 2943
        for (int i = 0; i < nrOfStageLevels;i++)
89c4a3a6 sago007 2008-08-29 14:32 2944
        {
89c4a3a6 sago007 2008-08-29 14:32 2945
            DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2946
            if (stageCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
89c4a3a6 sago007 2008-08-29 14:32 2947
        }
89c4a3a6 sago007 2008-08-29 14:32 2948
89c4a3a6 sago007 2008-08-29 14:32 2949
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 2950
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 2951
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 2952
            {
89c4a3a6 sago007 2008-08-29 14:32 2953
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 2954
                    levelNr = -1;
89c4a3a6 sago007 2008-08-29 14:32 2955
                    levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2956
                }
89c4a3a6 sago007 2008-08-29 14:32 2957
            }
89c4a3a6 sago007 2008-08-29 14:32 2958
89c4a3a6 sago007 2008-08-29 14:32 2959
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 2960
89c4a3a6 sago007 2008-08-29 14:32 2961
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 2962
89c4a3a6 sago007 2008-08-29 14:32 2963
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 2964
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 2965
        {
89c4a3a6 sago007 2008-08-29 14:32 2966
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 2967
        }
89c4a3a6 sago007 2008-08-29 14:32 2968
89c4a3a6 sago007 2008-08-29 14:32 2969
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 2970
        {
89c4a3a6 sago007 2008-08-29 14:32 2971
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 2972
89c4a3a6 sago007 2008-08-29 14:32 2973
            int levelClicked = -1;
89c4a3a6 sago007 2008-08-29 14:32 2974
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2975
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2976
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2977
                    levelClicked = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2978
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2979
            if (levelClicked != -1)
89c4a3a6 sago007 2008-08-29 14:32 2980
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2981
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2982
                    {
89c4a3a6 sago007 2008-08-29 14:32 2983
                        levelClicked +=j;
89c4a3a6 sago007 2008-08-29 14:32 2984
                        levelSelected = true;
89c4a3a6 sago007 2008-08-29 14:32 2985
                        levelNr = levelClicked;
89c4a3a6 sago007 2008-08-29 14:32 2986
                    }
89c4a3a6 sago007 2008-08-29 14:32 2987
        }
89c4a3a6 sago007 2008-08-29 14:32 2988
        //Find what we are over:
89c4a3a6 sago007 2008-08-29 14:32 2989
            int overLevel = -1;
89c4a3a6 sago007 2008-08-29 14:32 2990
            int i;
89c4a3a6 sago007 2008-08-29 14:32 2991
            for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
89c4a3a6 sago007 2008-08-29 14:32 2992
                if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
89c4a3a6 sago007 2008-08-29 14:32 2993
                    overLevel = i*10;
89c4a3a6 sago007 2008-08-29 14:32 2994
            i++;
89c4a3a6 sago007 2008-08-29 14:32 2995
            if (overLevel != -1)
89c4a3a6 sago007 2008-08-29 14:32 2996
                for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
89c4a3a6 sago007 2008-08-29 14:32 2997
                    if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
89c4a3a6 sago007 2008-08-29 14:32 2998
                    {
89c4a3a6 sago007 2008-08-29 14:32 2999
                        overLevel +=j;
89c4a3a6 sago007 2008-08-29 14:32 3000
                        string scoreString = "Best score: 0";
89c4a3a6 sago007 2008-08-29 14:32 3001
                        string timeString = "Time used: -- : --";
89c4a3a6 sago007 2008-08-29 14:32 3002
                        
89c4a3a6 sago007 2008-08-29 14:32 3003
                        if(stageScores.at(overLevel)>0)
89c4a3a6 sago007 2008-08-29 14:32 3004
                            scoreString = "Best score: "+itoa(stageScores[overLevel]);
89c4a3a6 sago007 2008-08-29 14:32 3005
                        if(stageTimes[overLevel]>0)
89c4a3a6 sago007 2008-08-29 14:32 3006
                            timeString = "Time used: "+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60);
89c4a3a6 sago007 2008-08-29 14:32 3007
                        
89c4a3a6 sago007 2008-08-29 14:32 3008
                        SFont_Write(screen,fBlueFont,200,200,scoreString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3009
                        SFont_Write(screen,fBlueFont,200,250,timeString.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3010
                        
89c4a3a6 sago007 2008-08-29 14:32 3011
                        overLevel;
89c4a3a6 sago007 2008-08-29 14:32 3012
                    }
89c4a3a6 sago007 2008-08-29 14:32 3013
            string totalString = "Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60);
89c4a3a6 sago007 2008-08-29 14:32 3014
            SFont_Write(screen,fBlueFont,200,600,totalString.c_str());   
89c4a3a6 sago007 2008-08-29 14:32 3015
8d488d32 sago007 2011-04-17 13:02 3016
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3017
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3018
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3019
89c4a3a6 sago007 2008-08-29 14:32 3020
    } while (!levelSelected);
89c4a3a6 sago007 2008-08-29 14:32 3021
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3022
    return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 3023
}
89c4a3a6 sago007 2008-08-29 14:32 3024
89c4a3a6 sago007 2008-08-29 14:32 3025
//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 3026
int startSingleVs()
89c4a3a6 sago007 2008-08-29 14:32 3027
{
89c4a3a6 sago007 2008-08-29 14:32 3028
    //Where to place the windows
89c4a3a6 sago007 2008-08-29 14:32 3029
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3030
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3031
    Uint8 *keys;	//To take keyboard input
89c4a3a6 sago007 2008-08-29 14:32 3032
    int mousex, mousey;	//To allow mouse
89c4a3a6 sago007 2008-08-29 14:32 3033
    bool done = false;	//When are we done?
89c4a3a6 sago007 2008-08-29 14:32 3034
27ae0175 sago007 2009-01-30 06:02 3035
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3036
    DrawIMG(changeButtonsBack,background,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 3037
    SFont_Write(background,fBlueFont,xplace+10,yplace+10,"1 : Very Easy");
89c4a3a6 sago007 2008-08-29 14:32 3038
    SFont_Write(background,fBlueFont,xplace+10,yplace+40,"2 : Easy");
89c4a3a6 sago007 2008-08-29 14:32 3039
    SFont_Write(background,fBlueFont,xplace+10,yplace+70,"3 : Below Normal");
89c4a3a6 sago007 2008-08-29 14:32 3040
    SFont_Write(background,fBlueFont,xplace+10,yplace+100,"4 : Normal");
89c4a3a6 sago007 2008-08-29 14:32 3041
    SFont_Write(background,fBlueFont,xplace+10,yplace+130,"5 : Above Normal");
89c4a3a6 sago007 2008-08-29 14:32 3042
    SFont_Write(background,fBlueFont,xplace+10,yplace+160,"6 : Hard");
89c4a3a6 sago007 2008-08-29 14:32 3043
    SFont_Write(background,fBlueFont,xplace+10,yplace+190,"7 : Hardest");
89c4a3a6 sago007 2008-08-29 14:32 3044
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3045
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3046
    do
89c4a3a6 sago007 2008-08-29 14:32 3047
    {
89c4a3a6 sago007 2008-08-29 14:32 3048
89c4a3a6 sago007 2008-08-29 14:32 3049
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3050
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3051
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3052
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3053
            {
4f1d27f1 sago007 2011-03-18 15:53 3054
                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 3055
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3056
                }
4f1d27f1 sago007 2011-03-18 15:53 3057
                if ( event.key.keysym.sym == SDLK_1 || event.key.keysym.sym == SDLK_KP1 ) {
89c4a3a6 sago007 2008-08-29 14:32 3058
                    return 0;
89c4a3a6 sago007 2008-08-29 14:32 3059
                }
4f1d27f1 sago007 2011-03-18 15:53 3060
                if ( event.key.keysym.sym == SDLK_2 || event.key.keysym.sym == SDLK_KP2 ) {
89c4a3a6 sago007 2008-08-29 14:32 3061
                    return 1;
89c4a3a6 sago007 2008-08-29 14:32 3062
                }
4f1d27f1 sago007 2011-03-18 15:53 3063
                if ( event.key.keysym.sym == SDLK_3 || event.key.keysym.sym == SDLK_KP3 ) {
89c4a3a6 sago007 2008-08-29 14:32 3064
                    return 2;
89c4a3a6 sago007 2008-08-29 14:32 3065
                }
4f1d27f1 sago007 2011-03-18 15:53 3066
                if ( event.key.keysym.sym == SDLK_4 || event.key.keysym.sym == SDLK_KP4 ) {
89c4a3a6 sago007 2008-08-29 14:32 3067
                    return 3;
89c4a3a6 sago007 2008-08-29 14:32 3068
                }
4f1d27f1 sago007 2011-03-18 15:53 3069
                if ( event.key.keysym.sym == SDLK_5 || event.key.keysym.sym == SDLK_KP5 ) {
89c4a3a6 sago007 2008-08-29 14:32 3070
                    return 4;
89c4a3a6 sago007 2008-08-29 14:32 3071
                }
4f1d27f1 sago007 2011-03-18 15:53 3072
                if ( event.key.keysym.sym == SDLK_6 || event.key.keysym.sym == SDLK_KP6 ) {
89c4a3a6 sago007 2008-08-29 14:32 3073
                    return 5;
89c4a3a6 sago007 2008-08-29 14:32 3074
                }
4f1d27f1 sago007 2011-03-18 15:53 3075
                if ( event.key.keysym.sym == SDLK_7 || event.key.keysym.sym == SDLK_KP7 ) {
89c4a3a6 sago007 2008-08-29 14:32 3076
                    return 6;
89c4a3a6 sago007 2008-08-29 14:32 3077
                }
89c4a3a6 sago007 2008-08-29 14:32 3078
            }
89c4a3a6 sago007 2008-08-29 14:32 3079
89c4a3a6 sago007 2008-08-29 14:32 3080
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3081
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3082
        {
89c4a3a6 sago007 2008-08-29 14:32 3083
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3084
        }
89c4a3a6 sago007 2008-08-29 14:32 3085
89c4a3a6 sago007 2008-08-29 14:32 3086
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3087
        {
89c4a3a6 sago007 2008-08-29 14:32 3088
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3089
89c4a3a6 sago007 2008-08-29 14:32 3090
            for (int i=0; i<7;i++)
89c4a3a6 sago007 2008-08-29 14:32 3091
            {
89c4a3a6 sago007 2008-08-29 14:32 3092
                if ((mousex>xplace+10)&&(mousex<xplace+410)&&(mousey>yplace+10+i*30)&&(mousey<yplace+38+i*30))
89c4a3a6 sago007 2008-08-29 14:32 3093
                    return i;
89c4a3a6 sago007 2008-08-29 14:32 3094
            }
89c4a3a6 sago007 2008-08-29 14:32 3095
        }
89c4a3a6 sago007 2008-08-29 14:32 3096
89c4a3a6 sago007 2008-08-29 14:32 3097
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3098
        DrawIMG(background, screen, 0, 0);
8d488d32 sago007 2011-04-17 13:02 3099
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3100
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3101
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3102
    }while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3103
89c4a3a6 sago007 2008-08-29 14:32 3104
89c4a3a6 sago007 2008-08-29 14:32 3105
    return 3; //Returns normal
89c4a3a6 sago007 2008-08-29 14:32 3106
}
89c4a3a6 sago007 2008-08-29 14:32 3107
89c4a3a6 sago007 2008-08-29 14:32 3108
//The function that allows the player to choose Level number
89c4a3a6 sago007 2008-08-29 14:32 3109
void startVsMenu()
89c4a3a6 sago007 2008-08-29 14:32 3110
{
89c4a3a6 sago007 2008-08-29 14:32 3111
    const int xplace = 200;
89c4a3a6 sago007 2008-08-29 14:32 3112
    const int yplace = 100;
89c4a3a6 sago007 2008-08-29 14:32 3113
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3114
    int mousex, mousey;
89c4a3a6 sago007 2008-08-29 14:32 3115
    bool done = false;
89c4a3a6 sago007 2008-08-29 14:32 3116
89c4a3a6 sago007 2008-08-29 14:32 3117
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3118
    //int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3119
27ae0175 sago007 2009-01-30 06:02 3120
    MakeBackground(xsize,ysize);
89c4a3a6 sago007 2008-08-29 14:32 3121
    SFont_Write(background,fBlueFont,360,650,"Press ESC to accept");
27ae0175 sago007 2009-01-30 06:02 3122
    DrawIMG(bBack,background,xsize/2-120/2,600);
89c4a3a6 sago007 2008-08-29 14:32 3123
    do
89c4a3a6 sago007 2008-08-29 14:32 3124
    {
89c4a3a6 sago007 2008-08-29 14:32 3125
        //nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3126
        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3127
        DrawIMG(changeButtonsBack,screen,xplace,yplace);
89c4a3a6 sago007 2008-08-29 14:32 3128
        SFont_Write(screen,fBlueFont,xplace+50,yplace+20,"Player 1");
89c4a3a6 sago007 2008-08-29 14:32 3129
        SFont_Write(screen,fBlueFont,xplace+300+50,yplace+20,"Player 2");
89c4a3a6 sago007 2008-08-29 14:32 3130
        SFont_Write(screen,fBlueFont,xplace+50,yplace+70,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 3131
        SFont_Write(screen,fBlueFont,xplace+50+300,yplace+70,"Speed:");
89c4a3a6 sago007 2008-08-29 14:32 3132
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3133
        {
89c4a3a6 sago007 2008-08-29 14:32 3134
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3135
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3136
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3137
            SFont_Write(screen,fBlueFont,xplace+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3138
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3139
            if (player1Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3140
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3141
        }
89c4a3a6 sago007 2008-08-29 14:32 3142
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3143
        {
89c4a3a6 sago007 2008-08-29 14:32 3144
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3145
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3146
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3147
            SFont_Write(screen,fBlueFont,xplace+300+50+i*40,yplace+110,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3148
            DrawIMG(iLevelCheckBox,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3149
            if (player2Speed==i)
89c4a3a6 sago007 2008-08-29 14:32 3150
                DrawIMG(iLevelCheck,screen,xplace+300+50+i*40,yplace+150);
89c4a3a6 sago007 2008-08-29 14:32 3151
        }
89c4a3a6 sago007 2008-08-29 14:32 3152
        SFont_Write(screen,fBlueFont,xplace+50,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3153
        DrawIMG(iLevelCheckBox,screen,xplace+50+70,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3154
        if (player1AI)
89c4a3a6 sago007 2008-08-29 14:32 3155
            DrawIMG(iLevelCheck,screen,xplace+50+70,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3156
        SFont_Write(screen,fBlueFont,xplace+50,yplace+250,"TT Handicap: ");
89c4a3a6 sago007 2008-08-29 14:32 3157
        SFont_Write(screen,fBlueFont,xplace+50+300,yplace+200,"AI: ");
89c4a3a6 sago007 2008-08-29 14:32 3158
        DrawIMG(iLevelCheckBox,screen,xplace+50+70+300,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3159
        if (player2AI)
89c4a3a6 sago007 2008-08-29 14:32 3160
            DrawIMG(iLevelCheck,screen,xplace+50+70+300,yplace+200);
89c4a3a6 sago007 2008-08-29 14:32 3161
        SFont_Write(screen,fBlueFont,xplace+50+300,yplace+250,"TT Handicap: ");
89c4a3a6 sago007 2008-08-29 14:32 3162
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3163
        {
89c4a3a6 sago007 2008-08-29 14:32 3164
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3165
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3166
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3167
            SFont_Write(screen,fBlueFont,xplace+50+i*40,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3168
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3169
            if (player1handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3170
                DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3171
        }
89c4a3a6 sago007 2008-08-29 14:32 3172
        for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3173
        {
89c4a3a6 sago007 2008-08-29 14:32 3174
            char levelS[2]; //level string;
89c4a3a6 sago007 2008-08-29 14:32 3175
            levelS[0]='1'+i;
89c4a3a6 sago007 2008-08-29 14:32 3176
            levelS[1]=0;
89c4a3a6 sago007 2008-08-29 14:32 3177
            SFont_Write(screen,fBlueFont,xplace+50+i*40+300,yplace+290,levelS);
89c4a3a6 sago007 2008-08-29 14:32 3178
            DrawIMG(iLevelCheckBox,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3179
            if (player2handicap==i)
89c4a3a6 sago007 2008-08-29 14:32 3180
                DrawIMG(iLevelCheck,screen,xplace+50+i*40+300,yplace+330);
89c4a3a6 sago007 2008-08-29 14:32 3181
        }
89c4a3a6 sago007 2008-08-29 14:32 3182
89c4a3a6 sago007 2008-08-29 14:32 3183
        SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3184
        while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3185
            if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3186
            {
89c4a3a6 sago007 2008-08-29 14:32 3187
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
89c4a3a6 sago007 2008-08-29 14:32 3188
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3189
                }
89c4a3a6 sago007 2008-08-29 14:32 3190
                if ( event.key.keysym.sym == SDLK_RETURN ) {
89c4a3a6 sago007 2008-08-29 14:32 3191
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3192
                }
89c4a3a6 sago007 2008-08-29 14:32 3193
                if ( event.key.keysym.sym == SDLK_KP_ENTER ) {
89c4a3a6 sago007 2008-08-29 14:32 3194
                    done = true;
89c4a3a6 sago007 2008-08-29 14:32 3195
                }
89c4a3a6 sago007 2008-08-29 14:32 3196
            }
89c4a3a6 sago007 2008-08-29 14:32 3197
89c4a3a6 sago007 2008-08-29 14:32 3198
        keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 3199
89c4a3a6 sago007 2008-08-29 14:32 3200
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 3201
89c4a3a6 sago007 2008-08-29 14:32 3202
        // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 3203
        if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 3204
        {
89c4a3a6 sago007 2008-08-29 14:32 3205
            bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 3206
        }
89c4a3a6 sago007 2008-08-29 14:32 3207
89c4a3a6 sago007 2008-08-29 14:32 3208
        if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 3209
        {
89c4a3a6 sago007 2008-08-29 14:32 3210
            bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 3211
89c4a3a6 sago007 2008-08-29 14:32 3212
            if ((mousex>xplace+50+70)&&(mousey>yplace+200)&&(mousex<xplace+50+70+30)&&(mousey<yplace+200+30))
89c4a3a6 sago007 2008-08-29 14:32 3213
                player1AI=!player1AI;
89c4a3a6 sago007 2008-08-29 14:32 3214
            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 3215
                player2AI=!player2AI;
89c4a3a6 sago007 2008-08-29 14:32 3216
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3217
            {
89c4a3a6 sago007 2008-08-29 14:32 3218
                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 3219
                    player1Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3220
            }
89c4a3a6 sago007 2008-08-29 14:32 3221
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3222
            {
89c4a3a6 sago007 2008-08-29 14:32 3223
                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 3224
                    player2Speed=i;
89c4a3a6 sago007 2008-08-29 14:32 3225
            }
89c4a3a6 sago007 2008-08-29 14:32 3226
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3227
            {
89c4a3a6 sago007 2008-08-29 14:32 3228
                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 3229
                    player1handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3230
            }
89c4a3a6 sago007 2008-08-29 14:32 3231
            for (int i=0; i<5;i++)
89c4a3a6 sago007 2008-08-29 14:32 3232
            {
89c4a3a6 sago007 2008-08-29 14:32 3233
                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 3234
                    player2handicap=i;
89c4a3a6 sago007 2008-08-29 14:32 3235
            }
27ae0175 sago007 2009-01-30 06:02 3236
            if ((mousex>xsize/2-120/2)&&(mousex<xsize/2+120/2)&&(mousey>600)&&(mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 3237
                done = true;
89c4a3a6 sago007 2008-08-29 14:32 3238
        }
89c4a3a6 sago007 2008-08-29 14:32 3239
8d488d32 sago007 2011-04-17 13:02 3240
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 3241
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 3242
        SDL_Flip(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 3243
        SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3244
89c4a3a6 sago007 2008-08-29 14:32 3245
    } while (!done);
89c4a3a6 sago007 2008-08-29 14:32 3246
    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3247
}
89c4a3a6 sago007 2008-08-29 14:32 3248
89c4a3a6 sago007 2008-08-29 14:32 3249
//This function will promt for the user to select another file for puzzle mode
89c4a3a6 sago007 2008-08-29 14:32 3250
void changePuzzleLevels()
89c4a3a6 sago007 2008-08-29 14:32 3251
{
89c4a3a6 sago007 2008-08-29 14:32 3252
    char theFileName[30];
89c4a3a6 sago007 2008-08-29 14:32 3253
    strcpy(theFileName,puzzleName.c_str());
89c4a3a6 sago007 2008-08-29 14:32 3254
    for (int i=puzzleName.length();i<30;i++)
89c4a3a6 sago007 2008-08-29 14:32 3255
        theFileName[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 3256
    theFileName[29]=0;
89c4a3a6 sago007 2008-08-29 14:32 3257
    if (OpenFileDialogbox(200,100,theFileName))
89c4a3a6 sago007 2008-08-29 14:32 3258
    {
89c4a3a6 sago007 2008-08-29 14:32 3259
        for (int i=28;((theFileName[i]==' ')&&(i>0));i--)
89c4a3a6 sago007 2008-08-29 14:32 3260
            theFileName[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 3261
        puzzleName = theFileName;
89c4a3a6 sago007 2008-08-29 14:32 3262
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3263
        string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3264
        puzzleSavePath = home+"/.gamesaves/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3265
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3266
        string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3267
        if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3268
        {
89c4a3a6 sago007 2008-08-29 14:32 3269
            puzzleSavePath = home+"/My Games/blockattack/"+puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3270
        }
89c4a3a6 sago007 2008-08-29 14:32 3271
        else
89c4a3a6 sago007 2008-08-29 14:32 3272
        {
89c4a3a6 sago007 2008-08-29 14:32 3273
            puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3274
        }
89c4a3a6 sago007 2008-08-29 14:32 3275
#else
89c4a3a6 sago007 2008-08-29 14:32 3276
        puzzleSavePath = puzzleName+".save";
89c4a3a6 sago007 2008-08-29 14:32 3277
#endif
89c4a3a6 sago007 2008-08-29 14:32 3278
    }
89c4a3a6 sago007 2008-08-29 14:32 3279
89c4a3a6 sago007 2008-08-29 14:32 3280
}
89c4a3a6 sago007 2008-08-29 14:32 3281
6d48320c sago007 2009-03-28 17:06 3282
class Keymenu {
6d48320c sago007 2009-03-28 17:06 3283
    static void setXY(int x, int y)
6d48320c sago007 2009-03-28 17:06 3284
    {
6d48320c sago007 2009-03-28 17:06 3285
        keymenu.x = x;
6d48320c sago007 2009-03-28 17:06 3286
        keymenu.y = y;
6d48320c sago007 2009-03-28 17:06 3287
    }
6d48320c sago007 2009-03-28 17:06 3288
6d48320c sago007 2009-03-28 17:06 3289
    static void startMenu()
6d48320c sago007 2009-03-28 17:06 3290
    {
6d48320c sago007 2009-03-28 17:06 3291
        keymenu.activated = true;
6d48320c sago007 2009-03-28 17:06 3292
        setXY(0,0);
6d48320c sago007 2009-03-28 17:06 3293
    }
6d48320c sago007 2009-03-28 17:06 3294
6d48320c sago007 2009-03-28 17:06 3295
    static void stopMenu()
6d48320c sago007 2009-03-28 17:06 3296
    {
6d48320c sago007 2009-03-28 17:06 3297
        keymenu.activated = false;
6d48320c sago007 2009-03-28 17:06 3298
    }
6d48320c sago007 2009-03-28 17:06 3299
};
6d48320c sago007 2009-03-28 17:06 3300
30f910dd sago007 2010-11-10 21:02 3301
static BlockGameSdl *player1;
30f910dd sago007 2010-11-10 21:02 3302
static BlockGameSdl *player2;
30f910dd sago007 2010-11-10 21:02 3303
30f910dd sago007 2010-11-10 21:02 3304
void StartSinglePlayerEndless() {
30f910dd sago007 2010-11-10 21:02 3305
    //1 player - endless
30f910dd sago007 2010-11-10 21:02 3306
    player1->NewGame(50,100,SDL_GetTicks());
30f910dd sago007 2010-11-10 21:02 3307
    player1->putStartBlocks(time(0));
30f910dd sago007 2010-11-10 21:02 3308
    bNewGameOpen = false;
30f910dd sago007 2010-11-10 21:02 3309
    b1playerOpen = false;
30f910dd sago007 2010-11-10 21:02 3310
    twoPlayers =false;
30f910dd sago007 2010-11-10 21:02 3311
    player2->SetGameOver();
30f910dd sago007 2010-11-10 21:02 3312
    showGame = true;
30f910dd sago007 2010-11-10 21:02 3313
    strcpy(player1->name, player1name);
30f910dd sago007 2010-11-10 21:02 3314
    strcpy(player2->name, player2name);
30f910dd sago007 2010-11-10 21:02 3315
}
30f910dd sago007 2010-11-10 21:02 3316
4f1d27f1 sago007 2011-03-18 15:53 3317
void StartSinglePlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3318
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3319
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3320
    twoPlayers =false;
4f1d27f1 sago007 2011-03-18 15:53 3321
    player2->SetGameOver();
4f1d27f1 sago007 2011-03-18 15:53 3322
    showGame = true;
4f1d27f1 sago007 2011-03-18 15:53 3323
    //vsMode = false;
4f1d27f1 sago007 2011-03-18 15:53 3324
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3325
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3326
}
4f1d27f1 sago007 2011-03-18 15:53 3327
4f1d27f1 sago007 2011-03-18 15:53 3328
4f1d27f1 sago007 2011-03-18 15:53 3329
void StarTwoPlayerTimeTrial() {
4f1d27f1 sago007 2011-03-18 15:53 3330
    player1->NewTimeTrialGame(50,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3331
    player2->NewTimeTrialGame(xsize-500,100,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3332
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3333
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3334
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3335
    closeAllMenus();
4f1d27f1 sago007 2011-03-18 15:53 3336
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3337
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3338
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3339
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3340
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3341
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3342
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3343
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3344
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3345
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3346
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3347
}
4f1d27f1 sago007 2011-03-18 15:53 3348
4f1d27f1 sago007 2011-03-18 15:53 3349
void StartTwoPlayerVs() {
4f1d27f1 sago007 2011-03-18 15:53 3350
    //2 player - VsMode
4f1d27f1 sago007 2011-03-18 15:53 3351
    player1->NewVsGame(50,100,player2,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3352
    player2->NewVsGame(xsize-500,100,player1,SDL_GetTicks());
4f1d27f1 sago007 2011-03-18 15:53 3353
    bNewGameOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3354
    //vsMode = true;
4f1d27f1 sago007 2011-03-18 15:53 3355
    twoPlayers = true;
4f1d27f1 sago007 2011-03-18 15:53 3356
    b2playersOpen = false;
4f1d27f1 sago007 2011-03-18 15:53 3357
    player1->setGameSpeed(player1Speed);
4f1d27f1 sago007 2011-03-18 15:53 3358
    player2->setGameSpeed(player2Speed);
4f1d27f1 sago007 2011-03-18 15:53 3359
    player1->setHandicap(player1handicap);
4f1d27f1 sago007 2011-03-18 15:53 3360
    player2->setHandicap(player2handicap);
4f1d27f1 sago007 2011-03-18 15:53 3361
    if(player1AI)
4f1d27f1 sago007 2011-03-18 15:53 3362
        player1->setAIlevel(player1AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3363
    if(player2AI)
4f1d27f1 sago007 2011-03-18 15:53 3364
        player2->setAIlevel(player2AIlevel);
4f1d27f1 sago007 2011-03-18 15:53 3365
    int theTime = time(0);
4f1d27f1 sago007 2011-03-18 15:53 3366
    player1->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3367
    player2->putStartBlocks(theTime);
4f1d27f1 sago007 2011-03-18 15:53 3368
    strcpy(player1->name, player1name);
4f1d27f1 sago007 2011-03-18 15:53 3369
    strcpy(player2->name, player2name);
4f1d27f1 sago007 2011-03-18 15:53 3370
}
4f1d27f1 sago007 2011-03-18 15:53 3371
1572de2b sago007 2008-09-11 18:15 3372
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3373
#include "NetworkThing.hpp"
eec83b7d sago007 2009-03-29 15:46 3374
//#include "MenuSystem.h"
89c4a3a6 sago007 2008-08-29 14:32 3375
#endif
89c4a3a6 sago007 2008-08-29 14:32 3376
89c4a3a6 sago007 2008-08-29 14:32 3377
//The main function, quite big... too big
89c4a3a6 sago007 2008-08-29 14:32 3378
int main(int argc, char *argv[])
89c4a3a6 sago007 2008-08-29 14:32 3379
{
89c4a3a6 sago007 2008-08-29 14:32 3380
    //We first create the folder there we will save (only on UNIX systems)
89c4a3a6 sago007 2008-08-29 14:32 3381
    //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 3382
#if defined(__unix__)
42f8ed5f sago007 2009-03-05 11:47 3383
    //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 3384
    if(system("mkdir -p ~/.gamesaves/blockattack/screenshots"))
42f8ed5f sago007 2009-03-05 11:47 3385
        cout << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl;
42f8ed5f sago007 2009-03-05 11:47 3386
    if(system("mkdir -p ~/.gamesaves/blockattack/replays"))
42f8ed5f sago007 2009-03-05 11:47 3387
        cout << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl;
42f8ed5f sago007 2009-03-05 11:47 3388
    if(system("mkdir -p ~/.gamesaves/blockattack/puzzles"))
42f8ed5f sago007 2009-03-05 11:47 3389
        cout << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3390
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3391
    //Now for Windows NT/2k/xp/2k3 etc.
89c4a3a6 sago007 2008-08-29 14:32 3392
    string tempA = getMyDocumentsPath()+"\\My Games";
c325f4fa sago007 2009-05-09 18:33 3393
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3394
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack";
c325f4fa sago007 2009-05-09 18:33 3395
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3396
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays";
c325f4fa sago007 2009-05-09 18:33 3397
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3398
    tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots";
c325f4fa sago007 2009-05-09 18:33 3399
    CreateDirectory(tempA.c_str(),NULL);
89c4a3a6 sago007 2008-08-29 14:32 3400
#endif
78d03b38 sago007 2008-11-13 19:56 3401
    highPriority = false;	//if true the game will take most resources, but increase framerate.
89c4a3a6 sago007 2008-08-29 14:32 3402
    bFullscreen = false;
2e57d791 sago007 2009-06-04 17:48 3403
    //Set default Config variables:
2e57d791 sago007 2009-06-04 17:48 3404
    Config::getInstance()->setDefault("themename","default");
89c4a3a6 sago007 2008-08-29 14:32 3405
    if (argc > 1)
89c4a3a6 sago007 2008-08-29 14:32 3406
    {
89c4a3a6 sago007 2008-08-29 14:32 3407
        int argumentNr = 1;
89c4a3a6 sago007 2008-08-29 14:32 3408
        forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3409
        while (argc>argumentNr)
89c4a3a6 sago007 2008-08-29 14:32 3410
        {
89c4a3a6 sago007 2008-08-29 14:32 3411
            char helpString[] = "--help";
89c4a3a6 sago007 2008-08-29 14:32 3412
            char priorityString[] = "-priority";
89c4a3a6 sago007 2008-08-29 14:32 3413
            char forceRedrawString[] = "-forceredraw";
89c4a3a6 sago007 2008-08-29 14:32 3414
            char forcepartdrawString[] = "-forcepartdraw";
89c4a3a6 sago007 2008-08-29 14:32 3415
            char singlePuzzleString[] = "-SP";
89c4a3a6 sago007 2008-08-29 14:32 3416
            char noSoundAtAll[] = "-nosound";
89c4a3a6 sago007 2008-08-29 14:32 3417
            char IntegratedEditor[] = "-editor";
2e57d791 sago007 2009-06-04 17:48 3418
            char selectTheme[] = "-theme";
89c4a3a6 sago007 2008-08-29 14:32 3419
            if (!(strncmp(argv[argumentNr],helpString,6)))
89c4a3a6 sago007 2008-08-29 14:32 3420
            {
89c4a3a6 sago007 2008-08-29 14:32 3421
                cout << "Block Attack Help" << endl << "--help Display this message" <<
89c4a3a6 sago007 2008-08-29 14:32 3422
                endl << "-priority  Starts game in high priority" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3423
                "-forceredraw  Redraw the whole screen every frame, prevents garbage" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3424
                "-forcepartdraw  Only draw what is changed, sometimes cause garbage" << endl <<
2e57d791 sago007 2009-06-04 17:48 3425
                "-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 3426
                "-theme <THEMENAME>  Changes to the theme <THEMENAME> on startup" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3427
                "-editor  Starts the build-in editor (not yet integrated)" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3428
#ifdef WIN32
89c4a3a6 sago007 2008-08-29 14:32 3429
                system("Pause");
89c4a3a6 sago007 2008-08-29 14:32 3430
#endif
89c4a3a6 sago007 2008-08-29 14:32 3431
                return 0;
89c4a3a6 sago007 2008-08-29 14:32 3432
            }
89c4a3a6 sago007 2008-08-29 14:32 3433
            if (!(strncmp(argv[argumentNr],priorityString,9)))
89c4a3a6 sago007 2008-08-29 14:32 3434
            {
89c4a3a6 sago007 2008-08-29 14:32 3435
                cout << "Priority mode" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3436
                highPriority = true;
89c4a3a6 sago007 2008-08-29 14:32 3437
            }
89c4a3a6 sago007 2008-08-29 14:32 3438
            if (!(strncmp(argv[argumentNr],forceRedrawString,12)))
89c4a3a6 sago007 2008-08-29 14:32 3439
            {
89c4a3a6 sago007 2008-08-29 14:32 3440
                forceredraw = 1;
89c4a3a6 sago007 2008-08-29 14:32 3441
            }
89c4a3a6 sago007 2008-08-29 14:32 3442
            if (!(strncmp(argv[argumentNr],forcepartdrawString,14)))
89c4a3a6 sago007 2008-08-29 14:32 3443
            {
89c4a3a6 sago007 2008-08-29 14:32 3444
                forceredraw = 2;
89c4a3a6 sago007 2008-08-29 14:32 3445
            }
89c4a3a6 sago007 2008-08-29 14:32 3446
            if (!(strncmp(argv[argumentNr],singlePuzzleString,3)))
89c4a3a6 sago007 2008-08-29 14:32 3447
            {
89c4a3a6 sago007 2008-08-29 14:32 3448
                singlePuzzle = true; //We will just have one puzzle
89c4a3a6 sago007 2008-08-29 14:32 3449
                if (argv[argumentNr+1][1]!=0)
89c4a3a6 sago007 2008-08-29 14:32 3450
                    singlePuzzleNr = (argv[argumentNr+1][1]-'0')+(argv[argumentNr+1][0]-'0')*10;
89c4a3a6 sago007 2008-08-29 14:32 3451
                else
89c4a3a6 sago007 2008-08-29 14:32 3452
                    singlePuzzleNr = (argv[argumentNr+1][0]-'0');
89c4a3a6 sago007 2008-08-29 14:32 3453
                singlePuzzleFile = argv[argumentNr+2];
89c4a3a6 sago007 2008-08-29 14:32 3454
                argumentNr+=2;
89c4a3a6 sago007 2008-08-29 14:32 3455
                cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl;
89c4a3a6 sago007 2008-08-29 14:32 3456
            }
89c4a3a6 sago007 2008-08-29 14:32 3457
            if (!(strncmp(argv[argumentNr],noSoundAtAll,8)))
89c4a3a6 sago007 2008-08-29 14:32 3458
            {
89c4a3a6 sago007 2008-08-29 14:32 3459
                NoSound = true;
89c4a3a6 sago007 2008-08-29 14:32 3460
            }
89c4a3a6 sago007 2008-08-29 14:32 3461
            if (!(strncmp(argv[argumentNr],IntegratedEditor,7)))
89c4a3a6 sago007 2008-08-29 14:32 3462
            {
1572de2b sago007 2008-09-11 18:15 3463
                #if LEVELEDITOR
89c4a3a6 sago007 2008-08-29 14:32 3464
                editorMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3465
                cout << "Integrated Puzzle Editor Activated" << endl;
1572de2b sago007 2008-09-11 18:15 3466
                #else
1572de2b sago007 2008-09-11 18:15 3467
                cout << "Integrated Puzzle Editor was disabled at compile time" << endl;
2e57d791 sago007 2009-06-04 17:48 3468
                return -1;
1572de2b sago007 2008-09-11 18:15 3469
                #endif
89c4a3a6 sago007 2008-08-29 14:32 3470
            }
2e57d791 sago007 2009-06-04 17:48 3471
            if(!(strncmp(argv[argumentNr],selectTheme,6)))
2e57d791 sago007 2009-06-04 17:48 3472
            {
2e57d791 sago007 2009-06-04 17:48 3473
                argumentNr++; //Go to themename (the next argument)
2e57d791 sago007 2009-06-04 17:48 3474
                cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
2e57d791 sago007 2009-06-04 17:48 3475
                Config::getInstance()->setString("themename",argv[argumentNr]);
2e57d791 sago007 2009-06-04 17:48 3476
            }
89c4a3a6 sago007 2008-08-29 14:32 3477
            argumentNr++;
89c4a3a6 sago007 2008-08-29 14:32 3478
        }   //while
89c4a3a6 sago007 2008-08-29 14:32 3479
    }   //if
89c4a3a6 sago007 2008-08-29 14:32 3480
89c4a3a6 sago007 2008-08-29 14:32 3481
    SoundEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3482
    MusicEnabled = true;
89c4a3a6 sago007 2008-08-29 14:32 3483
    int mousex, mousey;   //Mouse coordinates
89c4a3a6 sago007 2008-08-29 14:32 3484
    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3485
    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3486
    b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3487
    bReplayOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 3488
    bScreenLocked = false;
f72abf8b sago007 2010-01-16 20:00 3489
    twoPlayers = false;	//true if two players splitscreen
89c4a3a6 sago007 2008-08-29 14:32 3490
    bool vsMode = false;
89c4a3a6 sago007 2008-08-29 14:32 3491
    theTopScoresEndless = Highscore(1);
89c4a3a6 sago007 2008-08-29 14:32 3492
    theTopScoresTimeTrial = Highscore(2);
89c4a3a6 sago007 2008-08-29 14:32 3493
    drawBalls = true;
89c4a3a6 sago007 2008-08-29 14:32 3494
    puzzleLoaded = false;
89c4a3a6 sago007 2008-08-29 14:32 3495
    bool weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3496
89c4a3a6 sago007 2008-08-29 14:32 3497
    //Things used for repeating keystrokes:
30f910dd sago007 2010-11-10 21:02 3498
    bool repeatingS[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3499
    bool repeatingW[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3500
    bool repeatingN[2] = {false,false};
30f910dd sago007 2010-11-10 21:02 3501
    bool repeatingE[2] = {false,false};
89c4a3a6 sago007 2008-08-29 14:32 3502
    const int startRepeat = 200;
89c4a3a6 sago007 2008-08-29 14:32 3503
    const int repeatDelay = 100;    //Repeating
89c4a3a6 sago007 2008-08-29 14:32 3504
    unsigned long timeHeldP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3505
    unsigned long timeHeldP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3506
    unsigned long timeHeldP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3507
    unsigned long timeHeldP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3508
    unsigned long timeHeldP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3509
    unsigned long timeHeldP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3510
    unsigned long timeHeldP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3511
    unsigned long timeHeldP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3512
    unsigned long timesRepeatedP1N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3513
    unsigned long timesRepeatedP1S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3514
    unsigned long timesRepeatedP1E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3515
    unsigned long timesRepeatedP1W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3516
    unsigned long timesRepeatedP2N = 0;
89c4a3a6 sago007 2008-08-29 14:32 3517
    unsigned long timesRepeatedP2S = 0;
89c4a3a6 sago007 2008-08-29 14:32 3518
    unsigned long timesRepeatedP2E = 0;
89c4a3a6 sago007 2008-08-29 14:32 3519
    unsigned long timesRepeatedP2W = 0;
89c4a3a6 sago007 2008-08-29 14:32 3520
89c4a3a6 sago007 2008-08-29 14:32 3521
    theBallManeger = ballManeger();
89c4a3a6 sago007 2008-08-29 14:32 3522
    theExplosionManeger = explosionManeger();
89c4a3a6 sago007 2008-08-29 14:32 3523
89c4a3a6 sago007 2008-08-29 14:32 3524
//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 3525
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3526
    string home = getenv("HOME");
89c4a3a6 sago007 2008-08-29 14:32 3527
    string optionsPath = home+"/.gamesaves/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3528
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3529
    string home = getMyDocumentsPath();
89c4a3a6 sago007 2008-08-29 14:32 3530
    string optionsPath;
89c4a3a6 sago007 2008-08-29 14:32 3531
    if (&home!=NULL) //Null if no APPDATA dir exists (win 9x)
89c4a3a6 sago007 2008-08-29 14:32 3532
        optionsPath = home+"/My Games/blockattack/options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3533
    else
89c4a3a6 sago007 2008-08-29 14:32 3534
        optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3535
#else
89c4a3a6 sago007 2008-08-29 14:32 3536
    string optionsPath = "options.dat";
89c4a3a6 sago007 2008-08-29 14:32 3537
#endif
89c4a3a6 sago007 2008-08-29 14:32 3538
89c4a3a6 sago007 2008-08-29 14:32 3539
#if defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3540
    stageClearSavePath = home+"/.gamesaves/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3541
    puzzleSavePath = home+"/.gamesaves/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3542
#elif defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3543
    if (&home!=NULL)
89c4a3a6 sago007 2008-08-29 14:32 3544
    {
89c4a3a6 sago007 2008-08-29 14:32 3545
        stageClearSavePath = home+"/My Games/blockattack/stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3546
        puzzleSavePath = home+"/My Games/blockattack/puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3547
    }
89c4a3a6 sago007 2008-08-29 14:32 3548
    else
89c4a3a6 sago007 2008-08-29 14:32 3549
    {
89c4a3a6 sago007 2008-08-29 14:32 3550
        stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3551
        puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3552
    }
89c4a3a6 sago007 2008-08-29 14:32 3553
#else
89c4a3a6 sago007 2008-08-29 14:32 3554
    stageClearSavePath = "stageClear.SCsave";
89c4a3a6 sago007 2008-08-29 14:32 3555
    puzzleSavePath = "puzzle.levels.save";
89c4a3a6 sago007 2008-08-29 14:32 3556
#endif
89c4a3a6 sago007 2008-08-29 14:32 3557
    puzzleName="puzzle.levels";
89c4a3a6 sago007 2008-08-29 14:32 3558
89c4a3a6 sago007 2008-08-29 14:32 3559
    Uint8 *keys;
89c4a3a6 sago007 2008-08-29 14:32 3560
866417ca sago007 2009-05-10 21:35 3561
95bc02ff sago007 2009-03-15 02:46 3562
89c4a3a6 sago007 2008-08-29 14:32 3563
    //Init SDL
89c4a3a6 sago007 2008-08-29 14:32 3564
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
89c4a3a6 sago007 2008-08-29 14:32 3565
    {
89c4a3a6 sago007 2008-08-29 14:32 3566
        cout << "Unable to init SDL: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3567
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3568
    }
89c4a3a6 sago007 2008-08-29 14:32 3569
    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 3570
    
89c4a3a6 sago007 2008-08-29 14:32 3571
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
89c4a3a6 sago007 2008-08-29 14:32 3572
89c4a3a6 sago007 2008-08-29 14:32 3573
    Joypad_init();    //Prepare the joysticks
89c4a3a6 sago007 2008-08-29 14:32 3574
89c4a3a6 sago007 2008-08-29 14:32 3575
    Joypad joypad1 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3576
    Joypad joypad2 = Joypad();    //Creates a joypad
89c4a3a6 sago007 2008-08-29 14:32 3577
89c4a3a6 sago007 2008-08-29 14:32 3578
    theTextManeger = textManeger();
89c4a3a6 sago007 2008-08-29 14:32 3579
89c4a3a6 sago007 2008-08-29 14:32 3580
    //Open Audio
89c4a3a6 sago007 2008-08-29 14:32 3581
    if (!NoSound) //If sound has not been disabled, then load the sound system
89c4a3a6 sago007 2008-08-29 14:32 3582
        if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
89c4a3a6 sago007 2008-08-29 14:32 3583
        {
89c4a3a6 sago007 2008-08-29 14:32 3584
            cout << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
89c4a3a6 sago007 2008-08-29 14:32 3585
            << "Sound will be disabled!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3586
            NoSound = true; //Tries to stop all sound from playing/loading
89c4a3a6 sago007 2008-08-29 14:32 3587
        }
89c4a3a6 sago007 2008-08-29 14:32 3588
89c4a3a6 sago007 2008-08-29 14:32 3589
    SDL_WM_SetCaption("Block Attack - Rise of the Blocks", NULL); //Sets title line
866417ca sago007 2009-05-10 21:35 3590
    
89c4a3a6 sago007 2008-08-29 14:32 3591
89c4a3a6 sago007 2008-08-29 14:32 3592
    //Copyright notice:
4f1d27f1 sago007 2011-03-18 15:53 3593
    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 3594
    "A SDL based game (see www.libsdl.org)" << endl <<
89c4a3a6 sago007 2008-08-29 14:32 3595
    "The game is availeble under the GPL, see COPYING for details." << endl;
89c4a3a6 sago007 2008-08-29 14:32 3596
#if defined(_WIN32)
89c4a3a6 sago007 2008-08-29 14:32 3597
    cout << "Windows build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3598
#elif defined(__linux__)
89c4a3a6 sago007 2008-08-29 14:32 3599
    cout << "Linux build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3600
#elif defined(__unix__)
89c4a3a6 sago007 2008-08-29 14:32 3601
    cout << "Unix build" <<  endl;
89c4a3a6 sago007 2008-08-29 14:32 3602
#else
89c4a3a6 sago007 2008-08-29 14:32 3603
    cout << "Alternative build" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3604
#endif
89c4a3a6 sago007 2008-08-29 14:32 3605
    cout << "-------------------------------------------" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3606
95bc02ff sago007 2009-03-15 02:46 3607
    //The menu cannot be activated the first second to prevent unexpected events
95bc02ff sago007 2009-03-15 02:46 3608
    keymenu.canBeActivatedTime = SDL_GetTicks()+1000;
95bc02ff sago007 2009-03-15 02:46 3609
    keymenu.activated = false;
95bc02ff sago007 2009-03-15 02:46 3610
    for(int i=0;i<KEYMENU_MAXWITH;i++)
95bc02ff sago007 2009-03-15 02:46 3611
        keymenu.menumap[i][0] = true;
95bc02ff sago007 2009-03-15 02:46 3612
89c4a3a6 sago007 2008-08-29 14:32 3613
    keySettings[0].up= SDLK_UP;
89c4a3a6 sago007 2008-08-29 14:32 3614
    keySettings[0].down = SDLK_DOWN;
89c4a3a6 sago007 2008-08-29 14:32 3615
    keySettings[0].left = SDLK_LEFT;
89c4a3a6 sago007 2008-08-29 14:32 3616
    keySettings[0].right = SDLK_RIGHT;
6d48320c sago007 2009-03-28 17:06 3617
    keySettings[0].change = SDLK_RCTRL;
6d48320c sago007 2009-03-28 17:06 3618
    keySettings[0].push = SDLK_RSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3619
89c4a3a6 sago007 2008-08-29 14:32 3620
    keySettings[2].up= SDLK_w;
89c4a3a6 sago007 2008-08-29 14:32 3621
    keySettings[2].down = SDLK_s;
89c4a3a6 sago007 2008-08-29 14:32 3622
    keySettings[2].left = SDLK_a;
89c4a3a6 sago007 2008-08-29 14:32 3623
    keySettings[2].right = SDLK_d;
89c4a3a6 sago007 2008-08-29 14:32 3624
    keySettings[2].change = SDLK_LCTRL;
89c4a3a6 sago007 2008-08-29 14:32 3625
    keySettings[2].push = SDLK_LSHIFT;
89c4a3a6 sago007 2008-08-29 14:32 3626
89c4a3a6 sago007 2008-08-29 14:32 3627
    player1keys=0;
89c4a3a6 sago007 2008-08-29 14:32 3628
    player2keys=2;
89c4a3a6 sago007 2008-08-29 14:32 3629
89c4a3a6 sago007 2008-08-29 14:32 3630
    strcpy(player1name, "Player 1                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3631
    strcpy(player2name, "Player 2                    \0");
89c4a3a6 sago007 2008-08-29 14:32 3632
769a41a0 sago007 2008-09-24 12:54 3633
    Config *configSettings = Config::getInstance();
769a41a0 sago007 2008-09-24 12:54 3634
    //configSettings->setString("aNumber"," A string");
769a41a0 sago007 2008-09-24 12:54 3635
    //configSettings->save();
769a41a0 sago007 2008-09-24 12:54 3636
    if(configSettings->exists("fullscreen")) //Test if an configFile exists
89c4a3a6 sago007 2008-08-29 14:32 3637
    {
769a41a0 sago007 2008-09-24 12:54 3638
        bFullscreen = (bool)configSettings->getInt("fullscreen");
769a41a0 sago007 2008-09-24 12:54 3639
        MusicEnabled = (bool)configSettings->getInt("musicenabled");
769a41a0 sago007 2008-09-24 12:54 3640
        SoundEnabled = (bool)configSettings->getInt("soundenabled");
769a41a0 sago007 2008-09-24 12:54 3641
        mouseplay1 = (bool)configSettings->getInt("mouseplay1");
769a41a0 sago007 2008-09-24 12:54 3642
        mouseplay2 = (bool)configSettings->getInt("mouseplay2");
769a41a0 sago007 2008-09-24 12:54 3643
        joyplay1 = (bool)configSettings->getInt("joypad1");
769a41a0 sago007 2008-09-24 12:54 3644
        joyplay2 = (bool)configSettings->getInt("joypad2");
769a41a0 sago007 2008-09-24 12:54 3645
        
769a41a0 sago007 2008-09-24 12:54 3646
        if(configSettings->exists("player1keyup")) keySettings[0].up = (SDLKey)configSettings->getInt("player1keyup");
769a41a0 sago007 2008-09-24 12:54 3647
        if(configSettings->exists("player1keydown")) keySettings[0].down = (SDLKey)configSettings->getInt("player1keydown");
769a41a0 sago007 2008-09-24 12:54 3648
        if(configSettings->exists("player1keyleft")) keySettings[0].left = (SDLKey)configSettings->getInt("player1keyleft");
769a41a0 sago007 2008-09-24 12:54 3649
        if(configSettings->exists("player1keyright")) keySettings[0].right = (SDLKey)configSettings->getInt("player1keyright");
769a41a0 sago007 2008-09-24 12:54 3650
        if(configSettings->exists("player1keychange")) keySettings[0].change = (SDLKey)configSettings->getInt("player1keychange");
769a41a0 sago007 2008-09-24 12:54 3651
        if(configSettings->exists("player1keypush")) keySettings[0].push = (SDLKey)configSettings->getInt("player1keypush");
769a41a0 sago007 2008-09-24 12:54 3652
        
769a41a0 sago007 2008-09-24 12:54 3653
        if(configSettings->exists("player2keyup")) keySettings[2].up = (SDLKey)configSettings->getInt("player2keyup");
769a41a0 sago007 2008-09-24 12:54 3654
        if(configSettings->exists("player2keydown")) keySettings[2].down = (SDLKey)configSettings->getInt("player2keydown");
769a41a0 sago007 2008-09-24 12:54 3655
        if(configSettings->exists("player2keyleft")) keySettings[2].left = (SDLKey)configSettings->getInt("player2keyleft");
769a41a0 sago007 2008-09-24 12:54 3656
        if(configSettings->exists("player2keyright")) keySettings[2].right = (SDLKey)configSettings->getInt("player2keyright");
769a41a0 sago007 2008-09-24 12:54 3657
        if(configSettings->exists("player2keychange")) keySettings[2].change = (SDLKey)configSettings->getInt("player2keychange");
769a41a0 sago007 2008-09-24 12:54 3658
        if(configSettings->exists("player2keypush")) keySettings[2].push = (SDLKey)configSettings->getInt("player2keypush");
769a41a0 sago007 2008-09-24 12:54 3659
        if(configSettings->exists("player1name"))
769a41a0 sago007 2008-09-24 12:54 3660
            strncpy(player1name,(configSettings->getString("player1name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3661
        if(configSettings->exists("player2name"))
769a41a0 sago007 2008-09-24 12:54 3662
            strncpy(player2name,(configSettings->getString("player2name")).c_str(),28);
769a41a0 sago007 2008-09-24 12:54 3663
        cout << "Data loaded from config file" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3664
    }
89c4a3a6 sago007 2008-08-29 14:32 3665
    else
89c4a3a6 sago007 2008-08-29 14:32 3666
    {
769a41a0 sago007 2008-09-24 12:54 3667
        //Reads options from file:
769a41a0 sago007 2008-09-24 12:54 3668
        ifstream optionsFile(optionsPath.c_str(), ios::binary);
769a41a0 sago007 2008-09-24 12:54 3669
        if (optionsFile)
769a41a0 sago007 2008-09-24 12:54 3670
        {
769a41a0 sago007 2008-09-24 12:54 3671
            //reads data: xsize,ysize,fullescreen, player1keys, player2keys, MusicEnabled, SoundEnabled,player1name,player2name
769a41a0 sago007 2008-09-24 12:54 3672
            optionsFile.read(reinterpret_cast<char*>(&xsize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3673
            optionsFile.read(reinterpret_cast<char*>(&ysize), sizeof(int));
769a41a0 sago007 2008-09-24 12:54 3674
            optionsFile.read(reinterpret_cast<char*>(&bFullscreen), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3675
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3676
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3677
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3678
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3679
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3680
            optionsFile.read(reinterpret_cast<char*>(&keySettings[0].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3681
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].up), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3682
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].down), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3683
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].left), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3684
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].right), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3685
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].change), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3686
            optionsFile.read(reinterpret_cast<char*>(&keySettings[2].push), sizeof(SDLKey));
769a41a0 sago007 2008-09-24 12:54 3687
            optionsFile.read(reinterpret_cast<char*>(&MusicEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3688
            optionsFile.read(reinterpret_cast<char*>(&SoundEnabled), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3689
            optionsFile.read(player1name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3690
            optionsFile.read(player2name, 30*sizeof(char));
769a41a0 sago007 2008-09-24 12:54 3691
            //mouseplay?
769a41a0 sago007 2008-09-24 12:54 3692
            if (!optionsFile.eof())
769a41a0 sago007 2008-09-24 12:54 3693
            {
769a41a0 sago007 2008-09-24 12:54 3694
                optionsFile.read(reinterpret_cast<char*>(&mouseplay1), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3695
                optionsFile.read(reinterpret_cast<char*>(&mouseplay2), sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3696
                optionsFile.read(reinterpret_cast<char*>(&joyplay1),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3697
                optionsFile.read(reinterpret_cast<char*>(&joyplay2),sizeof(bool));
769a41a0 sago007 2008-09-24 12:54 3698
            }
769a41a0 sago007 2008-09-24 12:54 3699
            optionsFile.close();
769a41a0 sago007 2008-09-24 12:54 3700
            cout << "Data loaded from oldstyle options file" << endl;
769a41a0 sago007 2008-09-24 12:54 3701
        }
769a41a0 sago007 2008-09-24 12:54 3702
        else
769a41a0 sago007 2008-09-24 12:54 3703
        {
769a41a0 sago007 2008-09-24 12:54 3704
            cout << "Unable to load options file, using default values" << endl;
769a41a0 sago007 2008-09-24 12:54 3705
        }
89c4a3a6 sago007 2008-08-29 14:32 3706
    }
27ae0175 sago007 2009-01-30 06:02 3707
    
27ae0175 sago007 2009-01-30 06:02 3708
#if NETWORK
27ae0175 sago007 2009-01-30 06:02 3709
    strcpy(serverAddress, "192.168.0.2                 \0");
27ae0175 sago007 2009-01-30 06:02 3710
    if(configSettings->exists("address0"))
27ae0175 sago007 2009-01-30 06:02 3711
    {
27ae0175 sago007 2009-01-30 06:02 3712
        strcpy(serverAddress, "                            \0");
27ae0175 sago007 2009-01-30 06:02 3713
        strncpy(serverAddress,configSettings->getString("address0").c_str(),sizeof(serverAddress)-1);
27ae0175 sago007 2009-01-30 06:02 3714
    }
27ae0175 sago007 2009-01-30 06:02 3715
#endif
89c4a3a6 sago007 2008-08-29 14:32 3716
89c4a3a6 sago007 2008-08-29 14:32 3717
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3718
    {
89c4a3a6 sago007 2008-08-29 14:32 3719
        xsize=300;
89c4a3a6 sago007 2008-08-29 14:32 3720
        ysize=600;
89c4a3a6 sago007 2008-08-29 14:32 3721
    }
89c4a3a6 sago007 2008-08-29 14:32 3722
    
89c4a3a6 sago007 2008-08-29 14:32 3723
    
89c4a3a6 sago007 2008-08-29 14:32 3724
    //Open video
89c4a3a6 sago007 2008-08-29 14:32 3725
    if ((bFullscreen)&&(!singlePuzzle)) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3726
    else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 3727
89c4a3a6 sago007 2008-08-29 14:32 3728
    if ( screen == NULL )
89c4a3a6 sago007 2008-08-29 14:32 3729
    {
89c4a3a6 sago007 2008-08-29 14:32 3730
        cout << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl;
89c4a3a6 sago007 2008-08-29 14:32 3731
        exit(1);
89c4a3a6 sago007 2008-08-29 14:32 3732
    }
89c4a3a6 sago007 2008-08-29 14:32 3733
866417ca sago007 2009-05-10 21:35 3734
    //Init the file system abstraction layer
866417ca sago007 2009-05-10 21:35 3735
    PHYSFS_init(argv[0]);
866417ca sago007 2009-05-10 21:35 3736
    //Load default theme
2e57d791 sago007 2009-06-04 17:48 3737
    loadTheme(Config::getInstance()->getString("themename"));
866417ca sago007 2009-05-10 21:35 3738
    //Now sets the icon:
1f61db96 sago007 2010-11-15 20:12 3739
    SDL_Surface *icon = IMG_Load2("gfx/icon.png");
866417ca sago007 2009-05-10 21:35 3740
    SDL_WM_SetIcon(icon,NULL);
89c4a3a6 sago007 2008-08-29 14:32 3741
89c4a3a6 sago007 2008-08-29 14:32 3742
    cout << "Images loaded" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3743
78d03b38 sago007 2008-11-13 19:56 3744
    //InitMenues();
89c4a3a6 sago007 2008-08-29 14:32 3745
6b1dc7a6 sago007 2010-11-08 21:03 3746
    BlockGameSdl theGame = BlockGameSdl(50,100);			//creates game objects
6b1dc7a6 sago007 2010-11-08 21:03 3747
    BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
30f910dd sago007 2010-11-10 21:02 3748
    player1 = &theGame;
30f910dd sago007 2010-11-10 21:02 3749
    player2 = &theGame2;
e1290bdf sago007 2010-10-25 19:56 3750
    /*if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3751
    {
e1290bdf sago007 2010-10-25 19:56 3752
        theGame.GetTopY()=0;
e1290bdf sago007 2010-10-25 19:56 3753
        theGame.GetTopX()=0;
e1290bdf sago007 2010-10-25 19:56 3754
        theGame2.GetTopY()=10000;
e1290bdf sago007 2010-10-25 19:56 3755
        theGame2.GetTopX()=10000;
e1290bdf sago007 2010-10-25 19:56 3756
    }*/
89c4a3a6 sago007 2008-08-29 14:32 3757
    theGame.DoPaintJob();			//Makes sure what there is something to paint
89c4a3a6 sago007 2008-08-29 14:32 3758
    theGame2.DoPaintJob();
89c4a3a6 sago007 2008-08-29 14:32 3759
    theGame.SetGameOver();		//sets the game over in the beginning
89c4a3a6 sago007 2008-08-29 14:32 3760
    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 3761
89c4a3a6 sago007 2008-08-29 14:32 3762
89c4a3a6 sago007 2008-08-29 14:32 3763
    //Takes names from file instead
89c4a3a6 sago007 2008-08-29 14:32 3764
    strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 3765
    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 3766
89c4a3a6 sago007 2008-08-29 14:32 3767
    //Keeps track of background;
89c4a3a6 sago007 2008-08-29 14:32 3768
    int nowTime=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3769
89c4a3a6 sago007 2008-08-29 14:32 3770
1572de2b sago007 2008-09-11 18:15 3771
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3772
    NetworkThing nt = NetworkThing();
89c4a3a6 sago007 2008-08-29 14:32 3773
    nt.setBGpointers(&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3774
#endif
89c4a3a6 sago007 2008-08-29 14:32 3775
89c4a3a6 sago007 2008-08-29 14:32 3776
    if (singlePuzzle)
89c4a3a6 sago007 2008-08-29 14:32 3777
    {
89c4a3a6 sago007 2008-08-29 14:32 3778
        LoadPuzzleStages();
e1290bdf sago007 2010-10-25 19:56 3779
        theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3780
        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 3781
        vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 3782
    }
89c4a3a6 sago007 2008-08-29 14:32 3783
    //Draws everything to screen
89c4a3a6 sago007 2008-08-29 14:32 3784
    if (!editorMode)
e1290bdf sago007 2010-10-25 19:56 3785
        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3786
    else
e1290bdf sago007 2010-10-25 19:56 3787
        MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 3788
    DrawIMG(background, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 3789
    DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3790
    SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 3791
    //game loop
89c4a3a6 sago007 2008-08-29 14:32 3792
    int done = 0;
89c4a3a6 sago007 2008-08-29 14:32 3793
    cout << "Starting game loop" << endl;
89c4a3a6 sago007 2008-08-29 14:32 3794
    while (done == 0)
89c4a3a6 sago007 2008-08-29 14:32 3795
    {
89c4a3a6 sago007 2008-08-29 14:32 3796
        if (!(highPriority)) SDL_Delay(10);
89c4a3a6 sago007 2008-08-29 14:32 3797
89c4a3a6 sago007 2008-08-29 14:32 3798
        if ((standardBackground)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3799
        {
e1290bdf sago007 2010-10-25 19:56 3800
            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3801
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3802
        }
89c4a3a6 sago007 2008-08-29 14:32 3803
89c4a3a6 sago007 2008-08-29 14:32 3804
        if ((standardBackground)&&(editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3805
        {
89c4a3a6 sago007 2008-08-29 14:32 3806
            DrawIMG(backgroundImage, screen, 0, 0);
e1290bdf sago007 2010-10-25 19:56 3807
            MakeBackground(xsize,ysize,&theGame);
89c4a3a6 sago007 2008-08-29 14:32 3808
            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3809
        }
89c4a3a6 sago007 2008-08-29 14:32 3810
89c4a3a6 sago007 2008-08-29 14:32 3811
        //updates the balls and explosions:
89c4a3a6 sago007 2008-08-29 14:32 3812
        theBallManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3813
        theExplosionManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3814
        theTextManeger.update();
89c4a3a6 sago007 2008-08-29 14:32 3815
1572de2b sago007 2008-09-11 18:15 3816
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 3817
        if (nt.isConnected())
89c4a3a6 sago007 2008-08-29 14:32 3818
        {
89c4a3a6 sago007 2008-08-29 14:32 3819
            nt.updateNetwork();
89c4a3a6 sago007 2008-08-29 14:32 3820
            networkActive = true;
89c4a3a6 sago007 2008-08-29 14:32 3821
            if (!nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 3822
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3823
        }
89c4a3a6 sago007 2008-08-29 14:32 3824
        else
89c4a3a6 sago007 2008-08-29 14:32 3825
            networkActive = false;
89c4a3a6 sago007 2008-08-29 14:32 3826
        if (nt.isConnectedToPeer())
89c4a3a6 sago007 2008-08-29 14:32 3827
        {
89c4a3a6 sago007 2008-08-29 14:32 3828
            networkPlay=true;
89c4a3a6 sago007 2008-08-29 14:32 3829
            if (!weWhereConnected) //We have just connected
89c4a3a6 sago007 2008-08-29 14:32 3830
            {
e1290bdf sago007 2010-10-25 19:56 3831
                theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3832
                theGame.putStartBlocks(nt.theSeed);
e1290bdf sago007 2010-10-25 19:56 3833
                theGame2.playNetwork(xsize-500,100,SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 3834
                nt.theGameHasStarted();
89c4a3a6 sago007 2008-08-29 14:32 3835
                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3836
            }
89c4a3a6 sago007 2008-08-29 14:32 3837
            weWhereConnected = true;
89c4a3a6 sago007 2008-08-29 14:32 3838
        }
89c4a3a6 sago007 2008-08-29 14:32 3839
        else
89c4a3a6 sago007 2008-08-29 14:32 3840
        {
89c4a3a6 sago007 2008-08-29 14:32 3841
            networkPlay=false;
89c4a3a6 sago007 2008-08-29 14:32 3842
            weWhereConnected = false;
89c4a3a6 sago007 2008-08-29 14:32 3843
        }
89c4a3a6 sago007 2008-08-29 14:32 3844
#endif
89c4a3a6 sago007 2008-08-29 14:32 3845
89c4a3a6 sago007 2008-08-29 14:32 3846
        if (!bScreenLocked)
89c4a3a6 sago007 2008-08-29 14:32 3847
        {
89c4a3a6 sago007 2008-08-29 14:32 3848
            SDL_Event event;
89c4a3a6 sago007 2008-08-29 14:32 3849
89c4a3a6 sago007 2008-08-29 14:32 3850
            while ( SDL_PollEvent(&event) )
89c4a3a6 sago007 2008-08-29 14:32 3851
            {
89c4a3a6 sago007 2008-08-29 14:32 3852
                if ( event.type == SDL_QUIT )  {
89c4a3a6 sago007 2008-08-29 14:32 3853
                    done = 1;
89c4a3a6 sago007 2008-08-29 14:32 3854
                }
89c4a3a6 sago007 2008-08-29 14:32 3855
89c4a3a6 sago007 2008-08-29 14:32 3856
                if ( event.type == SDL_KEYDOWN )
89c4a3a6 sago007 2008-08-29 14:32 3857
                {
89c4a3a6 sago007 2008-08-29 14:32 3858
                    if ( event.key.keysym.sym == SDLK_ESCAPE )
89c4a3a6 sago007 2008-08-29 14:32 3859
                    {
89c4a3a6 sago007 2008-08-29 14:32 3860
                            if (showOptions)
89c4a3a6 sago007 2008-08-29 14:32 3861
                            {
89c4a3a6 sago007 2008-08-29 14:32 3862
                                showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 3863
                            }
89c4a3a6 sago007 2008-08-29 14:32 3864
                            else
89c4a3a6 sago007 2008-08-29 14:32 3865
                                done=1;
89c4a3a6 sago007 2008-08-29 14:32 3866
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3867
89c4a3a6 sago007 2008-08-29 14:32 3868
                    }
e1290bdf sago007 2010-10-25 19:56 3869
                    if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled()))
89c4a3a6 sago007 2008-08-29 14:32 3870
                    {
89c4a3a6 sago007 2008-08-29 14:32 3871
                        //player1:
89c4a3a6 sago007 2008-08-29 14:32 3872
                        if ( event.key.keysym.sym == keySettings[player1keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 3873
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 3874
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3875
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3876
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 3877
                        }
89c4a3a6 sago007 2008-08-29 14:32 3878
                        if ( event.key.keysym.sym == keySettings[player1keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 3879
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 3880
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3881
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3882
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 3883
                        }
89c4a3a6 sago007 2008-08-29 14:32 3884
                        if ( (event.key.keysym.sym == keySettings[player1keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3885
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 3886
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3887
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3888
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 3889
                        }
89c4a3a6 sago007 2008-08-29 14:32 3890
                        if ( (event.key.keysym.sym == keySettings[player1keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3891
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 3892
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 3893
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3894
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 3895
                        }
89c4a3a6 sago007 2008-08-29 14:32 3896
                        if ( event.key.keysym.sym == keySettings[player1keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 3897
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 3898
                        }
89c4a3a6 sago007 2008-08-29 14:32 3899
                        if ( event.key.keysym.sym == keySettings[player1keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 3900
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 3901
                        }
89c4a3a6 sago007 2008-08-29 14:32 3902
                    }
e1290bdf sago007 2010-10-25 19:56 3903
                    if (!editorMode && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 3904
                    {
89c4a3a6 sago007 2008-08-29 14:32 3905
                        //player2:
89c4a3a6 sago007 2008-08-29 14:32 3906
                        if ( event.key.keysym.sym == keySettings[player2keys].up ) {
89c4a3a6 sago007 2008-08-29 14:32 3907
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 3908
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3909
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3910
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 3911
                        }
89c4a3a6 sago007 2008-08-29 14:32 3912
                        if ( event.key.keysym.sym == keySettings[player2keys].down ) {
89c4a3a6 sago007 2008-08-29 14:32 3913
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 3914
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3915
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3916
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 3917
                        }
89c4a3a6 sago007 2008-08-29 14:32 3918
                        if ( (event.key.keysym.sym == keySettings[player2keys].left) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3919
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 3920
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3921
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3922
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 3923
                        }
89c4a3a6 sago007 2008-08-29 14:32 3924
                        if ( (event.key.keysym.sym == keySettings[player2keys].right) && (showGame) ) {
89c4a3a6 sago007 2008-08-29 14:32 3925
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 3926
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 3927
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 3928
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 3929
                        }
89c4a3a6 sago007 2008-08-29 14:32 3930
                        if ( event.key.keysym.sym == keySettings[player2keys].push ) {
89c4a3a6 sago007 2008-08-29 14:32 3931
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 3932
                        }
89c4a3a6 sago007 2008-08-29 14:32 3933
                        if ( event.key.keysym.sym == keySettings[player2keys].change ) {
89c4a3a6 sago007 2008-08-29 14:32 3934
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 3935
                        }
89c4a3a6 sago007 2008-08-29 14:32 3936
                    }
89c4a3a6 sago007 2008-08-29 14:32 3937
                    //common:
89c4a3a6 sago007 2008-08-29 14:32 3938
                    if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 3939
                    {
89c4a3a6 sago007 2008-08-29 14:32 3940
                        if ( event.key.keysym.sym == SDLK_F2 ) {
2f30c381 sago007 2008-09-14 13:08 3941
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3942
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 3943
                            #else
47529580 sago007 2008-12-09 02:34 3944
                            if ((!showOptions)){
2f30c381 sago007 2008-09-14 13:08 3945
                            #endif
30f910dd sago007 2010-11-10 21:02 3946
                                StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 3947
                            }}
89c4a3a6 sago007 2008-08-29 14:32 3948
                        if ( event.key.keysym.sym == SDLK_F3 ) {
2f30c381 sago007 2008-09-14 13:08 3949
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3950
                            if ((!showOptions)&&(!networkActive)){
2f30c381 sago007 2008-09-14 13:08 3951
                            #else
47529580 sago007 2008-12-09 02:34 3952
                            if ((!showOptions)){    
2f30c381 sago007 2008-09-14 13:08 3953
                            #endif
4f1d27f1 sago007 2011-03-18 15:53 3954
                                StartSinglePlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 3955
                            }}
89c4a3a6 sago007 2008-08-29 14:32 3956
                        if ( event.key.keysym.sym == SDLK_F5 )
89c4a3a6 sago007 2008-08-29 14:32 3957
                        {
2f30c381 sago007 2008-09-14 13:08 3958
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3959
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 3960
                            #else
47529580 sago007 2008-12-09 02:34 3961
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 3962
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 3963
                            {
89c4a3a6 sago007 2008-08-29 14:32 3964
                                int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 3965
                                theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 3966
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 3967
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 3968
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 3969
                                twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 3970
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 3971
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 3972
                                vsMode = false;
c96f480e sago007 2009-03-28 18:59 3973
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 3974
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 3975
                            }
89c4a3a6 sago007 2008-08-29 14:32 3976
                        }
89c4a3a6 sago007 2008-08-29 14:32 3977
                        if ( event.key.keysym.sym == SDLK_F6 )
89c4a3a6 sago007 2008-08-29 14:32 3978
                        {
2f30c381 sago007 2008-09-14 13:08 3979
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3980
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 3981
                            #else
47529580 sago007 2008-12-09 02:34 3982
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 3983
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 3984
                            {
4f1d27f1 sago007 2011-03-18 15:53 3985
                                StartTwoPlayerVs();
89c4a3a6 sago007 2008-08-29 14:32 3986
                            }
89c4a3a6 sago007 2008-08-29 14:32 3987
                        }
89c4a3a6 sago007 2008-08-29 14:32 3988
                        if ( event.key.keysym.sym == SDLK_F4 )
89c4a3a6 sago007 2008-08-29 14:32 3989
                        {
2f30c381 sago007 2008-09-14 13:08 3990
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 3991
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 3992
                            #else
47529580 sago007 2008-12-09 02:34 3993
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 3994
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 3995
                            {
4f1d27f1 sago007 2011-03-18 15:53 3996
                                StarTwoPlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 3997
                            }
89c4a3a6 sago007 2008-08-29 14:32 3998
                        }
89c4a3a6 sago007 2008-08-29 14:32 3999
                        if ( event.key.keysym.sym == SDLK_F7 )
89c4a3a6 sago007 2008-08-29 14:32 4000
                        {
2f30c381 sago007 2008-09-14 13:08 4001
                            #if NETWORK
47529580 sago007 2008-12-09 02:34 4002
                            if ((!showOptions)&&(!networkActive))
2f30c381 sago007 2008-09-14 13:08 4003
                            #else
47529580 sago007 2008-12-09 02:34 4004
                            if ((!showOptions))    
2f30c381 sago007 2008-09-14 13:08 4005
                            #endif
89c4a3a6 sago007 2008-08-29 14:32 4006
                            {
89c4a3a6 sago007 2008-08-29 14:32 4007
                                int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4008
                                theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4009
                                MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4010
                                DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4011
                                closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4012
                                twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4013
                                theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4014
                                showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4015
                                vsMode = true;
c96f480e sago007 2009-03-28 18:59 4016
                                strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4017
                                strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4018
                            }
89c4a3a6 sago007 2008-08-29 14:32 4019
                        }
89c4a3a6 sago007 2008-08-29 14:32 4020
                        if ( event.key.keysym.sym == SDLK_F8 )
89c4a3a6 sago007 2008-08-29 14:32 4021
                        {
95bc02ff sago007 2009-03-15 02:46 4022
                            if(!keymenu.activated && keymenu.canBeActivatedTime > SDL_GetTicks())
95bc02ff sago007 2009-03-15 02:46 4023
                            {
95bc02ff sago007 2009-03-15 02:46 4024
                                keymenu.activated = true;
95bc02ff sago007 2009-03-15 02:46 4025
                                keymenu.x = 0;
95bc02ff sago007 2009-03-15 02:46 4026
                                keymenu.y = 0;
95bc02ff sago007 2009-03-15 02:46 4027
                            }
89c4a3a6 sago007 2008-08-29 14:32 4028
                        }
89c4a3a6 sago007 2008-08-29 14:32 4029
                        if ( event.key.keysym.sym == SDLK_F9 ) {
89c4a3a6 sago007 2008-08-29 14:32 4030
                            writeScreenShot();
89c4a3a6 sago007 2008-08-29 14:32 4031
                        }
89c4a3a6 sago007 2008-08-29 14:32 4032
                        if ( event.key.keysym.sym == SDLK_F11 ) {
89c4a3a6 sago007 2008-08-29 14:32 4033
                            /*This is the test place, place function to test here*/
89c4a3a6 sago007 2008-08-29 14:32 4034
89c4a3a6 sago007 2008-08-29 14:32 4035
                            //theGame.CreateGreyGarbage();
78d03b38 sago007 2008-11-13 19:56 4036
                            //char mitNavn[30];
78d03b38 sago007 2008-11-13 19:56 4037
                            //SelectThemeDialogbox(300,400,mitNavn);
78d03b38 sago007 2008-11-13 19:56 4038
                           // MainMenu();
47529580 sago007 2008-12-09 02:34 4039
                            OpenScoresDisplay();
89c4a3a6 sago007 2008-08-29 14:32 4040
                        } //F11
89c4a3a6 sago007 2008-08-29 14:32 4041
                    }
89c4a3a6 sago007 2008-08-29 14:32 4042
                    if ( event.key.keysym.sym == SDLK_F12 ) {
89c4a3a6 sago007 2008-08-29 14:32 4043
                        done=1;
89c4a3a6 sago007 2008-08-29 14:32 4044
                    }
89c4a3a6 sago007 2008-08-29 14:32 4045
                }
89c4a3a6 sago007 2008-08-29 14:32 4046
            } //while event PollEvent - read keys
89c4a3a6 sago007 2008-08-29 14:32 4047
89c4a3a6 sago007 2008-08-29 14:32 4048
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4049
            **************************** Repeating start **************************
89c4a3a6 sago007 2008-08-29 14:32 4050
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4051
89c4a3a6 sago007 2008-08-29 14:32 4052
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4053
//Also the joysticks:
89c4a3a6 sago007 2008-08-29 14:32 4054
//Repeating not implemented
89c4a3a6 sago007 2008-08-29 14:32 4055
89c4a3a6 sago007 2008-08-29 14:32 4056
//Player 1 start
89c4a3a6 sago007 2008-08-29 14:32 4057
            if (!(keys[keySettings[player1keys].up]))
30f910dd sago007 2010-11-10 21:02 4058
                repeatingN[0]=false;
30f910dd sago007 2010-11-10 21:02 4059
            while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4060
            {
89c4a3a6 sago007 2008-08-29 14:32 4061
                theGame.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4062
                timesRepeatedP1N++;
89c4a3a6 sago007 2008-08-29 14:32 4063
            }
89c4a3a6 sago007 2008-08-29 14:32 4064
89c4a3a6 sago007 2008-08-29 14:32 4065
            if (!(keys[keySettings[player1keys].down]))
30f910dd sago007 2010-11-10 21:02 4066
                repeatingS[0]=false;
30f910dd sago007 2010-11-10 21:02 4067
            while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4068
            {
89c4a3a6 sago007 2008-08-29 14:32 4069
                theGame.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4070
                timesRepeatedP1S++;
89c4a3a6 sago007 2008-08-29 14:32 4071
            }
89c4a3a6 sago007 2008-08-29 14:32 4072
89c4a3a6 sago007 2008-08-29 14:32 4073
            if (!(keys[keySettings[player1keys].left]))
30f910dd sago007 2010-11-10 21:02 4074
                repeatingW[0]=false;
30f910dd sago007 2010-11-10 21:02 4075
            while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4076
            {
89c4a3a6 sago007 2008-08-29 14:32 4077
                timesRepeatedP1W++;
89c4a3a6 sago007 2008-08-29 14:32 4078
                theGame.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4079
            }
89c4a3a6 sago007 2008-08-29 14:32 4080
89c4a3a6 sago007 2008-08-29 14:32 4081
            if (!(keys[keySettings[player1keys].right]))
30f910dd sago007 2010-11-10 21:02 4082
                repeatingE[0]=false;
30f910dd sago007 2010-11-10 21:02 4083
            while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4084
            {
89c4a3a6 sago007 2008-08-29 14:32 4085
                timesRepeatedP1E++;
89c4a3a6 sago007 2008-08-29 14:32 4086
                theGame.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4087
            }
89c4a3a6 sago007 2008-08-29 14:32 4088
89c4a3a6 sago007 2008-08-29 14:32 4089
//Player 1 end
89c4a3a6 sago007 2008-08-29 14:32 4090
89c4a3a6 sago007 2008-08-29 14:32 4091
//Player 2 start
89c4a3a6 sago007 2008-08-29 14:32 4092
            if (!(keys[keySettings[player2keys].up]))
30f910dd sago007 2010-11-10 21:02 4093
                repeatingN[1]=false;
30f910dd sago007 2010-11-10 21:02 4094
            while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4095
            {
89c4a3a6 sago007 2008-08-29 14:32 4096
                theGame2.MoveCursor('N');
89c4a3a6 sago007 2008-08-29 14:32 4097
                timesRepeatedP2N++;
89c4a3a6 sago007 2008-08-29 14:32 4098
            }
89c4a3a6 sago007 2008-08-29 14:32 4099
89c4a3a6 sago007 2008-08-29 14:32 4100
            if (!(keys[keySettings[player2keys].down]))
30f910dd sago007 2010-11-10 21:02 4101
                repeatingS[1]=false;
30f910dd sago007 2010-11-10 21:02 4102
            while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4103
            {
89c4a3a6 sago007 2008-08-29 14:32 4104
                theGame2.MoveCursor('S');
89c4a3a6 sago007 2008-08-29 14:32 4105
                timesRepeatedP2S++;
89c4a3a6 sago007 2008-08-29 14:32 4106
            }
89c4a3a6 sago007 2008-08-29 14:32 4107
89c4a3a6 sago007 2008-08-29 14:32 4108
            if (!(keys[keySettings[player2keys].left]))
30f910dd sago007 2010-11-10 21:02 4109
                repeatingW[1]=false;
30f910dd sago007 2010-11-10 21:02 4110
            while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4111
            {
89c4a3a6 sago007 2008-08-29 14:32 4112
                theGame2.MoveCursor('W');
89c4a3a6 sago007 2008-08-29 14:32 4113
                timesRepeatedP2W++;
89c4a3a6 sago007 2008-08-29 14:32 4114
            }
89c4a3a6 sago007 2008-08-29 14:32 4115
89c4a3a6 sago007 2008-08-29 14:32 4116
            if (!(keys[keySettings[player2keys].right]))
30f910dd sago007 2010-11-10 21:02 4117
                repeatingE[1]=false;
30f910dd sago007 2010-11-10 21:02 4118
            while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat))
89c4a3a6 sago007 2008-08-29 14:32 4119
            {
89c4a3a6 sago007 2008-08-29 14:32 4120
                theGame2.MoveCursor('E');
89c4a3a6 sago007 2008-08-29 14:32 4121
                timesRepeatedP2E++;
89c4a3a6 sago007 2008-08-29 14:32 4122
            }
89c4a3a6 sago007 2008-08-29 14:32 4123
89c4a3a6 sago007 2008-08-29 14:32 4124
//Player 2 end
89c4a3a6 sago007 2008-08-29 14:32 4125
89c4a3a6 sago007 2008-08-29 14:32 4126
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4127
            **************************** Repeating end ****************************
89c4a3a6 sago007 2008-08-29 14:32 4128
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4129
89c4a3a6 sago007 2008-08-29 14:32 4130
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4131
            ***************************** Joypad start ****************************
89c4a3a6 sago007 2008-08-29 14:32 4132
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4133
6d48320c sago007 2009-03-28 17:06 4134
            //Menu
6d48320c sago007 2009-03-28 17:06 4135
            if(joypad1.working)
6d48320c sago007 2009-03-28 17:06 4136
            {
6d48320c sago007 2009-03-28 17:06 4137
                joypad1.update();
6d48320c sago007 2009-03-28 17:06 4138
                if(joypad1.but1)
6d48320c sago007 2009-03-28 17:06 4139
                {
6d48320c sago007 2009-03-28 17:06 4140
                    if(!keymenu.activated && keymenu.canBeActivatedTime > SDL_GetTicks())
6d48320c sago007 2009-03-28 17:06 4141
                    {
6d48320c sago007 2009-03-28 17:06 4142
                        keymenu.activated = true;
6d48320c sago007 2009-03-28 17:06 4143
                        keymenu.x = 0;
6d48320c sago007 2009-03-28 17:06 4144
                        keymenu.y = 0;
6d48320c sago007 2009-03-28 17:06 4145
                    }
6d48320c sago007 2009-03-28 17:06 4146
                }
6d48320c sago007 2009-03-28 17:06 4147
            }
6d48320c sago007 2009-03-28 17:06 4148
6d48320c sago007 2009-03-28 17:06 4149
            //Gameplay
89c4a3a6 sago007 2008-08-29 14:32 4150
            if (joyplay1||joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4151
            {
e1290bdf sago007 2010-10-25 19:56 4152
                if (joypad1.working && !theGame.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4153
                    if (joyplay1)
89c4a3a6 sago007 2008-08-29 14:32 4154
                    {
89c4a3a6 sago007 2008-08-29 14:32 4155
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4156
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4157
                        {
89c4a3a6 sago007 2008-08-29 14:32 4158
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4159
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4160
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4161
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4162
                        }
89c4a3a6 sago007 2008-08-29 14:32 4163
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4164
                        {
89c4a3a6 sago007 2008-08-29 14:32 4165
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4166
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4167
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4168
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4169
                        }
89c4a3a6 sago007 2008-08-29 14:32 4170
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4171
                        {
89c4a3a6 sago007 2008-08-29 14:32 4172
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4173
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4174
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4175
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4176
                        }
89c4a3a6 sago007 2008-08-29 14:32 4177
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4178
                        {
89c4a3a6 sago007 2008-08-29 14:32 4179
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4180
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4181
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4182
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4183
                        }
89c4a3a6 sago007 2008-08-29 14:32 4184
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4185
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4186
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4187
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4188
                    }
89c4a3a6 sago007 2008-08-29 14:32 4189
                    else
89c4a3a6 sago007 2008-08-29 14:32 4190
                    {
89c4a3a6 sago007 2008-08-29 14:32 4191
                        joypad1.update();
89c4a3a6 sago007 2008-08-29 14:32 4192
                        if (joypad1.up)
89c4a3a6 sago007 2008-08-29 14:32 4193
                        {
89c4a3a6 sago007 2008-08-29 14:32 4194
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4195
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4196
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4197
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4198
                        }
89c4a3a6 sago007 2008-08-29 14:32 4199
                        if (joypad1.down)
89c4a3a6 sago007 2008-08-29 14:32 4200
                        {
89c4a3a6 sago007 2008-08-29 14:32 4201
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4202
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4203
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4204
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4205
                        }
89c4a3a6 sago007 2008-08-29 14:32 4206
                        if (joypad1.left)
89c4a3a6 sago007 2008-08-29 14:32 4207
                        {
89c4a3a6 sago007 2008-08-29 14:32 4208
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4209
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4210
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4211
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4212
                        }
89c4a3a6 sago007 2008-08-29 14:32 4213
                        if (joypad1.right)
89c4a3a6 sago007 2008-08-29 14:32 4214
                        {
89c4a3a6 sago007 2008-08-29 14:32 4215
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4216
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4217
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4218
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4219
                        }
89c4a3a6 sago007 2008-08-29 14:32 4220
                        if (joypad1.but1)
89c4a3a6 sago007 2008-08-29 14:32 4221
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4222
                        if (joypad1.but2)
89c4a3a6 sago007 2008-08-29 14:32 4223
                            theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4224
                    }
e1290bdf sago007 2010-10-25 19:56 4225
                if (joypad2.working && !theGame2.GetAIenabled())
89c4a3a6 sago007 2008-08-29 14:32 4226
                    if (!joyplay2)
89c4a3a6 sago007 2008-08-29 14:32 4227
                    {
89c4a3a6 sago007 2008-08-29 14:32 4228
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4229
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4230
                        {
89c4a3a6 sago007 2008-08-29 14:32 4231
                            theGame.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4232
                            repeatingN[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4233
                            timeHeldP1N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4234
                            timesRepeatedP1N=0;
89c4a3a6 sago007 2008-08-29 14:32 4235
                        }
89c4a3a6 sago007 2008-08-29 14:32 4236
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4237
                        {
89c4a3a6 sago007 2008-08-29 14:32 4238
                            theGame.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4239
                            repeatingS[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4240
                            timeHeldP1S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4241
                            timesRepeatedP1S=0;
89c4a3a6 sago007 2008-08-29 14:32 4242
                        }
89c4a3a6 sago007 2008-08-29 14:32 4243
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4244
                        {
89c4a3a6 sago007 2008-08-29 14:32 4245
                            theGame.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4246
                            repeatingW[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4247
                            timeHeldP1W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4248
                            timesRepeatedP1W=0;
89c4a3a6 sago007 2008-08-29 14:32 4249
                        }
89c4a3a6 sago007 2008-08-29 14:32 4250
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4251
                        {
89c4a3a6 sago007 2008-08-29 14:32 4252
                            theGame.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4253
                            repeatingE[0]=true;
89c4a3a6 sago007 2008-08-29 14:32 4254
                            timeHeldP1E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4255
                            timesRepeatedP1E=0;
89c4a3a6 sago007 2008-08-29 14:32 4256
                        }
89c4a3a6 sago007 2008-08-29 14:32 4257
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4258
                            theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4259
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4260
                            theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4261
                    }
89c4a3a6 sago007 2008-08-29 14:32 4262
                    else
89c4a3a6 sago007 2008-08-29 14:32 4263
                    {
89c4a3a6 sago007 2008-08-29 14:32 4264
                        joypad2.update();
89c4a3a6 sago007 2008-08-29 14:32 4265
                        if (joypad2.up)
89c4a3a6 sago007 2008-08-29 14:32 4266
                        {
89c4a3a6 sago007 2008-08-29 14:32 4267
                            theGame2.MoveCursor('N');
30f910dd sago007 2010-11-10 21:02 4268
                            repeatingN[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4269
                            timeHeldP2N=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4270
                            timesRepeatedP2N=0;
89c4a3a6 sago007 2008-08-29 14:32 4271
                        }
89c4a3a6 sago007 2008-08-29 14:32 4272
                        if (joypad2.down)
89c4a3a6 sago007 2008-08-29 14:32 4273
                        {
89c4a3a6 sago007 2008-08-29 14:32 4274
                            theGame2.MoveCursor('S');
30f910dd sago007 2010-11-10 21:02 4275
                            repeatingS[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4276
                            timeHeldP2S=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4277
                            timesRepeatedP2S=0;
89c4a3a6 sago007 2008-08-29 14:32 4278
                        }
89c4a3a6 sago007 2008-08-29 14:32 4279
                        if (joypad2.left)
89c4a3a6 sago007 2008-08-29 14:32 4280
                        {
89c4a3a6 sago007 2008-08-29 14:32 4281
                            theGame2.MoveCursor('W');
30f910dd sago007 2010-11-10 21:02 4282
                            repeatingW[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4283
                            timeHeldP2W=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4284
                            timesRepeatedP2W=0;
89c4a3a6 sago007 2008-08-29 14:32 4285
                        }
89c4a3a6 sago007 2008-08-29 14:32 4286
                        if (joypad2.right)
89c4a3a6 sago007 2008-08-29 14:32 4287
                        {
89c4a3a6 sago007 2008-08-29 14:32 4288
                            theGame2.MoveCursor('E');
30f910dd sago007 2010-11-10 21:02 4289
                            repeatingE[1]=true;
89c4a3a6 sago007 2008-08-29 14:32 4290
                            timeHeldP2E=SDL_GetTicks();
89c4a3a6 sago007 2008-08-29 14:32 4291
                            timesRepeatedP2E=0;
89c4a3a6 sago007 2008-08-29 14:32 4292
                        }
89c4a3a6 sago007 2008-08-29 14:32 4293
                        if (joypad2.but1)
89c4a3a6 sago007 2008-08-29 14:32 4294
                            theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4295
                        if (joypad2.but2)
89c4a3a6 sago007 2008-08-29 14:32 4296
                            theGame2.PushLine();
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
            /**********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4301
            ***************************** Joypad end ******************************
89c4a3a6 sago007 2008-08-29 14:32 4302
            **********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4303
89c4a3a6 sago007 2008-08-29 14:32 4304
89c4a3a6 sago007 2008-08-29 14:32 4305
            keys = SDL_GetKeyState(NULL);
89c4a3a6 sago007 2008-08-29 14:32 4306
6d48320c sago007 2009-03-28 17:06 4307
            if(keymenu.activated)
6d48320c sago007 2009-03-28 17:06 4308
            {
6d48320c sago007 2009-03-28 17:06 4309
                mousex = keymenu.x*buttonXsize-10;
6d48320c sago007 2009-03-28 17:06 4310
                mousey = keymenu.y*buttonYsize-10;
6d48320c sago007 2009-03-28 17:06 4311
            }
6d48320c sago007 2009-03-28 17:06 4312
            else
6d48320c sago007 2009-03-28 17:06 4313
                SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 4314
89c4a3a6 sago007 2008-08-29 14:32 4315
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4316
            **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4317
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4318
e1290bdf sago007 2010-10-25 19:56 4319
            if ((mouseplay1)&&((!editorMode)&&(!theGame.GetAIenabled())||(editorModeTest))) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4320
                if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4321
                {
89c4a3a6 sago007 2008-08-29 14:32 4322
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4323
                    yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4324
                    xLine = (mousex-50+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4325
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4326
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4327
                    if ((yLine>10)&&(theGame.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4328
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4329
                    if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4330
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4331
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4332
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4333
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4334
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4335
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4336
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4337
                    theGame.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4338
                }
89c4a3a6 sago007 2008-08-29 14:32 4339
e1290bdf sago007 2010-10-25 19:56 4340
            if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4341
                if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4342
                {
89c4a3a6 sago007 2008-08-29 14:32 4343
                    int yLine, xLine;
e1290bdf sago007 2010-10-25 19:56 4344
                    yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50;
89c4a3a6 sago007 2008-08-29 14:32 4345
                    xLine = (mousex-(xsize-500)+25)/50;
89c4a3a6 sago007 2008-08-29 14:32 4346
                    yLine-=2;
89c4a3a6 sago007 2008-08-29 14:32 4347
                    xLine-=1;
e1290bdf sago007 2010-10-25 19:56 4348
                    if ((yLine>10)&&(theGame2.GetTowerHeight()<12))
89c4a3a6 sago007 2008-08-29 14:32 4349
                        yLine=10;
e1290bdf sago007 2010-10-25 19:56 4350
                    if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11))
89c4a3a6 sago007 2008-08-29 14:32 4351
                        yLine=11;
89c4a3a6 sago007 2008-08-29 14:32 4352
                    if (yLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4353
                        yLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4354
                    if (xLine<0)
89c4a3a6 sago007 2008-08-29 14:32 4355
                        xLine=0;
89c4a3a6 sago007 2008-08-29 14:32 4356
                    if (xLine>4)
89c4a3a6 sago007 2008-08-29 14:32 4357
                        xLine=4;
e1290bdf sago007 2010-10-25 19:56 4358
                    theGame2.MoveCursorTo(xLine,yLine);
89c4a3a6 sago007 2008-08-29 14:32 4359
                }
89c4a3a6 sago007 2008-08-29 14:32 4360
89c4a3a6 sago007 2008-08-29 14:32 4361
            /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4362
            **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4363
            ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4364
89c4a3a6 sago007 2008-08-29 14:32 4365
            // If the mouse button is released, make bMouseUp equal true
89c4a3a6 sago007 2008-08-29 14:32 4366
            if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
89c4a3a6 sago007 2008-08-29 14:32 4367
            {
89c4a3a6 sago007 2008-08-29 14:32 4368
                bMouseUp=true;
89c4a3a6 sago007 2008-08-29 14:32 4369
            }
89c4a3a6 sago007 2008-08-29 14:32 4370
89c4a3a6 sago007 2008-08-29 14:32 4371
            // If the mouse button 2 is released, make bMouseUp2 equal true
89c4a3a6 sago007 2008-08-29 14:32 4372
            if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3))
89c4a3a6 sago007 2008-08-29 14:32 4373
            {
89c4a3a6 sago007 2008-08-29 14:32 4374
                bMouseUp2=true;
89c4a3a6 sago007 2008-08-29 14:32 4375
            }
89c4a3a6 sago007 2008-08-29 14:32 4376
89c4a3a6 sago007 2008-08-29 14:32 4377
            if ((!singlePuzzle)&&(!editorMode))
89c4a3a6 sago007 2008-08-29 14:32 4378
            {
89c4a3a6 sago007 2008-08-29 14:32 4379
                //read mouse events
89c4a3a6 sago007 2008-08-29 14:32 4380
                if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
89c4a3a6 sago007 2008-08-29 14:32 4381
                {
89c4a3a6 sago007 2008-08-29 14:32 4382
                    bMouseUp = false;
89c4a3a6 sago007 2008-08-29 14:32 4383
                    DrawIMG(background, screen, 0, 0);
2f30c381 sago007 2008-09-14 13:08 4384
                    #if NETWORK
2f30c381 sago007 2008-09-14 13:08 4385
                    //Nothing
2f30c381 sago007 2008-09-14 13:08 4386
                    #else
2f30c381 sago007 2008-09-14 13:08 4387
                    bool networkActive=false;
2f30c381 sago007 2008-09-14 13:08 4388
                    #endif
9050a50a sago007 2008-12-09 13:35 4389
                    if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4390
                    {
89c4a3a6 sago007 2008-08-29 14:32 4391
                        //New game clicked
89c4a3a6 sago007 2008-08-29 14:32 4392
                        bool state = (!bNewGameOpen);
89c4a3a6 sago007 2008-08-29 14:32 4393
                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4394
                        bNewGameOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4395
                        showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4396
                    }
89c4a3a6 sago007 2008-08-29 14:32 4397
                    else
1572de2b sago007 2008-09-11 18:15 4398
#if NETWORK
9050a50a sago007 2008-12-09 13:35 4399
                        if ((0<mousex) && (mousex<buttonXsize) && (0<mousey) && (mousey<40) &&(networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4400
                        {
89c4a3a6 sago007 2008-08-29 14:32 4401
                            //Disconnect clicked!
89c4a3a6 sago007 2008-08-29 14:32 4402
                            cout << "Disconnect clicked!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4403
                            nt.ntDisconnect();
89c4a3a6 sago007 2008-08-29 14:32 4404
                        }
89c4a3a6 sago007 2008-08-29 14:32 4405
                        else
89c4a3a6 sago007 2008-08-29 14:32 4406
#endif
9050a50a sago007 2008-12-09 13:35 4407
                            if ((0<mousex) && (mousex<buttonXsize) && (40<mousey) && (mousey<80) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4408
                            {
89c4a3a6 sago007 2008-08-29 14:32 4409
                                //1player
89c4a3a6 sago007 2008-08-29 14:32 4410
                                b1playerOpen = (!b1playerOpen);
89c4a3a6 sago007 2008-08-29 14:32 4411
                                b2playersOpen = false;
1572de2b sago007 2008-09-11 18:15 4412
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4413
                                bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4414
#endif
89c4a3a6 sago007 2008-08-29 14:32 4415
                            }
89c4a3a6 sago007 2008-08-29 14:32 4416
                            else
9050a50a sago007 2008-12-09 13:35 4417
                                if ((0<mousex) && (mousex<buttonXsize) && (80<mousey) && (mousey<120) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4418
                                {
89c4a3a6 sago007 2008-08-29 14:32 4419
                                    //2player
89c4a3a6 sago007 2008-08-29 14:32 4420
                                    b2playersOpen = (!b2playersOpen);
89c4a3a6 sago007 2008-08-29 14:32 4421
                                    b1playerOpen = false;
1572de2b sago007 2008-09-11 18:15 4422
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4423
                                    bNetworkOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4424
#endif
89c4a3a6 sago007 2008-08-29 14:32 4425
                                }
1572de2b sago007 2008-09-11 18:15 4426
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4427
                                else
9050a50a sago007 2008-12-09 13:35 4428
                                    if ((0<mousex) && (mousex<buttonXsize) && (120<mousey) && (mousey<160) && (bNewGameOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4429
                                    {
89c4a3a6 sago007 2008-08-29 14:32 4430
                                        //Network
89c4a3a6 sago007 2008-08-29 14:32 4431
                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4432
                                        b2playersOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4433
                                        bNetworkOpen = (!bNetworkOpen);
89c4a3a6 sago007 2008-08-29 14:32 4434
                                    }
89c4a3a6 sago007 2008-08-29 14:32 4435
#endif
89c4a3a6 sago007 2008-08-29 14:32 4436
                                    else
9050a50a sago007 2008-12-09 13:35 4437
                                        if ((buttonXsize<mousex) && (mousex<240) && (40<mousey) && (mousey<80) && (b1playerOpen) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4438
                                        {
30f910dd sago007 2010-11-10 21:02 4439
                                            StartSinglePlayerEndless();
89c4a3a6 sago007 2008-08-29 14:32 4440
                                        }
89c4a3a6 sago007 2008-08-29 14:32 4441
                                        else
9050a50a sago007 2008-12-09 13:35 4442
                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b1playerOpen) &&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4443
                                            {
4f1d27f1 sago007 2011-03-18 15:53 4444
                                                StartSinglePlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4445
                                            }
89c4a3a6 sago007 2008-08-29 14:32 4446
                                            else
9050a50a sago007 2008-12-09 13:35 4447
                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b1playerOpen)&&(!networkActive) )
89c4a3a6 sago007 2008-08-29 14:32 4448
                                                {
89c4a3a6 sago007 2008-08-29 14:32 4449
                                                    //1 player - stage clear
89c4a3a6 sago007 2008-08-29 14:32 4450
                                                    bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4451
                                                    b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4452
                                                    int myLevel = StageLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4453
                                                    theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4454
                                                    MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4455
                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4456
                                                    twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4457
                                                    theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4458
                                                    showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4459
                                                    vsMode = false;
c96f480e sago007 2009-03-28 18:59 4460
                                                    strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4461
                                                    strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4462
                                                }
89c4a3a6 sago007 2008-08-29 14:32 4463
                                                else
9050a50a sago007 2008-12-09 13:35 4464
                                                    if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4465
                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4466
                                                        //1 player - puzzle
89c4a3a6 sago007 2008-08-29 14:32 4467
                                                        bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4468
                                                        b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4469
                                                        int myLevel = PuzzleLevelSelect();
e1290bdf sago007 2010-10-25 19:56 4470
                                                        theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4471
                                                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4472
                                                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4473
                                                        twoPlayers =false;
89c4a3a6 sago007 2008-08-29 14:32 4474
                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4475
                                                        showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4476
                                                        vsMode = false;
c96f480e sago007 2009-03-28 18:59 4477
                                                        strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4478
                                                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4479
                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4480
                                                    else
9050a50a sago007 2008-12-09 13:35 4481
                                                        if ((buttonXsize<mousex) && (mousex<240) && (200<mousey) && (mousey<240) && (b1playerOpen))
89c4a3a6 sago007 2008-08-29 14:32 4482
                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4483
                                                            //1 player - Vs mode
89c4a3a6 sago007 2008-08-29 14:32 4484
                                                            bNewGameOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4485
                                                            b1playerOpen = false;
89c4a3a6 sago007 2008-08-29 14:32 4486
                                                            int theAIlevel = startSingleVs();
e1290bdf sago007 2010-10-25 19:56 4487
                                                            theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4488
                                                            theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4489
                                                            MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4490
                                                            DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4491
                                                            twoPlayers = true; //Single player, but AI plays
89c4a3a6 sago007 2008-08-29 14:32 4492
                                                            showGame = true;
89c4a3a6 sago007 2008-08-29 14:32 4493
                                                            vsMode = true;
89c4a3a6 sago007 2008-08-29 14:32 4494
                                                            theGame2.setAIlevel((Uint8)theAIlevel);
89c4a3a6 sago007 2008-08-29 14:32 4495
                                                            int theTime = time(0);
89c4a3a6 sago007 2008-08-29 14:32 4496
                                                            theGame.putStartBlocks(theTime);
89c4a3a6 sago007 2008-08-29 14:32 4497
                                                            theGame2.putStartBlocks(theTime);
c96f480e sago007 2009-03-28 18:59 4498
                                                            strcpy(theGame.name, player1name);
c96f480e sago007 2009-03-28 18:59 4499
                                                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4500
                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4501
                                                        else
9050a50a sago007 2008-12-09 13:35 4502
                                                            if ((buttonXsize<mousex) && (mousex<240) && (80<mousey) && (mousey<120) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4503
                                                            {
4f1d27f1 sago007 2011-03-18 15:53 4504
                                                                StarTwoPlayerTimeTrial();
89c4a3a6 sago007 2008-08-29 14:32 4505
                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4506
                                                            else
9050a50a sago007 2008-12-09 13:35 4507
                                                                if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (b2playersOpen))
89c4a3a6 sago007 2008-08-29 14:32 4508
                                                                {
4f1d27f1 sago007 2011-03-18 15:53 4509
                                                                    StartTwoPlayerVs();
89c4a3a6 sago007 2008-08-29 14:32 4510
                                                                }
1572de2b sago007 2008-09-11 18:15 4511
#if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4512
                                                                else
9050a50a sago007 2008-12-09 13:35 4513
                                                                    if ((buttonXsize<mousex) && (mousex<240) && (120<mousey) && (mousey<160) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4514
                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4515
                                                                        //Host
89c4a3a6 sago007 2008-08-29 14:32 4516
                                                                        cout << "Host" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4517
                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4518
                                                                        theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4519
                                                                        theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4520
                                                                        nt.startServer();
89c4a3a6 sago007 2008-08-29 14:32 4521
                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4522
                                                                    else
9050a50a sago007 2008-12-09 13:35 4523
                                                                        if ((buttonXsize<mousex) && (mousex<240) && (160<mousey) && (mousey<200) && (bNetworkOpen))
89c4a3a6 sago007 2008-08-29 14:32 4524
                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4525
                                                                            //Connect
89c4a3a6 sago007 2008-08-29 14:32 4526
                                                                            cout << "Connect" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4527
                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4528
                                                                            theGame.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4529
                                                                            theGame2.SetGameOver();
89c4a3a6 sago007 2008-08-29 14:32 4530
                                                                            if (OpenDialogbox(200,100,serverAddress))
89c4a3a6 sago007 2008-08-29 14:32 4531
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4532
                                                                                char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4533
                                                                                memcpy(buf,serverAddress,30);
89c4a3a6 sago007 2008-08-29 14:32 4534
                                                                                nt.connectToServer(strtok(buf," "));
89c4a3a6 sago007 2008-08-29 14:32 4535
                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4536
                                                                            while ( SDL_PollEvent(&event) ); //If the user have pressed ESC or the like
89c4a3a6 sago007 2008-08-29 14:32 4537
                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4538
#endif
89c4a3a6 sago007 2008-08-29 14:32 4539
                                                                        else
9050a50a sago007 2008-12-09 13:35 4540
                                                                            if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4541
                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4542
                                                                                //options button clicked
89c4a3a6 sago007 2008-08-29 14:32 4543
                                                                                if (bOptionsOpen)
89c4a3a6 sago007 2008-08-29 14:32 4544
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4545
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4546
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4547
                                                                                else
89c4a3a6 sago007 2008-08-29 14:32 4548
                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4549
                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4550
                                                                                    bOptionsOpen = true;
89c4a3a6 sago007 2008-08-29 14:32 4551
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4552
                                                                                }
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) && (40<mousey) && (mousey<80) && (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
                                                                                    if (!showOptions) {
89c4a3a6 sago007 2008-08-29 14:32 4560
                                                                                        showOptions = true;
89c4a3a6 sago007 2008-08-29 14:32 4561
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4562
                                                                                    else showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4563
                                                                                    DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4564
                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4565
                                                                                else
9050a50a sago007 2008-12-09 13:35 4566
                                                                                    if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (80<mousey) && (mousey<120) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4567
                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4568
                                                                                        //Configure button clicked
89c4a3a6 sago007 2008-08-29 14:32 4569
                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4570
                                                                                        changePuzzleLevels();
89c4a3a6 sago007 2008-08-29 14:32 4571
                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4572
                                                                                    else
9050a50a sago007 2008-12-09 13:35 4573
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (120<mousey) && (mousey<160) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4574
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4575
                                                                                            //vsMode button clicked
89c4a3a6 sago007 2008-08-29 14:32 4576
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4577
                                                                                            startVsMenu();
89c4a3a6 sago007 2008-08-29 14:32 4578
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4579
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4580
                                                                                        if ((buttonXsize<mousex) && (mousex<2*buttonXsize) && (160<mousey) && (mousey<200) && (bOptionsOpen) )
89c4a3a6 sago007 2008-08-29 14:32 4581
                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4582
                                                                                            //selectThemClicked
89c4a3a6 sago007 2008-08-29 14:32 4583
                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4584
                                                                                            char temp[30];
89c4a3a6 sago007 2008-08-29 14:32 4585
                                                                                            SelectThemeDialogbox(200,100,temp);
89c4a3a6 sago007 2008-08-29 14:32 4586
                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4587
                                                                                        else
9050a50a sago007 2008-12-09 13:35 4588
                                                                                            if ((buttonXsize*2<mousex) && (mousex<3*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4589
                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4590
                                                                                                //highscore button clicked
47529580 sago007 2008-12-09 02:34 4591
                                                                                                OpenScoresDisplay();
47529580 sago007 2008-12-09 02:34 4592
89c4a3a6 sago007 2008-08-29 14:32 4593
                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4594
                                                                                            else
9050a50a sago007 2008-12-09 13:35 4595
                                                                                                if ((360<mousex) && (mousex<4*buttonXsize) && (0<mousey) && (mousey<40) &&(!networkActive))
89c4a3a6 sago007 2008-08-29 14:32 4596
                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4597
                                                                                                    //Replay clicked!
89c4a3a6 sago007 2008-08-29 14:32 4598
                                                                                                    bool state = (!bReplayOpen);
89c4a3a6 sago007 2008-08-29 14:32 4599
                                                                                                    closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4600
                                                                                                    bReplayOpen = state; //theGame.NewGame(50,100);
89c4a3a6 sago007 2008-08-29 14:32 4601
                                                                                                    showOptions = false;
89c4a3a6 sago007 2008-08-29 14:32 4602
                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4603
                                                                                                else
9050a50a sago007 2008-12-09 13:35 4604
                                                                                                    if ((360<mousex) && (mousex<4*buttonXsize) && (40<mousey) && (mousey<80) &&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4605
                                                                                                    {
89c4a3a6 sago007 2008-08-29 14:32 4606
                                                                                                        //Replay->Save clicked!
89c4a3a6 sago007 2008-08-29 14:32 4607
                                                                                                        //cout << "Replay->Save clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4608
                                                                                                        char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4609
                                                                                                        for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4610
                                                                                                        buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4611
                                                                                                        OpenDialogbox(200,100,buf);
89c4a3a6 sago007 2008-08-29 14:32 4612
                                                                                                        for (int i=28;buf[i]==' ';i--)
89c4a3a6 sago007 2008-08-29 14:32 4613
                                                                                                            buf[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 4614
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 4615
                                                                                                        string saveHere = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4616
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 4617
                                                                                                        string saveHere = home+(string)"/My Games/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4618
#else
89c4a3a6 sago007 2008-08-29 14:32 4619
                                                                                                        string saveHere = (string)"./replays"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4620
#endif
89c4a3a6 sago007 2008-08-29 14:32 4621
                                                                                                        if (lastNrOfPlayers<2)
89c4a3a6 sago007 2008-08-29 14:32 4622
                                                                                                            theGame.theReplay.saveReplay(saveHere);
89c4a3a6 sago007 2008-08-29 14:32 4623
                                                                                                        else
89c4a3a6 sago007 2008-08-29 14:32 4624
                                                                                                            theGame.theReplay.saveReplay(saveHere,theGame2.theReplay);
89c4a3a6 sago007 2008-08-29 14:32 4625
89c4a3a6 sago007 2008-08-29 14:32 4626
                                                                                                        closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4627
                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4628
                                                                                                    else
9050a50a sago007 2008-12-09 13:35 4629
                                                                                                        if ((360<mousex) && (mousex<4*buttonXsize) && (80<mousey) && (mousey<120)&&(bReplayOpen))
89c4a3a6 sago007 2008-08-29 14:32 4630
                                                                                                        {
89c4a3a6 sago007 2008-08-29 14:32 4631
                                                                                                            //Replay->Load clicked!
89c4a3a6 sago007 2008-08-29 14:32 4632
                                                                                                            //cout << "Replay->Load clicked" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4633
89c4a3a6 sago007 2008-08-29 14:32 4634
                                                                                                            char buf[30];
89c4a3a6 sago007 2008-08-29 14:32 4635
                                                                                                            for (int i=0;i<29;i++)buf[i]=' ';
89c4a3a6 sago007 2008-08-29 14:32 4636
                                                                                                            buf[30]=0;
89c4a3a6 sago007 2008-08-29 14:32 4637
                                                                                                            if (OpenReplayDialogbox(50,100,buf))
89c4a3a6 sago007 2008-08-29 14:32 4638
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4639
                                                                                                                //cout << "Good way" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4640
                                                                                                                for (int i=28;buf[i]==' ';i--)
89c4a3a6 sago007 2008-08-29 14:32 4641
                                                                                                                    buf[i]=0;
89c4a3a6 sago007 2008-08-29 14:32 4642
#ifdef __unix__
89c4a3a6 sago007 2008-08-29 14:32 4643
                                                                                                                string loadThis = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4644
#elif WIN32
89c4a3a6 sago007 2008-08-29 14:32 4645
                                                                                                                string loadThis = home+(string)"/My Games/blockattack/replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4646
#else
89c4a3a6 sago007 2008-08-29 14:32 4647
                                                                                                                string loadThis = (string)"./replays/"+(string)buf;
89c4a3a6 sago007 2008-08-29 14:32 4648
#endif
89c4a3a6 sago007 2008-08-29 14:32 4649
                                                                                                                ifstream replayFileIn;
89c4a3a6 sago007 2008-08-29 14:32 4650
                                                                                                                replayFileIn.open(loadThis.c_str(),ios::binary);
89c4a3a6 sago007 2008-08-29 14:32 4651
                                                                                                                bool play2 = false;
89c4a3a6 sago007 2008-08-29 14:32 4652
                                                                                                                if (replayFileIn)
89c4a3a6 sago007 2008-08-29 14:32 4653
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4654
                                                                                                                    Uint8 version = 0;
89c4a3a6 sago007 2008-08-29 14:32 4655
                                                                                                                    replayFileIn.read(reinterpret_cast<char*>(&version),sizeof(Uint8));                                                                                                                  replayFileIn.close();
89c4a3a6 sago007 2008-08-29 14:32 4656
                                                                                                                    Replay r1;
e03ae476 sago007 2009-03-06 22:49 4657
                                                                                                                    if(r1.loadReplay(loadThis))
89c4a3a6 sago007 2008-08-29 14:32 4658
                                                                                                                    {
e03ae476 sago007 2009-03-06 22:49 4659
                                                                                                                        Replay r2;
e03ae476 sago007 2009-03-06 22:49 4660
                                                                                                                        play2 = r2.loadReplay2(loadThis);
e1290bdf sago007 2010-10-25 19:56 4661
                                                                                                                        theGame.playReplay(50,100,SDL_GetTicks()); //Fejlen sker her
e03ae476 sago007 2009-03-06 22:49 4662
                                                                                                                        theGame.theReplay = r1;
e03ae476 sago007 2009-03-06 22:49 4663
                                                                                                                        if (play2)
e03ae476 sago007 2009-03-06 22:49 4664
                                                                                                                        {
e1290bdf sago007 2010-10-25 19:56 4665
                                                                                                                            theGame2.playReplay(xsize-500,100,SDL_GetTicks());
e03ae476 sago007 2009-03-06 22:49 4666
                                                                                                                            theGame2.theReplay = r2;
e03ae476 sago007 2009-03-06 22:49 4667
                                                                                                                        }
e03ae476 sago007 2009-03-06 22:49 4668
                                                                                                                        else
e03ae476 sago007 2009-03-06 22:49 4669
                                                                                                                            theGame2.SetGameOver();
e03ae476 sago007 2009-03-06 22:49 4670
                                                                                                                        cout << "Replay should have been read" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4671
                                                                                                                    }
89c4a3a6 sago007 2008-08-29 14:32 4672
                                                                                                                    else
e03ae476 sago007 2009-03-06 22:49 4673
                                                                                                                        cout << "Failed to read replay" << endl;
89c4a3a6 sago007 2008-08-29 14:32 4674
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4675
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4676
                                                                                                            closeAllMenus();
89c4a3a6 sago007 2008-08-29 14:32 4677
                                                                                                        }
89c4a3a6 sago007 2008-08-29 14:32 4678
                                                                                                        else
9050a50a sago007 2008-12-09 13:35 4679
                                                                                                            if ((xsize-120<mousex) && (xsize-20>mousex) && (ysize-buttonXsize<mousey) && (ysize-20>mousey))
89c4a3a6 sago007 2008-08-29 14:32 4680
                                                                                                            {
89c4a3a6 sago007 2008-08-29 14:32 4681
                                                                                                                //Exit clicked
89c4a3a6 sago007 2008-08-29 14:32 4682
                                                                                                                done=1;
89c4a3a6 sago007 2008-08-29 14:32 4683
                                                                                                            }
89c4a3a6 sago007 2008-08-29 14:32 4684
                                                                                                            else
89c4a3a6 sago007 2008-08-29 14:32 4685
                                                                                                                if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>220) && (mousey<260))
89c4a3a6 sago007 2008-08-29 14:32 4686
                                                                                                                {
89c4a3a6 sago007 2008-08-29 14:32 4687
                                                                                                                    MusicEnabled = !MusicEnabled;
89c4a3a6 sago007 2008-08-29 14:32 4688
                                                                                                                    if (!MusicEnabled) Mix_FadeOutMusic(500);
89c4a3a6 sago007 2008-08-29 14:32 4689
                                                                                                                }
89c4a3a6 sago007 2008-08-29 14:32 4690
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>270) && (mousey<310))
89c4a3a6 sago007 2008-08-29 14:32 4691
                    {
89c4a3a6 sago007 2008-08-29 14:32 4692
                        SoundEnabled = !SoundEnabled;
89c4a3a6 sago007 2008-08-29 14:32 4693
                    }
89c4a3a6 sago007 2008-08-29 14:32 4694
                    if ((showOptions) && (mousex>500) && (mousex<560) && (mousey>320) && (mousey<360))
89c4a3a6 sago007 2008-08-29 14:32 4695
                    {
89c4a3a6 sago007 2008-08-29 14:32 4696
                        //Fullscreen
89c4a3a6 sago007 2008-08-29 14:32 4697
                        bFullscreen = !bFullscreen;
89c4a3a6 sago007 2008-08-29 14:32 4698
#if defined(WIN32)
89c4a3a6 sago007 2008-08-29 14:32 4699
                        if (bFullscreen) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 4700
                        else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT);
89c4a3a6 sago007 2008-08-29 14:32 4701
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4702
#else
89c4a3a6 sago007 2008-08-29 14:32 4703
                        SDL_WM_ToggleFullScreen(screen); //Will only work in Linux
89c4a3a6 sago007 2008-08-29 14:32 4704
#endif
89c4a3a6 sago007 2008-08-29 14:32 4705
                        SDL_ShowCursor(SDL_DISABLE);
89c4a3a6 sago007 2008-08-29 14:32 4706
                    }
89c4a3a6 sago007 2008-08-29 14:32 4707
89c4a3a6 sago007 2008-08-29 14:32 4708
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 4709
                    {
89c4a3a6 sago007 2008-08-29 14:32 4710
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 4711
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 4712
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 4713
                        strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 4714
                        if (OpenDialogbox(200,100,player1name))
89c4a3a6 sago007 2008-08-29 14:32 4715
                            strcpy(theGame.name, player1name);
89c4a3a6 sago007 2008-08-29 14:32 4716
                        else
89c4a3a6 sago007 2008-08-29 14:32 4717
                            strcpy(player1name,theGame.name);
89c4a3a6 sago007 2008-08-29 14:32 4718
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 4719
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 4720
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4721
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4722
                    }
89c4a3a6 sago007 2008-08-29 14:32 4723
                    if ((showOptions) && (mousex>330) && (mousex<470) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 4724
                    {
89c4a3a6 sago007 2008-08-29 14:32 4725
                        //change name
89c4a3a6 sago007 2008-08-29 14:32 4726
                        bScreenLocked = true;
89c4a3a6 sago007 2008-08-29 14:32 4727
                        showDialog = true;
c96f480e sago007 2009-03-28 18:59 4728
                        strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4729
                        if (OpenDialogbox(200,100,player2name))
89c4a3a6 sago007 2008-08-29 14:32 4730
                            strcpy(theGame2.name, player2name);
89c4a3a6 sago007 2008-08-29 14:32 4731
                        else
89c4a3a6 sago007 2008-08-29 14:32 4732
                            strcpy(player2name,theGame2.name);
89c4a3a6 sago007 2008-08-29 14:32 4733
                        bScreenLocked = false;
89c4a3a6 sago007 2008-08-29 14:32 4734
                        showDialog = false;
e1290bdf sago007 2010-10-25 19:56 4735
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4736
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4737
                    }
89c4a3a6 sago007 2008-08-29 14:32 4738
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>535) && (mousey<585))
89c4a3a6 sago007 2008-08-29 14:32 4739
                    {
89c4a3a6 sago007 2008-08-29 14:32 4740
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 4741
                        OpenControlsBox(200,100,0);
e1290bdf sago007 2010-10-25 19:56 4742
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4743
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4744
                    }
89c4a3a6 sago007 2008-08-29 14:32 4745
                    if ((showOptions) && (mousex>510) && (mousex<630) && (mousey>600) && (mousey<640))
89c4a3a6 sago007 2008-08-29 14:32 4746
                    {
89c4a3a6 sago007 2008-08-29 14:32 4747
                        //changeControls
89c4a3a6 sago007 2008-08-29 14:32 4748
                        OpenControlsBox(200,100,2);
e1290bdf sago007 2010-10-25 19:56 4749
                        MakeBackground(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4750
                        DrawIMG(background, screen, 0, 0);
89c4a3a6 sago007 2008-08-29 14:32 4751
                    }
89c4a3a6 sago007 2008-08-29 14:32 4752
89c4a3a6 sago007 2008-08-29 14:32 4753
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4754
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4755
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 4756
                    if ((!showOptions))
89c4a3a6 sago007 2008-08-29 14:32 4757
                    {
e1290bdf sago007 2010-10-25 19:56 4758
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4759
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4760
                            {
89c4a3a6 sago007 2008-08-29 14:32 4761
                                theGame.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4762
                            }
e1290bdf sago007 2010-10-25 19:56 4763
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4764
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4765
                            {
89c4a3a6 sago007 2008-08-29 14:32 4766
                                theGame2.SwitchAtCursor();
89c4a3a6 sago007 2008-08-29 14:32 4767
                            }
89c4a3a6 sago007 2008-08-29 14:32 4768
                    }
89c4a3a6 sago007 2008-08-29 14:32 4769
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4770
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4771
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4772
e1290bdf sago007 2010-10-25 19:56 4773
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
e1290bdf sago007 2010-10-25 19:56 4774
                            &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
e1290bdf sago007 2010-10-25 19:56 4775
                            &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 4776
                    {
89c4a3a6 sago007 2008-08-29 14:32 4777
                        //Clicked the next button after a stage clear or puzzle
e1290bdf sago007 2010-10-25 19:56 4778
                        theGame.nextLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4779
                    }
e1290bdf sago007 2010-10-25 19:56 4780
                    if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
e1290bdf sago007 2010-10-25 19:56 4781
                            &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
e1290bdf sago007 2010-10-25 19:56 4782
                            &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize))
89c4a3a6 sago007 2008-08-29 14:32 4783
                    {
89c4a3a6 sago007 2008-08-29 14:32 4784
                        //Clicked the retry button
e1290bdf sago007 2010-10-25 19:56 4785
                        theGame.retryLevel(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4786
                    }
89c4a3a6 sago007 2008-08-29 14:32 4787
                        
89c4a3a6 sago007 2008-08-29 14:32 4788
                    
89c4a3a6 sago007 2008-08-29 14:32 4789
                    //cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
89c4a3a6 sago007 2008-08-29 14:32 4790
                }
89c4a3a6 sago007 2008-08-29 14:32 4791
89c4a3a6 sago007 2008-08-29 14:32 4792
                //Mouse button 2:
89c4a3a6 sago007 2008-08-29 14:32 4793
                if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2)
89c4a3a6 sago007 2008-08-29 14:32 4794
                {
89c4a3a6 sago007 2008-08-29 14:32 4795
                    bMouseUp2=false; //The button is pressed
89c4a3a6 sago007 2008-08-29 14:32 4796
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4797
                    **************** Here comes mouse play ******************************
89c4a3a6 sago007 2008-08-29 14:32 4798
                    ********************************************************************/
47529580 sago007 2008-12-09 02:34 4799
                    if (!showOptions)
89c4a3a6 sago007 2008-08-29 14:32 4800
                    {
e1290bdf sago007 2010-10-25 19:56 4801
                        if (mouseplay1 && !theGame.GetAIenabled()) //player 1
89c4a3a6 sago007 2008-08-29 14:32 4802
                            if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4803
                            {
89c4a3a6 sago007 2008-08-29 14:32 4804
                                theGame.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4805
                            }
e1290bdf sago007 2010-10-25 19:56 4806
                        if (mouseplay2 && !theGame2.GetAIenabled()) //player 2
89c4a3a6 sago007 2008-08-29 14:32 4807
                            if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600))
89c4a3a6 sago007 2008-08-29 14:32 4808
                            {
89c4a3a6 sago007 2008-08-29 14:32 4809
                                theGame2.PushLine();
89c4a3a6 sago007 2008-08-29 14:32 4810
                            }
89c4a3a6 sago007 2008-08-29 14:32 4811
                    }
89c4a3a6 sago007 2008-08-29 14:32 4812
                    /********************************************************************
89c4a3a6 sago007 2008-08-29 14:32 4813
                    **************** Here ends mouse play *******************************
89c4a3a6 sago007 2008-08-29 14:32 4814
                    ********************************************************************/
89c4a3a6 sago007 2008-08-29 14:32 4815
                }
89c4a3a6 sago007 2008-08-29 14:32 4816
            } //if !singlePuzzle
89c4a3a6 sago007 2008-08-29 14:32 4817
            else
89c4a3a6 sago007 2008-08-29 14:32 4818
            {
89c4a3a6 sago007 2008-08-29 14:32 4819
89c4a3a6 sago007 2008-08-29 14:32 4820
            }
89c4a3a6 sago007 2008-08-29 14:32 4821
        } //if !bScreenBocked;
89c4a3a6 sago007 2008-08-29 14:32 4822
89c4a3a6 sago007 2008-08-29 14:32 4823
89c4a3a6 sago007 2008-08-29 14:32 4824
        //Sees if music is stopped and if music is enabled
6d48320c sago007 2009-03-28 17:06 4825
        if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath))
89c4a3a6 sago007 2008-08-29 14:32 4826
        {
89c4a3a6 sago007 2008-08-29 14:32 4827
            // then starts playing it.
6d48320c sago007 2009-03-28 17:06 4828
            Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4829
            Mix_PlayMusic(bgMusic, -1); //music loop
89c4a3a6 sago007 2008-08-29 14:32 4830
        }
89c4a3a6 sago007 2008-08-29 14:32 4831
6d48320c sago007 2009-03-28 17:06 4832
        if(bNearDeath!=bNearDeathPrev)
6d48320c sago007 2009-03-28 17:06 4833
        {
6d48320c sago007 2009-03-28 17:06 4834
            if(bNearDeath)
6d48320c sago007 2009-03-28 17:06 4835
            {
6d48320c sago007 2009-03-28 17:06 4836
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 4837
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4838
                    Mix_PlayMusic(highbeatMusic, 1);
6d48320c sago007 2009-03-28 17:06 4839
                }
6d48320c sago007 2009-03-28 17:06 4840
            }
6d48320c sago007 2009-03-28 17:06 4841
            else
6d48320c sago007 2009-03-28 17:06 4842
            {
6d48320c sago007 2009-03-28 17:06 4843
                if(!NoSound &&(MusicEnabled)) {
6d48320c sago007 2009-03-28 17:06 4844
                    Mix_VolumeMusic(MIX_MAX_VOLUME);
6d48320c sago007 2009-03-28 17:06 4845
                    Mix_PlayMusic(bgMusic, -1);
6d48320c sago007 2009-03-28 17:06 4846
                }
6d48320c sago007 2009-03-28 17:06 4847
            }
6d48320c sago007 2009-03-28 17:06 4848
        }
6d48320c sago007 2009-03-28 17:06 4849
6d48320c sago007 2009-03-28 17:06 4850
        bNearDeathPrev = bNearDeath;
6d48320c sago007 2009-03-28 17:06 4851
6d48320c sago007 2009-03-28 17:06 4852
6d48320c sago007 2009-03-28 17:06 4853
        //set bNearDeath to false theGame*.Update() will change to true as needed
6d48320c sago007 2009-03-28 17:06 4854
        bNearDeath = false;
89c4a3a6 sago007 2008-08-29 14:32 4855
        //Updates the objects
e1290bdf sago007 2010-10-25 19:56 4856
        theGame.Update(SDL_GetTicks());
e1290bdf sago007 2010-10-25 19:56 4857
        theGame2.Update(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4858
89c4a3a6 sago007 2008-08-29 14:32 4859
//see if anyone has won (two players only)
2f30c381 sago007 2008-09-14 13:08 4860
        #if NETWORK
89c4a3a6 sago007 2008-08-29 14:32 4861
        if (!networkPlay)
2f30c381 sago007 2008-09-14 13:08 4862
        #endif
89c4a3a6 sago007 2008-08-29 14:32 4863
            if (twoPlayers)
89c4a3a6 sago007 2008-08-29 14:32 4864
            {
89c4a3a6 sago007 2008-08-29 14:32 4865
                lastNrOfPlayers = 2;
e1290bdf sago007 2010-10-25 19:56 4866
                if ((theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4867
                {
e1290bdf sago007 2010-10-25 19:56 4868
                    if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 4869
                        theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4870
                    else
e1290bdf sago007 2010-10-25 19:56 4871
                        if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap())
89c4a3a6 sago007 2008-08-29 14:32 4872
                            theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4873
                        else {
89c4a3a6 sago007 2008-08-29 14:32 4874
                            theGame.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 4875
                            theGame2.setDraw();
89c4a3a6 sago007 2008-08-29 14:32 4876
                        }
89c4a3a6 sago007 2008-08-29 14:32 4877
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4878
                }
e1290bdf sago007 2010-10-25 19:56 4879
                if ((theGame.isGameOver()) && (!theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4880
                {
89c4a3a6 sago007 2008-08-29 14:32 4881
                    theGame2.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4882
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4883
                }
e1290bdf sago007 2010-10-25 19:56 4884
                if ((!theGame.isGameOver()) && (theGame2.isGameOver()))
89c4a3a6 sago007 2008-08-29 14:32 4885
                {
89c4a3a6 sago007 2008-08-29 14:32 4886
                    theGame.setPlayerWon();
89c4a3a6 sago007 2008-08-29 14:32 4887
                    twoPlayers = false;
89c4a3a6 sago007 2008-08-29 14:32 4888
                }
89c4a3a6 sago007 2008-08-29 14:32 4889
            }
89c4a3a6 sago007 2008-08-29 14:32 4890
89c4a3a6 sago007 2008-08-29 14:32 4891
        //Once evrything has been checked, update graphics
e1290bdf sago007 2010-10-25 19:56 4892
        DrawEverything(xsize,ysize,&theGame,&theGame2);
89c4a3a6 sago007 2008-08-29 14:32 4893
        SDL_GetMouseState(&mousex,&mousey);
89c4a3a6 sago007 2008-08-29 14:32 4894
        //Remember mouse placement
89c4a3a6 sago007 2008-08-29 14:32 4895
        oldMousex = mousex;
89c4a3a6 sago007 2008-08-29 14:32 4896
        oldMousey = mousey;
89c4a3a6 sago007 2008-08-29 14:32 4897
        //Draw the mouse:
8d488d32 sago007 2011-04-17 13:02 4898
        //DrawIMG(mouse,screen,mousex,mousey);
8d488d32 sago007 2011-04-17 13:02 4899
        mouse.PaintTo(screen,mousex,mousey);
89c4a3a6 sago007 2008-08-29 14:32 4900
        SDL_Flip(screen);
89c4a3a6 sago007 2008-08-29 14:32 4901
    } //game loop
89c4a3a6 sago007 2008-08-29 14:32 4902
89c4a3a6 sago007 2008-08-29 14:32 4903
89c4a3a6 sago007 2008-08-29 14:32 4904
89c4a3a6 sago007 2008-08-29 14:32 4905
    //Saves options
89c4a3a6 sago007 2008-08-29 14:32 4906
    if (!editorMode)
89c4a3a6 sago007 2008-08-29 14:32 4907
    {
769a41a0 sago007 2008-09-24 12:54 4908
        configSettings->setInt("fullscreen",(int)bFullscreen);
769a41a0 sago007 2008-09-24 12:54 4909
        configSettings->setInt("musicenabled",(int)MusicEnabled);
769a41a0 sago007 2008-09-24 12:54 4910
        configSettings->setInt("soundenabled",(int)SoundEnabled);
769a41a0 sago007 2008-09-24 12:54 4911
        configSettings->setInt("mouseplay1",(int)mouseplay1);
769a41a0 sago007 2008-09-24 12:54 4912
        configSettings->setInt("mouseplay2",(int)mouseplay2);
769a41a0 sago007 2008-09-24 12:54 4913
        configSettings->setInt("joypad1",(int)joyplay1);
769a41a0 sago007 2008-09-24 12:54 4914
        configSettings->setInt("joypad2",(int)joyplay2);
769a41a0 sago007 2008-09-24 12:54 4915
        
769a41a0 sago007 2008-09-24 12:54 4916
        configSettings->setInt("player1keyup",(int)keySettings[0].up);
769a41a0 sago007 2008-09-24 12:54 4917
        configSettings->setInt("player1keydown",(int)keySettings[0].down);
769a41a0 sago007 2008-09-24 12:54 4918
        configSettings->setInt("player1keyleft",(int)keySettings[0].left);
769a41a0 sago007 2008-09-24 12:54 4919
        configSettings->setInt("player1keyright",(int)keySettings[0].right);
769a41a0 sago007 2008-09-24 12:54 4920
        configSettings->setInt("player1keychange",(int)keySettings[0].change);
769a41a0 sago007 2008-09-24 12:54 4921
        configSettings->setInt("player1keypush",(int)keySettings[0].push);
769a41a0 sago007 2008-09-24 12:54 4922
        
769a41a0 sago007 2008-09-24 12:54 4923
        configSettings->setInt("player2keyup",(int)keySettings[2].up);
769a41a0 sago007 2008-09-24 12:54 4924
        configSettings->setInt("player2keydown",(int)keySettings[2].down);
769a41a0 sago007 2008-09-24 12:54 4925
        configSettings->setInt("player2keyleft",(int)keySettings[2].left);
769a41a0 sago007 2008-09-24 12:54 4926
        configSettings->setInt("player2keyright",(int)keySettings[2].right);
769a41a0 sago007 2008-09-24 12:54 4927
        configSettings->setInt("player2keychange",(int)keySettings[2].change);
769a41a0 sago007 2008-09-24 12:54 4928
        configSettings->setInt("player2keypush",(int)keySettings[2].push);
769a41a0 sago007 2008-09-24 12:54 4929
        
769a41a0 sago007 2008-09-24 12:54 4930
        configSettings->setString("player1name",player1name);
769a41a0 sago007 2008-09-24 12:54 4931
        configSettings->setString("player2name",player2name);
769a41a0 sago007 2008-09-24 12:54 4932
        configSettings->save();
89c4a3a6 sago007 2008-08-29 14:32 4933
    }
89c4a3a6 sago007 2008-08-29 14:32 4934
89c4a3a6 sago007 2008-08-29 14:32 4935
    //calculate uptime:
c09d0e4f sago007 2009-01-27 01:15 4936
    //int hours, mins, secs,
cd12e0fe sago007 2009-01-29 08:47 4937
    commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
89c4a3a6 sago007 2008-08-29 14:32 4938
89c4a3a6 sago007 2008-08-29 14:32 4939
    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 4940
cd12e0fe sago007 2009-01-29 08:47 4941
    ct = TimeHandler::addTime("totalTime",ct);
c09d0e4f sago007 2009-01-27 01:15 4942
89c4a3a6 sago007 2008-08-29 14:32 4943
    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 4944
c09d0e4f sago007 2009-01-27 01:15 4945
    Stats::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 4946
c09d0e4f sago007 2009-01-27 01:15 4947
    Config::getInstance()->save();
c09d0e4f sago007 2009-01-27 01:15 4948
    
c09d0e4f sago007 2009-01-27 01:15 4949
    //Frees memory from music and fonts
c09d0e4f sago007 2009-01-27 01:15 4950
    //This is done after writing of configurations and stats since it often crashes the program :(
c09d0e4f sago007 2009-01-27 01:15 4951
    UnloadImages();
41f02ab2 sago007 2009-05-10 21:40 4952
      
91886cae sago007 2008-09-12 16:28 4953
    //Close file system Apstraction layer!
91886cae sago007 2008-09-12 16:28 4954
    PHYSFS_deinit();
89c4a3a6 sago007 2008-08-29 14:32 4955
    return 0;
89c4a3a6 sago007 2008-08-29 14:32 4956
}
1970-01-01 00:00 4957