Learn while playing with HTML5 (8)-Brick map lattice characters
I originally thought that in small games such as Tank Battle and Super Mario, the brick characters in the initial screen were static pictures. Now I know that they are all posted with dynamic textures. I will use the drawing function of HTML5 below. Make a starting screen for a tank battle, and study the dot matrix characters by the way.
1. Dot matrix characters
The texture is actually not much different from the dot matrix characters. The only difference is that the dots are replaced by small pictures. That's it, here is a small program for dot matrix characters. You can input Chinese characters or English letters, and then the program will analyze and generate the dot matrix of the text, and then display it. As for how to analyze and generate a dot matrix, the ideas are as follows:
1. Use the ctx.fillText method to draw the text onto a memory canvas, with the foreground color being black and the background color being white
2. Read each pixel of the canvas and replace it with the corresponding symbol to form a string
There is a question here, how big should the memory canvas be? My solution is to make it as large as possible to ensure that no matter what font is, it will not go out of bounds.
During the process of analyzing the pixels, the width and height of the text can be recorded at the same time. After the analysis is completed, a new canvas will be generated again, this time it can be better equal to the size of the text.
Another problem is that when the text is too small, the font is a bit distorted. This should be a resolution problem. The human eye cannot see the small font clearly, and the program cannot analyze it clearly.
So small-sized fonts need to be specially designed, like the fonts on tank battles.
2. Brick characters
After knowing the principle of dot matrix, it is very simple to implement brick characters. Here is a resource In the picture, the bricks are taken from the inside:
The bricks are very small, in the middle of the picture and on the lower right, the # of each level in the tank battle game we played. ##MAP I didn’t expect it to be generated from such a simple picture.
The following is the dot matrix data of the brick characters. There is only a part here, which just constitutes the BATTLE CITY in the game startup screen and the in the game end screen. 3. Code
Because time is tight, the code is ugly. The code uses a jsgame.js. This is my own simple implementation of the HTML5 2D function. The packaging imitates some interface styles of pygame. After encapsulation, it can be seen that the drawing-related code is very simple, and the rest are mainly operational logic codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
The above is the detailed content of Learn while playing with HTML5 (8)-Brick map lattice characters. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.
