Showing posts with label Un-Escapable Loop. Show all posts
Showing posts with label Un-Escapable Loop. Show all posts

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.

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.