Showing posts with label images. Show all posts
Showing posts with label images. Show all posts

Monday, March 29, 2010

Big Update is finished.

I have finally finished the overhaul I was talking about couple of days ago. And I think I managed to create some good stuff, albeit messy and hard to understand. 


Part 1: The Problem


The problem I had was the arrays. At first I wanted to be able to store them in a class, or a structure or even inside a text file that I would load. I rejected the first two, because making a class directly for a single array would be contrary to Object Oriented Programming and text files were useless since placing them outside my program was just as bad as bluntly dropping them in the middle of my main form, which was what I wanted to change. 


At first, I had arrays. My procedures would activate themselves with the arrays I needed by parameter and would fix the matrix accordingly. The problem with this approach, is that I need to know exactly what arrays to load when executing my procedures. This is chaotic because of transitions, going from map to map, as my game is not linear. I know not if the player will take a turn right or left. How can I decide what tile array to load in my functions ? This could have been hell...


Part 2  The Solution


 Instead I made a Terrain class. This class would have several parameters to hold the various arrays such as the tile and sprites arrays. As well as track which map is to its right, left, bottom or top. So instead of giving my sub several arrays. I would give him an instance of the clsTerrain class that represented a map. For example BasicRoad. I can them access its parameter inside the matrix such as BasicRoad.Spritemap or BasicRoad.TilesMap.  I would have a block of code on top that job would be to instantiate each map and give them the geographical location in relation to the other maps. 


The clsTerrain class:

So now that all our maps are there, we need to make our player able to switch maps. This is called a transition, it is triggered by stepping in a tile and pressing the according button. If you are at the top tile and you press the top arrow you get to the map that is right on top of the current one.But then we need to identify which tile is a transition, I could just leave it like if you are standing a tile in the border and you press the according button you get thrown to the next map. But then what would I do with doors and such ? I chose to make transition recognition  as early as I can. For this I had a couple of choices: I could just programmatically make them by telling him which tile to mark as such by hand. That is tedious and stupid. Instead I choose to add a third array and in there marking the transitions myself once and let him do the work. But how can a tile remember that it is a transition ? By adding a property, so I created a Tile class that inherits from picturebox and I added a couple of properties like IsTransition, a boolean value that marks a tile as one used as transition.

The clsTile class



This being done, I only need to configure the movement sub of each direction to respond if they are on a transition.  So the procedure is now ( in two parts ):

The moveRIGHT subroutine

Pretty big procedure. Theres 4 possible choices:
  • You are NOT on the border and NOT on a transition tile: You walk normally
  • You are are ON the border and ON a transition tile: Switch to next map
  • You are ON the border and NOT on a transition: Walk as long as the direction you're going is not out of bounds
  • You are NOT on the border and ON a transition: This is a "Door-transition", this will teleport you somewhere else. Not yet implemented
There IS a lot cleaner way to do it, but this is just a project to "make it work". The really big thinking process will be done in the final version of the project. Until then I just hack my way through my game and I will optimize later on. This is to keep me from falling out of morale. Since this is my first project that has a slightly bigger scale than normal ( for me ), I think that If I was to take 3 weeks to think out a single perfect function I would drop the project after 3 days. Now I can see my progress clearly, establish goals and accomplish them with relative ease, giving me the satisfaction needed to go forward.

Part 3: What's next ?
Right now, I have no idea. I'd like to take some time to create some more tiles to make rather more complex maps to bring me to the next features. The next logical course of action would be to make "Doors transitions", basically when I am walking on a door transition I get "inside" the building. Which is a map by itself. To do that I first need to create some kind of house tiles and that means a lot of work since all I did yet was some crappy grass and patches of road. And I was lucky with those, I just happened to arrive at a really good result on my 2nd try. I tried to make some mountainside tile a few days ago and it was really crappy. So lots of studies and practice incoming. I'd welcome any kind of suggestion, I understand that since this is not my final product I could just go to some website, rip some sprites and use them like some of my colleagues are doing. But what would be the point ??? I'm going to end up doing all the work anyway, might as well do it now and gloat the power of my magnificent tiles for a while. I would agree with the person that tells me that since they're nowhere near done yet that my tiles are "un-gloatable" but its a work in progress ! At least I can be happy in the fact that I don't need to steal all my shit. Anyway. I should also start thinking about the music and the game-atmosphere like the story and characters, in short the non-VB stuff. I'll be sure to keep you posted with updates. I still have a couple posts about problems that needs some explaining. I would like to explain in details how the transitions work because I think my system is pretty damn well though ( without wanting me to give myself too much credit ). 

