Procedural Hills Example
with parallax and snow tops!
![](/media/45599/procedural hills_7.gif)
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.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/46611/Screenshot 2020-12-04 at 11.01.48.png)
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.
![](/media/46611/proceduralhills_0.gif)
![](/media/46611/fasthill_2.gif)
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.
![](/media/46611/10_nosedive_2.gif)
(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! 😆)
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi8.png)
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]