PDA

View Full Version : Art-Based RPG Tutorial



Marz
February 21st, 2005, 06:50 PM
Art-Based RPG Tutorial
-----------------------------------
Part One :rd:

     Here it is. Something most of you guys have been waiting for. How to create an Art-Based RPG. Again, I'll be using my lovable character : Marz to instead of walking around in a tile based environment, will now walk around in an art based landmass. Is it harder than tiles? Actually I found it to be easier to code for an art-based rpg instead of a tile-based.

     So what's the big difference? Well that I will cover when I write my tile-based vs art-based rpg tutorial. But for now, let's just worry about how we are going to work with an art-based rpg.

     In Part One we are going to discuss what it takes to make the hit boundries for a art-based rpg. The fact that it's almost as simple as tile-based to make these hitBoundries is something to attest to. But before we get into that, let's look at what we are going to be creating.

http://www.mentalconcepts.com/game/art_walking.swf

Note : At 100% jpeg quality and the code involved, the movie still stays around 50-60 kbs. Not too shabby.

     Now, here is the interesting part. What does it involve? Well, my character already knows how to walk around, so we shouldn't have to go over that again. But in case you need a piece of code, here is my function that allows my character to walk and walk with animation as well. You can find more out about this function in my original rpg game programming tutorial.




MovieClip.prototype.moveMan = function(moveX, moveY, facing)
{
if(_global.aniMation == 5)
{
_global.aniMation = 1;
}
else
{
_global.aniMation++;
}
currentFacing = (facing * 5) + _global.aniMation;
this.gotoAndStop(currentFacing);
this._x += moveX;
this._y += moveY;
}

_root.onEnterFrame = function()
{
// Walking Script for Marz

if(Key.isDown(Key.DOWN))
{
if(!walkingMarz.testLimits(0, 5))
{
walkingMarz.moveMan(0, 5, 0);
}
}
else if(Key.isDown(Key.UP))
{
if(!walkingMarz.testLimits(0, -5))
{
walkingMarz.moveMan(0, -5, 1);
}
}
else if(Key.isDown(Key.RIGHT))
{
if(!walkingMarz.testLimits(5, 0))
{
walkingMarz.moveMan(5, 0, 2);
}
}
else if(Key.isDown(Key.LEFT))
{
if(!walkingMarz.testLimits(-5, 0))
{
walkingMarz.moveMan(-5, 0, 3);
}
}
}



     Now. In this you will see another function. The testLimits function. This function allows us to test for boundries. But first, let's check out the boundries for the art-based RPG above.

http://www.mentalconcepts.com/game/art_based_1.jpg

     OOoo... Let's check out the function that tests our limits in this now.



MovieClip.prototype.testLimits = function(xdisplacement, ydisplacement)
{
ydisplacement += 20;
for(var i in _root.limits)
{
if(_root.limits[i].hitTest(this._x+xdisplacement, this._y+ydisplacement, true))
{
return true;
}
}
return false;
}


     This allows a quick and easy system to be made. You can create a whole messload of boundries, place them inside of a movieClip named limits, and this function will rotate through them all to make sure you are hitting them correctly. The returning result will tell you if they run into a wall : true or if they don't run into a wall : false.

     Now... A couple of the variables you see in this might look a little bit awkward. Lemme explain. I am using this variable to check and see if I should move the character, so I use the testLimits function with an xdisplacement / ydisplacement factor to allow me to check ahead of my character. You can change around these values to change where you want your character to be tested. There are a whole sleugh of options available.

     Hopefully you guys took in the ease of using those functions. As always, if you have any questions post here or PM me :) Peace

superNoobice
February 22nd, 2005, 08:36 AM
:thumb: You are a big Help marz. Giving tuts every once in a while. Hope you never get tired of doing this. Keep it up! :thumb: I'm also looking forward to your AI tuts. It's not yet finished right?

And 1 more thing can you explain the functions further? :)

peace

Inferno
February 22nd, 2005, 08:41 AM
Dont u have anything better to do? :D

j/k

Coke
February 22nd, 2005, 09:32 AM
Shut up, hes helping people

