PDA

View Full Version : Creating an RPG - A few questions


anthonyds
09-05-2005, 11:19 PM
Hello there. I absolutely love old-fashioned RPG's, and am thus trying to create one myself. But I'm facing a few problems at the moment.

I designed the game like this : I have 6 layers
-Actions
-Status
-Player
-Text
-Plaque
-Mainscene

The main problem is movement. I have no trouble moving the player movieclip around the scene, but I don't know how to make walls or other objects block the player. If I want the player to be blocked, I have to (at this point) repeat the movement code for the player in every frame, and manually implement the "blocked spots" into the program. How can I let my player always be blocked by a wall tile ?

Thanks in advance,

Anthony

[Sx]
09-05-2005, 11:48 PM
Well, you can create your tiles as movie clips and then use .hitTest(your_player) against them to check for collision... However, that's not practical for anything large-scale, at least not with current .hitTest's limitations...

I would do it totally scripted... e.g. you can create a grid array of your stage like:

gameGrid = [
[ 1, 0, 0, 1 ],
[ 1, 1, 0, 1 ],
[ 1, 1, 0, 1 ],
[ 0, 1, 1, 1 ]
];

Where 0s would represent walls... And then have your player move in that grid. If player is currently at [3][2] position, and presses UP, you check for [2][2] - it's 0 so it's wall and you prevent player to go up... If user presses LEFT, then you check for [3][1], it's 1 so user can move to that 'tile'... Beside plenty advantages of such approach, one of the biggest advantages is ability to do path finding script and then move user allong that path, which is usually a must-have for RPGs...

Hope it helps...

Tower2
09-06-2005, 03:25 AM
I think that sx has a good approach.

You could also make it more complex by adding more chars than 0 and 1.

3 might be mud which you can walk through but would slow you down.

K9, might be a door which you can only walkthrough if you have a certain key in your inventory.

Just some ideas...

emergency_pants
09-06-2005, 09:39 AM
There are a few good resources for tile-based games in Flash. A web search will probably kick up some good tutorials but here are a couple for starters:

http://www.gotoandplay.it/_articles/

http://oos.moxiecode.com/

Collisions in Tile-based games consists of calculating which tile you are moving into and testing BEFORE moving the character whether the tile is one which will block movement. If the return is true, don't move the player sprite.

In a nutshell, you run a virtual test for your movement BEFORE actually moving anything, so that you know whether to run your sprite movement script or not.

anthonyds
09-06-2005, 10:15 AM
I'll have to think it through a bit more, but I will definetly use the grid method.

Thanks a lot !

anthonyds
09-06-2005, 11:52 AM
Hi again. I've succesfully implemented the grid system into my game, however, one additional problem has occurred. I've put my player on the location (0,0), and started drawing the walls, but the wall does not overlap my player fully, even though the location of the wall on screen is also (0,0). My guess is that, instead of taking the upper left corner of the wall as the reference point for positioning, it uses the center of the wall. How can I change this ?

Here's the code :

//0 = clear, 1 = wall
map1 =[
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
]

function assumeGrid()
{
currentmap = _root["map"+mc_Player._currentframe];
wallCounter=0;
for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{
if(currentmap[i][j])
{
trace("creating wall number :" + wallCounter);
_root.attachMovie("Wall", "mc_Wall"+i+"_"+j,wallCounter );
_root["mc_Wall"+i+"_"+j]._x=50*j;
_root["mc_Wall"+i+"_"+j]._y=50*i;
wallCounter++;
}
}
}
}