git repos / blockattack-game

blame: source/code/HelpHowtoState.cpp

normal view · raw

d8fe60bd sago007 2018-04-02 16:15 1
/*
d8fe60bd sago007 2018-04-02 16:15 2
===========================================================================
d8fe60bd sago007 2018-04-02 16:15 3
blockattack - Block Attack - Rise of the Blocks
d8fe60bd sago007 2018-04-02 16:15 4
Copyright (C) 2005-2018 Poul Sander
d8fe60bd sago007 2018-04-02 16:15 5
d8fe60bd sago007 2018-04-02 16:15 6
This program is free software: you can redistribute it and/or modify
d8fe60bd sago007 2018-04-02 16:15 7
it under the terms of the GNU General Public License as published by
d8fe60bd sago007 2018-04-02 16:15 8
the Free Software Foundation, either version 2 of the License, or
d8fe60bd sago007 2018-04-02 16:15 9
(at your option) any later version.
d8fe60bd sago007 2018-04-02 16:15 10
d8fe60bd sago007 2018-04-02 16:15 11
This program is distributed in the hope that it will be useful,
d8fe60bd sago007 2018-04-02 16:15 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
d8fe60bd sago007 2018-04-02 16:15 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d8fe60bd sago007 2018-04-02 16:15 14
GNU General Public License for more details.
d8fe60bd sago007 2018-04-02 16:15 15
d8fe60bd sago007 2018-04-02 16:15 16
You should have received a copy of the GNU General Public License
d8fe60bd sago007 2018-04-02 16:15 17
along with this program.  If not, see http://www.gnu.org/licenses/
d8fe60bd sago007 2018-04-02 16:15 18
d8fe60bd sago007 2018-04-02 16:15 19
Source information and contacts persons can be found at
d8fe60bd sago007 2018-04-02 16:15 20
https://blockattack.net
d8fe60bd sago007 2018-04-02 16:15 21
===========================================================================
d8fe60bd sago007 2018-04-02 16:15 22
*/
d8fe60bd sago007 2018-04-02 16:15 23
d8fe60bd sago007 2018-04-02 16:15 24
#include "HelpHowtoState.hpp"
d8fe60bd sago007 2018-04-02 16:15 25
#include "global.hpp"
d8fe60bd sago007 2018-04-02 16:15 26
#include "common.h"
d8fe60bd sago007 2018-04-02 16:15 27
#include "MenuSystem.h"
d8fe60bd sago007 2018-04-02 16:15 28
d4f28be2 sago007 2018-04-24 09:33 29
const int xsize = 1024;
d4f28be2 sago007 2018-04-24 09:33 30
const int ysize = 768;
d4f28be2 sago007 2018-04-24 09:33 31
const int buttonOffset = 160;
d4f28be2 sago007 2018-04-24 09:33 32
extern sago::SagoSprite bExit;
d4f28be2 sago007 2018-04-24 09:33 33
e0c7836a sago007 2018-04-25 12:38 34
/**
e0c7836a sago007 2018-04-25 12:38 35
 * Draws bricks with a string like:
e0c7836a sago007 2018-04-25 12:38 36
 * "aab" for two identical one and another
e0c7836a sago007 2018-04-25 12:38 37
 * "aaB" the third one will have a bomb
e0c7836a sago007 2018-04-25 12:38 38
 * The any char not in 'a' to 'g' or 'A' to 'G' the behavior is undefined. 
e0c7836a sago007 2018-04-25 12:38 39
 * @param target Target to draw to
e0c7836a sago007 2018-04-25 12:38 40
 * @param bricks description on what to draw as a string
e0c7836a sago007 2018-04-25 12:38 41
 * @param x
e0c7836a sago007 2018-04-25 12:38 42
 * @param y
e0c7836a sago007 2018-04-25 12:38 43
 */
