LoginLogin

Random's Big Dumb Library + Map Editor

Root / Submissions / [.]

haloopdyCreated:
Download:N383Z4MD
Version:0.7.0Size:680KB
This is the library I'll use in my programs (if I ever make any). Oh, and there's also a map editor. It's a collection of functions that provide:
  • Noise generation (useful for terrain)
  • Prime number generation/detection
  • Kinda fast dictionaries (associative arrays/arrays indexed by strings)
  • Bit and byte vectors with automatic resizing
  • LZS compression for GRPs (both slower and worse at compression than rei's, so it's useless)
  • Various math functions
  • Debug logger for outputting messages on top/bottom screen
  • Functions for basic character movement around a map
  • Textboxes
  • Menus (built from textboxes)
  • Sound effects
  • Screen Effects (render to sprite)
  • A Turing machine?
OK but seriously, it's not good. Run RNDLIBTEST to check out some of the stuff it can do. For instance, try the Noise Gen function. It has an implementation of the Plasma effect. RNDMAP is a simple map editor. Maybe it'll be useful? But it only saves maps in a format that you have to extract with RNDLIBFULL; if anybody wants to use it, I can create another tutorial for it. https://www.youtube.com/watch?v=JDlII65rCZM https://www.youtube.com/watch?v=ZTeuFlkbtYM https://www.youtube.com/watch?v=4lY3t_yYRVQ I don't want any credit if you use this library.

Instructions:

How to use the Game Engine

Also, included in the project are EXAMPLE1, EXAMPLE2, and EXAMPLE3 which are the completed programs from the above tutorial.

How to use the map editor

Run RNDMAP. You must have RNDLIBFULL in the same folder as RNDMAP. It saves in a custom format, so use the BGMAPLOAD function in RNDLIBFULL to unpack it:
DIM MAP$,META$[0]
LOAD "TXT:MYFILE",MAP$,FALSE
META$=BGMAPLOAD(MAP$)
BUT! If you're using the map with my dumb GAME engine, you do this:
GAMEPREPAREMAP "MYFILE",3,1.0

How to use everything else:

EXEC "PRG3:RNDLIBFULL"
Run the above to make all functions available. You can make the slot whatever you like; it doesn't have to be 3.

Functions Available:

Prime Numbers:

ISPRIME(NUM) : determine if a number is prime (up to 16,383*) NEXTPRIME(NUM) : get the closest prime larger than NUM (up to 16,383*) PREVPRIME(NUM) : get the closest prime smaller than NUM (up to 16,383*) CACHEPRIMES NUM : generate the prime data for numbers up to NUM * = with default settings. Running CACHEPRIMES will change the upper range; for instance, CACHEPRIMES(100000) will change the upper bound to 100000 for ISPRIME, NEXTPRIME, and PREVPRIME Examples:
?ISPRIME(5) 'TRUE
?ISPRIME(200) 'FALSE
?NEXTPRIME(20) '23
?NEXTPRIME(11) '13
?PREVPRIME(10) '7
CACHEPRIMES 100000 'Takes a little bit
?ISPRIME(99999) ' FALSE

Bit/Byte Vectors

GETBIT(BIT,VECTOR%) : Get the bit (0 or 1) for the position BIT within the given bit vector* SETBIT BIT,VALUE%,VECTOR% : Set the bit for the position BIT to the value VALUE (0 or 1) within the given bit vector* GETBYTE(BYTE,VECTOR%) : Get the byte (0-255) for the position BYTE within the given byte vector* SETBYTE BYTE,VALUE%,VECTOR%) : Set the byte for the position BIT to the value VALUE (0-255) within the given byte vector* * = A bit/byte vector is just an integer array. You can use existing arrays; the data is treated as though it is packed. Examples:
DIM V%[0] 'A bit/byte vector is just an integer array
?GETBIT(0,V%) '0
SETBIT 5,1,V%
?GETBIT(5,V%) '1
?GETBYTE(65,V%) '0
SETBYTE 12,128,V%
?GETBYTE(12,V%) '128
?GETBIT(103,V%) '1 (we set that bit with the previous SETBYTE)

Dictionary

DICCREATE$(INITIALSIZE) : Create a dictionary with the given initial capacity (can be 0) DICGET$(KEY$,DIC$) : Retrieve the value* from dictionary DIC$ at the given key (returns "" if key doesn't exist) DICSET KEY$,VALUE$,DIC$) : Set the value* for the given key in dictionary DIC$ (adds key if key doesn't exist yet. Increases capacity automatically if dictionary is getting full) DICHASKEY(KEY$,DIC$) : Return whether or not dictionary DIC$ has the given key. DICRESIZE DIC$,NEWSIZE : NOT NECESSARY TO CALL. Increase capacity to at LEAST given size. Will only increase dictionary size. Actual size set may be different. * = float and integer versions are available: DICGETI%, DICGETF#, DICSETI, DICSETF Examples:
DIM D$[0] 'A dictionary is just a string array.
D$=DICCREATE$(10) 'Set initial capacity to a large value for faster insertion. Resizes automatically regardless
?DICGET$("MYKEY",D$) 'Prints nothing
DICSET "MYKEY","HIHI", D$ 
?DICGET$("MYKEY",D$) 'Prints HIHI
DICSETI "MONKEYS",53,D$
?DICGETI%("MONKEYS",D$) 'Prints 53

