[SOLVED]Is there a sort of work-around to avoid using StopMoving();?

Started by Snake, Mon 31/03/2008 15:15:14

Previous topic - Next topic

Snake

Is there any way, some sort of walk-around, that I can set the character's walk speed and/or view without having to use StopMoving();?

Since I'm using the arrow keys for movement, it's not fluid having to stop him before going again, I'd like the player to be able to keep running.

Thanks for any help and patience in advance,


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

.M.M.

I think it is only way to use
Code: ags
 player.StopMoving();
player.WalkSpeed = 10; 

It isn't so bad and many commercial games are using this.

Snake

That's what I have and am trying to avoid. I really don't want to force the player to have to push the arrow key again after gaining speed.
I suppose I could just have something display that your speed has increased to sort of camouflage, but I'd like not to annoy the player. I guess either way is annoying, so maybe it doesn't matter?

I doubt there's any way to do this, but yet, one shouldn't doubt the power of AGS ;)


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

TwinMoon

I haven't checked this, but maybe if you set the player.Frame  to 1 before making him walk?

Or you could make another view where the first frame is the same as the last frame, that way it would look as if he's walking.

.M.M.


Snake

No no no, maybe I didn't explain right (I'm already using that module to move the character with the arrows):

There is a power up that you can get that makes you run faster.

After grabbing this power up I have to stop the player from moving before I can change his walking speed, thus, resulting in having to press and hold the direction arrow again to start moving (because he was stopped in the code).

I want it so you can just run by and grab the power up and keep running.

Thanks again,


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

.M.M.

#6
Corect me if I´m wrong ( again  ::) ) but you must stop the character to change his walking speed. But maybe this can work. I think in there are variables dx and dy in this module.Try to store to where was player moving before he took speed power-up.
Code: ags

if (dx = 0) {
  if (dy = -DISTANCE) {
  player.StopMoving();
  player.WalkSpeed = 10;
  dx= 0;
  dy= -DISTANCE;
}
}

So, if player clicked on keybord on "up", he sholud be moving up faster now. Sorry if it isn´t working, i did not try it in game. :P
[EDIT] Sorry- I tried it in game, but it don´t want to work... But I let it be here, because I hope it will be still little useful for you.

Snake

Yes, you are right. Before changing the character speed or view (if the character is moving) you must stop the character. If you don't you get an error telling you to do so. This is what my whole question is about - if there's a work-around so that I don't have to stop the player from running. If the player is on the run and about to get hit, he can't be pausing because of the code - highly unfair to the player.
I'm going to maybe think about doing some sort of animation and explaination to kind of hide these pauses.

Thank you for the code, though. I tried it out two different ways without any result. I even fiddled with other parts of the code and still got nothing - and it doesn't help to not understand the whole thing ;)

I'm going to PM the creator of the module and see if they have any ideas.


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

RickJ

Hey Snake, I don't think there needs to be a pause noticeable to the player.  You should be able to do something like the following to get the results you desire. 
Code: ags

function ChangeSpeed(int spd, int x, int y) {
  player.StopMoving();
  player.WalkSpeed = spd;
  player.Move(x,y);
}


You will need to know the players current x,y destination so you can pass them into the function.  Probably the module needs to be modified so that the destination points are remembered and so that it includes a change speed function.

Shane 'ProgZmax' Stevens

The best way to handle this when using keyboard control, Snake, is to do away with the built-in Walk function completely and handle the animation and movement speed yourself.  Basically, you'll keep track of the player's current frame, you'll store their movement speed, and you'll also store an animation delay to prevent the frames from all running at once.  Then you can go about it in one of two ways:

1.  Use a character, adjusting their x/y values based on your movement speed and their current frame based on the animation delay and maximum frames.  This is rather trivial to implement.

2.  Use the Rawdraw functions to render the player to the screen dynamically and then control his frames based on sprite indexes stored in arrays.


Option 1 just involves you having an IsKeyPressed(LEFT_ARROW) and then something like:
Code: ags
 cHero.x-=hero_x_speed;
if(hero_anim_delay<=0)
{ 
if(cHero.Frame<hero_walk_max_frames)
{
cHero.Frame+=1;
hero_anim_delay=hero_max_anim_delay;
}
else
{
cHero.Frame=0;
}
}
else
{
hero_anim_delay -=1;
}


I'm using really large, descriptive names to get the idea across, but you'll probably want to use a struct instead with these variables in it.  Also, If the character is going to be limited to the walkable areas like other characters you'll need to do a check prior to having them move with GetWalkableAreaAt, factoring in the viewport if it is a scrolling room.

Snake

Rick:
I PM'd Strazer and he's too busy right now to update the module. He suggested either posting about this in the module's thread to get further help or PM Rui first - which I think is what I'll do.

ProgZ:
Heh, thanks for responding so thoroughly, but unfortunately for me, either way is way beyond my scripting ability and know-how. I would absolutely try to understand and implement doing everything you suggested, but I'd end up getting so overwhelmed without someone actually being here to help.
And I don't think Chris has hired you guys for home visits yet ;)

Heh, it would be nice if AGS didn't have to stop the character to do those things...

I'm going to go PM Rui now.

Thanks again, guys!


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Snake

Hey, guys,

Rui got back to me and solved my problem.

All it came down to was copying and pasting some code from the module into the script after stopping the character.

Works awesome now!

Thanks everyone else for your help,


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

SMF spam blocked by CleanTalk