git repos / blockattack-game

blame: source/code/BlockGameSdl.hpp

normal view · raw

06fd7dec sago007 2016-04-04 17:53 1
/*
06fd7dec sago007 2016-04-04 17:53 2
===========================================================================
06fd7dec sago007 2016-04-04 17:53 3
blockattack - Block Attack - Rise of the Blocks
06fd7dec sago007 2016-04-04 17:53 4
Copyright (C) 2005-2016 Poul Sander
06fd7dec sago007 2016-04-04 17:53 5
06fd7dec sago007 2016-04-04 17:53 6
This program is free software: you can redistribute it and/or modify
06fd7dec sago007 2016-04-04 17:53 7
it under the terms of the GNU General Public License as published by
06fd7dec sago007 2016-04-04 17:53 8
the Free Software Foundation, either version 2 of the License, or
06fd7dec sago007 2016-04-04 17:53 9
(at your option) any later version.
06fd7dec sago007 2016-04-04 17:53 10
06fd7dec sago007 2016-04-04 17:53 11
This program is distributed in the hope that it will be useful,
06fd7dec sago007 2016-04-04 17:53 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
06fd7dec sago007 2016-04-04 17:53 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
06fd7dec sago007 2016-04-04 17:53 14
GNU General Public License for more details.
06fd7dec sago007 2016-04-04 17:53 15
06fd7dec sago007 2016-04-04 17:53 16
You should have received a copy of the GNU General Public License
06fd7dec sago007 2016-04-04 17:53 17
along with this program.  If not, see http://www.gnu.org/licenses/
06fd7dec sago007 2016-04-04 17:53 18
06fd7dec sago007 2016-04-04 17:53 19
Source information and contacts persons can be found at
810e1c2f sago007 2018-03-28 09:40 20
https://blockattack.net
06fd7dec sago007 2016-04-04 17:53 21
===========================================================================
06fd7dec sago007 2016-04-04 17:53 22
*/
8b1ab1cb sago007 2016-04-04 17:51 23
e8d66c68 sago007 2016-07-12 17:32 24
#include "BlockGame.hpp"
c310f8a5 sago007 2017-03-25 16:05 25
#include "global.hpp"
343fbe43 sago007 2018-03-27 19:53 26
#include "sago/SagoTextField.hpp"
a3a8b2b4 Poul Sander 2023-10-15 21:04 27
#include "BallManager.hpp"
a3a8b2b4 Poul Sander 2023-10-15 21:04 28
#include "puzzlehandler.hpp"
a3a8b2b4 Poul Sander 2023-10-15 21:04 29
a3a8b2b4 Poul Sander 2023-10-15 21:04 30
extern BallManager theBallManager;
a3a8b2b4 Poul Sander 2023-10-15 21:04 31
a3a8b2b4 Poul Sander 2023-10-15 21:04 32
extern ExplosionManager theExplosionManager;
e8d66c68 sago007 2016-07-12 17:32 33
5d36f49f Poul Sander 2023-07-11 22:38 34
5d601060 Poul Sander 2023-10-26 21:00 35
static void setScoreboardFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
343fbe43 sago007 2018-03-27 19:53 36
	field.SetHolder(holder);
343fbe43 sago007 2018-03-27 19:53 37
	field.SetFont("penguinattack");
343fbe43 sago007 2018-03-27 19:53 38
	field.SetColor({255,255,255,255});
343fbe43 sago007 2018-03-27 19:53 39
	field.SetFontSize(20);
343fbe43 sago007 2018-03-27 19:53 40
	field.SetText(text);
343fbe43 sago007 2018-03-27 19:53 41
}
e8d66c68 sago007 2016-07-12 17:32 42
5d601060 Poul Sander 2023-10-26 21:00 43
static void setButtonFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) {
871ce5d6 sago007 2018-03-28 12:36 44
	field.SetHolder(holder);
871ce5d6 sago007 2018-03-28 12:36 45
	field.SetFont("freeserif");
871ce5d6 sago007 2018-03-28 12:36 46
	field.SetColor({255,255,255,255});
871ce5d6 sago007 2018-03-28 12:36 47
	field.SetFontSize(24);
f6e8c704 sago007 2018-04-03 21:39 48
	field.SetOutline(1, {64,64,64,255});
871ce5d6 sago007 2018-03-28 12:36 49
	field.SetText(text);
871ce5d6 sago007 2018-03-28 12:36 50
}
871ce5d6 sago007 2018-03-28 12:36 51
dc7f7fbd Poul Sander 2023-10-22 12:26 52
template <class T> void sagoTextSetHelpFont(T& field) {
5d601060 Poul Sander 2023-10-26 21:00 53
	field.SetHolder(&globalData.spriteHolder->GetDataHolder());
5d601060 Poul Sander 2023-10-26 21:00 54
	field.SetFont("freeserif");
5d601060 Poul Sander 2023-10-26 21:00 55
	field.SetFontSize(30);
5d601060 Poul Sander 2023-10-26 21:00 56
	field.SetOutline(1, {128,128,128,255});
dc7f7fbd Poul Sander 2023-10-22 12:26 57
}
dc7f7fbd Poul Sander 2023-10-22 12:26 58
8b1ab1cb sago007 2016-04-04 17:51 59
class BlockGameSdl : public BlockGame {
8b1ab1cb sago007 2016-04-04 17:51 60
public:
343fbe43 sago007 2018-03-27 19:53 61
	BlockGameSdl(int tx, int ty, const sago::SagoDataHolder* holder) {
8b1ab1cb sago007 2016-04-04 17:51 62
		topx = tx;
8b1ab1cb sago007 2016-04-04 17:51 63
		topy = ty;
343fbe43 sago007 2018-03-27 19:53 64
		setScoreboardFont(holder, scoreLabel, _("Score:"));
343fbe43 sago007 2018-03-27 19:53 65
		setScoreboardFont(holder, timeLabel, _("Time:"));
343fbe43 sago007 2018-03-27 19:53 66
		setScoreboardFont(holder, chainLabel, _("Chain:"));
343fbe43 sago007 2018-03-27 19:53 67
		setScoreboardFont(holder, speedLabel, _("Speed:"));
871ce5d6 sago007 2018-03-28 12:36 68
		setButtonFont(holder, buttonNext, _("Next"));
871ce5d6 sago007 2018-03-28 12:36 69
		setButtonFont(holder, buttonRetry, _("Retry"));
871ce5d6 sago007 2018-03-28 12:36 70
		setButtonFont(holder, buttonSkip, _("Skip"));
fc338170 sago007 2018-03-28 14:31 71
		setButtonFont(holder, stopIntField, "");
43e3097e Poul Sander 2023-10-22 08:50 72
5d601060 Poul Sander 2023-10-26 21:00 73
		sagoTextSetBlueFont(player_name);
5d601060 Poul Sander 2023-10-26 21:00 74
		sagoTextSetBlueFont(player_time);
5d601060 Poul Sander 2023-10-26 21:00 75
		sagoTextSetBlueFont(player_score);
5d601060 Poul Sander 2023-10-26 21:00 76
		sagoTextSetBlueFont(player_chain);
5d601060 Poul Sander 2023-10-26 21:00 77
		sagoTextSetBlueFont(player_speed);
8b1ab1cb sago007 2016-04-04 17:51 78
	}
5d601060 Poul Sander 2023-10-26 21:00 79
8b1ab1cb sago007 2016-04-04 17:51 80
8b1ab1cb sago007 2016-04-04 17:51 81
	void DrawImgBoard(const sago::SagoSprite& img, int x, int y) const {
72383a9e sago007 2016-10-30 11:56 82
		DrawIMG(img, globalData.screen, x+topx, y+topy);
8b1ab1cb sago007 2016-04-04 17:51 83
	}
8b1ab1cb sago007 2016-04-04 17:51 84
8b1ab1cb sago007 2016-04-04 17:51 85
	void DrawImgBoardBounded(const sago::SagoSprite& img, int x, int y) const {
5d36f49f Poul Sander 2023-07-11 22:38 86
		DrawIMG_Bounded(img, globalData.screen, x+topx, y+topy, topx, topy, topx + BOARD_WIDTH, topy + BOARD_HEIGHT);
8b1ab1cb sago007 2016-04-04 17:51 87
	}
8b1ab1cb sago007 2016-04-04 17:51 88
871ce5d6 sago007 2018-03-28 12:36 89
	void PrintTextCenteredBoard(int x, int y, sago::SagoTextField& field) {
5d601060 Poul Sander 2023-10-26 21:00 90
		field.Draw(globalData.screen, x+topx+60, y+topy+20,
5d601060 Poul Sander 2023-10-26 21:00 91
		           sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::center);
8b1ab1cb sago007 2016-04-04 17:51 92
	}
5d601060 Poul Sander 2023-10-26 21:00 93
7d649ca8 sago007 2016-10-02 16:43 94
	void SetTopXY(int tx, int ty) {
7d649ca8 sago007 2016-10-02 16:43 95
		topx = tx;
7d649ca8 sago007 2016-10-02 16:43 96
		topy = ty;
7d649ca8 sago007 2016-10-02 16:43 97
	}
8b1ab1cb sago007 2016-04-04 17:51 98
8b1ab1cb sago007 2016-04-04 17:51 99
	int GetTopX() const {
8b1ab1cb sago007 2016-04-04 17:51 100
		return topx;
8b1ab1cb sago007 2016-04-04 17:51 101
	}
8b1ab1cb sago007 2016-04-04 17:51 102
	int GetTopY() const {
8b1ab1cb sago007 2016-04-04 17:51 103
		return topy;
8b1ab1cb sago007 2016-04-04 17:51 104
	}
5d601060 Poul Sander 2023-10-26 21:00 105
8b1ab1cb sago007 2016-04-04 17:51 106
	/**
8b1ab1cb sago007 2016-04-04 17:51 107
	 * Retrives the coordinate to a given brick based on mouse input.
8b1ab1cb sago007 2016-04-04 17:51 108
	 * @param match true if the coordinate are within borders
8b1ab1cb sago007 2016-04-04 17:51 109
	 * @param mousex mouse coordinate input
8b1ab1cb sago007 2016-04-04 17:51 110
	 * @param mousey mouse coordiante input
8b1ab1cb sago007 2016-04-04 17:51 111
	 * @param x brick x. Unchanged if outside border
8b1ab1cb sago007 2016-04-04 17:51 112
	 * @param y brick y. Unchanged if outside border
8b1ab1cb sago007 2016-04-04 17:51 113
	 */
8b1ab1cb sago007 2016-04-04 17:51 114
	void GetBrickCoordinateFromMouse(bool& match, int mousex, int mousey, int& x, int& y) const {
706e81fe sago007 2016-04-05 19:17 115
		if (!IsInTheBoard(mousex, mousey)) {
8b1ab1cb sago007 2016-04-04 17:51 116
			match = false;
8b1ab1cb sago007 2016-04-04 17:51 117
			return;
8b1ab1cb sago007 2016-04-04 17:51 118
		}
8b1ab1cb sago007 2016-04-04 17:51 119
		match = true;
e34256c1 Poul Sander 2021-10-06 20:10 120
		x = (mousex-topx) / bsize;
e34256c1 Poul Sander 2021-10-06 20:10 121
		y = (bsize*12+topy-mousey-pixels) / bsize;
8b1ab1cb sago007 2016-04-04 17:51 122
	}
5d601060 Poul Sander 2023-10-26 21:00 123
706e81fe sago007 2016-04-05 19:17 124
	bool IsInTheBoard(int mousex, int mousey) const {
e34256c1 Poul Sander 2021-10-06 20:10 125
		if (mousex < topx || mousex > topx+bsize*6 || mousey < topy || mousey > topy+bsize*12) {
706e81fe sago007 2016-04-05 19:17 126
			return false;
706e81fe sago007 2016-04-05 19:17 127
		}
706e81fe sago007 2016-04-05 19:17 128
		return true;
706e81fe sago007 2016-04-05 19:17 129
	}
5d601060 Poul Sander 2023-10-26 21:00 130
706e81fe sago007 2016-04-05 19:17 131
	bool IsUnderTheBoard(int mousex, int mousey) const {
e34256c1 Poul Sander 2021-10-06 20:10 132
		if (mousex < topx || mousex > topx+bsize*6 || mousey < topy+bsize*12) {
706e81fe sago007 2016-04-05 19:17 133
			return false;
706e81fe sago007 2016-04-05 19:17 134
		}
706e81fe sago007 2016-04-05 19:17 135
		return true;
706e81fe sago007 2016-04-05 19:17 136
	}
8b1ab1cb sago007 2016-04-04 17:51 137
3f3ff0b6 sago007 2018-03-30 12:59 138
	void AddText(int x, int y, unsigned int text, int time) const override {
c310f8a5 sago007 2017-03-25 16:05 139
		globalData.theTextManager.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time);
8b1ab1cb sago007 2016-04-04 17:51 140
	}
