Four-directional movement
Displaying 1-16 of 16 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
rpgking

Anyone know a good way to force movement in only four directions, so that the player can't move diagonally? Movement will still be pixel-based, as it is now. I'm just trying to figure out a way to stop diagonal movement.

Posted on 2004-11-04 00:05:16

zonker6666

Sure, what u do is simply not set any entity as the player. Then write a hooked function for the entities in which u poll the keyboard and do the movement yourself.

in your keyboard check you should use the following form

if(key[scan_down])
entity.y[event.entity]+=16;
else if(key[scan_up])
entity.y[event.entity]-=16;
else if(key[scan_left])
entity.x[event.entity]-=16;
else if(key[scan_right])
entity.x[event.entity]+=16;

Posted on 2004-11-04 01:05:10

rpgking

Yes, that seems simple enough, though I'd have to end up checking for obstructions, zones, and other entities within that code if I set no one as the player :P

Posted on 2004-11-04 01:11:13

RageCage

zones is the difficult part of that...

just brainstorming... if you kept the setPlayer and you corrected the entity's placement every cycle BEFORE the entities are blitted, you might be able to get away with it.

I can help you with the correction coding if you cant figure it out your self. The more I think about it, the more I think this would work.

Posted on 2004-11-04 02:53:25 (last edited on 2004-11-04 02:54:22)

rpgking

Eh...it's fine. I decided to just stick with 8 directional movement.

Posted on 2004-11-04 21:49:21

TomT64

There really should be some kind of function that forces the movement engine into a tile based state.

Posted on 2004-11-10 22:36:02

rpgking

That may be useful.

But just for the record, this topic was not referring to tile-based movement.

Posted on 2004-11-11 06:13:34

Omni

I had a whole other response and sample code, but it only achieved the creation of ...something stupid.

How about, if two directions are ever pressed at the same time, unpress one of them.

EDIT: Altered the function to correct occasion presses of Left and Right while moving down, that would shift the character's x value.

It checks to see if the player if moving up or down. Then, if the player is moving left or right, it unpresses left or right, and restores the original X position the player had before he pressed left or right. The 'cd_player' variable needs to be set manually, though.

HookRetrace or HookTimer this function. Unfortunately, spazzing on left or right while moving up and down will cause the character's animation to flicker, but I don't know how to I can stop that.


int cd_player;
int cd_last_x;

void CorrectDiagonal() {
if (up || down) {
//Unpress left and right.
if (left || right) {
Unpress(7);
Unpress(8);
entity.x[cd_player] = cd_last_x;
}
}
else
{
cd_last_x = entity.x[cd_player];
}
}
}


HookRetrace or HookTimer that. In fact, maybe that should do it.

Posted on 2004-11-11 22:22:01 (last edited on 2004-11-11 22:44:24)

rpgking

I just tried that code, and movement looks really awkward, especially when walking in a circle. Sometimes, it seems like I keep on getting pulled back while walking. Thanks for making an effort to help though, Omni.

I think I'll just stick with 8-directional movement now. I was planning on 4-directional movement just for the overworld in my game, but 8-directional won't be too bad.

Posted on 2004-11-12 05:58:22

Omni

It looked...awkward? There's only brief flicker on my machine, and that's only if I spazz on all the buttons at once. If I just press the directional keys it looks fine.

Posted on 2004-11-12 15:07:58

Eldritch05

It also seems to have the interesting side effect of warping any entities set to stalk the cd_player to the same position whenever it corrects the x-location. I didn't know that EntityStalk() warped stalking entities along with the main one, but this prompted me to check, and:

entity.x[partychr[0]]=x*16;
entity.y[partychr[0]]=y*16;

does indeed warp an entire party of 5 to the new location. Very interesting.

Posted on 2004-11-12 16:29:52

rpgking

Quote:Originally posted by Omni

It looked...awkward? There's only brief flicker on my machine, and that's only if I spazz on all the buttons at once. If I just press the directional keys it looks fine.


For me as I'm moving I'd be warped back a few pixels from time to time, usually when turning in a direction perpendicular to where I am... The fact that I have 3 party members + a horse and wagon following just adds to the weirdness of this warping effect :P

Posted on 2004-11-12 18:06:27 (last edited on 2004-11-12 18:07:14)

Omni

I still don't think I understand why. You shouldn't be getting warped back a few pixels--as long as you're moving up or down, no matter how much the animation glitches, any movement on the X-axis should be negated.

Are you saying the following happens?

1. You hold up or down.
2. You press or tap left/right rapidly.
3. The player shifts left or right by significant amounts.

#3 should not occur if the X value of the player is being corrected. But I haven't actually tried it with entity stalking yet, so I will check it. Perhaps stalking will always glitch up with arbitrary altering of entity X and Y.

Do you have any other reason why it might be doing this? I thought this solution would be too simple to be horribly flawed as it is.

EDIT: It would appear that whenever a stalked entity has X and Y values changed, the stalking entity is immediately given those same X and Y values, which creates the warping effect. Unfortunately I have no clue how to fix this.

EDIT2: When a stalked entity changes X or Y values, perhaps the stalking entity should only correct the value that has changed. For example, if X changes, only reset the X value. Vecna, if this was implemented, it would fix the glitching in this correction. ...Then again, there's not really a point in altering the stalking method just for my silly fix, when in fact that is the only thing the alteration would be good for, and you guys could probably end up implementing your own native four-direction or tile-based movements later anyway.

Posted on 2004-11-12 18:47:27 (last edited on 2004-11-12 18:53:24)

Omni

I made some new code. It doesn't use X correction -- it allows one direction to be canceled into another, and it doesn't glitch up the entity following.


int cd_pressed;
int cd_pressed_lr;
int cd_pressed_ud;

void CorrectDiagonal() {
//If left and right are pressed after up and down, unpress them.
//If up and down are pressed after left and right, unpress them.
if (cd_pressed == 0) //Press a button.
{
if (left || right) //Check if left and right.
{
cd_pressed_lr = 1;
cd_pressed = 1;
}
else if (up || down) //Check if up and down.
{
cd_pressed_ud = 1;
cd_pressed = 1;
}
}
if (cd_pressed == 1) //If anything is pressed...
{
if (cd_pressed_lr) //If left or right _was_ pressed...
{
if (left || right) //Still is pressed...
{
if (up || down) //And now up or down has been pressed...
{
//Then change direction.
cd_pressed_lr = 0;
cd_pressed_ud = 1;
Unpress(7);
Unpress(8);
}
}
else //If left and right are no longer pressed, change the flags.
{
cd_pressed_lr = 0;
cd_pressed = 0;
}
}
if (cd_pressed_ud) //If up or down _was_ pressed...
{
if (up || down) //Still is pressed...
{
if (left || right) //And now left or right has been pressed...
{
//Then change direction.
cd_pressed_ud = 0;
cd_pressed_lr = 1;
Unpress(5);
Unpress(6);
}
}
else //If up and down are no longer pressed, change the flags.
{
cd_pressed_ud = 0;
cd_pressed = 0;
}
}
}
}

Posted on 2004-11-12 21:48:57

rpgking

Thanks a lot Omni. That is perfect!

I tried doing something like this myself(cancelling directions), but failed. Thanks again. :)

Posted on 2004-11-13 02:17:42 (last edited on 2004-11-13 02:18:02)

Omni

No problem at all. I'm glad to help.

Posted on 2004-11-13 04:17:29


Displaying 1-16 of 16 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.