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