Author Topic: Get a sprite to skip in the game (as a minigame)  (Read 261 times)

ToeKnee

  • If you are not flexible, you break!
    • I can help with AGS tutoring
    • I can help with backgrounds
    • I can help with play testing
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
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

  • slasher
    • I can help with AGS tutoring
    • Lifetime Achievement Award Winner
    • I can help with scripting
    • I can help with story design
    • Slasher worked on one or more games that won an AGS Award!
    •  
    • Slasher worked on one or more games that was nominated for an AGS Award!
Re: Get a sprite to skip in the game (as a minigame)
« Reply #1 on: 12 Sep 2020, 11:45 »
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..
« Last Edit: 12 Sep 2020, 11:48 by Slasher »

Re: Get a sprite to skip in the game (as a minigame)
« Reply #2 on: 12 Sep 2020, 12:14 »
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 :).
« Last Edit: 12 Sep 2020, 12:34 by Crimson Wizard »

ToeKnee

  • If you are not flexible, you break!
    • I can help with AGS tutoring
    • I can help with backgrounds
    • I can help with play testing
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
Re: Get a sprite to skip in the game (as a minigame)
« Reply #3 on: 13 Sep 2020, 09:43 »
Quote
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...
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

  • If you are not flexible, you break!
    • I can help with AGS tutoring
    • I can help with backgrounds
    • I can help with play testing
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
Re: Get a sprite to skip in the game (as a minigame)
« Reply #4 on: 13 Sep 2020, 09:52 »
Quote
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.
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!!!

Quote
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.
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!.

Quote
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.
This is what I will do, thank you > it's what I was after is pointing in the right direction for this thanks Crimson.

Quote
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.

Quote
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 :).
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...!

Re: Get a sprite to skip in the game (as a minigame)
« Reply #5 on: 13 Sep 2020, 17:42 »
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.
« Last Edit: 13 Sep 2020, 17:44 by Crimson Wizard »

ToeKnee

  • If you are not flexible, you break!
    • I can help with AGS tutoring
    • I can help with backgrounds
    • I can help with play testing
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
Re: Get a sprite to skip in the game (as a minigame)
« Reply #6 on: 14 Sep 2020, 15:03 »
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

  • If you are not flexible, you break!
    • I can help with AGS tutoring
    • I can help with backgrounds
    • I can help with play testing
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
Re: Get a sprite to skip in the game (as a minigame)
« Reply #7 on: 16 Sep 2020, 17:39 »
Ok I am getting 'close'!! - excepting for a couple of weird things I can't quite nail yet... any help would be great Crimson?!?!

Quote
PS 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!!

Quote
and 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: Adventure Game Studio
  1. //----------------------------------------------------------------------------------------------------
  2. dDialog1
  3.         Hero: "Can you show me how good you can SKIP?"
  4.         Abbey: "Sure let me show you!"
  5.                 StartSkipping = 0;
  6. //----------------------------------------------------------------------------------------------------
  7.  
  8. function repeatedly_execute()
  9. {
  10.   if (StartSkipping == 0) { //Moved from -1 to 0 in Abbey Dialog, to try skipping MINIGAME
  11.     StartSkipping = 1;
  12.     cAbbey.Say("&70 I really LOVE practising my Skipping!");
  13.     cHero.Transparency = 100;
  14.     cAbbey.x = 265;
  15.     cAbbey.y = 427;
  16.     cAbbey.LockView(30);
  17.     cAbbey.Animate(1, 0, eOnce, eNoBlock, eForwards, 1);
  18.     open_gui(gSkipping);
  19.     TxtJumpScore.Text = String.Format("Record: %d", JumpScore);
  20.     }
  21.  
  22.   if (StartSkipping == 2) { // If rope moving
  23.     if (object[5].Frame == 12) //If Rope going to the Back
  24.       object[5].Baseline = 420; //Put Rope in BEHIND of Abbey
  25.     else if (object[5].Frame == 1) //If Rope going to the Front
  26.       object[5].Baseline = 430; //Put Rope in FRONT of Abbey
  27.     }
  28.    
  29.   if (StartSkipping == 2) // If rope moving
  30.     if ((object[5].Frame == 10) || (object[5].Frame == 11)) //if Rope on RED bottom spots (Frames 10 and 11)
  31.       if (cAbbey.Frame == 21) { // if Abbey not moving
  32.         Display("WHOOPS! you missed the jump![- Click JUMP to try again...");
  33.         StartSkipping = 1;
  34.         object[5].SetView(30, 0, 9);
  35.         }
  36.  
  37.   if (StartSkipping == 2) // If rope moving
  38.     if (object[5].Frame == 12) { //if Rope PAST RED spots then Abbey Jumped it
  39.       SkipCount++;
  40.       TxtJumpScore.Text = String.Format("Score: %d", SkipCount);
  41.       }
  42. }
  43. //----------------------------------------------------------------------------------------------------
  44.  
  45. function BtnJump_OnClick(GUIControl *control, MouseButton button)
  46. {
  47.  
  48.   if (StartSkipping == 2) { //Already started so JUMP
  49.     cAbbey.Animate(1, 0, eOnce, eNoBlock);
  50.     TxtJumpScore.Text = String.Format("Score: %d", SkipCount);
  51.     }
  52.    
  53.   else if (StartSkipping == 1) { //First time so setup for MINIGAME
  54.     StartSkipping = 2;
  55.     SkipCount = 0; // Rest Counter
  56.     Display("The Rope is about to start so click the JUMP button to skip it!");
  57.     Display("You have to jump every time the rope is right at the BOTTOM (the rope goes RED to guide you");
  58.     TxtJumpScore.Text = String.Format("Record: %d", JumpScore);
  59.     object[5].SetView(30); //Skipping ROPE to Skip Views
  60.     object[5].Visible = true; //Skipping ROPE to visible
  61.     object[5].Animate(0, 4, eRepeat, eNoBlock);
  62.     cAbbey.Animate(1, 4, eRepeat, eNoBlock);
  63.     }
  64. }
  65. //----------------------------------------------------------------------------------------------------
  66.  
  67. // hide SKIPPING GUI directly from an OnClick event
  68. function close_skipping_gui_onclick(GUIControl *control, MouseButton button)
  69. {
  70.   StartSkipping = -1;
  71.   object[5].Visible = false; //Skipping ROPE to hidden
  72.   close_owning_gui(control);
  73.   cAbbey.x = 170;
  74.   cAbbey.y = 341;
  75.   cHero.Transparency = 0;
  76.   cHero.UnlockView();
  77.   cAbbey.LockView(2); // Return to default view
  78.   cAbbey.Animate(0, 0, eOnce, eNoBlock, eForwards, 1);
  79. }
  80. //----------------------------------------------------------------------------------------------------
  81.  
If it’s not broken, let’s fix it till it is...!