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