Making an RPG type game
In this tutorial you will learn how to make a RPG type game in flash. I will only be teaching you how to set up the character and the actionscript, not how to animate the character. You should already know some actionscript and know how to find your way around flash.
The final result will look something like this.
First of all you need to make two movieclips of your main character, the first one is a birds eye view (top, looking down on the character) of him/her standing still. The other one of them walking. Now put them both into one movieclip, with the standing still MC (movieclip) on the first frame and the walking MC on the second frame. Make sure you put the action ’stop();’ without the quotes on each of those frames. Once you have that done give that MC an instance name of ‘man’ and put these actions on it:
if(Key.isDown(65)){
this._rotation = 270;
this._x -= 3;
this.gotoAndStop(2);
}else if(Key.isDown(68)){
this._rotation = 90;
this._x += 3;
this.gotoAndStop(2);
}else if(Key.isDown(87)){
this._y -= 3;
this._rotation = 0;
this.gotoAndStop(2);
}else if(Key.isDown(83)){
this._y += 3;
this._rotation = 180;
this.gotoAndStop(2);
}else{
this.gotoAndStop(1);
}
}
Okay, I will try to explain that as best I can.
onClipEvent(enterFrame){
All that means is ‘every time this frame is entered’. So if you have a frame rate of 30 (which I do) the following script would run 30 times a second.
if(Key.isDown(65)){
this._rotation = 270;
this._x -= 3;
this.gotoAndStop(2);
‘If the key ‘65 is down, this rotates to 270 degrees, this _x decreases by 5 (moves left) and this goes and stops on frame 2 (the walking frame). 65 is the key code for ‘A’. For this tutorial the controls for the character are going to be ‘W’, ‘A’, ‘S’ and ‘D’. Most of the other code is exactly the same as above with a few numbers changed, so I am not going to explain that.
}else{
this.gotoAndStop(1);
If none of the above code is happening (In other words, if none of the keys are down) this MC can go to and stop on frame 1 (the standing frame). Therefore when the MC isn’t moving it will stop on frame 1.
Now, if you haven’t already make an item for you character to pick up, and an inventory for it to go in.
Now, copy and paste your item and place the copied one in the inventory, like so:
But make it’s alpha 0, so you can’t see it. Give it an instance name of ’smallItem’ without the quotes.
Now select your item (the visible one), and put these actions on it:
if(this.hitTest(_root.man)){
this._alpha = 0;
_root.smallItem._alpha = 100;
}
}
All that means is when the ‘man’ MC hits the item (the visible one), that ones alpha goes down to 0 and the one in the inventories alpha goes up to 100. So it looks like you have taken the one of the ground and put it into your inventory.
That is it for this tutorial. Keep coming back for more















Awsome. I love your tutorials, keep em’ comming.
I made this with the help of some of your tutorials.
http://www.deviantart.com/deviation/42079834/
Nice work
Hi,
Are you going to be continueing this tutorial to make like a full game.
Thank
How did you program it to make the W,A,S,D keys move? Whenever I try to incorperate those into a game it doesn’t accept them.
@Lachy: Yes, but it might not be for a while.
@Bob: What version of flash are you using? If you use the code I used there it should work fine.
Flash 8 (basic). I need to be more specific, How do you program letter keys in any flash. Is there a website that will tell you what number is assigned to what letter?
Wait that didn’t make much sense either. I mean to say, what numbers for any key.
I don’t get it, just kidding!
@Bob: http://www.awestyproductions.c.....eycode.txt
Thanks! That will help.
Hi Awesty,
I was just wondering if there was some way of selecting the sword when you have it in your inventory.
@mohit: id say that will be in the next tutorial
when will the next tutorial be out?
thanks for the tutorial
http://denvish.net/ulf/1164564329_RPG Item example.php
that’s hat i made from it
I made few altercations though
1: for movement i used friction etc from the other tut
2: instead of playing with the MC’s alpha, i used blank keyframes, so my code was like
onClipEvent(enterFrame){
if(this.hitTest(_root.knight)) {
this.gotoAndStop(2);
_root.inventory1.gotoAndStop(2);
}
}
great tut, look forward to more by you
How do you make a flash game on your own?Cause I want to make one but I dont know how to…
@iAnimate: Nice, I never thought of that. I might have to try it out.
Btw, I don\’t think denvish works anymore.
@Zach: Just apply all your knowledge from tutorials into your game.
@Mohit: Yea, what eb264 said. There are so many tutorials I am trying to do at the moment I keep forgetting them.
@David: Do you mean one in particular? Because I try to add at least one every week, plus maybe a few articles or something. But I have been a bit slack lately because I have had other stuff to do.
dude you should make like a Ninja game it would kick ass, you know like running up walls and like sticking to them using a Samurai Sword and some sherikans (ninja stars) that would be sick! (Also if you don’t know wut i mean play Matrix Bullettime Fighting [I furgot wut website it was on but u can search it up on google :)])
Just a though
Just a thought*
Do you mean a tutorial about it or actually make it?
actually make it
then we can all play it 
Where do you find good life ,of course in the games .beause in the real life ,we have many distresses and pain, only in the games if we have enough gold to buy the good arms,and we can play the games well
@Bryce: Lol, that would take ages and involve a fair bit of coding. I don’t know if I’m up for it.
@Dorain: …
I understood the tutorial, but I’d like to know how to make the character throw an object, and how I can make an enemy move and throw an object at random and harm the character on contact.
I will do a tutorial on birds eye view AI.
how can i make it change character frames when i turn?
That script already makes it go to the 2nd frame, if you want it to go to different frame just change the number.
this tut is very good but i wanna know more about buying and trading inventory system… anyone has that kind of tut please let me know..? TNX…
Nice tut. it helped alot. I know this isnt topic related but does anyone have a tut on how to make a certain key play a certain noise, cause i want to make a game that allows you to play an instrument but you have to hit certain keys to get points, i hop you know what i am talking about.
Thankyou,
Darker
Awesty i have a “money shop” but im trying to make it when you have $10 (U.S.A. currency) you cant buy a $100 thing but when i click (buy $100 thing) it will say -$90 then it will say you have no money. this is hard to explain so ill send you a .fla file, (but my e-mail isn’t working to well and doesnt recgonize ur e-mail address so e-mail me then ill reply with the .fla file) my e-mail is ekusnierz@san.rr.com
ty
also when i e-mail you the .fla file can you give me some advice to? as when you buy the item it goes into your inventory? (ill have to make an inventory tho :))
can you show me how to make a currency, cause i really want to make a full flash game, if anyone has a different tutorial site please post it. It wouldnt really work to send me an email tutorial because my email doesnt work.
Much Appreciation,
Darker
@Bryce K: I got you email and replied.
@Everyone else: I will try to implement these into future tutorials.
ok i got everything working except this… i want my guy to permanently change frame when he pics up a sword so he goes from regular “man” to “sword man” so to speak…. when i step on the sword it changes the frame but when i step off it changes back….
please help me!!!
Okay, change this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
this._alpha = 0;
_root.smallItem._alpha = 100;
}
}
To this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
this._alpha = 0;
_root.smallItem._alpha = 100;
_root.man.gotoAndStop(FRAME);
}
}
Just replace FRAME with the frame number of the “sword” man.
well darn it still not working…. do you think i could send it to you and u can try to see whats wrong?
it would be a great help
if so then whats your e-mail?
make sure he has the instance name of man.
awesty i replied the e-mail
@RedV: admin[@]awestyproductions[.]com
@Bryce K: Yep. I might not reply tonight, I will when I have time.
awesty do you have a tut on rpg inventory.. i mean with trading system or buying items.. please let me know where i could have that kind of tut..
TNX A LOT…
okey dokey
@gram669: To tell you the truth I have never seen a tutorial like that. Maybe I might do one.
im sorta new to this flash, is there and easier way to understan this?
Hi. Good tutorial! Ive got one problem - when i load the game the small sword is already in the inventory box, and the big sword is on the ground (but it can still be picked up) cud u plz help?
hey he dosent walk diagnal waaaaaaaaaaaaaa but still nice work
plz make him walk diagnal.
@@”"£barns£”"@: No.
@RDB2006: Click on the small sword and in the properties panel you should see a drop down menu called Color. Click on it and select alpha. Make it 0.
@ebulp: Maybe.
i tried it, nd still doesnt work. WHen i change its alpha to 0 it can still be seen when i preview the game, and it also changes every other movie clip’s alpha to 0, and nothing disapears
:S
Im using all this stuff in ur tuts to put together a wee game, but im stuk, i have 4 drawings of my chacrater, he has his back facing towards you, he is facing you, he is facing left, he is facing right. Do you know how to make it so that when you use the arrow keys, the picture will change? e.g u press the left key and the picture of im facing left comes up, etc?
@RDB2006
name each frame of what the picture is of (eg. left, right, front, back)
and use this code:
onClipEvent(load){
if(Key.isDown(Key.LEFT)){
this.gotoAndPlay(”left”);
}
if(Key.isDown(Key.RIGHT)){
this.gotoAndPlay(”right”);
}
if(Key.isDown(Key.UP)){
this.gotoAndPlay(”back”);
}
if(Key.isDown(Key.DOWN)){
this.gotoAndPlay(”front”);
}
}
the last 2 are based on if when you press the UP arrow key, you want his back facing you (eg. he’s moving away from the screen) and when the DOWN arrow key is pressed, you want him to move towards you and face you. Should work
kk ty eb ill try it soon
Yep, eb246 is right. But I prefer to use frame numbers than labels, but that is just a personal choice.
Also you could use
if(something){
do this
}else if(somethign){
do this
}
So then it doesn’t jerk up when someone pushes two buttons at once.
i made 4 frames with the diff pics, nd i put the code on everyguy. It still doesnt work, but no errors come up :S
An error only comes up if there is a problem with the syntax, not if it doesn’t do you want it to since flash can’t tell what you want it to do.
You only need 1 MC, and put that code on it.
I’m trying to make an RPG and i’ve run into a problem:
How do you link scenes/frames together so that when you hit a door the scene/frame(which ever is easier) will switch to the inside of a room.
I know it has something to do with the hit.test action script code but I can’t figure it out
@Gray - Copy and paste this code into the door.
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.gotoAndStop(41);
}
}
Change 41 to whatever frame number the inside of the building is on. nd make sure the instance name of your char is man.
how do u make it so that when your char hits an object, a picture and text will appear without it changing frame, and when you bring your character off the object, it disapears. Im tryna make a game like the sims…..
and does anybody have a good name for my game? i want a really good name but my mind is completley empty
k so i have only once MC (Guy facing towards u) nd put this code on it
onClipEvent(load){
if(Key.isDown(Key.LEFT)){
this.gotoAndPlay(”left”);
}
if(Key.isDown(Key.RIGHT)){
this.gotoAndPlay(”right”);
}
if(Key.isDown(Key.UP)){
this.gotoAndPlay(”back”);
}
if(Key.isDown(Key.DOWN)){
this.gotoAndPlay(”front”);
}
}
nd i replace down nd stuff with numbers? nd leave the guy facing left, right, and back facing you, non movie clips?? :S
thanks that really helped
@rrr444: You would have to put something like this on it:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
this._alpha = 100;
}else{
this._alpha = 0;
}
}
Just change man to whatever the MC is called.
@RDB2006: You can replace “LEFT” etc with the numbers of the frames if you like, or you could give the frame facing left the name left, the frame facing right the name right etc.
wouldnt i hav to put code on the text and the person i wana walk into?
can somebody help me?
when the player moves the man, and it hits the door, and then also presses a button, then it leads to another frame?
hi umm i want to make a game can somebody tell me
i know how to walk into an object and get to a different frame but how do you get it so that when you come out of the frame you went into, (say a shop,) it returns you next to the door, not originally where your character started out on that frame. any help????
hey im realy looking foward to the next tutorial
keep em coming when is the next one lined up for
awesty: tnx so much.. im looking forward on it.
@RDB2006
you need to have a movieclip with the four frames inside and a stop(); action on each frame. then on the main scene, click once on the character and put the code in the actions panel. don’t forget to name each frame
thanks for the tut it helped me. Would it work if you sent it by email to your cell phone? I mean would you be able to play it because cell phone games are java but still…
ok. Ive set a specfic text field to alpha 0. When you click a button, i need it to appear. Can you help
how do you put to guys in MC and then switch between them.
I need help with mine, How do you make a wall, I mean so you just make like a rectangle and like instance name it wall or w.e and the hole thing turns into a wall? Instead of just keep naming top one top1 bottom one bottom1 and so on. Also if theres actionscript tell please
can someone tell me wuts worng with my Xp bar its malfunctioning http://www.swfup.com/swf-view.php?id=3345
@rrr444:
on(release){
_root.TEXT._alpha = 100;
}
Just change TEXT to whatever the text MCs instance name is.
@yakult: So you want that to happen?
Once you have the button and the door, put this code on the button:
on(release){
if(_root.man.hitTest(_root.door)){
_root.gotoAndStop(FRAME);
}
}
You would obviously have to change the doors instance name to what it really is and change FRAME to what frame you want it to go to.
About the door thing, you would use a variable, so when it hits the door, door = true. So when it enters the shop if(door = true) it starts off in a certain _x and _y coordinates.
@no1jock: As far as I know, it wouldn’t work.
@ptp: You would need to put them both into 1 movieclip, one on the 1st frame and one on the 2nd. And then to use the first do _root.man.gotoAndStop(1);. Just change the frame number depending on which one it is. Make sure the guy has an instance name of man though.
@John:
http://www.awestyproductions.c.....h-hittests
@Bryce K:
Can you post or send me the code so I can have a look at it?
@mike: Hopefully over the next few days.
okay i e-mailed the code to you, plz post it in the forums cause the e-mail isnt workin rite
There are no errors anymore, but it doesn’t jump. I wasn’t sure what it was supposed to do so I just left it like that.
onClipEvent(load){
if(jumping == true && this.hitTest(_root[”ground” i])){
if(!jumping && !this.hitTest(_root[”ground” i]) && !falling){
if(this.hitTest(_root[”ground” i])){
var jump:Number = 0;
var falling:Boolean = false;
var g:Number = 4;
}
onClipEvent(enterFrame){
if(jumping == false){
if(!falling){
jump = 0;
}
if(Key.isDown(Key.UP)){
jump = 15;
jumping = true
}
}
if(jumping == true){
jump -= 1;
}
if(jump <= -10){
jump = -10;
}
for(i=0;i
//Is there supposed to be some code here?
}
}
if(Key.isDown(Key.LEFT)){
this._x -= 5;
}else if(Key.isDown(Key.RIGHT)){
this._x = 5;
}
for(i=0;i
falling = true;
this._y -= 1;
}
if(falling == true){
for(i=0;i
falling = false;
}
}
jump -= 1;
}
}
}
wasn’t even close to working had to many errors (and i did fix most of them)
I have problem, everythings right, instances, MCs, all that other stuff but one my character touches the pick-upable object it doesn’t do anything. Help?
@Bryce K: That is very weird, it didn’t have any errors for me.
@Eddie: What version of flash are you using?
Awesty this tutorial is really good, but since you use alpha you would have to have a different inventory slot for every item in the game right?
I’m not saying it isn’t still a good idea, but I searched a lot and found a pretty cool way to make a little bit better one, though it takes a whole lot more scripting.
For each of your item slots you name them, itemSlot1, itemSlot2, itemSlot3, and so on..
this is the script for the items -
onClipEvent (enterFrame) {
if (_root.character.hitTest (this)) {
_root.addToslot (this);
}
}
this is for frame one -
currentslotnum = 1;
stop ();
function addToslot (item) {
if (!item.found) {
item._x = eval (”itemSlot” currentslotnum)._x;
item._y = eval (”itemSlot” currentslotnum)._y;
item.found = true;
currentslotnum ;
}
}
make sure that your moving symbol is instance named - character
It worked perfectly for me and i give praise to the person that thought of this beautiful actionscript.
P.S. - Awesty I still think you are the best ^.^
how do you make a flash button link to a html link?
@BulletLuigi: Yes, that is a much better code. I will be using that from now on.
@no1jock:
on(release){
getURL(”URL”);
}
Yea it is awsome, I have been doing adjustments like, making the “I” key change the alpha of the items in the slots and the inventory from 0% to 100% its great.
Oh yea, hate to double post like this, but i wanted to ask you something about the script that i posted for the inventory. I understand all of the script, but I am not familiar with “eval” could you explain that to me?
ty for the code, but this error came up. What do i do?
**Error** Scene=Scene 1, layer=menu, frame=1:Line 2: ‘)’ or ‘,’ expected
getURL(http://www.awestyproductions.com/tutorials/flash-tutorials/making-an-rpg-type-game/#more-33);
good tutorial awesty. Im making an rpg, and i need help with some code. Im having it on my game that when you walk into an object (movieclip,) if you have variables, then it will take you to another frame. I tried this code:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
if _root.kill = 3;
‘(’
if _root.drug = 14;
‘(’
_root.gotoAndStop(207);
}
is it something like that? cuz it isnt working for me. If it isn’t plz post me the exact code if it isnt 2 much trouble becuz im rubbish at following detailed intrsuctions.. lol :S
thanks
@no1jock
put inverted commas (” or ‘) at the start and end of the web address. it would be something like:
on(release){
getURL(”http://www.awestyproductions.com/tutorials/flash-tutorials/making-an-rpg-type-game/#more-33″);
}
i think thats it
ty for ur help
there is a problem with my game. When you press the W,A,S,D, keys it rotates weird. one minute its in the centre, then when you press the keys, it rotates around the centre can anybody help me pleez?
if you open up your mc the little crosshair is the pivot point so basicly you have to put the midlle of the charecter on the pivot point.