New games every week!
JNKrunch Blog
26th January 2013
Aaah, the joys of data compression!

OK, here's the complications with Monkey.

1. File Access is a little bit touch and go.
I've had a play with it, and sometimes it works, sometimes it doesn't.
I'm not entirely sure why this is, but.. Whatever! For the meantime, until Mark Sibly's had time to get everything perfected, I'll be staying out of it's way.

2. Can't read a raw .png
This is annoying! For the past few years, I've been getting used to using .png files to store my level data.
I've even been doing it over at PlayMyCode!
Now, I can no longer do it, and that's just plain annoying!

So, what to do about all that level data?
Well, it just so happens that I have a handy little function ready and waiting, that I first started using back at College, 15 years ago, for JNKPlat 2!
Yes, that long ago!!
-=-=-

JNKrunch()

Here's basically how it works.
It scans through a string from left to right, counts repetitions, and returns a string with both counts and characters.
Assuming your string uses plain ascii characters, the resulting string will also then contain plain ascii, and you can fling it around as required, pasting it into your sourcecode, shoving it on a forum, tweeting it, or whatever!

Examples..
Words don't usually compress well, since there's a lot of single-character events.
"Jayenkai" results in "AJAaAyAeAnAkAaAi"
... which isn't very good! But for most level-data purposes, it should be good enough.

"00000111110000011111" results in "E0E1E0E1"
E is the 5th letter in the alphabet, so that's basically saying 5 0's, 5 1's, 5 0's, 5 1's
And in this example it's resulted in a MUCH shorter string.
Much Neater!

So, there we go! I can now shove level data into neat little strings, and build separate level editors for my games.
Yum-yum!
Views 30, Upvotes 3  
2013 Framework
New games every week!
Site credits : Site built from the ground up, in php, using Programmer's Notepad 2, and a very bored Jayenkai.
(c) Jayenkai 2023 and onwards, RSS feed

Blog - JNKrunch - AGameAWeek