Category Archives: Uncategorized

Lighting system in Fruit Wars

Lately, I rewrote some parts of the lighting system of Fruit Wars (once again).
The old system had a “spreadLight” method that was called when a tile that emits light was placed on the map. This worked fine, but it did not work well with sunlights.
Why? Because an air block DOESN’T emit light. It receives light from above the map.

In the new system I redid this and split the calculation of light into two layers: “sunlight layer” and “tilelight layer”. To know the light value of a tile at (x, y) I implemented a method “getLight” that does something like light = max(sunlight[x, y], tilelight[x, y])

You can see the new light system in the following screenshot
Lighting system

WebGL is awesome

WebGL is a javascript API and is its specifications is managed by the Khronos group.

All modern browsers (even IE11) got support for WebGL, but it may not be enabled by default.
For example, in Safari, you’ll need to enable it in developer tools.
WebGL is much like OpenglES 2.0, so you won’t be able to use things like glBegin & glEnd…
It runs almost at the same speed of a the same thing in C++ and that’s really nice! 🙂