| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Jun 2001
Posts: 31
|
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
}
}
}
|
|
|
|
|
|
#2 |
|
(@_@) -("pretty lights")
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
|
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 ? |
|
|
|
|
|
|
|
|
#3 |
|
Registered User
Join Date: Jun 2001
Posts: 31
|
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!!!! |
|
|
|
|
|
#4 |
|
(@_@) -("pretty lights")
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
|
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
}
How do you think to make it small, if its final fantasy like !
__________________
RicoD Link ? |
|
|
|
|
|
#5 |
|
Registered User
Join Date: Jun 2001
Posts: 31
|
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. ![]() |
|
|
|
|
|
#6 |
|
(@_@) -("pretty lights")
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
|
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);
}
}
}
.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) {
__________________
RicoD Link ? |
|
|
|
|
|
#7 |
|
Registered User
Join Date: Jun 2001
Posts: 31
|
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() 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;
}
}
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)
thank you soooo much |
|
|
|
|
|
#8 |
|
Registered User
Join Date: Jun 2001
Posts: 31
|
ricod?
|
|
|
|
|
|
#9 |
|
(@_@) -("pretty lights")
Join Date: Sep 2001
Location: the Netherlands
Posts: 3,988
|
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 ? |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |