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
77531130 Poul Sander 2016-02-17 18:42 20
http://www.blockattack.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"
9b99cf7a sago007 2015-12-04 20:22 26
#include "scopeHelpers.hpp"
acc78225 sago007 2015-12-29 18:10 27
#include "icon.hpp"
9dc80982 sago007 2016-01-02 21:08 28
#include "os.hpp"
215ca7b3 sago007 2009-03-06 16:37 29
27ae0175 sago007 2009-01-30 06:02 30
#include <string.h>
27ae0175 sago007 2009-01-30 06:02 31
b6fd59ea sago007 2016-03-16 19:04 32
#include "version.h"
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
571b4d47 sago007 2015-12-05 16:02 36
#define DEBUG 1
1572de2b sago007 2008-09-11 18:15 37
#endif
89c4a3a6 sago007 2008-08-29 14:32 38
2e57d791 sago007 2009-06-04 17:48 39
#define WITH_SDL 1
2e57d791 sago007 2009-06-04 17:48 40
c6bde3e3 sago007 2015-12-22 16:56 41
#include "sago/SagoSpriteHolder.hpp"
89c4a3a6 sago007 2008-08-29 14:32 42
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 43
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 44
#include <time.h>           //Used for srand()
769a41a0 sago007 2008-09-24 12:54 45
#include <sstream>          //Still used by itoa2
89c4a3a6 sago007 2008-08-29 14:32 46
#include <string>
89c4a3a6 sago007 2008-08-29 14:32 47
#include "SDL.h"            //The SDL libary, used for most things
89c4a3a6 sago007 2008-08-29 14:32 48
#include <SDL_mixer.h>      //Used for sound & music
89c4a3a6 sago007 2008-08-29 14:32 49
#include <SDL_image.h>      //To load PNG images!
41f02ab2 sago007 2009-05-10 21:40 50
#include <physfs.h>         //Abstract file system. To use containers
925b7e58 sago007 2011-04-25 16:35 51
#include "Libs/NFont.h"
47529580 sago007 2008-12-09 02:34 52
//#include "ttfont.h"        //To use True Type Fonts in SDL
89c4a3a6 sago007 2008-08-29 14:32 53
//#include "config.h"
89c4a3a6 sago007 2008-08-29 14:32 54
#include <vector>
b7590374 sago007 2011-05-19 16:15 55
#include "MenuSystem.h"
055218be sago007 2015-08-22 18:44 56
#include "puzzlehandler.hpp"
ae5d6381 sago007 2015-12-29 13:26 57
#include "stageclearhandler.hpp"
f3a1637d sago007 2015-11-14 21:32 58
#include <memory>
c3b697c6 sago007 2016-02-07 17:30 59
#include "ScoresDisplay.hpp"
89c4a3a6 sago007 2008-08-29 14:32 60
89c4a3a6 sago007 2008-08-29 14:32 61
//if SHAREDIR is not used we look in current directory
89c4a3a6 sago007 2008-08-29 14:32 62
#ifndef SHAREDIR
89c4a3a6 sago007 2008-08-29 14:32 63
#define SHAREDIR "."
89c4a3a6 sago007 2008-08-29 14:32 64
#endif
89c4a3a6 sago007 2008-08-29 14:32 65
c9dd376f sago007 2012-01-20 17:13 66
#ifndef LOCALEDIR
c9dd376f sago007 2012-01-20 17:13 67
#define LOCALEDIR SHAREDIR"/locale"
c9dd376f sago007 2012-01-20 17:13 68
#endif
89c4a3a6 sago007 2008-08-29 14:32 69
c9dd376f sago007 2012-01-20 17:13 70
#ifndef PACKAGE
c9dd376f sago007 2012-01-20 17:13 71
#define PACKAGE "blockattack_roftb"
c9dd376f sago007 2012-01-20 17:13 72
#endif
89c4a3a6 sago007 2008-08-29 14:32 73
89c4a3a6 sago007 2008-08-29 14:32 74
#include "highscore.h"      //Stores highscores
89c4a3a6 sago007 2008-08-29 14:32 75
#include "ReadKeyboard.h"   //Reads text from keyboard
89c4a3a6 sago007 2008-08-29 14:32 76
#include "stats.h"          //Saves general stats 
bc9ea011 sago007 2009-04-12 17:43 77
//#include "uploadReplay.h"   //Takes care of everything libcurl related
89c4a3a6 sago007 2008-08-29 14:32 78
89c4a3a6 sago007 2008-08-29 14:32 79
#include "common.h"
826cf176 sago007 2016-03-12 10:53 80
#include "gamecontroller.h"
c8b43ea3 sago007 2016-02-02 18:20 81
#include <boost/program_options.hpp>
89c4a3a6 sago007 2008-08-29 14:32 82
89c4a3a6 sago007 2008-08-29 14:32 83
/*******************************************************************************
ee077313 sago007 2016-02-09 18:39 84
* All variables and constant has been moved to mainVars.inc for the overview.  *
89c4a3a6 sago007 2008-08-29 14:32 85
*******************************************************************************/
ee077313 sago007 2016-02-09 18:39 86
#include "mainVars.inc"
89c4a3a6 sago007 2008-08-29 14:32 87
90e6c797 sago007 2015-11-22 21:46 88
using namespace std;
90e6c797 sago007 2015-11-22 21:46 89
89c4a3a6 sago007 2008-08-29 14:32 90
1d2e2129 sago007 2015-12-23 15:41 91
static int InitImages(sago::SagoSpriteHolder& holder);
866417ca sago007 2009-05-10 21:35 92
8c45a7b1 sago007 2016-02-05 21:39 93
static void FsSearchParthMainAppend(std::vector<std::string>& paths) {
8c45a7b1 sago007 2016-02-05 21:39 94
	paths.push_back((string)SHAREDIR+"/blockattack.data");
8c45a7b1 sago007 2016-02-05 21:39 95
	paths.push_back((string)PHYSFS_getBaseDir()+"/blockattack.data");
8c45a7b1 sago007 2016-02-05 21:39 96
	paths.push_back((string)PHYSFS_getBaseDir()+"/data");
8c45a7b1 sago007 2016-02-05 21:39 97
}
8c45a7b1 sago007 2016-02-05 21:39 98
8c45a7b1 sago007 2016-02-05 21:39 99
static void PhysFsSetSearchPath(const vector<string>& paths, const string& savepath) {
8c45a7b1 sago007 2016-02-05 21:39 100
	for (const string& path : paths) {
8c45a7b1 sago007 2016-02-05 21:39 101
		PHYSFS_addToSearchPath(path.c_str(),1);
8c45a7b1 sago007 2016-02-05 21:39 102
	}
8c45a7b1 sago007 2016-02-05 21:39 103
	PHYSFS_addToSearchPath(savepath.c_str(), 1);
3647d72c sago007 2016-02-12 22:24 104
	PHYSFS_setWriteDir(savepath.c_str());
89c4a3a6 sago007 2008-08-29 14:32 105
}
89c4a3a6 sago007 2008-08-29 14:32 106
89c4a3a6 sago007 2008-08-29 14:32 107
cd724e02 sago007 2016-02-13 16:04 108
static void PhysFsCreateFolders() {
cd724e02 sago007 2016-02-13 16:04 109
	PHYSFS_mkdir("screenshots");
cd724e02 sago007 2016-02-13 16:04 110
	PHYSFS_mkdir("replays");
cd724e02 sago007 2016-02-13 16:04 111
	PHYSFS_mkdir("puzzles");
cd724e02 sago007 2016-02-13 16:04 112
}
cd724e02 sago007 2016-02-13 16:04 113
89c4a3a6 sago007 2008-08-29 14:32 114
//Load all image files to memory
1d2e2129 sago007 2015-12-23 15:41 115
static int InitImages(sago::SagoSpriteHolder& holder) {
1d2e2129 sago007 2015-12-23 15:41 116
	bricks[0] = holder.GetSprite("blue");
1d2e2129 sago007 2015-12-23 15:41 117
	bricks[1] = holder.GetSprite("green");
1d2e2129 sago007 2015-12-23 15:41 118
	bricks[2] = holder.GetSprite("purple");
1d2e2129 sago007 2015-12-23 15:41 119
	bricks[3] = holder.GetSprite("red");
1d2e2129 sago007 2015-12-23 15:41 120
	bricks[4] = holder.GetSprite("turkish");
1d2e2129 sago007 2015-12-23 15:41 121
	bricks[5] = holder.GetSprite("yellow");
1d2e2129 sago007 2015-12-23 15:41 122
	bricks[6] = holder.GetSprite("grey");
1d2e2129 sago007 2015-12-23 15:41 123
	bomb = holder.GetSprite("block_bomb");
1d2e2129 sago007 2015-12-23 15:41 124
	backgroundImage = holder.GetSprite("background");
1d2e2129 sago007 2015-12-23 15:41 125
	bHighScore = holder.GetSprite("b_highscore");
c7e50476 sago007 2015-12-25 09:44 126
	bBack = holder.GetSprite("b_blank");
1d2e2129 sago007 2015-12-23 15:41 127
	bForward = holder.GetSprite("b_forward");
1d2e2129 sago007 2015-12-23 15:41 128
	blackLine = holder.GetSprite("black_line");
1d2e2129 sago007 2015-12-23 15:41 129
	stageBobble = holder.GetSprite("i_stage_clear_limit");
1d2e2129 sago007 2015-12-23 15:41 130
	crossover = holder.GetSprite("crossover");
1d2e2129 sago007 2015-12-23 15:41 131
	balls[0] = holder.GetSprite("ball_blue");
1d2e2129 sago007 2015-12-23 15:41 132
	balls[1] = holder.GetSprite("ball_green");
1d2e2129 sago007 2015-12-23 15:41 133
	balls[2] = holder.GetSprite("ball_purple");
1d2e2129 sago007 2015-12-23 15:41 134
	balls[3] = holder.GetSprite("ball_red");
1d2e2129 sago007 2015-12-23 15:41 135
	balls[4] = holder.GetSprite("ball_turkish");
1d2e2129 sago007 2015-12-23 15:41 136
	balls[5] = holder.GetSprite("ball_yellow");
1d2e2129 sago007 2015-12-23 15:41 137
	balls[6] = holder.GetSprite("ball_gray");
1d2e2129 sago007 2015-12-23 15:41 138
	cursor = holder.GetSprite("cursor");
1d2e2129 sago007 2015-12-23 15:41 139
	ready = holder.GetSprite("ready");
1d2e2129 sago007 2015-12-23 15:41 140
	explosion[0] = holder.GetSprite("explosion0");
9d259921 sago007 2015-12-23 18:46 141
	explosion[1] = holder.GetSprite("explosion1");
9d259921 sago007 2015-12-23 18:46 142
	explosion[2] = holder.GetSprite("explosion2");
9d259921 sago007 2015-12-23 18:46 143
	explosion[3] = holder.GetSprite("explosion3");
1d2e2129 sago007 2015-12-23 15:41 144
	counter[0] = holder.GetSprite("counter_1");
1d2e2129 sago007 2015-12-23 15:41 145
	counter[1] = holder.GetSprite("counter_2");
1d2e2129 sago007 2015-12-23 15:41 146
	counter[2] = holder.GetSprite("counter_3");
1d2e2129 sago007 2015-12-23 15:41 147
	iGameOver = holder.GetSprite("i_game_over");
1d2e2129 sago007 2015-12-23 15:41 148
	iWinner = holder.GetSprite("i_winner");
1d2e2129 sago007 2015-12-23 15:41 149
	iDraw = holder.GetSprite("i_draw");
1d2e2129 sago007 2015-12-23 15:41 150
	iLoser = holder.GetSprite("i_loser");
c1bd83fb sago007 2015-12-23 19:41 151
	iChainFrame = holder.GetSprite("chain_frame");
1d2e2129 sago007 2015-12-23 15:41 152
	dialogBox = holder.GetSprite("dialogbox");
1d2e2129 sago007 2015-12-23 15:41 153
	iLevelCheck = holder.GetSprite("i_level_check");
1d2e2129 sago007 2015-12-23 15:41 154
	iLevelCheckBox = holder.GetSprite("i_level_check_box");
1d2e2129 sago007 2015-12-23 15:41 155
	iLevelCheckBoxMarked = holder.GetSprite("i_level_check_box_marked");
1d2e2129 sago007 2015-12-23 15:41 156
	iCheckBoxArea = holder.GetSprite("i_check_box_area");
1d2e2129 sago007 2015-12-23 15:41 157
	boardBackBack = holder.GetSprite("board_back_back");
1d2e2129 sago007 2015-12-23 15:41 158
	garbageTL = holder.GetSprite("garbage_tl");
1d2e2129 sago007 2015-12-23 15:41 159
	garbageT = holder.GetSprite("garbage_t");
1d2e2129 sago007 2015-12-23 15:41 160
	garbageTR = holder.GetSprite("garbage_tr");
1d2e2129 sago007 2015-12-23 15:41 161
	garbageR = holder.GetSprite("garbage_r");
1d2e2129 sago007 2015-12-23 15:41 162
	garbageBR = holder.GetSprite("garbage_br");
1d2e2129 sago007 2015-12-23 15:41 163
	garbageB = holder.GetSprite("garbage_b");
1d2e2129 sago007 2015-12-23 15:41 164
	garbageBL = holder.GetSprite("garbage_bl");
1d2e2129 sago007 2015-12-23 15:41 165
	garbageL = holder.GetSprite("garbage_l");
1d2e2129 sago007 2015-12-23 15:41 166
	garbageFill = holder.GetSprite("garbage_fill");
1d2e2129 sago007 2015-12-23 15:41 167
	garbageML = holder.GetSprite("garbage_ml");
1d2e2129 sago007 2015-12-23 15:41 168
	garbageM = holder.GetSprite("garbage_m");
1d2e2129 sago007 2015-12-23 15:41 169
	garbageMR = holder.GetSprite("garbage_mr");
1d2e2129 sago007 2015-12-23 15:41 170
	garbageGM = holder.GetSprite("garbage_gm");
1d2e2129 sago007 2015-12-23 15:41 171
	garbageGML = holder.GetSprite("garbage_gml");
1d2e2129 sago007 2015-12-23 15:41 172
	garbageGMR = holder.GetSprite("garbage_gmr");
1d2e2129 sago007 2015-12-23 15:41 173
	smiley[0] = holder.GetSprite("smileys0");
1d2e2129 sago007 2015-12-23 15:41 174
	smiley[1] = holder.GetSprite("smileys1");
1d2e2129 sago007 2015-12-23 15:41 175
	smiley[2] = holder.GetSprite("smileys2");
1d2e2129 sago007 2015-12-23 15:41 176
	smiley[3] = holder.GetSprite("smileys3");
1d2e2129 sago007 2015-12-23 15:41 177
	transCover = holder.GetSprite("trans_cover");
38fa9b68 sago007 2016-03-12 08:46 178
	bExit = holder.GetSprite("b_exit");
c7e50476 sago007 2015-12-25 09:44 179
	bSkip = holder.GetSprite("b_blank");
c7e50476 sago007 2015-12-25 09:44 180
	bNext = holder.GetSprite("b_blank");
c7e50476 sago007 2015-12-25 09:44 181
	bRetry = holder.GetSprite("b_blank");
1d2e2129 sago007 2015-12-23 15:41 182
	mouse = holder.GetSprite("mouse");
1d2e2129 sago007 2015-12-23 15:41 183
	menuMarked = holder.GetSprite("menu_marked");
1d2e2129 sago007 2015-12-23 15:41 184
	menuUnmarked = holder.GetSprite("menu_unmarked");
7d1936bd sago007 2015-12-23 16:06 185
	backBoard = holder.GetSprite("back_board");
53203200 sago007 2015-12-25 13:30 186
c53e6443 sago007 2012-04-17 11:04 187
	SDL_Color nf_button_color, nf_standard_blue_color, nf_standard_small_color;
c53e6443 sago007 2012-04-17 11:04 188
	memset(&nf_button_color,0,sizeof(SDL_Color));
c53e6443 sago007 2012-04-17 11:04 189
	nf_button_color.b = 255;
c53e6443 sago007 2012-04-17 11:04 190
	nf_button_color.g = 255;
c53e6443 sago007 2012-04-17 11:04 191
	nf_button_color.r = 255;
3a23aa5e sago007 2015-12-23 18:06 192
	nf_button_color.a = 255;
c53e6443 sago007 2012-04-17 11:04 193
	nf_standard_blue_color.b = 255;
c53e6443 sago007 2012-04-17 11:04 194
	nf_standard_blue_color.g = 0;
c53e6443 sago007 2012-04-17 11:04 195
	nf_standard_blue_color.r = 0;
3a23aa5e sago007 2015-12-23 18:06 196
	nf_standard_blue_color.a = 255;
c53e6443 sago007 2012-04-17 11:04 197
	nf_standard_small_color.b = 0;
c53e6443 sago007 2012-04-17 11:04 198
	nf_standard_small_color.g = 0;
c53e6443 sago007 2012-04-17 11:04 199
	nf_standard_small_color.r = 200;
3a23aa5e sago007 2015-12-23 18:06 200
	nf_standard_small_color.a = 255;
7d1936bd sago007 2015-12-23 16:06 201
	nf_button_font.load(screen, holder.GetDataHolder().getFontPtr("freeserif", 24), nf_button_color);
7d1936bd sago007 2015-12-23 16:06 202
	nf_standard_blue_font.load(screen, holder.GetDataHolder().getFontPtr("freeserif", 30), nf_standard_blue_color);
7d1936bd sago007 2015-12-23 16:06 203
	nf_standard_small_font.load(screen, holder.GetDataHolder().getFontPtr("freeserif", 16), nf_standard_small_color);
7d1936bd sago007 2015-12-23 16:06 204
	nf_scoreboard_font.load(screen, holder.GetDataHolder().getFontPtr("penguinattack", 20), nf_button_color);
c53e6443 sago007 2012-04-17 11:04 205
89c4a3a6 sago007 2008-08-29 14:32 206
//Loads the sound if sound present
ecef5838 sago007 2015-11-24 20:01 207
	if (!NoSound) {
c53e6443 sago007 2012-04-17 11:04 208
		//And here the music:
546803fd sago007 2015-12-23 19:18 209
		bgMusic = holder.GetDataHolder().getMusicPtr("bgmusic");
546803fd sago007 2015-12-23 19:18 210
		highbeatMusic = holder.GetDataHolder().getMusicPtr("highbeat");
c53e6443 sago007 2012-04-17 11:04 211
		//the music... we just hope it exists, else the user won't hear anything
c53e6443 sago007 2012-04-17 11:04 212
		//Same goes for the sounds
546803fd sago007 2015-12-23 19:18 213
		boing = holder.GetDataHolder().getSoundPtr("pop");
546803fd sago007 2015-12-23 19:18 214
		applause = holder.GetDataHolder().getSoundPtr("applause");
546803fd sago007 2015-12-23 19:18 215
		photoClick = holder.GetDataHolder().getSoundPtr("cameraclick");
546803fd sago007 2015-12-23 19:18 216
		typingChunk = holder.GetDataHolder().getSoundPtr("typing");
fd234987 sago007 2015-12-25 09:34 217
		counterChunk = holder.GetDataHolder().getSoundPtr("counter");
546803fd sago007 2015-12-23 19:18 218
		counterFinalChunk = holder.GetDataHolder().getSoundPtr("counter_final");
c53e6443 sago007 2012-04-17 11:04 219
	} //All sound has been loaded or not
c53e6443 sago007 2012-04-17 11:04 220
	return 0;
89c4a3a6 sago007 2008-08-29 14:32 221
} //InitImages()
89c4a3a6 sago007 2008-08-29 14:32 222
89c4a3a6 sago007 2008-08-29 14:32 223
89c4a3a6 sago007 2008-08-29 14:32 224
89c4a3a6 sago007 2008-08-29 14:32 225
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
ce444d3b sago007 2016-04-02 18:59 226
void DrawIMG(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y) {
7d1936bd sago007 2015-12-23 16:06 227
	sprite.Draw(target, SDL_GetTicks() ,x,y);
89c4a3a6 sago007 2008-08-29 14:32 228
}
89c4a3a6 sago007 2008-08-29 14:32 229
ce444d3b sago007 2016-04-02 18:59 230
void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y, int minx, int miny, int maxx, int maxy) {
c6bde3e3 sago007 2015-12-22 16:56 231
	SDL_Rect bounds;
c6bde3e3 sago007 2015-12-22 16:56 232
	bounds.x = minx;
c6bde3e3 sago007 2015-12-22 16:56 233
	bounds.y = miny;
c6bde3e3 sago007 2015-12-22 16:56 234
	bounds.w = maxx-minx;
c6bde3e3 sago007 2015-12-22 16:56 235
	bounds.h = maxy-miny;
7d1936bd sago007 2015-12-23 16:06 236
	sprite.DrawBounded(target, SDL_GetTicks(),x,y,bounds);
89c4a3a6 sago007 2008-08-29 14:32 237
}
89c4a3a6 sago007 2008-08-29 14:32 238
cf54d8c3 sago007 2012-05-03 20:52 239
c3b697c6 sago007 2016-02-07 17:30 240
static void NFont_Write(SDL_Renderer* target, int x, int y, const string& text) {
6332acb6 sago007 2015-12-19 17:51 241
	nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
925b7e58 sago007 2011-04-25 16:35 242
}
925b7e58 sago007 2011-04-25 16:35 243
c3b697c6 sago007 2016-02-07 17:30 244
static void NFont_Write(SDL_Renderer* target, int x, int y, const char* text) {
15b9c93b sago007 2016-02-03 20:03 245
	nf_standard_blue_font.draw(target, x, y, "%s", text);
15b9c93b sago007 2016-02-03 20:03 246
}
15b9c93b sago007 2016-02-03 20:03 247
fee9551a sago007 2016-01-20 19:05 248
SDL_Window* sdlWindow;
fee9551a sago007 2016-01-20 19:05 249
1383de53 sago007 2016-02-21 12:18 250
std::unique_ptr<sago::SagoDataHolder> dataHolder;
1383de53 sago007 2016-02-21 12:18 251
std::unique_ptr<sago::SagoSpriteHolder> spriteHolder;
1383de53 sago007 2016-02-21 12:18 252
ecef5838 sago007 2015-11-24 20:01 253
void ResetFullscreen() {
1383de53 sago007 2016-02-21 12:18 254
	Mix_HaltMusic();  //We need to reload all data in case the screen type changes. Music must be stopped before unload.
fee9551a sago007 2016-01-20 19:05 255
	if (bFullscreen) {
1383de53 sago007 2016-02-21 12:18 256
		SDL_SetWindowFullscreen(sdlWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
335635ec sago007 2016-02-06 13:51 257
	}
fee9551a sago007 2016-01-20 19:05 258
	else {
fee9551a sago007 2016-01-20 19:05 259
		SDL_SetWindowFullscreen(sdlWindow, 0);
fee9551a sago007 2016-01-20 19:05 260
	}
1383de53 sago007 2016-02-21 12:18 261
	dataHolder.reset(new sago::SagoDataHolder(screen));
1383de53 sago007 2016-02-21 12:18 262
	spriteHolder.reset(new sago::SagoSpriteHolder( *(dataHolder.get()) ) );
1383de53 sago007 2016-02-21 12:18 263
	InitImages(*(spriteHolder.get()) );
c53e6443 sago007 2012-04-17 11:04 264
	SDL_ShowCursor(SDL_DISABLE);
78d03b38 sago007 2008-11-13 19:56 265
}
78d03b38 sago007 2008-11-13 19:56 266
78d03b38 sago007 2008-11-13 19:56 267
89c4a3a6 sago007 2008-08-29 14:32 268
//The small things that are faaling when you clear something
d8c1f444 sago007 2016-01-31 11:36 269
class ABall {
89c4a3a6 sago007 2008-08-29 14:32 270
private:
a944c46b sago007 2016-04-02 13:34 271
	double x = 0.0;
a944c46b sago007 2016-04-02 13:34 272
	double y = 0.0;
a944c46b sago007 2016-04-02 13:34 273
	double velocityY = 0.0;
a944c46b sago007 2016-04-02 13:34 274
	double velocityX = 0.0;
a944c46b sago007 2016-04-02 13:34 275
	int color = 0;
a944c46b sago007 2016-04-02 13:34 276
	unsigned long int lastTime = 0;
89c4a3a6 sago007 2008-08-29 14:32 277
public:
89c4a3a6 sago007 2008-08-29 14:32 278
d8c1f444 sago007 2016-01-31 11:36 279
	ABall() {
ecef5838 sago007 2015-11-24 20:01 280
	}
c53e6443 sago007 2012-04-17 11:04 281
c53e6443 sago007 2012-04-17 11:04 282
	//constructor:
d8c1f444 sago007 2016-01-31 11:36 283
	ABall(int X, int Y, bool right, int coulor) {
9d59a0e2 sago007 2013-11-15 23:05 284
		double tal = 1.0+((double)rand()/((double)RAND_MAX));
c53e6443 sago007 2012-04-17 11:04 285
		velocityY = -tal*startVelocityY;
c53e6443 sago007 2012-04-17 11:04 286
		lastTime = currentTime;
c53e6443 sago007 2012-04-17 11:04 287
		x = (double)X;
c53e6443 sago007 2012-04-17 11:04 288
		y = (double)Y;
c53e6443 sago007 2012-04-17 11:04 289
		color = coulor;
ecef5838 sago007 2015-11-24 20:01 290
		if (right) {
c53e6443 sago007 2012-04-17 11:04 291
			velocityX = tal*VelocityX;
acd79baf sago007 2015-11-22 19:37 292
		}
ecef5838 sago007 2015-11-24 20:01 293
		else {
c53e6443 sago007 2012-04-17 11:04 294
			velocityX = -tal*VelocityX;
acd79baf sago007 2015-11-22 19:37 295
		}
c53e6443 sago007 2012-04-17 11:04 296
	}  //constructor
c53e6443 sago007 2012-04-17 11:04 297
ecef5838 sago007 2015-11-24 20:01 298
	void update() {
c53e6443 sago007 2012-04-17 11:04 299
		double timePassed = (((double)(currentTime-lastTime))/1000.0);  //time passed in seconds
c53e6443 sago007 2012-04-17 11:04 300
		x = x+timePassed*velocityX;
c53e6443 sago007 2012-04-17 11:04 301
		y = y+timePassed*velocityY;
c53e6443 sago007 2012-04-17 11:04 302
		velocityY = velocityY + gravity*timePassed;
ecef5838 sago007 2015-11-24 20:01 303
		if (y<1.0) {
c53e6443 sago007 2012-04-17 11:04 304
			velocityY=10.0;
acd79baf sago007 2015-11-22 19:37 305
		}
ecef5838 sago007 2015-11-24 20:01 306
		if ((velocityY>minVelocity) && (y>(double)(768-ballSize)) && (y<768.0)) {
c53e6443 sago007 2012-04-17 11:04 307
			velocityY = -0.70*velocityY;
c53e6443 sago007 2012-04-17 11:04 308
			y = 768.0-ballSize;
c53e6443 sago007 2012-04-17 11:04 309
		}
c53e6443 sago007 2012-04-17 11:04 310
		lastTime = currentTime;
c53e6443 sago007 2012-04-17 11:04 311
	}
c53e6443 sago007 2012-04-17 11:04 312
ecef5838 sago007 2015-11-24 20:01 313
	int getX() {
c53e6443 sago007 2012-04-17 11:04 314
		return (int)x;
c53e6443 sago007 2012-04-17 11:04 315
	}
c53e6443 sago007 2012-04-17 11:04 316
ecef5838 sago007 2015-11-24 20:01 317
	int getY() {
c53e6443 sago007 2012-04-17 11:04 318
		return (int)y;
c53e6443 sago007 2012-04-17 11:04 319
	}
c53e6443 sago007 2012-04-17 11:04 320
ecef5838 sago007 2015-11-24 20:01 321
	int getColor() {
c53e6443 sago007 2012-04-17 11:04 322
		return color;
c53e6443 sago007 2012-04-17 11:04 323
	}
89c4a3a6 sago007 2008-08-29 14:32 324
};  //aBall
89c4a3a6 sago007 2008-08-29 14:32 325
4b0c248f sago007 2010-11-10 21:13 326
static const int maxNumberOfBalls = 6*12*2*2;
89c4a3a6 sago007 2008-08-29 14:32 327
d8c1f444 sago007 2016-01-31 11:36 328
class BallManager {
89c4a3a6 sago007 2008-08-29 14:32 329
public:
d8c1f444 sago007 2016-01-31 11:36 330
	ABall ballArray[maxNumberOfBalls];
c53e6443 sago007 2012-04-17 11:04 331
	bool ballUsed[maxNumberOfBalls];
c53e6443 sago007 2012-04-17 11:04 332
d8c1f444 sago007 2016-01-31 11:36 333
	BallManager() {
ecef5838 sago007 2015-11-24 20:01 334
		for (int i=0; i<maxNumberOfBalls; i++) {
c53e6443 sago007 2012-04-17 11:04 335
			ballUsed[i] = false;
c53e6443 sago007 2012-04-17 11:04 336
		}
c53e6443 sago007 2012-04-17 11:04 337
	}
c53e6443 sago007 2012-04-17 11:04 338
c53e6443 sago007 2012-04-17 11:04 339
	//Adds a ball to the screen at given coordiantes, traveling right or not with color
ecef5838 sago007 2015-11-24 20:01 340
	int addBall(int x, int y,bool right,int color) {
c53e6443 sago007 2012-04-17 11:04 341
		int ballNumber = 0;
c53e6443 sago007 2012-04-17 11:04 342
		//Find a free ball
7c4b468f sago007 2016-03-24 14:42 343
		while (ballNumber<maxNumberOfBalls && ballUsed[ballNumber]) {
c53e6443 sago007 2012-04-17 11:04 344
			ballNumber++;
acd79baf sago007 2015-11-22 19:37 345
		}
c53e6443 sago007 2012-04-17 11:04 346
		//Could not find a free ball, return -1
ecef5838 sago007 2015-11-24 20:01 347
		if (ballNumber==maxNumberOfBalls) {
c53e6443 sago007 2012-04-17 11:04 348
			return -1;
acd79baf sago007 2015-11-22 19:37 349
		}
c53e6443 sago007 2012-04-17 11:04 350
		currentTime = SDL_GetTicks();
d8c1f444 sago007 2016-01-31 11:36 351
		ballArray[ballNumber] = ABall(x,y,right,color);
c53e6443 sago007 2012-04-17 11:04 352
		ballUsed[ballNumber] = true;
c53e6443 sago007 2012-04-17 11:04 353
		return 1;
c53e6443 sago007 2012-04-17 11:04 354
	}  //addBall
c53e6443 sago007 2012-04-17 11:04 355
ecef5838 sago007 2015-11-24 20:01 356
	void update() {
c53e6443 sago007 2012-04-17 11:04 357
		currentTime = SDL_GetTicks();
ecef5838 sago007 2015-11-24 20:01 358
		for (int i = 0; i<maxNumberOfBalls; i++) {
c53e6443 sago007 2012-04-17 11:04 359
ecef5838 sago007 2015-11-24 20:01 360
			if (ballUsed[i]) {
c53e6443 sago007 2012-04-17 11:04 361
				ballArray[i].update();
ecef5838 sago007 2015-11-24 20:01 362
				if (ballArray[i].getY()>800 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize) {
c53e6443 sago007 2012-04-17 11:04 363
					ballUsed[i] = false;
c53e6443 sago007 2012-04-17 11:04 364
				}
c53e6443 sago007 2012-04-17 11:04 365
			}
c53e6443 sago007 2012-04-17 11:04 366
		}
c53e6443 sago007 2012-04-17 11:04 367
	} //update
89c4a3a6 sago007 2008-08-29 14:32 368
89c4a3a6 sago007 2008-08-29 14:32 369
a6b97827 sago007 2016-01-24 11:15 370
}; //theBallManager
89c4a3a6 sago007 2008-08-29 14:32 371
d8c1f444 sago007 2016-01-31 11:36 372
static BallManager theBallManager;
89c4a3a6 sago007 2008-08-29 14:32 373
89c4a3a6 sago007 2008-08-29 14:32 374
//a explosions, non moving
d8c1f444 sago007 2016-01-31 11:36 375
class AnExplosion {
89c4a3a6 sago007 2008-08-29 14:32 376
private:
b651f87a sago007 2016-03-24 20:55 377
	int x = 0;
b651f87a sago007 2016-03-24 20:55 378
	int y = 0;
b651f87a sago007 2016-03-24 20:55 379
	Uint8 frameNumber = 0;
89c4a3a6 sago007 2008-08-29 14:32 380
#define frameLength 80
c53e6443 sago007 2012-04-17 11:04 381
	//How long an image in an animation should be showed
89c4a3a6 sago007 2008-08-29 14:32 382
#define maxFrame 4
c53e6443 sago007 2012-04-17 11:04 383
	//How many images there are in the animation
b651f87a sago007 2016-03-24 20:55 384
	unsigned long int placeTime = 0; //Then the explosion occored
89c4a3a6 sago007 2008-08-29 14:32 385
public:
89c4a3a6 sago007 2008-08-29 14:32 386
d8c1f444 sago007 2016-01-31 11:36 387
	AnExplosion() {
ecef5838 sago007 2015-11-24 20:01 388
	}
c53e6443 sago007 2012-04-17 11:04 389
c53e6443 sago007 2012-04-17 11:04 390
	//constructor:
d8c1f444 sago007 2016-01-31 11:36 391
	AnExplosion(int X, int Y) {
c53e6443 sago007 2012-04-17 11:04 392
		placeTime = currentTime;
c53e6443 sago007 2012-04-17 11:04 393
		x = X;
c53e6443 sago007 2012-04-17 11:04 394
		y = Y;
c53e6443 sago007 2012-04-17 11:04 395
		frameNumber=0;
c53e6443 sago007 2012-04-17 11:04 396
	}  //constructor
c53e6443 sago007 2012-04-17 11:04 397
c53e6443 sago007 2012-04-17 11:04 398
	//true if animation has played and object should be removed from the screen
ecef5838 sago007 2015-11-24 20:01 399
	bool removeMe() {
c53e6443 sago007 2012-04-17 11:04 400
		frameNumber = (currentTime-placeTime)/frameLength;
c53e6443 sago007 2012-04-17 11:04 401
		return (!(frameNumber<maxFrame));
c53e6443 sago007 2012-04-17 11:04 402
	}
c53e6443 sago007 2012-04-17 11:04 403
ecef5838 sago007 2015-11-24 20:01 404
	int getX() {
c53e6443 sago007 2012-04-17 11:04 405
		return (int)x;
c53e6443 sago007 2012-04-17 11:04 406
	}
c53e6443 sago007 2012-04-17 11:04 407
ecef5838 sago007 2015-11-24 20:01 408
	int getY() {
c53e6443 sago007 2012-04-17 11:04 409
		return (int)y;
c53e6443 sago007 2012-04-17 11:04 410
	}
c53e6443 sago007 2012-04-17 11:04 411
ecef5838 sago007 2015-11-24 20:01 412
	int getFrame() {
c53e6443 sago007 2012-04-17 11:04 413
		return frameNumber;
c53e6443 sago007 2012-04-17 11:04 414
	}
89c4a3a6 sago007 2008-08-29 14:32 415
};  //nExplosion
89c4a3a6 sago007 2008-08-29 14:32 416
d8c1f444 sago007 2016-01-31 11:36 417
class ExplosionManager {
89c4a3a6 sago007 2008-08-29 14:32 418
public:
d8c1f444 sago007 2016-01-31 11:36 419
	AnExplosion explosionArray[maxNumberOfBalls];
c53e6443 sago007 2012-04-17 11:04 420
	bool explosionUsed[maxNumberOfBalls];
c53e6443 sago007 2012-04-17 11:04 421
d8c1f444 sago007 2016-01-31 11:36 422
	ExplosionManager() {
ecef5838 sago007 2015-11-24 20:01 423
		for (int i=0; i<maxNumberOfBalls; i++) {
c53e6443 sago007 2012-04-17 11:04 424
			explosionUsed[i] = false;
c53e6443 sago007 2012-04-17 11:04 425
		}
c53e6443 sago007 2012-04-17 11:04 426
	}
c53e6443 sago007 2012-04-17 11:04 427
ecef5838 sago007 2015-11-24 20:01 428
	int addExplosion(int x, int y) {
c53e6443 sago007 2012-04-17 11:04 429
		int explosionNumber = 0;
602d9101 sago007 2016-03-24 14:46 430
		while ( explosionNumber<maxNumberOfBalls && explosionUsed[explosionNumber]) {
c53e6443 sago007 2012-04-17 11:04 431
			explosionNumber++;
acd79baf sago007 2015-11-22 19:37 432
		}
ecef5838 sago007 2015-11-24 20:01 433
		if (explosionNumber==maxNumberOfBalls) {
c53e6443 sago007 2012-04-17 11:04 434
			return -1;
acd79baf sago007 2015-11-22 19:37 435
		}
c53e6443 sago007 2012-04-17 11:04 436
		currentTime = SDL_GetTicks();
d8c1f444 sago007 2016-01-31 11:36 437
		explosionArray[explosionNumber] = AnExplosion(x,y);
c53e6443 sago007 2012-04-17 11:04 438
		explosionUsed[explosionNumber] = true;
c53e6443 sago007 2012-04-17 11:04 439
		return 1;
c53e6443 sago007 2012-04-17 11:04 440
	}  //addBall
c53e6443 sago007 2012-04-17 11:04 441
ecef5838 sago007 2015-11-24 20:01 442
	void update() {
c53e6443 sago007 2012-04-17 11:04 443
		currentTime = SDL_GetTicks();
ecef5838 sago007 2015-11-24 20:01 444
		for (int i = 0; i<maxNumberOfBalls; i++) {
c53e6443 sago007 2012-04-17 11:04 445
ecef5838 sago007 2015-11-24 20:01 446
			if (explosionUsed[i]) {
ecef5838 sago007 2015-11-24 20:01 447
				if (explosionArray[i].removeMe()) {
c53e6443 sago007 2012-04-17 11:04 448
					explosionUsed[i] = false;
c53e6443 sago007 2012-04-17 11:04 449
				}
c53e6443 sago007 2012-04-17 11:04 450
			}
c53e6443 sago007 2012-04-17 11:04 451
		}
c53e6443 sago007 2012-04-17 11:04 452
	} //update
89c4a3a6 sago007 2008-08-29 14:32 453
89c4a3a6 sago007 2008-08-29 14:32 454
a6b97827 sago007 2016-01-24 11:15 455
}; //explosionManager
89c4a3a6 sago007 2008-08-29 14:32 456
d8c1f444 sago007 2016-01-31 11:36 457
static ExplosionManager theExplosionManager;
89c4a3a6 sago007 2008-08-29 14:32 458
89c4a3a6 sago007 2008-08-29 14:32 459
//text pop-up
d8c1f444 sago007 2016-01-31 11:36 460
class TextMessage {
89c4a3a6 sago007 2008-08-29 14:32 461
private:
c98e567e sago007 2016-03-25 09:39 462
	int x = 0;
c98e567e sago007 2016-03-25 09:39 463
	int y = 0;
571b4d47 sago007 2015-12-05 16:02 464
	string textt;
c98e567e sago007 2016-03-25 09:39 465
	unsigned long int time = 0;
c98e567e sago007 2016-03-25 09:39 466
	unsigned long int placeTime = 0; //Then the text was placed
89c4a3a6 sago007 2008-08-29 14:32 467
public:
89c4a3a6 sago007 2008-08-29 14:32 468
d8c1f444 sago007 2016-01-31 11:36 469
	TextMessage() {
ecef5838 sago007 2015-11-24 20:01 470
	}
c53e6443 sago007 2012-04-17 11:04 471
c53e6443 sago007 2012-04-17 11:04 472
	//constructor:
d8c1f444 sago007 2016-01-31 11:36 473
	TextMessage(int X, int Y,const char* Text,unsigned int Time) {
c53e6443 sago007 2012-04-17 11:04 474
		placeTime = currentTime;
c53e6443 sago007 2012-04-17 11:04 475
		x = X;
c53e6443 sago007 2012-04-17 11:04 476
		y = Y;
571b4d47 sago007 2015-12-05 16:02 477
		textt = Text;
c53e6443 sago007 2012-04-17 11:04 478
		time = Time;
c53e6443 sago007 2012-04-17 11:04 479
	}  //constructor
c53e6443 sago007 2012-04-17 11:04 480
c53e6443 sago007 2012-04-17 11:04 481
	//true if the text has expired
ecef5838 sago007 2015-11-24 20:01 482
	bool removeMe() {
c53e6443 sago007 2012-04-17 11:04 483
		return currentTime-placeTime>time;
c53e6443 sago007 2012-04-17 11:04 484
	}
c53e6443 sago007 2012-04-17 11:04 485
ecef5838 sago007 2015-11-24 20:01 486
	int getX() {
c53e6443 sago007 2012-04-17 11:04 487
		return x;
c53e6443 sago007 2012-04-17 11:04 488
	}
c53e6443 sago007 2012-04-17 11:04 489
ecef5838 sago007 2015-11-24 20:01 490
	int getY() {
c53e6443 sago007 2012-04-17 11:04 491
		return y;
c53e6443 sago007 2012-04-17 11:04 492
	}
c53e6443 sago007 2012-04-17 11:04 493
ecef5838 sago007 2015-11-24 20:01 494
	const char* getText() {
571b4d47 sago007 2015-12-05 16:02 495
		return textt.c_str();
c53e6443 sago007 2012-04-17 11:04 496
	}
89c4a3a6 sago007 2008-08-29 14:32 497
};  //text popup
89c4a3a6 sago007 2008-08-29 14:32 498
d8c1f444 sago007 2016-01-31 11:36 499
class TextManager {
89c4a3a6 sago007 2008-08-29 14:32 500
public:
d8c1f444 sago007 2016-01-31 11:36 501
	TextMessage textArray[maxNumberOfBalls];
c53e6443 sago007 2012-04-17 11:04 502
	bool textUsed[maxNumberOfBalls];
c53e6443 sago007 2012-04-17 11:04 503
d8c1f444 sago007 2016-01-31 11:36 504
	TextManager() {
ecef5838 sago007 2015-11-24 20:01 505
		for (int i=0; i<maxNumberOfBalls; i++) {
c53e6443 sago007 2012-04-17 11:04 506
			textUsed[i] = false;
c53e6443 sago007 2012-04-17 11:04 507
		}
c53e6443 sago007 2012-04-17 11:04 508
	}
c53e6443 sago007 2012-04-17 11:04 509
ecef5838 sago007 2015-11-24 20:01 510
	int addText(int x, int y,string Text,unsigned int Time) {
c53e6443 sago007 2012-04-17 11:04 511
		int textNumber = 0;
571b4d47 sago007 2015-12-05 16:02 512
		while (textNumber<maxNumberOfBalls && textUsed[textNumber]) {
c53e6443 sago007 2012-04-17 11:04 513
			textNumber++;
acd79baf sago007 2015-11-22 19:37 514
		}
ecef5838 sago007 2015-11-24 20:01 515
		if (textNumber==maxNumberOfBalls) {
c53e6443 sago007 2012-04-17 11:04 516
			return -1;
acd79baf sago007 2015-11-22 19:37 517
		}
c53e6443 sago007 2012-04-17 11:04 518
		currentTime = SDL_GetTicks();
d8c1f444 sago007 2016-01-31 11:36 519
		textArray[textNumber] = TextMessage(x,y,Text.c_str(),Time);
c53e6443 sago007 2012-04-17 11:04 520
		textUsed[textNumber] = true;
c53e6443 sago007 2012-04-17 11:04 521
		return 1;
c53e6443 sago007 2012-04-17 11:04 522
	}  //addText
c53e6443 sago007 2012-04-17 11:04 523
ecef5838 sago007 2015-11-24 20:01 524
	void update() {
c53e6443 sago007 2012-04-17 11:04 525
		currentTime = SDL_GetTicks();
ecef5838 sago007 2015-11-24 20:01 526
		for (int i = 0; i<maxNumberOfBalls; i++) {
c53e6443 sago007 2012-04-17 11:04 527
ecef5838 sago007 2015-11-24 20:01 528
			if (textUsed[i]) {
ecef5838 sago007 2015-11-24 20:01 529
				if (textArray[i].removeMe()) {
c53e6443 sago007 2012-04-17 11:04 530
					textUsed[i] = false;
c53e6443 sago007 2012-04-17 11:04 531
				}
c53e6443 sago007 2012-04-17 11:04 532
			}
c53e6443 sago007 2012-04-17 11:04 533
		}
c53e6443 sago007 2012-04-17 11:04 534
	} //update
89c4a3a6 sago007 2008-08-29 14:32 535
89c4a3a6 sago007 2008-08-29 14:32 536
a6b97827 sago007 2016-01-24 11:15 537
}; //textManager
89c4a3a6 sago007 2008-08-29 14:32 538
d8c1f444 sago007 2016-01-31 11:36 539
static TextManager theTextManager;
89c4a3a6 sago007 2008-08-29 14:32 540
89c4a3a6 sago007 2008-08-29 14:32 541
//Here comes the Block Game object
89c4a3a6 sago007 2008-08-29 14:32 542
#include "BlockGame.hpp"
9dc80982 sago007 2016-01-02 21:08 543
#include "os.hpp"
c3fc09e9 sago007 2016-01-22 18:31 544
#include "sago/SagoMiscSdl2.hpp"
c3b697c6 sago007 2016-02-07 17:30 545
#include "ScoresDisplay.hpp"
89c4a3a6 sago007 2008-08-29 14:32 546
8b1ab1cb sago007 2016-04-04 17:51 547
#include "BlockGameSdl.inc"
6b1dc7a6 sago007 2010-11-08 21:03 548
6b1dc7a6 sago007 2010-11-08 21:03 549
6b1dc7a6 sago007 2010-11-08 21:03 550
89c4a3a6 sago007 2008-08-29 14:32 551
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
ecef5838 sago007 2015-11-24 20:01 552
void writeScreenShot() {
ecef5838 sago007 2015-11-24 20:01 553
	if (verboseLevel) {
56241205 sago007 2012-08-05 11:15 554
		cout << "Saving screenshot" << endl;
acd79baf sago007 2015-11-22 19:37 555
	}
acd79baf sago007 2015-11-22 19:37 556
	int rightNow = (int)time(nullptr);
9dc80982 sago007 2016-01-02 21:08 557
	string buf = getPathToSaveFiles() + "/screenshots/screenshot"+itoa(rightNow)+".bmp";
335635ec sago007 2016-02-06 13:51 558
	SDL_Surface* sreenshotSurface = SDL_CreateRGBSurface(0, 1024, 768, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
fee9551a sago007 2016-01-20 19:05 559
	SDL_RenderReadPixels(screen, NULL, SDL_PIXELFORMAT_ARGB8888, sreenshotSurface->pixels, sreenshotSurface->pitch);
fee9551a sago007 2016-01-20 19:05 560
	SDL_SaveBMP(sreenshotSurface, buf.c_str());
fee9551a sago007 2016-01-20 19:05 561
	SDL_FreeSurface(sreenshotSurface);
1d2e2129 sago007 2015-12-23 15:41 562
	if (!NoSound) {
acd79baf sago007 2015-11-22 19:37 563
		if (SoundEnabled) {
acd79baf sago007 2015-11-22 19:37 564
			Mix_PlayChannel(1,photoClick,0);
acd79baf sago007 2015-11-22 19:37 565
		}
1d2e2129 sago007 2015-12-23 15:41 566
	}
89c4a3a6 sago007 2008-08-29 14:32 567
}
89c4a3a6 sago007 2008-08-29 14:32 568
89c4a3a6 sago007 2008-08-29 14:32 569
//Function to return the name of a key, to be displayed...
1d2e2129 sago007 2015-12-23 15:41 570
static string getKeyName(SDL_Keycode key) {
c53e6443 sago007 2012-04-17 11:04 571
	string keyname(SDL_GetKeyName(key));
c53e6443 sago007 2012-04-17 11:04 572
	return keyname;
89c4a3a6 sago007 2008-08-29 14:32 573
}
89c4a3a6 sago007 2008-08-29 14:32 574
89c4a3a6 sago007 2008-08-29 14:32 575
58a2d7e1 sago007 2016-02-12 18:53 576
void RunGameState(sago::GameStateInterface& state ) {
c53e6443 sago007 2012-04-17 11:04 577
	int mousex,mousey;
c53e6443 sago007 2012-04-17 11:04 578
	bool done = false;     //We are done!
ecef5838 sago007 2015-11-24 20:01 579
	while (!done && !Config::getInstance()->isShuttingDown()) {
c3b697c6 sago007 2016-02-07 17:30 580
		state.Draw(screen);
58a2d7e1 sago007 2016-02-12 18:53 581
571b4d47 sago007 2015-12-05 16:02 582
		SDL_Delay(1);
c53e6443 sago007 2012-04-17 11:04 583
		SDL_Event event;
c53e6443 sago007 2012-04-17 11:04 584
c53e6443 sago007 2012-04-17 11:04 585
		SDL_GetMouseState(&mousex,&mousey);
fee9551a sago007 2016-01-20 19:05 586
		bool mustWriteScreenshot = false;
58a2d7e1 sago007 2016-02-12 18:53 587
ecef5838 sago007 2015-11-24 20:01 588
		while ( SDL_PollEvent(&event) ) {
ecef5838 sago007 2015-11-24 20:01 589
			if ( event.type == SDL_QUIT ) {
c53e6443 sago007 2012-04-17 11:04 590
				Config::getInstance()->setShuttingDown(5);
c53e6443 sago007 2012-04-17 11:04 591
				done = true;
c53e6443 sago007 2012-04-17 11:04 592
			}
58a2d7e1 sago007 2016-02-12 18:53 593
c3b697c6 sago007 2016-02-07 17:30 594
			if ( event.key.keysym.sym == SDLK_F9 ) {
c3b697c6 sago007 2016-02-07 17:30 595
				mustWriteScreenshot = true;
c53e6443 sago007 2012-04-17 11:04 596
			}
58a2d7e1 sago007 2016-02-12 18:53 597
c3b697c6 sago007 2016-02-07 17:30 598
			bool processed = false;
c3b697c6 sago007 2016-02-07 17:30 599
			state.ProcessInput(event, processed);
58a2d7e1 sago007 2016-02-12 18:53 600
c53e6443 sago007 2012-04-17 11:04 601
		}
58a2d7e1 sago007 2016-02-12 18:53 602
c3b697c6 sago007 2016-02-07 17:30 603
		state.Update();
58a2d7e1 sago007 2016-02-12 18:53 604
1d2e2129 sago007 2015-12-23 15:41 605
		mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
1d2e2129 sago007 2015-12-23 15:41 606
		SDL_RenderPresent(screen);
fee9551a sago007 2016-01-20 19:05 607
		if (mustWriteScreenshot) {
fee9551a sago007 2016-01-20 19:05 608
			writeScreenShot();
fee9551a sago007 2016-01-20 19:05 609
		}
6b1dc7a6 sago007 2010-11-08 21:03 610
c3b697c6 sago007 2016-02-07 17:30 611
		if (!state.IsActive()) {
c3b697c6 sago007 2016-02-07 17:30 612
			done = true;
c3b697c6 sago007 2016-02-07 17:30 613
		}
c3b697c6 sago007 2016-02-07 17:30 614
	}
c3b697c6 sago007 2016-02-07 17:30 615
}
6b1dc7a6 sago007 2010-11-08 21:03 616
c3b697c6 sago007 2016-02-07 17:30 617
void OpenScoresDisplay() {
c3b697c6 sago007 2016-02-07 17:30 618
	ScoresDisplay d;
c3b697c6 sago007 2016-02-07 17:30 619
	d.scoreX = buttonXsize*2;
c3b697c6 sago007 2016-02-07 17:30 620
	d.scoreY = 0;
c3b697c6 sago007 2016-02-07 17:30 621
	d.backX = 20;
c3b697c6 sago007 2016-02-07 17:30 622
	d.backY = ysize-buttonYsize-20;
c3b697c6 sago007 2016-02-07 17:30 623
	d.nextX = xsize-buttonXsize-20;
c3b697c6 sago007 2016-02-07 17:30 624
	d.nextY = d.backY;
c3b697c6 sago007 2016-02-07 17:30 625
	d.xsize = xsize;
c3b697c6 sago007 2016-02-07 17:30 626
	d.ysize = ysize;
c3b697c6 sago007 2016-02-07 17:30 627
	d.buttonXsize = buttonXsize;
c3b697c6 sago007 2016-02-07 17:30 628
	d.buttonYsize = buttonYsize;
c3b697c6 sago007 2016-02-07 17:30 629
	RunGameState(d);
81d9c25d sago007 2008-11-24 09:50 630
}
81d9c25d sago007 2008-11-24 09:50 631
89c4a3a6 sago007 2008-08-29 14:32 632
89c4a3a6 sago007 2008-08-29 14:32 633
//Draws the balls and explosions
ecef5838 sago007 2015-11-24 20:01 634
static void DrawBalls() {
ecef5838 sago007 2015-11-24 20:01 635
	for (int i = 0; i< maxNumberOfBalls; i++) {
a6b97827 sago007 2016-01-24 11:15 636
		if (theBallManager.ballUsed[i]) {
a6b97827 sago007 2016-01-24 11:15 637
			DrawIMG(balls[theBallManager.ballArray[i].getColor()],screen,theBallManager.ballArray[i].getX(),theBallManager.ballArray[i].getY());
c53e6443 sago007 2012-04-17 11:04 638
		} //if used
a6b97827 sago007 2016-01-24 11:15 639
		if (theExplosionManager.explosionUsed[i]) {
a6b97827 sago007 2016-01-24 11:15 640
			DrawIMG(explosion[theExplosionManager.explosionArray[i].getFrame()],screen,theExplosionManager.explosionArray[i].getX(),theExplosionManager.explosionArray[i].getY());
c53e6443 sago007 2012-04-17 11:04 641
		}
a6b97827 sago007 2016-01-24 11:15 642
		if (theTextManager.textUsed[i]) {
a6b97827 sago007 2016-01-24 11:15 643
			int x = theTextManager.textArray[i].getX()-12;
a6b97827 sago007 2016-01-24 11:15 644
			int y = theTextManager.textArray[i].getY()-12;
c1bd83fb sago007 2015-12-23 19:41 645
			DrawIMG(iChainFrame,screen,x,y);
53203200 sago007 2015-12-25 13:30 646
a6b97827 sago007 2016-01-24 11:15 647
			nf_standard_small_font.draw(screen, x+12,y+7, NFont::CENTER, "%s",theTextManager.textArray[i].getText());
c53e6443 sago007 2012-04-17 11:04 648
		}
c53e6443 sago007 2012-04-17 11:04 649
	} //for
89c4a3a6 sago007 2008-08-29 14:32 650
}    //DrawBalls
89c4a3a6 sago007 2008-08-29 14:32 651
89c4a3a6 sago007 2008-08-29 14:32 652
89c4a3a6 sago007 2008-08-29 14:32 653
//draws everything
ecef5838 sago007 2015-11-24 20:01 654
void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* theGame2) {
c53e6443 sago007 2012-04-17 11:04 655
	SDL_ShowCursor(SDL_DISABLE);
c699a9f9 sago007 2015-12-05 17:22 656
	DrawIMG(backgroundImage,screen,0,0);
ae0f6c7a sago007 2015-12-05 16:58 657
	theGame->DoPaintJob();
c699a9f9 sago007 2015-12-05 17:22 658
	theGame2->DoPaintJob();
c53e6443 sago007 2012-04-17 11:04 659
	string strHolder;
c53e6443 sago007 2012-04-17 11:04 660
	strHolder = itoa(theGame->GetScore()+theGame->GetHandicap());
c53e6443 sago007 2012-04-17 11:04 661
	NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
ecef5838 sago007 2015-11-24 20:01 662
	if (theGame->GetAIenabled()) {
c53e6443 sago007 2012-04-17 11:04 663
		NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("AI") );
acd79baf sago007 2015-11-22 19:37 664
	}
ecef5838 sago007 2015-11-24 20:01 665
	else if (editorMode) {
c53e6443 sago007 2012-04-17 11:04 666
		NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("Playing field") );
acd79baf sago007 2015-11-22 19:37 667
	}
