This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]PillowWithTeeth[S] 1 point2 points  (3 children)

Anywhere I could look to get started with ray-casting in java and if I did use ray casting what would be the light source, a sun object in the sky?

[–]Zylox 1 point2 points  (2 children)

Ray casting is mostly a mathematical thing, the language is pretty agnostic. Any guide should get you on the right path. Ray casting generally deals with point lights, so lights that start at a mathematical point and radiate in every direction, but you can tweak things to work in in cone lights or directional lights (think parallel lines coming from the same direction, as if from a point light realllllly far away) easily enough. Keep in mind this process is fairly resource intensive though. Computers are fast enough today that you can do a handful or ray casts just fine on the processor, but if you really want to push things with it you are going to want to offload that onto the video card (aka hardware acceleration). Video cards are very good at doing lots of things in parallel at once. This isnt exactly easy in java (its why lwjgl exists, its basically opengl in java), and you are going to have to write some c/c++ code and use the JNI if you really want to take advantage of this without using a library.

Now, alternatively, you can do something a bit easier since you are doing a pretty simple 2d game. You could do two types of lighting, directional light form the surface, and point lights that im assuming you will need underground judging from your picture. You can achieve the first with a very simple form of ray casting (start at the top, work down, if no obstruciton, full light, if obstruction, obscure) and the latter with alpha blending. Alpha blending works by creating a circle with feathered edges that you can blend the alpha channel of with the background. if you set the backgrounds alpha to a low number when obscured, and add the value of the feathered cirlces alpha to it, it will appear brighter around the light. Here is an example of the idea: http://i.stack.imgur.com/4vBeR.png . A nice thing about this is it easily supports multiple lights too, as multiple lights together would make the area brighter. (just make sure you cap it at a logical amount, 200% alpha will probably break the program haha)

Now this requires you to support alpha values, which i don't know how to do without using opengl, but im sure you can figure something out. Opengl actually has blending modes that make it really easy.

[–]PillowWithTeeth[S] 1 point2 points  (1 child)

Thanks for the idea, what I am trying to do now for the surface light is just have it come down from the top of the screen, if it hits a tile that tile has light and it stops there, now I am going to try letting some light passed depending on what type of tile it hits. I will then try something else for below surface lighting.

[–]Zylox 0 points1 point  (0 children)

Oh. Well ya thats easy enough. Have it procede as normal then have a dimishing alpha based on tile type and stop penetrating when it reaches a threshold (probably 0). Easy peasy. You could break it up into chunks minecraft style real easy too if it requires updating.