Tuesday, March 20, 2012

God or bad news

I have some good or bad news depending on how you see it.

I have some how convinced my 3d artist friend to create some models for a tower defense game. This means that I will not have time for my own little project, and I will be moving to 3d for that project.

So good news is that I have models to play with, bad news is that this project is shelved for a longer time than first expected.

Tuesday, March 6, 2012

Spring is here

Well almost here anyway, that means that I have a lot of things to do in the garden and around the house, so it will be a bit quite on this blog for a while.

My little project is not scraped, it's just dormant.

Wednesday, February 22, 2012

More items and player image

I added some more items "feet and head", they have the same item types as the other, iron, steel, dwarven and so on. They can be equipped as well and so can the chest armor now. All I need is pants and shield or other left hand items for a full set of drops. It's coming along quite nicely and all items that get equipped or unequipped change the players stats. I want to add more items like books "inc xp when read", postions "permanent inc of str, int" to allow player to gain extra stats from drops.

Why yeesssss, I drew them all my self, how did you know?


I added a player image so that I could remove the red square in the center. He get's colored by the lightmap when the player move around. And yes, he's not pretty and only point in one direction, but that's all you get from a free game :-)



So what's the next step in my development. I think it's time for some combat. It's going to be simple, walk up to a monster and then walk into it until you or the monster is dead. Should be fairly simple to implement, all I need now are some cool drawings of monsters........ Hmmm, could just reuse the player image for all monsters. That's a great idea, or not :-)

And  I should probably change the lighting to something more dungeon like instead of the disco lighting I have now. Some torches might be god, with lights of course.

Tuesday, February 21, 2012

Equipping weapons and bug hunting

Bug hunting, sounds more exiting than it is, and I am not talking about hunting monsters.

I had an annoying bug where chests and bags would not be removed when it was empty. As there are no way to distinguish between a chest that's empty and one that got items in it, I would need to remove them or the player would have to spend a lot of time checking empty chests for missed loot. It's fixed now, turned out that I didn't remove it correctly from the ItemGroupList that's controlled by the map.

I added the possibility to equip items. At the moment its just the right hand that's working, but all the basic code for adding item effects to the player like changing armor class, damage, strength and so on is in place. I also added swapping items so that the player don't have to place the item in the inventory before picking up an equipped item, that also goes for items in the inventory.

So my inventory looks like it did last time I showed it, added some stats in the top part to show effects of using items.


 I drank a potion from the inventory by right clicking it and equipped an iron mace that increased the damage from 1-2 to 2-6, mace doing 1-4 damage and unarmed player doing 1-2.

Swapped iron mace to a dwarven  shortsword and thereby increasing my damage. All seems to work fine, just need to add the other items and create more items that can be randomly generated.

Might switch player stats and item stats to float to give more variety, player doing 1.5 damage and item doing 6.6 with monsters having float health as well. Will make item hunting better as you can find more items without drastic increases in damage. Mace 1.0/4.0 dam to 2.0/5.0 dam, it's a lot of possibilities compared to 1/4 dam to 2/5 dam.

Just noticed that I have 2 slots for the feet, probably going to remove one, and might add slots for rings and necklace. No rpg is complete without magic rings.

Friday, February 17, 2012

Not switching technologies

I have decided not to switch technologies and keep using slick and java to create my game.

I have over the last week experimented with Unity 3D and it's a fantastic tool for creating 3d games. If you have access to 3d models "an artist" you can in no time create a basic game that you can keep expanding on.

I created a flat box that was the ground, a player controller to move the camera around, some objects that I created in max and added some scripts to objects allowing the player to move them around. It's just a matter of writing more scripts and adding them to the player or objects to keep evolving the game. Fast and fun.

The reason why I am not using it is that I like programming, and there's not a lot of that in Unity. Granted, you can write a lot of scripts in java script or c#, but I spend a lot of time manipulating 3d objects in the editor and creating stuff in a 3d modeling program when I would rather be programming.

My pace will slow down a bit from now on as I have a lot of other things on my plate at the moment, but hoping for a bit of time this weekend. Would be nice to add some unholy monsters that are in dire need of some smiting :-)

Monday, February 13, 2012

How to draw isometric tile map

Drawing an isometric map is not that different from a regular tile map. Granted there are a bit more going on when calculating where to draw the next tile on the screen, but traversing the map is the same.

On a regular tile map, you start by drawing the tile furthest away so that you don't overwrite tiles that have already been drawn. It's the same with isometric. In your head, keep thinking of the map as a 2 dimensional array where you start by drawing all tiles on the x axis and then increasing y and draw all tiles along the x axis on the line. It's the same thing you do with isometric. There are other ways, but this is the easiest one, at least I think so. The other one involves even and odd lines and stepping through the map in a strange way.

Now you need to draw them on the screen, and that is where the tricky part is. I have added my code to draw the floor, see it below. There are surprisingly..... comments in it, how did that happen?

