Thursday 23 September 2010

Save it for a rainy day

So the other day I bought a PS3. Shocking, I know. So far I've only got the one game: Heavy Rain, but I'm playing it with every spare minute I have. Also next week I get FF14 and Fifa 11 to distract me even more! Things are not looking good on the Marc being focused horizon! If things start to go quiet, you know where I am...but you also know I'll be back just as soon as I've played these games to death ;)

Sunday 19 September 2010

Collision detection

Making a map with lots of objects can cause problems in terms of detecting collision between scenery and the player character. Each update, every object on the map must be checked to see if the player is about to walk into it or not. If you're on a world map, that's a lot of things to check every time the player moves just one pixel! So I figure the easiest way is to have something that I'm going to dub a "collision map".

Take this small map for example (made in the map maker! woo!)

This map is tiny (10x10 tiles) and yet there are 7 objects in this scene that will need to be checked for collisions:

The tree
The tree stump
The archway
The building
Three separate rock objects moved close together to give the impression of a rock cluster

The idea behind the collision map is to allow a single check to be performed for collisions rather than one per object. To do this I'll need something that looks like this:



Black regions indicate solid areas while white regions indicate passable areas. As the game runs I can check the player position and the direction they are moving and then check to see if they will end up in a black region. One check that encompasses all objects on the map. Handy! Combine the collision checking with the graphics side of things and no longer are we restricted to checking "collision bounds" (rectangles). We can have any shape we want.


I'll have to add this functionality into the map component, so give me a few days to get it sorted =)

Friday 17 September 2010

Bug fix update

Things are looking good. A lot of bugs have been fixed and I'm nearing the stage where I'll be working on the maps themselves. The tree is now sorting everything alphabetically which makes things nice and tidy. Copied objects are now working. There was a problem where copied objects "forgot" their name which kept popping up time and time again, even after I thought I had fixed it. Seem's I've squashed that one for the last time. There were also a few problems with tilesets not being loaded in time for objects to be drawn. All these have been sorted.

The only thing really left to do is to tidy up the GUI. I've begun work on the object preview panel which shows a picture of the object that has been selected in the tree. I figure it just makes things easier to find, especially when you have a lot of variations of the same object (Tree, Tree2, Tree3 etc...)

We'r getting close to some creative map creation people!! The sprites are coming along nicely as well, courtesy of James Boote. Will have some posts dedicated to the cast once I begin work on the game engine, cus that won't be fun to write about...

Wednesday 15 September 2010

