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