Jump to content


Photo

My memory match game


  • Please log in to reply
31 replies to this topic

#1 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 07 May 2012 - 06:42 AM

Hi guys,

I’m making my own memory match game but is getting really difficult , I’m testing first on how to do things right since the beginning using only 2 cards and I’m doing things like these

I have two cards and 1 controller object , card 1 has a create event and a variable named “selected” set to value 0, when left is pressed in card 1 this value is changed to 1 , same happens with card 2

Now my controller says that when card 1 “selected =1” change instance to obj_apple1 and the same happens with card 2, now I want that if both images match (obj_apple1 and obj_apple2) these must disappear let’s say after 2 seconds, I guess I have to use a create variable to affect the obj_apple1 and obj_apple2 in my controller, lest say this variable will be apples_are_up=0 then put a create event on each obj_apple affecting this variable (let’s say for obj_ controller set var apples_are_up=+1) and then I guess I must call the variable with an if declaration that would go like “if apples_are_up=2 destroy instances obj_apple1 and obj_apple2”


You know I’m new to GM and probably I’m taking the long road, my problem is that I do not know how to make them disappear after 2 seconds when both apples are up, they are disappearing right after the first click. Your help and suggestions will be highly appreciated guys.
:thumbsup:
  • 0

#2 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 07 May 2012 - 06:48 AM

I'm guessing you'll need an alarm event.
also is that all?!
  • 0

#3 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 07 May 2012 - 07:04 AM

I made my own memory match which works quite well. I based my matching off of image_index. If the image_index matched then that means it was the same card. This is much better because it only requires one obj and no instance changes, only image_index changes. (you can make the first or last subimage of the card stack the back of the card image)

Sounds like your method requires an obj per different card type which sounds horrendous!
  • 0

#4 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 07 May 2012 - 07:05 AM

