Get a sprite to skip in the game (as a minigame)

Started by ToeKnee, Sat 12/09/2020 10:29:58

Previous topic - Next topic

ToeKnee

Hi all,
I have only one tiny thing left in my full AGS Game which is to deliver on a promise I have made to my daughter > to get her playable drawing/character to SKIP in the game, with a skipping rope Inventory item.... unfortunately for me - I then went further and said I can probably make it into a '(mini)game' where you press a key and it 'jumps the rope' like in some Video Arcades at the moment.... i.e: When the 'rope' gets toward the bottom you hit a key to make the character 'jump' the rope.... You could of course get a point for each jump and after say 5 jumps it should start to get faster and faster! - until you 'miss' the jump.

I assume I will have to separate the girl jumping and the rope so they can operate 'independently' however her 'hand' will technically be touching the 'rope' so the sprite collision code done way back in 2006 by SSH probably won't work for this...

I created all the images and have started to animate this but not sure of the best way to achieve the 'miss' of hitting a button (Eg an Object button on the screen) at the right 2 x FRAMES (it has 22 frames total for the Animation to make it smooth when slow). It also has arrows showing the current 'height' of the rope and this turns RED when in two positions I am thinking they would need to hit the button within... is there an easy way to 'sequence' frames and jump a character (like skipping) or error and stop?

See Sample Video of what I have done so far, loaded here: http://www.p360.com.au/game360/AbbeySkipping.mp4

Any advice would be great. Inefficient code will likely slow the whole thing down and make a game very 'easy' and, unfortunately, therefore make this feature not very interesting for young kids to play (and try and beat a previous score etc).... if they can't get out becuase it won't go fast enough (I can use a view that has every second frame of course as things get faster to double the speed and only have one 'red' spot where you can get the jump timing right....

Thanks,
Tony
If it’s not broken, let’s fix it till it is...!

Slasher

#1
As a basic suggestion..

Why not have the rope animate from back to front and then stop animation with a message and then start at back again and repeat if jump key not pressed. Else if jump key pressed before rope at front the girl jumps and the rope starts back at the back and a point added and repeats etc...

Food for thought..

Crimson Wizard

#2
In my opinion, this could be easily achieved by having character and rope as separate objects/characters in the room, and animated separately. If the rope is animated using standard views, then hitting the character may be deduced from the rope's animation frame number. If it's procedurically drawn, then there will be a way to tell its position from some variable too.
In any case you don't have to literally test for pixels colliding (if that's what you meant by using sprite collision module?), it may be enough to simply test for a frame number / other animation variable.

When player presses a button - character jump animation runs, and then you may compare rope and character animation frame numbers to see if character reached needed "jump height" (key frames) at the same time as rope reached lowest position (key frames). If this matches condition - then let it continue, if it does not - then make animations stop and signal a mistake.

For above you'd need a continious test in repeatedly-execute function (whether global or room one's - if this may only occur in particular room). This test may for example look like:
* if character is in "rope skipping" minigame,
* if rope is animating,
* if rope is at certain key frame(s),
* if character is NOT animating a jump, or IS animating a jump BUT NOT at certain key frame(s),
- then fail.


PS I certainly would recommend using GUI for jump button and meter, thus avoiding unnecessary complications room objects may create; and if the rope is made as a character then you may have this minigame in any room in game :).

ToeKnee

QuoteWhy not have the rope animate from back to front and then stop animation with a message and then start at back again and repeat if jump key not pressed. Else if jump key pressed before rope at front the girl jumps and the rope starts back at the back and a point added and repeats etc...
Thanks for your thoughts and reply Slasher... I think Message would 'block' the animation though but yes I will strip the Rope and the Character apart... Then just set the Z Order for when it's at the back so it looks right...
If it’s not broken, let’s fix it till it is...!

ToeKnee

QuoteIn my opinion, this could be easily achieved by having character and rope as separate objects/characters in the room, and animated separately. If the rope is animated using standard views, then hitting the character may be deduced from the rope's animation frame number. If it's procedurically drawn, then there will be a way to tell its position from some variable too.
Yes I get both of those options 100%.... I think i'll try both and see which makes it the fastest (sicne at '0' delay it's barely quick enough to 'test' those that are skilled in reaction!!!

QuoteIn any case you don't have to literally test for pixels colliding (if that's what you meant by using sprite collision module?), it may be enough to simply test for a frame number / other animation variable.
Yes it is what I meant..!! :-(, but separating out both graphic elements and testing for FRAME position of each (then triggering when they are not where they are meant to be) will make this work without anything fancy and processor consuming!.

QuoteWhen player presses a button - character jump animation runs, and then you may compare rope and character animation frame numbers to see if character reached needed "jump height" (key frames) at the same time as rope reached lowest position (key frames). If this matches condition - then let it continue, if it does not - then make animations stop and signal a mistake.
This is what I will do, thank you > it's what I was after is pointing in the right direction for this thanks Crimson.

QuoteFor above you'd need a continious test in repeatedly-execute function (whether global or room one's - if this may only occur in particular room). This test may for example look like:
* if character is in "rope skipping" minigame,
* if rope is animating,
* if rope is at certain key frame(s),
* if character is NOT animating a jump, or IS animating a jump BUT NOT at certain key frame(s),
- then fail.

QuotePS I certainly would recommend using GUI for jump button and meter, thus avoiding unnecessary complications room objects may create; and if the rope is made as a character then you may have this minigame in any room in game :).
Yes - I think I will make it a character > since this has the best way to allocate a VIEW and then frame-set that as needed.

Thanks again Crimson....
I'll see how I go getting this running this week.... very keen to release the game here!
If it’s not broken, let’s fix it till it is...!

Crimson Wizard

#5
Quote from: ToeKnee on Sun 13/09/2020 09:52:11
Yes I get both of those options 100%.... I think i'll try both and see which makes it the fastest (sicne at '0' delay it's barely quick enough to 'test' those that are skilled in reaction!!!

I don't think this will be much affected by drawing, not on modern PC at least. But the frame speed is fixed and may be changed using SetGameSpeed. Perhaps try setting it to 60 for a test, unless you did that already. Or make less middle frames in rope animation when it goes faster.

ToeKnee

Quote from: Crimson Wizard on Sun 13/09/2020 17:42:26
Quote from: ToeKnee on Sun 13/09/2020 09:52:11
Yes I get both of those options 100%.... I think i'll try both and see which makes it the fastest (sicne at '0' delay it's barely quick enough to 'test' those that are skilled in reaction!!!

I don't think this will be much affected by drawing, not on modern PC at least. But the frame speed is fixed and may be changed using SetGameSpeed. Perhaps try setting it to 60 for a test, unless you did that already. Or make less middle frames in rope animation when it goes faster.

Yes, I think I am best to SAVE Game speed (user has currently set this to on the GPanel) then set it to what I want them to play at that works best (I will use SetGameSpeed in tests when nearly done so I can see what works), then set it BACK once the Minigame has finished...
Then they can't 'cheat' and run Game speed really slow and get a crazy score to torment their family etc!  :cheesy: :cheesy: :cheesy:
If it’s not broken, let’s fix it till it is...!

ToeKnee

Ok I am getting 'close'!! - excepting for a couple of weird things I can't quite nail yet... any help would be great Crimson?!?!

QuotePS I certainly would recommend using GUI for jump button and meter, thus avoiding unnecessary complications room objects may create
I used this GUI recommendation thanks Crimson, as you can see on the video! - and I am sure it would have saved me from a lot of messy code!!

Quoteand if the rope is made as a character then you may have this minigame in any room in game
I went off this idea since there are far too many rooms with rivers and caves and cliffs and quicksand (and some with no character showing at all!)!! etc that the character appearing to start skipping would look silly. Plus, I would have needed to work out the best walk-able areas and then screen-percentage that away from the sides of the screen etc, plus with some screens being dark and gloomy it would be hard to see... Plus who wants to have fun 'SKIPPING' at a cemetery?!?! or when about to get burnt by a Dragon in a dungeon!

The main problem at the moment is that if I COUNT when a frame is hit in repeatedly execute, and add 1 to a running total (SkipCount), then display that on the GUI in a Text Box, I always get a count of 5 being added!... Mind you, I can probably leave it at 5, since it is a SCORE - and you can get rewarded whatever works, however I would be happier if I knew what might be going on here... I assume it's the repeatedly execute timing with the cpu cycles per second...
- You can see the VIDEO recording I did of it so far here: http://www.p360.com.au/game360/SkippingCoding.mp4