Math Crap

DISTANCE(X1#,Y1#,X2#,Y2#) : Get the distance between two points CLOSESTMULTIPLE(NUM,MULT) : Get the closest number to NUM that is a multiple of MULT. LERP(A#,B#,T#) : Get the value for linear interpolation between A and B at point T. BLENDCOLORS(COL1,COL2,SHIFT#) : Blend two colors together. SHIFT# tells how much of the second color to add (0 is all the first color, 1 is all the second color, 0.5 is a perfect blend) BRIGHTENCOLOR(COL,AMT) : Brighten color by given amount. This is a linear shift: all channels are increased by the given amount. If the amount goes over 255, it is capped. BRIGHTENCOLORM(COL,M#) : Bright color by given multiple. This is much more like the "brightening" you would expect: each channel is scaled by the given amount, which keeps the overall color roughly the same. Use this version if you expect real brightening. SIGN(X) : Gives the sign of X. Returns 1 if X>0, -1 if X<0, and 0 if X==0. Examples:
?DISTANCE(1,2,2,2) '1
?DISTANCE(1,1,2,3) '2.236...
?CLOSESTMULTIPLE(10,3) '9
?CLOSESTMULTIPLE(12,5) '10
?LERP(5,10,0.5) '7.5
?BLENDCOLORS(&HFF00FF00,&HFFFF0000,0.5) ' &HFF777700
?SIGN(-5) '-1
?SIGN(5) '1

String Stuff

STRINGJOIN$(ARRAY$,JOINCHR$) : Join an array of strings together and place JOINCHR$ between them. STRINGSPLIT$(STRING$,DELIM$) : Split a string into an array using the given character as a delimiter. SARRAYTOSTRING$(ARRAY$) : Convert a string array into a single string. This can be used to turn dictionaries into single strings. STRINGTOARRAY$(STRING$) : Convert a string converted with SARRAYTOSTRING back into a string array. This can be used to unpack dictionaries (if you pack them into a single string with the above function). Examples:
DIM A$[0]
A$=STRINGSPLIT$("DATA1/DATA2/SOMETHING/WHATEVER","/") 'An array with 4 elements: DATA1, DATA2, SOMETHING, WHATEVER
?STRINGJOIN$(A$,"%") ' DATA1%DATA2%SOMETHING%WHATEVER

Noise Generators

There are currently two noise generator functions: DIAMONDSQUARE2D# and HILLGENERATOR#. Both return a 2D array filled with values ranging from 0-1 (floating point). DIAMONDSQUARE2D#(N,WIDTH,HEIGHT,SEED,DECAY#,CURVE#) HILLGENERATOR#(WIDTH,HEIGHT,SEED,HILLCOUNT,MINRADIUS#,MAXRADIUS#,CURVE#,CIRCULAR) In DIAMONDSQUARE2D#, N is the "chunk" size and width/height are the chunks across/down. Chunk size is 2N. So, the final map size will be 2N*WIDTH by 2N*HEIGHT. This is just how Diamond-Square works. The chunk size will determine the "feature" size, so a larger N will make the landscape "bigger" while a smaller one will give more details. N=2 is the smallest you should go, and remember that it's 2N so making it like 15 might cause an out of memory error. DECAY# basically determines the noisiness (smaller = less noise) and CURVE# flattens out the areas (higher = flatter). HILLGENERATOR# raises HILLCOUNT circles in a WIDTHxHEIGHT area. The minimum and maximum circle radius can be set. CIRCULAR does nothing right now, but in the future it will generate something akin to an island. CURVE# does the same thing as before: flattens out areas wither higher CURVE# values. Examples:
DIM D#[0,0]
D#=DIAMONDSQUARE2D#(3,16,16,MILLISEC,0.8,1) 'D will be 128x128
'Do something with the float values in D#

Textboxes

Textboxes are simple boxes which display formatted text with automatic line breaking and scrolling. They are drawn on the GRP layer of your choosing. They are nowhere near finished, but maybe they're a little usable... not really. Textboxes are HIGHLY customizable, so there's a lot of settings and it might get confusing. I'll add a wrapper around customization in the future so it's easier, but for now, I would stick with the default settings. Textboxes are OBJECTS, so you will need to create the textbox object, then pass that object around to all the functions. Keep this in mind when you're looking at the following examples: Examples:
DIM TB$[0]
TB$=TBCREATE$()
'DICSETF "CHRSCL",2.0,TB$ 'Uncomment this to see text scaling in action

DIM TEXT$="Look at all this text that we're outputting to the screen! Too bad it's not enough to make it scroll."
TBSHOW TB$ 'Draw textbox
TBTEXT TBFIX$(TEXT$,TB$),TB$ 'Show text with automatically-inserted elements (such as the pause at the end)
TBHIDE TB$
You can also load TESTTB to see a test program for textboxes.

Menus

Every game needs a menu somewhere. Most of the time, unless it's the MAIN menu, you're just selecting from a small set of choices. Why program this every time you need it when you can have an automatic menu that matches your textboxes? Menus work a lot like textboxes, except that they require more setup. Since they require more setup, I've created a "quick" function which does all the setup for you. Maybe one day I'll go over the ridiculous amount of customization, but for now, this'll have to do. Menus can be placed anywhere on the screen, HOWEVER, unlike textboxes, they can be "anchored" to a corner other than the top left. For instance, if you set the menu's X and Y to 0 and you specify the anchor as the bottom left, the 0,0 will now mean the bottom left. Menus can be anchored to any of the four corners; the default is the lower right (for use with textboxes). Furthermore, even though menus are built from textboxes, they will ignore their width, height, and text location settings since menus are automatically sized to fit the text they are displaying. Examples:
DIM MN$[0]
MN$=MENUCREATE$()

DIM OPT$[0]
PUSH OPT$,"Kittens"
PUSH OPT$,"Puppies"
PUSH OPT$,"Echidnas"
PUSH OPT$,"Bunnies"

DIM SELECTED=MENUQUICK(OPT$,MN$)

IF SELECTED>=0 THEN PRINT "You've selected: "+OPT$[SELECTED] ELSE PRINT "You cancelled!"
You can also load TESTMENU to see it in action. I use STRINGSPLIT to create the list of options in that program.

Turing Machine

Why use this? IDK. Run RNDLIBTEST, then select "Toys" at the main menu, then "Turing". This is a Turing "editor" and "debugger" all in one. -Left panel of 0's = test tape (circular). Use CPAD to move head up/down, left/right to alter symbol manually. -Main area is state list. Each state can perform 3 actions based on input (only 3 inputs for the debugger: 0,1,S). -W = write symbol, M = move head, S = next state. -DPAD to move around state/action list. A=change action, B=clear -X = menu. Can load/save turing machines or clear current -Y = run next Turing step using current head position and current state. Holding Y will run machine at 30fps. machine will beep if runs into halt state -Empty = no write, no move, or halt state. I'll add the others later or something.

Notes:

Changes:

0.7.0

  • Added a Turing machine
  • Added some string functions (RPAD, LPAD, STRREPLACE)

0.6.1

  • Fixed file select menu crash for rndmap
  • Fixed REMOVECHUNK incorrect removal

0.6

  • Added a BG map editor called RNDMAP
  • Added more functions for saving/loading backgrounds
  • Updated the game library functions to work... better? Old programs won't work with the new library.

0.5

  • Simple Game Engine superseded by just Game Engine which is faster and better
  • Fixed some textbox bugs; can disable animations now
  • Added easy textbox coloring; sets a pile of colors all automatically
  • Textbox text selection color (menus, input) can be set separate from regular text color
  • Added test library to test all the crap
  • More sound effects
  • The beginning of a framework for stacked special effects using render to sprite.
  • Stuff for automatic path smoothing (if you follow my BG tile order (which I haven't posted yet))
  • Diamond-square noise generator
  • Hill-raising noise generator
  • A simple frame timer
  • Path snaker (useful for rivers/paths/whatever)
  • Scaled GCOPY (slow but useful maybe)
  • Convert between reals (0-1) to grayscale, tricolor, and hue wheel
  • Convert button directions to angles
  • Rotate points around an origin

0.4

  • Dictionaries are now much faster and should keep their constant access time for much larger dictionaries. Dictionaries up to 1000 elements now have roughly the same access time as dictionaries with 100.
  • Added menu system. Menus can be anchored to corners of the screen and use many of the same options as textboxes.
  • Added string functions for splitting/joining/etc.

0.3

  • Made dictionary work for single character keys (it would crash before)
  • Made dictionary lookup twice as fast for keys which resort to linear scan.
  • Added the textbox library

0.2

  • Fixed dictionary functions so it actually hashes correctly now
  • Added the beginnings of Simple Game Engine stuff.
In the future, I want to add:
  • Textbox wrapper functions so it's easier to use
  • An RPG Library

Replying to:Midnight
Please tell me the "main features" of the text-box library.
I think I understand most of it save for "the control characters." It seems like it has the basics included with your ... 3rd released text-box thing on PTC, but it has a lot more customization and fancy tweaks like smooth scrolling and the animated displaying and removal. Do you have an example program you used it in? Also, y'know how this allows you to control pauses as text is printed or something? I tried modifying the ... 1st text-box thing you made, but I don't think I'd saved it. I had put delays during the printing of some text or changed the pitch/sound effect maybe of others. "High pitched quick text would have a surprising feeling; low pitched slow text would have a creepy feeling." 'Sound effect.' Does your newest one play any sounds as text is printed? Either way, it sounds awesome. I'm stubborn to change and usually not motivated to download SmileBASIC Programs so it might take while, if at all, for me to move from the first text-box thing you made to the newest. -w- I wonder what you're going to use this library for.
SpoilerI have a guess.

Replying to:Midnight
Please tell me the "main features" of the text-box library.
Control characters allow you to change how the textbox operates while it's running. For instance, you can do: "This is `S2;MY`S1; house!". The `S2; and `S1; are commands which change the size of text, so after it processes `S2; the MY is now twice as big. Then we do `S1; which changes it back to the original size. There are settings in the textbox object that let you change the control characters (the ` and the ;) in case you really need to use ` in your text (; can be used without issue, but if you use ` is interprets it as a command). If you download this library, you can run TESTTB to see examples. It runs several textboxes that test various features. Yes, this one has sound effects for text output, textbox display, textbox hiding, and continue. This library is just going to be part of the game library I'm working on.

Replying to:Midnight
Please tell me the "main features" of the text-box library.
nice

Hail randomouscrap.

SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255

Replying to:12Me21
SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255
Wow... wow, it's called SGN instead of SIGN? Like... they have CEIL, why can't they have SIGN? They can't say "compatibility" because SB isn't even compatible with old BASICs. I don't trust that functionality to remain the same, so I'll stick with forcing it to be rounded down. I didn't know about DIV being integer division though, so I can do that. I also don't trust THAT functionality to remain the same. I would rather have slower functions with known results than faster functions that *MIGHT* not work in an update where they decide to use modulus instead of MAX. But thank you for the info!

Replying to:12Me21
SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255
Also, I noticed you sometimes use #FALSE/#TRUE and sometimes FALSE/FALSE.... MAKE UP YOUR MIND!!!!

Replying to:12Me21
SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255
Hey that's YOUR fault! >:P You told me #TRUE and #FALSE were faster when I was in the middle of writing the library, so I switched over. Nobody's gonna use this thing anyway, so I'll just switch TRUE to #TRUE when I come across them.

Replying to:12Me21
SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255
I think the speed difference is so small that it might be better to pick the one that you think looks nicer, rather than the one that's 0.00001% faster.

Replying to:12Me21
SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255
constants are faster but only by such a micron of difference you're better off dedicating optimization elsewhere. Like SGN. It's been called that since PTC, come on. Even if they DO make a new SB (probably wont) they're not gonna change it

Replying to:12Me21
SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255
I'm sorry, I was just mindlessly complaining. I just didn't see SGN in the reference because I was looking for SIGN. I should've looked harder.

there is a little error in textboxes a part says tbchrsize$

Replying to:hakke
there is a little error in textboxes a part says tbchrsize$
That can be fixed (as you may have already figured out) by taking off the $ from that function call.

Replying to:Mochameinko
Interesting. Also, thanks for taking my image, lol.
Really? (*vOv )

LZS Loading zone storage? i like markdown

Replying to:IAmRalsei
LZS Loading zone storage? i like markdown

Replying to:IAmRalsei
LZS Loading zone storage? i like markdown
oh. i thought it was loading zone storage from Paper Mario Loading Zone Storage storage doesn't make sense tho lol

Why was my comment here deleted? All I asked was how to make a textbox in the code and put it anywhere throughout the code since I can't seem to be able to do so with this library.

Replying to:Arkzen
Why was my comment here deleted? All I asked was how to make a textbox in the code and put it anywhere throughout the code since I can't seem to be able to do so with this library.
Oh your comment was deleted? I'm sorry; maybe something got messed up. Anyway, I really do need to make a tutorial for the textboxes. You said you want to be able to use the textbox anywhere in the code? Look at uhh... https://smilebasicsource.com/page?pid=965#Textboxes That should give you the basic idea (hopefully). You don't have to look at the stuff before or after the textboxes section (unless you want to). If you put the textbox initialization stuff at the top of your code (the array, TBCREATE, etc.), you can then call TB[HIDE/SHOW/TEXT/WAIT] with the textbox object anywhere in your code. If you still need help, let me know. Some of the textbox customization stuff can be found here: https://smilebasicsource.com/page?pid=972

What about 3D?