RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Memoria Mini-game!!! (see the projects/games area also)

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 90
Hello people. Since someone requested me to do a tutorial on how to do the Memory mini-game (you can check it out and download it at the projects/games area), I made it. Hope it is useful for you and a little tiny credit in your game would be nice :)
Now let's start this, shall we?

First thing you'll need is a deck (or decks). If you have downloaded the mini-game you can see they're nothing but character sprites (each card with 64x64 pixels). Since my board has place for 24 cards (you can add more if you want), I needed 12 different cards plus the back-side of the cards.

The second thing is a cursor: mine is also a character sprite. What I did was to create a hero that has it.

The third thing is the switch and variables we will use in all card events.

SWITCH:
   a) "Chose 1st card" to check if we've already chosen the 1st card;
VARIABLES:
   a) "Chosen card" to store the value of the card we chose;
   c) "Chosen card figure" to store the value of the figure that is in the chosen card;
   b) "Tries" to store the number of tries we made and "Right" to store the number of right tries.

So,
1) Create the sprites, the cursor and the switches/variables above.

2) Now you have to create the map where the game will take place. Mine is a normal 20x15 map with the board at the center.

3) Since this game its about cards, create an event in the map and call it Card1.

Put it with the "Action key" trigger, and check the "Lock Facing" and "Phasing" options.

The graphic is the back-side of the card.

And now its comes the hard part. For THIS card we will need:
   a) A switch called "Card1 off" that turns ON if you have matched it with its pair;
   b) Another one called "Card1 show" that turns ON when you select the card;
   c) A variable called "Card1" that stores the value of the card;

I advise you to create this switches one after another, for them to be consecutive. This will make scripting easier. For example:

0001: Card1 off
0002: Card1 show

Since you'll need switches for the other cards, I advise you again to make them consecutive:

0001: Card1 off
0002: Card1 show
0003: Card2 off
0004: Card3 show
...

4) Create them and now we will begin the card1 editing (I present the code after all the explanations):

   4.1) In the event commands, check if the switch "Chose 1st card" is off. This will tell us if this is the 1st card we're selecting or the 2nd one, cuz if it is the 2nd we have to check if this one is equal to the 1st we chose. We will need an "Else Handler" in the condition.

   <> Conditional Branch: Switch [00XX: Chose 1st Card] == OFF

4.2) Inside the conditional Branch:

   4.2.1) Play a sound to tell the player it has done the choice:
       <>Play SE:'005-System05', 80, 100        (For Example)

   4.2.2) Switch on the "Card1 show" and "Chose 1st Card" switches. This will show the card to the player and tell us the player has done its 1st choice. Set the variable "Chosen Card" to 1, since it is the number of the card the player chose. We'll also set the figure chosen.

       <> Switch: [00XX: Card1 show] = ON
       <> Switch: [00XX: Chose 1st card] = ON
       <> Variable: [00XX: Chosen Card] = 1
       <> Variable: [00XX: Chosen Card Figure] = Variable: [00XX:Card1]

4.3) Now let's do the Else Handler, which tells us that the player chose a card before this one. So, we will have to check if this one is equal to the 1st.
Inside the else handler we'll need another conditional branch without else handler. This one will check if the player is choosing the same card or not. So,

   4.3.1) :   Else Handler
                <>Conditional Branch: Variables [00XX: Chosen Card] != 1 (avoid choosing card 1 again)
                <>Variable: [00XX: Tries] += 1       (adds a try since we have chosen 2 cards)
                <>Play SE:'005-System05', 80, 100    (plays the choice sound)
                <>Switch: [00XX: Card1 show] = ON   (since we have chosen another card, we have to show this one to the player)
                <>Wait: 10 Frames        (so the player has time to see the card)
                <>Conditional Branch: Variable [00XX: Chosen Card Figure] == Variable [00XX: Card1] (This will check if the figures from the cards are equal. Need else handler)
                     <>Play SE:'055-Right01', 80, 100    (plays the right choice sound)
                     <>Switch: [00XX:Card1 off] = ON   (erases card1)
                     <>Script: $game_temp.erase_card($game_variables[!!!!])   (!!!! is the "Chosen Card" variable ID. This will set the 1st card off. We'll build it later.)
                     <>Variable: [00XX: Right] += 1     (adds 1 to the right choices counter)
                     <> Switch: [00XX: Chose 1st card] = OFF    (reset chosen cards)
                     <> Variable: [00XX: Chosen Card] = 0     (reset chosen cards)
                     <>
                :     Else Handler
                     <>Play SE:'057-Wrong01', 80, 100    (well, that was a bad choice...)

         Ok, now breathe before the next step. If you think it through, this is only Card no.1, which means we will have to create all the others 23 AND switches for all of them. Each card has 2 switches: 'OFF' and 'Show'. So, in the next step you will have to turn ALL the cards down:

                     <>Switch: [00XX: Card1 Show] = OFF   (put EVERY 'show' switch here)
                     <>Switch: [00XX: Card2 Show] = OFF   (and so on till the Card24 Show is OFF)
                       ...
                     <> Switch: [00XX: Chose 1st card] = OFF    (reset chosen cards)
                     <> Variable: [00XX: Chosen Card] = 0     (reset chosen cards)

5) Pfuu... that was though... Next, we'll make ALL the possible figures in card 1. Create a new page:
In preconditions check the Switch  (00XX: Card1 show) and the variable (00XX: Card1 greater than or equal to 0).  Options just the 1st, the trigger action key (doesn't matter cuz we won't put code). The graphic is figure no.1 (for example, mine is Laguna).

6) Copy and paste and make all the other figures until the variable reaches 11 (since I have 24 cards, they are 12 figures)

7) If you have more than one deck, copy all the pages with figures again and check the second switch to be  00XX: 2nd Deck and change the figures to match the 2nd deck.

8) Last page has no graphic, and has the precondition to Switch:  00XX: Card1 off.

We have created the 1st card! Hurray!!! Now do all the others. Take your time and don't forget to change the values to fit the number of the card.

9) Arrange the events in the map so they don't overlap due to their 64x64 size.

10) Now that we have all the cards, we'll start the game. New event named "Keys", no graphic, parallel process. This one will control our cursor around the board. The commands are:

   <>Variable: [00XX: Hero X] = Player X Coordinate          (Save the cursor's X)
   <>Variable: [00XX: Hero Y] = Player Y Coordinate          (Save the cursor's Y)
   <>Variable: [00XX: Map] = Map ID          (Save the cursor's map ID)

11) Now we will check the keys:

   <>Conditional Branch: Key Down pushed
        <>Play SE: '002-System02', 80, 100   (sound of cursor movement)
        <>Conditional Branch: Variable [00XX: Hero Y] == 11  (or whatever. It checks if the cursor is in the last line. So, in MY map, if it is in the last line the Y coordinate will be equal to 11).
            <>Variable: [00XX: Hero Y] -= 6        (Since I have 4 lines and each card is 2 times each square (64), I need the cursor to go up 3 lines (3x2=6  duh).
        :   Else Handler
            <>Variable: [00XX: Hero Y] += 2       (If the cursor is not in the last line, I want it to go down 1. Again, since one square is 32x32 and our cards are 64x64, I will increase the Y coordinate by 2)
        :   End
        <>Teleport: By Variables [Map][HeroX][HeroY], NO FADE   (to place the cursor)
        <>Wait:2 Frames     (to smooth the movement)
   :   End

12) Same thing to the other directions with the proper values.

13) After the directions check if the player is trying to leave the game:

   <>Conditional Branch: Key B pushed
       <>Play SE: '002-System02', 80, 100
       <>Switch: [00XX: B Press] = ON        (switch to know if B is pressed)
   :  End

14) New page with the "B press" switch in the conditions. Auto-start page. Commands:
   <>Show Choices: Continue, Exit           (presents choices to the player)
   :    [Continue] Handler
       <>Switch: [00XX: B Press] = OFF
   :    [Exit] Handler
       <> .... (put here what you want, to return to the map before the game, or whatever)
   :   End

15) Create another event now and call it "End". Make it parallel process. This one will check if the game's over:

   <>Conditional Branch: Variable [00XX: Right] == 12
       <> .... (put here what you want, to return to the map before the game, or whatever. You can even give the "New Game" and "Exit" choices to the player. For the new game, don't forget to reset all switches and variables, and to insert "Script: $game_temp.dist". You will see this script below.)   
   :   End

And it's done. Now we have to build the scripts. Easy. But first I will explain what you have to do to include the mini-game in your game.

When you want to start the game, you should save the player's coordinates and map ID so you can return him to it after the game. Then you should put the "Cursor" hero in your party, and teleport the hero to the game board (just above card1 so it can start to play).

How do the cards randomly choose their figure, you ask? Before or after the teleporting you add the command  "Script: $game_temp.dist". We will build this one and the other now.

16) Open the script editor in "Game_Temp". In the bottom of the script before the last end add this script:

  def erase_card(id)
    chosen_card = id
    switch_off = (chosen_card * 2) - 1   #!!!!
    $game_switches[switch_off] = true
  end

This script will turn ON the switch [CardXX off].

Be careful with the line with "!!!!". The "switch_off" calculates the id of the switch 'OFF' for the card id. For example, is it's

