Best viewed in Firefox

Awesty Productions

Making an RPG type game

October 29th, 2006 by awesty

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:

onClipEvent(enterFrame){
    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:

onClipEvent(enterFrame){
    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 ;)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • del.icio.us
  • digg
  • Furl
  • MyShare
  • NewsVine
  • Netscape
  • Reddit
  • Simpy
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

RSS feed | Trackback URI

211 Comments »

Comment by Bob
2006-11-04 07:18:12

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/

 
Comment by awesty
2006-11-04 14:39:26

Nice work ;)

 
Comment by Lachy
2006-11-05 18:17:16

Hi,

Are you going to be continueing this tutorial to make like a full game.

Thank

 
Comment by Bob
2006-11-08 21:55:17

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.

 
Comment by awesty
2006-11-09 15:36:01

@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.

 
Comment by Bob
2006-11-09 21:40:30

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?

 
Comment by Bob
2006-11-09 21:43:03

Wait that didn’t make much sense either. I mean to say, what numbers for any key.

 
Comment by Ryan
2006-11-10 10:43:07

I don’t get it, just kidding!

 
 
Comment by Bob
2006-11-10 21:36:55

Thanks! That will help.

 
Comment by Mohit
2006-11-25 21:46:25

Hi Awesty,
I was just wondering if there was some way of selecting the sword when you have it in your inventory.

 
Comment by eb264
2006-11-26 08:13:00

@mohit: id say that will be in the next tutorial

 
Comment by David
2006-11-26 20:56:16

when will the next tutorial be out?

 
Comment by iAnimate
2006-11-27 04:51:35

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

 
Comment by Zach
2006-11-27 10:51:17

How do you make a flash game on your own?Cause I want to make one but I dont know how to…

 
Comment by awesty
2006-11-27 16:20:43

@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.

 
Comment by awesty
2006-11-27 17:26:03

@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.

 
Comment by Bryce K :P
2006-11-29 13:48:01

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 :)

 
Comment by Bryce K :P
2006-11-29 13:48:30

Just a thought*

 
Comment by awesty
2006-11-29 15:41:40

Do you mean a tutorial about it or actually make it?

 
Comment by Bryce K :P
2006-11-30 01:12:21

actually make it :) then we can all play it :)

 
Comment by Dorian
2006-11-30 02:11:24

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 :)

 
Comment by awesty
2006-11-30 11:11:47

@Bryce: Lol, that would take ages and involve a fair bit of coding. I don’t know if I’m up for it. :P
@Dorain: …

 
Comment by Angel
2006-12-01 15:50:40

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.

 
Comment by awesty
2006-12-01 16:19:30

I will do a tutorial on birds eye view AI.

 
Comment by RedV
2006-12-02 11:47:41

how can i make it change character frames when i turn?

 
Comment by awesty
2006-12-03 17:40:43

That script already makes it go to the 2nd frame, if you want it to go to different frame just change the number.

 
Comment by gram669
2006-12-03 23:22:31

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…

 
Comment by =ßoC= Darker
2006-12-04 02:04:24

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 :D

 
Comment by Bryce K :P
2006-12-04 02:44:53

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

 
Comment by Bryce K :P
2006-12-04 02:54:06

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 :))

 
Comment by =ßoC= Darker
2006-12-04 03:14:11

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

 
Comment by awesty
2006-12-04 12:38:10

@Bryce K: I got you email and replied.

@Everyone else: I will try to implement these into future tutorials.

 
Comment by RedV
2006-12-04 13:13:19

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!!!

 
Comment by awesty
2006-12-04 16:52:05

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.

 
Comment by RedV
2006-12-04 17:29:02

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?

 
Comment by =ßoC= Darker
2006-12-05 01:23:07

make sure he has the instance name of man. :)

 
Comment by Bryce K :P
2006-12-05 13:41:26

awesty i replied the e-mail :P

 
Comment by awesty
2006-12-05 16:05:05

@RedV: admin[@]awestyproductions[.]com

@Bryce K: Yep. I might not reply tonight, I will when I have time.

 
Comment by gram669
2006-12-05 16:23:50

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…

 
Comment by Bryce K :P
2006-12-06 13:09:14

okey dokey :P

 
Comment by awesty
2006-12-07 15:30:47

@gram669: To tell you the truth I have never seen a tutorial like that. Maybe I might do one.

 
Comment by @""£barns£""@
2006-12-09 23:19:38

im sorta new to this flash, is there and easier way to understan this?

 
Comment by RDB2006
2006-12-10 02:30:50

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?

 
Comment by eblup
2006-12-10 05:29:01

