Sunday, May 9, 2010

Design update !!

Hey, I told you all that I would take my time and post something eventually. Well now is the time !

I have been working on the way my main form looks like. I had a few problems: 
First I wanted to get rid of the ugly conversation panel I have. The idea of a form popping whenever you talk to someone is crap, and having to close it again and again is a pain sometimes. I wanted to have some kind of control that would show messages for me. I have recently learned to make my own custom controls and found the idea of having a portable "messages & communication" box quite good. And here is the control and the code: 

The images speaks for themselves. The messagebar has a sub named addMSG() used to send messages to the textbox. The textbox is readonly to prevent the user disturbing the text and because the keys I use to move are the arrow keys I have made a sub to replace the caret (the little horizontal line standing where you clicked) every time a key is pressed. That way you cannot scroll through the textbox inadvertently when moving, only with the scroll bar. 

I have also begun to look into the code involved in moving around. The same 4 subs ( one for each direction) are both used to move and initiate a transition and I think this is a flawed way of getting around since the complexity is very case-by-case and thus need a lot of if's to verify stupid stuff. Due to the complexity of the overhaul this could take some time but I am still working on other parts while I'm digging around for a better solution. 

I have downloaded some tiles on a website because I don't really have *that* much time on my hand for designing .jpegs, time that could be better used somewhere else. They look good and I plan to make use of them someday to showoff a better version of the game. 

The game now looks thus: 



As you see I have made some subs to handle conversation. Now every sprite has an NPC class that is used to store conversation and other relevant stuff. I'll explain it in a later post. On this note see you all at the next post !


Saturday, April 17, 2010

Blog is NOT dead.

Like I said in an earlier post. I won't be posting a lot these days. I have a shitload of work to do for school and friends to take care of, so the little time I get to program stuff is spent in fruitless attempts to re-engineer my movement system. That or creating sprites or tiles. I'm hoping to be able to post a bit more in the coming weeks, I just need some new material to blog about. I'll find something new to implement in my game and work on it.


Until then, take care !

Thursday, April 8, 2010

Ha, been a week already !

Yeah no kidding, more than a week without post. You guys must be really bored. Well as you know I've been doing design lately and since I'm doing this on paper ( with a pen yes ! Like old times ) because it illustrates ideas better when you can freely draw and cross things out.


I have nearly a page of story and some pages of mechanics for the game that I'd like to implement. The story will be put in a .doc format and sent online so it can be browsed. Its NOT finished yet and I might just take another story that I started from scratch.


Beside that I'm pretty busy with other stuff, school and friends have successfully managed in keeping me away from concentrating on programming ( or sprite creation ), I'll be sure to make a couple big updates when I get a breather.


I'm also looking for books to read on subjects like A.I. , game design, story writing ( for games), graphical design ( Pixel art preferred, I don't do 3d ) and programming ( vb.net, of course ^.^ ).

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 24, 2010

Update !

Hello, I've been working a lot on the project these days. I have implemented transitions between maps ( will make a post about that piece of code soon, I'm still working on the "Un-escapable loop" post ), and I have arrived at a point where my system began to be messy and unorganized. I have began to code a massive overhaul regarding my arrays. I can't just let them sit at the top of my class. Because of my goal of having at least 30 minutes pf content, I will probably have to make a lot of individual maps. Outside maps, indoor, inside dungeons etc. And triple that because I need to add a sprites_map and a transition_map to each of them. That could mean a couple hundred of arrays just sitting there waiting to be used.