Card1  => switch_off = (1*2)-1 = 1
Card2  => switch_off = 3

This is because of my switches' IDs, since I have:

0001: Card1 off
0002: Card1 show
0003: Card2 off
0004: Card 2 show
.....

That's why I advised you to make them consecutive. However, if you have switches before these, just change "switch_off = (chosen_card * 2) - 1" to: 

switch_off = (chosen_card * 2) - 1 + XXX           (XXX is the number of switches you have before)

Imagine I have one switch before them.

0001: Damn switch
0002: Card1 off
0003: Card1 show
0004: Card2 off
...

This way, if I'm looking for card1 off:

Chosen_card = 1
switch_off = (1*2) -1 + 1= 2

If I'm looking for card2 off:

Chosen_card = 2
switch_off = (2*2) -1 + 1= 4

17) Next: a big one, the random figure picking. XX is the ID for the variable "Card1", and YY for "Card2":

def dist
    type = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]  #sets 24 numbers
    # --------------------
    card1 = rand(23)    #picks a random number for card 1. Notice we have 24 numbers in "type", but we have to input 23 so it picks one number from index "0" to index "23".
    $game_variables[XX] = type[card1]     #This sets card1 with the random figure
    $game_variables[XX] -= 12 if $game_variables[XX] >= 12      #Since we have 12 figures, each one appearing 2 times, if the number picked is greater than 12 we have to
#turn it into a number from 0 to 12 by removing 12 from its value.
     type.delete(type[card1])   # deletes the value chosen from "type", avoiding it to be chosen again
    # --------------------
    card2 = rand(22)   #same for card2 but we only have 23 numbers in "type", so "rand(22)"
    $game_variables[YY] = type[card2]    #This sets card2 with the random figure
    $game_variables[YY] -= 12 if $game_variables[YY] >= 12
    type.delete(type[card2]) # deletes the value chosen from "type", avoiding it to be chosen again
    ...
end

Continue doing this for all cards until you reach:

    card23 = rand(1)
    $game_variables[ZZ] = type[card23]
    $game_variables[ZZ] -= 12 if $game_variables[ZZ] >= 12
    type.delete(type[card23])
    # --------------------
    card24 = 0
    $game_variables[WW] = type[card24]
    $game_variables[WW] -= 12 if $game_variables[WW] >= 12
    type.delete(type[card24])
  end
end

18) I think that's all. Now you should be able to play it. Any questions or errors please tell me. Thanks for reading!
« Last Edit: October 26, 2006, 09:12:11 AM by Sir Edeon X »
~ Love me... I want you to love me... ~

Scripting Academy || My Deviantart || Project: Tsol - Aishite Aishite

Tired of:
Main character being found in a cliff and not being human;
Angel characters against demon ones;
Vampire characters falling in love with humans;
Human rebelling against Dragons;
More than one world in ACTUALLY one world;
DNA transfusions and mutations;
Powerful races and humans who amazingly rule almost every part of the world having absolutely no super power;
Demons being released after some time in "slumber";
Titles with Legacy or the name of the world on it;

****
MONOCLE MAN
Rep:
Level 89
-::Gone::-
Can we make an event with this? So you don't play at start up?

***
Rep:
Level 90
I didn't get it. At start up?
The game will only start when you teleport the hero to the map of the game.
~ Love me... I want you to love me... ~

Scripting Academy || My Deviantart || Project: Tsol - Aishite Aishite

Tired of:
Main character being found in a cliff and not being human;
Angel characters against demon ones;
Vampire characters falling in love with humans;
Human rebelling against Dragons;
More than one world in ACTUALLY one world;
DNA transfusions and mutations;
Powerful races and humans who amazingly rule almost every part of the world having absolutely no super power;
Demons being released after some time in "slumber";
Titles with Legacy or the name of the world on it;

*
I love Firerain
Rep:
Level 97
=D
OMG! THIS IS GREAT!@ Exactly i didnt ask the thing, i asked the time. BUT THIS IS AWSOME!
I may use it..99%
Arlen is hot.

****
Rep:
Level 89
What will that crazy ape do next?
w00t i learned something today ^^

i'm not sure if I will use this, but it certianly is awesome.
My Project: Dark Empire
http://rmrk.net/index.php/topic,7815.0.html
Official Site: http://darkempirerpg.tripod.com
Process: Getting back to work.

Always looking for sprites, if your interested, PM.

"But then I realized, why stop things from exploding, when in fact it is in exploding that things reach their perfect form. Of course, they only reach it for a few glorious seconds, but during that short time there is no object in the universe more beautiful." -Kite Rockswell, the Mad-Mad Bomber, from The Final War, my very own novel project.  PM me if you would like to read.

"Oh, sure, blaim the wizards..."