Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-06-2002, 02:36 AM   #1
psychommunity0
Registered User
 
Join Date: Jun 2001
Posts: 31
Default RPG game navigation help

Hello, I'm making a rpg game in flash. THe code below is for the navigation. I'm trying to create the game so that it uses the grid-like motion in the classical rpg games. The grid-like motion prevents the characters from walking diagonally. So the character must walk forward 2 blocks, left 3 blocks, forward 1 block, etc. The code below compares the coordinate where the character is currently standing, to the coordinate that your mouse clicks (i'm not using the keyboard for navigation).

MY QUESTION: How would I change the code so that the character will first move on the x axis, THEN, the y-axis? For example, If I were to click a location diagonal to the character, I want to see him move to left/right first, THEN, up/down.

The code below is put on the character m/c that i'm moving.
Code:
onClipEvent(load){
nPosOldX = this._x
nPosOldY = this._y
}
onClipEvent(mouseDown){
nPosOldX = nPosNewX;
nPosOldY = nPosNewY;
nPosNewX = _root._xmouse;
nPosNewY = _root._ymouse;
if (nPosOldX != null && nPosOldY != null){
if (nPosOldX != nPosNewX || nPosOldY != nPosNewY){
this._x = nPosNewX
this._y = nPosNewY
}
}
}
psychommunity0 is offline   Reply With Quote
Old 05-06-2002, 11:35 AM   #2
Ricod
(@_@) -("pretty lights")
 
Ricod's Avatar
 
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
Default

Arghhh ! My reply didn't come through !

ehmr ... the basic thing was :
U'll need to use the current x and y, and compare them to the destination x and y. Now, using a little trigonometry u can find out wether or not the direction is diagonal (or you could just check if there's only movement in either the x or y, but when there's movement in both, its diagonal.)

If its indeed diagonal, you can start a loop which will move your character horizontal by the difference between the destination x and the current x, and when its finished (if currentX == destinationX) it starts the vertical loop. If u don't know how to make loops, take a look at the tutorial.

Cuz of my huge interest in gaming I'm kinda curious what yer making here, can I have a look ?
__________________
RicoD
Link ?
Ricod is offline   Reply With Quote
Old 05-06-2002, 04:14 PM   #3
psychommunity0
Registered User
 
Join Date: Jun 2001
Posts: 31
Default hi

Yes. What I've been doing is getting both the current and new X distance AND the current and new Y distance. This way I won't have to use any trig stuff. The code below does compare the old and the new coordinates. However, I can't seem to get the character to move on the x-axis first, THEN move on the y-axis. Also, i've tried:
if(this._x = nPosNewX){
this._y = nPosNewY
}
I'm sure this means the character's horizontal position MUST equal that of the new horizontal coordinate in order for the vertical movement to engage. However, it doesn't work. So maybe I didn't explain correctly. How would I change the code below so that it gets the character to move horizontally first, THEN vertically?

Hey Ricod, i'll be happy to show you the end product(if i can finish it ). I'm trying to create a little rpg(final fantasy) game and implement it into a site.

thanks!!!!
psychommunity0 is offline   Reply With Quote
Old 05-06-2002, 04:21 PM   #4
Ricod
(@_@) -("pretty lights")
 
Ricod's Avatar
 
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
Default

I usually use a three frame mc that loops until the destined position is reached , with a piece that tells it, when the maximum value is crossed to set the position to the max value, in this case the destination _x. (for a smooth transition, but your moving it instantly ?)

anyway, to compare data, use :
Code:
if(this._x == nPosNewX){ 
   this._y = nPosNewY 
}
== compares a value, while = sets a value.

How do you think to make it small, if its final fantasy like !
__________________
RicoD
Link ?
Ricod is offline   Reply With Quote
Old 05-07-2002, 12:13 AM   #5
psychommunity0
Registered User
 
Join Date: Jun 2001
Posts: 31
Default

woops~
i mean the put == instead of a single =
Even with ==, the code still doesn't work. Any ideas? One more thing. I didn't quite get the part about having 3 frames. Can you explain it again? hehe
thanks!!!!
P.S. I'm starting off small with the game. Maybe just one town that allows the character to walk around and talk to people.
psychommunity0 is offline   Reply With Quote
Old 05-07-2002, 12:27 PM   #6
Ricod
(@_@) -("pretty lights")
 
Ricod's Avatar
 
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
Default

The 3 frames mc is what I use for loops ... but your doing instant move or sumthing ? Anyway, I use them to let something increment (like with movement). Basically, the 1st frame has a stop(). The 2nd has actions that check the current position, opposed to the destination position, and then moves according to the speed that's appropriate. The 3rd also has this, but also a gotoAndPlay(2);

let's see what we can do with the current setup ...
Code:
onClipEvent(mouseDown){
    nPosOldX = nPosNewX;
    nPosOldY = nPosNewY;
    nPosNewX = _root._xmouse;
    nPosNewY = _root._ymouse;
    if (nPosOldX != null && nPosOldY != null){
        if (nPosOldX != nPosNewX || nPosOldY != nPosNewY){
             _root.movementControl.gotoAndPlay(2);
        }
    }
}
Now we let movementControl ... well, control the movement .

Code:
characterSpeed = 10;
var currentX = _root.myCharacter._x;
var destinationX = _root.myCharacter.nPosNewX;
if (currentX != destinationX){
    XDiff = destinationX - currentX;
    if (XDiff >= characterSpeed) {
        _root.myCharacter._x += XDiff;
    }else{
        _root.myCharacter._x = destinationX;
    }
}else{
    if (currentY != destinationY) {
etc ... repeat everything for X with Y ... now, with this construction, if everything is set appr. it should always check wether or not there's a difference in _X ,and if not, then check wether or not there's a difference in _y.
__________________
RicoD
Link ?
Ricod is offline   Reply With Quote
Old 05-08-2002, 06:01 AM   #7
psychommunity0
Registered User
 
Join Date: Jun 2001
Posts: 31
Red face hello

hey ricod
I really appreciated helping me with this. I'm not totally sure where to put the code you just wrote down there . What I did was:
A) in an empty mc called movementControl:
frame 1:
Code:
stop()
frame 2:
Code:
characterSpeed = 10;
var currentX = _root.myCharacter._x;
var currentY = _root.myCharacter._y;
var destinationX = _root.myCharacter.nPosNewX;
var destinationY = _root.myCharacter.nPosNewY;
if (currentX != destinationX){
    XDiff = destinationX - currentX;
    if (XDiff >= characterSpeed) {
        _root.myCharacter._x += XDiff;
    }else{
        _root.myCharacter._x = destinationX;
    }
        }
if (currentY != destinationY){
    YDiff = destinationY - currentY;
    if (YDiff >= characterSpeed) {
        _root.myCharacter._y += YDiff;
    }else{
        _root.myCharacter._y = destinationY;
    }
        }
frame 3:
Code:
characterSpeed = 10;
var currentX = _root.myCharacter._x;
var currentY = _root.myCharacter._y;
var destinationX = _root.myCharacter.nPosNewX;
var destinationY = _root.myCharacter.nPosNewY;
if (currentX != destinationX){
    XDiff = destinationX - currentX;
    if (XDiff >= characterSpeed) {
        _root.myCharacter._x += XDiff;
    }else{
        _root.myCharacter._x = destinationX;
    }
        }
if (currentY != destinationY){
    YDiff = destinationY - currentY;
    if (YDiff >= characterSpeed) {
        _root.myCharacter._y += YDiff;
    }else{
        _root.myCharacter._y = destinationY;
    }
        }
gotoAndPlay(2)
I'm not exactly sure where to put the other code. Sorry to bother you with this simple question~
thank you soooo much
psychommunity0 is offline   Reply With Quote
Old 05-11-2002, 02:12 AM   #8
psychommunity0
Registered User
 
Join Date: Jun 2001
Posts: 31
Default

ricod?
psychommunity0 is offline   Reply With Quote
Old 05-12-2002, 03:37 PM   #9
Ricod
(@_@) -("pretty lights")
 
Ricod's Avatar
 
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
Default

Sorry, I'm not around as often as I used to be ... (u can all thank my 2 bossess)

The other code would be where u put it right ? I believe u put it on your character.

But, eh , do u understand what the code is saying ? (it's more important ...)
__________________
RicoD
Link ?
Ricod is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS2] help on a rpg game mordocai Gaming and Game Development 3 09-11-2004 04:54 PM
FLASH RPG game (2) mko ActionScript 1.0 (and below) 2 07-06-2004 02:31 PM
About RPG Game windson2002 Gaming and Game Development 1 09-06-2003 01:11 AM
Which one to use for online RPG game xxlm General Chat 15 06-10-2003 01:02 AM


All times are GMT. The time now is 12:20 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.