It is triggered from a Dialog and it shows the count going up in 5's!!

I also have a second issue in that I am currently checking if the character is NOT animating unless JUMP is clicked and this has been the only real way to trigger it to get it functioning as it is.... however this means the character's ARMS are not animating either when the rope goes around.... until they jump since that uses the frames from the overall view of frames which have the character's arms moving... so again, any ideas or advice about a better way to do this would be great.

The code is here FYI
(however please note that the code is currently UN-compressed and IN-efficient, for example layering if<>else statements in the repeatedly execute - so please ignore the inefficient coding atm) and I have added the Dialog Trigger part;
Code: ags

//----------------------------------------------------------------------------------------------------
dDialog1
	Hero: "Can you show me how good you can SKIP?"
	Abbey: "Sure let me show you!"
       		StartSkipping = 0;
//----------------------------------------------------------------------------------------------------

function repeatedly_execute() 
{
  if (StartSkipping == 0) { //Moved from -1 to 0 in Abbey Dialog, to try skipping MINIGAME
    StartSkipping = 1;
    cAbbey.Say("&70 I really LOVE practising my Skipping!");
    cHero.Transparency = 100;
    cAbbey.x = 265;
    cAbbey.y = 427;
    cAbbey.LockView(30);
    cAbbey.Animate(1, 0, eOnce, eNoBlock, eForwards, 1);
    open_gui(gSkipping);
    TxtJumpScore.Text = String.Format("Record: %d", JumpScore);
    }

  if (StartSkipping == 2) { // If rope moving
    if (object[5].Frame == 12) //If Rope going to the Back
      object[5].Baseline = 420; //Put Rope in BEHIND of Abbey
    else if (object[5].Frame == 1) //If Rope going to the Front
      object[5].Baseline = 430; //Put Rope in FRONT of Abbey
    }
    
  if (StartSkipping == 2) // If rope moving
    if ((object[5].Frame == 10) || (object[5].Frame == 11)) //if Rope on RED bottom spots (Frames 10 and 11)
      if (cAbbey.Frame == 21) { // if Abbey not moving
        Display("WHOOPS! you missed the jump![- Click JUMP to try again...");
        StartSkipping = 1;
        object[5].SetView(30, 0, 9);
        }

  if (StartSkipping == 2) // If rope moving
    if (object[5].Frame == 12) { //if Rope PAST RED spots then Abbey Jumped it
      SkipCount++;
      TxtJumpScore.Text = String.Format("Score: %d", SkipCount);
      }
}
//----------------------------------------------------------------------------------------------------

function BtnJump_OnClick(GUIControl *control, MouseButton button)
{

  if (StartSkipping == 2) { //Already started so JUMP
    cAbbey.Animate(1, 0, eOnce, eNoBlock);
    TxtJumpScore.Text = String.Format("Score: %d", SkipCount);
    }
    
  else if (StartSkipping == 1) { //First time so setup for MINIGAME
    StartSkipping = 2;
    SkipCount = 0; // Rest Counter
    Display("The Rope is about to start so click the JUMP button to skip it!");
    Display("You have to jump every time the rope is right at the BOTTOM (the rope goes RED to guide you");
    TxtJumpScore.Text = String.Format("Record: %d", JumpScore);
    object[5].SetView(30); //Skipping ROPE to Skip Views
    object[5].Visible = true; //Skipping ROPE to visible
    object[5].Animate(0, 4, eRepeat, eNoBlock);
    cAbbey.Animate(1, 4, eRepeat, eNoBlock);
    }
}
//----------------------------------------------------------------------------------------------------

// hide SKIPPING GUI directly from an OnClick event
function close_skipping_gui_onclick(GUIControl *control, MouseButton button)
{
  StartSkipping = -1;
  object[5].Visible = false; //Skipping ROPE to hidden
  close_owning_gui(control);
  cAbbey.x = 170;
  cAbbey.y = 341;
  cHero.Transparency = 0;
  cHero.UnlockView(); 
  cAbbey.LockView(2); // Return to default view
  cAbbey.Animate(0, 0, eOnce, eNoBlock, eForwards, 1);
}
//----------------------------------------------------------------------------------------------------
If it’s not broken, let’s fix it till it is...!

SMF spam blocked by CleanTalk