• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Problem with collision y + 32, match 3

B

Bhreno Kevin

Guest
Hello!
I have a project "Match 3" style where 3 random pieces are created each time and they descend (y + 32) whenever there is nothing solid in y + 32.
If y + 32 has something solid, these three pieces go to "solid pieces" (another type of pieces).
However, it turns out that the second piece (which is in the middle) will always stop inside the first piece (the bottom piece) when they hit something solid. This is not the case when the first piece is yellow.

Obj_parent_pieces_down codes:

CREATE:
Code:
y_solid=false;
STEP:
Code:
if !place_free(x,y+32)
{
y_solid=true;
}

if y_solid=false
{
y+=32;
}
else
{
with(ob_piece_yellow_down)
instance_change(ob_piece_yellow,1);
with(ob_piece_blue_down)
instance_change(ob_piece_blue,1);
with(ob_piece_orange_down)
instance_change(ob_piece_orange,1);
with(ob_piece_pink_down)
instance_change(ob_piece_pink,1);
with(ob_piece_purple_down)
instance_change(ob_piece_purple,1);
with(ob_piece_green_down)
instance_change(ob_piece_green,1);
}
KEY DOWN:
Code:
if y_solid=false
{
if (x<288) and (y<512)
{
y+=32
}
}
Notes: The "down" pieces are not solid, just the normal pieces are. And there is also an obj_block that is also solid.
 
Last edited by a moderator:
J

jsterj

Guest
I'm not certain I completely understand what you're describing when you say "always stop inside the first piece". Do you mean it's overlapping it?

I do see two errors in your code though: When comparing values in your IF statements, you need to use the double equals.

e.g.
Code:
if y_solid=false
{
    y+=32;
}

SHOULD BE

if (y_solid == false)
{
   y+=32;
}
A single equals is assigning value, not comparing values.
 
B

Bhreno Kevin

Guest
I will try to explain the problem better through these images. The yellow piece is the "third piece," the blue "the second," and the purple one is "the first." When the "down" pieces collide with the obj_block, the sure thing was to happen like in the "How should they stay" image, but what really happens is the "How they stand" error.
 

Attachments

J

jsterj

Guest
Without seeing more of your project, I'm not certain whats happening. Is there a reason you have two different objects for each block?

I did a quick test on my end and it's easy enough to do with a single object. I don't know exactly what you're building though, so you may have a legitimate reason for having two.

If this helps at all, here's the code I used in my blocks.


CREATE:
Code:
isFalling = true;
fallSpeed = 16;
STEP:
Code:
if(!isFalling) { return };

if(place_free(x,y + fallSpeed))
{   
   y += fallSpeed;
   
   if(y + sprite_height >= room_height)
   {
       y = room_height - sprite_height;
       isFalling = false;
   }
}
This code is assuming that your block height is evenly divisible by the speed that the blocks are falling. i.e. my blocks are 64px, and the speed is 16. (64 / 16 = no remainder)
 
Top