| 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" |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
28 |
#include <cmath> |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
29 |
|
| d4f28be2 |
sago007 |
2018-04-24 09:33 |
30 |
|
| e0c7836a |
sago007 |
2018-04-25 12:38 |
31 |
/** |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
32 |
* Draws bricks with a string like: |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
33 |
* "aab" for two identical one and another |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
34 |
* "aaB" the third one will have a bomb |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
35 |
* The any char not in 'a' to 'g' or 'A' to 'G' the behavior is undefined. |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
36 |
* @param target Target to draw to |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
37 |
* @param bricks description on what to draw as a string |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
38 |
* @param x |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
39 |
* @param y |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
40 |
*/ |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
41 |
static void RenderRowOfBricks(SDL_Renderer* target, const std::string& brickStr, int x, int y) { |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
42 |
Uint32 tick = SDL_GetTicks(); |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
43 |
for (size_t i = 0; i < brickStr.size(); ++i) { |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
44 |
bool bomb = false; |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
45 |
char brickChar = brickStr[i]; |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
46 |
if (brickChar >= 'A' && brickChar <= 'G') { |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
47 |
bomb = true; |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
48 |
brickChar = brickChar + 'a' - 'A'; |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
49 |
} |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
50 |
if (brickChar >= 'a' && brickChar <= 'g') { |
| a3a8b2b4 |
Poul Sander |
2023-10-15 21:04 |
51 |
globalData.bricks[brickChar - 'a'].Draw(target, tick, x+i*50, y); |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
52 |
if (bomb) { |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
53 |
globalData.spriteHolder->GetSprite("block_bomb").Draw(target, tick, x+i*50, y); |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
54 |
} |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
55 |
} |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
56 |
} |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
57 |
} |
| e0c7836a |
sago007 |
2018-04-25 12:38 |
58 |
|
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
59 |
class HorizontalSwitchAnimation { |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
60 |
public: |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
61 |
std::string brickStr = "abc"; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
62 |
int cursorPos = 0; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
63 |
int state = 0; //0=move left, 1 = switch, 2 = move right, 3 = switch |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
64 |
Uint32 lastTick = 0; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
65 |
Uint32 animationSpeed = 2000; |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
66 |
|
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
67 |
void Update (Uint32 tick) { |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
68 |
if (tick > lastTick + animationSpeed) { |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
69 |
lastTick = tick; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
70 |
switch (state) { |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
71 |
case 0: |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
72 |
cursorPos = 1; |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
73 |
break; |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
74 |
case 1: //fallthough |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
75 |
case 3: |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
76 |
std::swap(brickStr[cursorPos], brickStr[cursorPos + 1]); |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
77 |
break; |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
78 |
case 2: |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
79 |
cursorPos = 0; |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
80 |
break; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
81 |
} |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
82 |
++state; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
83 |
if (state > 3) { |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
84 |
state = 0; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
85 |
} |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
86 |
} |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
87 |
} |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
88 |
}; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
89 |
|
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
90 |
class MultiLineBlocks { |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
91 |
private: |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
92 |
std::vector<std::string> lines; |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
93 |
public: |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
94 |
MultiLineBlocks& addLine(const std::string& line) { |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
95 |
lines.push_back(line); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
96 |
return *this; |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
97 |
} |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
98 |
|
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
99 |
void Render(SDL_Renderer* target, int x, int y) { |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
100 |
for (size_t i = 0; i < lines.size(); ++i) { |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
101 |
RenderRowOfBricks(target, lines[i], x, y+i*50); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
102 |
} |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
103 |
} |
| d2ba3cf5 |
sago007 |
2018-05-13 15:00 |
104 |
|
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
105 |
}; |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
106 |
|
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
107 |
HorizontalSwitchAnimation switchAnimation; |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
108 |
sago::SagoTextField switchAnimationField; |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
109 |
sago::SagoTextField clearRowfield; |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
110 |
sago::SagoTextField comboField; |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
111 |
sago::SagoTextField dropField; |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
112 |
sago::SagoTextField chainField; |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
113 |
|
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
114 |
static void InitTextField(sago::SagoTextField& field, const char* text) { |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
115 |
field.SetHolder(&globalData.spriteHolder->GetDataHolder()); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
116 |
field.SetFontSize(30); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
117 |
field.SetOutline(2, {0,0,0,255}); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
118 |
field.SetText(text); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
119 |
} |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
120 |
|
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
121 |
HelpHowtoState::HelpHowtoState() { |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
122 |
InitTextField(switchAnimationField, _("Switch block horizontally")); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
123 |
InitTextField(clearRowfield, _("Match 3 to clear")); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
124 |
InitTextField(comboField, _("Create combos!")); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
125 |
InitTextField(dropField, _("Drop blocks!")); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
126 |
InitTextField(chainField, _("Create a chain effect")); |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
127 |
} |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
128 |
|
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
129 |
HelpHowtoState::~HelpHowtoState() { |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
130 |
} |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
131 |
|
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
132 |
const double PI =3.141592653589793238463; |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
133 |
|
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
134 |
static void DrawArrow(SDL_Renderer* target, int x1, int y1, int x2, int y2) { |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
135 |
double dx = x1-x2; |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
136 |
double dy = y1-y2; |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
137 |
double distance = std::sqrt((dx*dx)+(dy*dy)); |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
138 |
dx = dx * 10.0 / distance; |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
139 |
dy = dy * 10.0 / distance; |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
140 |
double angle= PI/4.0; |
| 51ba5a85 |
Poul Sander |
2018-05-06 12:48 |
141 |
double nx1 = dx * std::cos(angle) - dy * std::sin(angle) + x2; |
| 51ba5a85 |
Poul Sander |
2018-05-06 12:48 |
142 |
double ny1 = dx * std::sin(angle) + dy * std::cos(angle) + y2; |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
143 |
SDL_RenderDrawLine(target, x1, y1, x2, y2); |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
144 |
SDL_RenderDrawLine(target, nx1, ny1, x2, y2); |
| 51ba5a85 |
Poul Sander |
2018-05-06 12:48 |
145 |
nx1 = dx * std::cos(-angle) - dy * std::sin(-angle) + x2; |
| 51ba5a85 |
Poul Sander |
2018-05-06 12:48 |
146 |
ny1 = dx * std::sin(-angle) + dy * std::cos(-angle) + y2; |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
147 |
SDL_RenderDrawLine(target, nx1, ny1, x2, y2); |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
148 |
} |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
149 |
|
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
150 |
void HelpHowtoState::Draw(SDL_Renderer* target) { |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
151 |
DrawBackground(target); |
| 855544ea |
Poul Sander |
2021-10-06 20:05 |
152 |
SDL_SetRenderDrawColor(target, 0, 0, 0, SDL_ALPHA_OPAQUE); |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
153 |
RenderRowOfBricks(target, switchAnimation.brickStr, 50, 50); |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
154 |
globalData.spriteHolder->GetSprite("cursor").Draw(target, SDL_GetTicks(), 50+switchAnimation.cursorPos*50, 50); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
155 |
switchAnimationField.Draw(target, 50 +150+30, 50+25, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::center); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
156 |
RenderRowOfBricks(target, "adaa", 50, 150); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
157 |
globalData.spriteHolder->GetSprite("cursor").Draw(target, SDL_GetTicks(), 50, 150); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
158 |
RenderRowOfBricks(target, "dAAA", 50+300, 150); |
| 702c3f63 |
sago007 |
2018-04-29 16:40 |
159 |
DrawArrow(target, 50+200+25, 150+25, 50+300-25, 150+25); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
160 |
clearRowfield.Draw(target, 600, 150+25, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::center); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
161 |
comboField.Draw(target, 50+175, 410, sago::SagoTextField::Alignment::center); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
162 |
MultiLineBlocks().addLine("ab").addLine("ba").addLine("ab").Render(target, 50, 250); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
163 |
globalData.spriteHolder->GetSprite("cursor").Draw(target, SDL_GetTicks(), 50, 250+50); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
164 |
MultiLineBlocks().addLine("AB").addLine("AB").addLine("AB").Render(target, 50+200, 250); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
165 |
DrawArrow(target, 175, 325, 225, 325); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
166 |
MultiLineBlocks().addLine("a").addLine("b").addLine("e").Render(target, 50+400, 250); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
167 |
globalData.spriteHolder->GetSprite("cursor").Draw(target, SDL_GetTicks(), 50+400, 250); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
168 |
MultiLineBlocks().addLine(" ").addLine("b").addLine("ea").Render(target, 50+400+200, 250); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
169 |
dropField.Draw(target, 50+400+150, 410, sago::SagoTextField::Alignment::center); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
170 |
DrawArrow(target, 575, 325, 625, 325); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
171 |
DrawArrow(target, 475, 275, 525, 275); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
172 |
DrawArrow(target, 525, 275, 525, 375); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
173 |
DrawArrow(target, 675, 275, 725, 275); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
174 |
DrawArrow(target, 725, 275, 725, 375); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
175 |
MultiLineBlocks().addLine(" d").addLine(" f").addLine(" f").addLine("fdd").Render(target, 50, 500); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
176 |
MultiLineBlocks().addLine(" d").addLine(" F").addLine(" F").addLine("dFd").Render(target, 50+200, 500); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
177 |
MultiLineBlocks().addLine(" d").addLine(" ").addLine(" ").addLine("d d").Render(target, 50+200*2, 500); |
| a66aa2dd |
sago007 |
2018-04-27 10:00 |
178 |
MultiLineBlocks().addLine(" ").addLine(" ").addLine(" ").addLine("DDD").Render(target, 50+200*3, 500); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
179 |
globalData.spriteHolder->GetSprite("cursor").Draw(target, SDL_GetTicks(), 50, 650); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
180 |
DrawArrow(target, 200, 600, 250, 600); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
181 |
DrawArrow(target, 400, 600, 450, 600); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
182 |
DrawArrow(target, 600, 600, 650, 600); |
| 4830f315 |
Poul Sander |
2018-05-06 12:44 |
183 |
DrawArrow(target, 525, 525, 525, 675); |
| 8f6cc9b3 |
sago007 |
2018-04-29 15:12 |
184 |
chainField.Draw(target, 400, 710, sago::SagoTextField::Alignment::center); |
| ec3f09de |
Poul Sander |
2022-01-29 14:33 |
185 |
HelpCommonState::Draw(target); |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
186 |
} |
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
187 |
|
| d8fe60bd |
sago007 |
2018-04-02 16:15 |
188 |
void HelpHowtoState::Update() { |
| e3e89d02 |
sago007 |
2018-04-26 06:50 |
189 |
switchAnimation.Update(SDL_GetTicks()); |
| ec3f09de |
Poul Sander |
2022-01-29 14:33 |
190 |
HelpCommonState::Update(); |
| a3a8b2b4 |
Poul Sander |
2023-10-15 21:04 |
191 |
} |
|
|
1970-01-01 00:00 |
192 |
|