Sunday, August 21, 2011

More AstroMiner Updates

I added some fun stuff to AstroMiner tonight.  First off, the screenshot:

Light fixtures everywhere.
So for starters, the entire world is not illuminated anymore.  The player has an area around them that's ~5x5 blocks that is illuminated by their ship lights.  Everything else will be a black block.  The player can also lay down lighting (they're the yellow circles you see there) that will light up a 4x4 area around them.

The same world without any light fixtures.

The other thing I added is fuel depots.  The red circle you see there is a fuel depot.  Fuel depots have to have light to power them.  If they don't, you get a gray circle like the one to the top left of the player.  Unpowered depots will not fill the player up with fuel.

So I spent the night working on those.  From a technical point of view, I'm happy with my implementation of fuel and lighting.  Both of them use the same technique.  When a player puts a light structure down, I add it to the list of light structures.  That list is referenced when it comes time to draw things on the screen.  After it's added to the list, I add it to my light map.

My light map is a Dictionary<Vector2,byte>.  The Vector2 is the location of the light itself and the byte is the strength.  I then have a loop that goes from the light position - maxLightStrength to the light position + maxLightStrength (on the x and y axis) and I added 1 to the positions on the map.  If I want to know if an area is lit, I check if the map contains the key for the location and if it does, if the strength is > 0.  When I delete a light fixture, I do the same loop and subtract 1 from the positions.

I use the same exact technique to detect if the player is within fueling range.  The only difference with that is I also check to make sure the fuel depot has power.

So besides those, I've been trying to work out a couple of glitches.  Since I've added momentum, the world randomly flickrs out of position for a split second at random moments.  My current guess is that it's a rounding issue when I draw the world but I'm not entirely sure.  The other glitch I'm working on is when the player goes from full screen to windowed, my code isn't centering everything properly.  That one's an easy fix though.

So until next time..

No comments: