PDA

Click to See Complete Forum and Search --> : Beginners Mapping System.


tonyenkiducx
Oct 12th, 2000, 04:50 AM
Heres what I found to be the easiest way to program a movement system.

Create 2 arrays, one is your map, the other is your Character.

Dim CharacterArray(5)
Dim MapArray(10,10,1) ' this will allow for a set of squares, 10 by 10.


Then you need to setup the map array, you need to draw the 10 by 10 grid on paper, and draw your map on it using 1 square as a location. Then make a note on each square what exits are available, using N for north, S for south and so on. Then match up the grid locations, (i.e. 2(across),5(down)) and do...

MapArray(2,5,0) = "NS" ' this tells the program that the user can move North, and South
MapArray(2,5,1) = "An empty Street" ' This is the description of the location.


Then the character array contains this data.

CharacterArray(0) = "Allanon" ' There name
CharacterArray(1) = 0 ' There Across position in relation to the maparray
CharacterArray(2) = 0 ' There Down position in relation to the maparray


Then When a character requests to move, all you need do is this code...

If moverequest = "N" and instr(maparray(characterarray(1),characterarray(2),0),"N") Then
CharacterArray(2) = CharacterArray(2) + 1
End If

TO move south, just subtract 1 from that, and user characterarray(1) for moving east and west.

Then all you need to do it print out the description..

User.Screen.Caption = maparray(characterarray(1),characterarray(2),1)

You can expand on this lots, adding up and down, is very easy, and both the character array, and the map array can have any amount of extra data added to them.

Tony@Work.

HarryW
Oct 12th, 2000, 09:31 AM
Quite a neat and tiday way of doing it.

One point: wouldn't you be better off with a user-defined type for the character? You seem to be using the array to hold general information on the character, I think maybe a UDT would be more appropriate.

tonyenkiducx
Oct 12th, 2000, 09:36 AM
Most definately.. but for simplicity(Simpletons?) sake, I figured, array heh ;) whats your opinion on a method of storing these arrays? Im was debating binary or text file, but then I realised that the character is constantly updated, so it needs to be written to the file on a regular basis, in case of crashes and the like.. :P

DarkMoose
Oct 13th, 2000, 03:41 PM
Yep, it probably will crash a lot. Keywourd: MICROSOFT visual basic ;) I agree with the user defined types thou. A lot more convenient than arrays.

[Edited by DarkMoose on 10-13-2000 at 09:52 PM]

/\/\isanThr0p
Oct 13th, 2000, 05:37 PM
Seems like DarkMoose found the way to underline! lol

Koralt
Oct 13th, 2000, 06:17 PM
Heh ... surprised though I am to find stuff about text adventure games on a VB forum ... well, frankly, that's quite probably *not* the best way of doing it.

I say that mainly because in text adventure games rooms are very rarely uniform size. Going E-N-W-S will not always take you back to the same room. Plus, there's up, down, and any number of other directions.

A better method would be to have a one dimensional array of descriptions, array(s) to store any other info (including what items are there, etc.), and what room you'll end up in for each direction you can go.

DarkMoose
Oct 13th, 2000, 08:53 PM
sourry about the excessive underlining! i fixed it now ;D

PaulLewis
Oct 13th, 2000, 09:16 PM
But with the support VB gives you for Classes and the forthcoming additional OO tools in VB7, I would use a customised linked list for each room.

Each room object can contain a collection of direction objects (or simple UDT). Each direction object contains a link to another room object. Direction objects have two labels (depending on which direction you are looking from) and may be enabled or disabled in each direction.

You would have to read in all of the serialised rooms and directions, but you will end up with a far easier way of dealing with events that can happen in rooms, objects/creatures that are present and other things that may change (such as night/day or weather conditions).

Each room object (and direction object for that matter) can implement an interface which accounts for any environmental changes that take place.

As I said, I've never made one so I cannot prove the worth of my suggestion. In OO terms though the theory is sound.

Regards

tonyenkiducx
Oct 14th, 2000, 06:46 AM
I said it was the EASIEST way, not the best, try reading my posts before replying to them. and its is a movement system for a MUD really, not a text adventure..

Koralt
Oct 14th, 2000, 12:57 PM
Erm ... I did read it, and I didn't say it wasn't the easiest way, either. I was simply suggesting another idea, nearly as easy but more versatile. ::shrugs::

PaulLewis
Oct 14th, 2000, 03:20 PM
tonyenkiducx, I was replying to Koralt who mentioned text adventure :)

Your posts didn't really say what the system it was for so of course I assumed it was for what Koralt thought :)

But if I were to critique your original post, I would need to disagree with your idea of easy. I understand that you thought of using multidimensional arrays and no UDT's for ease of use, but by ignoring UDT's you make your job harder.

Personally, I find that beginners learn UDT's ultra fast whent hey have a good example to work from. The next step from UDT is really a Class but I would admitt that writing good classes is beyond most beginners.

Finally, Koralt makes a good point about directions and relative room sizes so I guess a MUD is by definition a 2-D grid of same sized rooms? Does MUD=Multi User Dungeon or something?

Anyhow, sorry for any insult you may have taken from my suggestion. :)

Cheers

tonyenkiducx
Oct 14th, 2000, 05:19 PM
Ok, I guess I reacted badly, it comes from answering emails at 6:30am when you cant sleep. I apologise as well for being bad tempered when there was no need. If you wanna do something for international relations(Theres me assuming your all american again ;)), you could take a look at my full app. A shortened(Little content) version is sat at http://www.enkidu.cx. A website is forthcoming, when I can be arsed. Considering this is the first full VB app Ive written, Id appreciate any comments on wether it even comes close to what you would consider sane. I've been told lots of times before that arrays are bad, but I like em dammit, and Im perfectly happy working with them, so, no array comments please :0

PaulLewis
Oct 14th, 2000, 11:48 PM
I for one am not American. I'm Kiwi (in case that is meaningless to you it means I am from New Zealand).

Where is .cx?

Regards

tonyenkiducx
Oct 15th, 2000, 04:27 AM
.cx is christmas island, but Im in the UK, I just got the domain cheap ;)