Procedural Hills Example
with parallax and snow tops!
Wouldn’t be possible without help from the great community on the Pico-8 Discord.
Use left and right keys arrows to move.
Restart cart to get different hills and snow.
Hey cool to see the cart in action! I saw your conversation with Valkhiya on Discord about optimizing it more by rotating the hill data one pixel to the left each frame and adding one new column to the right. It's something I'm actually using in a game I'm working on at the moment but I'm a bit too zapped tonight to work on that so instead I pulled your cart and tried to apply that technique to it!
I stripped the code down to the least amount of abstraction I could, left your sinw and topography functions in there, and jammed all the hill data into a bunch of tables that get updated each frame just like Valkhiya was talking about. Then I also cranked up the speed a little bit to really show the difference in the CPU usage when you do it this way instead of re-computing the hill data from scratch on each frame.
You can totally tell from the snow that I haven't fully understood how to call that topography function to match your implementation but hey! And anyway, those wibbly wobbly background hills in my version are accidentally very cute I think! Best of all, doing this actually helped me understand a bug in my own game that I've noticed when I mess with the speed value.
Here's a little glimpse of my cart BTW: I'm doing procedural cave generation and using this exact same trick in that.
(lol, just noticed I messed up the _init loop that should be filling the initial screen's worth of hill data. Definitely too tired to accomplish much tonight! 😆)
Hi @hen,
to avoid the background mountain jagged look the line:
add(background, topography(distance + i))
should be replaced with:
add(background, topography(distance/2 + i))
since the background is moving at half the speed, when we update it, it moved only half the distance of the foreground.
If anybody understands how the snow works with the topography function please let me know.
Thank you!
[Please log in to post a comment]