ericb [Lexaloffle Blog Feed] Picopelago <p> <table><tr><td> <a href="/bbs/?pid=134179#p"> <img src="/bbs/thumbs/pico8_picopelago-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=134179#p"> picopelago</a><br><br> by <a href="/bbs/?uid=68442"> ericb</a> <br><br><br> <a href="/bbs/?pid=134179#p"> [Click to Play]</a> </td></tr></table> </p> <p><strong>Create landscapes or sit back and watch them change over time</strong></p> <p>Picopelago is a <strong>terrain toy</strong> in 1024 bytes. It includes a <strong>screensaver mode</strong> which generates landscapes and a <strong>draw mode</strong> where you can shape them yourself</p> <p>As time passes, erosion smooths out rugged terrain</p> <p>As mountain peaks reach the sky, the landscape sinks into the sea</p> <h2>Controls</h2> <ul> <li><strong>(▲)</strong>/<strong>(▼)</strong>/<strong>( X )</strong> to navigate main menu</li> <li><strong>Mouse</strong> or <strong>touchscreen</strong> required for draw mode</li> <li><strong>Enter</strong> and choose <strong>&quot;Reset Cart&quot;</strong> to return to main menu</li> </ul> <img style="margin-bottom:16px" border=0 src="/media/68442/picopelago p8_4.gif" alt="" /> <h2>About</h2> <p>Created for <a href="">PICO-1k Jam 2023</a> (code is 1024 bytes after minification &amp; compression)</p> <p><a href="">Commented source code (github)</a></p> Mon, 11 Sep 2023 16:14:51 UTC Player Piano: Maple Leaf Rag <p> <table><tr><td> <a href="/bbs/?pid=121275#p"> <img src="/bbs/thumbs/pico8_playerpiano-4.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=121275#p"> Player Piano: Maple Leaf Rag</a><br><br> by <a href="/bbs/?uid=68442"> ericb</a> <br><br><br> <a href="/bbs/?pid=121275#p"> [Click to Play]</a> </td></tr></table> </p> <p>On this day 154 years ago, Scott Joplin was born. Happy birthday to the King of Ragtime!</p> <p>Here's a rendition of his famous Maple Leaf Rag, with accompanying animation.</p> <p>I've been trying to learn this piece on piano for a while. At some point I thought it might be fun to try transcribing it in PICO-8, and this is the result! Information on the music and animation is below:</p> <h3>Music</h3> <p>I tried to stay as true to the score as possible - since I was limited to only 4 channels, I had to make creative use of instruments and effects. So even though it's all just piano, there are 5 different instruments used:</p> <ul> <li>normal held note</li> <li>held note that's one octave down (for the low note at the start of the run that goes all the way up the piano)</li> <li>held note with simultaneous octave down (using detune)</li> <li>staccato note</li> <li>staccato note with simultaneous octave down (using detune)</li> </ul> <p>Since this piece makes heavy use of octaves in the bass and the accented parts of the melody, the detune trick was a huge help in getting all of the notes in (there are a lot of notes!). The detune emphasizes the lower note over the higher one, but I think it sounds convincing enough. Even with this trick, there were a handful of places I had to leave a note out of a chord, but I tried to leave out notes which were the least important/noticeable (eg. repeated nearby in either the bass or melody, or notes less important to the character of a chord, like prioritizing the 3rd/7th over the 5th). I think unless you know this piece really well and closely watch the animation, it would be pretty hard to notice the missing notes.</p> <p>There weren't quite enough sfx slots to fit the last section of the piece, so I ended up arranging that in a separate cart and then putting it into the map data using CSTORE(). Partway through playback, I swap out some sfx that are no longer needed for the ones used in the last section.</p> <h3>Animation</h3> <p>The animation is all dynamic, based on the SFX data. Which is nice, because once I got it working I could change the sfx or add new parts and the animation would continue to reflect the music.</p> <p>As for how it works, I wrote a function GETNOTES() which takes as parameters a time offset and returns a list of the notes that would be playing. I'm using STAT(54) to get the index of the currently playing pattern, and STAT(56) to get the current tick within it. With that information, I can add the time offset and use PEEK() to determine which pattern/sounds would be playing at the requested time and get the note information. By checking the pitch along with which instrument voice is playing a given note, I can figure out which keys should be pressed. For the detune notes that means playing two keys at once an octave apart. For staccato notes or notes with the fade out effect the key lets off earlier in the beat.</p> <p>For the animation of the actual keys, I call GETNOTES() without a time offset to get the currently playing notes. Each of the keys is rendered with a sprite, and we can look up whether the key's note is being played to determine whether we should draw its pressed or unpressed sprite.</p> <p>For the piano roll, I call GETNOTES() with a different time offset for each line, and for all the notes returned I use PSET() to change the colour at the coresponding spot on the roll (adjusting for perspective and scaling so the 88 notes of the piano span 44 horizontal pixels). Since it's all offset based on what's currently playing, doing this every frame naturally makes the dots scroll down the screen as if the roll is moving.</p> <h3>Other thoughts</h3> <p>If you'd like to see how it works in more detail, the code is reasonable well-commented so take a peek inside :) You could probably use a similar approach to automatically synchronize things in a rhythm game.</p> <p>I also think it would be cool to transcribe more pieces of piano music and make this into a series -- you could even fit multiple songs in a single cart by using PX9 compression or similar, since the current code doesn't use very many tokens/characters. But it took me quite a while to transcribe just this one piece, and styles with more sustained notes / big chords wouldn't work well with PICO-8's limitations, so I'll leave it at this for now.</p> Thu, 24 Nov 2022 16:05:07 UTC Into Ruins <p> <table><tr><td> <a href="/bbs/?pid=119614#p"> <img src="/bbs/thumbs/pico8_intoruins-6.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=119614#p"> Into Ruins</a><br><br> by <a href="/bbs/?uid=68442"> ericb</a> <br><br><br> <a href="/bbs/?pid=119614#p"> [Click to Play]</a> </td></tr></table> <br /> <em>Reach depth 16 and retrieve the Wings of Yendor</em></p> <h1>Controls</h1> <p><strong>(◀)(▶)(▼)</strong> : Turn</p> <p><strong>(▲)</strong> : Step forward / Attack / Interact</p> <p><strong>(X)</strong> : Open inventory</p> <p><strong>(O)/Z/C</strong> : Wait 1 turn</p> <img style="margin-bottom:16px" border=0 src="/media/68442/intoruins_main_22.gif" alt="" /> <p>Into Ruins is a roguelike for the PICO-8 Fantasy Console.</p> <p><strong>There are no stairs</strong>. Jump down <strong>holes</strong> in the ground to make your way to the bottom. You will encounter <strong>natural cave formations</strong>, <strong>crumbling dungeon rooms</strong>, and <strong>terrifying creatures</strong> on your way.</p> <p><strong>There are no doors</strong>. Tread carefully or the creature in the next room might spot you. <strong>Light</strong> helps you explore more easily, but also reveals you to your foes. <strong>Fires</strong> can spread wildly through the environment, while <strong>glowing mushroom spores</strong> can mend your wounds.</p> <p><strong>There are no classes or character levels</strong>. Expand your abilities by finding <strong>magical items</strong> on your descent, and bring them to their full potential with <strong>Orbs of Power</strong>.</p> <p><strong>Each attempt is a new beginning</strong> &mdash; the different types of <strong>orbs, staves, cloaks</strong> and <strong>amulets</strong> will not be immediately recognizable to you. Some experimentation is required to identify them. </p> <img style="margin-bottom:16px" border=0 src="/media/68442/intoruins_main_12.gif" alt="" /> <h1>Credits</h1> <p>Into Ruins was created by <strong>Eric Billingsley</strong>. It was greatly inspired by <strong><a href="">Brogue</a></strong> by <strong>Brian Walker</strong>.</p> <p>Thanks to <strong>FReDs72, Heracleum, James Edward Smith, morgan, Oli414, Sim, SlainteES, SmellyFishstiks</strong> and <strong>Waporwave</strong> for beta testing and feedback.</p> <img style="margin-bottom:16px" border=0 src="/media/68442/cavedunj_0.png" alt="" /> <h1>Technical Info</h1> <p>I figured some of you might be interested in some of the technical aspects of the game. This was my first foray into PICO-8 and Lua, and I learned a lot along the way -- from discovering with shock that variables are global by default after a week and a half of strange bugs, to trying to cram as much as possible into strings, and _ENV abuse to reduce token count.</p> <h2>How does it all fit?</h2> <p>Initially I thought I could fit everything into 1 cart, but partway through I realized that even if I could fit all the features I had planned in while respecting the token limit, the compressed character limit would be a problem.</p> <p>The final version of the game is in 2 carts -- one for the title screen and text intro, and another for the main game. The title screen cart also puts a huge string containing most of the game's data (creature stat blocks, animation data, item stats, text descriptions) into the upper memory region, which is then read and parsed by the main cart. Because the title screen still displays the environment and character, there's a lot of similar code between the two carts, though a lot of things that were refactored to save tokens in the main cart are still in the title cart in their original form.</p> <p>Even with these measures, the main cart still needed to be stripped of comments, newlines, and whitespace using <a href="">shrinko8</a> to fit within the compressed character limit.</p> <p>As far as tokens go, making almost everything in the game be the same type of object went a long way. Each object has a type (which is just its sprite number), and from that we can initialize its properties with a combination of default values and ones read from the huge string mentioned earlier. Having everything be intialized and accessed the same way means that each object has a lot of data it doesn't actually need, but we aren't strapped for Lua memory so that's okay! The upside is we can reuse code where appropriate, and make things interact more easily. To save tokens on accessing properties, I also made heavy use of the <a href="">_ENV trick outlined by slainte here</a>, and <a href="">seleb's list of token optimizations</a> was indispensible as well.</p> <h2>Level generation</h2> <img style="margin-bottom:16px" border=0 src="/media/68442/intoruins_main_50.gif" alt="" /> <p>The levels are generated using a couple different algorithms. Levels can contain natural caves, manmade dungeon rooms, or both. In either case, there is a variable called <em>Entropy</em> which ticks down as more of the level is generated.</p> <h3>Caves</h3> <p><strong>Caves</strong> are made recursively using a type of random walk. From our current position, we try to generate another tile in a random neighbouring space. We then decide whether to recurse again from this position or backtrack -- this probability is based on the current entropy, so at the start we always continue, and by the end backtracking is more likely. Playing with the starting entropy and the amount it goes down by with each recursion allows us to achieve the right density and balance between narrow tunnels and wide open areas.</p> <p>When choosing which tile to put in a new space, we consider the tile we are generating from. Each tile type has a corresponding section of the map data which defines 16 possibilities for the next tile, so we choose one at random from these. In a way this is like a <a href="">Markov Chain</a>, where the state is just based on the tile we are coming from. Holes, grass and other environmental features are all generated this way. The tile definition can also include an entity to generate, like a mushroom, brazier, chair or barrel. </p> <img style="margin-bottom:16px" border=0 src="/media/68442/intoruins_main_0.png" alt="" /> <p>With each recursion, there's a very small chance we switch to generating <strong>rooms</strong>.</p> <h3>Rooms</h3> <p>For <strong>rooms</strong>, we choose a random point on the map which will be contained in the room, and then random values for the room's width and height. The boundaries of the room are clamped to multiples of 2 or 4 to get them to lock together well and play nice with the rendering. We then create the floor and walls of the room, with one dimension being staggered to fit properly into the hex grid. Each room gets a random <em>crumble</em> value, which we use to decide if we should replace parts of the wall with different tiles (selected in the same way as in the cave generation). </p> <p>After generating each room, there's a chance we switch to cave generation. Otherwise, we keep generating rooms at random positions until the entropy reaches 0. The rooms can overlap each other, and each time we generate one, a random <em>openplan</em> variable sets whether it should have walls on all sides, or try to merge with any overlapping rooms. In this way, we can get all kinds of interesting dungeon shapes just by combining rectangles.</p> <h3>Post-processing</h3> <p>Once the initial generation is complete, we analyze the level to find parts that are inaccessible, and then find a nearby position the player can get to and connect them in a straight line, either by building bridges or tunneling through walls. Then we recurse randomly through the level and fill out the contents of the manmade rooms, in the same way we did with the caves earlier.</p> <p>There are a few more steps, like creating cave walls, ensuring there are exit holes, and running the code to connect areas again at various points. One interesting step is to replace cave walls which have walkable tiles both below and above them with a random tile, again sampled from the map data. This is actually the only way that stalagmites and mushrooms can be generated, and I think it makes their placement a bit more natural looking.</p> <h3>Spawning</h3> <p>With the environment generated, all that's left is to spawn creatures and items. </p> <p>Creature spawn groups are again defined in the map, with each line corresponding to a different depth. We attempt 6 times to spawn a group of creatures, either choosing a group from the current depth or sometimes randomly from a greater one for a nasty surprise. We pick a random position, and try to spawn a creature there, and then move on to a to a neighbouring tile for the next one in the group. If it turns out the spawn point is invalid, we don't try again, just move on. This means some levels, especially smaller ones, will tend to have fewer creatures but that's okay -- it just adds variety!</p> <img style="margin-bottom:16px" border=0 src="/media/68442/intoruins_main_2.png" alt="" /> <p>Items are spawned in a similar way, with the depth just affecting how many we try to spawn (we attempt to spawn slightly more items on earlier depths than on later ones). For certain important orbs, we make extra spawn attempts if there haven't been enough of them generated yet over the course of the game based on the current depth.</p> <h3>Wrap-up</h3> <p>There's a lot of other things that I think could be interesting to write about, like the lighting, FOV algorithm, or various aspects of the AI, but for now I think this post is long enough. Let me know if there's anything you'd like to hear more about!</p> <p>Into Ruins is also <a href="">available on</a>, and the unminified code is up <a href="">on Github</a>.</p> <h2>v1.06 changes</h2> <ul> <li>Web player touch controls (itch &amp; newgrounds only): removed ability to input a diagonal on the d-pad by pressing in between two directions.</li> <li>Web player touch controls (itch &amp; newgrounds only): removed ability to input simultaneous X and O by pressing in between both buttons. </li> <li>Fixed cursor being off by 1 pixel vertically when aiming</li> <li>Adjusted aiming prompt text alignment</li> </ul> <h2>v1.05 Changes</h2> <ul> <li>Added custom font</li> <li>Clearer text descriptions for Orbs of Gravity and Light</li> <li>Fixed searching enemies sometimes moving after spotting you</li> <li>Fixed orbs not activating when thrown at enemies flying over a hole</li> <li>Fixed Pink Jellies having the wrong icon when hit with an Orb of Data</li> </ul> <h2>v1.04 Changes</h2> <ul> <li>Increased chance that a given spawned item will be a &quot;fun&quot; orb (fire, ice, teleport) -- other items will spawn slightly less often as a result</li> <li>Improved several movement animations (player &amp; some enemies) that had incorrect timing</li> </ul> <h2>v1.03 Changes</h2> <ul> <li>Increased chance of spawning a weapon or staff until at least one has been spawned</li> <li>Increased chance of spawning an uncursed wearable item until at least one has been spawned</li> <li>Flesh Horrors have a new unique ability...</li> <li>Frozen enemies no longer display &quot;?&quot; when switching to searching state</li> <li>Fixed player appearing not to die on game over screen when killed while being pushed down a pit with slofall active</li> <li>Fixed a visual glitch that would happen if you blinked to victory</li> <li>Fixed player not casting light until taking a step after descending while on fire</li> <li>Fixed creatures not casting light until next turn when they catch fire from being in light</li> <li>Fixed tiles not catching fire if a burning creature moves onto it and either dies or stops burning immediately after</li> <li>Fixed creatures with idle animations still animating while frozen</li> </ul> <h2>v1.02 Changes:</h2> <ul> <li>Improved fire animation (was intended to flip horizontally every 3 frames, but I accidentally broke this before release)</li> <li>Changed text description for Orb of Light for improved clarity</li> </ul> <h2>v1.01 Changes:</h2> <ul> <li>You can now pick up &lt;important item&gt; even if your inventory is full.</li> <li>Fix a rare bug where 2 Mirrorshards could teleport into the same space, with strange effects. </li> <li>Increase Mirrorshard HP from 6 to 8</li> </ul> Thu, 27 Oct 2022 14:52:50 UTC midi 073 Flute <p> <iframe src="sfxp.php?id=68442_0" width="769" height="97" style="border:none; overflow:hidden"></iframe><a style="cursor:pointer; font-size:8pt" onclick=' var el = document.getElementById("sfxcode_68442_0"); if ( == "none") = ""; else = "none"; microAjax("/bbs/sfxc/68442_0.txt", function (retdata){ var el = document.getElementById("sfxcode_68442_0"); el.innerHTML = retdata; el.focus();; } ); '> [sfx] </a> <textarea rows=3 class=lexinput id="sfxcode_68442_0" style="width:480px;background-color:#fed;display:none;overflow:hidden; font-size:4pt;"></textarea> </p> <p>Here's a flute I made for a track in my current project. I tried to capture the breathy harmonics that happen on the attack of a note. After the note is held, it goes into a looping tremelo.</p> <p>I didn't switch on the reverb here, but I am using it with medium reverb on the pattern in my track.</p> <p>For a softer sound, you can use the fade-in effect (4), or alternate between fading in and hard attack for more variety in sound. I've also had success with using a fast arpeggio between 2 notes for a trill effect.</p> <p>Feel free to use it in your projects under CC4-BY-NC-SA license. Enjoy!</p> Mon, 26 Sep 2022 03:06:06 UTC