Stormworks: Build and Rescue

Stormworks: Build and Rescue

70 ratings
3D Vector Graphics DEMO
3
3
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
188.834 KB
28 Dec, 2023 @ 10:32pm
28 Dec, 2023 @ 10:42pm
3 Change Notes ( view )

Subscribe to download
3D Vector Graphics DEMO

In 1 collection by Kernle Frizzle
Lua, etc.
8 items
Description
UPDATE: Improved culling and edge compensation

Ever wanted to play a game inside a game?

This isn't that, but it's not too far off. This is a tech demo for drawing world space coordinate polygons (triangles) onto screens using the nifty LUA block thingies in microcontrollers.

Keep in mind this doesn't work perfectly the order in which the script draws the triangles doesn't fully account for the more massive triangles. Same goes for when the camera gets very close to a triangle point, but isn't facing towards it. It's not fully refined.

No shadows because 1) I don't know where I would start with that other than trying to make my own raytracing and 2) no way in hell that would fit within even twice the character limit.

This LUA will work for every screen size, or at least the ones I've tested. No guarantees you'll be able to tell whats actually going on in most of them though.

If you do want to add your own triangles, follow the instructions below:

Data Layout:
In the array "obj," there are "objects" containing triangles in the format:
{{x=x,y=y,z=z},{x=x,y=y,z=z},{x=x,y=y,z=z},c={r,g,b,a},col=true}
where the first 3 elements containing x y and z correspond to the coordinates of the vertices of a triangle. In this frame of reference, x and z are the horizontal plane and y is the "altitude." c represents the color value for the triangle, and col determines if the triangle has collision. Currently there is only vertical collision, no wall collision so beware.
One element in the array "obj" represents one object, and is therefore made of multiple triangles. A full object might look like this:
{ {{x=0,y=1,z=0.2},{x=1,y=1,z=5},{x=2,y=0.9,z=6},c={5,0,0,255},col=true}, {{x=7,y=2,z=4},{x=3,y=67,z=4},{x=4,y=3,z=1},c={0,5,0,255},col=true} }
This object contains two triangles, one red and one green. If you wanted to add this object to the "obj" array, you would write:
obj[#obj+1]= { {{x=0,y=1,z=0.2},{x=1,y=1,z=5},{x=2,y=0.9,z=6},c={5,0,0,255},col=true}, {{x=7,y=2,z=4},{x=3,y=67,z=4},{x=4,y=3,z=1},c={0,5,0,255},col=true} }

Unfortunately, due to the 4096 character limit, there is only so much you can add before the LUA rejects any more. If you do add your own shapes, I would suggest deleting the subprograms that draw the ones already added as well as the --comments marking where you're meant to add objects. Finding a way to automate the triangle process using for loops or your own subprograms will allow you to draw in more complex shapes, contours and and what else.


If you don't want to deal with that however, just have fun in the somewhat limited space already loaded into the script. It has a very large 2-tiered concrete looking cake for you!


development issues if you can call it that
When small triangles get too close to big triangles, in some cases the draw order gets confused and draws one on top of the other instead of the other way round. When a triangle clips through another triangle, there is no way to draw both without having overlap that doesn't actually exist. When the vertex of a triangle passes behind the camera, the way they're drawn on the screen can't account for it (I have a stopgap fix for it but it's far from perfect and usually bends the lines in odd ways).
For the last two, I could possibly try to detect when this kind of thing happens and cut a triangle that's either clipping or passing off the screen into multiple smaller triangles. This would in theory work, but optimizing it would be at a level I can't really do at the moment.
I tried abandoning drawn triangles entirely, instead doing a kind of a raster scan over the simulated 3D scene logging order and color values of the triangles that show up in each pixel, then using those values to draw an individual rectangle for every pixel on the screen. This in theory should fix every problem I have, but unfortunately the amount of checks and cycling through arrays makes it practically impossible to implement. Even on a 1x1 screen, 32x32 pixels, the max execution time (an entire second) is exceeded when more than 20 or so triangles are simulated.

TL;DR I would love to make doom in this but I have no ♥♥♥♥♥♥ clue what I could do to make it work
82 Comments
ACE 6 Jul @ 5:18am 
HMD verision?
NoNameIdk1 1 Sep, 2024 @ 12:36pm 
Troagv, im pretty sure that would take more lines than we have in all of lua.
Kernle Frizzle  [author] 4 Aug, 2024 @ 6:48pm 
does this mean stormworks is turing-complete
Ication 4 Aug, 2024 @ 6:30pm 
i swear we are going to be able to play stormworks in stormworks
Troagv 18 May, 2024 @ 6:33am 
pls pls make a raymarching renderer that would be amazing
Potato Enthusiast 24 Mar, 2024 @ 7:43pm 
working on stormworks in stormworks :KOh:
habanero7715 18 Mar, 2024 @ 5:08pm 
DOOM.
Kernle Frizzle  [author] 16 Mar, 2024 @ 2:41pm 
gotem
Kernle Frizzle  [author] 16 Mar, 2024 @ 2:41pm 
when ur mother
metro893 16 Mar, 2024 @ 11:39am 
when doom?