My idea is that I would make individual text files containing the maps ( single map per file or a single big file with all maps, I don't know yet. Or even an XML file on the condition that I re-read on the subject). I now have to make a class and get the I/O working well. Every time you move to the edge of the map over a transitional tile, the matrix will change its tileset and put you in place. This is particularly rough part on me and I need to read a lot of stuff and my post count will probably drop a bit. I will try to keep you all entertained ( all two of you reading my site ). even though I'm busy as hell.

Keep looking over my GitHub page, frequent updates are to be found. For those who forgot the link, check my pages.


EDIT 10:32 24/03/10 :
I have nearly finished the overhaul I was talking about. It is a MAJOR change throughout the project. If I was to explain everything I'd have enough material for 2 weeks. Prepare for some big posts later in the week or the next.

Saturday, March 20, 2010

Now on GitHub

Hello all, quick update. As you can see from last post I have now a GitHub account and I will posting my code at various intervals in there. For those who does not know, GitHub is a version control system with a website front-end. It allows people to upload their code, branch it, fork it and post it so other people can see it. You can visit my page here.


My page at GitHub will be less updated due to the fact that I will release both a vb.net 2008 and vb.net 2010 version. They both use different version of the .net framework so they are not backward compatible. So I have to downgrade my code and make modifications to it. I will try to keep everyone informed when I add major modifications on my repository.

Friday, March 19, 2010

I love the smell of burning CPU in the evening, smells almost like... Victory

Oh yes ladies and gentlemen. I have now a playable version of my game, its not much. But it is the content of all I've been doing these past 2 weeks. You can browse the code here and download an executable from this page.

And I DID solve my Un-Escapable loop problem, I'm going to make a port on this one. 


Milestone 2


After hitting more walls in my previous version of the program I decided to create another form where I would put only the code I need. To make it cleaner and more manageable. It is currently at its third iteration. But while I was looking at my code ( which was muuuch easier to read in a clean environment not chuck full of properties and classes anywhere) I though of the following logistic: I have two matrices, two arrays and 3 methods to help me put those on the form. If I followed my plan to make another matrix for the game hero, I'd have even more. So why not make it only 2 methods, one to fill the matrices, and one to show them. Simple since they do pretty much the same. And to that conclustion I said, why not have a single matrix ? Why would I need 2 layers when I could easily do it with one, and actually make this a lot more simpler and easy. The final result is that I have a single matrix of pictureboxes and two arrays with two methods to fill and stamp it. 


This is the code I used. you can see this all the simpler. 


The loop problem was caused by this: from the moment I decided to use an matrix of pictureboxes instead of images I changed from a type to an object. Do when typing 


Dim tileMatrix(15, 15) as Picturebox


What it did was to create 256 pictureboxes that are actually the SAME picturebox. Because there is no New()   I will create a subsequent post explaining this particular error but for now do understand that the problem was that every picturebox in my matrix was the same picturebox. It was a single one with 256 references through the matrix. 

Tuesday, March 16, 2010

A brief intermission.

I haven't been active a lot these days due to a couple things. First off I hit a problem on my project that is rather frustrating and I chose to take a break to get my mind off. I don't particularly mind problems when they're solvable. Like, the problem I had with the For Each that I will explain here is that kind of problem. Its possible to solve them using logic and a couple of tests. But there are problems that require a little bit more patience and hacking to solve.


The problem I have is related to the debugging phase. You get a bug, you yell "WTF !" you look in your code: nothing. You check the logic of your reasoning, the way data is handled: nothing. Then you decide to put a break point somewhere and run your program. Execution stops, you take a peek at the data, you see what the problem. you go back the code, you change a line or two and TADAM. Magic, problem solved ! But I did that, and nothing at all. Heres a sample of the broken code ( I thought I had it saved somewhere but it seems that part of code was deleted, here is something that should look like it. )

Sub something()
For Each c as heroTile in Me.Controls
       Me.controls.remove(c)
Next   ' Breakpoint right at this line. 


msgbox("Test Test Test")


End Sub
I inserted a break point at the Next keyword. And the msgbox method is for testing purposes, you will see why in a moment. After execution, the loops go through the controls and removes them. ( This will actually return an error, but this is just a sample to illustrate my problem ) When he hits the next, after every iterations are finished or while he is doing it. Execution stops. You heard me right, it just stops !! It will not budge, I can't make the execution go forward because he will NOT go to the next line. The compiler just waits there and looks stupid. I repeat, msgbox is NOT shown because execution will NOT go through that line. Which admittedly is weird. It might be something I'm missing or knowledge I don't have, but without a couple of hours of research I just can't see how I will solve this. Meanwhile, I thought of something for you guys:

For Next "Remove control" error.
Lets say I have this piece of code in a procedure:
Your guess is a good as mine, is scrolls through every control inside the form, and removes every pictureboxes. One by one, pictureboxes will be removed. From the first to the last. Unfortunately, you will find yourself with this result:

Can you spot why ? I'll tell you why. Because the Remove() function works in a special way. I made up a little .png to explain how it works. Image looks like crap but at least I can explain what it all means.
First lets say I have 10 picture boxes numbered 0 to 9. I want them all dead. I invoke the Remove() function inside a loop and I'm done. Actually, its otherwise. First, during the very first iteration of the loop ( lets say a For Each ) he will "plug" himself on the first picturebox he sees. He will then delete the control. BUT he will take every other control in the collection and move them one place up the collection. So element 1 will be element 0, element 2 will be element 1 etc. But a For Each works in ONE way and its numerically from the first control to the last. After deleting what was contained in the first address, he will move to the second EVEN IF THE CONTENTS OF THE FIRST ADDRESS WAS FILLED UP. At the second pass, he will remove the second element ( which is originally element #3, the second one is replacing the #1). This will create the blanks you can see in my output. Each one he removes, the next one is skipped. The problem is easily resolved by using a Do Until or another mechanism to check if there is a pictureBox remaining and delete it until there is none on the form.      

I'm hoping this piece will help some people when they see the same problem. This information was found using MSDN, never forget to hit the f1 key when you need help !

Thursday, March 11, 2010

Milestone achieved !

The Proof
Well I finally have something to show as a proof of concept:

Isn't that awesome ? Megaman standing on a map full of road and grass ! I made the image extra large so you all could see it. The simplicity of this piece of program is more complex than you can image. I will deploy a few images to explain what code I used to piece this up.

First I used both the "ArrayMap" and the "GridMatrix" technique from earlier posts. I have two arrays - BasicRoad and SpriteMap, that contains the values of which tile and sprite to apply in which position of the matrix ( as seen on the left ).

Then I created a method to take the values in the BasicRoad array to decide which image to place in the tiles matrix.
Afterwards I took the images from the matrix and put them inside a picturebox-like class and placed the tile on the form.
Next I had to do the same with the sprites, but unfortunately I had a problem. My idea was to place the sprite in a picturebox and put that picturebox on top of the tile he's resting on. But there is no opacity property on pictureboxes so wherever I put the sprite he was hiding the tile under him. Making an ugly hole in the map. to solve this problem I used the backgroundImage property and took the image of the tile he's resting on and applied it as background.

I created two classed derived from picturebox: GridTile and SpriteTile so when I scrolled through the form I could use their type to get only the tiles or only the sprites.
 
You can see that I am passing quite a few parameters to these classes, instead of giving them their values after I created them. I made a New() so I could give them their values directly when created. Much cleaner that way. You can see where I use the me.backgroundImage property and used the coordinates from the matrix. 

I'd like to stress that this is NOT a representation of the final project. This is from the vbProject that I made to explore the mechanism that I will use in my game. I still haven't done a single line of code regarding the game itself. The sprite I used are not mine and property of their respective owner. But I can take credit for the tiles since I made them, and they are awesome.

Wednesday, March 10, 2010

The "ArrayMap" technique.

The Basics
This technique is another way of representing a map created from a set of tiles. With the GridMatrix technique, I created a matrix with the exact size of my window and applied and scrolled through the matrix generation pictureboxes and applying them a specific tile ( a 32x32 picture ). 


There are a few weaknesses with this techique. First if you look my code closely I AM NOT EVEN inserting values inside the matrix, I am merely strolling through its dimensions and using this to represent rows and columns. This strikes me as the first big weakness. The second one is that: what if I need to access the tiles afterward ? Lets say my caracter is at the right edge of the screen and goes right, supposedly to make the map scroll to the right. Well because I did not store the location of the tiles and images somewhere, I have to re-scan the whole window and somehow code a way to remove the leftmost column and add one at the right. This is a would-be pain in the ass.


And here comes the ArrayMap technique:



This is an array. It signifies that the letter A represents all those numbers at once. And that we can get their values easily. 

An array is declared just like any other value:

Dim tileset as array

And to populate this array:

tileset = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 }

