PREFACE: There are probably easier ways to do this. This is how I did it, but you can experiment and come up with your own solutions; I mostly did this just to see if I could do it without any help.
One of my favorite little mini-games in a classic game is the N-Card from Super Mario Bros. 3, a simple card-matching memory game that rewarded you with whatever was on the card if you matched them--but if you missed two matches, you were kicked out of the game and would need to wait for another N-Card to come up. I decided to try my hand at replicating it without the use of external scripts, just to see if I could do it, and it turns out--I could! So I'm going to share the process with everyone.
To start with, we'll need some new graphics: two sets of cards (one for the backs, and one for the flipped cards) and one "selector" that we'll use to replace the player graphic later. Here are the ones I made; the card-back one was meant to be used for a proper "flip" animation, but it didn't play for some reason so I decided not to fight too hard with it.
EXTRA NOTES: If you want to animate the cursor, you can do so with Modern Algebra's Stopped Actor Stepping Animation script! I wanted to do this without scripts, though, so the only scripts in my sample project are outside the game itself.
Click to expand...
The number of cards you can use is dependent on the size of the sprites and your game's resolution. I used the default resolution and the cards don't exceed the 32x32 grid, and by using each "frame" as a card I was able to place 24 cards.
DIY: Give the player some alternative boards, with more or less cards. Just vary the rewards; more cards gives better rewards, fewer cards give less valuable rewards!
Click to expand...
Next, we'll need an event to call the game, and a map to transfer the player for the game itself. For my example, we'll use a simple NPC offering to let the player play a game for a small cost of 10G. I would also recommend including an option to let the player review how the game is played, so they don't get too confused on how it works.
EXTRA NOTES: There's some extra NPCs in this example for the sake of filling up the room. The gentleman by the fireplace runs a Sell-Only Shop (code by Tsukihime) to sell the prizes you get; the green-haired man (Kendrick) gives you some money to start the game, since you don't have any money to start out; the white-haired man encourages the player to look at the code; and the maid is just a maid.
Click to expand...
Now, we'll set up a game board. You can use any sort of tiles you want, but the map cannot be bigger than the game's resolution to avoid scrolling. In this instance, the resolution is the default RMVXA resolution, 680x520. Set up an event for each card, in whatever arrangement you want. I would suggest making one event and setting up everything, then copying it and changing the switches as needed. I also included a spot where the player can end the game early if they want.
Each event (including the quick-exit event) should be set to be below the player, and activated with the action button (meaning it will be activated when the player presses the button while hovering over the event). The events have three pages: the default, face-down state, when the player has not selected the card; a face-up state, when the card has been selected; and a blank page, used after the cards have been properly matched. To determine when each state is used, we'll be using switches.
There are 24 cards in play, so we'll need 24 switches to determine if each card has been flipped; we'll also make an extra 12 switches, which are used when pairs are matched, and finally two extra switches: "Card Flipped", to determine if a card was flipped, and "Missed Match", to determine if the player has already missed one match. You can use fewer or more switches, depending on how many cards you have in play.
EXTRA NOTES: This can also be done with a couple of variables, which in hindsight might have been easier. I did this with switches and didn't think about using variables until earlier. I'll probably do a different version using variables instead to see how easily it works.
Click to expand...
The face-down card is where all of our coding will be. It will have the conditions for matching as well as the transfers back out of the game after it ends. At the start of each selection, we'll turn on the switch for the respective card, then run a series of conditional branches to determine if it's a match.
- BRANCH 1: Is another card selected?
- IF YES:
- BRANCH 2: Does the card match?
- IF YES:
- Remove both cards, and give the player a prize.
- BRANCH 2.5: Has the player matched all of the cards?
- IF YES: The player has won; transfer the player back to the map, and reward them.
- IF NO: Continue the game.
- IF NO:
- BRANCH 3: Did the player already miss one match?
- IF YES:
- End the game, reset all switches and variables.
- IF NO:
- Flip the cards back over, mark that the player missed a match.
- IF NO:
- Let the player select the next card.
复制代码
Now, we'll break down each branch, bit by bit.
For Branch 1, we're checking if the "Card Flipped" switch has already been set to ON. If it has, then we run the next branch; if not, we turn the switch on, and the player selects the next card they want to flip. There's really nothing fancy about that one.
For Branch 2, we're checking if the cards match. For this, we're checking the status of the switch for its corresponding card. For example, if Card 2 has been flipped, we need to see if Card 1 has been flipped. If the right card has been flipped, it's considered a match. We'll turn on the switch that represents the proper pair, which removes the cards from the board by calling the event's third page (the blank page), then turn the "Card Flipped" switch and all of the different card switches off to prepare for the next selection. We'll also give the player a prize, similar to how SMB3 would reward the player with whatever was on the card (a 1UP, coins, etc.).
DIY: You can put a picture of the item the player would receive on the cards, just like SMB3. It gives an incentive to match them!
Click to expand...
Additionally, we need to ensure that if there are no pairs left, the game ends correctly. For this, we'll set a variable up called "Matched Pairs", which we'll increase by 1 with each pair we match. When we reach the maximum number of pairs, in this case 12, we run an extra code block that transfers the player back to the original map and gives them a bonus prize for winning.
If it isn't a match, however, we run the third branch. Branch 3 checks if "Missed Match" is ON or not; if it is, that means this is the second missed pair, which ends the game. We'll return the player to the initial map, then reset all of the switches and the Matches Made variable to prepare the game for another run. We can also include a consolation prize, based on the Matched Pairs; if they haven't gotten any pairs at all (the variable is equal to 0), we can give the player a small prize for playing. However, if the switch isn't on, then we just turn it on, then reset the card switches as before to let the player pick another pair.
Now, let's go back to the actual transfer event. When the player decides to play the game, we'll set a few changes. First, disable access to the menu, so there's no interrupting the game. Then, while the screen is faded out for the transfer, change the player graphic to our Selector graphic, to imitate a cursor on the screen. And finally, transfer the player to the game's map, and let the game do its thing. When we're transferring back from the game to the map, we just undo those changes while the fadeout is happening (return the player graphic to normal and restore menu access), and then reset all the switches and variables.
The end result, if everything has been set up correctly, is that the player can select two cards, determine if they match, and if they do they win a prize but if they don't they get nothing.
You can check the sample project on the Steam Workshop
here, or download the project directly on
MediaFire!
本贴来自国际rpgmaker官方论坛作者:Pandappuccino处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/how-to-make-a-card-matching-game-without-scripts.141437/