ecef5838 sago007 2015-11-24 20:01 668
	else if (!singlePuzzle) {
c53e6443 sago007 2012-04-17 11:04 669
		NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name);
acd79baf sago007 2015-11-22 19:37 670
	}
ecef5838 sago007 2015-11-24 20:01 671
	if (theGame->isTimeTrial()) {
c53e6443 sago007 2012-04-17 11:04 672
		int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
c53e6443 sago007 2012-04-17 11:04 673
		int minutes;
c53e6443 sago007 2012-04-17 11:04 674
		int seconds;
ecef5838 sago007 2015-11-24 20:01 675
		if (tid>=0) {
c53e6443 sago007 2012-04-17 11:04 676
			minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
c53e6443 sago007 2012-04-17 11:04 677
			seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
c53e6443 sago007 2012-04-17 11:04 678
		}
ecef5838 sago007 2015-11-24 20:01 679
		else {
c53e6443 sago007 2012-04-17 11:04 680
			minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
c53e6443 sago007 2012-04-17 11:04 681
			seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
c53e6443 sago007 2012-04-17 11:04 682
		}
acd79baf sago007 2015-11-22 19:37 683
		if (theGame->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 684
			minutes=0;
acd79baf sago007 2015-11-22 19:37 685
		}
acd79baf sago007 2015-11-22 19:37 686
		if (theGame->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 687
			seconds=0;
acd79baf sago007 2015-11-22 19:37 688
		}
ecef5838 sago007 2015-11-24 20:01 689
		if (seconds>9) {
c53e6443 sago007 2012-04-17 11:04 690
			strHolder = itoa(minutes)+":"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 691
		}
acd79baf sago007 2015-11-22 19:37 692
		else {
acd79baf sago007 2015-11-22 19:37 693
			strHolder = itoa(minutes)+":0"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 694
		}
c53e6443 sago007 2012-04-17 11:04 695
		//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 696
		NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
c53e6443 sago007 2012-04-17 11:04 697
	}