I'm pretty happy with my progress so far. In ONE month I went from a corpse-less form with nothing at all on it, to a corpseless form with nothing at all on it BUT at least now I can make characters pop on the screen and move around. OK OK, I admit. Some people could do that in a day and do it better. I am not one of those people, I am studying in my second year. This is some pretty heavy stuff for the amount we learned in class. And I plan on making a LOT more with increasing complexity. I am talking of course about the battle system, and inventory and menus and all. I have yet to know what and how I will do this, but it will be grand I think. 

Until then ! See you on top of the next article.

Saturday, March 27, 2010

Object's Virtual Frame

As an answer to the "un-escapable loop" problem I had a few days back, Object Oriented concepts are directly relevant. The virtual space an object take can be a complex topic and I will try to explain as I can.

Objects are just representation of a concept, or a class in VB. When creating a new object, you use the keyword "New" to tell the compiler that this object is totally another thing. When you have a clsChair class, you ideally want to pump out a chair that is going to be distinguished by other with its properties, its name, tag or any other. When VB sees the "New" keyword, its meaning to create another area in memory where this chair will be stored at. If you have two "New"' 's you will have two areas in your memory allocated to chairs.

Similarly, you can omit the "New" keyword entirely. And it will not give you an error. Because if you do not specify the "New", you will just use the class as default and only object. And note here, ONLY object. Meaning he will re-use the default one over and over.

I say defaut but its not exactly that way, an object is pointed to by its reference address. Say our class resides inside the memory at 0x11AA00, thats the "reference" I will be using. Lets say I want to get the number of legs our chair has, I tell my computer to look at whatever class is stored at 0x11AA0 and return me whatever leg property is in there. It will NOT use the name of the class you defined. And this is exactly the problem.

When using the technique I used, that is, not using a new. You end up with every object ( in this case, pictureboxes) using the same address. Same address means properties having the same values. When looping through my image matrix, the lowerbound and upperbound had the same reference address, therefore the first object is ALSO the last one. Which explains why it stopped after a single iteration. Because it already complete ALL its run in a SINGLE shot ( because every other tile were already affected instantly ).

Take a look at this picture:

Wednesday, March 3, 2010

Design UPDATE !

Yes, an update already. I've been messing around with my IDE and decided to give a go to the design of the game. What I did here was to generate the grid of the game window. As you know in earlier RPG's, the world was a series of tiles aligned in a matrix pattern ( Meaning for example: a 16x16 grid, showing 256 tiles total ) and your character and anything in the game world occupied a single tile. I made a few samples to give me a better idea of what I wanted my game grid to look like.


I had a choice between placing each individual tile on the form, or programatically add them after the form loads. The advantage in adding them after the form has loaded is that your form can be easily modified. As well as giving a greater number of design tweaks. I tried both method thought, placing them manually and automatically. And here are my results:


The one on the left is the automatic, right now is manual.

I chose the colors at random just to give me an idea on the output. Not a lot of difference you might say ? Well when you look at my design form, you can see it is a lot less cluttered. 

Automatic generation yields a much cleaner form designer.


The one on the left is the auto-generated window, the one on the left is the one I added every single tile by hand ( with the help of CTRL+V of course ). You can see the absence of picture boxes on the one on the left because there is currently no tile alive yet. They have yet to be created. Also, the code for autogeneration is MUCH smaller than the manually added at start. 

Let me explain why: When placing controls on the form, even thought you cannot see the related code, some is still created. For a single picture-box, is looks like that
      Me.PictureBox195.Location = New System.Drawing.Point(288, 372)
        Me.PictureBox195.Name = "PictureBox195"
        Me.PictureBox195.Size = New System.Drawing.Size(32, 32)
        Me.PictureBox195.TabIndex = 213
        Me.PictureBox195.TabStop = False
Multiply that by 256 times, and you get quite a big file to load already at start. Meanwhile, when adding them automatically when the form loads, they are added one by one with much cleaner code thus making your source code smaller and lighter. The code I used for both forms is thus:

The first one is for the auto-generate, and the second one is manual. You can see on the second image that the only code running is the color-chooser, thats be cause there IS NO code needed on the main() procedure for showing all the picture boxes. But when you compare the first to the second, one simple method is much cleaner than 265 chunks of designer data.


All in all, auto-generation is a much better choice for the purpose of making game because the grid is not static. As we move to the edge of the screen I have to be able to change the map very quickly and efficiently .