Monday, January 30, 2012

One level wonder game design

I have been busy that last couple of days doing other stuff than programming. I upgraded my graphics card to an Nvidia GTX 580. For some reason, every time I upgrade my computer i seem to loos all my spare time ;-) I did manage to play Skyrim, Rage and Serious Sam 3. Rage is so close to perfect that it's unbelievable. Once you get the shotgun, you can almost feel the kick.

Well back to programming games :-)

I have been thinking about how I want my game to proceed. There are basically 2 ways it can work. First is that the player start out on level one, finds a set of stairs down and start all over again. If the player reaches a level that is too tough, he can walk up the stairs and retry the last level. Or it's a one level game, meaning, every time the player completes a level, he is returned to a score / menu where he can choose to play another level. Every time he completes one, he is rewarded with something extra.

I am sort of leaning towards the last one where one level is played, when the "quest" is solved, he is returned and rewarded. This simplifies things allot and also opens up for shops, skill assignment, character leveling up and other in between killing monsters stuff.

I have also been trying out Unity 3D and think that once I have completed this game, I should try to create something in that. It's a great way to enter 3d game programming as the engine and editor is already there, all you need is a programmer and an artist to start creating something, and the free version is fairly good. Missing a few things that would be nice to have like some lighting stuff, but all in all fairly good.

Sunday, January 22, 2012

More inventory and item description

Did a bit more inventory programming to resolve some of the bugs and minor issues.

First thing was that I had to figure out how to create a lot of random items with different stats without creating a weapons class, potion class, and so on. What I did was to just create a basic item class that had all the information that all items must have. I the added a HashMap where I add all the stats that this item will affect and by how much. I then just run through that map and add or subtract from the player stats when an item is used.

I added item description, so when you move the mouse over an item, it shows name and the stats it will modify. This might have to be changed in the future if items start having a lot of stats as they just get rendered next to the mouse cursor.

Also prevented ground items from exceeding the 8 boxes. Still have to add a way to scroll through them or some other way. Could be to just push the remaining items to a tile next to this one. It's the Diablo 2 way. You could not have more than one item on a tile.

Anyhow, I only need to equip items and the inventory is done.

Inventory and item generation

So inventory is almost done. I had to draw a few more item images to actually be able to tell the difference between items as I don't have any item descriptions popping op when mouse hovers over an item.


There is room for 8 items on the ground. If there are more than 8 items they will just render outside the ground area and onto the character part. That needs fixing. Items can be added to the inventory by clicking them. At the moment they just get added to the first free slot. I will change that to allow the player to place them where he wants.


Potions can be used from the inventory but items can't be equipped yet. All items when in the inventory can be moved around by clicking an item, it's then displayed under the mouse cursor and you can place it again by left clicking. If you right click, the item is returned to it's previous location. You can also drop it on the ground by clicking one of the looting boxes in the bottom of the screen.


There's a lot of fiddling around before it's done.

I have started on an item generator so that I don't have to create a lot of content. It can generate items of 4 different levels. A short sword can have an Iron, Steel, Dwarf or Elven blade. There's only 2 weapons, short sword and mace, one chest armor and a healing potion that gets generated at the moment. But it's fairly easy to add more.

Thursday, January 19, 2012

Looting and inventory

Could not escape it any longer, so grabbed my favorite free drawing program and started creating an inventory with space for a looting section. I decided to combine the two things as they are fairly similar. With my limited drawing skills and this being a first draft I drew this

I am particularly proud of the man underneath the equipped boxes, to bad you cant see him smiling, so here's he's face :-)

The plan is that the bottom row of boxes are for items on the ground that can be picked up. When clicked they will be moved to the first free box in the inventory. If there are more items than what can be shown, a small arrow should be shown to scroll through them. I have actually implemented this, sort of anyway. Well not the scrolling arrow thing, but the picking up item stuff. Took a few shortcuts and when the mouse is clicked it just moves the first item from ground to the first free inventory slot.

I only have one item at the moment, lacking more images and an item generator I only created a healing potion. It looks like this


And after clicking the mouse it's moved to the inventory and it looks remarkably similar.


So what's missing. A proper way to loot items and a way to move them around in the bag. A way to equip them or use them from inventory. And a lot of code clean up. As I had no idea what I wanted, and took a few shortcuts to get something working there's a few problems that need eliminating.

Wednesday, January 18, 2012

Overlay

I didn't feel like programming items, well to be honest, I am a bit stuck on the looting system. Not really sure how I want it to work. So I added something else that I had planed on doing later as it wont add anything game wise, but looks good. Well it would if I could draw.

I added overlays to floor and both walls. It's a small image that get's drawn over the floor or walls to add variety. It creates a sens of the walls being different without actually having different walls.

It didn't reduce the fps as much as I had thought it would. I only have 1 image for the walls, a drain pipe kind of thing and 1 for the floor a scratch. It's easy to ad more, just draw, add and set how much it needs displacing when drawn.

I know there are to many drain pipes, some of them will get replaced with other images as they get added.

I was thinking of combining wall and floor overlays, so that if there is a certain kind of overlay on the wall, it automatically draws a matching overlay on the floor. Like the drain pipe and then a puddle of water on the floor. A crack in the wall and some loos bricks on the floor. Stuff like that.

Monday, January 16, 2012

Lootable items on map and placeholders

I will be drawing placeholders for items as I do not want to spend 2 - 3 hours drawing something like a chest. I would rather spend the time programming. So my first place holder is a chest, it's not pretty, but with a bit of imagination, you can see that it is.

I have added a hash map to my map class that contain MapItemGroup where the key is an integer that is calculated based on x and y coordinate (y * MAX_MAP_X) + x. All items on them map is pooled in a chest if generated by the map or a bag if dropped from monsters.