ecef5838 sago007 2015-11-24 20:01 698
	else {
c53e6443 sago007 2012-04-17 11:04 699
		int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
c53e6443 sago007 2012-04-17 11:04 700
		int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000;
acd79baf sago007 2015-11-22 19:37 701
		if (theGame->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 702
			minutes=(theGame->GetGameEndedAt()/1000/60)%100;
acd79baf sago007 2015-11-22 19:37 703
		}
acd79baf sago007 2015-11-22 19:37 704
		if (theGame->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 705
			seconds=(theGame->GetGameEndedAt()/1000)%60;
acd79baf sago007 2015-11-22 19:37 706
		}
ecef5838 sago007 2015-11-24 20:01 707
		if (seconds>9) {
c53e6443 sago007 2012-04-17 11:04 708
			strHolder = itoa(minutes)+":"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 709
		}
ecef5838 sago007 2015-11-24 20:01 710
		else {
c53e6443 sago007 2012-04-17 11:04 711
			strHolder = itoa(minutes)+":0"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 712
		}
c53e6443 sago007 2012-04-17 11:04 713
		NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
c53e6443 sago007 2012-04-17 11:04 714
	}
c53e6443 sago007 2012-04-17 11:04 715
	strHolder = itoa(theGame->GetChains());
c53e6443 sago007 2012-04-17 11:04 716
	NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
c53e6443 sago007 2012-04-17 11:04 717
	//drawspeedLevel:
c53e6443 sago007 2012-04-17 11:04 718
	strHolder = itoa(theGame->GetSpeedLevel());
c53e6443 sago007 2012-04-17 11:04 719
	NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
ecef5838 sago007 2015-11-24 20:01 720
	if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY())) {
c53e6443 sago007 2012-04-17 11:04 721
		oldBubleX = theGame->GetTopX()+280;
c53e6443 sago007 2012-04-17 11:04 722
		oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1;
c53e6443 sago007 2012-04-17 11:04 723
		DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
c53e6443 sago007 2012-04-17 11:04 724
	}
c53e6443 sago007 2012-04-17 11:04 725
	//player1 finnish, player2 start
c53e6443 sago007 2012-04-17 11:04 726
	//DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
ecef5838 sago007 2015-11-24 20:01 727
	if (!editorMode) {
c53e6443 sago007 2012-04-17 11:04 728
		/*
c53e6443 sago007 2012-04-17 11:04 729
		 *If single player mode (and not VS)
c53e6443 sago007 2012-04-17 11:04 730
		 */
ecef5838 sago007 2015-11-24 20:01 731
		if (!twoPlayers && !theGame->isGameOver()) {
c53e6443 sago007 2012-04-17 11:04 732
			//Blank player2's board:
c53e6443 sago007 2012-04-17 11:04 733
			DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
c53e6443 sago007 2012-04-17 11:04 734
			//Write a description:
d064f90f sago007 2016-01-26 17:25 735
			string gametypeName;
599a0479 sago007 2016-01-26 17:17 736
			string infostring;
ecef5838 sago007 2015-11-24 20:01 737
			if (theGame->isTimeTrial()) {
d064f90f sago007 2016-01-26 17:25 738
				gametypeName = _("Time Trial");
599a0479 sago007 2016-01-26 17:17 739
				infostring = _("Score as much as possible in 2 minutes");
335635ec sago007 2016-02-06 13:51 740
c53e6443 sago007 2012-04-17 11:04 741
			}
ecef5838 sago007 2015-11-24 20:01 742
			else if (theGame->isStageClear()) {
d064f90f sago007 2016-01-26 17:25 743
				gametypeName = _("Stage Clear");
599a0479 sago007 2016-01-26 17:17 744
				infostring = _("You must clear a number of lines. Speed is rapidly increased.");
c53e6443 sago007 2012-04-17 11:04 745
			}
ecef5838 sago007 2015-11-24 20:01 746
			else if (theGame->isPuzzleMode()) {
d064f90f sago007 2016-01-26 17:25 747
				gametypeName = _("Puzzle");
599a0479 sago007 2016-01-26 17:17 748
				infostring = _("Clear the entire board with a limited number of moves.");
c53e6443 sago007 2012-04-17 11:04 749
			}
ecef5838 sago007 2015-11-24 20:01 750
			else {
d064f90f sago007 2016-01-26 17:25 751
				gametypeName = _("Endless");
599a0479 sago007 2016-01-26 17:17 752
				infostring = _("Score as much as possible. No time limit.");
599a0479 sago007 2016-01-26 17:17 753
			}
599a0479 sago007 2016-01-26 17:17 754
			if (infostring.length() > 0) {
d064f90f sago007 2016-01-26 17:25 755
				NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10, gametypeName);
d064f90f sago007 2016-01-26 17:25 756
				NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160, _("Objective:"));
599a0479 sago007 2016-01-26 17:17 757
				nf_standard_blue_font.drawBox(screen, { static_cast<float>(theGame2->GetTopX()+7),static_cast<float>(theGame2->GetTopY()+160+32), 280, 200}, "%s", infostring.c_str());
c53e6443 sago007 2012-04-17 11:04 758
			}
