2D Sandbox game

Hi,

Been working on this game for around two weeks on and off when I have time, doing the procedural landscape generation which is using
a mix of perlin noise and cellular automata.

My blog website with latest screen shot is at:

https://sites.google.com/site/sterrialand/development/news/cavesarelookinggood

Next is to add trees on the grass level, easy enough working out where to place them, but guess should use sprites for them and not add to tile array…

Any advice on how I could add some tile lighting? Maybe use shaders?

I’m using Libgdx and OGL.

Thanks,
Steve

Tile lighting? I’ve covered this practically the same amount of times I have with basic cave systems, so I will dump an older post here and go over it more in depth.

Each block has a byte of data (I only use half a byte b/c I don’t use the negative part). That byte corresponds to the “brightness” of each block. There is also a float for each block but that’s for colour, which I won’t go over.

Lighting is calculated with light sources and a recursion method at each source. The recursiveness of the lighting gives it that diamond shape.
My code is here.

This does use one shader, and it’s to mask the lighting buffer onto the world without covering up the background. The smoothness is merely a gradient quad.

This is what the lighting looks like without gradients:

This is what the lighting looks like without masking:

As you can see the moon and the stars have the “shadow” effect as a result.

Thanks for that.

Quite a lot of code there to look through :wink:

Do you have any video’s of your game?

Hi,

I’ve got this shader to do the whole screen:


varying LOWP vec4 vColor;
varying vec2 vTexCoord;

//texture samplers
uniform sampler2D u_texture; //diffuse map

//additional parameters for the shader
uniform LOWP vec4 ambientColor;

void main() {
	vec4 diffuseColor = texture2D(u_texture, vTexCoord);
	vec3 ambient = ambientColor.rgb * ambientColor.a;
	
	vec3 final = vColor * diffuseColor.rgb * ambient;
	gl_FragColor = vec4(final, diffuseColor.a);
}

with a default vertex shader.

This just sets my whole screen lighter or darker dependant on the ambient colour that is passed in.
How could I apply the lighting to just parts of the screen? Would I need to use a fbo?

Any help is much appreciated, knew to shaders.

Thanks

I drew gradients over the blocks with their corresponding light levels. The corners of the gradients were the surrounding 3 adjacent blocks (counting diagonal) averaged with the block itself.
If you want simple blocky lighting, all you have to do is draw a 1x1 texture (either generated at runtime or read from file) and stretch it over your blocks. I myself haven’t worked too much with shaders, but if you need a good resource, mattdesl has an awesome starting guide here.