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