e0c7836a sago007 2018-04-25 12:38 44
static void RenderRowOfBricks(SDL_Renderer* target, const std::string& brickStr, int x, int y) {
e0c7836a sago007 2018-04-25 12:38 45
	int tick = SDL_GetTicks();
e0c7836a sago007 2018-04-25 12:38 46
	for (size_t i = 0; i < brickStr.size(); ++i) {
e0c7836a sago007 2018-04-25 12:38 47
		bool bomb = false;
e0c7836a sago007 2018-04-25 12:38 48
		char brickChar = brickStr[i];
e0c7836a sago007 2018-04-25 12:38 49
		if (brickChar >= 'A' && brickChar <= 'G') {
e0c7836a sago007 2018-04-25 12:38 50
			bomb = true;
e0c7836a sago007 2018-04-25 12:38 51
			brickChar = brickChar + 'a' - 'A';
e0c7836a sago007 2018-04-25 12:38 52
		}
e0c7836a sago007 2018-04-25 12:38 53
		if (brickChar >= 'a' &&  brickChar <= 'g') {
e0c7836a sago007 2018-04-25 12:38 54
			bricks[brickChar - 'a'].Draw(target, tick, x+i*50, y);
e0c7836a sago007 2018-04-25 12:38 55
			if (bomb) {
e0c7836a sago007 2018-04-25 12:38 56
				globalData.spriteHolder->GetSprite("block_bomb").Draw(target, tick, x+i*50, y);
e0c7836a sago007 2018-04-25 12:38 57
			}
e0c7836a sago007 2018-04-25 12:38 58
		}
e0c7836a sago007 2018-04-25 12:38 59
	}
e0c7836a sago007 2018-04-25 12:38 60
}
e0c7836a sago007 2018-04-25 12:38 61
d8fe60bd sago007 2018-04-02 16:15 62
HelpHowtoState::HelpHowtoState() {
d8fe60bd sago007 2018-04-02 16:15 63
	box.SetHolder(&globalData.spriteHolder->GetDataHolder());
d8fe60bd sago007 2018-04-02 16:15 64
	box.SetFontSize(30);
d8fe60bd sago007 2018-04-02 16:15 65
	box.SetOutline(1, {128,128,128,255});
d8fe60bd sago007 2018-04-02 16:15 66
	box.SetText(_("The basic purpose of the game is to match 3 or more blocks of identical color to make them explode.\n"
d8fe60bd sago007 2018-04-02 16:15 67
	"You can only move blocks vertically."
d8fe60bd sago007 2018-04-02 16:15 68
	"The blocks are constantly raising from the bottom of the screen. Once they reach the top the game will start counting down to your"
d8fe60bd sago007 2018-04-02 16:15 69
	" imminent defeat."));
d8fe60bd sago007 2018-04-02 16:15 70
}
d8fe60bd sago007 2018-04-02 16:15 71
d8fe60bd sago007 2018-04-02 16:15 72
HelpHowtoState::~HelpHowtoState() {
d8fe60bd sago007 2018-04-02 16:15 73
}
d8fe60bd sago007 2018-04-02 16:15 74
d8fe60bd sago007 2018-04-02 16:15 75
bool HelpHowtoState::IsActive() {
d8fe60bd sago007 2018-04-02 16:15 76
	return isActive;
d8fe60bd sago007 2018-04-02 16:15 77
}
d8fe60bd sago007 2018-04-02 16:15 78
d8fe60bd sago007 2018-04-02 16:15 79
void HelpHowtoState::ProcessInput(const SDL_Event& event, bool& processed) {
d8fe60bd sago007 2018-04-02 16:15 80
d8fe60bd sago007 2018-04-02 16:15 81
	UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
d8fe60bd sago007 2018-04-02 16:15 82
d8fe60bd sago007 2018-04-02 16:15 83
	if (isConfirmEvent(event) || isEscapeEvent(event)) {
d8fe60bd sago007 2018-04-02 16:15 84
		isActive = false;
d8fe60bd sago007 2018-04-02 16:15 85
		processed = true;
d8fe60bd sago007 2018-04-02 16:15 86
	}
d8fe60bd sago007 2018-04-02 16:15 87
}
d8fe60bd sago007 2018-04-02 16:15 88
d8fe60bd sago007 2018-04-02 16:15 89
void HelpHowtoState::Draw(SDL_Renderer* target) {
d8fe60bd sago007 2018-04-02 16:15 90
	DrawBackground(target);
d8fe60bd sago007 2018-04-02 16:15 91
	box.SetMaxWidth(1000);
d8fe60bd sago007 2018-04-02 16:15 92
	box.Draw(target, 10,10);
e0c7836a sago007 2018-04-25 12:38 93
	RenderRowOfBricks(target, "aa gB", 50, 50);
d4f28be2 sago007 2018-04-24 09:33 94
	bExit.Draw(globalData.screen, SDL_GetTicks(), xsize-buttonOffset, ysize-buttonOffset);
d8fe60bd sago007 2018-04-02 16:15 95
}
d8fe60bd sago007 2018-04-02 16:15 96
d8fe60bd sago007 2018-04-02 16:15 97
void HelpHowtoState::Update() {
d4f28be2 sago007 2018-04-24 09:33 98
	// If the mouse button is released, make bMouseUp equal true
d4f28be2 sago007 2018-04-24 09:33 99
	if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
d4f28be2 sago007 2018-04-24 09:33 100
		bMouseUp=true;
d4f28be2 sago007 2018-04-24 09:33 101
	}
d4f28be2 sago007 2018-04-24 09:33 102
d4f28be2 sago007 2018-04-24 09:33 103
	if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
d4f28be2 sago007 2018-04-24 09:33 104
		bMouseUp = false;
d4f28be2 sago007 2018-04-24 09:33 105
d4f28be2 sago007 2018-04-24 09:33 106
		//The Score button:
d4f28be2 sago007 2018-04-24 09:33 107
		if ((globalData.mousex>xsize-buttonOffset) && (globalData.mousex<xsize-buttonOffset+bExit.GetWidth()) 
d4f28be2 sago007 2018-04-24 09:33 108
				&& (globalData.mousey>ysize-buttonOffset) && (globalData.mousey<ysize-buttonOffset+bExit.GetHeight())) {
d4f28be2 sago007 2018-04-24 09:33 109
			isActive = false;
d4f28be2 sago007 2018-04-24 09:33 110
		}
d4f28be2 sago007 2018-04-24 09:33 111
d4f28be2 sago007 2018-04-24 09:33 112
	}
d8fe60bd sago007 2018-04-02 16:15 113
}