Hi all, first time posting in the tutorials section. I've made this mini-game for my own project, and have no idea if anyone has posted something similar before, so I'll just go ahead and share.
Introduction:
This mini-game has many variants, like catching fruit with a basket or collecting coins. For the purposes of this tutorial I will be using the backstory of Harold and friends getting flying powers from a fairy to punch some chickens.
Plugins Used:
The plugins we need is Yanfly's Core Engine, Region Restrictions and Move Route Core. These are all included in the Free Starter Pack Essentials bundle.
Variables and Switches
2 Variables are used for the Score and Highscore respectively, although it is technically optional. A third variable will be needed for a timer on the mini-game (Unless Harold wants to change his career to chicken puncher)
Spoiler: Step 1: Creating the scene
Depending on your screen size, the best map size may change, but I would recommend making it such that the map will not scroll vertically when moving the player. Also, make the ends of the map not visible to the player.
I'm using a 19 x 13 map with a 816 x624 game window.
Add a nice parallax and let it scroll for the illusion of movement.
As for the Tileset... we don't need one! By use of region restrictions, we can control the movable area of the player.
Spoiler: Step 2: Set the map
Go to the Region Restrictions plugin and set a region for 'Event Allow' and 'All Allow'. The rest are unneeded for this barebones build of the mini-game. Cover the entire area with the 'Event Allow' region. Draw out the area you want to allow your player to move around in with the 'All Allow' region. I'm just using a line in this case
We'll come back to this map later, but for now let's make the second map, where we set the event to launch this game.
Spoiler: Step 3: The launcher NPC
Create another map, use one of your existing ones, it's all fine. The important thing is to have an NPC to run the game.
The only thing this NPC needs to do is to transfer the player into the mini-game map, but you can also turn off the followers and fixed the direction of the player to make the game neater. If you're using a score system, remember to set the current score to 0.
Note: Ignore the self switch that I have on this NPC, its irrelevant.
Spoiler: Step 4: The Birds
Back at the mini-game map with the region restrictions, create a new event on the right end of the map. This will be the object you want your player to catch. Set it to run in parallel and run the following events:
Set a variable (mentioned previously) to the number of frames for this event to wait until it 'spawns' in the mini-game. I find a random 60-600 frames (1-10 seconds) quite decent.
Next, run a script for a wait time same as the respawn variable with the script call "this.wait($gameVariables.value(x))", replacing x with the respawn variable.
Set the self-switch to trigger once the wait is complete, and the we move on to page 2!
Note: For page 1, the image can be left blank.
Step 4.5
In page 2 of the object event,
Put the graphic (I highly recommend chicken) and tick the Walking, Stepping and Direction Fix boxes. Set the priority to Same as Characters, else the chicken will run right under Harold's legs! Use Event Touch as the trigger. Now the event contents will play when the chicken touches Harold.
Put an animation to show that you've successfully punched/caught the object, and use a move event with the 'Teleport: x, y' scriptcall to bring the object back to its original position. The original position of the object can be seen at the bottom left of the editor, so you don't have to keep closing and opening it.
Turn off the self-switch to bring the object back to its waiting phase. If you are counting score, remember to add or subtract from the variable!
Step 4.75
In a custom move route on page 2, use the Move Route Core plugin to call for a script to move the chicken to the left end of the map. Remember to use 'Crash Move To' rather than the regular 'Move To', or the object will dodge the player.
Once it reaches the end, teleport it back to its original position.
Since there is no toggle self-switch button in move routes, we have to use a script instead. Use this format
$gameSelfSwitches.setValue([a, b, 'c'], false)
a is the map id, b is the event id and c is the self switch (I'm using 'A' as c, don't get confused). Remember to put a quote around the self switch letter. Refer to the picture below for an example.
Step 4.875
Aaaand we're finally done with the object! The last thing for this part is to copy-paste the object a few times to make more objects. Remember to change the event id of the object in the self switch part! Also adjust the co-ordinates for the 'Crash Move To' and the 'Teleport' script calls! If the objects behave weirdly when testing, this is the most likely reason.
Now Harold can catch chickens forever! But what if he needs to go back to saving the world?
Spoiler: Step 5: Timer
Create a new event. This will be the timer for the game. Set the first page to Trigger in parallel. Set a wait command for however long you want the round to last. 60 frames = 10 seconds, so my example is 25s with 1500 frames.
After the timer is done, it needs to record the highscore, if you want that function. Do a check to see if the current score is higher than the highscore, and replace it if it is. Now flip a self switch to toggle the 2nd page, and set it to Autorun. This page is in is just to do all the clean up before transferring the player back to the original map. Turn off Direction Fix, turn on Followers etc.
The reason we need a second page is that anything after a map transfer event stops working after the transfer, due to page 1 being in parallel. Basically, the fade in won't work and Harold will be trapped in darkness forever.
And we're done!
This basic game can be modified in many ways. Change the movement of the objects, give the player more than a line to move in, make the goal to avoid the objects instead, there is a lot of possibility.
I hope this will help anyone thinking of adding a simple mini-game for their heroes taking a break from fighting evil. As always, I recommend punching chickens.