hey he dosent walk diagnal waaaaaaaaaaaaaa but still nice work

 
Comment by eblup
2006-12-10 07:56:09

plz make him walk diagnal.

 
Comment by awesty
2006-12-10 11:12:11

@@”"£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.

 
Comment by RDB2006
2006-12-10 21:49:34

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

 
Comment by RDB2006
2006-12-11 00:22:33

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?

 
Comment by eb264
2006-12-11 01:23:23

@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

 
Comment by RDB2006
2006-12-11 04:17:14

kk ty eb ill try it soon

 
Comment by awesty
2006-12-11 15:45:29

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.

 
Comment by RDB2006
2006-12-11 18:14:58

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

 
Comment by awesty
2006-12-12 15:54:23

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.

 
Comment by Gray
2006-12-12 22:25:05

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

 
Comment by RDB2006
2006-12-13 02:53:42

@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.

 
Comment by rrr444
2006-12-13 02:55:01

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…..

 
Comment by rrr444
2006-12-13 02:56:38

and does anybody have a good name for my game? i want a really good name but my mind is completley empty

 
Comment by RDB2006
2006-12-13 03:04:54

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

 
Comment by Gray
2006-12-13 05:26:14

thanks that really helped

 
Comment by awesty
2006-12-13 17:22:59

@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.

 
Comment by rrr444
2006-12-13 18:03:39

wouldnt i hav to put code on the text and the person i wana walk into?

 
Comment by yakult
2006-12-13 18:08:27

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?

 
Comment by yakult
2006-12-13 18:20:13

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????

 
Comment by mike
2006-12-13 18:29:43

hey im realy looking foward to the next tutorial
keep em coming when is the next one lined up for

 
Comment by gram669
2006-12-14 00:41:13

awesty: tnx so much.. im looking forward on it.

 
Comment by eb264
2006-12-14 02:01:27

@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

 
Comment by no1jock
2006-12-14 03:24:18

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…

 
Comment by rrr444
2006-12-14 06:12:34

ok. Ive set a specfic text field to alpha 0. When you click a button, i need it to appear. Can you help

 
Comment by ptp
2006-12-14 13:29:38

how do you put to guys in MC and then switch between them.

 
Comment by John
2006-12-15 04:23:18

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 :D

 
Comment by Bryce K :P
2006-12-15 10:32:19

can someone tell me wuts worng with my Xp bar its malfunctioning http://www.swfup.com/swf-view.php?id=3345

 
Comment by awesty
2006-12-15 11:37:46

@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?

 
Comment by awesty
2006-12-15 12:12:52

@mike: Hopefully over the next few days.

 
Comment by Bryce K :P
2006-12-17 01:06:56

okay i e-mailed the code to you, plz post it in the forums cause the e-mail isnt workin rite

 
Comment by awesty
2006-12-17 11:27:55

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){
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 if(jumping == true && this.hitTest(_root[”ground” 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 if(!jumping && !this.hitTest(_root[”ground” i]) && !falling){
falling = true;
this._y -= 1;
}
if(falling == true){
for(i=0;i if(this.hitTest(_root[”ground” i])){
falling = false;
}
}
jump -= 1;
}
}
}

 
Comment by Bryce K :P
2006-12-18 00:06:45

wasn’t even close to working had to many errors (and i did fix most of them)

 
Comment by Eddie
2006-12-18 08:33:53

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?

 
Comment by awesty
2006-12-18 10:32:49

@Bryce K: That is very weird, it didn’t have any errors for me. :(
@Eddie: What version of flash are you using?

 
Comment by Bulletluigi
2006-12-18 11:57:25

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 ^.^

 
Comment by no1jock
2006-12-18 22:28:11

how do you make a flash button link to a html link?

 
Comment by awesty
2006-12-19 17:56:00

@BulletLuigi: Yes, that is a much better code. I will be using that from now on.

@no1jock:

on(release){
getURL(”URL”);
}

 
Comment by Bulletluigi
2006-12-19 18:57:39

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.

 
Comment by Bulletluigi
2006-12-19 18:59:20

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?

 
Comment by no1jock
2006-12-19 22:16:23

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);

 
Comment by Bobkins
2006-12-19 22:19:41

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

 
Comment by eb264
2006-12-20 00:45:14

@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

 
Comment by no1jock
2006-12-20 02:28:25

ty for ur help

 
Comment by ???
2006-12-20 21:02:48

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?

Comment by Nicholas Subscribed to comments via email
2007-11-30 05:02:18

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.