Thursday, 21 February 2013

Lighting and teleports

Hey Internet, so here is my second update after a week worth of progress. I've done a couple of things. First of all I wanted to make some sort of lighting so you can see if you are in the shadows or not. I thought it would be really neat to do this with shaders and set out do so. So what I made was a shader that calculates the distance to each light source and takes the minimum. The effect was ok, but diamond shaped rather than square like the grid. You can see the effect in the Figure below.

Lighting with shaders
So I wasn't really pleased, since the performance seemed to be quite bad, however that it something attribute to my sloppy code. I have had no experience with shaders and while slow and not what I wanted, I did learn quite a bit. So next up I tried another solution: an overlay. This was quite a bit faster and a lot easier to make. I simply take the bounding box of a map and draw tiles with an alpha value based on the minimum distance to a light source. The result of this can be seen in the figure below.

Lighting with an overlay
Hmm, we now have it aligned with the grid of the tiles but the effect is not as pronounced as before. This was because with the shader we can acutely make things brighter than they are. Now we can only make them darker. However, too dark and you cannot see the player, so it's a bit more difficult to really get those layers. But this is good enough for now.

As you might have noticed, I'm on a map which is on the inside of a building. And you are correct. I made the option to load a new map when you hit a certain spot. That way you can move in and out of buildings and so forth. I call it a teleport, which is sort of a remnant of how it was called in RPGMaker and how I still think about it, and most of all, it describes what it does, right? So if you move to the door on the bottom (where the light is coming from) you 'teleport' outside to the original map.

Outside of the room, with global lighting
As you can see, it is light outside so we don't need to shadow layer. I can just set the maximum about of shadow per map in the editor (I added a slider). Speaking of the editor, in order to place lights and teleports, I extended the editor to support this too. You can now drag a square with the light tool to create light areas. Another is the teleport tool which, when used, lets you select a map file and position from it with a special pop-up window.

Lights tool
Teleport tool
So far my progress this week. Furthermore, I decided to make this a one-month project where I get as much stuff done in about a month. I think I sort of rushed into this idea without too much thought (as usual) and seeing things blow up a bit before I actually have a finished game. Nonetheless, I plan to make it at least playable. So what I will be adding is at least some gunplay where you can shoot some of the lights and maybe some NPCs. I was also thinking of implementing path finding using the A* algorithm for some basic NPC movement since this is something I will need at some point and it's a good learning point. But that is something for future blogposts. See you then, internet.

No comments:

Post a Comment