8b1ab1cb sago007 2016-04-04 17:51 141
8b1ab1cb sago007 2016-04-04 17:51 142
	void AddBall(int x, int y, bool right, int color) const  override {
8b1ab1cb sago007 2016-04-04 17:51 143
		theBallManager.addBall(topx+40+x*bsize, topy+bsize*12-y*bsize, right, color);
8b1ab1cb sago007 2016-04-04 17:51 144
	}
8b1ab1cb sago007 2016-04-04 17:51 145
8b1ab1cb sago007 2016-04-04 17:51 146
	void AddExplosion(int x, int y) const  override {
8b1ab1cb sago007 2016-04-04 17:51 147
		theExplosionManager.addExplosion(topx-10+x*bsize, topy+bsize*12-10-y*bsize);
8b1ab1cb sago007 2016-04-04 17:51 148
	}
8b1ab1cb sago007 2016-04-04 17:51 149
8b1ab1cb sago007 2016-04-04 17:51 150
	void PlayerWonEvent() const  override {
72383a9e sago007 2016-10-30 11:56 151
		if (!globalData.SoundEnabled) {
8b1ab1cb sago007 2016-04-04 17:51 152
			return;
8b1ab1cb sago007 2016-04-04 17:51 153
		}
a3a8b2b4 Poul Sander 2023-10-15 21:04 154
		Mix_PlayChannel(1, globalData.applause.get(), 0);
8b1ab1cb sago007 2016-04-04 17:51 155
	}
8b1ab1cb sago007 2016-04-04 17:51 156
8b1ab1cb sago007 2016-04-04 17:51 157
	void DrawEvent() const override {
8b1ab1cb sago007 2016-04-04 17:51 158
		Mix_HaltChannel(1);
8b1ab1cb sago007 2016-04-04 17:51 159
	}
8b1ab1cb sago007 2016-04-04 17:51 160
8b1ab1cb sago007 2016-04-04 17:51 161
	void BlockPopEvent() const  override {
72383a9e sago007 2016-10-30 11:56 162
		if (!globalData.SoundEnabled) {
8b1ab1cb sago007 2016-04-04 17:51 163
			return;
8b1ab1cb sago007 2016-04-04 17:51 164
		}
a3a8b2b4 Poul Sander 2023-10-15 21:04 165
		Mix_PlayChannel(0, globalData.boing.get(), 0);
8b1ab1cb sago007 2016-04-04 17:51 166
	}
8b1ab1cb sago007 2016-04-04 17:51 167
8b1ab1cb sago007 2016-04-04 17:51 168
	void LongChainDoneEvent() const  override {
72383a9e sago007 2016-10-30 11:56 169
		if (!globalData.SoundEnabled) {
8b1ab1cb sago007 2016-04-04 17:51 170
			return;
8b1ab1cb sago007 2016-04-04 17:51 171
		}
a3a8b2b4 Poul Sander 2023-10-15 21:04 172
		Mix_PlayChannel(1, globalData.applause.get(), 0);
8b1ab1cb sago007 2016-04-04 17:51 173
	}
8b1ab1cb sago007 2016-04-04 17:51 174
8b1ab1cb sago007 2016-04-04 17:51 175
	void TimeTrialEndEvent() const  override {
72383a9e sago007 2016-10-30 11:56 176
		if (!globalData.NoSound && globalData.SoundEnabled) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 177
			Mix_PlayChannel(1,globalData.counterFinalChunk.get(),0);
8b1ab1cb sago007 2016-04-04 17:51 178
		}
8b1ab1cb sago007 2016-04-04 17:51 179
	}
