Working Raycasting example! WolfenLöve 3D if you will...

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Working Raycasting example?

Post by bartbes »

Sounds plausible.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Working Raycasting example?

Post by Robin »

Works for me.
Help us help you: attach a .love.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Working Raycasting example?

Post by T-Bone »

I buy it.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Working Raycasting example?

Post by Jasoco »

Okay, guys. Very funny, but I've made some progress...

First things, it now has textures. I also made it so you can specify the resolution. In the below examples it has a 640x200 mode and a 320x200 mode. The latter is more true to the original Wolfenstein and DOOM and old DOS game resolutions. It's also faster. The former is fast too, but not as fast. Most of the time it'll be around 50-60FPS and is drawing 640 lines (rays) per frame.
Image Image
Actually, the first thing I did was change the strip width from 2 to 1 so it makes each ray 1 pixel wide on screen. That was easy as changing that one variable and made the game look much better. So it went from 160 rays to 320 rays in the first code and is now 640 when using "high-resolution" mode.

Next steps:
Sprites: Obviously you can't just have an empty world. Even MineCraft had flowers and animals before it had players and enemies. I have a feeling this will be the hard part. The original Opera project is based on HTML which has Z-Indexing built-in. I guess I could give every "strip" of the screen a Z-index based on its Dist, then add sprites that are on screen to a table, sort the table full of sprites and ray-strips by distance, then draw them all in order. I just hope it doesn't slow things down since it'd be done every frame. The Opera site has a page dedicated to this. I'll look into it.

Sprite clipping: Make sure they're clipped instead of overlapping when they're supposed to be behind a wall.

Depth shading if I can do it fast enough: I made a gradient for the floor and ceiling to make it less plain, but I'd love to also shade the images darker, but it would require a second draw call per frame and I discovered even having that ray drawing part (Which is just a line) was slowing things down, but it might still work if I can do it right. That way further walls will be slightly tinted dark. Or I could customize the "fog" if I need to make it white or red or whatever color the world requires.

Switches: Wolf only had a single switch and that was to end levels. (Elevator) Switches are easy as pie. It's a block that when activated changes to another block. Badda-bing, badda-boom. Easy.

Doors: I don't know how they were done in the original Wolfenstein. Doors were a unique thing. They were a block and were rendered differently. The inside frames of doors could be a different image than the other parts of the same wall tile, the door was inset. It'll be interesting to figure out how to get doors working. Or at least drawing right.

Pushable walls: In Wolf, you could push certain walls and they'd slide backwards. I guess if I can get doors working, I could get sliding walls working too eventually.

Weapons: Should be easy. Just trace a single ray from the player out when the button is pressed, but instead of just checking for walls, also check for enemies. For other weapons that aren't hit-scan, like rockets or fireballs, they'd just be sprites. Easy-ish I guess. Once sprites are done.


Right now these are the important things that must be done to make the game even work as a game.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Working Raycasting example?

Post by Robin »

That's awesome.
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Working Raycasting example?

Post by Jasoco »

For some reason now I'm having trouble sorting a table. Problem is the table can't be in incremental order. It's not possible with how I need to do the engine. The entries need to be in arbitrary order, maybe the numbers will be in order, but they won't be consecutive. So I can't use ipairs. I even tried giving each table row an index of the distance of the item/line being drawn and it still doesn't draw in the correct order.

Edit: Please hold, I may have figured it out. Stay tuned for an important message...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Working Raycasting example?

Post by Robin »

What exactly are you trying to sort? Which order does it need to have? For what purpose?
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Working Raycasting example?

Post by Jasoco »

The ONLY way to get sprites to show up in the right order is to have them sort themselves by how far they are. And in order to make them also sort behind walls you need to add every strip of the wall to the same table. Then sort the table so the far wall strips, far sprites all draw in order from far to near.

It's literally the only way.

The Opera example uses CSS' ability to use z-indexes.
jfroco
Prole
Posts: 24
Joined: Fri Jan 06, 2012 5:14 pm

Re: Working Raycasting example?

Post by jfroco »

Hello Jasoco,

I'm not going to say that I'm not Jasoco from the future, because I remembered that someone helped me in 2012 or 2013 to make my first US$ 1 million video game, with that money I built a time-machine, but that's another story :)

Regarding the engine, yes I did implemented a texture-version, but yours look better as far as I remember, I'm not at home right now to check it.

Best regards

JF
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Working Raycasting example?

Post by Jasoco »

And boom, we have proper sorting.
Image

Now to keep fingers crossed.

The hard part next is going to be getting moving sprites that still render properly. Like enemies.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 217 guests