Log In  

Cart #up-1 | 2020-01-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

(01-02-20) If you just want to see it in action, try out the cart above and examine the source-code. For a more detailed demonstration including compression, try out the cart below this.

Cart #sccm-4 | 2020-01-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3
TO LOAD THIS CART in Pico-8, in immediate mode type:

load #sccm

UPDATE (01-01-20) Removed all loose global variables.
UPDATE (12-31-19) Tightened code slightly.

The mapper for Pico-8 is a good idea, isn't it ? But maybe it doesn't cover all the space you need for all the levels you want in your game. Thus I have made (especially for Scrubsandwich) two useful functions.

One compresses map data to a 6-bit string.
The other decompresses map data from that 6-bit string.

And why would you use a string do you ask ? Quite simply so you can include it directly in your code.

To make use of the first function, STR=COMPRESMAP(H,V,X,Y)

Understand the 5-arguments used for this function:

  1. Where H and V are the top-left hand coordinates of the map you wish to compress.
  2. Where X and Y are the number of tiles across and down for the map you wish to compress.
  3. Where STR is the string that is recorded to.

For instance if you wanted to compress mapper data starting from coordinates 0,0 to 15,15 and wanted to save it in the string called "ROOM" that would be:

ROOM=COMPRESMAP(0,0,15,15)

Room would then be a 6-bit string of about 214-chars. Less if there were less tiles in that area.

. . .

The 2nd function is DECOMPRESMAP(H,V,STR)

Understand the 3-arguments used for this function:

  1. Where H and V are the top-left hand coordinates of where you will overwrite existing mapper data.
  2. Where STR is the 6-bit string that contains the mapper data you wish to overwrite at this position.

For instance if you wanted to decompress mapper data starting from coordinates 0,0 and wanted to use the 6-bit string called, "ROOM" that already contains the mapper data you want, that would be:

DECOMPRESMAP(0,0,ROOM)

Understanding that the SIZE of this map is already encoded in the 6-bit string and does not need to be entered later for decompression.

Thanks big to @merwok for considering using a function within a function. Works great and frees up the need to have true exposed global variables remaining after you compress or decompress.

ALSO important, forgot to mention. I am using the number 255 as a reference to compression so you CANNOT use sprite #255 in here if you want to maintain the compression. Nothing else is needed. You're still welcome to use all the sprites #0-254.

. . .

If you want to save the newly compressed 6-bit map string to your cart, in immediate mode type:

printh(t,"@clip")

Which will save it to your clipboard.

Then in your new cart, type out:

mapp="

(or whatever variable you want to create) with an opening quote. Press CTRL+V, then an ending quote "

Include the CHAR6 routine above and the DECOMPRES() function below and it's all you need !

And that's it. Feel free to try out this demo and examine the source-code to see how it was done. I hope you find these two functions useful and instrumental in your code.

Comments, Questions, Kerosene :) Let me know.

P#71599 2019-12-31 19:59 ( Edited 2020-01-02 17:47)


[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-04-05 20:33 | 0.049s | 4194k | Q:44