Log In  
Follow
ozjerry
[ :: Read More :: ]

Cart #animdungen-0 | 2024-05-14 | Embed ▽ | License: CC4-BY-NC-SA
5

This is an animated version of a procedural dungeon generator. It was inspired by a blog post (details below), which included a number of animated demo's which I found quite hypnotic to watch. So I built this to emulate the demo. I also have a cut-down version which runs straight through and generates a full dungeon in one hit. In hindsight I should have probably built the run-through version first and then expanded it out to animate it as I think that would have made for more efficient code.
The generated 'dungeon' is a 2D array of cells, each of which has a type of either wall, passage, door or room (represented by number constants). It could potentially be translated to a simple grid of numbers representing colours or a tilemap, or used as the map for a raycasting 3D game.

Controls

There is a minimalist menu system allowing you to choose the size/density of the dungeon layout. Choose the option you want using the up/down arrows and then 'X' to select and run. Once the dungeon has finished generating you can press 'X' again to bring the menu back up and generate a new maze.

Background

This was inspired by an old article by Bob Nystrom on his blog here. I was googling around for procedural dungeon generator algorithm and came across the article. My version isn't an exact translation of his code as his is in Dart, which I don't understand. So I just built it using his basic principles, outlined below:

  • Create a number of random, non-overlapping, rooms
  • Carve passages into the remaining space with a maze generator
  • Join each of the rooms to the adjoining passage using one door for each room-passage connection, then add a few extra random doors so that the whole maze is not perfect.
  • Remove all the dead-ends

I'll also publish the version that runs straight through, once I've tidied it up a bit.

P#148376 2024-05-15 00:39

[ :: Read More :: ]

Cart #puniyasaba-0 | 2024-05-08 | Embed ▽ | License: CC4-BY-NC-SA
9

Generates a random maze, then places the player in the middle of it and ensures that you're not staring straight at a blank wall. Find your way to one of the corners and it will reset with a new maze and plonk you back in the middle. Not really intended as a game, just a learning exercise for me and the hope that the code will be of use to someone with more creativity than myself:)

Controls

Arrow keys to move forward/backward and turn.
Z/X will sidestep left and right
Hitting 'P' at any time will generate a new Maze and place the player in the middle of it.

Background

This is an extension of my previous raycaster. I had to adapt the raycaster logic a bit to handle the maze walls rather than a grid based map.
This runs consistently at 60fps on my pc with 2:1 horizontal scale (i.e. 240 rays). You can change the 'scale' global variable to 3 if you have a slower machine.
The maze generation logic is a 'recursive backtracker'. Based on Dan Shiffman's excellent JavaScript tutorial on youtube here.

P#148105 2024-05-08 04:17

[ :: Read More :: ]

Cart #picotroncaster-3 | 2024-04-16 | Embed ▽ | License: CC4-BY-NC-SA
14

Edit: updated to include a few more optimisations

This is a simple raycasting demo for Picotron. I wanted to check out the performance. It now manages 60fps most of the time thanks to optimisation suggestions by @freds72 and @Eiyeron. Rays are scaled to one third of the screen width to achieve this.

It is an implementation of the DDA algorithm, which is more efficient than a basic marching forward algorithm. The basic algorithm is included in the package if anyone is interested.

I used the extended palette to dither/darken the colour based on distance which does help to enhance the visuals.

Controls

Move using the arrow keys.
The 2D overlay map can be toggled on and off with the 'Z' key.
Basic performance stats can be toggled on and off with the 'X' key; A basic copy of Pico-8's Ctrl-P stats.
If you download to Picotron (using 'load #picotroncaster-2') then you can also used WASD to move and <> (,.) will sidestep left and right (these keys don't work in the browser version).

Background

This has been converted from a JavaScript version I built, which itself was a distillation of numerous tutorials on YouTube and other places and in different programming languages. I initially tried to port it to Pico-8 but it was too slow. But it ran buttery smooth in TIC-80 at 60fps, but didn't look as nice as this version due to limited colours.

What I learned playing with Picotron

Although the raycasting itself was relatively slow, rendering the result is very efficient. Picotron could easily render full native resolution (1 ray per horizontal pixel) if it could calculate it fast enough.
There's no built-in Tan function, so had to create it from sin/cos.
The built-in sin and cos functions are faster than the LUA equivalents(math.), but the difference can be mitigated by aliasing the math. function (msin = math.sin etc. Thanks to Eiyeron for that tip)
However, math.sqrt is faster than Picotron's sqrt() function and math.random is also faster than the built-in version (although math.random doesn't work with tables directly).
It seems that key() & keyp() don't work in the browser version, so you need to use btn() & btnp() if you upload a cart to the BBS.

Credits

I took the colour re-mapping code from @luchak's smoke simulator and used it to create the blue gradient for the walls. The original raycasting tutorials were from the following YouTube channels and websites(among others, not all of which are still running): The Coding Train, 3DSage, MaximIvanov, playfulJS.com, lodev.org.

P#146436 2024-04-12 06:03 ( Edited 2024-04-16 06:18)

[ :: Read More :: ]

Ceil() function does not work correctly:

ceil(1)   -->returns 1
ceil(1.0) -->returns 2 (Error)

Same for any N.0 float. Seems to work correctly in other circumstances.

LUA math.ceil(1.0) correctly returns 1 and can therefore be used as an alternative in the meantime.

Tested with version 0.1.0e on Windows 10

(I already posted this in the 'Picotron bugs' thread, but including it here with a proper 'Bugs' tag as I couldn't work out how to add a tag to the other post)

P#145215 2024-03-31 05:54

[ :: Read More :: ]

Version 0.1.0e on Windows 10

Strings cannot be indexed using var[n]. This is different to Pico-8, where strings are indexable. However, for Picotron, it may be by design as strings are not indexable in Lua itself.

a = "string"
print(a[2])

--> outputs nil (should be 't')

A workaround for the time being is to use sub(a, 2, 2)

P#145214 2024-03-31 05:39 ( Edited 2024-04-01 03:37)