Tileset will now have those values stores inside him. To retrieve them we can make a For Each loop and write each in a console

For Each x as Integer in tileset
        writeline(x)
Next


The Method I use

So I made a couple of arrays and planned to make picturebox images from the value contained in the array. Say the first value in the array would be 0 so the tile at (0, 0) is going to be say, grass. The 14's value would be the code for (14, 0) and the 16'th would be (0, 1)  (because we are scrolling left to right and then go to next line after the 15'th element ). 

Those are my arrays
The code I used to turn values into tiles:


And the result of using the BasicRoad tileset is: 



This is pretty much like the GridMatrix technique but instead of looping through a matrix we are using a For Each to cycle through the values of the array and using a Select Case to decide which tile to use as the image. 

Sunday, March 7, 2010

My Tools

The IDE
IDE for Integrated Development Environment, is the "main tool" used for programming. It is the workbench in which you will code and look at the results. Nearly every language have an IDE, many languages indeed have many of them. The one I am using is the Visual Studio 2010 from Microsoft. 
Visual Studio 2010 - Ultimate

This is the release candidate for the 2010 version of Visual Studio. This include the Team Suite. The Team Suite is the set of tools to work with a Team Foundation Server, I manage one and I use it to share all my projects with different computers. It is a very powerful version control system. 


Team Foundation Server


Team Foundation Server is a version control software. In layman's terms, it keeps your projects sync'ed between computers. How it works is that you first upload a project to a Collection. A collection might contain many files and VB projects. When you want to work on a project you do a "Check-Out" of the files you need. While the files are checked out, no one can save any modifications to it until files are checked back in.  

Red Gate's Reflector

This tool is a decompiler made specifically for .net assemblies. What a decompiler does, is that it shows you the software source just by looking at the .exe or .dll.  You can understand that it is a very powerfull tool to inspect other's people code without having the source code. This decompiler works only with .net assembles. 



Sandcastle

Sandcastle and its GUI package is a software that will go through your project's code pages and generate .htm files out of your XML comments. This is very useful for publishing documentation.



SQL Server



SQL Server is what helps me with the configuration and use of the Team Foundation server. It allows me to create databases for each collection.







Thursday, March 4, 2010

The "GridMatrix" technique.

The Basics
As you can see from my last posts, I will be using matrices a lot. First off what is a matrix ? It is an array of data arranged in a special fashion with each other. A single matrix may have several dimension
A matrix can have any number of dimension but it is impossibly hard to imagine more than 3. But there are applications for them still. 

A matrix is created thus:

Dim myMatrix(4, 4) as Integer

This will have created a matrix with two dimensions, each containing 5 elements ( starts at 0 ). Easy isn't it ?

The Method I use
We will then look at this piece of code here:

This is the code to make a simple 5 x 5 matrix and write the column number to the console. Note than I did not generate values inside the matrix, it is still empty. I allowed my program to follow the flow of the matrix and reflect the geometry of the matrix itself. 

I use a sweeping technique, I choose each line one by one with the first For Next loop. This will allow me to "plug" myself in a single line. After this I sweep through the columns using another For Next. Then moving unto the next line and repeating. 

Couple interesting points here.  myMatrix.getLowerBound(0) will take the lowest position of the first dimension ( in this case the dimension 0 ) and will go up from there until he encounters the upper boundary of the dimension. If I wanted to make a 3-dimension matrix I would have written 

Dim myMatrix(4, 4, 4) as integer

The output is then: 


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 .