1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Problem with collision y + 32, match 3

Discussion in 'Programming' started by Bhreno Kevin, Mar 28, 2017.

  1. Bhreno Kevin

    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: Mar 28, 2017
  2. jsterj

    jsterj Member

    Joined:
    Mar 24, 2017
    Posts:
    21
    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.
     
  3. Bhreno Kevin

    Bhreno Kevin Guest

    Yes, the second piece is overlapping the first.
     
  4. Bhreno Kevin

    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.
     

    Attached Files:

  5. jsterj

    jsterj Member

    Joined:
    Mar 24, 2017
    Posts:
    21
    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)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice