Delete items from a list in a particulary way

Hi,

I make a game like tetris.
I can delete a list of vector (represent the pixels of my tetris game) to the left at the right in a linear (with Vector x) way (and with couroutine for animation effect), but in this way i don’t figure how (see the white tiles, i would like the same result) →

Thank you !

Nope. You made a “falling sand” game. Tetris is about purposefully stacking shaped objects. That’s quite different. :wink:

Unclear what you mean. You want all the white pixels to disappear even though they zigzag up and down? If so you need a floodfill algorithm even despite it’s name isn’t going to fill anything you can use it to determine whether the “fill” operation starting at the left side actually finds a pixel on the very right side. In that case, you can then delete all the pixels that have been traversed.

In that sense the game is like Tetris, by removing a layer of sand. But still not Tetris. :wink:

2 Likes

Thank you so much for your reply !

Yes its a floodfill algo and a tetris sand :slight_smile:

But if you look at the beginning of the white tiles (some tiles are delete at the beginning and other after it’s not linear not at the same time, in my game they are delete to the left at the right whithout hole ), this effect (discontinue) can be done with a floodfill algo ?

Look inside the yellow circle of this image

Sorry i try to do my best to explain :slight_smile: , sorry for my english

@+

You mean the gaps between falling pixels?

You’ll notice many falling sands games have these. This can be caused by non-linear acceleration ie gravity, meaning the pixels that already fell for a while will move faster than then ones above them, thus these (unavoidable) gaps appear.

It also matters whether you update pixels bottom up or top down. If you do top-down the pixels above won’t fall down unless the pixel below it has moved, thus they will be forced to have a space between them by the nature of the update cycle. Be sure to update from bottom up but of course this reverses for pixels that “fall upwards” like steam.

1 Like

Hi,

I mean the white tiles is a clear line (its detected by a flood fill algo).
I put all tiles connected of the same color in list.
Then I ordered the list to be removed from the left to the right
I use a coroutine when I clear the lines.
It’s ok, that works, but the clear line has a “linear” animation .
There isn’t any gap effect, it’s fluid (cause of list order).

Thank you

Are you trying to say you want them to disappear in a random order, possibly with a random time?

I figure with the list of tiles you already have, on each frame, you pick a random number of them, and then a random selection of indices equal to the prior number, and then delete those/remove from the list. Rinse and repeat until you have nothing left.

Depending on the effect you want, you could have a certain falloff as you have less tiles. So it starts faster and slows down with less tiles.

If that’s not what you mean, I think you need to link a video of what you’re after. A still image isn’t really getting it across.

1 Like

Hi,

Yes, you are right, I have to make “a random selection of indices equal to the prior number”.
My list contains all clear tiles (vector).
But how can I randomly clear a list from the left to right ?
Maybe I can make 3 lists (depending on their vectors) from the main list, one to the left one to the middle and one other to the right, then I randomize one by one (i can shuffle the three lists also and i don’t need to make a random…).

What do you think ?

@+

I do feel like you’re overthinking this? If you have a List<T> - presumably of your positions - then you can generate a random index, and remove it with List<T>.RemoveAt after you use that position to remove the voxel. Unless there’s something I’m not understanding about what you mean.

1 Like

Thank you !

My problem is solved