8b1ab1cb sago007 2016-04-04 17:51 180
8b1ab1cb sago007 2016-04-04 17:51 181
	void EndlessHighscoreEvent() const  override {
72383a9e sago007 2016-10-30 11:56 182
		if (!globalData.SoundEnabled) {
8b1ab1cb sago007 2016-04-04 17:51 183
			return;
8b1ab1cb sago007 2016-04-04 17:51 184
		}
a3a8b2b4 Poul Sander 2023-10-15 21:04 185
		Mix_PlayChannel(1, globalData.applause.get(), 0);
8b1ab1cb sago007 2016-04-04 17:51 186
	}
8b1ab1cb sago007 2016-04-04 17:51 187
private:
e34256c1 Poul Sander 2021-10-06 20:10 188
e34256c1 Poul Sander 2021-10-06 20:10 189
	/**
e34256c1 Poul Sander 2021-10-06 20:10 190
	This crops "dstrect" and "srcrect" to fit inside "bounds"
e34256c1 Poul Sander 2021-10-06 20:10 191
	dstrect and srcrect are modified in place.
e34256c1 Poul Sander 2021-10-06 20:10 192
	*/
e34256c1 Poul Sander 2021-10-06 20:10 193
	void CropTexture(SDL_Rect& dstrect, SDL_Rect& srcrect, const SDL_Rect& bounds) const {
e34256c1 Poul Sander 2021-10-06 20:10 194
		if (dstrect.x > bounds.x+bounds.w) {
e34256c1 Poul Sander 2021-10-06 20:10 195
			dstrect = {0,0,0,0};
e34256c1 Poul Sander 2021-10-06 20:10 196
			return;
e34256c1 Poul Sander 2021-10-06 20:10 197
		}
e34256c1 Poul Sander 2021-10-06 20:10 198
		if (dstrect.y > bounds.y+bounds.h) {
e34256c1 Poul Sander 2021-10-06 20:10 199
			dstrect = {0,0,0,0};
e34256c1 Poul Sander 2021-10-06 20:10 200
			return;
e34256c1 Poul Sander 2021-10-06 20:10 201
		}
e34256c1 Poul Sander 2021-10-06 20:10 202
		if (dstrect.x+dstrect.w < bounds.x) {
e34256c1 Poul Sander 2021-10-06 20:10 203
			dstrect = {0,0,0,0};
e34256c1 Poul Sander 2021-10-06 20:10 204
			return;
e34256c1 Poul Sander 2021-10-06 20:10 205
		}
e34256c1 Poul Sander 2021-10-06 20:10 206
		if (dstrect.y+dstrect.h < bounds.y) {
e34256c1 Poul Sander 2021-10-06 20:10 207
			dstrect = {0,0,0,0};
e34256c1 Poul Sander 2021-10-06 20:10 208
			return;
e34256c1 Poul Sander 2021-10-06 20:10 209
		}
e34256c1 Poul Sander 2021-10-06 20:10 210
		if (dstrect.x < bounds.x) {
e34256c1 Poul Sander 2021-10-06 20:10 211
			Sint16 absDiff = bounds.x-dstrect.x;
e34256c1 Poul Sander 2021-10-06 20:10 212
			dstrect.x+=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 213
			srcrect.x+=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 214
			dstrect.w-=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 215
			srcrect.w-=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 216
		}
e34256c1 Poul Sander 2021-10-06 20:10 217
		if (dstrect.y < bounds.y) {
e34256c1 Poul Sander 2021-10-06 20:10 218
			Sint16 absDiff = bounds.y-dstrect.y;
e34256c1 Poul Sander 2021-10-06 20:10 219
			dstrect.y+=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 220
			srcrect.y+=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 221
			dstrect.h-=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 222
			srcrect.h-=absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 223
		}
e34256c1 Poul Sander 2021-10-06 20:10 224
		if (dstrect.x+dstrect.w > bounds.x+bounds.w) {
e34256c1 Poul Sander 2021-10-06 20:10 225
			Sint16 absDiff = dstrect.x+dstrect.w-(bounds.x+bounds.w);
e34256c1 Poul Sander 2021-10-06 20:10 226
			dstrect.w -= absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 227
			srcrect.w -= absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 228
		}
e34256c1 Poul Sander 2021-10-06 20:10 229
		if (dstrect.y+dstrect.h > bounds.y+bounds.h) {
e34256c1 Poul Sander 2021-10-06 20:10 230
			Sint16 absDiff = dstrect.y+dstrect.h-(bounds.y+bounds.h);
e34256c1 Poul Sander 2021-10-06 20:10 231
			dstrect.h -= absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 232
			srcrect.h -= absDiff;
e34256c1 Poul Sander 2021-10-06 20:10 233
		}
e34256c1 Poul Sander 2021-10-06 20:10 234
	}
e34256c1 Poul Sander 2021-10-06 20:10 235
e34256c1 Poul Sander 2021-10-06 20:10 236
	/**
e34256c1 Poul Sander 2021-10-06 20:10 237
	 * Creates a new texture for a garabge block of size size_x*size_y at x,y and crops it.
e34256c1 Poul Sander 2021-10-06 20:10 238
	 * Also sets globalData.screen to point to the texture, so Draw now draws on the Texture.
e34256c1 Poul Sander 2021-10-06 20:10 239
	*/
e34256c1 Poul Sander 2021-10-06 20:10 240
	SDL_Texture* CreateGarbageTexture(int x, int y, int size_x, int size_y, SDL_Rect& dstrect, SDL_Rect& srcrect) const {
e34256c1 Poul Sander 2021-10-06 20:10 241
		dstrect = { x, y, size_x*bsize, size_y*bsize };
e34256c1 Poul Sander 2021-10-06 20:10 242
		srcrect = { 0, 0, size_x*bsize, size_y*bsize };
5d36f49f Poul Sander 2023-07-11 22:38 243
		SDL_Rect bound = {topx, topy, BOARD_WIDTH, BOARD_HEIGHT};
e34256c1 Poul Sander 2021-10-06 20:10 244
		CropTexture (dstrect, srcrect, bound);
e34256c1 Poul Sander 2021-10-06 20:10 245
		SDL_Texture* mTexture = SDL_CreateTexture( globalData.screen, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, size_x*bsize, size_y*bsize );
e34256c1 Poul Sander 2021-10-06 20:10 246
		SDL_SetRenderTarget( globalData.screen, mTexture );
e34256c1 Poul Sander 2021-10-06 20:10 247
e34256c1 Poul Sander 2021-10-06 20:10 248
		SDL_SetRenderDrawBlendMode(globalData.screen, SDL_BLENDMODE_NONE);
e34256c1 Poul Sander 2021-10-06 20:10 249
		SDL_SetTextureBlendMode(mTexture, SDL_BLENDMODE_BLEND);
e34256c1 Poul Sander 2021-10-06 20:10 250
		SDL_SetRenderDrawColor(globalData.screen, 0, 0, 0, 0);
e34256c1 Poul Sander 2021-10-06 20:10 251
		SDL_RenderFillRect(globalData.screen, NULL);
e34256c1 Poul Sander 2021-10-06 20:10 252
		SDL_SetRenderDrawBlendMode(globalData.screen, SDL_BLENDMODE_BLEND);
e34256c1 Poul Sander 2021-10-06 20:10 253
		return mTexture;
e34256c1 Poul Sander 2021-10-06 20:10 254
	}
e34256c1 Poul Sander 2021-10-06 20:10 255
e34256c1 Poul Sander 2021-10-06 20:10 256
	/**
e34256c1 Poul Sander 2021-10-06 20:10 257
	Paints a garbage block of size size_x*size_y (size in blocks) at x,y (coordinates in pixels).
e34256c1 Poul Sander 2021-10-06 20:10 258
	The garbage block will be painted on an internal texture and rendered to screen to protect against tearing.
e34256c1 Poul Sander 2021-10-06 20:10 259
	The result will be cropped to the playable area.
e34256c1 Poul Sander 2021-10-06 20:10 260
	*/
