[SOLVED] Function to check if 3 equal "tiles" are side by side

B

Bhreno Kevin

Guest
I'm a beginner in Game Maker Studio 1.47, and I need help to create the following function (I hope you understand!):

//
if image_index(x+32,y) == image_index and image_index (x+64, y) == image_index
{
position_destroy(x,y);
position_destroy(x+32,y);
position_destroy(x+64,y);
}
//

Note: I am trying to set up a game in the "Magic Jewerly" style of Nintendo, and I need a function to check if 3 equal "pieces" are side by side, to destroy them.
 
Last edited by a moderator:

Perseus

Not Medusa
Forum Staff
Moderator
Please note that the GMC is an English-speaking community, so we require all the posts to be in English or at least contain their English versions, even if they've been translated using a tool like Google Translate. But since I've translated it myself to help you out, I've got a few remarks. The code that you've got there is not working because image_index is a variable, but you're treating it like a function. To get the image index of an instance at a certain position, you need to store the id of the instance in a local variable and use an instance.variable expression to get its image index. The instance id can be found out by using instance_position. Then you can use the same variables to destroy the instances instead of using position_destroy. Read up on this in the manual for further reference.

PS: I must add that you should use a tutorial like this one as the logic that you're currently trying to implement is a bit flawed for a match-3 game. But if you can provide more context in English, I'm sure you can be helped out of this situation far more quickly.
 
B

Bhreno Kevin

Guest
Okay, Thanks!
I've solved the problem.
I created the necessary variables and used this formula in the alarm [3] of the parent object.

Code:
off=false;

//horizontal
if (x<288) and (x>31)
if (!position_empty(x+32,y)) and (!position_empty(x+64,y))
{
var N1,N2;
N1=instance_position(x+32,y,ob_parent_pecas);
N2=instance_position(x+64,y,ob_parent_pecas);
if(N1 && N2){
if (N1.stable==true and N2.stable=true)
{
if (N1.image_index==image_index) and (N2.image_index==image_index)
{
match=1;
}
}
}
}

//vertical
if (y<480) and (y>63)
if (!position_empty(x,y+32)) and (!position_empty(x,y+64))
{
var N3,N4;
N3=instance_position(x,y+32,ob_parent_pecas);
N4=instance_position(x,y+64,ob_parent_pecas);
if(N3 && N4){
if (N3.stable==true and N4.stable=true)
{
if (N3.image_index==image_index) and (N4.image_index==image_index)
{
match=2;
}
}
}
}

//diagonal "/"
if (x<288) and (x>31)
if (!position_empty(x+32,y+32)) and (!position_empty(x+64,y+64))
{
var N5,N6;
N5=instance_position(x+32,y+32,ob_parent_pecas);
N6=instance_position(x+64,y+64,ob_parent_pecas);
if(N5 && N6){
if (N5.stable==true and N6.stable=true)
{
if (N5.image_index==image_index) and (N6.image_index==image_index)
{
match=3;
}
}
}
}

//diagonal "\"
if (x<288) and (x>31)
if (!position_empty(x-32,y+32)) and (!position_empty(x-64,y+64))
{
var N7,N8;
N7=instance_position(x-32,y+32,ob_parent_pecas);
N8=instance_position(x-64,y+64,ob_parent_pecas);
if(N7 && N8){
if (N7.stable==true and N8.stable=true)
{
if (N7.image_index==image_index) and (N8.image_index==image_index)
{
match=4;
}
}
}
}

switch (match)
{
case 1:
with(N1)
alarm[4]=1;
with(N2)
alarm[4]=1;
alarm[4]=1;
match=0;
break;

case 2:
with(N3)
alarm[4]=1;
with(N4)
alarm[4]=1;
alarm[4]=1;
match=0;
break;

case 3:
with(N5)
alarm[4]=1;
with(N6)
alarm[4]=1;
alarm[4]=1;
match=0;
break;

case 4:
with(N7)
alarm[4]=1;
with(N8)
alarm[4]=1;
alarm[4]=1;
match=0;
break;
}
 
Last edited by a moderator:
Top