Game Design Game Development Geek / Technical

Freshly Squeezed Progress Report: Raycasting a Dungeon?

Last week, I reported that I was working slowly to build up the 2d-simulating-3d art and math to represent the dungeon for The Dungeon Under My House, my second Freshly Squeezed Entertainment project.

This past week I got a suggestion and decided to explore a different approach.

Meanwhile, there are mere hours left in my “reverse sale” for my leaf-raking business simulation strategy game Toytles: Leaf Raking. Soon it will revert to the regular price, so either get it now or get it later. Your choice, and thank you for your support either way. B-)

Sprint 10: Pre-production and initialization

Planned and incomplete:

  • Move player in dungeon view

Much like the previous week, I did not get to spend as much time on development as I would have liked. Between the Iowa legislature making life tougher for the most vulnerable, some home improvement projects, and my back hurting me potentially due to those home improvement projects, it’s been tough to make time to sit down.

A few weeks ago, one colleague suggested that I simply use an existing 3d-engine instead of trying to create a 2D tileset. Thanks for the suggestion, Ken, and I apologize that I will ignore this otherwise very sensible advice.

As I said last week about why I insist on ignoring this advice:

Because I’m stubborn, maybe. I wanted to try it, and now I’m in the middle of it.

I know 3D would make a lot of this work easier, but switching to 3D would mean needing to switch to an existing game engine, something I’m not ready to do because then it means abandoning my many years of code that I’ve built up. Maybe I’ll think about it if I am still trying to figure this dungeon rendering effort weeks from now.

But it’s fun to figure things out, and that’s part of the reason why I like doing it the hard way.

Well, in response to last week’s report, another colleague suggested that I look into making a simple raycaster.

Thanks, Joel Davis, aka joeld42.

I had originally looked up how to mimic the look and feel of 2D 1st person RPGs from the 80s and 90s, and I found Reddit posts and forum posts in which people basically said, “You COULD do it this very difficult and time-consuming way, OR you could use a 3D engine and fake the old look.”

And people would also throw in raycasting, much like how Wolfenstein 3D and Doom’s engines worked, but I didn’t pay much attention because I didn’t want to make a real-time 1st person game.

But Joel said “Doing it in 3d in your own engine, whether a raycaster, a simple SW renderer, or regular 3d with opengl or something, doesn’t need to be that hard, you can keep it simple” and followed up with “You should try it, it’s fun and super simple. I’d say it’s less work than the approach you describe in the blog post.”

He also sent a link to this neat tutorial and web demo: A First Person Engine in 265 Lines by Hunter Loftis

So I downloaded it, toyed with it, and changed some parameters and values to get a sense of how the code and math worked, and I also played with the demo, which impressed me even when I disabled the lightning and rain effects. It was fast and looked pretty good.

There are quite a few raycasting tutorials out there, some of which I read a long time ago, and some of which are new and I read this past week.

I particularly enjoyed Lode’s Computer Graphics Tutorial: Raycasting and the follow-up on rendering the floor and ceiling, which helped me triangulate an understanding of what Loftis was describing in the other tutorial linked above.

And I also loved reading about this voxel space demo.

What I liked was the idea that instead of needing to generate multiple images to represent a single wall or floor tile, I could have one image and let the raycasting engine handle making it look like it is being seen at an angle for me.

And what I especially liked was that the math and technique seemed straightforward enough to implement.

As I said above, I did not spend much time on development this week, but what I did do was prove to myself that I could modify my code to render the walls in vertical strips the way a raycaster would.

So here’s how my in-game hardcoded hallway demo looks when I have separate tiles for the back wall and the side walls:

The Dungeon Under My House - initial in-dungeon art

And here’s how it looked when I rendered the back wall and side walls using the same image but drawn with vertical slices:

The Dungeon Under My House - in-dungeon art using vertical stripes

Ignore the fact that I didn’t get the floor or ceilings in. I think you can hardly tell the difference between these two renderings. The second image isn’t raycasting. It’s hardcoded much like how the demo above is, in that I render the side walls until I hit the end of the hallway, then I draw a back wall.

Remember, though, that second screenshot shows me using only a single image for the wall, rather than separate images for the side walls which are a little clunky and awkward to create. I could easily throw in a different image and have a new wall tile that can be rendered in three ways without me needing to modify or create even more art.

Even if I don’t implement a raycaster, this technique of rendering vertical slices of an image looks good AND reduces my art-creation effort. It also means that my game download will be a lot smaller and take less time to load.

I could even get creative with both how it grabs portions of the source image and how it renders to the target location to perhaps create certain effects.

But I think I do want to implement the raycaster code. I want to be able to render walls seen from the sides, not just the direct hallway in front, and I want to be able to turn and have the code manage rotating in space with no extra effort.

And while I could use an existing engine and not need to implement any code to handle it at all, I don’t want to use an existing engine. I have my own code that I’ve been building up for years, and creating a raycaster using it seems like it will be quick, easy, and enjoyable enough. And being able to do things with my existing code is why I have existing code.

Thanks for reading!

Want to learn when I release The Dungeon Under My House, or about future Freshly Squeezed games I am creating? Sign up for the GBGames Curiosities newsletter, and download the full color Player’s Guides to my existing and future games for free!

One reply on “Freshly Squeezed Progress Report: Raycasting a Dungeon?”

Comments are closed.