e34256c1 Poul Sander 2021-10-06 20:10 261
	void PaintGarbageBlock(int x, int y, int size_x, int size_y) const {
e34256c1 Poul Sander 2021-10-06 20:10 262
		SDL_Rect dstrect ;
e34256c1 Poul Sander 2021-10-06 20:10 263
		SDL_Rect srcrect ;
e34256c1 Poul Sander 2021-10-06 20:10 264
		SDL_Texture* mTexture = CreateGarbageTexture(x, y, size_x, size_y, dstrect, srcrect);
e34256c1 Poul Sander 2021-10-06 20:10 265
		const Sint32 draw_time = SDL_GetTicks();
e34256c1 Poul Sander 2021-10-06 20:10 266
e34256c1 Poul Sander 2021-10-06 20:10 267
		if (size_y == 1) {
e34256c1 Poul Sander 2021-10-06 20:10 268
			//single line
a3a8b2b4 Poul Sander 2023-10-15 21:04 269
			globalData.garbageML.Draw(globalData.screen, draw_time, 0, 0);
e34256c1 Poul Sander 2021-10-06 20:10 270
			for (int i = 1; i < size_x-1; ++i) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 271
				globalData.garbageM.Draw(globalData.screen, draw_time, i*bsize, 0);
e34256c1 Poul Sander 2021-10-06 20:10 272
			}
a3a8b2b4 Poul Sander 2023-10-15 21:04 273
			globalData.garbageMR.Draw(globalData.screen, draw_time, (size_x-1)*bsize, 0);
e34256c1 Poul Sander 2021-10-06 20:10 274
		}
e34256c1 Poul Sander 2021-10-06 20:10 275
		if (size_y > 1) {
e34256c1 Poul Sander 2021-10-06 20:10 276
			// Top line
a3a8b2b4 Poul Sander 2023-10-15 21:04 277
			globalData.garbageTL.Draw(globalData.screen, draw_time, 0, 0);
e34256c1 Poul Sander 2021-10-06 20:10 278
			for (int i = 1; i < size_x-1; ++i) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 279
				globalData.garbageT.Draw(globalData.screen, draw_time, i*bsize, 0);
e34256c1 Poul Sander 2021-10-06 20:10 280
			}
a3a8b2b4 Poul Sander 2023-10-15 21:04 281
			globalData.garbageTR.Draw(globalData.screen, draw_time, (size_x-1)*bsize, 0);
e34256c1 Poul Sander 2021-10-06 20:10 282
			// Middle lines (if any)
e34256c1 Poul Sander 2021-10-06 20:10 283
			for (int j=1; j < size_y-1; ++j) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 284
				globalData.garbageL.Draw(globalData.screen, draw_time, 0, j*bsize);
e34256c1 Poul Sander 2021-10-06 20:10 285
				for (int i = 1; i < size_x-1; ++i) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 286
					globalData.garbageFill.Draw(globalData.screen, draw_time, i*bsize, j*bsize);
e34256c1 Poul Sander 2021-10-06 20:10 287
				}
a3a8b2b4 Poul Sander 2023-10-15 21:04 288
				globalData.garbageR.Draw(globalData.screen, draw_time, (size_x-1)*bsize, j*bsize);
e34256c1 Poul Sander 2021-10-06 20:10 289
			}
e34256c1 Poul Sander 2021-10-06 20:10 290
			//Buttom line
a3a8b2b4 Poul Sander 2023-10-15 21:04 291
			globalData.garbageBL.Draw(globalData.screen, draw_time, 0, (size_y-1)*bsize);
e34256c1 Poul Sander 2021-10-06 20:10 292
			for (int i = 1; i < size_x-1; ++i) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 293
				globalData.garbageB.Draw(globalData.screen, draw_time, i*bsize, (size_y-1)*bsize);
e34256c1 Poul Sander 2021-10-06 20:10 294
			}
a3a8b2b4 Poul Sander 2023-10-15 21:04 295
			globalData.garbageBR.Draw(globalData.screen, draw_time, (size_x-1)*bsize, (size_y-1)*bsize);
e34256c1 Poul Sander 2021-10-06 20:10 296
		}
e34256c1 Poul Sander 2021-10-06 20:10 297
e34256c1 Poul Sander 2021-10-06 20:10 298
		SDL_SetRenderTarget( globalData.screen, nullptr );
e34256c1 Poul Sander 2021-10-06 20:10 299
		SDL_RenderCopy( globalData.screen, mTexture, &srcrect, &dstrect );
e34256c1 Poul Sander 2021-10-06 20:10 300
		SDL_DestroyTexture(mTexture);
e34256c1 Poul Sander 2021-10-06 20:10 301
	}
e34256c1 Poul Sander 2021-10-06 20:10 302
e34256c1 Poul Sander 2021-10-06 20:10 303
	/**
e34256c1 Poul Sander 2021-10-06 20:10 304
	Paints a grey garbage block of size size_x (size in blocks, always 6) at x,y (coordinates in pixels).
e34256c1 Poul Sander 2021-10-06 20:10 305
	The result will be cropped to the playable area.
e34256c1 Poul Sander 2021-10-06 20:10 306
	*/
e34256c1 Poul Sander 2021-10-06 20:10 307
	void PaintGreyGarbageBlock(int x, int y, int size_x) const {
e34256c1 Poul Sander 2021-10-06 20:10 308
		const int size_y = bsize;
e34256c1 Poul Sander 2021-10-06 20:10 309
		SDL_Rect dstrect ;
e34256c1 Poul Sander 2021-10-06 20:10 310
		SDL_Rect srcrect ;
e34256c1 Poul Sander 2021-10-06 20:10 311
		SDL_Texture* mTexture = CreateGarbageTexture(x, y, size_x, size_y, dstrect, srcrect);
e34256c1 Poul Sander 2021-10-06 20:10 312
		const Sint32 draw_time = SDL_GetTicks();
e34256c1 Poul Sander 2021-10-06 20:10 313
e34256c1 Poul Sander 2021-10-06 20:10 314
		for (int j=0; j < size_y; ++j) {
e34256c1 Poul Sander 2021-10-06 20:10 315
			if (j==0) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 316
				globalData.garbageGML.Draw(globalData.screen, draw_time, j*bsize, 0);
e34256c1 Poul Sander 2021-10-06 20:10 317
			}
e34256c1 Poul Sander 2021-10-06 20:10 318
			else if (j==5) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 319
				globalData.garbageGMR.Draw(globalData.screen, draw_time, j*bsize, 0);
e34256c1 Poul Sander 2021-10-06 20:10 320
			}
e34256c1 Poul Sander 2021-10-06 20:10 321
			else {
a3a8b2b4 Poul Sander 2023-10-15 21:04 322
				globalData.garbageGM.Draw(globalData.screen, draw_time, j*bsize, 0);
e34256c1 Poul Sander 2021-10-06 20:10 323
			}
e34256c1 Poul Sander 2021-10-06 20:10 324
		}
e34256c1 Poul Sander 2021-10-06 20:10 325
e34256c1 Poul Sander 2021-10-06 20:10 326
		SDL_SetRenderTarget( globalData.screen, nullptr );
e34256c1 Poul Sander 2021-10-06 20:10 327
		SDL_RenderCopy( globalData.screen, mTexture, &srcrect, &dstrect );
e34256c1 Poul Sander 2021-10-06 20:10 328
		SDL_DestroyTexture(mTexture);
e34256c1 Poul Sander 2021-10-06 20:10 329
	}
e34256c1 Poul Sander 2021-10-06 20:10 330
e34256c1 Poul Sander 2021-10-06 20:10 331
	std::pair<int, int> getGarbageSize(int topx, int topy) const {
e34256c1 Poul Sander 2021-10-06 20:10 332
		int size_x = 0;
e34256c1 Poul Sander 2021-10-06 20:10 333
		int size_y = 0;
e34256c1 Poul Sander 2021-10-06 20:10 334
		int number = board[topx][topy];
e34256c1 Poul Sander 2021-10-06 20:10 335
		for (int i=topy; i < 30 ; ++i) {
5d601060 Poul Sander 2023-10-26 21:00 336
			if (number == board[topx][i]) {
e34256c1 Poul Sander 2021-10-06 20:10 337
				++size_y;
e34256c1 Poul Sander 2021-10-06 20:10 338
			}
e34256c1 Poul Sander 2021-10-06 20:10 339
		}
e34256c1 Poul Sander 2021-10-06 20:10 340
		for (int i=topx; i < 7 ; ++i) {
5d601060 Poul Sander 2023-10-26 21:00 341
			if (number == board[i][topy]) {
e34256c1 Poul Sander 2021-10-06 20:10 342
				++size_x;
e34256c1 Poul Sander 2021-10-06 20:10 343
			}
e34256c1 Poul Sander 2021-10-06 20:10 344
		}
e34256c1 Poul Sander 2021-10-06 20:10 345
		return std::make_pair(size_x, size_y);
e34256c1 Poul Sander 2021-10-06 20:10 346
	}
