MapSwitch- Getting the player to spawn where you want on the map
Displaying 1-20 of 39 total.
12 next
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
M_Dragon

Hello again! In my game I have a world map (Map of the main character's world) which has many zones leading off to different maps, i.e. a town, but I don't know how I can switch the maps back to the world map and have you appear back at the zone you stepped on.

Posted on 2014-05-09 19:45:12

Kildorf

If you'd like to load into a map somewhere other than the "starting location" defined in the map, you'll have to do a bit of extra work.

Basically, you'll want to write you're own function for switching maps. In that function, set some global variables to the X and Y coordinate you'd like to load into on the new map. Then, use Map() to actually load the map.

Give the map an autorun function, and in the autorun just set the player's location to whatever you have stored in the global variables. The map will load and immediately the player will be set to the place you wanted!

If you want to see an example of this, check out my (painfully old) game Journey to Black Mountain -- http://verge-rpg.com/downloads/journey-to-black-mountain. In system.vc, starting on line 219, there is a function called MapSwitch(). Then, every one of my maps has an autorun script called start(), which does what I describe. (Feel free to just go ahead and copy anything in that code that looks useful to you, by the way!)

Let me know if anything doesn't make sense, or if you're having trouble understanding what's going on in Black Mountain.

Posted on 2014-05-10 15:27:47

M_Dragon

Thank you!!!! I will be sure to check it out.

Posted on 2014-05-10 22:23:41

M_Dragon

I downloaded the game so I'll look through the system. Thanks again Kildorf!

Posted on 2014-05-10 22:37:07

M_Dragon

For the mapswitch code, I copied and pasted it into my system vc but when I tried to start verge, it didn't run. I got something along the lines of "error, there is no such thing as mapSwitchT!" What did I do wrong Kildorf?

Posted on 2014-05-17 02:47:23

Kildorf

You know, now that I look at this all again, this is a lot more complicated than it needs to be. Let me fiddle around with a bit of code and get back to you with something a little easier to work with.

Posted on 2014-05-17 04:56:27

Kildorf

Okay, I dug into the old code and have made some updates. I didn't really do much to the maps (or the art or the music or... ugh), but I updated to the latest engine and cleaned up the main system code some.

http://kildorf.com/westrun/journey_to_black_mountain.zip

(If you use Chrome, it might warn you that this is dangerous to download or whatever because no one else has; I assure you it's the same game as available on the site, with a few tweaks to the code.)

The important parts here are two files: mapswitch.vc and transitions.vc. Feel free to copy these right into your project! You can use them with #include ...

#include "mapswitch.vc"
#include "transitions.vc"


... in your system.vc file.

There are three functions you'll need to use. First, before you call any maps (somewhere in autoexec() would work), call setDefaultPlayerCHR(). This sets the CHR file you want to use for your main character. In JtBM I call it right before my first mapSwitch, on line 255 of system.vc.

    setDefaultPlayerCHR("kiel.chr");


Next, when you want to switch to a map, instead of calling Map() directly, call mapSwitch() instead. It takes five parameters:

void mapSwitch(string mapname, int x, int y, string face, int trans);


- mapname is the name of the MAP file you want to load.
- x and y are the coordinates you want to put the player at to start.
- face is one of "U", "D", "L", or "R" (for up, down, left, and right, of course) which is what direction you want them to be facing when the new map loads. Lastly,
- trans is the transition you want to use for the map change, and should be one of either TRANS_BOX or TRANS_FADE. TRANS_BOX will give you a sort of shrinking/expanding box effect , while fade just does a fade to black and then back in.

I use mapSwitch all over the place in the map VC files. The first one I use is in system.vc on line 256, and looks like

    mapSwitch("home.map", 13, 4, "R", TRANS_BOX);


Lastly, in every map file you need to specify a Startup Script. You do this in the map properties (Map > Properties...) in maped3. I use the startup script name 'start' for all my maps, and they're always right at the top of the map's VC file, just for convenience. You need to call onMapLoaded() in this function. For example, from gory.vc in JtBM...

void start() {
	hookRetrace("tick");
	onMapLoaded();
}


You can ignore the hookRetrace, the important line is the second one. What that function call does is goes and retrieves all the things that got saved when you called mapSwitch() -- where you want the player to end up, etc -- and spawns a new player entity for you, and hooks it all up.


Whew! It's been quite a while since I've written any VergeC. I hope this has been somewhat informative! Take a look at how I implemented mapSwitch() -- hopefully it should be pretty straightforward. If you're still confused as to how it's working, I'm happy to explain more. :)

Posted on 2014-05-17 06:52:40

Kildorf

Okay, I realized there is one final tiny detail that you'll need for the transitions to work right. Check out line 9 in my system.vc

int img_flatblack = NewImage(320,240);


and then, inside autoexec(), line 68

    RectFill(0,0,320,240,RGB(0,0,0),img_flatblack);


Add those to your system.vc and you'll be able to do the fade effect properly. Sorry! It's hard to do this modular thing right sometimes, heh.

Posted on 2014-05-17 06:54:43

M_Dragon

OK! Thanks again!

Posted on 2014-05-21 22:52:23

M_Dragon

I tried to start verge to see if the code worked but I got 'error, setDefaultCHR is not known!'

Posted on 2014-05-22 00:06:40

Kildorf

Try setDefaultPlayerCHR() instead. ;)

Posted on 2014-05-22 04:10:24

M_Dragon

this is what i put in systems.vc under autoexec. Xerma is the main character.

setDefaultPlayerCHR("Xerma.chr");

Posted on 2014-05-22 22:57:29

Kildorf

Hmm... That does look like you're using it right. Would you mind sending me a .zip of your game and I can take a look at what's going on?

Posted on 2014-05-23 06:46:02

M_Dragon

What's a .zip? (Sorry, I am pretty new to coding and video game creation)

Posted on 2014-05-23 19:01:23

Kildorf

No worries at all!

A .zip file is where you compress all your files into a single file, so it's smaller and easier to pass around. The easiest way to make one in Windows, is to right click in Explorer and choose "New > Compressed (zipped) folder", and then drag files into it.

http://www.kildorf.com/junk/zip_folder.png

Then if you send that zip file to anyone, it will contain all of the files you dragged in there.

Posted on 2014-05-24 00:31:43

M_Dragon

I have windows 8 and I tried that but I can only make a new folder, no a zipped one. :(

Posted on 2014-05-24 14:13:54

Kildorf

Give this a try: http://windows.microsoft.com/en-us/windows-8/zip-unzip-files

Posted on 2014-05-25 03:07:38

M_Dragon

How should I send it to you?

Posted on 2014-05-26 15:50:05

Kildorf

Try emailing it to kildorf@kildorf.com -- assuming it comes through, I'll see if I can figure out what's up.

Posted on 2014-05-26 19:25:53

M_Dragon

I tried to e-mail it but gmail wouldn't let me do it because it contained executable files or something. I will try to send it again without those.

Posted on 2014-05-28 01:33:58


Displaying 1-20 of 39 total.
12 next
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.