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