Example

Ray Casting Demo

15

nathanielbabiak 2020-04-26 16:12 (Edited)

The cardinal directions across the top help orient the player (west is replaced by a moon, north by the "north star", but these are just place holders for now).

Also, the code is really well commented (I hope!) if you want to check it out. I rewrote the geometry explanations too.

Inspired by was8bit and Timo - thanks! (However, the code is entirely my own.)

Wolf 3D Demo.nx | Open in app
2020-05-06 03:33
Wolf 3D Demo.nx | Open in app
2020-04-28 01:28
Wolf 3D Demo.nx | Open in app
2020-04-26 16:12

was8bit 2020-04-26 16:39

Super duper wonderously wonderful !!!


GAMELEGEND 2020-04-26 16:48

This is awesome i also like that it has a moon and a star


was8bit 2020-04-26 16:52

There are actually a few things in the sky,,as well as a textured floor!!


GAMELEGEND 2020-04-26 16:54

Why is this poor practice what would be the right way to do it

GLOBAL A0 , A1 , A2 , A3 , A4 , A5 , A6 , A7 , B0 , B1 , B2 , B3 , B4 , B5 , B6 , B7
GLOBAL A0M, A1M, A2M, A3M, A4M, A5M, A6M, A7M, B0M, B1M, B2M, B3M, B4M, B5M, B6M, B7M


was8bit 2020-04-26 16:56

Oh, just figured out that PAUSE toggles between walk and run :)


nathanielbabiak 2020-04-26 18:13 (Edited)

I'm glad y'all like it!

@was8bit - the sky was originally going to have cardinal directions (N/S/E/W) shown, but I figured the text would be pretty arbitrary, so there's a "north star" instead of N, and a moon too. The next version will have those sprites rotate at the same scale as the wall panels. (And the jumping issue with strafing will be fixed too - I just noticed it.)

@GAMELEGEND - the most maintainable code is written in small, modular sections that limit what's effected. (It helps other programmers to understand a whole project when it's presented that way, and it limits the damage any individual can do if they modify it poorly.) In this language, we've only got SUB to work with. If those same variables were declared and initialized inside MAIN (and therefore local), rather than declared and initialized with GLOBAL, each of them would need passed as an argument to WOLF_DRAW, and each variable passed costs a clock cycle.


nathanielbabiak 2020-04-26 18:19 (Edited)

Oh! One more thing I forgot to mention... I decided not to set up buttons A/B to strafe, so that those buttons could be reserved for other things. But, when you change direction, strafing occurs automatically (just a little). I found that really helped orient me in the 3D environment.

@was8bit - the texture on the floor is a dither. You can see the available dithers in the Char Designer. I set up the dithers so my wife could easily pick the colors of the panels, panel moulding, and floor. I'm no good at color matching, and LowRes NX is pretty limited too.


Timo 2020-04-26 18:41

Very impressive, I'm surprised by the performance!


nathanielbabiak 2020-04-26 18:55

Thank you! (When was8bit shared your original code, I noticed it seemed like the original LowRes didn't have a significant performance cost for pixel-level graphics.) I used what I learned making Pxl Library to optimize this a lot. Each byte is only written once per screen update, and the bytes are written in eight-row-blocks where possible. It's in the WOLF_DRAW subprogram. (Not to mention completely taking advantage of the 1 clock cycle cost of floating point operations.)


desbyc 2020-04-26 20:33

😮😮😮😮😮😮😮😮😮


G_9 2020-04-27 08:29

If there is an exit ?? :)


G_9 2020-04-27 08:31

https://tic.computer/play?cart=237

If you can do like ^^^^ this ...


nathanielbabiak 2020-04-27 14:36

That's definitely the plan! Unfortunately, LowRes NX is too slow to allow textured wall panels (or even walls with more than 3 colors total). I have some ideas though for decorating the panels though, they're commented in the source below WOLF_SHADER (to be implemented in the next version).


Jonnywhateva 2020-04-27 21:31

Wow this is fantastic! Definitely going to look through your code and see how this one ticks! Well done! :)


nathanielbabiak 2020-04-28 01:29 (Edited)

I fixed the cardinal directions - now they project onto the inside of a skybox. I have a few more improvements planned, but had to work too much today.

Also, you can strafe with A/B now, but not permanently, it's just to help me debug the jumping issue. (I know what's causing it, just haven't worked out the math to fix it yet, since I want to fix some other stuff on the subject of movement at the same time.)


Blockhead 2020-04-28 14:44

It’s possible to make a sort of doom with this?


nathanielbabiak 2020-04-28 19:39

The system is too slow for Doom, but will work OK for 1992's Wolfenstein 3D. There won't be textures on the walls though, just simple geometric shapes and patterns. I have a motif developed so the player associates switches with doors though, so besides being much more abstract, I think it'll work out OK.

What's funny is, the wall patterns will have to be super simple compared to Wolfenstein 3D, but the enemies will be just as detailed.


GAMELEGEND 2020-04-28 20:02

Are the blue dots going to be replaced with a floor?


nathanielbabiak 2020-04-28 20:13 (Edited)

Unfortunately the floor can't be textured either. The floor can be a dither (the available dithers are in the Char Designer). If the floor had a complex pattern or a texture to it, then it would need projected from 3D to 2D. The system's too slow for that.

Also, I've optimized a few more things (haven't uploaded yet) to make it even faster. *BUT*, it's going to slow down substantially when the display gets buffered. (I need to buffer the display so that there's enough cells available for enemies and objects.)


PranXter 2020-05-05 18:39

Almost as good as mine. Just kidding lol. I’ve figured out the math, just not how to present it.


nathanielbabiak 2020-05-06 03:42

Just some quick comments on my latest update - it's now one to two frames-per-screen-update faster than before, and there's also an 'interleave' setting to speed things up by 50 pct after that. The BG Designer is used to read off the level data, and besides doors, switches, buttons, and sound, all expected feature expansions are commented with "(NOT YET)..." so I can keep track of everything.

Barring crazy work hours, this should take another few weeks to wrap up, then it's on to game mechanics!


GAMELEGEND 2020-05-06 03:44

The 3d graphics are better now but why do the walls break up when you turn


nathanielbabiak 2020-05-06 03:47 (Edited)

That's the interleave. Since the display is made of individual cells, the interleave will only cast rays onto every-other-column of cells in a single screen-update. You can turn it off by searching for WOLF_INTERLEAVE and setting the value to 0 (not 1), but it will then update the whole screen at once rather than just half, so it's much slower.

It's going to slow down significantly when the buffer is added, but that's required so that it can have enemies and objects 3D-projected into the environment. It needs to be as fast as possible otherwise.

I also tried not refreshing the sky or panel pixels to save clock cycles, but it turns out that's not really significant. The slowest calcs are in the ray casting algorithm itself.


GAMELEGEND 2020-05-06 03:49 (Edited)

I see now
good job on the graphics


nathanielbabiak 2020-05-06 03:53

Thank you!


Log in to reply.