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