[SOLVED] Moving a character a set amount of pixels with a push of a button

Started by nads, Thu 21/06/2012 08:58:32

Previous topic - Next topic

nads

Heya guys,

I've been fooling around with Brisby's KeyboardMovement Module and having some fun with it. Being able to have the character moving into a crouching position and moving in that position. But I'm wanting to do a roll function in this game I'm working on. I have the space button set up and read to go, but I was just wondering if there is a form of code I can use where every time I hit this button the character will roll lets say 40 pixels right (for now)
this is the code I've gotten so far

      else if (newdirection == eKeyboardMovement_Action1) {
        cCharacter.ChangeView (3);
        cCharacter.StopMoving ();
        cCharacter.SetWalkSpeed(8, 8);
        cCharacter.Move(+40, 0);
        cCharacter.StopMoving();
        cCharacter.SetWalkSpeed(4, 4);

The main issue I already know is the cCharacter.Move and alot of the codes you have to have a set x,y. Surely there is a way to do and is most likely reeeeeally simple. Just wondering if anyone could point me in the right correction. Hopefully this makes sense

Cheers.


Khris

Code: ags
  cCharacter.Move(cCharacter.x+40, cCharacter.y);


If you use wide sprites for the animation that already cover the movement, run the animation, then call cCharacter.x += 40; and reset the character's view.

nads

Thanks Khris, I'll give it a shot now.

So I guess I could use a similar principle with jumping. Thou there will be a little bit more to it, say if a character misses his jump..

EDIT: Ok I've tried it and it seems to work fine, only a small issue with the animation itself. He will be standing there, and instead of rolling forwards, the animation will cause him to jump back abit then roll forwards. If that makes sense

Khris

What I would do is change the character's frame depending on their current state and number of frames that have passed.
After the player hits space, you start counting frames and do the animation yourself, moving the character and changing the frame yourself. If they hit a wall during that process, switch to the "hit wall during rolling" animation, while moving the character back slightly.

nads

Haha I like your thinking Khris, any idea how I can smooth up the animation to stop it from dropping back before going forward. It seems like the sprites or focused on a centerpoint rather than using the bottom right corner. Is it something I'm just going to have to chance in my sprites, or is this something I can change.. Again, I hope I make sense

Khris

Objects use the bottom left corner, but character sprites are positioned using their bottom center, yes.
That's because usually they are restricted to a drawn walkable area.

nads

Cheers, I'll have to fool around with the sprites and to coding to get it running smooth. Thanks for the help. I just added a "Sprint" function to the game! Now I'm going to fool around with it a bit more and hope to get some more done. I'm not really working with over the top sprites, just basic stick figures just to get the all the code side done right before I get deep into the whole character sprites and detailed animation sprite part. Hopefully I'll get all this prototype stuff done soon so I can create some sort of tech demo to show you guys to hear your thoughts. Looks like it could be a sleepless night for me, oh well.

Thanks again..

SMF spam blocked by CleanTalk