e34256c1 Poul Sander 2021-10-06 20:10 347
8b1ab1cb sago007 2016-04-04 17:51 348
	//Draws all the bricks to the board (including garbage)
8b1ab1cb sago007 2016-04-04 17:51 349
	void PaintBricks() const {
e34256c1 Poul Sander 2021-10-06 20:10 350
		int lastGarbageNumber = 0;
32754436 Poul Sander 2020-08-15 15:12 351
		for (int i=0; i<13; ++i) {
32754436 Poul Sander 2020-08-15 15:12 352
			for (int j=0; j<6; ++j) {
8b1ab1cb sago007 2016-04-04 17:51 353
				int basicBrick = board[j][i]%10; //The basic brick, stored on the least significant digit
8b1ab1cb sago007 2016-04-04 17:51 354
				if ((basicBrick > -1) && (basicBrick < 7) && ((board[j][i]/1000000)%10==0)) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 355
					DrawImgBoardBounded(globalData.bricks[basicBrick],  j*bsize, bsize*12-i*bsize-pixels);
8b1ab1cb sago007 2016-04-04 17:51 356
					if ((board[j][i]/BLOCKWAIT)%10==1) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 357
						DrawImgBoard(globalData.bomb,  j*bsize, bsize*12-i*bsize-pixels);
8b1ab1cb sago007 2016-04-04 17:51 358
					}
8b1ab1cb sago007 2016-04-04 17:51 359
					if ((board[j][i]/BLOCKHANG)%10==1) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 360
						DrawImgBoardBounded(globalData.ready,  j*bsize, bsize*12-i*bsize-pixels);
8b1ab1cb sago007 2016-04-04 17:51 361
					}
8b1ab1cb sago007 2016-04-04 17:51 362
8b1ab1cb sago007 2016-04-04 17:51 363
				}
8b1ab1cb sago007 2016-04-04 17:51 364
				if ((board[j][i]/1000000)%10==1) {
8b1ab1cb sago007 2016-04-04 17:51 365
					int number = board[j][i];
e34256c1 Poul Sander 2021-10-06 20:10 366
					if (number != lastGarbageNumber) {
e34256c1 Poul Sander 2021-10-06 20:10 367
						const auto& garbage_size = getGarbageSize(j, i);
e34256c1 Poul Sander 2021-10-06 20:10 368
						lastGarbageNumber = number;
e34256c1 Poul Sander 2021-10-06 20:10 369
						PaintGarbageBlock(topx+j*bsize, topy+12*bsize-i*bsize-(garbage_size.second-1)*bsize -pixels, garbage_size.first, garbage_size.second);
8b1ab1cb sago007 2016-04-04 17:51 370
					}
8b1ab1cb sago007 2016-04-04 17:51 371
				}
8b1ab1cb sago007 2016-04-04 17:51 372
				if ((board[j][i]/1000000)%10==2) {
e34256c1 Poul Sander 2021-10-06 20:10 373
					int number = board[j][i];
e34256c1 Poul Sander 2021-10-06 20:10 374
					if (number != lastGarbageNumber) {
e34256c1 Poul Sander 2021-10-06 20:10 375
						const auto& garbage_size = getGarbageSize(j, i);
e34256c1 Poul Sander 2021-10-06 20:10 376
						lastGarbageNumber = number;
e34256c1 Poul Sander 2021-10-06 20:10 377
						PaintGreyGarbageBlock(topx+j*bsize, topy+12*bsize-i*bsize-(garbage_size.second-1)*bsize -pixels, garbage_size.first);
8b1ab1cb sago007 2016-04-04 17:51 378
					}
8b1ab1cb sago007 2016-04-04 17:51 379
				}
8b1ab1cb sago007 2016-04-04 17:51 380
			}
8b1ab1cb sago007 2016-04-04 17:51 381
		}
8b1ab1cb sago007 2016-04-04 17:51 382
		const int j = 0;
8b1ab1cb sago007 2016-04-04 17:51 383
8b1ab1cb sago007 2016-04-04 17:51 384
		int garbageSize=0;
8b1ab1cb sago007 2016-04-04 17:51 385
		for (int i=0; i<20; i++) {
8b1ab1cb sago007 2016-04-04 17:51 386
			if ((board[j][i]/1000000)%10==1) {
8b1ab1cb sago007 2016-04-04 17:51 387
				int left, right, over, under;
8b1ab1cb sago007 2016-04-04 17:51 388
				int number = board[j][i];
32754436 Poul Sander 2020-08-15 15:12 389
				left = -1;
32754436 Poul Sander 2020-08-15 15:12 390
				right = board[j+1][i];
8b1ab1cb sago007 2016-04-04 17:51 391
				if (i>28) {
8b1ab1cb sago007 2016-04-04 17:51 392
					over = -1;
8b1ab1cb sago007 2016-04-04 17:51 393
				}
8b1ab1cb sago007 2016-04-04 17:51 394
				else {
8b1ab1cb sago007 2016-04-04 17:51 395
					over = board[j][i+1];
8b1ab1cb sago007 2016-04-04 17:51 396
				}
8b1ab1cb sago007 2016-04-04 17:51 397
				if (i<1) {
8b1ab1cb sago007 2016-04-04 17:51 398
					under = -1;
8b1ab1cb sago007 2016-04-04 17:51 399
				}
8b1ab1cb sago007 2016-04-04 17:51 400
				else {
8b1ab1cb sago007 2016-04-04 17:51 401
					under = board[j][i-1];
8b1ab1cb sago007 2016-04-04 17:51 402
				}
8b1ab1cb sago007 2016-04-04 17:51 403
				if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) {
a0c212cb Poul Sander 2023-08-13 16:10 404
					if (globalData.theme.decoration.decoration_sprites.size()) {
a0c212cb Poul Sander 2023-08-13 16:10 405
						const sago::SagoSprite& sprite = globalData.spriteHolder->GetSprite(globalData.theme.decoration.decoration_sprites[board[j][i]%globalData.theme.decoration.decoration_sprites.size()]);
a0c212cb Poul Sander 2023-08-13 16:10 406
						DrawImgBoardBounded(sprite,  2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize);
a0c212cb Poul Sander 2023-08-13 16:10 407
					}
8b1ab1cb sago007 2016-04-04 17:51 408
				}
8b1ab1cb sago007 2016-04-04 17:51 409
				if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) { //not in garbage
8b1ab1cb sago007 2016-04-04 17:51 410
					garbageSize=0;
8b1ab1cb sago007 2016-04-04 17:51 411
				}
8b1ab1cb sago007 2016-04-04 17:51 412
				else {
8b1ab1cb sago007 2016-04-04 17:51 413
					garbageSize++;
8b1ab1cb sago007 2016-04-04 17:51 414
				}
8b1ab1cb sago007 2016-04-04 17:51 415
8b1ab1cb sago007 2016-04-04 17:51 416
			}
8b1ab1cb sago007 2016-04-04 17:51 417
		}
8b1ab1cb sago007 2016-04-04 17:51 418
		for (int i=0; i<6; i++) {
8b1ab1cb sago007 2016-04-04 17:51 419
			if (board[i][0]!=-1) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 420
				DrawImgBoardBounded(globalData.transCover,  i*bsize, 12*bsize-pixels);    //Make the appering blocks transperant
8b1ab1cb sago007 2016-04-04 17:51 421
			}
8b1ab1cb sago007 2016-04-04 17:51 422
		}
8b1ab1cb sago007 2016-04-04 17:51 423
8b1ab1cb sago007 2016-04-04 17:51 424
	}
8b1ab1cb sago007 2016-04-04 17:51 425
public:
8b1ab1cb sago007 2016-04-04 17:51 426
	//Draws everything
8b1ab1cb sago007 2016-04-04 17:51 427
	void DoPaintJob() {
a3a8b2b4 Poul Sander 2023-10-15 21:04 428
		DrawIMG(globalData.boardBackBack,globalData.screen,this->GetTopX()-60,this->GetTopY()-68);
8b1ab1cb sago007 2016-04-04 17:51 429
343fbe43 sago007 2018-03-27 19:53 430
		this->scoreLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+148);
343fbe43 sago007 2018-03-27 19:53 431
		this->timeLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+197);
343fbe43 sago007 2018-03-27 19:53 432
		this->chainLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+246);
