• 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!

Bust-A-Move collision check

B

Blakkid489

Guest
I've been pondering this for a little bit now and wondered how this can be done. My initial response to this would be to use a bunch of if statements.
Like so...
Code:
if placemeeting(x,y,oBlue)
{
    //Do stuff
}
But this would only work for the two and NOT multiples of the same color.
So what would be a good way to go about this?
 
G

Guest User

Guest
are you asking how to do collisions with all bubbles or how to check if there's multiples of the same color connected to the one you're colliding with?
 
B

Blakkid489

Guest
Well both really... I've tried adding different variables to check the collision when running into other bubbles but it but doesn't work well. So I scrapped it.
So now I'm trying a different method where I have a sprite box that I want the bubble to snap to once colliding with it.

Code:
//create
gridSnap = false;

//step
if (gridSnap == false) && (place_meeting(x,y,oBubbleBox))
{
    gridSnap = true;
}

if gridSnap == true
{
    
}
This is. . . bleh because I not sure how i would do this with multiple boxes in the room

I'm kind of running out of ideas
 
G

Guest User

Guest
hrm well if im understanding right then you could probably use a multiple-collision script to check for the other colors, then use an if else to check for the same color i guess:
Code:
/// @function place_meeting_ext
/// @param x
/// @param y
/// @param [object_index]
for(var i = 2; i < argument_count; i++) {
    if(place_meeting(argument[0], argument[1], argument[i])) {
        return TRUE; } }

return FALSE;
Code:
// check for collision with other, loser colors
if(place_meeting_ext(whatever, whatever, oblue, oyellow, ougly, owhatever0, owhatever1, etc) {
    /* do stuff if true */ }
// check for collision with our own, superior colored brethren
if else(place_meeting(whatever, whatever, osamecolor)) {
    /* do stuff if true */ }
// and if we're lonely move along
else {
    /* meh */ }
i'm not so sure about detecting multiple bubbles. i'd say, if a collision with the same color is found...you could perhaps with() that and check for another collision, and another....and another...but that seems hack-y and cheap and something that'd cause one of those recursion error things. :confused:
 
B

Blakkid489

Guest
This is kind of what I was looking for. It does exactly what it's supposed to do I should say. How would I alter this to snap to an invisible grid instead?
like this. . . .

Should I make a ds grid or something like to accomplish this?
 
G

Guest User

Guest
h dur, i never noticed the bubbles are on a grid when i was a kid. so yes thats a good idea.

you can get the bubble's closest position on the grid by dividing it's (x, y) coords by it's own size (since they're all the same) (you will have to round it), you can also use this to check for matching colors since you can store what color is occupying the grid once it's found a place to nest. when getting the position just have to take into account offset of the play area, the fact that odd-numbered rows have one less bubble, and offset of the y axis (the crushy thingy).

i can't remember how to get something to "slid" into position. while(!inPosition) i guess?
 
B

Blakkid489

Guest
Alright I see what you're saying. So here's my next question. The "invisible" grid, is there a way to shift that grid?
 
B

Blakkid489

Guest
This is how I have the code working now
Code:
iAngle += 10;

if (gridSnap)
{
   if (!place_snapped(24,24)) && (place_meeting(x,y,oWall))
   {
       move_snap(24,24);
       speed = 0;
   }
   if (!place_snapped(24,24)) && (place_meeting(x,y,oBubbleParent))
   {
       move_snap(24,24);
       speed = 0;
   }
}

if (place_meeting(x,y,oWall))
{
   gridSnap = true;
}
if (place_meeting(x,y,oBubbleParent))
{
   gridSnap = true;
}

if x < 24 || x > 192
{
   if (!gridSnap)
   hspeed = hspeed * -1;
}
 
G

Guest User

Guest
shift a grid as in move all the squarebbles down or make it so there's only 7 in odd-numbered rows?

i think, and bear with me here my ability to visualize code is horrendous, my guess would be that when you get where on the grid the bubble should be placed, and determine that it's an odd-numbered row, you'd simply snap it with an offset. this...shouldn't affect collisions since you're physically moving the bubble so it IS there and the incoming bubbles should detect it as so. something like
Code:
if(floor(y / bubble_size) % 2 != 0) {
    move_snap(24 + (bubble_size div 2), 24);
    speed = 0; }
the other one would probably be having a global y_shift variable that gets bigger by the size of the bubbles each time and every bubble has their y position updated by 24 + y_shift. not sure about the best way to go about that tho since you probably don't want every bubble constantly checking if the y_shift has changed. :confused:
 
B

Blakkid489

Guest
hmmm I see. It looks like this code will solve the position on the bubble lining up with one another (sort of) I'll have to play with that a bit. I guess the next issue is the detecting multiple objects touching ... any was around that lol I've been tickling this almost all day. On the crapper, driving, talking to my gf while talks about nothing :p.... I can't seem to figure out how this would go down
 
G

Guest User

Guest
that's where i'd use a ds_grid personally, updating the corresponding grid entry to a constant representing a respective color once the bubble has settled. then, once collision is detected you can simply get the current position on the grid, run a sweep of all the adjacent entries outward from the position to determine if there's enough matching bubbles.

don't know if it'd work in the end, but that's the best i can think of.
 
B

Blakkid489

Guest
Alright so I watched a really...bad.. . . . .real bad tutorial on how to make this work and here's what I got out of it



Alarm 0
Code:
if (x < 145) && (y > 47)
if (!position_empty(x+24,y)) && (!position_empty(x+48,y))
{
   var n1,n2
   n1 = instance_position(x+24,y,oBubble);
   n2 = instance_position(x+48,y,oBubble);
   if (n1.iStable) && (n2.iStable)
   {
       if (n1.iColor == iColor) && (n2.iColor == iColor)
       {
           match = 1;
       }
   }
}
if (y < 169) && (y > 47)
if (!position_empty(x,y+24)) && (!position_empty(x,y+48))
{
   var n3,n4
   n3 = instance_position(x,y+24,oBubble);
   n4 = instance_position(x,y+48,oBubble);
   if (n3.iStable) && (n4.iStable)
   {
       if (n3.iColor == iColor) && (n4.iColor == iColor)
       {
           match = 2;
       }
   }
}


switch (match)
{
   case 1:
       with (n1)
       alarm[1] = 1;
       with (n2)
       alarm[1] = 1;
       alarm[1] = 1;
       match = 0;
   break;
  
   case 2:
       with (n3)
       alarm[1] = 1;
       with (n4)
       alarm[1] = 1;
       alarm[1] = 1;
       match = 0;
   break;
}
Alarm 1
Code:
instance_destroy();
if iColor == 1
{
   with (instance_create_layer(x,y,"Animations",oBubblePop))
   co = c_red;
}
if iColor == 2
{
   with (instance_create_layer(x,y,"Animations",oBubblePop))
   co = c_yellow;
}
if iColor == 3
{
   with (instance_create_layer(x,y,"Animations",oBubblePop))
   co = c_lime;
}
As you can see it erases vertically and horizontally. To be honest I'm quite satisfied with this but it's not exactly what I wanted (Hopefully that made sense)
So would I edit this to check collision colors more than 3?
 
B

Blakkid489

Guest
As this point I think it's safe to assume that this is now a programming question. Can this be moved there?
 
Top