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

Help with group object and line of object

H

hiep

Guest
Hello.
First, is there anyway to group some different object to run the same code like : I have object A and B.
When an object C is between A and B then A and B will do the same object when i need.

Second, How to know that some diffent object is create a consecutive row or consecutive column ?

Thanks for advance !
 
You need to give more details. It sounds like you're making a "connect" puzzle game, like Puyo Puyo / Dr robotniks mean bean machine...? When 3, or more, of the same coloured object connect they merge together and are destroyed - that kind of game?

For example (as an answer to your first question): Object A to Object B - is Object C in between?

Well, you could use collision_line for that, but without knowing what you intend to do (or how your project is set up) it is tricky to say if that is a good solution :) If you were making the kind of game I described above, then collision_line probably wouldn't fit.
 
H

hiep

Guest
yeah that's right. I want to make a game like you said. Any solution for this ?
 
I have attempted this before, and partially solved it. But I can't 100% give you an answer to this.

1) In the example that I have, the objects aren't moving. By clicking on an instance it sets off a chain reaction, where only touching objects of the same colour are destroyed, and only if the number of collisions is >= 3. The problem is that I haven't figured out how to do this without the player manually starting the process. Whereas you'd want it to happen when a block stops moving - i.e it has collided with another block underneath it, and settles into a fixed position.

2) The other problem my example has, is that it occasionally misses a block that is connected.

Unfortunately I don't have the time to really figure out why number 2 happens, and number 1 is something I'd have to look into a lot more to make it work on the fly.
 
@RefresherTowel
I suppose the problem my example has, is that its quite controlled at the moment.

1) An instance of the same colour is found to be in collision around the top / left / right / bottom side. If their ids are not found on a ds list, then the id of the collisions are added.

2) Those in collision become "active" and repeat the same check. By looking at the list for ids they don't repeat the process with the previous instance in collision.

3) When no collisions are found, that is not already an id on the list (the last object in the chain), it looks to see if the list size is larger than, or equal, to three.

4) If the list size is >= 3 it then loops through the ids on the list, and tells them to destroy themselves. If its less than 3 it clears the list.

It's probably doable for the OP' purposes, it's just that I haven't set it up as anything other than a controlled test.

@hiep
https://1drv.ms/f/s!Avll8phMVHjc9nxJ0wELeKs9OIgd

This will give you an idea of how to approach this, but I can't go into detail about what it's doing (my explanation to RefresherTowel above describes the basic gist), or set it up exactly as you may want.

It is randomly setting colours for the instances. If you click on any of the groups it will destroy those with 3 or more of the same colour. And do nothing if they are less than three.

Unfortunately I did notice some times where it didn't destroy every instance of the same colour, and haven't yet fixed that. Maybe you will figure that out yourself - hope it helps.
 
Last edited:
Yeah, I'm saying start that chain of events every time a block "falls" onto another. That should trigger like 90% of the circumstances where blocks need to be controlled. You could also run a sweep across each instance every second or so and trigger the chain of events for each one. I'm just saying, I'm not sure why you need the user to click to make that happen. Just move the click code into the two circumstances I outlined above.
 
Yeah, I'm saying start that chain of events every time a block "falls" onto another. That should trigger like 90% of the circumstances where blocks need to be controlled. You could also run a sweep across each instance every second or so and trigger the chain of events for each one. I'm just saying, I'm not sure why you need the user to click to make that happen. Just move the click code into the two circumstances I outlined above.
This is just a project I tested quite some time ago, to help another user. Not one that I personally have made to replicate that kind of game entirely. Whilst your solutions are probably correct I don't have the time to configure this under those conditions.

I included the project file in a link for the user, if you want to take a look.
 
Hahaha, ok man. From the sound of your first post it sounded like something you were actively working on. Just trying to offer some ideas for the automatic trigger instead of a manual one. In any case, I'm sure OP can take some helpful details away from our back and forth.
 

NightFrost

Member
So a match-3 type of game where matching rows and columns get removed? My implementation tracked the positions on a 2d array (ds grid would work just as well). The matcher was a simple brute-force loop. Pick the color of item in first position (if the position is not empty). Do any of the neighbours have same color and they are currently not falling? If so, keep exploring in those directions. Is there a third? If so, create a temporary array and store those positions in it. Keep exploring until different color or field edge is found. Store the temporary arrays in found matches array. Then pick the color in second position and repeat. Once the entire field has been explored, go through the found matches array, destroy every instance listed in there, and empty the array.

The grid also has a routine that looks for empty cells beneath filled ones. Is the cell beneath this occupied cell empty? If so, how far down does the empty region go? Switch the instance's position to the deepest empty cell and mark it as falling. This check needs to run from bottom up or the items won't fall right. The routine does not have them do positioning in intervening empty cells because there's no point in that. The items will not stop in them, and while falling they cannot be part of matches. So it makes sense to immediately set them to their destination.

Relating to these actions the instances mostly had just a fall routine. Am I set to falling state? If so, animate from my sprite from its current position towards my position marked in the grid, and have gravity global accelerate my speed. Did my sprite reach or go past my grid position? If so, center sprite to my position, set speed to zero and switch from falling state to stationary state.

In other words, an item has two positions: their actual position on the grid and a position for their sprite. When they fall, their physical position changes immediately to destination to reserve it, and then the item animates their sprite falling to that position. While fall is animated, the item will not match with other items, because visually it is not yet in correct position. If you don't switch the physical position immediately when the fall starts, the item may need to compete with other falling items for that position and try to figure out which one reaches it first (which could be difficult because items falling from higher up have accelerated to faster speeds). Best to skip all that nonsense and reserve positions immediately - again, checking from bottom up so they pile in correct order.
 

NightFrost

Member
I failed to mention that the match finder loop only checked towards right and bottom, starting from top left corner of the grid. This way it will not registed duplicate matches that are identical, just to opposite direction. It will however register long lines multiple times. So if there's a line with five matching items, it will register as match-3, match-4 and match-5 long records in the found matches array. You don't need to remove duplicate instances though, because just doing instance_exists() when using the list to delete them is faster than mucking around in extra loops and trying to figure if the instance is already in one of the arrays.

If you are scoring by removed match length, that is also simple to handle. As explained above, every long match is guaranteed to exist on the list in every shorter form; a match that is 5 items long will also have 4 and 3 item match on the list (both only once because we're just exploring left and down). So if you want to score the lengths for example at 600, 500 and 400 respectively, you define the 5-match as 600-500=100 worth, 4-match as 500-400=100 worth, and 3-match as 400. So when the score calculator sees the 5-match line as 5-4-3 match discoveries, it awards a total of 100+100+400=600 points.

Which is a long way of explaining you do not need to waste time trying to remove overlapping duplicates from the discovered matches list, you just adjust scoring to work around it and save a lot of work. Of course, if you for some reason need to keep record of number of matches found, then you'll have to remove the overlapping dupes.
 
Top