This working hard is hard work =(

I've not had a chance to do an awful lot toward the map maker in the last few days. In fact truth be told, since my last update I have fixed a grand total of 1 bug. Actual work has been so crazy lately it leaves my head exhausted and I can't think straight. I went to bed at 10 o'clock the other night....10!!! I haven't done that for about 2 years! But as things quieten down (they feel like they are anyway...) I can get the ball rolling again.

Naturally; as I've fixed one bug another shows it's face. It was the case that copied objects are pasted under the name of "copy of ", however a bug meant that any object that was copied was just called "copy of". That has been fixed, but now it seems copied objects aren't copied so much as...they are the same object... That is to say that if I made a bed and called it "Bed", then copy and pasted bed into another folder I'd have a new object "Copy of Bed". If I then opened "Copy of Bed" and placed a desk next to the bed, you would find that the desk has also been drawn on the original "Bed" object. Fun fun fun!! In theory this is easy to solve, but it just takes time and time is what I lack! Hold on for just a bit longer, we'l be getting to the fun part soon...

Sunday 12 September 2010

Bugs live in tree's...

While working on some additional options for the tree (the object browser thingy) I seem to have stirred up a nest of bugs. Some of which seem to only appear at random. Something tells me the next few day's will be nothing but cleaning up some of the stuff that already exists. Doesn't look like there will be many updates over the next few days =(

Saturday 11 September 2010

Booya!

Hooray!!! After days of headaches trying to figure this thing out I've finally got the tree structure saving and loading the way I want it. Objects and folders are loaded into their correct parent folders, with the correct names, with the correct icons. Objects within the tree also save and load the objects data, booya!
Because I am using custom tree classes I had to learn how to write some custom serialization and deserialization to get things working properly. Not to mention a few recursive for loops to get things displaying correctly!

consider the fact that a for loop...well....loops...It does the same thing over and over again. Then consider in terms of programming recursion is the process of something running it's code again. I've essentially made something that loops...then half way through the loop it runs another loop....which runs the same loop under different circumstances...and so on. Even if you don't understand what I'm talking about you can understand where my headaches came from! I mean that alone sounds complicated. Imagine trying to figure out some of the numbers that you get after all those loops have been run! Crazy stuff!

But still, the reward is that I've learnt some new stuff. Hoorah! Knowledge is power you know. There's still some things I'd like to sort out, namely the ability to right click a folder and create a new folder/object directly within the folder that has been clicked. Also at the moment although objects and folders can be moved to different folders, once they are inside a folder, the order of them can't be changed. I'd like either some automatic sorting or manual organisation within folders. But for now I'm gonna go rest my poor head =(

Friday 10 September 2010

We've gotta save the tree's man!!

Alrighty folks, some progress has been made regarding browsing objects. I've created the tree so that it supports restructuring. For example:


Objects can be moved from folder to folder. Folders can be moved in and out of folders carrying all of their contents with it. You can NOT move a folder into an object or move a parent folder into one of it's child folders.

The only problem I'm having now is creating a class that can hold the information needed to save the current structure and load it again once the program starts back up. Once I've figured this out, I can tidy up a few things like creating folders inside other folders. Slow progress, but progress none the less. Saving these things are a pain! Now I know how the hippy's fealt...

Monday 6 September 2010

Planting tree's

Time to update you on why there have been no updates for the past couple days. I'm struggling with tree's...That's right, you heard me. I figure the best way to view/manage the large amounts of objects I need to create is to view them in a tree. That is to say place them in a folder, but have the ability to have folders within folders separating objects into sections and sub sections. Normally this is easily done, however I also want to be able to add new folders on the fly and rearrange existing objects so they can be moved around. This is proving significantly difficult to implement, but I'm on the ball and powering through it...Updates to come once I've figured it out!

Wednesday 1 September 2010

Yay! Progress!

So it's the last day before I go back to work, kinda lookin forward to it actually...I'm sure that feeling will disperse when I have to wake up...Anyway's, I made the most of it by sorting out a few optimizations and finalizing the object maker. Aside from a few GUI tweaks the job is done! Check it out.


You can now select any portion of a tileset and draw it to a base layer (layer 1) or a height layer (layer 2). Anything drawn on layer 2 is drawn on top of the player character making it seem as though he has moved behind it. In the example above you can see I have drawn a pillar, however the top half is semi transparent. This is because it has been drawn to the second layer but I am currently drawing to the first layer. This means it's possible to see both layers while working. Makes things a lot easier!

Another feature you can't see here is that when you have tiles selected and you move the mouse over the drawing area you will get a semi transparent preview of the object you are about to draw so that you can see what it looks like before you draw to the object.

Objects can be saved and loaded correctly (although I have not implemented loading properly yet, but I have tested it to make sure it doesn't blow up).  Better still I've also made optimizations to the tileset manager so that saved files do not take up as much space. The optimization also means that when you load a tileset, the file is copied in the programs directory so that it doesn't have to keep looking for where the file is hidden on your computer. Thinking ahead, it also makes it easier for me to load resources once I begin working on the game itself.

Other features that have been implemented allow you to resize the size of the object (i.e how much space you have to draw stuff), the ability to snap your tile placements to a grid, as well as the ability to toggle grid drawing, tile placement previews and the snap to grid function on/off.

I'll begin working on a browser for all saved objects soon so that we can begin making maps!

Also as promised the solution to the puzzle from my last post:

You can work out the number of tiles that go across the tileset easy enough by doing
Tiles Across = Tileset Width / Single Tile Width

We can also find the row and column of the first tile ID that is selected
First Tile Column = X Position of Selected Tiles / Single Tile Width
First Tile Row = Y Position of Selected Tiles / Single Tile Height

From which we can get the ID of the first selected tile
First Tile ID = (First Tile Row * Tiles Across) + First Tile Column

Now all we need is the total number of tiles selected down and across
Selected Tiles Across = Width of Selection Box / Single Tile Width
Selected Tiles Down = Height of Selection Box / Single Tile Height

Now we have to use for loops to make numbers increment every time we run this next equation.

ID = (First Tile ID + Incrementing Number 1) + (Tiles Across * Incrementing Number 2)

Incrementing Number 1 is constantly incremented, until it is equal to the number of Selected Tiles Across at which point it is reset to 0.
Incrementing Number 2 remains at 0 until Incrementing Number 1 is reset. When this happens Incrementing Number 2 is incremented.
The process is repeated until Incrementing Number 2 is equal to the number of Selected Tiles Down

For any programmers looking for the solution here it is in C#


                        int TilesAcross = (m_Texture.Width / m_TileWidth);

                        int FirstTileColumn = (m_SelectedTile.X / m_TileWidth);
                        int FirstTileRow = (m_SelectedTile.Y / m_TileHeight);

                        int FirstTileID = (FirstTileRow * TilesAcross) + FirstTileColumn;

                        int SelectedTilesAcross = m_SelectedTile.Width / m_TileWidth;
                        int SelectedTilesDown = m_SelectedTile.Height / m_TileHeight;

                        List list = new List();

                        for (int y = 0; y < SelectedTilesDown; y++)
                        {
                            for (int x = 0; x < SelectedTilesAcross; x++)
                            {
                                int i = (FirstTileID + x) + (TilesAcross * y);
                                list.Add(i);
                            }
                        }

                        return list;