c53e6443 sago007 2012-04-17 11:04 759
c53e6443 sago007 2012-04-17 11:04 760
			//Write the keys that are in use
c53e6443 sago007 2012-04-17 11:04 761
			int y = theGame2->GetTopY()+400;
c53e6443 sago007 2012-04-17 11:04 762
			NFont_Write(screen, theGame2->GetTopX()+7,y,_("Movement keys:") );
c53e6443 sago007 2012-04-17 11:04 763
			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 764
			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 765
			NFont_Write(screen, theGame2->GetTopX()+7,y+120,( _("Switch: ")+getKeyName(keySettings[0].change) ).c_str() );
ecef5838 sago007 2015-11-24 20:01 766
			if (theGame->isPuzzleMode()) {
c53e6443 sago007 2012-04-17 11:04 767
				NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Restart: ")+getKeyName(keySettings[0].push) ).c_str() );
acd79baf sago007 2015-11-22 19:37 768
			}
ecef5838 sago007 2015-11-24 20:01 769
			else {
c53e6443 sago007 2012-04-17 11:04 770
				NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Push line: ")+getKeyName(keySettings[0].push) ).c_str() );
acd79baf sago007 2015-11-22 19:37 771
			}
335635ec sago007 2016-02-06 13:51 772
c53e6443 sago007 2012-04-17 11:04 773
		}
c53e6443 sago007 2012-04-17 11:04 774
		strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap());
c53e6443 sago007 2012-04-17 11:04 775
		NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
ecef5838 sago007 2015-11-24 20:01 776
		if (theGame2->GetAIenabled()) {
c53e6443 sago007 2012-04-17 11:04 777
			NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,_("AI") );
acd79baf sago007 2015-11-22 19:37 778
		}
ecef5838 sago007 2015-11-24 20:01 779
		else {
c53e6443 sago007 2012-04-17 11:04 780
			NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name);
acd79baf sago007 2015-11-22 19:37 781
		}
ecef5838 sago007 2015-11-24 20:01 782
		if (theGame2->isTimeTrial()) {
c53e6443 sago007 2012-04-17 11:04 783
			int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
c53e6443 sago007 2012-04-17 11:04 784
			int minutes;
c53e6443 sago007 2012-04-17 11:04 785
			int seconds;
ecef5838 sago007 2015-11-24 20:01 786
			if (tid>=0) {
c53e6443 sago007 2012-04-17 11:04 787
				minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
c53e6443 sago007 2012-04-17 11:04 788
				seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
c53e6443 sago007 2012-04-17 11:04 789
			}
ecef5838 sago007 2015-11-24 20:01 790
			else {
c53e6443 sago007 2012-04-17 11:04 791
				minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000;
c53e6443 sago007 2012-04-17 11:04 792
				seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000;
c53e6443 sago007 2012-04-17 11:04 793
			}
acd79baf sago007 2015-11-22 19:37 794
			if (theGame2->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 795
				minutes=0;
acd79baf sago007 2015-11-22 19:37 796
			}
acd79baf sago007 2015-11-22 19:37 797
			if (theGame2->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 798
				seconds=0;
acd79baf sago007 2015-11-22 19:37 799
			}
ecef5838 sago007 2015-11-24 20:01 800
			if (seconds>9) {
c53e6443 sago007 2012-04-17 11:04 801
				strHolder = itoa(minutes)+":"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 802
			}
ecef5838 sago007 2015-11-24 20:01 803
			else {
c53e6443 sago007 2012-04-17 11:04 804
				strHolder = itoa(minutes)+":0"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 805
			}
c53e6443 sago007 2012-04-17 11:04 806
			//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 807
			NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
c53e6443 sago007 2012-04-17 11:04 808
		}
ecef5838 sago007 2015-11-24 20:01 809
		else {
c53e6443 sago007 2012-04-17 11:04 810
			int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000;
c53e6443 sago007 2012-04-17 11:04 811
			int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000;
acd79baf sago007 2015-11-22 19:37 812
			if (theGame2->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 813
				minutes=(theGame2->GetGameEndedAt()/1000/60)%100;
acd79baf sago007 2015-11-22 19:37 814
			}
acd79baf sago007 2015-11-22 19:37 815
			if (theGame2->isGameOver()) {
acd79baf sago007 2015-11-22 19:37 816
				seconds=(theGame2->GetGameEndedAt()/1000)%60;
acd79baf sago007 2015-11-22 19:37 817
			}
ecef5838 sago007 2015-11-24 20:01 818
			if (seconds>9) {
c53e6443 sago007 2012-04-17 11:04 819
				strHolder = itoa(minutes)+":"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 820
			}
ecef5838 sago007 2015-11-24 20:01 821
			else {
c53e6443 sago007 2012-04-17 11:04 822
				strHolder = itoa(minutes)+":0"+itoa(seconds);
acd79baf sago007 2015-11-22 19:37 823
			}
c53e6443 sago007 2012-04-17 11:04 824
			NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
c53e6443 sago007 2012-04-17 11:04 825
		}
c53e6443 sago007 2012-04-17 11:04 826
		strHolder = itoa(theGame2->GetChains());
c53e6443 sago007 2012-04-17 11:04 827
		NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
c53e6443 sago007 2012-04-17 11:04 828
		strHolder = itoa(theGame2->GetSpeedLevel());
c53e6443 sago007 2012-04-17 11:04 829
		NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
38fa9b68 sago007 2016-03-12 08:46 830
		//draw exit
c7f2082f sago007 2016-03-13 11:48 831
		bExit.Draw(screen,SDL_GetTicks(), xsize-bExitOffset, ysize-bExitOffset);
c53e6443 sago007 2012-04-17 11:04 832
	}
c53e6443 sago007 2012-04-17 11:04 833
	//player2 finnish
89c4a3a6 sago007 2008-08-29 14:32 834
89c4a3a6 sago007 2008-08-29 14:32 835
c53e6443 sago007 2012-04-17 11:04 836
	DrawBalls();
89c4a3a6 sago007 2008-08-29 14:32 837
1572de2b sago007 2008-09-11 18:15 838
#if DEBUG
c53e6443 sago007 2012-04-17 11:04 839
	Frames++;
ecef5838 sago007 2015-11-24 20:01 840
	if (SDL_GetTicks() >= Ticks + 1000) {
acd79baf sago007 2015-11-22 19:37 841
		if (Frames > 999) {
acd79baf sago007 2015-11-22 19:37 842
			Frames=999;
acd79baf sago007 2015-11-22 19:37 843
		}
f306e3ca sago007 2015-12-04 21:16 844
		snprintf(FPS, sizeof(FPS), "%lu fps", Frames);
c53e6443 sago007 2012-04-17 11:04 845
		Frames = 0;
c53e6443 sago007 2012-04-17 11:04 846
		Ticks = SDL_GetTicks();
c53e6443 sago007 2012-04-17 11:04 847
	}
c53e6443 sago007 2012-04-17 11:04 848
1d2e2129 sago007 2015-12-23 15:41 849
	nf_standard_blue_font.draw(screen, 800, 4, "%s", FPS);
89c4a3a6 sago007 2008-08-29 14:32 850
#endif
89c4a3a6 sago007 2008-08-29 14:32 851
}
89c4a3a6 sago007 2008-08-29 14:32 852
89c4a3a6 sago007 2008-08-29 14:32 853
//The function that allows the player to choose PuzzleLevel
ecef5838 sago007 2015-11-24 20:01 854
int PuzzleLevelSelect(int Type) {
c53e6443 sago007 2012-04-17 11:04 855
	const int xplace = 200;
c53e6443 sago007 2012-04-17 11:04 856
	const int yplace = 300;
a5a3aa4f sago007 2015-08-23 15:31 857
	int levelNr = 0;
a5a3aa4f sago007 2015-08-23 15:31 858
	int mousex, mousey;
a5a3aa4f sago007 2015-08-23 15:31 859
	int oldmousex = 0;
a5a3aa4f sago007 2015-08-23 15:31 860
	int oldmousey = 0;
c53e6443 sago007 2012-04-17 11:04 861
	bool levelSelected = false;
a5a3aa4f sago007 2015-08-23 15:31 862
	int nrOfLevels = 0;
aede0664 sago007 2012-04-19 19:45 863
	Uint32 totalScore = 0;
aede0664 sago007 2012-04-19 19:45 864
	Uint32 totalTime = 0;
cc6724c9 sago007 2012-04-16 21:11 865
	int selected = 0;
89c4a3a6 sago007 2008-08-29 14:32 866
c53e6443 sago007 2012-04-17 11:04 867
	//Loads the levels, if they havn't been loaded:
ecef5838 sago007 2015-11-24 20:01 868
	if (Type == 0) {
aede0664 sago007 2012-04-19 19:45 869
		LoadPuzzleStages();
acd79baf sago007 2015-11-22 19:37 870
	}
ecef5838 sago007 2015-11-24 20:01 871
	if (Type == 0) {
055218be sago007 2015-08-22 18:44 872
		nrOfLevels = PuzzleGetNumberOfPuzzles();
c53e6443 sago007 2012-04-17 11:04 873
	}
ecef5838 sago007 2015-11-24 20:01 874
	if (Type == 1) {
ae5d6381 sago007 2015-12-29 13:26 875
		LoadStageClearStages();
ae5d6381 sago007 2015-12-29 13:26 876
		totalScore = GetTotalScore();
ae5d6381 sago007 2015-12-29 13:26 877
		totalTime = GetTotalTime();
ae5d6381 sago007 2015-12-29 13:26 878
		nrOfLevels = GetNrOfLevels();
c53e6443 sago007 2012-04-17 11:04 879
	}
c53e6443 sago007 2012-04-17 11:04 880
ecef5838 sago007 2015-11-24 20:01 881
	while (!levelSelected) {
c699a9f9 sago007 2015-12-05 17:22 882
		DrawIMG(backgroundImage, screen, 0, 0);
c53e6443 sago007 2012-04-17 11:04 883
		DrawIMG(iCheckBoxArea,screen,xplace,yplace);
ecef5838 sago007 2015-11-24 20:01 884
		if (Type == 0) {
aede0664 sago007 2012-04-19 19:45 885
			NFont_Write(screen, xplace+12,yplace+2,_("Select Puzzle") );
acd79baf sago007 2015-11-22 19:37 886
		}
ecef5838 sago007 2015-11-24 20:01 887
		if (Type == 1) {
aede0664 sago007 2012-04-19 19:45 888
			NFont_Write(screen, xplace+12,yplace+2, _("Stage Clear Level Select") );
acd79baf sago007 2015-11-22 19:37 889
		}
c53e6443 sago007 2012-04-17 11:04 890
		//Now drow the fields you click in (and a V if clicked):
ecef5838 sago007 2015-11-24 20:01 891
		for (int i = 0; i < nrOfLevels; i++) {
c53e6443 sago007 2012-04-17 11:04 892
			DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
ecef5838 sago007 2015-11-24 20:01 893
			if (i==selected) {
acd79baf sago007 2015-11-22 19:37 894
				DrawIMG(iLevelCheckBoxMarked,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
acd79baf sago007 2015-11-22 19:37 895
			}
acd79baf sago007 2015-11-22 19:37 896
			if (Type == 0 && PuzzleIsCleared(i)) {
acd79baf sago007 2015-11-22 19:37 897
				DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
acd79baf sago007 2015-11-22 19:37 898
			}
ae5d6381 sago007 2015-12-29 13:26 899
			if (Type == 1 && IsStageCleared(i)) {
acd79baf sago007 2015-11-22 19:37 900
				DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
acd79baf sago007 2015-11-22 19:37 901
			}
ed33b751 sago007 2012-04-17 10:48 902
		}
89c4a3a6 sago007 2008-08-29 14:32 903
c53e6443 sago007 2012-04-17 11:04 904
		SDL_Event event;
38c615f9 sago007 2016-01-27 17:26 905
		while ( SDL_PollEvent(&event) ) {
38c615f9 sago007 2016-01-27 17:26 906
			if ( event.type == SDL_QUIT ) {
38c615f9 sago007 2016-01-27 17:26 907
				Config::getInstance()->setShuttingDown(5);
38c615f9 sago007 2016-01-27 17:26 908
				levelNr = -1;
38c615f9 sago007 2016-01-27 17:26 909
				levelSelected = true;
38c615f9 sago007 2016-01-27 17:26 910
			}
8e3fb7e1 sago007 2016-03-13 11:26 911
			if (isEscapeEvent(event)) {
8e3fb7e1 sago007 2016-03-13 11:26 912
				levelNr = -1;
8e3fb7e1 sago007 2016-03-13 11:26 913
				levelSelected = true;
8e3fb7e1 sago007 2016-03-13 11:26 914
			}
8e3fb7e1 sago007 2016-03-13 11:26 915
			if (isConfirmEvent(event)) {
8e3fb7e1 sago007 2016-03-13 11:26 916
				levelNr = selected;
8e3fb7e1 sago007 2016-03-13 11:26 917
				levelSelected = true;
8e3fb7e1 sago007 2016-03-13 11:26 918
			}
8e3fb7e1 sago007 2016-03-13 11:26 919
			if (isRightEvent(event)) {
8e3fb7e1 sago007 2016-03-13 11:26 920
				++selected;
8e3fb7e1 sago007 2016-03-13 11:26 921
				if (selected >= nrOfLevels) {
8e3fb7e1 sago007 2016-03-13 11:26 922
					selected = 0;
c53e6443 sago007 2012-04-17 11:04 923
				}
8e3fb7e1 sago007 2016-03-13 11:26 924
			}
8e3fb7e1 sago007 2016-03-13 11:26 925
			if (isLeftEvent(event)) {
8e3fb7e1 sago007 2016-03-13 11:26 926
				--selected;
8e3fb7e1 sago007 2016-03-13 11:26 927
				if (selected < 0) {
8e3fb7e1 sago007 2016-03-13 11:26 928
					selected = nrOfLevels-1;
c53e6443 sago007 2012-04-17 11:04 929
				}
8e3fb7e1 sago007 2016-03-13 11:26 930
			}
8e3fb7e1 sago007 2016-03-13 11:26 931
			if (isDownEvent(event)) {
8e3fb7e1 sago007 2016-03-13 11:26 932
				selected+=10;
8e3fb7e1 sago007 2016-03-13 11:26 933
				if (selected >= nrOfLevels) {
8e3fb7e1 sago007 2016-03-13 11:26 934
					selected-=10;
c53e6443 sago007 2012-04-17 11:04 935
				}
8e3fb7e1 sago007 2016-03-13 11:26 936
			}
8e3fb7e1 sago007 2016-03-13 11:26 937
			if (isUpEvent(event)) {
8e3fb7e1 sago007 2016-03-13 11:26 938
				selected-=10;
8e3fb7e1 sago007 2016-03-13 11:26 939
				if (selected < 0) {
c53e6443 sago007 2012-04-17 11:04 940
					selected+=10;
c53e6443 sago007 2012-04-17 11:04 941
				}
c53e6443 sago007 2012-04-17 11:04 942
			}
38c615f9 sago007 2016-01-27 17:26 943
		}
c53e6443 sago007 2012-04-17 11:04 944
1d2e2129 sago007 2015-12-23 15:41 945
		SDL_GetKeyboardState(nullptr);
c53e6443 sago007 2012-04-17 11:04 946
c53e6443 sago007 2012-04-17 11:04 947
		SDL_GetMouseState(&mousex,&mousey);
ecef5838 sago007 2015-11-24 20:01 948
		if (mousex != oldmousex || mousey != oldmousey) {
ed33b751 sago007 2012-04-17 10:48 949
			int tmpSelected = -1;
ed33b751 sago007 2012-04-17 10:48 950
			int j;
42f05434 sago007 2012-04-19 20:25 951
			for (j = 0; (tmpSelected == -1) && ( (j<nrOfLevels/10)||((j<nrOfLevels/10+1)&&(nrOfLevels%10 != 0)) ); j++)
ecef5838 sago007 2015-11-24 20:01 952
				if ((60+j*50<mousey-yplace)&&(mousey-yplace<j*50+92)) {
c53e6443 sago007 2012-04-17 11:04 953
					tmpSelected = j*10;
acd79baf sago007 2015-11-22 19:37 954
				}
ed33b751 sago007 2012-04-17 10:48 955
			if (tmpSelected != -1)
42f05434 sago007 2012-04-19 20:25 956
				for (int k = 0; (( (!(nrOfLevels%10) || k<nrOfLevels-10*(j-1)) )&&(k<10)); k++)
ecef5838 sago007 2015-11-24 20:01 957
					if ((10+k*50<mousex-xplace)&&(mousex-xplace<k*50+42)) {
c53e6443 sago007 2012-04-17 11:04 958
						tmpSelected +=k;
c53e6443 sago007 2012-04-17 11:04 959
						selected = tmpSelected;
c53e6443 sago007 2012-04-17 11:04 960
					}
ed33b751 sago007 2012-04-17 10:48 961
		}
ed33b751 sago007 2012-04-17 10:48 962
		oldmousey = mousey;
ed33b751 sago007 2012-04-17 10:48 963
		oldmousex= mousex;
89c4a3a6 sago007 2008-08-29 14:32 964
c53e6443 sago007 2012-04-17 11:04 965
		// If the mouse button is released, make bMouseUp equal true
ecef5838 sago007 2015-11-24 20:01 966
		if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) {
c53e6443 sago007 2012-04-17 11:04 967
			bMouseUp=true;
c53e6443 sago007 2012-04-17 11:04 968
		}
89c4a3a6 sago007 2008-08-29 14:32 969
ecef5838 sago007 2015-11-24 20:01 970
		if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
c53e6443 sago007 2012-04-17 11:04 971
			bMouseUp = false;
c53e6443 sago007 2012-04-17 11:04 972
c53e6443 sago007 2012-04-17 11:04 973
			int levelClicked = -1;
c53e6443 sago007 2012-04-17 11:04 974
			int i;
aede0664 sago007 2012-04-19 19:45 975
			for (i = 0; (i<nrOfLevels/10)||((i<nrOfLevels/10+1)&&(nrOfLevels%10 != 0)); i++)
ecef5838 sago007 2015-11-24 20:01 976
				if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92)) {
c53e6443 sago007 2012-04-17 11:04 977
					levelClicked = i*10;
acd79baf sago007 2015-11-22 19:37 978
				}
c53e6443 sago007 2012-04-17 11:04 979
			i++;
c53e6443 sago007 2012-04-17 11:04 980
			if (levelClicked != -1)
c53e6443 sago007 2012-04-17 11:04 981
				for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
ecef5838 sago007 2015-11-24 20:01 982
					if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42)) {
c53e6443 sago007 2012-04-17 11:04 983
						levelClicked +=j;
c53e6443 sago007 2012-04-17 11:04 984
						levelSelected = true;
c53e6443 sago007 2012-04-17 11:04 985
						levelNr = levelClicked;
c53e6443 sago007 2012-04-17 11:04 986
					}
c53e6443 sago007 2012-04-17 11:04 987
		}
80b830cd sago007 2012-08-19 17:51 988
ecef5838 sago007 2015-11-24 20:01 989
		if (Type == 1) {
96c54803 sago007 2016-02-06 18:34 990
			string scoreString = SPrintStringF(_("Best score: %i"), GetStageScores(selected)) ;
96c54803 sago007 2016-02-06 18:34 991
			string timeString = SPrintStringF(_("Time used: %s"),"-- : --");
58a2d7e1 sago007 2016-02-12 18:53 992
ae5d6381 sago007 2015-12-29 13:26 993
			if (GetStageTime(selected)>0) {
a1072daf sago007 2016-02-20 12:47 994
				timeString = SPrintStringF(_("Time used: %d : %02d"), GetStageTime(selected)/1000/60, (GetStageTime(selected)/1000)%60);
acd79baf sago007 2015-11-22 19:37 995
			}
aede0664 sago007 2012-04-19 19:45 996
aede0664 sago007 2012-04-19 19:45 997
			NFont_Write(screen, 200,200,scoreString.c_str());
aede0664 sago007 2012-04-19 19:45 998
			NFont_Write(screen, 200,250,timeString.c_str());
a1072daf sago007 2016-02-20 12:47 999
			string totalString = (boost::format(_("Total score: %1% in %2%:%3%"))%totalScore%(totalTime/1000/60)%((totalTime/1000)%60)).str();
aede0664 sago007 2012-04-19 19:45 1000
			NFont_Write(screen, 200,600,totalString.c_str());
aede0664 sago007 2012-04-19 19:45 1001
		}