Thanks creators124, not thats not all, it will have 36 cards and a timer to match all the pairs,timer will start when a play button is pressed, each pair will have a value which will be added to the score, then a reset button that will shuffle the cards . Also there will be some cards that have a special picture and those will give you the chance to play for a nice price if you enter some numbers and letters in the secret code section (yes you are right my friend, I have to put a small keyboard with letters and numbers and when you type on it the characters need to appear on a text field, if they match a secret code stored I don't know where you win) . Now you will ask me how am I supposed to do all that? Believe me my dear friend, I really don´t have a clue :ermm: but I'll do it!!!

Have a good one pal,any help will be of high value for me :thumbsup:
  • 0

#5 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 07 May 2012 - 07:12 AM

Hey kupo15 that's amazing, could you please give more details my friend; believe me I'm overwhelmed with my own method but I don't know how to code yet and your method sounds terrific, do your images disappear after some seconds? you created a shuffled button to reset the cards in different positions? man I'll donate you a kidney or my liver if you need them someday if you help me :turned:
  • 0

#6 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 07 May 2012 - 05:39 PM

Lol Ill send you my game so you can see what I did and if you have any questions feel free to ask. I even included a word list where you can check which words you want included in the game. Backspace key exits the games/word list.
I haven't included a shuffling function though..

Though this file seems a bit unorganized so probably will have to ask where each action is maybe if you can't figure it out.
http://www.mediafire...lru4c24exb9zurm

My game is a little more complicated because its a language match so there are two card decks shuffled into 1. You will be able to remove half of what I have because yours will be dealing with 1 deck.

Edited by kupo15, 07 May 2012 - 05:45 PM.

  • 0

#7 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 07 May 2012 - 05:55 PM

Your method should work, so go ahead and try to program it. I recommend you get that done before going for the shuffle button. As for the 2 second delay, it's very easy. In the controller object's Step event:

if (apples_are_up = 2) and (alarm0 = -1) //checks if the alarm is not running
alarm[0] = 2 * room_speed //room_speed is the number of steps per second

In the Alarm0 event:

with (obj_apple1) {instance_destroy()}
with (obj_apple2) {instance_destroy()}

  • 0

#8 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 07 May 2012 - 06:11 PM

Yup, that is basically what I did:
// step
if click = 0 // counts how many cards clicked on (starts at 2)
    {
    click = -1;
    alarm[0] = room_speed; // I wanted mine to be 1 second
    }

// alarm0
click = 2; // reset clicks
if check[0].card != check[1].card // if they aren't a match
    {
    sound_play(card_flip);
    check[0].image_index = sprite_get_number(con_master.chapter[0]) - 1; // set the sprite index to the last one (the back of the card)
    check[1].image_index = sprite_get_number(con_master.chapter[0]) - 1;
    }
else 
    {
    with (check[0])
    instance_destroy();
    with (check[1])
    instance_destroy();
    if !instance_exists(obj_romanian) && !instance_exists(obj_english) instance_create(290,400,obj_complete);
    else
    sound_play(correct);
    }



Edited by kupo15, 07 May 2012 - 06:12 PM.

  • 0

#9 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 08 May 2012 - 04:12 AM

Guys, you are the best, kupo15 you are great and kind person indeed; I feel lucky for finding a place like this with people who share their Knowledge without being selfish at all.

PetzI thanks a lot too, it's good to know that something I started figuring out on my own could work; I'll give a try both ways

Thanks again pals :thumbsup: If I have any question I'll come back

Edited by Frankencost, 08 May 2012 - 04:33 AM.

  • 1

#10 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 08 May 2012 - 07:02 PM

Hey kupo15, your matching game works exactly the way I want mine to work, unfortunately it is kind of hard for me to decipher your code and adapt it to my game, probably you can give me an idea on how to do it, I have the room and there will be 20 cards (I decided to make it with less cards till I learn how to code), I noticed that you put all the images in a single sprite, why? And if it is necessary, how I do that? I’m sorry for asking too much my friend but I promise once I learn I won’t be bothering this much and I will share with others what I learned. :thumbsup:
  • 0

#11 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 08 May 2012 - 08:17 PM

Haha I had a feeling it would be difficult because I have other features and games and stuff. Probably the most confusing are the arrays that I used which is because I had multiple lessons which load different sprites depending on what chapter you click.

I put all the images in a single sprite because its just much easier than creating a separate sprite for each image. I can store each chapter in 1 sprite and just load that single sprite. Much easier then creating 256 and counting sprites for each card I've made and finding out which sprites belong to which chapter.

The con_matching is a controller object that is placed in the matching room and is responsible for creating the cards and assigning each card its face value as well as handing the logic for the game. Here is what is happening in the create event. As I said you can remove half of this because you won't be having to match the image_indexes of two different card decks like I did since I had one for romanian and 1 for the english translated version.

// This code finds out which words from the word list were selected 
// which ones weren't so it knows which cards shouldn't be included in the game
/*var type,xx,yy,i;
for (i=0;i<con_master.count;i+=1)
    {
    card_used[i] = con_list.active[con_list.lesson,i];
    if card_used[i] = 1 card_used[i] = noone;
    }    */
// TO SIMPLIFY THIS FOR YOUR GAME
var type,xx,yy,i;
for (i=0;i<20;i+=1)
card_used[i] = 0; // ALL CARDS HAVEN'T BEEN USED 



click = 2; // sets how many clicks until it checks for a match
check[0] = noone; // ro card log check // when the first card is clicked, its id will be stored here for comparision
check[1] = noone; // en card log check // same as above except for when the second card is clicked
//ro_number = con_master.left[con_list.lesson]; // number of avaliable cards // NUMBER FOUND BY HOW MANY SUBIMAGES THERE ARE. 
// BECAUSE YOU ONLY HAVE 1 DECK I THINK YOU CAN REMOVE THIS
//if ro_number > 21 ro_number = 21; // limit number of displayed cards // LIMIT IT BECAUSE THE ROOM CAN ONLY DISPLAY SO MANY CARDS. YOU CAN REMOVE THIS
//en_number = ro_number; // MATCH THE ENGLISH SET WITH THE RO SET. YOU CAN REMOVE THIS
// THIS CODE CREATES THE CARDS ON THE TABLE.
xx = 16; // X AND Y OF THE FIRST CARD (TOP LEFT)
yy = 16; //
repeat(ro_number*2) // create up to 42 cards // BASED ON NUMBER OF SUBIMAGES BUT YOU CAN JUST PUT 20
    /*{
   
    // REMEMBER I HAVE TWO DECKS SO THIS LOGIC RANDOMLY CREATES A CARD FROM EACH DECK
    if ro_number != 0 && en_number != 0 type = irandom(1);
    if ro_number != 0 && en_number = 0 type = 0;
    if ro_number = 0 && en_number != 0 type = 1;
    
    if type = 0 
        {
        instance_create(xx,yy,obj_romanian);
        ro_number -= 1;
        }
    else
        {
        instance_create(xx,yy,obj_english);
        en_number -= 1;
        }*/
// YOU CAN SIMPLIFY THIS FOR YOUR GAME BY DOING THIS
instance_create(xx,yy,CARDS);

// THIS SECTION SETS THE NEW LOCATION FOR THE NEXT INSTANCE TO BE CREATED OTHERWISE YOU WILL HAVE
// 20 CARDS AT THE SAME LOCATION. YOU WILL NEED TO TWEAK THESE NUMBERS BASED ON YOUR SPRITE SIZE
    xx += 144; 
    if xx > 740 // 740 IS THE LAST COLUMN LOCATION
        {
        xx = 16; // RESET X TO THE FIRST COLUMN
        yy += 80; // SET Y TO THE NEXT ROW
        }       
    }