343fbe43 sago007 2018-03-27 19:53 433
		this->speedLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+295);
8f0c9d80 Poul Sander 2023-07-24 21:33 434
		globalData.spriteHolder->GetSprite(globalData.theme.back_board).DrawScaled(globalData.screen, SDL_GetTicks(), this->GetTopX(),this->GetTopY(), BOARD_WIDTH, BOARD_HEIGHT);
8b1ab1cb sago007 2016-04-04 17:51 435
8b1ab1cb sago007 2016-04-04 17:51 436
		PaintBricks();
8b1ab1cb sago007 2016-04-04 17:51 437
		if (stageClear) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 438
			DrawImgBoard(globalData.blackLine,  0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1);
8b1ab1cb sago007 2016-04-04 17:51 439
		}
8b1ab1cb sago007 2016-04-04 17:51 440
		if (puzzleMode&&(!bGameOver)) {
8b1ab1cb sago007 2016-04-04 17:51 441
			//We need to write nr. of moves left!
549ecfae sago007 2016-10-09 08:37 442
			strHolder = _("Moves left: ") + std::to_string(MovesLeft);
810e1c2f sago007 2018-03-28 09:40 443
			static sago::SagoTextField movesPuzzleLabel;
810e1c2f sago007 2018-03-28 09:40 444
			sagoTextSetHelpFont(movesPuzzleLabel);
0b8fb137 sago007 2018-03-31 19:53 445
			movesPuzzleLabel.SetText(strHolder);
810e1c2f sago007 2018-03-28 09:40 446
			movesPuzzleLabel.Draw(globalData.screen, topx+5, topy+5);
8b1ab1cb sago007 2016-04-04 17:51 447
8b1ab1cb sago007 2016-04-04 17:51 448
		}
8b1ab1cb sago007 2016-04-04 17:51 449
		if (puzzleMode && stageButtonStatus == SBpuzzleMode) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 450
			DrawImgBoard(globalData.bRetry, globalData.cordRetryButton.x, globalData.cordRetryButton.y);
a3a8b2b4 Poul Sander 2023-10-15 21:04 451
			PrintTextCenteredBoard(globalData.cordRetryButton.x, globalData.cordRetryButton.y, buttonRetry);
8b1ab1cb sago007 2016-04-04 17:51 452
			if (getLevel()<PuzzleGetNumberOfPuzzles()-1) {
8b1ab1cb sago007 2016-04-04 17:51 453
				if (hasWonTheGame) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 454
					DrawImgBoard(globalData.bNext, globalData.cordNextButton.x, globalData.cordNextButton.y);
a3a8b2b4 Poul Sander 2023-10-15 21:04 455
					PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonNext);
8b1ab1cb sago007 2016-04-04 17:51 456
				}
8b1ab1cb sago007 2016-04-04 17:51 457
				else {
a3a8b2b4 Poul Sander 2023-10-15 21:04 458
					DrawImgBoard(globalData.bSkip, globalData.cordNextButton.x, globalData.cordNextButton.y);
a3a8b2b4 Poul Sander 2023-10-15 21:04 459
					PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonSkip);
8b1ab1cb sago007 2016-04-04 17:51 460
				}
8b1ab1cb sago007 2016-04-04 17:51 461
			}
8b1ab1cb sago007 2016-04-04 17:51 462
			else {
810e1c2f sago007 2018-03-28 09:40 463
				static sago::SagoTextField lastPuzzleLabel;
810e1c2f sago007 2018-03-28 09:40 464
				sagoTextSetHelpFont(lastPuzzleLabel);
810e1c2f sago007 2018-03-28 09:40 465
				lastPuzzleLabel.SetText(_("Last puzzle"));
810e1c2f sago007 2018-03-28 09:40 466
				lastPuzzleLabel.Draw(globalData.screen, topx+5, topy+5);
8b1ab1cb sago007 2016-04-04 17:51 467
			}
8b1ab1cb sago007 2016-04-04 17:51 468
		}
8b1ab1cb sago007 2016-04-04 17:51 469
		if (stageClear && stageButtonStatus == SBstageClear) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 470
			DrawImgBoard(globalData.bRetry, globalData.cordRetryButton.x, globalData.cordRetryButton.y);
a3a8b2b4 Poul Sander 2023-10-15 21:04 471
			PrintTextCenteredBoard(globalData.cordRetryButton.x, globalData.cordRetryButton.y, buttonRetry);
8b1ab1cb sago007 2016-04-04 17:51 472
			if (getLevel()<50-1) {
8b1ab1cb sago007 2016-04-04 17:51 473
				if (hasWonTheGame) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 474
					DrawImgBoard(globalData.bNext, globalData.cordNextButton.x, globalData.cordNextButton.y);
a3a8b2b4 Poul Sander 2023-10-15 21:04 475
					PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonNext);
8b1ab1cb sago007 2016-04-04 17:51 476
				}
8b1ab1cb sago007 2016-04-04 17:51 477
				else {
a3a8b2b4 Poul Sander 2023-10-15 21:04 478
					DrawImgBoard(globalData.bSkip, globalData.cordNextButton.x, globalData.cordNextButton.y);
a3a8b2b4 Poul Sander 2023-10-15 21:04 479
					PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonSkip);
8b1ab1cb sago007 2016-04-04 17:51 480
				}
8b1ab1cb sago007 2016-04-04 17:51 481
			}
8b1ab1cb sago007 2016-04-04 17:51 482
			else {
810e1c2f sago007 2018-03-28 09:40 483
				static sago::SagoTextField lastStageLabel;
810e1c2f sago007 2018-03-28 09:40 484
				sagoTextSetHelpFont(lastStageLabel);
810e1c2f sago007 2018-03-28 09:40 485
				lastStageLabel.SetText(_("Last stage"));
810e1c2f sago007 2018-03-28 09:40 486
				lastStageLabel.Draw(globalData.screen, topx+5, topy+5);
8b1ab1cb sago007 2016-04-04 17:51 487
			}
8b1ab1cb sago007 2016-04-04 17:51 488
		}
e8d66c68 sago007 2016-07-12 17:32 489
		if (!bGameOver && stop > 20) {
0b8fb137 sago007 2018-03-31 19:53 490
			stopIntField.SetText(std::to_string(stop/10));
fc338170 sago007 2018-03-28 14:31 491
			stopIntField.Draw(globalData.screen, 240+topx, -40+topy);
e8d66c68 sago007 2016-07-12 17:32 492
		}
8b1ab1cb sago007 2016-04-04 17:51 493
8b1ab1cb sago007 2016-04-04 17:51 494
#if DEBUG
8b1ab1cb sago007 2016-04-04 17:51 495
		if (AI_Enabled&&(!bGameOver)) {
e7e189c7 sago007 2018-03-31 15:30 496
			sagoTextSetBlueFont(aiStatusField);
549ecfae sago007 2016-10-09 08:37 497
			strHolder = "AI_status: " + std::to_string(AIstatus)+ ", "+ std::to_string(AIlineToClear);
0b8fb137 sago007 2018-03-31 19:53 498
			aiStatusField.SetText(strHolder);
e7e189c7 sago007 2018-03-31 15:30 499
			aiStatusField.Draw(globalData.screen, topx+5, topy+5);
8b1ab1cb sago007 2016-04-04 17:51 500
		}
8b1ab1cb sago007 2016-04-04 17:51 501
#endif
8b1ab1cb sago007 2016-04-04 17:51 502
		if (!bGameOver) {
8b1ab1cb sago007 2016-04-04 17:51 503
			bool touched = false;
8b1ab1cb sago007 2016-04-04 17:51 504
			int mx = 0;
8b1ab1cb sago007 2016-04-04 17:51 505
			int my = 0;
8b1ab1cb sago007 2016-04-04 17:51 506
			this->GetMouseCursor(touched, mx, my);
8b1ab1cb sago007 2016-04-04 17:51 507
			if (touched) {
72383a9e sago007 2016-10-30 11:56 508
				DrawImgBoard(globalData.spriteHolder->GetSprite("touchcursor"),mx*bsize, 11*bsize-my*bsize-pixels);
8b1ab1cb sago007 2016-04-04 17:51 509
			}
8b1ab1cb sago007 2016-04-04 17:51 510
			else {
a3a8b2b4 Poul Sander 2023-10-15 21:04 511
				DrawImgBoard(globalData.cursor,cursorx*bsize,11*bsize-cursory*bsize-pixels);
8b1ab1cb sago007 2016-04-04 17:51 512
			}
8b1ab1cb sago007 2016-04-04 17:51 513
		}
