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