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
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 »

Nixola wrote:Can you send me the .love file? I want to see how many FPS can I get, on a netbook...
I'll upload one a little later when I've worked some things out. You have 0.8.0, right? It uses Canvases instead of FrameBuffers. If you still have 0.7.2 you will have to edit the code to change them manually.

Right now I'm trying to figure out a better way to draw my gradient.

Does anyone have a really good gradient algorithm with a start color and end color for Löve? Please please please?
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Working Raycasting example?

Post by thelinx »

If RGB value gradients aren't good enough, try HSV gradients?
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 »

I just don't know how to implement a good gradient drawing function to draw the darkening floor and ceiling effect based on how dark the level ambience is supposed to be.

Seems like it would have been easy. Take a start color and an end color, figure out how many steps it takes to get there, then walk along the steps getting gradually darker.

This is what I used currently:

Code: Select all

  grad.stages = screenHeight / 2
  grad.step = (grad.stop - grad.start) / grad.stages
  grad.cur = grad.start
  for i = 0, grad.stages do
    grad.cur = grad.cur + grad.step
    love.graphics.setColor(100,100,100,255 * grad.cur)
    love.graphics.rectangle("fill", 0, screenHeight / 2 - i, screenWidth, 1)
  end

  grad.stages = screenHeight / 2
  grad.step = (grad.stop - grad.start) / grad.stages
  grad.cur = grad.start
  for i = 0, grad.stages do
    grad.cur = grad.cur + grad.step
    love.graphics.setColor(66,53,41,255 * grad.cur)
    love.graphics.rectangle("fill", 0, screenHeight / 2 + i, screenWidth, 1)
  end
To draw the grey ceiling and brown floor. But that's hard coded and based on opacity over black. I'd rather draw in the color.

Edit: Okay, in the meantime, here's a current version of what I have done so far:
WolfenLove3D.love
0.8.0 required or at least recommended.
(146.33 KiB) Downloaded 343 times
Notes:
Move with the arrow keys. No Strafing yet. And collision is really basic. I will fix collision and add strafing.

Press / to change the resolution. The way it works is screen width / scale factor = number of lines drawn across the screen. It currently lets you go up to 4 and down to 1 with 8 being the most pixelated and 1 being 1:1 pixel. 1:1 is slower and 8:1 is fast. But 1:1 looks really nice if your computer can run it smooth enough.

The current screen size is 800x500. Use the MENU to change the resolution! Adjust both options to fit your speed.

There is a current sprite bug where it gets indexed a bit wrong. I will fix as soon as possible.

Like the original, opposite walls are reversed. I tried disabling this as I'd rather control the reverse texturing myself, but need to figure it out more.

Press M to toggle the map.

Press L to toggle the lighting.

Don't criticize my code. It's still a bit messy since it was someone elses code that was ported from a JavaScript project. I'm working on optimizing and cleaning it up. But jfroco did a pretty damn good job porting it I must say.

Next Objectives:
> Sky - Can't believe I forgot that. This will be the easiest part. Simply place an image behind the walls and sprites and move it based on which direction you are facing. Easy peasy lemon squeezy.
> Transparent walls - This will be interesting. Will have to modify the ray cast function to record when it hits a transparent wall, save it for later and keep going, then modify the display portion to allow for an optional second layer over the first layer when there's a see-through wall in front. That will be fun.
> New mapping format - Will have to figure out an easy to modify and understand format for my maps.
> Enemies - Have to do them some time. I also have to fix the sprite clipping bug. Can't wait to start trying to create an AI for them. I want them to pursue the player when they see them and run and find shelter when running low on health. Maybe give some the ability to heal themselves. But I'm getting ahead of myself. Let's get static enemies in place first.
> Separate floor colors - If I can't do images for the floors, I can at least figure out how to draw each floor/ceiling tile individually so I can create lighting effects.
> Better player movement/collision detection - Self explanatory
> Editor - If time I will whip up an easy to use editor for creating maps.
> Animation - Sprites, walls, maybe eventually floors and ceilings.
> Doors - Still not sure how to handle this yet. Need to figure out how to have walls that aren't on the exact grid to do this. A door in Wolf3D was a flat wall that was inset half a block and slid to the side when opened. Hmm... I wonder if I could look at the original Wolfenstein code.
Last edited by Jasoco on Sun Jan 08, 2012 8:35 am, edited 1 time in total.
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 »

It crashes for me on startup:

Code: Select all

Error: main.lua:513: attempt to index field '?' (a nil value)
Apparently, it's because getScreenRes() returns -1. Because my monitor doesn't support 800x500 as a screen resolution.

Once I fix that, I get the error:

Code: Select all

Error: main.lua:764: attempt to call field 'setRenderTarget' (a nil value)
When I changed those to renderTo, it worked for me.

Once everything was fixed, it worked great. Really awesome.
Attachments
wolfen3D.love
Uploaded for others with the same predicament
(113.87 KiB) Downloaded 274 times
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 »

I guess I should set the default resolution to something everyone supports like 640x480. You could just change that in the Config file.

Also, I'll implement a better screen resolution code in later versions. One with an error checker and fallback or something.

Which version of Löve are you using that has renderTo instead of setRenderTarget?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin »

Using 0.8.0, like you. Only bartbes' PPA, which is a bit more recent than your build, probably.

That's the problem with making games for unreleased versions of LÖVE: the API may change before you're done.
Help us help you: attach a .love.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

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

Post by MarekkPie »

http://love2d.org/wiki/Framebuffer:renderTo

This says 0.7.0 and above. It's supposedly just syntactic sugar, according to the wiki. Just eliminates the need to reset drawing to the main screen.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

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

Post by Jasoco »

Does setRenderTarget work anymore in current 0.8.0? And does renderTo do exactly the same thing? As in let me draw to a canvas without it being cleared?

Edit: Also, we should probably now move this into the Demos forum. Or maybe I should just make a new official thread when I polish the demo a bit more. Whichever works. Seeing as I didn't post a demo until the 4th page. Though a working prototype did show up on the first page so I dunno.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin »

Ah, I see, love.graphics.setRenderTarget is renamed to love.graphics.setCanvas in "default". The latter is as of yet undocumented.
Help us help you: attach a .love.
jfroco
Prole
Posts: 24
Joined: Fri Jan 06, 2012 5:14 pm

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

Post by jfroco »

Hi all,

I'm using 0.7.2

I tested the version with Robin's changes, replaced love.graphics.newCanvas with love.graphics.newFramebuffer and then I had to remove all canvasobject:clear(0,0,0) lines. Is there any equivalent to this method in the framebuffer class?

Amazing work. Congratulations, Jasoco.

I will try to finish my own engine during mini LD 31.

Best regards

JF
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 69 guests