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