89c4a3a6 sago007 2008-08-29 14:32 1002
1d2e2129 sago007 2015-12-23 15:41 1003
		mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
1d2e2129 sago007 2015-12-23 15:41 1004
		SDL_RenderPresent(screen); //draws it all to the screen
89c4a3a6 sago007 2008-08-29 14:32 1005
c53e6443 sago007 2012-04-17 11:04 1006
	}
c699a9f9 sago007 2015-12-05 17:22 1007
	DrawIMG(backgroundImage, screen, 0, 0);
c53e6443 sago007 2012-04-17 11:04 1008
	return levelNr;
89c4a3a6 sago007 2008-08-29 14:32 1009
}
89c4a3a6 sago007 2008-08-29 14:32 1010
ecef5838 sago007 2015-11-24 20:01 1011
static BlockGameSdl* player1;
ecef5838 sago007 2015-11-24 20:01 1012
static BlockGameSdl* player2;
30f910dd sago007 2010-11-10 21:02 1013
dfdb7d66 sago007 2015-11-29 19:21 1014
static bool registerEndlessHighscore = false;
dfdb7d66 sago007 2015-11-29 19:21 1015
static bool registerTTHighscorePlayer1 = false;
dfdb7d66 sago007 2015-11-29 19:21 1016
static bool registerTTHighscorePlayer2 = false;
dfdb7d66 sago007 2015-11-29 19:21 1017
ecef5838 sago007 2015-11-24 20:01 1018
static void StartSinglePlayerEndless() {
c53e6443 sago007 2012-04-17 11:04 1019
	//1 player - endless
5159dd90 sago007 2016-02-21 15:50 1020
	BlockGameStartInfo startInfo;
5159dd90 sago007 2016-02-21 15:50 1021
	startInfo.ticks = SDL_GetTicks();
917dac61 sago007 2016-02-21 20:01 1022
	startInfo.startBlocks = startInfo.ticks;
5159dd90 sago007 2016-02-21 15:50 1023
	player1->NewGame(startInfo);
c53e6443 sago007 2012-04-17 11:04 1024
	twoPlayers =false;
c53e6443 sago007 2012-04-17 11:04 1025
	player2->SetGameOver();
8f632c05 sago007 2015-08-22 16:21 1026
	player1->name = player1name;
8f632c05 sago007 2015-08-22 16:21 1027
	player2->name = player2name;
dfdb7d66 sago007 2015-11-29 19:21 1028
	registerEndlessHighscore = true;
30f910dd sago007 2010-11-10 21:02 1029
}
30f910dd sago007 2010-11-10 21:02 1030
ecef5838 sago007 2015-11-24 20:01 1031
static void StartSinglePlayerTimeTrial() {
5159dd90 sago007 2016-02-21 15:50 1032
	BlockGameStartInfo startInfo;
5159dd90 sago007 2016-02-21 15:50 1033
	startInfo.ticks = SDL_GetTicks();
5159dd90 sago007 2016-02-21 15:50 1034
	startInfo.timeTrial = true;
5159dd90 sago007 2016-02-21 15:50 1035
	player1->NewGame(startInfo);
c53e6443 sago007 2012-04-17 11:04 1036
	twoPlayers =false;
c53e6443 sago007 2012-04-17 11:04 1037
	player2->SetGameOver();
c53e6443 sago007 2012-04-17 11:04 1038
	//vsMode = false;
8f632c05 sago007 2015-08-22 16:21 1039
	player1->name = player1name;
8f632c05 sago007 2015-08-22 16:21 1040
	player2->name = player2name;
dfdb7d66 sago007 2015-11-29 19:21 1041
	registerTTHighscorePlayer1 = true;
4f1d27f1 sago007 2011-03-18 15:53 1042
}
4f1d27f1 sago007 2011-03-18 15:53 1043
ecef5838 sago007 2015-11-24 20:01 1044
static int StartSinglePlayerPuzzle(int level) {
b256fda5 sago007 2016-02-21 16:21 1045
	BlockGameStartInfo startInfo;
b256fda5 sago007 2016-02-21 16:21 1046
	startInfo.ticks = SDL_GetTicks();
b256fda5 sago007 2016-02-21 16:21 1047
	startInfo.puzzleMode = true;
b256fda5 sago007 2016-02-21 16:21 1048
	startInfo.level = PuzzleLevelSelect(0);
b256fda5 sago007 2016-02-21 16:21 1049
	if (startInfo.level == -1) {
67a32395 sago007 2012-04-19 18:40 1050
		return 1;
acd79baf sago007 2015-11-22 19:37 1051
	}
b256fda5 sago007 2016-02-21 16:21 1052
	player1->NewGame(startInfo);
c699a9f9 sago007 2015-12-05 17:22 1053
	DrawIMG(backgroundImage, screen, 0, 0);
c53e6443 sago007 2012-04-17 11:04 1054
	twoPlayers = false;
c53e6443 sago007 2012-04-17 11:04 1055
	player2->SetGameOver();
c53e6443 sago007 2012-04-17 11:04 1056
	//vsMode = true;
8f632c05 sago007 2015-08-22 16:21 1057
	player1->name = player1name;
8f632c05 sago007 2015-08-22 16:21 1058
	player2->name = player2name;
67a32395 sago007 2012-04-19 18:40 1059
	return 0;
b7590374 sago007 2011-05-19 16:15 1060
}
b7590374 sago007 2011-05-19 16:15 1061
4f1d27f1 sago007 2011-03-18 15:53 1062
ecef5838 sago007 2015-11-24 20:01 1063
static void StarTwoPlayerTimeTrial() {
5159dd90 sago007 2016-02-21 15:50 1064
	BlockGameStartInfo startInfo;
5159dd90 sago007 2016-02-21 15:50 1065
	startInfo.ticks = SDL_GetTicks();
5159dd90 sago007 2016-02-21 15:50 1066
	startInfo.timeTrial = true;
6d6b2788 sago007 2016-02-21 18:51 1067
	BlockGameStartInfo startInfo2 = startInfo;
dfdb7d66 sago007 2015-11-29 19:21 1068
	registerTTHighscorePlayer1 = true;
dfdb7d66 sago007 2015-11-29 19:21 1069
	registerTTHighscorePlayer2 = true;
ecef5838 sago007 2015-11-24 20:01 1070
	if (player1AI) {
6d6b2788 sago007 2016-02-21 18:51 1071
		startInfo.AI = true;
6d6b2788 sago007 2016-02-21 18:51 1072
		startInfo.level = player1AIlevel;
dfdb7d66 sago007 2015-11-29 19:21 1073
		registerTTHighscorePlayer1 = false;
acd79baf sago007 2015-11-22 19:37 1074
	}
ecef5838 sago007 2015-11-24 20:01 1075
	if (player2AI) {
6d6b2788 sago007 2016-02-21 18:51 1076
		startInfo2.AI = true;
6d6b2788 sago007 2016-02-21 18:51 1077
		startInfo2.level = player2AIlevel;
dfdb7d66 sago007 2015-11-29 19:21 1078
		registerTTHighscorePlayer2 = false;
acd79baf sago007 2015-11-22 19:37 1079
	}
3e7b8813 sago007 2016-02-22 19:45 1080
	startInfo.gameSpeed = player1Speed;
3e7b8813 sago007 2016-02-22 19:45 1081
	startInfo2.gameSpeed = player2Speed;
3e7b8813 sago007 2016-02-22 19:45 1082
	startInfo.handicap = player1handicap;
3e7b8813 sago007 2016-02-22 19:45 1083
	startInfo2.handicap = player2handicap;
6d6b2788 sago007 2016-02-21 18:51 1084
	player1->NewGame(startInfo);
6d6b2788 sago007 2016-02-21 18:51 1085
	player2->NewGame(startInfo2);
6d6b2788 sago007 2016-02-21 18:51 1086
	twoPlayers = true;
8f632c05 sago007 2015-08-22 16:21 1087
	player1->name = player1name;
8f632c05 sago007 2015-08-22 16:21 1088
	player2->name = player2name;
4f1d27f1 sago007 2011-03-18 15:53 1089
}
4f1d27f1 sago007 2011-03-18 15:53 1090
ecef5838 sago007 2015-11-24 20:01 1091
static void StartTwoPlayerVs() {
c53e6443 sago007 2012-04-17 11:04 1092
	//2 player - VsMode
1e5aff60 sago007 2016-02-21 18:23 1093
	BlockGameStartInfo startInfo;
1e5aff60 sago007 2016-02-21 18:23 1094
	startInfo.ticks = SDL_GetTicks();
1e5aff60 sago007 2016-02-21 18:23 1095
	startInfo.vsMode = true;
917dac61 sago007 2016-02-21 20:01 1096
	startInfo.startBlocks = startInfo.ticks;
6d6b2788 sago007 2016-02-21 18:51 1097
	BlockGameStartInfo startInfo2 = startInfo;
6d6b2788 sago007 2016-02-21 18:51 1098
	if (player1AI) {
6d6b2788 sago007 2016-02-21 18:51 1099
		startInfo.AI = true;
6d6b2788 sago007 2016-02-21 18:51 1100
		startInfo.level = player1AIlevel;
6d6b2788 sago007 2016-02-21 18:51 1101
	}
6d6b2788 sago007 2016-02-21 18:51 1102
	if (player2AI) {
6d6b2788 sago007 2016-02-21 18:51 1103
		startInfo2.AI = true;
6d6b2788 sago007 2016-02-21 18:51 1104
		startInfo2.level = player2AIlevel;
6d6b2788 sago007 2016-02-21 18:51 1105
	}
3e7b8813 sago007 2016-02-22 19:45 1106
	startInfo.gameSpeed = player1Speed;
3e7b8813 sago007 2016-02-22 19:45 1107
	startInfo2.gameSpeed = player2Speed;
3e7b8813 sago007 2016-02-22 19:45 1108
	startInfo.handicap = player1handicap;
3e7b8813 sago007 2016-02-22 19:45 1109
	startInfo2.handicap = player2handicap;
1e5aff60 sago007 2016-02-21 18:23 1110
	player1->NewGame(startInfo);
6d6b2788 sago007 2016-02-21 18:51 1111
	player2->NewGame(startInfo2);
c53e6443 sago007 2012-04-17 11:04 1112
	//vsMode = true;
c53e6443 sago007 2012-04-17 11:04 1113
	twoPlayers = true;
8f632c05 sago007 2015-08-22 16:21 1114
	player1->name = player1name;
8f632c05 sago007 2015-08-22 16:21 1115
	player2->name = player2name;
4f1d27f1 sago007 2011-03-18 15:53 1116
}
4f1d27f1 sago007 2011-03-18 15:53 1117
f31fade1 sago007 2016-02-06 21:37 1118
//Warning: the arguments to main must be "int argc, char* argv[]" NO CONST! or SDL_main will fail to find it
f31fade1 sago007 2016-02-06 21:37 1119
int main(int argc, char* argv[]) {
c3fc09e9 sago007 2016-01-22 18:31 1120
	try {
335635ec sago007 2016-02-06 13:51 1121
		//Init the file system abstraction layer
335635ec sago007 2016-02-06 13:51 1122
		PHYSFS_init(argv[0]);
335635ec sago007 2016-02-06 13:51 1123
		vector<string> search_paths;
335635ec sago007 2016-02-06 13:51 1124
		FsSearchParthMainAppend(search_paths);
335635ec sago007 2016-02-06 13:51 1125
		string savepath = getPathToSaveFiles();
335635ec sago007 2016-02-06 13:51 1126
		highPriority = false;   //if true the game will take most resources, but increase framerate.
335635ec sago007 2016-02-06 13:51 1127
		bFullscreen = false;
335635ec sago007 2016-02-06 13:51 1128
		//Set default Config variables:
335635ec sago007 2016-02-06 13:51 1129
		setlocale (LC_ALL, "");
335635ec sago007 2016-02-06 13:51 1130
		bindtextdomain (PACKAGE, LOCALEDIR);
5f870c10 sago007 2016-02-07 09:38 1131
		bind_textdomain_codeset(PACKAGE, "utf-8");
335635ec sago007 2016-02-06 13:51 1132
		textdomain (PACKAGE);
ba2898e9 sago007 2016-03-15 20:09 1133
		int consoleWidth = boost::program_options::options_description::m_default_line_length;
ba2898e9 sago007 2016-03-15 20:09 1134
		const char* columnsEnv = getenv("COLUMNS"); // Allows using this: COLUMNS=300 help2man
ba2898e9 sago007 2016-03-15 20:09 1135
		if (columnsEnv) {
ba2898e9 sago007 2016-03-15 20:09 1136
			consoleWidth = atoi(columnsEnv);
ba2898e9 sago007 2016-03-15 20:09 1137
		}
ba2898e9 sago007 2016-03-15 20:09 1138
		const char* commandname = "blockattack";
ba2898e9 sago007 2016-03-15 20:09 1139
		if (argv[0]) {
ba2898e9 sago007 2016-03-15 20:09 1140
			//NULL on Windows
ba2898e9 sago007 2016-03-15 20:09 1141
			commandname = argv[0];
ba2898e9 sago007 2016-03-15 20:09 1142
		}
8dc4a9d6 sago007 2016-03-16 19:02 1143
		boost::program_options::options_description desc("Options", consoleWidth);
335635ec sago007 2016-02-06 13:51 1144
		desc.add_options()
7441aba7 sago007 2016-02-06 15:17 1145
		("help,h", "Displays this message")
ba2898e9 sago007 2016-03-15 20:09 1146
		("version", "Display the version information")
7441aba7 sago007 2016-02-06 15:17 1147
		("nosound", "Disables the sound. Can be used if sound errors prevents you from starting")
7441aba7 sago007 2016-02-06 15:17 1148
		("priority", "Causes the game to not sleep between frames.")
7441aba7 sago007 2016-02-06 15:17 1149
		("verbose-basic", "Enables basic verbose messages")
2cb68251 sago007 2016-03-14 18:01 1150
		("verbose-game-controller", "Enables verbose messages regarding controllers")
7441aba7 sago007 2016-02-06 15:17 1151
		("print-search-path", "Prints the search path and quits")
db454a2d sago007 2016-02-11 18:03 1152
		("bind-text-domain", boost::program_options::value<string>(), SPrintStringF("Overwrites the bind text domain used for finding translations. "
58a2d7e1 sago007 2016-02-12 18:53 1153
		        "Default: \"%s\"", LOCALEDIR).c_str())
db454a2d sago007 2016-02-11 18:03 1154
		("homepath", boost::program_options::value<string>(), SPrintStringF("Set the home folder where settings are saved. The directory must exsist."
58a2d7e1 sago007 2016-02-12 18:53 1155
		        " Default: \"%s\"", getPathToSaveFiles().c_str()).c_str())
58a2d7e1 sago007 2016-02-12 18:53 1156
335635ec sago007 2016-02-06 13:51 1157
		;
335635ec sago007 2016-02-06 13:51 1158
		boost::program_options::variables_map vm;
335635ec sago007 2016-02-06 13:51 1159
		try {
335635ec sago007 2016-02-06 13:51 1160
			boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
335635ec sago007 2016-02-06 13:51 1161
			boost::program_options::notify(vm);
335635ec sago007 2016-02-06 13:51 1162
		}
335635ec sago007 2016-02-06 13:51 1163
		catch (exception& e) {
335635ec sago007 2016-02-06 13:51 1164
			cerr << e.what() << endl;
335635ec sago007 2016-02-06 13:51 1165
			cerr << desc << endl;
335635ec sago007 2016-02-06 13:51 1166
			throw;
335635ec sago007 2016-02-06 13:51 1167
		}
7441aba7 sago007 2016-02-06 15:17 1168
		if (vm.count("bind-text-domain")) {
7441aba7 sago007 2016-02-06 15:17 1169
			string s = vm["bind-text-domain"].as<string>();
7441aba7 sago007 2016-02-06 15:17 1170
			bindtextdomain (PACKAGE, s.c_str());
7441aba7 sago007 2016-02-06 15:17 1171
		}
db454a2d sago007 2016-02-11 18:03 1172
		if (vm.count("homepath")) {
db454a2d sago007 2016-02-11 18:03 1173
			string s = vm["homepath"].as<string>();
db454a2d sago007 2016-02-11 18:03 1174
			setPathToSaveFiles(s);
db454a2d sago007 2016-02-11 18:03 1175
			savepath = getPathToSaveFiles();
db454a2d sago007 2016-02-11 18:03 1176
		}
335635ec sago007 2016-02-06 13:51 1177
		if (vm.count("help")) {
ba2898e9 sago007 2016-03-15 20:09 1178
			cout << SPrintStringF("Block Attack - Rise of the blocks %s\n\n"
a35ab74b sago007 2016-04-02 10:26 1179
			                      "Block Attack - Rise of the Blocks is a puzzle/blockfall game inspired by Tetris Attack for the SNES.\n\n"
ba2898e9 sago007 2016-03-15 20:09 1180
			                      "%s\n\n", VERSION_NUMBER, "www.blockattack.net");
ba2898e9 sago007 2016-03-15 20:09 1181
			cout << "Usage: "<< commandname << " [OPTION]..." << endl;
335635ec sago007 2016-02-06 13:51 1182
			cout << desc << endl;
ba2898e9 sago007 2016-03-15 20:09 1183
			cout << "Examples:" << endl;
8dc4a9d6 sago007 2016-03-16 19:02 1184
			cout << "\tblockattack          \tStart the game normally" << endl;
ba2898e9 sago007 2016-03-15 20:09 1185
			cout << "\tblockattack --nosound\tStart the game without sound. Can be used if sound problems prevents the game from starting" << endl;
8dc4a9d6 sago007 2016-03-16 19:02 1186
			cout << endl;
8dc4a9d6 sago007 2016-03-16 19:02 1187
			cout << "Report bugs to the issue tracker here: <https://github.com/blockattack/blockattack-game/issues>" << endl;
ba2898e9 sago007 2016-03-15 20:09 1188
			return 0;
ba2898e9 sago007 2016-03-15 20:09 1189
		}
ba2898e9 sago007 2016-03-15 20:09 1190
		if (vm.count("version")) {
8dc4a9d6 sago007 2016-03-16 19:02 1191
			cout << "blockattack " << VERSION_NUMBER << endl;
8dc4a9d6 sago007 2016-03-16 19:02 1192
			cout << endl;
ba2898e9 sago007 2016-03-15 20:09 1193
			cout << "Copyright (C) 2005-2016 Poul Sander" << endl;
8dc4a9d6 sago007 2016-03-16 19:02 1194
			cout << "License GPLv2+: GNU GPL version 2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> or later <http://gnu.org/licenses/gpl.html>" << endl;
ba2898e9 sago007 2016-03-15 20:09 1195
			cout << "This is free software: you are free to change and redistribute it." << endl;
ba2898e9 sago007 2016-03-15 20:09 1196
			cout << "There is NO WARRANTY, to the extent permitted by law." << endl;
ba2898e9 sago007 2016-03-15 20:09 1197
			return 0;
335635ec sago007 2016-02-06 13:51 1198
		}
335635ec sago007 2016-02-06 13:51 1199
		if (vm.count("nosound")) {
335635ec sago007 2016-02-06 13:51 1200
			NoSound = true;
335635ec sago007 2016-02-06 13:51 1201
		}
335635ec sago007 2016-02-06 13:51 1202
		if (vm.count("priority")) {
335635ec sago007 2016-02-06 13:51 1203
			highPriority = true;
335635ec sago007 2016-02-06 13:51 1204
		}
335635ec sago007 2016-02-06 13:51 1205
		if (vm.count("verbose-basic")) {
335635ec sago007 2016-02-06 13:51 1206
			verboseLevel++;
335635ec sago007 2016-02-06 13:51 1207
		}
2cb68251 sago007 2016-03-14 18:01 1208
		if (vm.count("verbose-game-controller")) {
2cb68251 sago007 2016-03-14 18:01 1209
			GameControllerSetVerbose(true);
2cb68251 sago007 2016-03-14 18:01 1210
		}
335635ec sago007 2016-02-06 13:51 1211
		if (vm.count("print-search-path")) {
335635ec sago007 2016-02-06 13:51 1212
			for (const string& s : search_paths) {
335635ec sago007 2016-02-06 13:51 1213
				cout << s << endl;
335635ec sago007 2016-02-06 13:51 1214
			}
335635ec sago007 2016-02-06 13:51 1215
			cout << savepath << endl;
335635ec sago007 2016-02-06 13:51 1216
			return 0;
8c45a7b1 sago007 2016-02-05 21:39 1217
		}
77531130 Poul Sander 2016-02-17 18:42 1218
		OsCreateSaveFolder();
59dcb571 sago007 2016-02-14 15:34 1219
		PhysFsSetSearchPath(search_paths, savepath);
58a2d7e1 sago007 2016-02-12 18:53 1220
		//Os create folders must be after the paramters because they can change the home folder
cd724e02 sago007 2016-02-13 16:04 1221
		PhysFsCreateFolders();
c53e6443 sago007 2012-04-17 11:04 1222
335635ec sago007 2016-02-06 13:51 1223
		SoundEnabled = true;
335635ec sago007 2016-02-06 13:51 1224
		MusicEnabled = true;
335635ec sago007 2016-02-06 13:51 1225
		twoPlayers = false; //true if two players splitscreen
7a956470 sago007 2016-02-14 17:09 1226
		theTopScoresEndless = Highscore("endless");
7a956470 sago007 2016-02-14 17:09 1227
		theTopScoresTimeTrial = Highscore("timetrial");
335635ec sago007 2016-02-06 13:51 1228
		drawBalls = true;
335635ec sago007 2016-02-06 13:51 1229
		puzzleLoaded = false;
c53e6443 sago007 2012-04-17 11:04 1230
335635ec sago007 2016-02-06 13:51 1231
		theBallManager = BallManager();
335635ec sago007 2016-02-06 13:51 1232
		theExplosionManager = ExplosionManager();
89c4a3a6 sago007 2008-08-29 14:32 1233
335635ec sago007 2016-02-06 13:51 1234
		PuzzleSetName("puzzle.levels");
89c4a3a6 sago007 2008-08-29 14:32 1235
335635ec sago007 2016-02-06 13:51 1236
		//Init SDL
335635ec sago007 2016-02-06 13:51 1237
		if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
335635ec sago007 2016-02-06 13:51 1238
			sago::SagoFatalErrorF("Unable to init SDL: %s", SDL_GetError());
335635ec sago007 2016-02-06 13:51 1239
		}
d0c62e33 sago007 2016-04-02 15:18 1240
		if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER ) != 0) {
826cf176 sago007 2016-03-12 10:53 1241
			cerr << "Warning: Game controller failed to initialize. Reason: " << SDL_GetError() << endl;
c7f2082f sago007 2016-03-13 11:48 1242
		}