8b1ab1cb sago007 2016-04-04 17:51 514
		if (ticks<gameStartedAt) {
8b1ab1cb sago007 2016-04-04 17:51 515
			int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;
72383a9e sago007 2016-10-30 11:56 516
			if ( (currentCounter!=lastCounter) && (globalData.SoundEnabled)&&(!globalData.NoSound)) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 517
				Mix_PlayChannel(1, globalData.counterChunk.get(), 0);
8b1ab1cb sago007 2016-04-04 17:51 518
			}
8b1ab1cb sago007 2016-04-04 17:51 519
			lastCounter = currentCounter;
8b1ab1cb sago007 2016-04-04 17:51 520
			switch (currentCounter) {
8b1ab1cb sago007 2016-04-04 17:51 521
			case 2:
a3a8b2b4 Poul Sander 2023-10-15 21:04 522
				DrawImgBoard(globalData.counter[2],  2*bsize, 5*bsize);
8b1ab1cb sago007 2016-04-04 17:51 523
				break;
8b1ab1cb sago007 2016-04-04 17:51 524
			case 1:
a3a8b2b4 Poul Sander 2023-10-15 21:04 525
				DrawImgBoard(globalData.counter[1],  2*bsize, 5*bsize);
8b1ab1cb sago007 2016-04-04 17:51 526
				break;
8b1ab1cb sago007 2016-04-04 17:51 527
			case 0:
a3a8b2b4 Poul Sander 2023-10-15 21:04 528
				DrawImgBoard(globalData.counter[0],  2*bsize, 5*bsize);
8b1ab1cb sago007 2016-04-04 17:51 529
				break;
8b1ab1cb sago007 2016-04-04 17:51 530
			default:
8b1ab1cb sago007 2016-04-04 17:51 531
				break;
8b1ab1cb sago007 2016-04-04 17:51 532
			}
8b1ab1cb sago007 2016-04-04 17:51 533
		}
8b1ab1cb sago007 2016-04-04 17:51 534
		else {
72383a9e sago007 2016-10-30 11:56 535
			if (globalData.SoundEnabled&&(!globalData.NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver)) {
8b1ab1cb sago007 2016-04-04 17:51 536
				int currentCounter = (ticks-(int)gameStartedAt)/1000;
8b1ab1cb sago007 2016-04-04 17:51 537
				if (currentCounter!=lastCounter) {
8b1ab1cb sago007 2016-04-04 17:51 538
					if (currentCounter>115 && currentCounter<120) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 539
						Mix_PlayChannel(1, globalData.counterChunk.get(), 0);
8b1ab1cb sago007 2016-04-04 17:51 540
					}
8b1ab1cb sago007 2016-04-04 17:51 541
				}
8b1ab1cb sago007 2016-04-04 17:51 542
				lastCounter = currentCounter;
8b1ab1cb sago007 2016-04-04 17:51 543
			}
8b1ab1cb sago007 2016-04-04 17:51 544
			else {
72383a9e sago007 2016-10-30 11:56 545
				if ( (0==lastCounter) && (globalData.SoundEnabled)&&(!globalData.NoSound)) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 546
					Mix_PlayChannel(1, globalData.counterFinalChunk.get(), 0);
8b1ab1cb sago007 2016-04-04 17:51 547
				}
8b1ab1cb sago007 2016-04-04 17:51 548
				lastCounter = -1;
8b1ab1cb sago007 2016-04-04 17:51 549
			}
8b1ab1cb sago007 2016-04-04 17:51 550
		}
8b1ab1cb sago007 2016-04-04 17:51 551
2c6a4bae sago007 2018-05-11 15:20 552
		if (bGameOver) {
8b1ab1cb sago007 2016-04-04 17:51 553
			if (hasWonTheGame) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 554
				globalData.tbWinner.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center);
8b1ab1cb sago007 2016-04-04 17:51 555
			}
8b1ab1cb sago007 2016-04-04 17:51 556
			else {
8b1ab1cb sago007 2016-04-04 17:51 557
				if (bDraw) {
a3a8b2b4 Poul Sander 2023-10-15 21:04 558
					globalData.tbDraw.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center);
8b1ab1cb sago007 2016-04-04 17:51 559
				}
8b1ab1cb sago007 2016-04-04 17:51 560
				else {
5d601060 Poul Sander 2023-10-26 21:00 561
					if (this->infostring.empty()) {
5d601060 Poul Sander 2023-10-26 21:00 562
						globalData.tbGameOver.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center);
5d601060 Poul Sander 2023-10-26 21:00 563
					}
8b1ab1cb sago007 2016-04-04 17:51 564
				}
8b1ab1cb sago007 2016-04-04 17:51 565
			}
8b1ab1cb sago007 2016-04-04 17:51 566
		}
43e3097e Poul Sander 2023-10-22 08:50 567
5d601060 Poul Sander 2023-10-26 21:00 568
		std::string strHolder;
5d601060 Poul Sander 2023-10-26 21:00 569
		strHolder = std::to_string(this->GetScore()+this->GetHandicap());
5d601060 Poul Sander 2023-10-26 21:00 570
		player_score.SetText(strHolder);
5d601060 Poul Sander 2023-10-26 21:00 571
		player_score.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()+100);
5d601060 Poul Sander 2023-10-26 21:00 572
		if (this->GetAIenabled()) {
5d601060 Poul Sander 2023-10-26 21:00 573
			player_name.SetText(_("AI"));
5d601060 Poul Sander 2023-10-26 21:00 574
		}
5d601060 Poul Sander 2023-10-26 21:00 575
		else {
5d601060 Poul Sander 2023-10-26 21:00 576
			player_name.SetText(name);
5d601060 Poul Sander 2023-10-26 21:00 577
		}
5d601060 Poul Sander 2023-10-26 21:00 578
		player_name.Draw(globalData.screen, this->GetTopX()+10,this->GetTopY()-34);
5d601060 Poul Sander 2023-10-26 21:00 579
		if (this->isTimeTrial()) {
5d601060 Poul Sander 2023-10-26 21:00 580
			int tid = (int)SDL_GetTicks()-this->GetGameStartedAt();
5d601060 Poul Sander 2023-10-26 21:00 581
			int minutes;
5d601060 Poul Sander 2023-10-26 21:00 582
			int seconds;
5d601060 Poul Sander 2023-10-26 21:00 583
			if (tid>=0) {
5d601060 Poul Sander 2023-10-26 21:00 584
				minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))/60/1000;
5d601060 Poul Sander 2023-10-26 21:00 585
				seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))%(60*1000))/1000;
5d601060 Poul Sander 2023-10-26 21:00 586
			}
5d601060 Poul Sander 2023-10-26 21:00 587
			else {
5d601060 Poul Sander 2023-10-26 21:00 588
				minutes = ((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))/60/1000;
5d601060 Poul Sander 2023-10-26 21:00 589
				seconds = (((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))%(60*1000))/1000;
5d601060 Poul Sander 2023-10-26 21:00 590
			}
5d601060 Poul Sander 2023-10-26 21:00 591
			if (this->isGameOver()) {
5d601060 Poul Sander 2023-10-26 21:00 592
				minutes=0;
5d601060 Poul Sander 2023-10-26 21:00 593
			}
5d601060 Poul Sander 2023-10-26 21:00 594
			if (this->isGameOver()) {
5d601060 Poul Sander 2023-10-26 21:00 595
				seconds=0;
5d601060 Poul Sander 2023-10-26 21:00 596
			}
5d601060 Poul Sander 2023-10-26 21:00 597
			if (seconds>9) {
5d601060 Poul Sander 2023-10-26 21:00 598
				strHolder = std::to_string(minutes)+":"+std::to_string(seconds);
5d601060 Poul Sander 2023-10-26 21:00 599
			}
5d601060 Poul Sander 2023-10-26 21:00 600
			else {
5d601060 Poul Sander 2023-10-26 21:00 601
				strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
5d601060 Poul Sander 2023-10-26 21:00 602
			}
5d601060 Poul Sander 2023-10-26 21:00 603
			player_time.SetText(strHolder);
5d601060 Poul Sander 2023-10-26 21:00 604
		}