The code that implements this.
private void drawFloor(){

    // Get player position, only used if player is always at the center of the screen
    int mapDrawCenterX = player.getMapPositionX();
    int mapDrawCenterY = player.getMapPositionY();

    // how many tiles to draw on either side of the player   
    int startMapX = mapDrawCenterX - Globals.DRAW_TILES_X;
    int startMapY = mapDrawCenterY - Globals.DRAW_TILES_Y;
    int endMapX = mapDrawCenterX + Globals.DRAW_TILES_X +1; // +1 is to create a center tile for player
    int endMapY = mapDrawCenterY + Globals.DRAW_TILES_Y +1; // +1 is to create a center tile for player

    // the first tile to draw
    int mapX = startMapX;
    int mapY = startMapY;

    // displacing the drawing area so that it's don't start at the top left of the screen
    int drawStartX = 512;
    int drawStartY = -250;

    int drawX = drawStartX;
    int drawY = drawStartY;

    int linesDone = 0;
    boolean done = false;
    while (!done){

        // Check if this tile is inside the map, check if the drawing coordinate is inside screen
        if ((map.isInsideMap(mapX, mapY)) && (drawX <= 1024 || drawY <= 768) && ((drawX + Globals.FLOOR_TILE_SIZE_X + Globals.FLOOR_TILE_PADDING_X > 0) && (drawY + Globals.FLOOR_TILE_SIZE_Y + Globals.FLOOR_TILE_PADDING_Y > 0))){

            // Get the tile and check if there is an image to draw. -1 means nothing there.
            Tile tile = map.getTile(mapX, mapY);

            if (tile.getImageIndex(Tile.FLOOR) != -1){
                Image floor = map.floorImageList.getImage((tile.getImageIndex(Tile.FLOOR))).getImage();

                // Get lightmap corners for this tile
                float[][] lightMapColor = lightMap.getLightCorner(mapX, mapY);
                   
                // Set image corners to the lightmap corners.
                floor.setColor(0, lightMapColor[0][0], lightMapColor[0][1], lightMapColor[0][2], 1.0f);
                floor.setColor(1, lightMapColor[1][0], lightMapColor[1][1], lightMapColor[1][2], 1.0f);
                floor.setColor(2, lightMapColor[2][0], lightMapColor[2][1], lightMapColor[2][2], 1.0f);
                floor.setColor(3, lightMapColor[3][0], lightMapColor[3][1], lightMapColor[3][2], 1.0f);

                // Finally draw image
                floor.draw(drawX, drawY);
            }
        }

        // step along the x axis of the map
        mapX++;

        // Move drawing "pointer" to the next tile, half tile length on x and half tile height on y
        drawX += (Globals.FLOOR_TILE_SIZE_X + Globals.FLOOR_TILE_PADDING_X)/2;
        drawY += (Globals.FLOOR_TILE_SIZE_Y + Globals.FLOOR_TILE_PADDING_Y)/2;

        // Nothing more on this x line on map, starting on next line
        if (mapX >= endMapX){

            linesDone++;
            mapX = startMapX;
            mapY++;

            // black magic moving the drawing pointer to the start of the next line ;-)
            drawX = drawStartX - (((Globals.FLOOR_TILE_SIZE_X+Globals.FLOOR_TILE_PADDING_X)/2)*linesDone);
            drawY = drawStartY + (((Globals.FLOOR_TILE_SIZE_Y+Globals.FLOOR_TILE_PADDING_Y)/2)*linesDone);
        }

        //Check if we are done and end the loop
        if (mapY >= endMapY)
            done = true;
    }
}


There are probably a lot of optimizations that can be done to it, I haven't looked into it yet as the game was running fast enough as it is. Besides, don't spend time optimizing stuff before it's necessary, and use a profiler to identify bottlenecks.

There's some stuff there you cant see, like the tile padding. I use that as my tiles don't connect directly, there is a 2 pixels gap between them on the x axis so that the tile below fit's in it. See pictures below.

The tiles are 62*32 pixels.


So when adding more rows of tiles they fit into the 2 pixel gap on the x axis.

The 2 pixel gap is not something I came up with, it's a friend of mine. He's a graphics artist and it all adds up in the end.

Hope that helped, please ask if you have any more questions.

Wednesday, February 8, 2012

Experimenting with a new technology

I have over the last couple of days been experimenting with Unity. It's a 3D game development environment. It's basically a 3D editor and scripting tool where you can load 3d models or create primitives in Unity, then add script to control those entities.

It am considering moving my project from 2d to 3d. All my game stuff right now is very basic, so a few new textures and it should be working.

I have not tried to generate a lot of random stuff in Unity, so don't know if my random level stuff would work, but it's worth a try.

There is a free version of Unity that everybody can download and use. Games developed in this free version is as far as I can see yours to do with as you please. There is of coarse a lot of stuff missing from the free version that you would get in the pro version, like real time shadows, refraction and other stuff that would be cool to have.

One more thing that unity allows for is releasing executables for different platforms, Windows, Mac, Iphone and android. You can also create a web launcher so that you game can be run from a web page, now that would be great for my project so that it can be played directly from the site I choose to release it from.

One downside is that I have to learn a 3d program of some sort. Hmmmm, not my strong side but might be a great learning experience and being self proficient might be a good thing.

More experimenting will follow. If it proves suitable for my project I will switch to Unity.

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.