I have expanded my move command to check the map for item groups and change the image from chest_closed to chest_open if it's a chest and the same for bag's.

Chests also have light on them, to make them look like they are part of the game and not just a sprite drawn on top of every thing else. I just add the color values of r, g, b and divide by 4 to average them and use that as a single color for the chest.




There's still no items in them, that's the next thing.

Fixing missing and broken things.

Got the refactoring done and it reduced the program size a bit and it's now easier to create new graphics without having to add them to a big tile sheet, The problem was that when adding a stone wall as wall1, then you either had to create a stone wall for wall2 or leave it blank to get the map image index to work right. index 1 on the map was image 1 for wall1, wall2, floor, wall top. If I only wanted a specific wall as wall1... You see the problem, or not. Anyway it's working fine now.

Second thing I fixed was the light blending on the walls. It was not smooth. It was an eyesore now that I finally got the blending on the floor to look right. And here is what it looks like now.


Pretty good if I must say so, and I must.

Now back to adding items, inventory and lootable things.

Refactoring images and rendering

So I had a bit of time this Sunday and was messing with the images that I use to render the scene. I had created sprite sheets to store all the images in, but it was getting increasingly annoying to add new tiles to the sheets. So I decided to split them up in single images. As I don't expect to have to many images in my little game it should not be a problem.

Refactoring a very important and deeply rooted function of a game is quite a big task. But well worth the effort when it's done. Might be a good time to separate the slick images from the game so that I can replace slick later if it proves not to live up to my expectations.

Saturday, January 7, 2012

Items and inventory

Started developing inventory and items. My plan is to have a list that contain item groups on the map, so if a monster drops 2 items on the same tile, they will appear in a bag on the map. When the player clicks the bag, a list of items shows up that can be looted.

This will also work well for chests and other objects that is generated and placed on the map. All I have to do is change the image that is draw from a bag to a chest and it's done.

I want to generate random items, from drops and chests. I will probably create something that looks like Diablo 2 item's. They will have a name, prefix, suffix and random stats. Example could be flaming short sword of might that would look like this :

Damage 2 - 6
Fire damage +3
Strength + 1

Flaming covers 1 - 5 fire damage, burning covers 6 - 10 fire damage and so on. There should be some limitations on what effects can be mixed, fire and ice is a no no. Flaming sword of freezing, fun but no.

That way a random item is pretty easy to create. I might also add the possibility to create something that's permanent, like a strength or health boost potion.

At the moment my items are very simple, only a name and an item level. Just working on getting the map, render and item group list to work as intended.

Friday, January 6, 2012

New image of light

I was testing some stuff when this map was generated, looks pretty good, so wanted to share.

Thursday, January 5, 2012

More light part 2

Okay, so averaging the corners from the tiles surrounding one til, did not work at all. I am not even going to post pictures of it. What I will post pictures of is another method that I used to get it to look very close to what I want.

A very simple step by step description of what I do from start to end.

1. Use  Bresenham's line algorithm to calculate what tiles have light on them and calculate the light strength based on distance from the light. All tiles are lit the same, so all corners are set to the same value.

2. Then spread the light from lit tiles to unlit tiles by adding all the light from surrounding tiles and dividing by the number of tiles then adding that value to the unlit tile.

3. I do step 2 again to spread it even more.

4. I calculate the color a corner should have based on the tile that it's overlapping. For exampled corner 0 overlaps the tile that is one to the left of this one, so -1 on x axis. I add the colors of corner 3 and 2 and divide by 2, then add the color of corner 1 and 2 and divide by 2 from the tile to the left. Those 2 numbers then gets added to the original color of corner 0 and divided by 3. I do the same for the rest of the corners.

5. I repeat step 4 one more time to even out the light a bit more.



6. I then add ambient light to all tiles that have a rgb value that is less then what i have chosen for my ambient light value.


I have tested the color blending as well and with 250 random lights on my map it looks like this.


There's still a few problems with walls that do not look like I want them, but it should be fixable.

If you would like to see some code, let me know and I will try to clean it up a bit and post some of it.

Wednesday, January 4, 2012

More light

For some strange reason, I can't stop fiddling with the lights. My plan was to move on to inventory and items to get some game content going, but every time I test something, I keep getting annoyed because the lights don't look exactly like I want them to.

So I am back for more light.

The plan is to rewrite the light map and try to get the light to fade from one tile to the next. This is a challenge as my images are squares with i diamond in them. That mean that they overlap each other. So it's not enough to get the corners of the images the same light %, but it has to be a calculation of light on the tiles around them.


I have several ideas on how to do this, the first one I will try is to just add up all the corners that overlap and divide by number of corners. This can also reduce my light map size as I only need one color for 1 corner of 4 tiles. I am not sure this will have the desired effect, but at the moment in my head it sounds okay. At least enough to try it out.

Will post pictures of success....... or failure if that is the case when I try it out.

Monday, January 2, 2012

Scripting

Scripting or not, I choose not to script.

The reason why is that scripting is overkill/unnecessary when only 1 or 2 people work on a project. Scripting is for a larger team of people where you need to work on multiple parts of the game at the same time. You can create almost the entire game in scripts if you want to, but it's more efficient to do it in you preferred programming language.

Scripting is fantastic if you have a stable version of your game, and a bunch of people that need to create for example AI. While the programmers work on graphic stuff the scripting people can create AI without recompiling the entire code base. They just need to reload some scripts and off they go. It's an efficient way to have many people working on different parts of a game at the same time.

I am just me and myself, and we don't work at the same time, so not a problem.