826cf176 sago007 2016-03-12 10:53 1243
		InitGameControllers();
335635ec sago007 2016-02-06 13:51 1244
		TTF_Init();
335635ec sago007 2016-02-06 13:51 1245
		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 1246
d0c62e33 sago007 2016-04-02 15:18 1247
		//SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
89c4a3a6 sago007 2008-08-29 14:32 1248
335635ec sago007 2016-02-06 13:51 1249
		theTextManager = TextManager();
89c4a3a6 sago007 2008-08-29 14:32 1250
335635ec sago007 2016-02-06 13:51 1251
		//Open Audio
335635ec sago007 2016-02-06 13:51 1252
		if (!NoSound) {
335635ec sago007 2016-02-06 13:51 1253
			//If sound has not been disabled, then load the sound system
335635ec sago007 2016-02-06 13:51 1254
			if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0) {
335635ec sago007 2016-02-06 13:51 1255
				cerr << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
335635ec sago007 2016-02-06 13:51 1256
				     << "Sound will be disabled!" << endl;
335635ec sago007 2016-02-06 13:51 1257
				NoSound = true; //Tries to stop all sound from playing/loading
335635ec sago007 2016-02-06 13:51 1258
			}
c53e6443 sago007 2012-04-17 11:04 1259
		}
c53e6443 sago007 2012-04-17 11:04 1260
89c4a3a6 sago007 2008-08-29 14:32 1261
335635ec sago007 2016-02-06 13:51 1262
		if (verboseLevel) {
335635ec sago007 2016-02-06 13:51 1263
			//Copyright notice:
335635ec sago007 2016-02-06 13:51 1264
			cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << endl << "http://www.blockattack.net" << endl << "Copyright 2004-2016 Poul Sander" << endl <<
335635ec sago007 2016-02-06 13:51 1265
			     "A SDL2 based game (see www.libsdl.org)" << endl <<
59dcb571 sago007 2016-02-14 15:34 1266
			     "The game is availeble under the GPL, see COPYING for details." << endl;
335635ec sago007 2016-02-06 13:51 1267
			cout << "-------------------------------------------" << endl;
335635ec sago007 2016-02-06 13:51 1268
		}
335635ec sago007 2016-02-06 13:51 1269
335635ec sago007 2016-02-06 13:51 1270
335635ec sago007 2016-02-06 13:51 1271
		keySettings[0].up= SDLK_UP;
335635ec sago007 2016-02-06 13:51 1272
		keySettings[0].down = SDLK_DOWN;
335635ec sago007 2016-02-06 13:51 1273
		keySettings[0].left = SDLK_LEFT;
335635ec sago007 2016-02-06 13:51 1274
		keySettings[0].right = SDLK_RIGHT;
335635ec sago007 2016-02-06 13:51 1275
		keySettings[0].change = SDLK_RCTRL;
335635ec sago007 2016-02-06 13:51 1276
		keySettings[0].push = SDLK_RSHIFT;
335635ec sago007 2016-02-06 13:51 1277
335635ec sago007 2016-02-06 13:51 1278
		keySettings[2].up= SDLK_w;
335635ec sago007 2016-02-06 13:51 1279
		keySettings[2].down = SDLK_s;
335635ec sago007 2016-02-06 13:51 1280
		keySettings[2].left = SDLK_a;
335635ec sago007 2016-02-06 13:51 1281
		keySettings[2].right = SDLK_d;
335635ec sago007 2016-02-06 13:51 1282
		keySettings[2].change = SDLK_LCTRL;
335635ec sago007 2016-02-06 13:51 1283
		keySettings[2].push = SDLK_LSHIFT;
335635ec sago007 2016-02-06 13:51 1284
335635ec sago007 2016-02-06 13:51 1285
		player1keys=0;
335635ec sago007 2016-02-06 13:51 1286
		player2keys=2;
335635ec sago007 2016-02-06 13:51 1287
96c54803 sago007 2016-02-06 18:34 1288
		player1name = _("Player 1");
96c54803 sago007 2016-02-06 18:34 1289
		player2name = _("Player 2");
335635ec sago007 2016-02-06 13:51 1290
335635ec sago007 2016-02-06 13:51 1291
		Config* configSettings = Config::getInstance();
335635ec sago007 2016-02-06 13:51 1292
		//configSettings->setString("aNumber"," A string");
335635ec sago007 2016-02-06 13:51 1293
		//configSettings->save();
335635ec sago007 2016-02-06 13:51 1294
		if (configSettings->exists("fullscreen")) { //Test if an configFile exists
335635ec sago007 2016-02-06 13:51 1295
			bFullscreen = (bool)configSettings->getInt("fullscreen");
335635ec sago007 2016-02-06 13:51 1296
			MusicEnabled = (bool)configSettings->getInt("musicenabled");
335635ec sago007 2016-02-06 13:51 1297
			SoundEnabled = (bool)configSettings->getInt("soundenabled");
335635ec sago007 2016-02-06 13:51 1298
			mouseplay1 = (bool)configSettings->getInt("mouseplay1");
335635ec sago007 2016-02-06 13:51 1299
			mouseplay2 = (bool)configSettings->getInt("mouseplay2");
335635ec sago007 2016-02-06 13:51 1300
335635ec sago007 2016-02-06 13:51 1301
			if (configSettings->exists("sdl2_player1keyup")) {
335635ec sago007 2016-02-06 13:51 1302
				keySettings[0].up = (SDL_Keycode)configSettings->getInt("sdl2_player1keyup");
335635ec sago007 2016-02-06 13:51 1303
			}
335635ec sago007 2016-02-06 13:51 1304
			if (configSettings->exists("sdl2_player1keydown")) {
335635ec sago007 2016-02-06 13:51 1305
				keySettings[0].down = (SDL_Keycode)configSettings->getInt("sdl2_player1keydown");
335635ec sago007 2016-02-06 13:51 1306
			}
335635ec sago007 2016-02-06 13:51 1307
			if (configSettings->exists("sdl2_player1keyleft")) {
335635ec sago007 2016-02-06 13:51 1308
				keySettings[0].left = (SDL_Keycode)configSettings->getInt("sdl2_player1keyleft");
335635ec sago007 2016-02-06 13:51 1309
			}
335635ec sago007 2016-02-06 13:51 1310
			if (configSettings->exists("sdl2_player1keyright")) {
335635ec sago007 2016-02-06 13:51 1311
				keySettings[0].right = (SDL_Keycode)configSettings->getInt("sdl2_player1keyright");
335635ec sago007 2016-02-06 13:51 1312
			}
335635ec sago007 2016-02-06 13:51 1313
			if (configSettings->exists("sdl2_player1keychange")) {
335635ec sago007 2016-02-06 13:51 1314
				keySettings[0].change = (SDL_Keycode)configSettings->getInt("sdl2_player1keychange");
335635ec sago007 2016-02-06 13:51 1315
			}
335635ec sago007 2016-02-06 13:51 1316
			if (configSettings->exists("sdl2_player1keypush")) {
335635ec sago007 2016-02-06 13:51 1317
				keySettings[0].push = (SDL_Keycode)configSettings->getInt("sdl2_player1keypush");
335635ec sago007 2016-02-06 13:51 1318
			}
c53e6443 sago007 2012-04-17 11:04 1319
335635ec sago007 2016-02-06 13:51 1320
			if (configSettings->exists("sdl2_player2keyup")) {
335635ec sago007 2016-02-06 13:51 1321
				keySettings[2].up = (SDL_Keycode)configSettings->getInt("sdl2_player2keyup");
335635ec sago007 2016-02-06 13:51 1322
			}
335635ec sago007 2016-02-06 13:51 1323
			if (configSettings->exists("sdl2_player2keydown")) {
335635ec sago007 2016-02-06 13:51 1324
				keySettings[2].down = (SDL_Keycode)configSettings->getInt("sdl2_player2keydown");
335635ec sago007 2016-02-06 13:51 1325
			}
335635ec sago007 2016-02-06 13:51 1326
			if (configSettings->exists("sdl2_player2keyleft")) {
335635ec sago007 2016-02-06 13:51 1327
				keySettings[2].left = (SDL_Keycode)configSettings->getInt("sdl2_player2keyleft");
335635ec sago007 2016-02-06 13:51 1328
			}
335635ec sago007 2016-02-06 13:51 1329
			if (configSettings->exists("sdl2_player2keyright")) {
335635ec sago007 2016-02-06 13:51 1330
				keySettings[2].right = (SDL_Keycode)configSettings->getInt("sdl2_player2keyright");
335635ec sago007 2016-02-06 13:51 1331
			}
335635ec sago007 2016-02-06 13:51 1332
			if (configSettings->exists("sdl2_player2keychange")) {
335635ec sago007 2016-02-06 13:51 1333
				keySettings[2].change = (SDL_Keycode)configSettings->getInt("sdl2_player2keychange");
335635ec sago007 2016-02-06 13:51 1334
			}
335635ec sago007 2016-02-06 13:51 1335
			if (configSettings->exists("sdl2_player2keypush")) {
335635ec sago007 2016-02-06 13:51 1336
				keySettings[2].push = (SDL_Keycode)configSettings->getInt("sdl2_player2keypush");
335635ec sago007 2016-02-06 13:51 1337
			}
335635ec sago007 2016-02-06 13:51 1338
			if (configSettings->exists("player1name")) {
335635ec sago007 2016-02-06 13:51 1339
				player1name = configSettings->getString("player1name");
335635ec sago007 2016-02-06 13:51 1340
			}
335635ec sago007 2016-02-06 13:51 1341
			if (configSettings->exists("player2name")) {
335635ec sago007 2016-02-06 13:51 1342
				player2name = configSettings->getString("player2name");
335635ec sago007 2016-02-06 13:51 1343
			}
335635ec sago007 2016-02-06 13:51 1344
			if (verboseLevel) {
335635ec sago007 2016-02-06 13:51 1345
				cout << "Data loaded from config file" << endl;
335635ec sago007 2016-02-06 13:51 1346
			}
335635ec sago007 2016-02-06 13:51 1347
		}
335635ec sago007 2016-02-06 13:51 1348
		else {
335635ec sago007 2016-02-06 13:51 1349
			if (verboseLevel) {
335635ec sago007 2016-02-06 13:51 1350
				cout << "Unable to load options file, using default values" << endl;
335635ec sago007 2016-02-06 13:51 1351
			}
335635ec sago007 2016-02-06 13:51 1352
		}
c53e6443 sago007 2012-04-17 11:04 1353
335635ec sago007 2016-02-06 13:51 1354
		if (singlePuzzle) {
335635ec sago007 2016-02-06 13:51 1355
			xsize=300;
335635ec sago007 2016-02-06 13:51 1356
			ysize=600;
335635ec sago007 2016-02-06 13:51 1357
		}
c53e6443 sago007 2012-04-17 11:04 1358
c53e6443 sago007 2012-04-17 11:04 1359
335635ec sago007 2016-02-06 13:51 1360
		// "Block Attack - Rise of the Blocks"
335635ec sago007 2016-02-06 13:51 1361
		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
335635ec sago007 2016-02-06 13:51 1362
		//Open video
335635ec sago007 2016-02-06 13:51 1363
		int createWindowParams = 0; //SDL_WINDOW_RESIZABLE;
cb49f111 sago007 2016-03-16 20:45 1364
		sdlWindow = SDL_CreateWindow("Block Attack - Rise of the Blocks " VERSION_NUMBER,
335635ec sago007 2016-02-06 13:51 1365
		                             SDL_WINDOWPOS_UNDEFINED,
335635ec sago007 2016-02-06 13:51 1366
		                             SDL_WINDOWPOS_UNDEFINED,
335635ec sago007 2016-02-06 13:51 1367
		                             xsize, ysize,
335635ec sago007 2016-02-06 13:51 1368
		                             createWindowParams );
335635ec sago007 2016-02-06 13:51 1369
		dieOnNullptr(sdlWindow, "Unable to create window");
335635ec sago007 2016-02-06 13:51 1370
		SDL_Renderer* renderer = SDL_CreateRenderer(sdlWindow, -1, 0);
335635ec sago007 2016-02-06 13:51 1371
		dieOnNullptr(renderer, "Unable to create render");
1383de53 sago007 2016-02-21 12:18 1372
		SDL_RenderSetLogicalSize(renderer, xsize, ysize);
335635ec sago007 2016-02-06 13:51 1373
		screen = renderer;
1383de53 sago007 2016-02-21 12:18 1374
		ResetFullscreen();
335635ec sago007 2016-02-06 13:51 1375
		SetSDLIcon(sdlWindow);
c53e6443 sago007 2012-04-17 11:04 1376
f6707482 sago007 2015-12-04 22:55 1377
		if (verboseLevel) {
335635ec sago007 2016-02-06 13:51 1378
			cout << "Images loaded" << endl;
c53e6443 sago007 2012-04-17 11:04 1379
		}
89c4a3a6 sago007 2008-08-29 14:32 1380
335635ec sago007 2016-02-06 13:51 1381
		BlockGameSdl theGame = BlockGameSdl(50,100);            //creates game objects
335635ec sago007 2016-02-06 13:51 1382
		BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
335635ec sago007 2016-02-06 13:51 1383
		player1 = &theGame;
335635ec sago007 2016-02-06 13:51 1384
		player2 = &theGame2;
335635ec sago007 2016-02-06 13:51 1385
		/*if (singlePuzzle)
335635ec sago007 2016-02-06 13:51 1386
		{
335635ec sago007 2016-02-06 13:51 1387
		    theGame.GetTopY()=0;
335635ec sago007 2016-02-06 13:51 1388
		    theGame.GetTopX()=0;
335635ec sago007 2016-02-06 13:51 1389
		    theGame2.GetTopY()=10000;
335635ec sago007 2016-02-06 13:51 1390
		    theGame2.GetTopX()=10000;
335635ec sago007 2016-02-06 13:51 1391
		}*/
335635ec sago007 2016-02-06 13:51 1392
		theGame.SetGameOver();      //sets the game over in the beginning
335635ec sago007 2016-02-06 13:51 1393
		theGame2.SetGameOver();
acc78225 sago007 2015-12-29 18:10 1394
b7590374 sago007 2011-05-19 16:15 1395
335635ec sago007 2016-02-06 13:51 1396
		//Takes names from file instead
335635ec sago007 2016-02-06 13:51 1397
		theGame.name = player1name;
335635ec sago007 2016-02-06 13:51 1398
		theGame2.name = player2name;
b7590374 sago007 2011-05-19 16:15 1399
335635ec sago007 2016-02-06 13:51 1400
		if (singlePuzzle) {
335635ec sago007 2016-02-06 13:51 1401
			LoadPuzzleStages();
b256fda5 sago007 2016-02-21 16:21 1402
			BlockGameStartInfo s;
b256fda5 sago007 2016-02-21 16:21 1403
			s.puzzleMode = true;
b256fda5 sago007 2016-02-21 16:21 1404
			s.level = singlePuzzleNr;
83e4f8fe sago007 2016-02-22 19:22 1405
			s.singlePuzzle = true;
b256fda5 sago007 2016-02-21 16:21 1406
			theGame.NewGame(s);
335635ec sago007 2016-02-06 13:51 1407
		}
335635ec sago007 2016-02-06 13:51 1408
		SDL_RenderClear(screen);
335635ec sago007 2016-02-06 13:51 1409
		DrawIMG(backgroundImage, screen, 0, 0);
335635ec sago007 2016-02-06 13:51 1410
		DrawEverything(xsize,ysize,&theGame,&theGame2);
335635ec sago007 2016-02-06 13:51 1411
		SDL_RenderPresent(screen);
335635ec sago007 2016-02-06 13:51 1412
		//game loop
335635ec sago007 2016-02-06 13:51 1413
		MainMenu();
b7590374 sago007 2011-05-19 16:15 1414
b7590374 sago007 2011-05-19 16:15 1415
c53e6443 sago007 2012-04-17 11:04 1416
335635ec sago007 2016-02-06 13:51 1417
		//Saves options
335635ec sago007 2016-02-06 13:51 1418
		if (!editorMode) {
335635ec sago007 2016-02-06 13:51 1419
			configSettings->setInt("fullscreen",(int)bFullscreen);
335635ec sago007 2016-02-06 13:51 1420
			configSettings->setInt("musicenabled",(int)MusicEnabled);
335635ec sago007 2016-02-06 13:51 1421
			configSettings->setInt("soundenabled",(int)SoundEnabled);
335635ec sago007 2016-02-06 13:51 1422
			configSettings->setInt("mouseplay1",(int)mouseplay1);
335635ec sago007 2016-02-06 13:51 1423
			configSettings->setInt("mouseplay2",(int)mouseplay2);
335635ec sago007 2016-02-06 13:51 1424
			configSettings->setInt("joypad1",(int)joyplay1);
335635ec sago007 2016-02-06 13:51 1425
			configSettings->setInt("joypad2",(int)joyplay2);
c53e6443 sago007 2012-04-17 11:04 1426
335635ec sago007 2016-02-06 13:51 1427
			configSettings->setInt("sdl2_player1keyup",(int)keySettings[0].up);
335635ec sago007 2016-02-06 13:51 1428
			configSettings->setInt("sdl2_player1keydown",(int)keySettings[0].down);
335635ec sago007 2016-02-06 13:51 1429
			configSettings->setInt("sdl2_player1keyleft",(int)keySettings[0].left);
335635ec sago007 2016-02-06 13:51 1430
			configSettings->setInt("sdl2_player1keyright",(int)keySettings[0].right);
335635ec sago007 2016-02-06 13:51 1431
			configSettings->setInt("sdl2_player1keychange",(int)keySettings[0].change);
335635ec sago007 2016-02-06 13:51 1432
			configSettings->setInt("sdl2_player1keypush",(int)keySettings[0].push);
c53e6443 sago007 2012-04-17 11:04 1433
335635ec sago007 2016-02-06 13:51 1434
			configSettings->setInt("sdl2_player2keyup",(int)keySettings[2].up);
335635ec sago007 2016-02-06 13:51 1435
			configSettings->setInt("sdl2_player2keydown",(int)keySettings[2].down);
335635ec sago007 2016-02-06 13:51 1436
			configSettings->setInt("sdl2_player2keyleft",(int)keySettings[2].left);
335635ec sago007 2016-02-06 13:51 1437
			configSettings->setInt("sdl2_player2keyright",(int)keySettings[2].right);
335635ec sago007 2016-02-06 13:51 1438
			configSettings->setInt("sdl2_player2keychange",(int)keySettings[2].change);
335635ec sago007 2016-02-06 13:51 1439
			configSettings->setInt("sdl2_player2keypush",(int)keySettings[2].push);
c53e6443 sago007 2012-04-17 11:04 1440
335635ec sago007 2016-02-06 13:51 1441
			configSettings->setString("player1name",player1name);
335635ec sago007 2016-02-06 13:51 1442
			configSettings->setString("player2name",player2name);
335635ec sago007 2016-02-06 13:51 1443
			configSettings->save();
335635ec sago007 2016-02-06 13:51 1444
		}
