git repos / blockattack-game

commit e0c7836a

sago007 · 2018-04-25 12:38
e0c7836a043f1d188d83615bf225067e1f2a66b4 patch · browse files
parent d4f28be28d36f12a6b1787f5883354f7fe2bb659

Add helper function to draw bricks in the help screen

Changed files

M source/code/HelpHowtoState.cpp before
M source/code/mainVars.inc before
diff --git a/source/code/HelpHowtoState.cpp b/source/code/HelpHowtoState.cpp index d455b52..bbab7bd 100644 --- a/source/code/HelpHowtoState.cpp +++ b/source/code/HelpHowtoState.cpp
@@ -31,6 +31,34 @@ const int ysize = 768;
const int buttonOffset = 160;
extern sago::SagoSprite bExit;
+/**
+ * Draws bricks with a string like:
+ * "aab" for two identical one and another
+ * "aaB" the third one will have a bomb
+ * The any char not in 'a' to 'g' or 'A' to 'G' the behavior is undefined.
+ * @param target Target to draw to
+ * @param bricks description on what to draw as a string
+ * @param x
+ * @param y
+ */
+static void RenderRowOfBricks(SDL_Renderer* target, const std::string& brickStr, int x, int y) {
+ int tick = SDL_GetTicks();
+ for (size_t i = 0; i < brickStr.size(); ++i) {
+ bool bomb = false;
+ char brickChar = brickStr[i];
+ if (brickChar >= 'A' && brickChar <= 'G') {
+ bomb = true;
+ brickChar = brickChar + 'a' - 'A';
+ }
+ if (brickChar >= 'a' && brickChar <= 'g') {
+ bricks[brickChar - 'a'].Draw(target, tick, x+i*50, y);
+ if (bomb) {
+ globalData.spriteHolder->GetSprite("block_bomb").Draw(target, tick, x+i*50, y);
+ }
+ }
+ }
+}
+
HelpHowtoState::HelpHowtoState() {
box.SetHolder(&globalData.spriteHolder->GetDataHolder());
box.SetFontSize(30);
@@ -62,6 +90,7 @@ void HelpHowtoState::Draw(SDL_Renderer* target) {
DrawBackground(target);
box.SetMaxWidth(1000);
box.Draw(target, 10,10);
+ RenderRowOfBricks(target, "aa gB", 50, 50);
bExit.Draw(globalData.screen, SDL_GetTicks(), xsize-buttonOffset, ysize-buttonOffset);
}
diff --git a/source/code/mainVars.inc b/source/code/mainVars.inc index 758d75f..8ab6b78 100644 --- a/source/code/mainVars.inc +++ b/source/code/mainVars.inc
@@ -69,7 +69,7 @@ static sago::SagoSprite ready; //Before the blocks fall
static sago::SagoSprite explosion[4]; //Then a block explodes
//Animations end
static sago::SagoSprite counter[3]; //Counts down from 3
-static sago::SagoSprite bricks[7]; //The bricks, saved in an array of pointers
+sago::SagoSprite bricks[7]; //The bricks, saved in an array of pointers
static sago::SagoSprite crossover; //Cross the bricks that will be cleared soon
static sago::SagoSprite balls[7]; //The balls (the small ones that jump around)