// THIS FINDS WHICH CARDS ARE UNUSED AND SETS A VAR TO THE CARD OBJ
/*with (obj_romanian) 
    {
    do
    card = irandom(con_master.count - 1); 
    until other.card_used[card] = false; // find unused cards
    other.card_used[card] = true; // identify used cards
    }


with (obj_english)
    {
    do
    card = irandom(con_master.count - 1);
    until other.card_used[card] = true; // find used RO cards
    other.card_used[card] = false; 
    }
// REPLACE THE ABOVE CODE WITH THIS
repeat (2)
{
with (CARDOBJ) 
    {
    do
    card = irandom(20); 
    until other.card_used[card] = false; // find unused cards
    other.card_used[card] = true; // identify used cards
    }
for (i=0;i<20;i+=1)
card_used[i] = 0; // RESET ALL CARDS BACK TO UNUSED SO YOU CAN REPEAT THIS
}

This is just the create event. I commented out all the code you didn't need. Once you understand this I can move onto the other stuff
  • 1

#12 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 08 May 2012 - 10:07 PM

Thank you very much Kupo15, this is great!!! Much easier to understand it this way, although I’m not into coding yet now I think I understand the functioning of every block of this code. Ok so to be clear I need to put all my cards (faces) in a single sprite let’s say I call it spr_faces, should I name the cards apple1,apple2, ball1, ball2, etc? Then I need to make a controller object and put the code you are explaining in the create event. Now, when cards are not a match then they turn back again to normal position, that has not been included in your code yet right?

I’m eager to get home ASAP and try this with my game, however I think I’ll need little bit more help from you my friend, we’ll talk later on pal, I owe you big time man and I won’t forget it… :thumbsup:
  • 0

#13 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 09 May 2012 - 01:39 AM

No problem man! :)

And not quite. First off, if you plan on having multiple levels with completely different cards then you will need 1 sprite per level so you should call them like level_1 level_2 etc..
And you only need 1 single object for the cards...for the entire game. Thats it! This is because we are softcoding things which means that you code it in a way so that all you have to do is plug in different values for the vars to get a different outcome. These variables will be the sprite that is being referenced and the number of cards. If this number will stay the same throughout the whole game then all you need to do is change which sprites the game will pull data from and there you have it! Level 2-finite. Which means that after the engine is done, to add new levels you simply need to add another sprite with new pictures and add another line that will reference the new sprite.

In fact I realized a slight problem with the code. It needs to be changed slightly since we are dealing with 1 deck.

var type,xx,yy,i,s; // I added another temp var s
for (i=0;i<10;i+=1) // if you want 20 cards total this means you will have 10 of each so this should be 10.
// If you want other levels to have different number of cards, this should be a var instead
card_used[i] = 2; // instead of seeing if a card is used, lets set each card at 2 and count down instead 
// this is still the same
click = 2; // sets how many clicks until it checks for a match
check[0] = noone; // when the first card is clicked, its id will be stored here for comparision
check[1] = noone; // same as above except for when the second card is clicked

// THIS CODE CREATES THE CARDS ON THE TABLE AND SETS THEIR FACE VALUE
xx = 16; // X AND Y OF THE FIRST CARD (TOP LEFT)
yy = 16; //
repeat(20) // creates 20 cards. if you plan on changing the number of cards you should make this a variable instead
{
s = instance_create(xx,yy,CARDS); // set the id of the created card to temp var s
do
s.card = irandom(10); // sets the subimage of the created card through a var "card" 
until card_used[card] != 0; // find unused cards
card_used[card] -= 1; // remove 1 from the card array

xx += 144; 
if xx > 740 // 740 IS THE LAST COLUMN LOCATION
    {
     xx = 16; // RESET X TO THE FIRST COLUMN
     yy += 80; // SET Y TO THE NEXT ROW
     }        
}


Remember this is only the create event of the matching game controller object. This will create all the cards you want with random images so that there are only 2 of each

Edited by kupo15, 09 May 2012 - 01:43 AM.

  • 0

#14 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 09 May 2012 - 05:49 PM

Thanks a lot Kupo15, tomorrow I’ll spend the day trying to finish my game and I’ll get back to you if I have any question. I really appreciate your good faith my friend. :thumbsup:
  • 0

#15 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 11 May 2012 - 12:20 AM

Hi Kupo15 , I was able to create the cards on the room but all of them are located in the same spot (I can see them switching rapidly), unable to separate the cards. I'm also getting the following error:

ERROR in
action number 1
of Create Event
for object obj_controller2:

Error in code at line 18:
until card_used[card] != 0; // find unused cards
^
at position 18: Unknown variable card

This is my code, I put all the images in sprite faces (spr_faces) and then obj_faces, my controller is obj_controller2:

var type,xx,yy,i,s;
for (i=0;i<10;i+=1)

card_used[i] = 2;
click = 2;
check[0] = noone;
check[1] = noone;

xx = 417;
yy = 72;
repeat(20)
{
s = instance_create(xx,yy,obj_faces);
do
s.card = irandom(10);
until card_used[card] != 0;
card_used[card] -= 1; y

xx += 144;
if xx > 740
{
xx = 16;
yy += 80;
}
}

repeat (2)
{
with (obj_faces)
{
do
card = irandom(20);
until other.card_used[card] = false;
other.card_used[card] = true;
}
for (i=0;i<20;i+=1)
card_used[i] = 0;
}

Please let me knowif I'm doing something wrong my friend; I really like the way your game works and I want mine to work exactly that way.

Thanks a lot man! :thumbsup:

Edited by Frankencost, 11 May 2012 - 12:25 AM.

  • 0

#16 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 11 May 2012 - 01:01 AM

no no no what are you doing!? Everything is completely there for you! haha First off please use code tags (the <> symbol)
Why are you creating new objects like obj controller2 and obj_faces? Con_match IS the controller object for the Matching game and Obj_romanian is the CARD object. Just change its name to something you want.

You didn't c/p the code in my last post because its too long. You need to remove everything after the "repeat (2)" because it isn't needed. Also there is a stray "y" here:
card_used[card] -= 1; y

You really shouldn't name the sprite "faces" especially if you are going to add more levels or if you want to use different decks. Change the names to reflect something like "deck1" or "level1"

Also you can delete all code related to "rm_multichoice" because you don't need it.

There will probably be a ton other errors you are getting because you won't be using half of what I programmed (like the word list and the chapters) but we can sort through them at that time.

Also its probably nothing but remove this line space
var type,xx,yy,i,s;
for (i=0;i<10;i+=1)

card_used[i] = 2;

so that the last line is up one.

And why did you change xx to 417? Why are you creating the first card at the right of the room? That will mess up the code that comes after it by making it look weird. Also if your room is smaller than mine you need to change these numbers to fit your room.

xx += 144; 
if xx > 740 // 740 IS THE LAST COLUMN LOCATION
    {
     xx = 16; // RESET X TO THE FIRST COLUMN
     yy += 80; // SET Y TO THE NEXT ROW
     }

Now give it a try

Edited by kupo15, 11 May 2012 - 01:05 AM.

  • 0

#17 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 11 May 2012 - 01:42 AM

LOL! Sorry for messing your code kupo15, I put xx to 417 because my room have some shadows where the cards must be placed (actually I made some round images instead of regular cards, but it should be the same) so my first card starts at that position, you will see the background image below:

My link

I'll be extremely grateful if you check and give me some suggestions, I'll keep trying in the meantime

Thanks a lot man!
  • 0

#18 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 11 May 2012 - 01:44 AM

Oh I didn't realize the room is bigger than mine??
Just send me the game lol

Edited by kupo15, 11 May 2012 - 01:45 AM.

  • 0

#19 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 11 May 2012 - 02:40 AM

Lol! yes my friend I think in the end you will be developing my own game!!! I'm sorry for bothering this much man, the thing is that I want to learn things always so fast and I end up annoying everyone around me. :confused:

Actually I do not have a game yet; I just made a colored circle (faceoff card) and I was playing with 10 cards numbered from 1 to 10, if you want I can make some graphics so you can share your wisdom with me master :thumbsup: (if you have Paypal or Neteller I'll handle you some $$$ to buy at least a t-shirt) :laugh:
  • 0

#20 Frankencost

Frankencost

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 11 May 2012 - 05:37 AM

Hey Kupo15 I kept trying and I think I'm getting closer, I'll let you know about my progress as soon I see my game in action (hopefully before 2013 :laugh:) Thanks a lot for your patience man :thumbsup:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users