git repos / blockattack-game

blame: source/code/main.cpp

normal view · raw

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