c53e6443 sago007 2012-04-17 11:04 1445
335635ec sago007 2016-02-06 13:51 1446
		//calculate uptime:
335635ec sago007 2016-02-06 13:51 1447
		//int hours, mins, secs,
335635ec sago007 2016-02-06 13:51 1448
		commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
c53e6443 sago007 2012-04-17 11:04 1449
335635ec sago007 2016-02-06 13:51 1450
		if (verboseLevel) {
335635ec sago007 2016-02-06 13:51 1451
			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;
335635ec sago007 2016-02-06 13:51 1452
		}
c53e6443 sago007 2012-04-17 11:04 1453
335635ec sago007 2016-02-06 13:51 1454
		ct = TimeHandler::addTime("totalTime",ct);
335635ec sago007 2016-02-06 13:51 1455
		if (verboseLevel) {
335635ec sago007 2016-02-06 13:51 1456
			cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
335635ec sago007 2016-02-06 13:51 1457
		}
c53e6443 sago007 2012-04-17 11:04 1458
335635ec sago007 2016-02-06 13:51 1459
		Stats::getInstance()->save();
335635ec sago007 2016-02-06 13:51 1460
335635ec sago007 2016-02-06 13:51 1461
		Config::getInstance()->save();
c7f2082f sago007 2016-03-13 11:48 1462
c7f2082f sago007 2016-03-13 11:48 1463
335635ec sago007 2016-02-06 13:51 1464
335635ec sago007 2016-02-06 13:51 1465
	}
335635ec sago007 2016-02-06 13:51 1466
	catch (exception& e) {
c3fc09e9 sago007 2016-01-22 18:31 1467
		sago::SagoFatalError(e.what());
c3fc09e9 sago007 2016-01-22 18:31 1468
	}
59dcb571 sago007 2016-02-14 15:34 1469
	//Close file system Apstraction layer!
59dcb571 sago007 2016-02-14 15:34 1470
	PHYSFS_deinit();
c53e6443 sago007 2012-04-17 11:04 1471
	return 0;
c53e6443 sago007 2012-04-17 11:04 1472
}
b7590374 sago007 2011-05-19 16:15 1473
b7590374 sago007 2011-05-19 16:15 1474
ecef5838 sago007 2015-11-24 20:01 1475
int runGame(int gametype, int level) {
c53e6443 sago007 2012-04-17 11:04 1476
	int mousex, mousey;   //Mouse coordinates
7a956470 sago007 2016-02-14 17:09 1477
	theTopScoresEndless = Highscore("endless");
7a956470 sago007 2016-02-14 17:09 1478
	theTopScoresTimeTrial = Highscore("timetrial");
c53e6443 sago007 2012-04-17 11:04 1479
	drawBalls = true;
c53e6443 sago007 2012-04-17 11:04 1480
	puzzleLoaded = false;
a5a3aa4f sago007 2015-08-23 15:31 1481
	bool bNearDeath = false;                        //Play music faster or louder while tru
c53e6443 sago007 2012-04-17 11:04 1482
d8c1f444 sago007 2016-01-31 11:36 1483
	theBallManager = BallManager();
d8c1f444 sago007 2016-01-31 11:36 1484
	theExplosionManager = ExplosionManager();
acd79baf sago007 2015-11-22 19:37 1485
	BlockGameSdl theGame = BlockGameSdl(50,100);            //creates game objects
c53e6443 sago007 2012-04-17 11:04 1486
	BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
c53e6443 sago007 2012-04-17 11:04 1487
	player1 = &theGame;
c53e6443 sago007 2012-04-17 11:04 1488
	player2 = &theGame2;
acd79baf sago007 2015-11-22 19:37 1489
	theGame.DoPaintJob();           //Makes sure what there is something to paint
c53e6443 sago007 2012-04-17 11:04 1490
	theGame2.DoPaintJob();
acd79baf sago007 2015-11-22 19:37 1491
	theGame.SetGameOver();      //sets the game over in the beginning
c53e6443 sago007 2012-04-17 11:04 1492
	theGame2.SetGameOver();
c53e6443 sago007 2012-04-17 11:04 1493
c53e6443 sago007 2012-04-17 11:04 1494
	//Takes names from file instead
8f632c05 sago007 2015-08-22 16:21 1495
	theGame.name = player1name;
8f632c05 sago007 2015-08-22 16:21 1496
	theGame2.name = player2name;
c53e6443 sago007 2012-04-17 11:04 1497
ecef5838 sago007 2015-11-24 20:01 1498
	if (singlePuzzle) {
c53e6443 sago007 2012-04-17 11:04 1499
		LoadPuzzleStages();
b256fda5 sago007 2016-02-21 16:21 1500
		BlockGameStartInfo s;
b256fda5 sago007 2016-02-21 16:21 1501
		s.puzzleMode = true;
b256fda5 sago007 2016-02-21 16:21 1502
		s.level = singlePuzzleNr;
83e4f8fe sago007 2016-02-22 19:22 1503
		s.singlePuzzle = true;
b256fda5 sago007 2016-02-21 16:21 1504
		theGame.NewGame(s);
c53e6443 sago007 2012-04-17 11:04 1505
	}
c53e6443 sago007 2012-04-17 11:04 1506
	//game loop
c53e6443 sago007 2012-04-17 11:04 1507
	int done = 0;
ecef5838 sago007 2015-11-24 20:01 1508
	if (verboseLevel) {
56241205 sago007 2012-08-05 11:15 1509
		cout << "Starting game loop" << endl;
acd79baf sago007 2015-11-22 19:37 1510
	}
c53e6443 sago007 2012-04-17 11:04 1511
c53e6443 sago007 2012-04-17 11:04 1512
	bool mustsetupgame = true;
53203200 sago007 2015-12-25 13:30 1513
ecef5838 sago007 2015-11-24 20:01 1514
	while (done == 0) {
ecef5838 sago007 2015-11-24 20:01 1515
		if (mustsetupgame) {
dfdb7d66 sago007 2015-11-29 19:21 1516
			registerEndlessHighscore = false;
dfdb7d66 sago007 2015-11-29 19:21 1517
			registerTTHighscorePlayer1 = false;
dfdb7d66 sago007 2015-11-29 19:21 1518
			registerTTHighscorePlayer2 = false;
ecef5838 sago007 2015-11-24 20:01 1519
			switch (gametype) {
c53e6443 sago007 2012-04-17 11:04 1520
			case 1:
c53e6443 sago007 2012-04-17 11:04 1521
				StartSinglePlayerTimeTrial();
c53e6443 sago007 2012-04-17 11:04 1522
				break;
ecef5838 sago007 2015-11-24 20:01 1523
			case 2: {
aede0664 sago007 2012-04-19 19:45 1524
				int myLevel = PuzzleLevelSelect(1);
ecef5838 sago007 2015-11-24 20:01 1525
				if (myLevel == -1) {
aede0664 sago007 2012-04-19 19:45 1526
					return 1;
acd79baf sago007 2015-11-22 19:37 1527
				}
b1fe2ae5 sago007 2016-02-21 16:01 1528
				BlockGameStartInfo s;
b1fe2ae5 sago007 2016-02-21 16:01 1529
				s.ticks = SDL_GetTicks();
b1fe2ae5 sago007 2016-02-21 16:01 1530
				s.stageClear = true;
b1fe2ae5 sago007 2016-02-21 16:01 1531
				s.level = myLevel;
b1fe2ae5 sago007 2016-02-21 16:01 1532
				theGame.NewGame(s);
c699a9f9 sago007 2015-12-05 17:22 1533
				DrawIMG(backgroundImage, screen, 0, 0);
aede0664 sago007 2012-04-19 19:45 1534
				twoPlayers =false;
aede0664 sago007 2012-04-19 19:45 1535
				theGame2.SetGameOver();
8f632c05 sago007 2015-08-22 16:21 1536
				theGame.name = player1name;
8f632c05 sago007 2015-08-22 16:21 1537
				theGame2.name = player2name;
aede0664 sago007 2012-04-19 19:45 1538
			}
aede0664 sago007 2012-04-19 19:45 1539
			break;
c53e6443 sago007 2012-04-17 11:04 1540
			case 3:
ecef5838 sago007 2015-11-24 20:01 1541
				if (StartSinglePlayerPuzzle(level)) {
67a32395 sago007 2012-04-19 18:40 1542
					return 1;
acd79baf sago007 2015-11-22 19:37 1543
				}
c53e6443 sago007 2012-04-17 11:04 1544
				break;
ecef5838 sago007 2015-11-24 20:01 1545
			case 4: {
c53e6443 sago007 2012-04-17 11:04 1546
				//1 player - Vs mode
67a32395 sago007 2012-04-19 18:40 1547
				int theAIlevel = level; //startSingleVs();
1e5aff60 sago007 2016-02-21 18:23 1548
				BlockGameStartInfo startInfo;
1e5aff60 sago007 2016-02-21 18:23 1549
				startInfo.ticks = SDL_GetTicks();
1e5aff60 sago007 2016-02-21 18:23 1550
				startInfo.vsMode = true;
ae5fb2bb sago007 2016-03-22 18:00 1551
				startInfo.vsAI = true;
ae5fb2bb sago007 2016-03-22 18:00 1552
				startInfo.level = theAIlevel;
1e5aff60 sago007 2016-02-21 18:23 1553
				theGame.NewGame(startInfo);
6d6b2788 sago007 2016-02-21 18:51 1554
				startInfo.AI = true;
1e5aff60 sago007 2016-02-21 18:23 1555
				theGame2.NewGame(startInfo);
c699a9f9 sago007 2015-12-05 17:22 1556
				DrawIMG(backgroundImage, screen, 0, 0);
c53e6443 sago007 2012-04-17 11:04 1557
				twoPlayers = true; //Single player, but AI plays
8f632c05 sago007 2015-08-22 16:21 1558
				theGame.name = player1name;
8f632c05 sago007 2015-08-22 16:21 1559
				theGame2.name = player2name;
c53e6443 sago007 2012-04-17 11:04 1560
			}
c53e6443 sago007 2012-04-17 11:04 1561
			break;
b0222eff sago007 2012-04-22 15:06 1562
			case 10:
b0222eff sago007 2012-04-22 15:06 1563
				StarTwoPlayerTimeTrial();
b0222eff sago007 2012-04-22 15:06 1564
				break;
b0222eff sago007 2012-04-22 15:06 1565
			case 11:
b0222eff sago007 2012-04-22 15:06 1566
				StartTwoPlayerVs();
b0222eff sago007 2012-04-22 15:06 1567
				break;
c53e6443 sago007 2012-04-17 11:04 1568
			case 0:
c53e6443 sago007 2012-04-17 11:04 1569
			default:
c53e6443 sago007 2012-04-17 11:04 1570
				StartSinglePlayerEndless();
c53e6443 sago007 2012-04-17 11:04 1571
				break;
c53e6443 sago007 2012-04-17 11:04 1572
			};
c53e6443 sago007 2012-04-17 11:04 1573
			mustsetupgame = false;
c699a9f9 sago007 2015-12-05 17:22 1574
			DrawIMG(backgroundImage, screen, 0, 0);
67a32395 sago007 2012-04-19 18:40 1575
			DrawEverything(xsize,ysize,&theGame,&theGame2);
1d2e2129 sago007 2015-12-23 15:41 1576
			SDL_RenderPresent(screen);
c53e6443 sago007 2012-04-17 11:04 1577
		}
b7590374 sago007 2011-05-19 16:15 1578
acd79baf sago007 2015-11-22 19:37 1579
		if (!(highPriority)) {
571b4d47 sago007 2015-12-05 16:02 1580
			SDL_Delay(1);
c53e6443 sago007 2012-04-17 11:04 1581
		}
335635ec sago007 2016-02-06 13:51 1582
b539639c sago007 2015-12-29 11:51 1583
		SDL_RenderClear(screen);
c699a9f9 sago007 2015-12-05 17:22 1584
		DrawIMG(backgroundImage, screen, 0, 0);
b7590374 sago007 2011-05-19 16:15 1585
c53e6443 sago007 2012-04-17 11:04 1586
		//updates the balls and explosions:
a6b97827 sago007 2016-01-24 11:15 1587
		theBallManager.update();
a6b97827 sago007 2016-01-24 11:15 1588
		theExplosionManager.update();
a6b97827 sago007 2016-01-24 11:15 1589
		theTextManager.update();
c53e6443 sago007 2012-04-17 11:04 1590
fee9551a sago007 2016-01-20 19:05 1591
		bool mustWriteScreenshot = false;
335635ec sago007 2016-02-06 13:51 1592
59dcb571 sago007 2016-02-14 15:34 1593
		if (true) {
c53e6443 sago007 2012-04-17 11:04 1594
			SDL_Event event;
c53e6443 sago007 2012-04-17 11:04 1595
ecef5838 sago007 2015-11-24 20:01 1596
			while ( SDL_PollEvent(&event) ) {
ecef5838 sago007 2015-11-24 20:01 1597
				if ( event.type == SDL_QUIT ) {
c53e6443 sago007 2012-04-17 11:04 1598
					Config::getInstance()->setShuttingDown(5);
c53e6443 sago007 2012-04-17 11:04 1599
					done = 1;
c53e6443 sago007 2012-04-17 11:04 1600
				}
c7f2082f sago007 2016-03-13 11:48 1601
ce5aa7d3 sago007 2016-03-13 11:44 1602
				if (theGame.isGameOver() && isEscapeEvent(event)) {
ce5aa7d3 sago007 2016-03-13 11:44 1603
					done = 1;
ce5aa7d3 sago007 2016-03-13 11:44 1604
				}
c53e6443 sago007 2012-04-17 11:04 1605
ecef5838 sago007 2015-11-24 20:01 1606
				if ( event.type == SDL_KEYDOWN ) {
ecef5838 sago007 2015-11-24 20:01 1607
					if ( event.key.keysym.sym == SDLK_ESCAPE || ( event.key.keysym.sym == SDLK_RETURN && theGame.isGameOver() ) ) {
1a156b60 sago007 2015-08-22 17:29 1608
						done=1;
c699a9f9 sago007 2015-12-05 17:22 1609
						DrawIMG(backgroundImage, screen, 0, 0);
c53e6443 sago007 2012-04-17 11:04 1610
c53e6443 sago007 2012-04-17 11:04 1611
					}
ecef5838 sago007 2015-11-24 20:01 1612
					if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled())) {
c53e6443 sago007 2012-04-17 11:04 1613
						//player1:
ecef5838 sago007 2015-11-24 20:01 1614
						if ( event.key.keysym.sym == keySettings[player1keys].up ) {
c53e6443 sago007 2012-04-17 11:04 1615
							theGame.MoveCursor('N');
c53e6443 sago007 2012-04-17 11:04 1616
						}
ecef5838 sago007 2015-11-24 20:01 1617
						if ( event.key.keysym.sym == keySettings[player1keys].down ) {
c53e6443 sago007 2012-04-17 11:04 1618
							theGame.MoveCursor('S');
c53e6443 sago007 2012-04-17 11:04 1619
						}
ecef5838 sago007 2015-11-24 20:01 1620
						if ( (event.key.keysym.sym == keySettings[player1keys].left) ) {
c53e6443 sago007 2012-04-17 11:04 1621
							theGame.MoveCursor('W');
c53e6443 sago007 2012-04-17 11:04 1622
						}
ecef5838 sago007 2015-11-24 20:01 1623
						if ( (event.key.keysym.sym == keySettings[player1keys].right) ) {
c53e6443 sago007 2012-04-17 11:04 1624
							theGame.MoveCursor('E');
c53e6443 sago007 2012-04-17 11:04 1625
						}
ecef5838 sago007 2015-11-24 20:01 1626
						if ( event.key.keysym.sym == keySettings[player1keys].push ) {
c53e6443 sago007 2012-04-17 11:04 1627
							theGame.PushLine();
c53e6443 sago007 2012-04-17 11:04 1628
						}
ecef5838 sago007 2015-11-24 20:01 1629
						if ( event.key.keysym.sym == keySettings[player1keys].change ) {
c53e6443 sago007 2012-04-17 11:04 1630
							theGame.SwitchAtCursor();
c53e6443 sago007 2012-04-17 11:04 1631
						}
c53e6443 sago007 2012-04-17 11:04 1632
					}
ecef5838 sago007 2015-11-24 20:01 1633
					if (!editorMode && !theGame2.GetAIenabled()) {
c53e6443 sago007 2012-04-17 11:04 1634
						//player2:
ecef5838 sago007 2015-11-24 20:01 1635
						if ( event.key.keysym.sym == keySettings[player2keys].up ) {
c53e6443 sago007 2012-04-17 11:04 1636
							theGame2.MoveCursor('N');
c53e6443 sago007 2012-04-17 11:04 1637
						}
ecef5838 sago007 2015-11-24 20:01 1638
						if ( event.key.keysym.sym == keySettings[player2keys].down ) {
c53e6443 sago007 2012-04-17 11:04 1639
							theGame2.MoveCursor('S');
c53e6443 sago007 2012-04-17 11:04 1640
						}
ecef5838 sago007 2015-11-24 20:01 1641
						if ( (event.key.keysym.sym == keySettings[player2keys].left) ) {
c53e6443 sago007 2012-04-17 11:04 1642
							theGame2.MoveCursor('W');
c53e6443 sago007 2012-04-17 11:04 1643
						}
ecef5838 sago007 2015-11-24 20:01 1644
						if ( (event.key.keysym.sym == keySettings[player2keys].right) ) {
c53e6443 sago007 2012-04-17 11:04 1645
							theGame2.MoveCursor('E');
c53e6443 sago007 2012-04-17 11:04 1646
						}
ecef5838 sago007 2015-11-24 20:01 1647
						if ( event.key.keysym.sym == keySettings[player2keys].push ) {
c53e6443 sago007 2012-04-17 11:04 1648
							theGame2.PushLine();
c53e6443 sago007 2012-04-17 11:04 1649
						}
ecef5838 sago007 2015-11-24 20:01 1650
						if ( event.key.keysym.sym == keySettings[player2keys].change ) {
c53e6443 sago007 2012-04-17 11:04 1651
							theGame2.SwitchAtCursor();
c53e6443 sago007 2012-04-17 11:04 1652
						}
c53e6443 sago007 2012-04-17 11:04 1653
					}
c53e6443 sago007 2012-04-17 11:04 1654
					//common:
ecef5838 sago007 2015-11-24 20:01 1655
					if ((!singlePuzzle)&&(!editorMode)) {
ecef5838 sago007 2015-11-24 20:01 1656
						if ( event.key.keysym.sym == SDLK_F2 ) {
c53e6443 sago007 2012-04-17 11:04 1657
							/*#if NETWORK
c53e6443 sago007 2012-04-17 11:04 1658
							if ((!showOptions)&&(!networkActive)){
c53e6443 sago007 2012-04-17 11:04 1659
							#else
c53e6443 sago007 2012-04-17 11:04 1660
							if ((!showOptions)){
c53e6443 sago007 2012-04-17 11:04 1661
							#endif
c53e6443 sago007 2012-04-17 11:04 1662
							    StartSinglePlayerEndless();
c53e6443 sago007 2012-04-17 11:04 1663
							}
c53e6443 sago007 2012-04-17 11:04 1664
							 */
c53e6443 sago007 2012-04-17 11:04 1665
							mustsetupgame = true;
c53e6443 sago007 2012-04-17 11:04 1666
						}
ecef5838 sago007 2015-11-24 20:01 1667
						if ( event.key.keysym.sym == SDLK_F10 ) {
ca486238 sago007 2015-08-23 15:12 1668
							//StartReplay("/home/poul/.gamesaves/blockattack/quicksave");
b283e0f7 sago007 2012-07-29 14:01 1669
						}
ecef5838 sago007 2015-11-24 20:01 1670
						if ( event.key.keysym.sym == SDLK_F9 ) {
fee9551a sago007 2016-01-20 19:05 1671
							mustWriteScreenshot = true;
c53e6443 sago007 2012-04-17 11:04 1672
						}
ca486238 sago007 2015-08-23 15:12 1673
						if ( event.key.keysym.sym == SDLK_F5 ) {
b283e0f7 sago007 2012-07-29 14:01 1674
						}
ecef5838 sago007 2015-11-24 20:01 1675
						if ( event.key.keysym.sym == SDLK_F11 ) {
c53e6443 sago007 2012-04-17 11:04 1676
						} //F11
c53e6443 sago007 2012-04-17 11:04 1677
					}
ecef5838 sago007 2015-11-24 20:01 1678
					if ( event.key.keysym.sym == SDLK_F12 ) {
c53e6443 sago007 2012-04-17 11:04 1679
						done=1;
c53e6443 sago007 2012-04-17 11:04 1680
					}
c53e6443 sago007 2012-04-17 11:04 1681
				}
c7f2082f sago007 2016-03-13 11:48 1682
ce5aa7d3 sago007 2016-03-13 11:44 1683
				if (isPlayerUpEvent(1, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 1684
					theGame.MoveCursor('N');
ce5aa7d3 sago007 2016-03-13 11:44 1685
				}
ce5aa7d3 sago007 2016-03-13 11:44 1686
				if (isPlayerDownEvent(1, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 1687
					theGame.MoveCursor('S');
ce5aa7d3 sago007 2016-03-13 11:44 1688
				}
ce5aa7d3 sago007 2016-03-13 11:44 1689
				if (isPlayerLeftEvent(1, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 1690
					theGame.MoveCursor('W');
ce5aa7d3 sago007 2016-03-13 11:44 1691
				}
ce5aa7d3 sago007 2016-03-13 11:44 1692
				if (isPlayerRightEvent (1, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 1693
					theGame.MoveCursor('E');
ce5aa7d3 sago007 2016-03-13 11:44 1694
				}
ce5aa7d3 sago007 2016-03-13 11:44 1695
				if (isPlayerSwitchEvent(1, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 1696
					theGame.SwitchAtCursor();
ce5aa7d3 sago007 2016-03-13 11:44 1697
				}
ce5aa7d3 sago007 2016-03-13 11:44 1698
				if (isPlayerPushEvent(1, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 1699
					theGame.PushLine();
ce5aa7d3 sago007 2016-03-13 11:44 1700
				}
d0c62e33 sago007 2016-04-02 15:18 1701
				
d0c62e33 sago007 2016-04-02 15:18 1702
				if (event.type == SDL_MOUSEBUTTONDOWN) {
d0c62e33 sago007 2016-04-02 15:18 1703
					if (event.button.button == SDL_BUTTON_LEFT) {
d0c62e33 sago007 2016-04-02 15:18 1704
						bool pressed = false;
d0c62e33 sago007 2016-04-02 15:18 1705
						int x = 0;
d0c62e33 sago007 2016-04-02 15:18 1706
						int y = 0;
d0c62e33 sago007 2016-04-02 15:18 1707
						theGame.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y);
d0c62e33 sago007 2016-04-02 15:18 1708
						if (pressed) {
d0c62e33 sago007 2016-04-02 15:18 1709
							theGame.MouseDown(x, y);
d0c62e33 sago007 2016-04-02 15:18 1710
						}
d0c62e33 sago007 2016-04-02 15:18 1711
						theGame2.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y);
d0c62e33 sago007 2016-04-02 15:18 1712
						if (pressed) {
d0c62e33 sago007 2016-04-02 15:18 1713
							theGame2.MouseDown(x, y);
d0c62e33 sago007 2016-04-02 15:18 1714
						}
d0c62e33 sago007 2016-04-02 15:18 1715
					} 
243ef769 sago007 2016-04-04 18:00 1716
					if (event.button.button == SDL_BUTTON_RIGHT) {
243ef769 sago007 2016-04-04 18:00 1717
						bool pressed = false;
243ef769 sago007 2016-04-04 18:00 1718
						int x = 0;
243ef769 sago007 2016-04-04 18:00 1719
						int y = 0;
243ef769 sago007 2016-04-04 18:00 1720
						theGame.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y);
243ef769 sago007 2016-04-04 18:00 1721
						if (pressed) {
243ef769 sago007 2016-04-04 18:00 1722
							theGame.PushLine();
243ef769 sago007 2016-04-04 18:00 1723
						}
243ef769 sago007 2016-04-04 18:00 1724
						theGame2.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y);
243ef769 sago007 2016-04-04 18:00 1725
						if (pressed) {
243ef769 sago007 2016-04-04 18:00 1726
							theGame2.PushLine();
243ef769 sago007 2016-04-04 18:00 1727
						}
243ef769 sago007 2016-04-04 18:00 1728
					}
c53e6443 sago007 2012-04-17 11:04 1729
				}
d0c62e33 sago007 2016-04-02 15:18 1730
				if (event.type == SDL_MOUSEBUTTONUP) {
d0c62e33 sago007 2016-04-02 15:18 1731
					if (event.button.button == SDL_BUTTON_LEFT) {
d0c62e33 sago007 2016-04-02 15:18 1732
						theGame.MouseUp();
d0c62e33 sago007 2016-04-02 15:18 1733
						theGame2.MouseUp();
acd79baf sago007 2015-11-22 19:37 1734
					}
d0c62e33 sago007 2016-04-02 15:18 1735
				}
d0c62e33 sago007 2016-04-02 15:18 1736
				if (event.type == SDL_MOUSEMOTION) {
d0c62e33 sago007 2016-04-02 15:18 1737
					//cout << "Moved" << endl;
d0c62e33 sago007 2016-04-02 15:18 1738
					bool pressed = false;
d0c62e33 sago007 2016-04-02 15:18 1739
					int x = 0;
d0c62e33 sago007 2016-04-02 15:18 1740
					int y = 0;
d0c62e33 sago007 2016-04-02 15:18 1741
					theGame.GetMouseCursor(pressed, x, y);
d0c62e33 sago007 2016-04-02 15:18 1742
					if (pressed) {
d0c62e33 sago007 2016-04-02 15:18 1743
						int mx = 0;
d0c62e33 sago007 2016-04-02 15:18 1744
						int my = 0;
d0c62e33 sago007 2016-04-02 15:18 1745
						theGame.GetBrickCoordinateFromMouse(pressed, event.motion.x, event.motion.y, mx, my);
d0c62e33 sago007 2016-04-02 15:18 1746
						if (pressed) {
d0c62e33 sago007 2016-04-02 15:18 1747
							if (mx != x) {
d0c62e33 sago007 2016-04-02 15:18 1748
								theGame.MouseMove(mx);
d0c62e33 sago007 2016-04-02 15:18 1749
							}
d0c62e33 sago007 2016-04-02 15:18 1750
						}
acd79baf sago007 2015-11-22 19:37 1751
					}
d0c62e33 sago007 2016-04-02 15:18 1752
					theGame2.GetMouseCursor(pressed, x, y);
d0c62e33 sago007 2016-04-02 15:18 1753
					if (pressed) {
d0c62e33 sago007 2016-04-02 15:18 1754
						int mx = 0;
d0c62e33 sago007 2016-04-02 15:18 1755
						int my = 0;
d0c62e33 sago007 2016-04-02 15:18 1756
						theGame2.GetBrickCoordinateFromMouse(pressed, event.motion.x, event.motion.y, mx, my);
d0c62e33 sago007 2016-04-02 15:18 1757
						if (pressed) {
d0c62e33 sago007 2016-04-02 15:18 1758
							if (mx != x) {
d0c62e33 sago007 2016-04-02 15:18 1759
								theGame2.MouseMove(mx);
d0c62e33 sago007 2016-04-02 15:18 1760
							}
d0c62e33 sago007 2016-04-02 15:18 1761
						}
acd79baf sago007 2015-11-22 19:37 1762
					}
d0c62e33 sago007 2016-04-02 15:18 1763
					
c53e6443 sago007 2012-04-17 11:04 1764
				}
d0c62e33 sago007 2016-04-02 15:18 1765
			} //while event PollEvent - read keys
c53e6443 sago007 2012-04-17 11:04 1766
d0c62e33 sago007 2016-04-02 15:18 1767
			SDL_GetMouseState(&mousex,&mousey);
c53e6443 sago007 2012-04-17 11:04 1768
c53e6443 sago007 2012-04-17 11:04 1769
			// If the mouse button is released, make bMouseUp equal true
ecef5838 sago007 2015-11-24 20:01 1770
			if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) {
c53e6443 sago007 2012-04-17 11:04 1771
				bMouseUp=true;
c53e6443 sago007 2012-04-17 11:04 1772
			}
c53e6443 sago007 2012-04-17 11:04 1773
c53e6443 sago007 2012-04-17 11:04 1774
			// If the mouse button 2 is released, make bMouseUp2 equal true
ecef5838 sago007 2015-11-24 20:01 1775
			if ((SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(3))!=SDL_BUTTON(3)) {
c53e6443 sago007 2012-04-17 11:04 1776
				bMouseUp2=true;
c53e6443 sago007 2012-04-17 11:04 1777
			}
c53e6443 sago007 2012-04-17 11:04 1778
ecef5838 sago007 2015-11-24 20:01 1779
			if ((!singlePuzzle)&&(!editorMode)) {
c53e6443 sago007 2012-04-17 11:04 1780
				//read mouse events
ecef5838 sago007 2015-11-24 20:01 1781
				if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
38fa9b68 sago007 2016-03-12 08:46 1782
					//This is the mouse events
c53e6443 sago007 2012-04-17 11:04 1783
					bMouseUp = false;
c699a9f9 sago007 2015-12-05 17:22 1784
					DrawIMG(backgroundImage, screen, 0, 0);
c53e6443 sago007 2012-04-17 11:04 1785
ecef5838 sago007 2015-11-24 20:01 1786
					if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
acd79baf sago007 2015-11-22 19:37 1787
					        &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
ecef5838 sago007 2015-11-24 20:01 1788
					        &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize)) {
c53e6443 sago007 2012-04-17 11:04 1789
						//Clicked the next button after a stage clear or puzzle
c1785ec5 sago007 2016-02-21 16:07 1790
						nextLevel(theGame, SDL_GetTicks());
c7f2082f sago007 2016-03-13 11:48 1791
c53e6443 sago007 2012-04-17 11:04 1792
					}
ecef5838 sago007 2015-11-24 20:01 1793
					if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x)
