6
\$\begingroup\$

I am studying how to make a 2D game with JavaScript by reading open source JavaScript games and I came across this gibberish...

aSpriteData = [
    "}\"¹-º\"À+º\"À+º\"À+º\"¿¤À ~C_ +º\"À+º\"À+º\"À*P7²OK%¾+½u_\"À<¡a¡a¡bM@±@ª",    //  0 ground
    "a ' ![± 7°³b£[mt<Nµ7z]~¨OR»[f_7l},tl},+}%XN²Sb[bl£[±%Y_¹ !@ $",        //  1 qbox
    "!A % @,[] ±}°@;µn¦&X£ <$ §¤ 8}}@Prc'U#Z'H'@· ¶\"is ¤&08@£(",           //  2 mario
    "  ´!A.@H#q8¸»e-½n®@±oW:&X¢a<&bbX~# }LWP41}k¬#3¨q#1f RQ@@:4@$",         //  3 mario jump
    "   40 q$!hWa-½n¦#_Y}a©,0#aaPw@=cmY<mq©GBagaq&@q#0§0t0¤ $",         //  4 mario run
    "+hP_@",                                    //  5 pipe left
    "¢,6< R¤",                                  //  6 pipe right
    "@ &  ,'+hP?>³®'©}[!»¹.¢_^¥y/pX¸#µ°=a¾½hP?>³®'©}[!»¹.¢_^  Ba a",        //  7 pipe top left
    "@ , !] \"º £] , 8O #7a&+¢ §²!cº 9] P &O ,4    e",              //  8 pipe top right
    " £ #! ,! P!!vawd/XO¤8¼'¤P½»¹²'9¨  \"P²Pa²(!¢5!N*(4´b!Gk(a",            //  9 goomba
    "   Xu X5 =ou!¯­¬a[Z¼q.°u#|xv ¸··@=~^H'WOJ!¯­¬a=Nu ²J <J   a",          // 10 coin  // yui
    "@ & !MX ~L \"y %P *¢ 5a K  w !L \"y %P *­a%¬¢ 4  a",               // 11 ebox // yui
    "¢ ,\"²+aN!@ &7 }\"²+aN!XH # }\"²+aN!X%  8}\"²+aN!X%£@ (",          // 12 bricks
    "} %¿¢!N° I¨²*<P%.8\"h,!Cg r¥ H³a4X¢*<P%.H#I¬ :a!u !q",         // 13 block
    makeSpace(20) + "4a }@ }0 N( w$ }\" N! +aa",                    // 14 bush left
    " r \"²y!L%aN zPN NyN#²L}[/cy¾ N" + makeSpace(18) + "@",            // 15 bush mid
    makeSpace(18) + "++ !R·a!x6 &+6 87L ¢6 P+ 8+ (",                // 16 bush right
    " %©¦ +pq 7> \"³  s" + makeSpace(25) + "@",                 // 17 cloud bottom left
    "a/a_#².Q¥'¥b}8.£¨7!X\"K+5cqs%(" + makeSpace(18) + "0",             // 18 cloud bottom mid
    "bP ¢L P+ 8%a,*a%§@ J" + makeSpace(22) + "(",                   // 19 cloud bottom right
    "",         // 20 mushroom
    "", // koopa 16x24
    "",             // 22 star
    "",                         // 23 flagpole
    "",         // 24 flag
    "",                 // 25 flagpole top
    "  6  ~  }a }@ }0 }( }$ }\" }! } a} @} 0} (} $} \"² $",             // 26 hill slope
    "a } \"m %8 *P!MF 5la\"y %P" + makeSpace(18) + "(",             // 27 hill mid
    makeSpace(30) + "%\" t!DK \"q",                         // 28 hill top
    "",         // 29 castle bricks
    "",                         // 30 castle doorway bottom
    "",                 // 31 castle doorway top
    "",         // 32 castle top
    "",         // 33 castle top 2
    "",             // 34 castle window right
    "",             // 35 castle window left
    "",         // 36 castle flag
    makeSpace(19) + "8@# (9F*RSf.8  A¢$!¢040HD",                    // 37 goomba flat
    "     *(!¬#q³¡[_´Yp~¡=<¥g=&'PaS²¿ Sbq*<I#*£Ld%Ryd%¼½e8H8bf#0a",         // 38 mario dead
    "   =  ³ #b 'N¶ Z½Z Z½Z Z½Z Z½Z Z½Z Z½Z =[q ²@ ³  ¶   0",           // 39 coin step 1
    "   ?@ /q /e '¤ #³ !ºa }@ N0 ?( /e '¤ #³  ¿  _a  \"",               // 40 coin step 2
    "   /  >  ]  º !² #¢ %a +  >  ]  º !² #¢ 'a  \"",               // 41 coin step 3
    "   7¢ +² *] %> \"p !Ga t¢ I² 4º *] %> \"p  ¡  Oa  \""              // 42 coin step 4
],

What does it do? If you want to look at the source file, here it is. Beware, there is more gibberish inside. I can't seem to make sense of any of it.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Those are images \$\endgroup\$
    – Kikaimaru
    Jun 21, 2012 at 8:52
  • 3
    \$\begingroup\$ By the way, don't actually do this - use base 64 or something else that fits in ASCII. Anything using non-ASCII turns into a false economy as soon as you use a character set that's not an ISO-8859 variant, and it all washes out in HTTP compression anyway. \$\endgroup\$
    – user744
    Jun 21, 2012 at 10:17
  • 4
    \$\begingroup\$ I like this question just for the title. \$\endgroup\$
    – user1430
    Jun 21, 2012 at 18:37
  • \$\begingroup\$ @JoeWreschnig how do you do it? Do you just run it through an encoding system? \$\endgroup\$
    – Codist
    Jun 21, 2012 at 20:06

1 Answer 1

6
\$\begingroup\$

There are two sets of gibberish: aSpriteData and aFont.

The former is passed to the loadSpriteData function and this is the only place it's used. The latter is used in the writeChar function and that's the only place it's used. Both are decoded by the base128ToBitString function.

So: they're base-128 encoded strings which store font and image data.

Source: CTRL+F plus following the variable and function names.

\$\endgroup\$
4
  • \$\begingroup\$ I looked through the script a second time and found that decoding function. How did the dev get these base-128 encodings of these images and fonts? Did he just run them through a base-128 encoder. \$\endgroup\$
    – Codist
    Jun 21, 2012 at 20:05
  • \$\begingroup\$ Well, unless he wanted to write them out by hand, yes probably. \$\endgroup\$ Jun 21, 2012 at 20:41
  • \$\begingroup\$ lol xD I didn't know. I know I couldn't write anything out by hand like this gibberish. \$\endgroup\$
    – Codist
    Jun 21, 2012 at 22:16
  • \$\begingroup\$ Don't worry. Anyone geeky enough to want to do that is also geeky enough to be able to just use an encoder. 8D \$\endgroup\$ Jun 21, 2012 at 22:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .