How To

How can I load larger structures in my 4x4 cell chunks


SP4CEBAR 2022-03-24 07:31

It's been a while since I last made a thread here, either way I'm working on my chunkloader engine and I recently added platforms to it, I really like the look of it and maybe I can soon make my own BroForce-like game: BetaForce. Either way, the platforms are bigger than my 4x4 cell chunks, so when they generate, they may be partially cut off because of unloaded chunks.

To fix this I think we need to find a way to load only the part of the structure that fits in the chunk that's currently being loaded To do this I'd need some sort of a seed-based random algorithm where each chunk can figure out which structures are inside of it and what the starting coordinates of those structures are

SP4CEBAR 2022-03-24 09:34

I'm currently trying to make a random sawtooth wave which starts at zero each time and has a slope of 1 and goes up to a random point before it falls back to zero and repeats
I'm trying to do this mathematically in desmos, and it's so hard!, it just wouldn't work

SP4CEBAR 2022-03-24 09:51

I think I should just go for a random square wave (like the one I'm currently using)
And then I need something that tells it what the starting coordinate of a structure is
Or I'd need do a bunch of checks, but I'm not a fan of that

SP4CEBAR 2022-03-24 09:54

I could make two of the same random square waves, each with a random height
And these values would give me an X and Y offset, or something like that, I guess

nathanielbabiak 2022-03-24 14:56

An exercise for you to try...

Draw a picture, pencil on paper, of two (maybe three, four, etc) overlapping rectangles. One represents the BG coordinate limits, one represents the loaded file, and one represents the 4x4 chunks.

Label the upper-left and lower-right corners of each with their coordinates. Use your variable names, not numbers.

...then redraw it like five more times until it's to-scale and super accurate...

Then just add some conditional if-then statements in your game engine to avoid loading stuff outside the area of interest.

nathanielbabiak 2022-03-24 14:56

Scratch that, I think I've misunderstood...

nathanielbabiak 2022-03-24 17:23 (Edited)

To get the sawtooth wave with slope=1, you actually will need the rectangle sketch exercise above. Just figure out which coordinates are "world" coordinates and then calc positions making good use of the MOD function.

SP4CEBAR 2022-03-24 23:11

Thanks for the replies!
The sawtooth I described, isn't really a sawtooth... it's more of a.. well sawtooth mountain range thingy
I did manage to make sawtooths (in my desmos experiments), but a sawtooth that climbs to a random point each time and then falls back to zero and repeats that, seems... doable at first, but turns out to be nearly impossible,

So I went for a different approach: just a random binary generator for: "1" there should be a building in this chunk, "0" there won't be a building in this chunk

SP4CEBAR 2022-03-24 23:12

And then I've used another random function inside an INT() function to determine the height of the building part in each chunk

SP4CEBAR 2022-03-24 23:15

This approach works, but I won't be able to change the starting height of a building, because I can't efficiently communicate that to neighboring chunks (they need to be able to know how to draw the building, even if the first chunk of the building isn't loaded

Log in to reply.