acd79baf sago007 2015-11-22 19:37 1794
					        &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize)
ecef5838 sago007 2015-11-24 20:01 1795
					        &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize)) {
c53e6443 sago007 2012-04-17 11:04 1796
						//Clicked the retry button
fde1f2dd sago007 2016-02-21 15:24 1797
						retryLevel(theGame, SDL_GetTicks());
c53e6443 sago007 2012-04-17 11:04 1798
					}
c53e6443 sago007 2012-04-17 11:04 1799
c7f2082f sago007 2016-03-13 11:48 1800
					if (mousex > xsize-bExitOffset && mousex < xsize-bExitOffset+bExitSize &&
c7f2082f sago007 2016-03-13 11:48 1801
					        mousey > ysize-bExitOffset && mousey < ysize-bExitOffset+bExitSize) {
38fa9b68 sago007 2016-03-12 08:46 1802
						done = 1;
38fa9b68 sago007 2016-03-12 08:46 1803
					}
c53e6443 sago007 2012-04-17 11:04 1804
					//cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
c53e6443 sago007 2012-04-17 11:04 1805
				}
c53e6443 sago007 2012-04-17 11:04 1806
c53e6443 sago007 2012-04-17 11:04 1807
				//Mouse button 2:
ecef5838 sago007 2015-11-24 20:01 1808
				if ((SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2) {
c53e6443 sago007 2012-04-17 11:04 1809
					bMouseUp2=false; //The button is pressed
c53e6443 sago007 2012-04-17 11:04 1810
				}
c53e6443 sago007 2012-04-17 11:04 1811
			} //if !singlePuzzle
ecef5838 sago007 2015-11-24 20:01 1812
			else {
c53e6443 sago007 2012-04-17 11:04 1813
c53e6443 sago007 2012-04-17 11:04 1814
			}
c53e6443 sago007 2012-04-17 11:04 1815
		} //if !bScreenBocked;
c53e6443 sago007 2012-04-17 11:04 1816
c53e6443 sago007 2012-04-17 11:04 1817
c53e6443 sago007 2012-04-17 11:04 1818
		//Sees if music is stopped and if music is enabled
ecef5838 sago007 2015-11-24 20:01 1819
		if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath)) {
c53e6443 sago007 2012-04-17 11:04 1820
			// then starts playing it.
c53e6443 sago007 2012-04-17 11:04 1821
			Mix_VolumeMusic(MIX_MAX_VOLUME);
c53e6443 sago007 2012-04-17 11:04 1822
			Mix_PlayMusic(bgMusic, -1); //music loop
c53e6443 sago007 2012-04-17 11:04 1823
		}
b7590374 sago007 2011-05-19 16:15 1824
ecef5838 sago007 2015-11-24 20:01 1825
		if (bNearDeath!=bNearDeathPrev) {
ecef5838 sago007 2015-11-24 20:01 1826
			if (bNearDeath) {
ecef5838 sago007 2015-11-24 20:01 1827
				if (!NoSound &&(MusicEnabled)) {
c53e6443 sago007 2012-04-17 11:04 1828
					Mix_VolumeMusic(MIX_MAX_VOLUME);
c53e6443 sago007 2012-04-17 11:04 1829
					Mix_PlayMusic(highbeatMusic, 1);
c53e6443 sago007 2012-04-17 11:04 1830
				}
c53e6443 sago007 2012-04-17 11:04 1831
			}
ecef5838 sago007 2015-11-24 20:01 1832
			else {
ecef5838 sago007 2015-11-24 20:01 1833
				if (!NoSound &&(MusicEnabled)) {
c53e6443 sago007 2012-04-17 11:04 1834
					Mix_VolumeMusic(MIX_MAX_VOLUME);
c53e6443 sago007 2012-04-17 11:04 1835
					Mix_PlayMusic(bgMusic, -1);
c53e6443 sago007 2012-04-17 11:04 1836
				}
c53e6443 sago007 2012-04-17 11:04 1837
			}
c53e6443 sago007 2012-04-17 11:04 1838
		}
b7590374 sago007 2011-05-19 16:15 1839
c53e6443 sago007 2012-04-17 11:04 1840
		bNearDeathPrev = bNearDeath;
b7590374 sago007 2011-05-19 16:15 1841
b7590374 sago007 2011-05-19 16:15 1842
c53e6443 sago007 2012-04-17 11:04 1843
		//set bNearDeath to false theGame*.Update() will change to true as needed
18055aa0 sago007 2012-06-05 19:43 1844
		bNearDeath = theGame.IsNearDeath() || theGame2.IsNearDeath();
c53e6443 sago007 2012-04-17 11:04 1845
		//Updates the objects
c53e6443 sago007 2012-04-17 11:04 1846
		theGame.Update(SDL_GetTicks());
c53e6443 sago007 2012-04-17 11:04 1847
		theGame2.Update(SDL_GetTicks());
b7590374 sago007 2011-05-19 16:15 1848
b7590374 sago007 2011-05-19 16:15 1849
//see if anyone has won (two players only)
c53e6443 sago007 2012-04-17 11:04 1850
#if NETWORK
c53e6443 sago007 2012-04-17 11:04 1851
		if (!networkPlay)
c53e6443 sago007 2012-04-17 11:04 1852
#endif
ecef5838 sago007 2015-11-24 20:01 1853
			if (twoPlayers) {
ecef5838 sago007 2015-11-24 20:01 1854
				if ((theGame.isGameOver()) && (theGame2.isGameOver())) {
ecef5838 sago007 2015-11-24 20:01 1855
					if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap()) {
c53e6443 sago007 2012-04-17 11:04 1856
						theGame.setPlayerWon();
acd79baf sago007 2015-11-22 19:37 1857
					}
ecef5838 sago007 2015-11-24 20:01 1858
					else if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap()) {
c53e6443 sago007 2012-04-17 11:04 1859
						theGame2.setPlayerWon();
acd79baf sago007 2015-11-22 19:37 1860
					}
ecef5838 sago007 2015-11-24 20:01 1861
					else {
c53e6443 sago007 2012-04-17 11:04 1862
						theGame.setDraw();
c53e6443 sago007 2012-04-17 11:04 1863
						theGame2.setDraw();
c53e6443 sago007 2012-04-17 11:04 1864
					}
b283e0f7 sago007 2012-07-29 14:01 1865
					//twoPlayers = false;
c53e6443 sago007 2012-04-17 11:04 1866
				}
ecef5838 sago007 2015-11-24 20:01 1867
				if ((theGame.isGameOver()) && (!theGame2.isGameOver())) {
c53e6443 sago007 2012-04-17 11:04 1868
					theGame2.setPlayerWon();
b283e0f7 sago007 2012-07-29 14:01 1869
					//twoPlayers = false;
c53e6443 sago007 2012-04-17 11:04 1870
				}
ecef5838 sago007 2015-11-24 20:01 1871
				if ((!theGame.isGameOver()) && (theGame2.isGameOver())) {
c53e6443 sago007 2012-04-17 11:04 1872
					theGame.setPlayerWon();
b283e0f7 sago007 2012-07-29 14:01 1873
					//twoPlayers = false;
c53e6443 sago007 2012-04-17 11:04 1874
				}
3d12f4a8 sago007 2016-03-21 18:40 1875
				vector<GarbageStruct> gs;
3d12f4a8 sago007 2016-03-21 18:40 1876
				theGame.PopSendGarbage(gs);
3d12f4a8 sago007 2016-03-21 18:40 1877
				for (const GarbageStruct& g : gs ) {
3d12f4a8 sago007 2016-03-21 18:40 1878
					if (g.greyGarbage) {
3d12f4a8 sago007 2016-03-21 18:40 1879
						theGame2.CreateGreyGarbage();
3d12f4a8 sago007 2016-03-21 18:40 1880
					}
3d12f4a8 sago007 2016-03-21 18:40 1881
					else {
3d12f4a8 sago007 2016-03-21 18:40 1882
						theGame2.CreateGarbage(g.width, g.height);
3d12f4a8 sago007 2016-03-21 18:40 1883
					}
3d12f4a8 sago007 2016-03-21 18:40 1884
				}
3d12f4a8 sago007 2016-03-21 18:40 1885
				gs.clear();
3d12f4a8 sago007 2016-03-21 18:40 1886
				theGame2.PopSendGarbage(gs);
3d12f4a8 sago007 2016-03-21 18:40 1887
				for (const GarbageStruct& g : gs ) {
3d12f4a8 sago007 2016-03-21 18:40 1888
					if (g.greyGarbage) {
3d12f4a8 sago007 2016-03-21 18:40 1889
						theGame.CreateGreyGarbage();
3d12f4a8 sago007 2016-03-21 18:40 1890
					}
3d12f4a8 sago007 2016-03-21 18:40 1891
					else {
3d12f4a8 sago007 2016-03-21 18:40 1892
						theGame.CreateGarbage(g.width, g.height);
3d12f4a8 sago007 2016-03-21 18:40 1893
					}
3d12f4a8 sago007 2016-03-21 18:40 1894
				}
c53e6443 sago007 2012-04-17 11:04 1895
			}
53203200 sago007 2015-12-25 13:30 1896
dfdb7d66 sago007 2015-11-29 19:21 1897
		if (theGame.isGameOver() && registerTTHighscorePlayer1) {
dfdb7d66 sago007 2015-11-29 19:21 1898
			registerTTHighscorePlayer1 = false;
dfdb7d66 sago007 2015-11-29 19:21 1899
			theTopScoresTimeTrial.addScore(theGame.name, theGame.GetScore());
dfdb7d66 sago007 2015-11-29 19:21 1900
		}
dfdb7d66 sago007 2015-11-29 19:21 1901
		if (theGame2.isGameOver() && registerTTHighscorePlayer2) {
dfdb7d66 sago007 2015-11-29 19:21 1902
			registerTTHighscorePlayer2 = false;
dfdb7d66 sago007 2015-11-29 19:21 1903
			theTopScoresTimeTrial.addScore(theGame2.name, theGame2.GetScore());
dfdb7d66 sago007 2015-11-29 19:21 1904
		}
dfdb7d66 sago007 2015-11-29 19:21 1905
		if (theGame.isGameOver() && registerEndlessHighscore) {
dfdb7d66 sago007 2015-11-29 19:21 1906
			registerEndlessHighscore = false;
dfdb7d66 sago007 2015-11-29 19:21 1907
			theTopScoresEndless.addScore(theGame.name, theGame.GetScore());
dfdb7d66 sago007 2015-11-29 19:21 1908
			theGame.EndlessHighscoreEvent();
dfdb7d66 sago007 2015-11-29 19:21 1909
		}
c53e6443 sago007 2012-04-17 11:04 1910
c53e6443 sago007 2012-04-17 11:04 1911
		//Once evrything has been checked, update graphics
c53e6443 sago007 2012-04-17 11:04 1912
		DrawEverything(xsize,ysize,&theGame,&theGame2);
c53e6443 sago007 2012-04-17 11:04 1913
		SDL_GetMouseState(&mousex,&mousey);
c53e6443 sago007 2012-04-17 11:04 1914
		//Draw the mouse:
1d2e2129 sago007 2015-12-23 15:41 1915
		mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
1d2e2129 sago007 2015-12-23 15:41 1916
		SDL_RenderPresent(screen);
fee9551a sago007 2016-01-20 19:05 1917
		if (mustWriteScreenshot) {
fee9551a sago007 2016-01-20 19:05 1918
			writeScreenShot();
fee9551a sago007 2016-01-20 19:05 1919
		}
c53e6443 sago007 2012-04-17 11:04 1920
	} //game loop
80b830cd sago007 2012-08-19 17:51 1921
	return 0;
605138b3 sago007 2012-04-14 15:12 1922
}
1970-01-01 00:00 1923