5d601060 Poul Sander 2023-10-26 21:00 605
		else {
5d601060 Poul Sander 2023-10-26 21:00 606
			int minutes = ((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))/60/1000;
5d601060 Poul Sander 2023-10-26 21:00 607
			int seconds = (((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))%(60*1000))/1000;
5d601060 Poul Sander 2023-10-26 21:00 608
			if (this->isGameOver()) {
5d601060 Poul Sander 2023-10-26 21:00 609
				minutes=(this->GetGameEndedAt()/1000/60)%100;
5d601060 Poul Sander 2023-10-26 21:00 610
			}
5d601060 Poul Sander 2023-10-26 21:00 611
			if (this->isGameOver()) {
5d601060 Poul Sander 2023-10-26 21:00 612
				seconds=(this->GetGameEndedAt()/1000)%60;
5d601060 Poul Sander 2023-10-26 21:00 613
			}
5d601060 Poul Sander 2023-10-26 21:00 614
			if (seconds>9) {
5d601060 Poul Sander 2023-10-26 21:00 615
				strHolder = std::to_string(minutes)+":"+std::to_string(seconds);
5d601060 Poul Sander 2023-10-26 21:00 616
			}
5d601060 Poul Sander 2023-10-26 21:00 617
			else {
5d601060 Poul Sander 2023-10-26 21:00 618
				strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
5d601060 Poul Sander 2023-10-26 21:00 619
			}
5d601060 Poul Sander 2023-10-26 21:00 620
			player_time.SetText(strHolder);
5d601060 Poul Sander 2023-10-26 21:00 621
		}
5d601060 Poul Sander 2023-10-26 21:00 622
		player_time.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()+150);
5d601060 Poul Sander 2023-10-26 21:00 623
		strHolder = std::to_string(this->GetChains());
5d601060 Poul Sander 2023-10-26 21:00 624
		player_chain.SetText(strHolder);
5d601060 Poul Sander 2023-10-26 21:00 625
		player_chain.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()+200);
5d601060 Poul Sander 2023-10-26 21:00 626
		//drawspeedLevel:
5d601060 Poul Sander 2023-10-26 21:00 627
		strHolder = std::to_string(this->GetSpeedLevel());
5d601060 Poul Sander 2023-10-26 21:00 628
		player_speed.SetText(strHolder);
5d601060 Poul Sander 2023-10-26 21:00 629
		player_speed.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()+250);
5d601060 Poul Sander 2023-10-26 21:00 630
		if ((this->isStageClear()) &&(this->GetTopY()+700+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1<600+this->GetTopY())) {
5d601060 Poul Sander 2023-10-26 21:00 631
			oldBubleX = this->GetTopX()+280;
5d601060 Poul Sander 2023-10-26 21:00 632
			oldBubleY = this->GetTopY()+650+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1;
5d601060 Poul Sander 2023-10-26 21:00 633
			DrawIMG(globalData.stageBobble,globalData.screen,this->GetTopX()+280,this->GetTopY()+650+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1);
5d601060 Poul Sander 2023-10-26 21:00 634
		}
5d601060 Poul Sander 2023-10-26 21:00 635
5d601060 Poul Sander 2023-10-26 21:00 636
		if (infostring.length() > 0) {
5d601060 Poul Sander 2023-10-26 21:00 637
			static sago::SagoTextBox infoBox;
5d601060 Poul Sander 2023-10-26 21:00 638
			static sago::SagoTextField objectiveField;
5d601060 Poul Sander 2023-10-26 21:00 639
			static sago::SagoTextField gametypeNameField;
5d601060 Poul Sander 2023-10-26 21:00 640
			sagoTextSetHelpFont(infoBox);
5d601060 Poul Sander 2023-10-26 21:00 641
			infoBox.SetMaxWidth(290);
5d601060 Poul Sander 2023-10-26 21:00 642
			infoBox.SetText(infostring);
5d601060 Poul Sander 2023-10-26 21:00 643
			sagoTextSetHelpFont(objectiveField);
5d601060 Poul Sander 2023-10-26 21:00 644
			objectiveField.SetText(_("Objective:"));
5d601060 Poul Sander 2023-10-26 21:00 645
			sagoTextSetHelpFont(gametypeNameField);
5d601060 Poul Sander 2023-10-26 21:00 646
			gametypeNameField.SetText(infostringName);
5d601060 Poul Sander 2023-10-26 21:00 647
			gametypeNameField.Draw(globalData.screen, this->GetTopX()+7,this->GetTopY()+10);
5d601060 Poul Sander 2023-10-26 21:00 648
			objectiveField.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160);
5d601060 Poul Sander 2023-10-26 21:00 649
			infoBox.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160+32);
5d601060 Poul Sander 2023-10-26 21:00 650
5d601060 Poul Sander 2023-10-26 21:00 651
			int y = this->GetTopY()+400;
5d601060 Poul Sander 2023-10-26 21:00 652
			static sago::SagoTextBox controldBox;
5d601060 Poul Sander 2023-10-26 21:00 653
			controldBox.SetHolder(&globalData.spriteHolder->GetDataHolder());
5d601060 Poul Sander 2023-10-26 21:00 654
			sagoTextSetHelpFont(controldBox);
5d601060 Poul Sander 2023-10-26 21:00 655
			controldBox.SetMaxWidth(290);
5d601060 Poul Sander 2023-10-26 21:00 656
			controldBox.SetText(controldBoxText);
5d601060 Poul Sander 2023-10-26 21:00 657
			controldBox.Draw(globalData.screen, this->GetTopX()+7,y);
5d601060 Poul Sander 2023-10-26 21:00 658
		}
8b1ab1cb sago007 2016-04-04 17:51 659
	}
8b1ab1cb sago007 2016-04-04 17:51 660
5d601060 Poul Sander 2023-10-26 21:00 661
	sago::SagoTextField player_name;
5d601060 Poul Sander 2023-10-26 21:00 662
	sago::SagoTextField player_time;
5d601060 Poul Sander 2023-10-26 21:00 663
	sago::SagoTextField player_score;
5d601060 Poul Sander 2023-10-26 21:00 664
	sago::SagoTextField player_chain;
5d601060 Poul Sander 2023-10-26 21:00 665
	sago::SagoTextField player_speed;
43e3097e Poul Sander 2023-10-22 08:50 666
5d601060 Poul Sander 2023-10-26 21:00 667
	//Old Stage Clear Buble
5d601060 Poul Sander 2023-10-26 21:00 668
	int oldBubleX;
5d601060 Poul Sander 2023-10-26 21:00 669
	int oldBubleY;
43e3097e Poul Sander 2023-10-22 08:50 670
5d601060 Poul Sander 2023-10-26 21:00 671
	std::string infostring;
5d601060 Poul Sander 2023-10-26 21:00 672
	std::string infostringName;
5d601060 Poul Sander 2023-10-26 21:00 673
	std::string controldBoxText;
dc7f7fbd Poul Sander 2023-10-22 12:26 674
43e3097e Poul Sander 2023-10-22 08:50 675
8b1ab1cb sago007 2016-04-04 17:51 676
private:
8b1ab1cb sago007 2016-04-04 17:51 677
	int topx, topy;
343fbe43 sago007 2018-03-27 19:53 678
	sago::SagoTextField scoreLabel;
343fbe43 sago007 2018-03-27 19:53 679
	sago::SagoTextField timeLabel;
343fbe43 sago007 2018-03-27 19:53 680
	sago::SagoTextField chainLabel;
343fbe43 sago007 2018-03-27 19:53 681
	sago::SagoTextField speedLabel;
871ce5d6 sago007 2018-03-28 12:36 682
	sago::SagoTextField buttonSkip;
871ce5d6 sago007 2018-03-28 12:36 683
	sago::SagoTextField buttonRetry;
871ce5d6 sago007 2018-03-28 12:36 684
	sago::SagoTextField buttonNext;
fc338170 sago007 2018-03-28 14:31 685
	sago::SagoTextField stopIntField;
e7e189c7 sago007 2018-03-31 15:30 686
#if DEBUG
e7e189c7 sago007 2018-03-31 15:30 687
	sago::SagoTextField aiStatusField;
e7e189c7 sago007 2018-03-31 15:30 688
#endif
8b1ab1cb sago007 2016-04-04 17:51 689
};
8b1ab1cb sago007 2016-04-04 17:51 690
8b1ab1cb sago007 2016-04-04 17:51 691
1970-01-01 00:00 692