JoMan
February 22nd, 2005, 11:16 AM
Great tutorial, Marzman :beam:!

kanpai

Inferno
February 22nd, 2005, 12:05 PM
Shut up, hes helping people

Umm.. as you can see it was a joke :shifty:

Oh yeah, my friend says thanks for this tute, he has been looking something like this long time :thumb:

Marz
February 22nd, 2005, 04:39 PM
No problem guys..

And no Inferno, I don't.

As for the functions.. Here is an explanation of how to use the testLimits function.



MovieClip.prototype.testLimits = function(xdisplacement, ydisplacement)
{
ydisplacement += 20;
for(var i in _root.limits)
{
if(_root.limits[i].hitTest(this._x+xdisplacement, this._y+ydisplacement, true))
{
return true;
}
}
return false;
}


Using my function, the only thing you have to do is attach it to a movieClip that you want to test the hitTests of. Like...

walkingMarz.testLimits(0, 0);

The (0, 0) arguments in this statement allows you to change the point that will tested against the boundries.

Now, this particular function returns something.. But for those of you who aren't familiar with functions. Think of this function like this. In our if statement I put this.

if(!walkingMarz.testLimits(0, 0))

Basically... When you run my function, it tests every single boundry in _root.limits and if you hit one of the boundries, the function returns a value of true, but if you don't... It returns a value of false. So...

if(false) or !walkingMarz.testLimits(0, 0)

or else

if(true) or walkingMarz.testLimits(0, 0);

If you guys need anymore explanations of this. Please ask me. :)

von_dragon
February 22nd, 2005, 09:56 PM
great tutorial marz. Your a great teacher.

E-Slayer
February 24th, 2005, 10:50 AM
Wow...that helped me out, but not with what you were planning. That gave a wonderful example of how to use a prototype... Also, could this script be used to create walls or objects where you can be on either side, but not in the boundary itself?

Marz
February 25th, 2005, 01:15 AM
Absolutely E-Slayer. You would just have to make a boundry for it to recognize. I'll make you a quick example of it tomorrow. :)

E-Slayer
February 25th, 2005, 01:19 AM
Nifty, thanks. I think that boundaries like that would work much nicer for my game than tiles.

Marz
February 25th, 2005, 10:20 PM
Don't have time to talk... But e-slayer... here is your example of a boundry inside... just a box around the cow... notice the swapDepths too guys ;)

http://www.mentalconcepts.com/game/walking_cow.jpg

http://www.mentalconcepts.com/game/art_walking.swf

Enjoy :)

Dr Warm
February 27th, 2005, 08:15 AM
Hey Marz, i'm a bit rusty, but i can't seem to figure out this line:


for (var i in _root.limits) {
is limits supposed to be a mc? Then where does the 'i' variable come from?
I tried making a fla out of it but i'm guessing i'm supposed to add something else?

Oh and also the _ydisplacement += 20, that's the height of you're mc, with registration at the bottom? Just to get that straight.

Thanks.

Marz
February 27th, 2005, 04:55 PM
That is correct about the _ydisplacement :)

As for the for...in loop. _root.limits is the movieclip that is holding all of the bounding boxes. Each bounding box has it's own instance name and is a movieclip in itself. This for...in loop goes throuh all objects / movieclips in _root.limits (or the movieclip that holds all the bounding boxes) and it assigns that obect to the i. I guess I should have been more clear with my code and stated something like :

for(var bounding_box in _root.limits)

But... Then you can use the variable as a basic instance name.. So you could say :

_root.limits[bounding_box]

pomogranate
March 9th, 2005, 01:30 PM
Yo, Marz what do I place this code under:

MovieClip.prototype.testLimits = function(xdisplacement, ydisplacement)
{
ydisplacement += 20;
for(var i in _root.limits)
{
if(_root.limits[i].hitTest(this._x+xdisplacement, this._y+ydisplacement, true))
{
return true;
}
}
return false;
} :puzzle:

Marz
March 9th, 2005, 05:32 PM
You would put that in your main timeline. The first frame... The one that loops consistantly around.