
Lesson 6 Source Files
Resource Files
In the last lesson I added in floors but didn’t want to assume anything about ceilings. I’m actually glad I waited because adding ceilings and floors caused the framerate to plummet. This lesson I was then able to use to get my framerate back up and finish up floors and ceilings.
The map now has three arrays of equal size. One for the walls, one for the ceiling and one for the floor. This allows us to texture anything however we want. I also added in transparency to the floors so players can see through the floor to the background texture. I also removed the default fence around the parimeter. That stopped working when I optimized the raycaster. Now that I think about it, I’ll probably remove the transparent walls. They don’t really work except on the outer edge anyway.
The original Wolf5K based everything on 64 pixels which resulted in a lot of excess math once we stopped working in pixels and started working in percentages. I’ve removed all that now and the raycaster works in map coordinates instead of pixels. All the multiply and divide by 64s are now gone. Before the optimization 320×240 ran at about 15fps. Now it runs at about 21fps. That’s pretty much the same speed it was running when only walls/objects were being rendered.
One of the things I’ve been wanting to do since I deobfuscated the Wolf5K javascript code was rename all the variables back to something meaningful. I’ve done that now with most of the raycasting code. It makes a lot more sense now and I was able to find some minor optimizations.
For the most part our raycaster is complete. We have walls, floors, and ceilings which is more than most raycasters out there. The only component missing is lighting. We’ll also be enhancing our 2D graphics capabilities. All games need title screens and menus as well as status bars. There’s no shortage of things that go into a rendering engine.